nut-2.8.4/0000755000175000017500000000000015045366657007355 500000000000000nut-2.8.4/LICENSE-GPL30000644000175000017500000010437414670526611011005 00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . nut-2.8.4/NEWS0000644000175000017500000000005115045354741007757 00000000000000Please see NEWS.adoc for actual contents nut-2.8.4/data/0000755000175000017500000000000015045366654010263 500000000000000nut-2.8.4/data/html/0000755000175000017500000000000015045366654011227 500000000000000nut-2.8.4/data/html/README.adoc0000644000175000017500000000570715000736161012726 00000000000000NUT HTML complementary information ================================== Arnaud Quette , Dave Breiland v1.0, 27 Jul 2005 (start date) This file provides some complementary information about the use and integration of NUT HTML pages. 1) Introduction --------------- NUT HTML pages have been created as a central point that ease the access to the various CGI scripts providing the NUT web interface. It consists of three HTML files: * `index.html`: defines the two container frames, `topFrame` and `mainFrame` * `header.html`: contains the header including links to NUT website, and `upsstats.cgi`/`upsset.cgi` * `bottom.html`: empty frame that will be replaced with the content of `upsstats.cgi` or `upsset.cgi`. 2) Integration -------------- You first need to install NUT CGI, i.e. using ---- :; ./configure --with-cgi ---- Refer to the NUT documentation for more information. There are two ways to integrate NUT HTML with your webserver, with the same results: a) take advantage of the existing tree ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - the cgi programs are (for example) installed in `/usr/lib/cgi-bin`, which is already configured in your webserver as the default CGI path - in the same spirit, we will use the existing `DocumentRoot` (in terms of Apache webserver) and create a `nut` subdirectory, and copy the three `.html` files (`index`, `header` and `bottom`) Note that the links to cgi programs in `header.html` are pre-configured to work in this situation, which eases the packagers' work. b) configure manually ~~~~~~~~~~~~~~~~~~~~~ - copy the `data/html` directory to some path (i.e. `/usr/local/nut` for a standard installation from source) - Now edit your webserver configuration file, adding for example (for Apache): + ---- #Begin Section ScriptAlias /nut/cgi-bin/ /usr/local/nut/cgi-bin/ AllowOverride AuthConfig Options ExecCGI Order allow,deny Allow from all Alias /nut/ /usr/local/nut/html/ Options None AllowOverride AuthConfig Order allow,deny Allow from all #End Section ---- - Make sure to change the links path in `header.html` according to your configuration and installation. 3) Conclusion ------------- - Make sure to restart your webserver. - Configure the CGI scripts. Man pages can be found from: + ---- :; man -M /usr/local/nut/man/ upsstats.cgi :; man -M /usr/local/nut/man/ upsset.cgi :; man -M /usr/local/nut/man/ upsimage.cgi :; man -M /usr/local/nut/man/ hosts.conf ---- - It is recommended that you use `.htaccess` files in the `cgi-bin` folder and the `html` folder. Please reference: http://httpd.apache.org/docs/howto/htaccess.html - You will then be able to access the NUT HTML page at: http://localhost/nut - Further protection with HTTPS is recommended, especially for installations on networks accessible by someone other than yourself. nut-2.8.4/data/html/nut-banner.png0000644000175000017500000000527614670526611013732 00000000000000PNG  IHDR("S$PLTE?8Uql tEXtSoftwaregif2png 1.1.1,!qtEXtmimencode_-d_gzip_-dc H4sICOfSNEAAA3owAKVUS2/jNhA+h79ijglq0ZQc+aFsF039wLpYZQPLLQoUPdDy2GZXJgWS ipOiP75D2Umd3Q1aoLyIEGe+x8yQM2v2MJHWouZ5eYeqqn6QdVnykv4vdw3McAXxCMQgi9NM JJAIcc0W6Buro3vpdxm8eyP9PYWVqB5wncEm0GgX4R7l3kv+QnH5Wz/h8YAnaY+PRr9fsYvV E2xR2pV55PhYV0Z5x43dwuWQxxQquqfvFRyU38G0yJf3oNag4p8ms9jNhYiHaZ9dbIyFd/az NSTpHOj9TfDVCaaCt+Dn2V0MkegL8aXuUre6tdtLVfGwDfpP8uN0xJM4JUGCXwcD8LLIyTct fzS+cTAxe6UNLLBC6RD6XPDeefZrd0GmSOJRnKTDdCDSKIn7AwE3ZwlfuYqTLB1m6QC+E7SA /RrlZABtBkcFd8ajexGQkoABQC5tuYMk7gSMmOXzfBr9gtYpozOIuWBFs/oDS5/B7f0YSrmq ENboCdixpcm+XXKWo3Nyi9F8QhGfZv3r3nT843jCR4NBcivGw+jT3VAkaX/am3GSnl4Pr3tn gzSjNmRvjSmbSI/Zv9kP7snL0srycwYFWiUr9SeGJi1M49GC0ZArrc2hO82nt12yN7581Z2/ Cqw97lcUm/Tb+vSuQHpGrF2RdF+RdtjFnGJPDG0XifPhSBPw82VLQZ//SEIMxPPa2X1OPG94 +b8kIj7diS9IqOJ1hR4p/o1wNjbao/aRf6qpMR4ffbeupNI3UO6kdei//7mIbovxfM4KL2kU M1iwl/VBdRibE4JF55XegjdgUa6DKb9DOFCDn0xjn8cO5IpMt0dhJIu9tB4KtdWyqiidtTPK GZs+oIa9sQjqDPwgHaWSF4IEWfqGsp6gblaVcjtc05lyZ8wdkI6F/TO52bRHx4sgbaiP3qg1 2ad6cZpK/ErRKVgdgT6qEnWJEN6roN+ZjT8QUId2pBRws6Hr1srbyQdKI4xtK7I0tcI1q44A rkUIdamtWTclXT3GiN79o7XNXyGVoZbOBXOmFW9pNqg4nhgbS0iUuMCttGtHnTjeOjjdOiqj K2UlPb0HUDR1bcjaVG+VRrShezvv66zbPRwOz48k/fwb3RDCHGYGAAA= NG~IDATxYMOWf1` ɂՊ]Yb{e%%"ɤ ;T7cpdqEߝ܏!O<ʃ_ۀE6`A@#&@|9 ϗv EYYk48 dlp>ܫLU^}ا<@BQQpm%!0 _|'r\ y\.nt2Yͱy[]%JD=R"Gy+G g^tUS|h8_,JPEz"A!+" }..<6f%jf2Ni.`6?xPﰹP 2"==u In 7?30lt4xnjSMډӧg_13q| EX>XXDהKMqk@Q>ֳ_;TVl Mi`L+wm'Q _n8\@@ Y__Q[ Y@ C6Qf%eI&m5%*Ɩ+؉!%y߳݌2V @>8 ;kۄNIzz}h)]DP&K^d(5F#@Ʃ+jnsޱbç@uFBs| h3aj"PnlQ<hVj,uڴ)+VuX ľ6=yI}ޚ kuIng3crﳍ*hkFg?=8yd.?{B% hbPIENDB`nut-2.8.4/data/html/bottom.html0000644000175000017500000000007614670526611013336 00000000000000 nut-2.8.4/data/html/Makefile.in0000644000175000017500000006561115045354760013220 00000000000000# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # Network UPS Tools: data/html VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ subdir = data/html ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_c___attribute__.m4 \ $(top_srcdir)/m4/ax_c_pragmas.m4 \ $(top_srcdir)/m4/ax_check_compile_flag.m4 \ $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/ax_realpath.m4 \ $(top_srcdir)/m4/ax_realpath_lib.m4 \ $(top_srcdir)/m4/ax_run_or_link_ifelse.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/m4/nut_arg_with.m4 \ $(top_srcdir)/m4/nut_check_asciidoc.m4 \ $(top_srcdir)/m4/nut_check_aspell.m4 \ $(top_srcdir)/m4/nut_check_bool.m4 \ $(top_srcdir)/m4/nut_check_cppcheck.m4 \ $(top_srcdir)/m4/nut_check_headers_windows.m4 \ $(top_srcdir)/m4/nut_check_libavahi.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libgpiod.m4 \ $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libmodbus.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libnss.m4 \ $(top_srcdir)/m4/nut_check_libopenssl.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ $(top_srcdir)/m4/nut_check_libregex.m4 \ $(top_srcdir)/m4/nut_check_libsystemd.m4 \ $(top_srcdir)/m4/nut_check_libusb.m4 \ $(top_srcdir)/m4/nut_check_libwrap.m4 \ $(top_srcdir)/m4/nut_check_os.m4 \ $(top_srcdir)/m4/nut_check_pkgconfig.m4 \ $(top_srcdir)/m4/nut_check_python.m4 \ $(top_srcdir)/m4/nut_check_socketlib.m4 \ $(top_srcdir)/m4/nut_compiler_family.m4 \ $(top_srcdir)/m4/nut_func_getnameinfo_argtypes.m4 \ $(top_srcdir)/m4/nut_report_feature.m4 \ $(top_srcdir)/m4/nut_stash_warnings.m4 \ $(top_srcdir)/m4/nut_type_socklen_t.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__dist_html_DATA_DIST) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/config.h CONFIG_CLEAN_FILES = header.html CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__dist_html_DATA_DIST = index.html bottom.html nut-banner.png am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } am__installdirs = "$(DESTDIR)$(htmldir)" "$(DESTDIR)$(htmldir)" DATA = $(dist_html_DATA) $(nodist_html_DATA) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/header.html.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) A2X = @A2X@ ACLOCAL = @ACLOCAL@ ALTPIDPATH = @ALTPIDPATH@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ ASCIIDOC = @ASCIIDOC@ ASCIIDOC_LINKMANEXT_SECTION_REWRITE = @ASCIIDOC_LINKMANEXT_SECTION_REWRITE@ ASCIIDOC_TEMPLATE_LINKMANEXT = @ASCIIDOC_TEMPLATE_LINKMANEXT@ ASCIIDOC_TEMPLATE_LINKMANEXT2 = @ASCIIDOC_TEMPLATE_LINKMANEXT2@ ASPELL = @ASPELL@ ASPELL_FILTER_LIB_PATH = @ASPELL_FILTER_LIB_PATH@ ASPELL_FILTER_SHARE_PATH = @ASPELL_FILTER_SHARE_PATH@ ASPELL_FILTER_TEX_PATH = @ASPELL_FILTER_TEX_PATH@ AUGPARSE = @AUGPARSE@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BINDIR = @BINDIR@ BSDKVMPROCLIBS = @BSDKVMPROCLIBS@ CC = @CC@ CCACHE_BASEDIR = @CCACHE_BASEDIR@ CCACHE_DIR = @CCACHE_DIR@ CCACHE_NAMESPACE = @CCACHE_NAMESPACE@ CCACHE_PATH = @CCACHE_PATH@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CONFIG_CFLAGS = @CONFIG_CFLAGS@ CONFIG_CPPFLAGS = @CONFIG_CPPFLAGS@ CONFIG_CXXFLAGS = @CONFIG_CXXFLAGS@ CONFIG_FLAGS = @CONFIG_FLAGS@ CONFIG_LDFLAGS = @CONFIG_LDFLAGS@ CONFPATH = @CONFPATH@ CPP = @CPP@ CPPCHECK = @CPPCHECK@ CPPFLAGS = @CPPFLAGS@ CPPUNIT_CFLAGS = @CPPUNIT_CFLAGS@ CPPUNIT_LIBS = @CPPUNIT_LIBS@ CPPUNIT_NUT_CXXFLAGS = @CPPUNIT_NUT_CXXFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH = @CYGPATH@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DEPLOYED_DUMMYUPS = @DEPLOYED_DUMMYUPS@ DEPLOYED_UPSC = @DEPLOYED_UPSC@ DEPLOYED_UPSD = @DEPLOYED_UPSD@ DEPLOYED_UPSIMAGE = @DEPLOYED_UPSIMAGE@ DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DOC_CHECK_LIST = @DOC_CHECK_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ DRIVER_MAN_LIST = @DRIVER_MAN_LIST@ DRIVER_MAN_LIST_PAGES = @DRIVER_MAN_LIST_PAGES@ DRVPATH = @DRVPATH@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FORCE_NUT_VERSION = @FORCE_NUT_VERSION@ GDLIB_CONFIG = @GDLIB_CONFIG@ GETENT = @GETENT@ GITLOG_END_POINT = @GITLOG_END_POINT@ GITLOG_START_POINT = @GITLOG_START_POINT@ GREP = @GREP@ HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@ HAVE_WINSOCK2_H = @HAVE_WINSOCK2_H@ HAVE_WS2TCPIP_H = @HAVE_WS2TCPIP_H@ ID = @ID@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDD = @LDD@ LDFLAGS = @LDFLAGS@ LDFLAGS_NUT_RPATH = @LDFLAGS_NUT_RPATH@ LDFLAGS_NUT_RPATH_CXX = @LDFLAGS_NUT_RPATH_CXX@ LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@ LIBAVAHI_LIBS = @LIBAVAHI_LIBS@ LIBDIR = @LIBDIR@ LIBGD_CFLAGS = @LIBGD_CFLAGS@ LIBGD_LDFLAGS = @LIBGD_LDFLAGS@ LIBGPIO_CFLAGS = @LIBGPIO_CFLAGS@ LIBGPIO_LIBS = @LIBGPIO_LIBS@ LIBI2C_LIBS = @LIBI2C_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBMODBUS_CFLAGS = @LIBMODBUS_CFLAGS@ LIBMODBUS_LIBS = @LIBMODBUS_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ LIBNETSNMP_LIBS = @LIBNETSNMP_LIBS@ LIBOBJS = @LIBOBJS@ LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@ LIBPOWERMAN_LIBS = @LIBPOWERMAN_LIBS@ LIBREGEX_LIBS = @LIBREGEX_LIBS@ LIBS = @LIBS@ LIBSSL_CFLAGS = @LIBSSL_CFLAGS@ LIBSSL_LDFLAGS_RPATH = @LIBSSL_LDFLAGS_RPATH@ LIBSSL_LIBS = @LIBSSL_LIBS@ LIBSSL_REQUIRES = @LIBSSL_REQUIRES@ LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIBUSB_CFLAGS = @LIBUSB_CFLAGS@ LIBUSB_CONFIG = @LIBUSB_CONFIG@ LIBUSB_LIBS = @LIBUSB_LIBS@ LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@ LIBWRAP_LIBS = @LIBWRAP_LIBS@ LIPO = @LIPO@ LN_S = @LN_S@ LN_S_R = @LN_S_R@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MAN_DIR_AS_BASE = @MAN_DIR_AS_BASE@ MAN_SECTION_API = @MAN_SECTION_API@ MAN_SECTION_API_BASE = @MAN_SECTION_API_BASE@ MAN_SECTION_CFG = @MAN_SECTION_CFG@ MAN_SECTION_CFG_BASE = @MAN_SECTION_CFG_BASE@ MAN_SECTION_CMD_SYS = @MAN_SECTION_CMD_SYS@ MAN_SECTION_CMD_SYS_BASE = @MAN_SECTION_CMD_SYS_BASE@ MAN_SECTION_CMD_USR = @MAN_SECTION_CMD_USR@ MAN_SECTION_CMD_USR_BASE = @MAN_SECTION_CMD_USR_BASE@ MAN_SECTION_MISC = @MAN_SECTION_MISC@ MAN_SECTION_MISC_BASE = @MAN_SECTION_MISC_BASE@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ NETLIBS = @NETLIBS@ NETLIBS_GETADDRS = @NETLIBS_GETADDRS@ NET_SNMP_CONFIG = @NET_SNMP_CONFIG@ NM = @NM@ NMEDIT = @NMEDIT@ NUT_AM_EXPORT_CCACHE_BASEDIR = @NUT_AM_EXPORT_CCACHE_BASEDIR@ NUT_AM_EXPORT_CCACHE_DIR = @NUT_AM_EXPORT_CCACHE_DIR@ NUT_AM_EXPORT_CCACHE_NAMESPACE = @NUT_AM_EXPORT_CCACHE_NAMESPACE@ NUT_AM_EXPORT_CCACHE_PATH = @NUT_AM_EXPORT_CCACHE_PATH@ NUT_AM_MAKE_CAN_EXPORT = @NUT_AM_MAKE_CAN_EXPORT@ NUT_CONFIG_CFLAGS = @NUT_CONFIG_CFLAGS@ NUT_CONFIG_CPPFLAGS = @NUT_CONFIG_CPPFLAGS@ NUT_CONFIG_CXXFLAGS = @NUT_CONFIG_CXXFLAGS@ NUT_CONFIG_LDFLAGS = @NUT_CONFIG_LDFLAGS@ NUT_DATADIR = @NUT_DATADIR@ NUT_LIBEXECDIR = @NUT_LIBEXECDIR@ NUT_MANDIR = @NUT_MANDIR@ NUT_NETVERSION = @NUT_NETVERSION@ NUT_SOURCE_GITREV = @NUT_SOURCE_GITREV@ NUT_SOURCE_GITREV_IS_PRERELEASE = @NUT_SOURCE_GITREV_IS_PRERELEASE@ NUT_SOURCE_GITREV_IS_RELEASE = @NUT_SOURCE_GITREV_IS_RELEASE@ NUT_SOURCE_GITREV_NUMERIC = @NUT_SOURCE_GITREV_NUMERIC@ NUT_SOURCE_GITREV_SEMVER = @NUT_SOURCE_GITREV_SEMVER@ NUT_WEBSITE_BASE = @NUT_WEBSITE_BASE@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OS_NAME = @OS_NAME@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_DURING_CONFIGURE = @PATH_DURING_CONFIGURE@ PATH_SEPARATOR = @PATH_SEPARATOR@ PIDPATH = @PIDPATH@ PKGCONFIGDIR = @PKGCONFIGDIR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PORT = @PORT@ POWERDOWNFLAG = @POWERDOWNFLAG@ PREFIX = @PREFIX@ PWDTOOL = @PWDTOOL@ PYTHON = @PYTHON@ PYTHON2 = @PYTHON2@ PYTHON2_SITE_PACKAGES = @PYTHON2_SITE_PACKAGES@ PYTHON3 = @PYTHON3@ PYTHON3_SITE_PACKAGES = @PYTHON3_SITE_PACKAGES@ PYTHON_SITE_PACKAGES = @PYTHON_SITE_PACKAGES@ RANLIB = @RANLIB@ REALPATH = @REALPATH@ RUN_AS_GROUP = @RUN_AS_GROUP@ RUN_AS_USER = @RUN_AS_USER@ SBINDIR = @SBINDIR@ SED = @SED@ SEMLIBS = @SEMLIBS@ SERLIBS = @SERLIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ SOURCE_HIGHLIGHT = @SOURCE_HIGHLIGHT@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ SYSTEMCTL = @SYSTEMCTL@ SYSTEMD_ANALYZE_PROGRAM = @SYSTEMD_ANALYZE_PROGRAM@ SYSTEMD_DAEMON_ARGS_DRIVER = @SYSTEMD_DAEMON_ARGS_DRIVER@ SYSTEMD_DAEMON_ARGS_UPSD = @SYSTEMD_DAEMON_ARGS_UPSD@ SYSTEMD_DAEMON_ARGS_UPSLOG = @SYSTEMD_DAEMON_ARGS_UPSLOG@ SYSTEMD_DAEMON_ARGS_UPSMON = @SYSTEMD_DAEMON_ARGS_UPSMON@ SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER = @SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSD = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSD@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON@ SYSTEMD_DAEMON_TYPE_DRIVER = @SYSTEMD_DAEMON_TYPE_DRIVER@ SYSTEMD_DAEMON_TYPE_UPSD = @SYSTEMD_DAEMON_TYPE_UPSD@ SYSTEMD_DAEMON_TYPE_UPSLOG = @SYSTEMD_DAEMON_TYPE_UPSLOG@ SYSTEMD_DAEMON_TYPE_UPSMON = @SYSTEMD_DAEMON_TYPE_UPSMON@ SYSTEMD_DAEMON_WATCHDOG_DRIVER = @SYSTEMD_DAEMON_WATCHDOG_DRIVER@ SYSTEMD_DAEMON_WATCHDOG_UPSD = @SYSTEMD_DAEMON_WATCHDOG_UPSD@ SYSTEMD_DAEMON_WATCHDOG_UPSLOG = @SYSTEMD_DAEMON_WATCHDOG_UPSLOG@ SYSTEMD_DAEMON_WATCHDOG_UPSMON = @SYSTEMD_DAEMON_WATCHDOG_UPSMON@ SYSTEMD_SYSTEMCTL_PROGRAM = @SYSTEMD_SYSTEMCTL_PROGRAM@ SYSTEMD_TMPFILES_PROGRAM = @SYSTEMD_TMPFILES_PROGRAM@ TREE_VERSION = @TREE_VERSION@ VALGRIND = @VALGRIND@ VERSION = @VERSION@ WINDMC = @WINDMC@ WINDRES = @WINDRES@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ XMLLINT = @XMLLINT@ XSLTPROC = @XSLTPROC@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ ac_ct_LD = @ac_ct_LD@ ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ auglensdir = @auglensdir@ auglenstestsdir = @auglenstestsdir@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ cgiexecdir = @cgiexecdir@ datadir = @datadir@ datarootdir = @datarootdir@ devddir = @devddir@ docdir = @docdir@ driverexecdir = @driverexecdir@ dummy_PKG_CONFIG = @dummy_PKG_CONFIG@ dummy_PKG_CONFIG_CFLAGS = @dummy_PKG_CONFIG_CFLAGS@ dummy_PKG_CONFIG_LIBS = @dummy_PKG_CONFIG_LIBS@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ freebsdquirksdir = @freebsdquirksdir@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ hotplugdir = @hotplugdir@ htmldir = @htmldir@ htmldocdir = @htmldocdir@ htmlmandir = @htmlmandir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ now = @now@ nut_with_nut_monitor = @nut_with_nut_monitor@ nut_with_nut_monitor_desktop = @nut_with_nut_monitor_desktop@ nut_with_nut_monitor_dir = @nut_with_nut_monitor_dir@ nut_with_nut_monitor_py2gtk2 = @nut_with_nut_monitor_py2gtk2@ nut_with_nut_monitor_py3qt5 = @nut_with_nut_monitor_py3qt5@ nut_with_nut_monitor_py3qt6 = @nut_with_nut_monitor_py3qt6@ nut_with_pynut = @nut_with_pynut@ nut_with_pynut_py = @nut_with_pynut_py@ nut_with_pynut_py2 = @nut_with_pynut_py2@ nut_with_pynut_py3 = @nut_with_pynut_py3@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ systemdshutdowndir = @systemdshutdowndir@ systemdsystempresetdir = @systemdsystempresetdir@ systemdsystemunitdir = @systemdsystemunitdir@ systemdtmpfilesdir = @systemdtmpfilesdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ udevdir = @udevdir@ # install these only if configured --with-cgi @WITH_CGI_TRUE@dist_html_DATA = index.html bottom.html nut-banner.png @WITH_CGI_TRUE@nodist_html_DATA = header.html EXTRA_DIST = README.adoc SPELLCHECK_SRC = README.adoc CLEANFILES = *-spellchecked MAINTAINERCLEANFILES = Makefile.in .dirstamp # Generated by configure script: DISTCLEANFILES = header.html all: all-am .SUFFIXES: .SUFFIXES: .in .in-spellchecked .sample .sample-spellchecked $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu data/html/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu data/html/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): header.html: $(top_builddir)/config.status $(srcdir)/header.html.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-dist_htmlDATA: $(dist_html_DATA) @$(NORMAL_INSTALL) @list='$(dist_html_DATA)'; test -n "$(htmldir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(htmldir)'"; \ $(MKDIR_P) "$(DESTDIR)$(htmldir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(htmldir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(htmldir)" || exit $$?; \ done uninstall-dist_htmlDATA: @$(NORMAL_UNINSTALL) @list='$(dist_html_DATA)'; test -n "$(htmldir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(htmldir)'; $(am__uninstall_files_from_dir) install-nodist_htmlDATA: $(nodist_html_DATA) @$(NORMAL_INSTALL) @list='$(nodist_html_DATA)'; test -n "$(htmldir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(htmldir)'"; \ $(MKDIR_P) "$(DESTDIR)$(htmldir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(htmldir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(htmldir)" || exit $$?; \ done uninstall-nodist_htmlDATA: @$(NORMAL_UNINSTALL) @list='$(nodist_html_DATA)'; test -n "$(htmldir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(htmldir)'; $(am__uninstall_files_from_dir) tags TAGS: ctags CTAGS: cscope cscopelist: distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(DATA) installdirs: for dir in "$(DESTDIR)$(htmldir)" "$(DESTDIR)$(htmldir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) clean: clean-am clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile distclean-am: clean-am distclean-generic dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-dist_htmlDATA install-nodist_htmlDATA install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-dist_htmlDATA uninstall-nodist_htmlDATA .MAKE: install-am install-strip .PHONY: all all-am check check-am clean clean-generic clean-libtool \ cscopelist-am ctags-am distclean distclean-generic \ distclean-libtool distdir dvi dvi-am html html-am info info-am \ install install-am install-data install-data-am \ install-dist_htmlDATA install-dvi install-dvi-am install-exec \ install-exec-am install-html install-html-am install-info \ install-info-am install-man install-nodist_htmlDATA \ install-pdf install-pdf-am install-ps install-ps-am \ install-strip installcheck installcheck-am installdirs \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags-am uninstall uninstall-am uninstall-dist_htmlDATA \ uninstall-nodist_htmlDATA .PRECIOUS: Makefile # NOTE: Due to portability, we do not use a GNU percent-wildcard extension. # We also have to export some variables that may be tainted by relative # paths when parsing the other makefile (e.g. MKDIR_P that may be defined # via expanded $(top_builddir)/install-sh): #%-spellchecked: % Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) # +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ # NOTE: Portable suffix rules do not allow prerequisites, so we shim them here # by a wildcard target in case the make implementation can put the two together. *-spellchecked: Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) .sample.sample-spellchecked: +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ .in.in-spellchecked: +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ spellcheck spellcheck-interactive spellcheck-sortdict: +$(MAKE) -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC="$(SPELLCHECK_SRC)" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: nut-2.8.4/data/html/Makefile.am0000664000175000017500000000423215000733176013172 00000000000000# Network UPS Tools: data/html # install these only if configured --with-cgi if WITH_CGI dist_html_DATA = index.html bottom.html nut-banner.png nodist_html_DATA = header.html endif EXTRA_DIST = README.adoc SPELLCHECK_SRC = README.adoc # NOTE: Due to portability, we do not use a GNU percent-wildcard extension. # We also have to export some variables that may be tainted by relative # paths when parsing the other makefile (e.g. MKDIR_P that may be defined # via expanded $(top_builddir)/install-sh): #%-spellchecked: % Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) # +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ # NOTE: Portable suffix rules do not allow prerequisites, so we shim them here # by a wildcard target in case the make implementation can put the two together. *-spellchecked: Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) .sample.sample-spellchecked: +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ .in.in-spellchecked: +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ spellcheck spellcheck-interactive spellcheck-sortdict: +$(MAKE) -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC="$(SPELLCHECK_SRC)" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ CLEANFILES = *-spellchecked MAINTAINERCLEANFILES = Makefile.in .dirstamp # Generated by configure script: DISTCLEANFILES = header.html nut-2.8.4/data/html/index.html0000644000175000017500000000077014777753336013160 00000000000000 Network UPS Tools -- https://www.networkupstools.org <body> </body> nut-2.8.4/data/html/header.html.in0000644000175000017500000000115714777753336013706 00000000000000 Network UPS Tools

Statistics Settings
nut-2.8.4/data/evolution500.seq0000644000175000017500000000257214670526611013166 00000000000000# dummy-ups example power sequence file # # Base is the same as .dev files, generated using: # $ upsc ups@host > evolution500.seq # # TIMER have then been added to generate power events. battery.charge: 90 battery.charge.low: 30 battery.runtime: 3690 battery.voltage: 230.0 driver.name: usbhid-ups driver.parameter.port: auto driver.version: 2.2.0 driver.version.data: MGE HID 0.7 driver.version.internal: 0.23 input.frequency: 49.0 input.transfer.boost.low: 184.0 input.transfer.high: 294.0 input.transfer.low: 160.0 input.transfer.trim.high: 265.0 input.voltage: 230.0 outlet.desc: Main Outlet outlet.id: 0 outlet.switchable: 0 outlet.1.autoswitch.charge.low: 0 outlet.1.delay.shutdown: -1 outlet.1.delay.start: -1 outlet.1.desc: PowerShare Outlet 1 outlet.1.id: 1 outlet.1.switch: 1 outlet.1.switchable: 1 outlet.2.autoswitch.charge.low: 0 outlet.2.delay.shutdown: -1 outlet.2.delay.start: -1 outlet.2.desc: PowerShare Outlet 2 outlet.2.id: 2 outlet.2.switch: 1 outlet.2.switchable: 1 output.current: 0.00 output.frequency: 49.0 output.voltage: 230.0 output.voltage.nominal: 230.0 ups.delay.shutdown: -1 ups.delay.start: -10 ups.load: 10 ups.mfr: MGE UPS SYSTEMS ups.model: Pulsar Evolution 500 ups.power.nominal: 500 ups.serial: AV2G3300L ups.status: OL CHRG ups.test.interval: 604800 ups.test.result: Done and passed TIMER 300 ups.status: OB DISCHRG TIMER 300 ups.status: OB LB DISCHRG TIMER 60 nut-2.8.4/data/Makefile.in0000644000175000017500000010122415045354760012243 00000000000000# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # Network UPS Tools: data VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ subdir = data ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_c___attribute__.m4 \ $(top_srcdir)/m4/ax_c_pragmas.m4 \ $(top_srcdir)/m4/ax_check_compile_flag.m4 \ $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/ax_realpath.m4 \ $(top_srcdir)/m4/ax_realpath_lib.m4 \ $(top_srcdir)/m4/ax_run_or_link_ifelse.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/m4/nut_arg_with.m4 \ $(top_srcdir)/m4/nut_check_asciidoc.m4 \ $(top_srcdir)/m4/nut_check_aspell.m4 \ $(top_srcdir)/m4/nut_check_bool.m4 \ $(top_srcdir)/m4/nut_check_cppcheck.m4 \ $(top_srcdir)/m4/nut_check_headers_windows.m4 \ $(top_srcdir)/m4/nut_check_libavahi.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libgpiod.m4 \ $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libmodbus.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libnss.m4 \ $(top_srcdir)/m4/nut_check_libopenssl.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ $(top_srcdir)/m4/nut_check_libregex.m4 \ $(top_srcdir)/m4/nut_check_libsystemd.m4 \ $(top_srcdir)/m4/nut_check_libusb.m4 \ $(top_srcdir)/m4/nut_check_libwrap.m4 \ $(top_srcdir)/m4/nut_check_os.m4 \ $(top_srcdir)/m4/nut_check_pkgconfig.m4 \ $(top_srcdir)/m4/nut_check_python.m4 \ $(top_srcdir)/m4/nut_check_socketlib.m4 \ $(top_srcdir)/m4/nut_compiler_family.m4 \ $(top_srcdir)/m4/nut_func_getnameinfo_argtypes.m4 \ $(top_srcdir)/m4/nut_report_feature.m4 \ $(top_srcdir)/m4/nut_stash_warnings.m4 \ $(top_srcdir)/m4/nut_type_socklen_t.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(dist_data_DATA) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/config.h CONFIG_CLEAN_FILES = driver.list CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ install-exec-recursive install-html-recursive \ install-info-recursive install-pdf-recursive \ install-ps-recursive install-recursive installcheck-recursive \ installdirs-recursive pdf-recursive ps-recursive \ tags-recursive uninstall-recursive am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } am__installdirs = "$(DESTDIR)$(datadir)" "$(DESTDIR)$(datadir)" DATA = $(dist_data_DATA) $(nodist_data_DATA) RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive am__recursive_targets = \ $(RECURSIVE_TARGETS) \ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ distdir distdir-am am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/driver.list.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) am__relativize = \ dir0=`pwd`; \ sed_first='s,^\([^/]*\)/.*$$,\1,'; \ sed_rest='s,^[^/]*/*,,'; \ sed_last='s,^.*/\([^/]*\)$$,\1,'; \ sed_butlast='s,/*[^/]*$$,,'; \ while test -n "$$dir1"; do \ first=`echo "$$dir1" | sed -e "$$sed_first"`; \ if test "$$first" != "."; then \ if test "$$first" = ".."; then \ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ else \ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ if test "$$first2" = "$$first"; then \ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ else \ dir2="../$$dir2"; \ fi; \ dir0="$$dir0"/"$$first"; \ fi; \ fi; \ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ done; \ reldir="$$dir2" A2X = @A2X@ ACLOCAL = @ACLOCAL@ ALTPIDPATH = @ALTPIDPATH@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ ASCIIDOC = @ASCIIDOC@ ASCIIDOC_LINKMANEXT_SECTION_REWRITE = @ASCIIDOC_LINKMANEXT_SECTION_REWRITE@ ASCIIDOC_TEMPLATE_LINKMANEXT = @ASCIIDOC_TEMPLATE_LINKMANEXT@ ASCIIDOC_TEMPLATE_LINKMANEXT2 = @ASCIIDOC_TEMPLATE_LINKMANEXT2@ ASPELL = @ASPELL@ ASPELL_FILTER_LIB_PATH = @ASPELL_FILTER_LIB_PATH@ ASPELL_FILTER_SHARE_PATH = @ASPELL_FILTER_SHARE_PATH@ ASPELL_FILTER_TEX_PATH = @ASPELL_FILTER_TEX_PATH@ AUGPARSE = @AUGPARSE@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BINDIR = @BINDIR@ BSDKVMPROCLIBS = @BSDKVMPROCLIBS@ CC = @CC@ CCACHE_BASEDIR = @CCACHE_BASEDIR@ CCACHE_DIR = @CCACHE_DIR@ CCACHE_NAMESPACE = @CCACHE_NAMESPACE@ CCACHE_PATH = @CCACHE_PATH@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CONFIG_CFLAGS = @CONFIG_CFLAGS@ CONFIG_CPPFLAGS = @CONFIG_CPPFLAGS@ CONFIG_CXXFLAGS = @CONFIG_CXXFLAGS@ CONFIG_FLAGS = @CONFIG_FLAGS@ CONFIG_LDFLAGS = @CONFIG_LDFLAGS@ CONFPATH = @CONFPATH@ CPP = @CPP@ CPPCHECK = @CPPCHECK@ CPPFLAGS = @CPPFLAGS@ CPPUNIT_CFLAGS = @CPPUNIT_CFLAGS@ CPPUNIT_LIBS = @CPPUNIT_LIBS@ CPPUNIT_NUT_CXXFLAGS = @CPPUNIT_NUT_CXXFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH = @CYGPATH@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DEPLOYED_DUMMYUPS = @DEPLOYED_DUMMYUPS@ DEPLOYED_UPSC = @DEPLOYED_UPSC@ DEPLOYED_UPSD = @DEPLOYED_UPSD@ DEPLOYED_UPSIMAGE = @DEPLOYED_UPSIMAGE@ DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DOC_CHECK_LIST = @DOC_CHECK_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ DRIVER_MAN_LIST = @DRIVER_MAN_LIST@ DRIVER_MAN_LIST_PAGES = @DRIVER_MAN_LIST_PAGES@ DRVPATH = @DRVPATH@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FORCE_NUT_VERSION = @FORCE_NUT_VERSION@ GDLIB_CONFIG = @GDLIB_CONFIG@ GETENT = @GETENT@ GITLOG_END_POINT = @GITLOG_END_POINT@ GITLOG_START_POINT = @GITLOG_START_POINT@ GREP = @GREP@ HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@ HAVE_WINSOCK2_H = @HAVE_WINSOCK2_H@ HAVE_WS2TCPIP_H = @HAVE_WS2TCPIP_H@ ID = @ID@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDD = @LDD@ LDFLAGS = @LDFLAGS@ LDFLAGS_NUT_RPATH = @LDFLAGS_NUT_RPATH@ LDFLAGS_NUT_RPATH_CXX = @LDFLAGS_NUT_RPATH_CXX@ LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@ LIBAVAHI_LIBS = @LIBAVAHI_LIBS@ LIBDIR = @LIBDIR@ LIBGD_CFLAGS = @LIBGD_CFLAGS@ LIBGD_LDFLAGS = @LIBGD_LDFLAGS@ LIBGPIO_CFLAGS = @LIBGPIO_CFLAGS@ LIBGPIO_LIBS = @LIBGPIO_LIBS@ LIBI2C_LIBS = @LIBI2C_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBMODBUS_CFLAGS = @LIBMODBUS_CFLAGS@ LIBMODBUS_LIBS = @LIBMODBUS_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ LIBNETSNMP_LIBS = @LIBNETSNMP_LIBS@ LIBOBJS = @LIBOBJS@ LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@ LIBPOWERMAN_LIBS = @LIBPOWERMAN_LIBS@ LIBREGEX_LIBS = @LIBREGEX_LIBS@ LIBS = @LIBS@ LIBSSL_CFLAGS = @LIBSSL_CFLAGS@ LIBSSL_LDFLAGS_RPATH = @LIBSSL_LDFLAGS_RPATH@ LIBSSL_LIBS = @LIBSSL_LIBS@ LIBSSL_REQUIRES = @LIBSSL_REQUIRES@ LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIBUSB_CFLAGS = @LIBUSB_CFLAGS@ LIBUSB_CONFIG = @LIBUSB_CONFIG@ LIBUSB_LIBS = @LIBUSB_LIBS@ LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@ LIBWRAP_LIBS = @LIBWRAP_LIBS@ LIPO = @LIPO@ LN_S = @LN_S@ LN_S_R = @LN_S_R@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MAN_DIR_AS_BASE = @MAN_DIR_AS_BASE@ MAN_SECTION_API = @MAN_SECTION_API@ MAN_SECTION_API_BASE = @MAN_SECTION_API_BASE@ MAN_SECTION_CFG = @MAN_SECTION_CFG@ MAN_SECTION_CFG_BASE = @MAN_SECTION_CFG_BASE@ MAN_SECTION_CMD_SYS = @MAN_SECTION_CMD_SYS@ MAN_SECTION_CMD_SYS_BASE = @MAN_SECTION_CMD_SYS_BASE@ MAN_SECTION_CMD_USR = @MAN_SECTION_CMD_USR@ MAN_SECTION_CMD_USR_BASE = @MAN_SECTION_CMD_USR_BASE@ MAN_SECTION_MISC = @MAN_SECTION_MISC@ MAN_SECTION_MISC_BASE = @MAN_SECTION_MISC_BASE@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ NETLIBS = @NETLIBS@ NETLIBS_GETADDRS = @NETLIBS_GETADDRS@ NET_SNMP_CONFIG = @NET_SNMP_CONFIG@ NM = @NM@ NMEDIT = @NMEDIT@ NUT_AM_EXPORT_CCACHE_BASEDIR = @NUT_AM_EXPORT_CCACHE_BASEDIR@ NUT_AM_EXPORT_CCACHE_DIR = @NUT_AM_EXPORT_CCACHE_DIR@ NUT_AM_EXPORT_CCACHE_NAMESPACE = @NUT_AM_EXPORT_CCACHE_NAMESPACE@ NUT_AM_EXPORT_CCACHE_PATH = @NUT_AM_EXPORT_CCACHE_PATH@ NUT_AM_MAKE_CAN_EXPORT = @NUT_AM_MAKE_CAN_EXPORT@ NUT_CONFIG_CFLAGS = @NUT_CONFIG_CFLAGS@ NUT_CONFIG_CPPFLAGS = @NUT_CONFIG_CPPFLAGS@ NUT_CONFIG_CXXFLAGS = @NUT_CONFIG_CXXFLAGS@ NUT_CONFIG_LDFLAGS = @NUT_CONFIG_LDFLAGS@ NUT_DATADIR = @NUT_DATADIR@ NUT_LIBEXECDIR = @NUT_LIBEXECDIR@ NUT_MANDIR = @NUT_MANDIR@ NUT_NETVERSION = @NUT_NETVERSION@ NUT_SOURCE_GITREV = @NUT_SOURCE_GITREV@ NUT_SOURCE_GITREV_IS_PRERELEASE = @NUT_SOURCE_GITREV_IS_PRERELEASE@ NUT_SOURCE_GITREV_IS_RELEASE = @NUT_SOURCE_GITREV_IS_RELEASE@ NUT_SOURCE_GITREV_NUMERIC = @NUT_SOURCE_GITREV_NUMERIC@ NUT_SOURCE_GITREV_SEMVER = @NUT_SOURCE_GITREV_SEMVER@ NUT_WEBSITE_BASE = @NUT_WEBSITE_BASE@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OS_NAME = @OS_NAME@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_DURING_CONFIGURE = @PATH_DURING_CONFIGURE@ PATH_SEPARATOR = @PATH_SEPARATOR@ PIDPATH = @PIDPATH@ PKGCONFIGDIR = @PKGCONFIGDIR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PORT = @PORT@ POWERDOWNFLAG = @POWERDOWNFLAG@ PREFIX = @PREFIX@ PWDTOOL = @PWDTOOL@ PYTHON = @PYTHON@ PYTHON2 = @PYTHON2@ PYTHON2_SITE_PACKAGES = @PYTHON2_SITE_PACKAGES@ PYTHON3 = @PYTHON3@ PYTHON3_SITE_PACKAGES = @PYTHON3_SITE_PACKAGES@ PYTHON_SITE_PACKAGES = @PYTHON_SITE_PACKAGES@ RANLIB = @RANLIB@ REALPATH = @REALPATH@ RUN_AS_GROUP = @RUN_AS_GROUP@ RUN_AS_USER = @RUN_AS_USER@ SBINDIR = @SBINDIR@ SED = @SED@ SEMLIBS = @SEMLIBS@ SERLIBS = @SERLIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ SOURCE_HIGHLIGHT = @SOURCE_HIGHLIGHT@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ SYSTEMCTL = @SYSTEMCTL@ SYSTEMD_ANALYZE_PROGRAM = @SYSTEMD_ANALYZE_PROGRAM@ SYSTEMD_DAEMON_ARGS_DRIVER = @SYSTEMD_DAEMON_ARGS_DRIVER@ SYSTEMD_DAEMON_ARGS_UPSD = @SYSTEMD_DAEMON_ARGS_UPSD@ SYSTEMD_DAEMON_ARGS_UPSLOG = @SYSTEMD_DAEMON_ARGS_UPSLOG@ SYSTEMD_DAEMON_ARGS_UPSMON = @SYSTEMD_DAEMON_ARGS_UPSMON@ SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER = @SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSD = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSD@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON@ SYSTEMD_DAEMON_TYPE_DRIVER = @SYSTEMD_DAEMON_TYPE_DRIVER@ SYSTEMD_DAEMON_TYPE_UPSD = @SYSTEMD_DAEMON_TYPE_UPSD@ SYSTEMD_DAEMON_TYPE_UPSLOG = @SYSTEMD_DAEMON_TYPE_UPSLOG@ SYSTEMD_DAEMON_TYPE_UPSMON = @SYSTEMD_DAEMON_TYPE_UPSMON@ SYSTEMD_DAEMON_WATCHDOG_DRIVER = @SYSTEMD_DAEMON_WATCHDOG_DRIVER@ SYSTEMD_DAEMON_WATCHDOG_UPSD = @SYSTEMD_DAEMON_WATCHDOG_UPSD@ SYSTEMD_DAEMON_WATCHDOG_UPSLOG = @SYSTEMD_DAEMON_WATCHDOG_UPSLOG@ SYSTEMD_DAEMON_WATCHDOG_UPSMON = @SYSTEMD_DAEMON_WATCHDOG_UPSMON@ SYSTEMD_SYSTEMCTL_PROGRAM = @SYSTEMD_SYSTEMCTL_PROGRAM@ SYSTEMD_TMPFILES_PROGRAM = @SYSTEMD_TMPFILES_PROGRAM@ TREE_VERSION = @TREE_VERSION@ VALGRIND = @VALGRIND@ VERSION = @VERSION@ WINDMC = @WINDMC@ WINDRES = @WINDRES@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ XMLLINT = @XMLLINT@ XSLTPROC = @XSLTPROC@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ ac_ct_LD = @ac_ct_LD@ ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ auglensdir = @auglensdir@ auglenstestsdir = @auglenstestsdir@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ cgiexecdir = @cgiexecdir@ datadir = @datadir@ datarootdir = @datarootdir@ devddir = @devddir@ docdir = @docdir@ driverexecdir = @driverexecdir@ dummy_PKG_CONFIG = @dummy_PKG_CONFIG@ dummy_PKG_CONFIG_CFLAGS = @dummy_PKG_CONFIG_CFLAGS@ dummy_PKG_CONFIG_LIBS = @dummy_PKG_CONFIG_LIBS@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ freebsdquirksdir = @freebsdquirksdir@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ hotplugdir = @hotplugdir@ htmldir = @htmldir@ htmldocdir = @htmldocdir@ htmlmandir = @htmlmandir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ now = @now@ nut_with_nut_monitor = @nut_with_nut_monitor@ nut_with_nut_monitor_desktop = @nut_with_nut_monitor_desktop@ nut_with_nut_monitor_dir = @nut_with_nut_monitor_dir@ nut_with_nut_monitor_py2gtk2 = @nut_with_nut_monitor_py2gtk2@ nut_with_nut_monitor_py3qt5 = @nut_with_nut_monitor_py3qt5@ nut_with_nut_monitor_py3qt6 = @nut_with_nut_monitor_py3qt6@ nut_with_pynut = @nut_with_pynut@ nut_with_pynut_py = @nut_with_pynut_py@ nut_with_pynut_py2 = @nut_with_pynut_py2@ nut_with_pynut_py3 = @nut_with_pynut_py3@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ systemdshutdowndir = @systemdshutdowndir@ systemdsystempresetdir = @systemdsystempresetdir@ systemdsystemunitdir = @systemdsystemunitdir@ systemdtmpfilesdir = @systemdtmpfilesdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ udevdir = @udevdir@ SUBDIRS = html dist_data_DATA = cmdvartab nodist_data_DATA = driver.list EXTRA_DIST = evolution500.seq epdu-managed.dev MAINTAINERCLEANFILES = Makefile.in .dirstamp CLEANFILES = *.pdf *.html *-spellchecked *.tabbed all: all-recursive .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu data/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu data/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): driver.list: $(top_builddir)/config.status $(srcdir)/driver.list.in cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-dist_dataDATA: $(dist_data_DATA) @$(NORMAL_INSTALL) @list='$(dist_data_DATA)'; test -n "$(datadir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(datadir)'"; \ $(MKDIR_P) "$(DESTDIR)$(datadir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(datadir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(datadir)" || exit $$?; \ done uninstall-dist_dataDATA: @$(NORMAL_UNINSTALL) @list='$(dist_data_DATA)'; test -n "$(datadir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(datadir)'; $(am__uninstall_files_from_dir) install-nodist_dataDATA: $(nodist_data_DATA) @$(NORMAL_INSTALL) @list='$(nodist_data_DATA)'; test -n "$(datadir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(datadir)'"; \ $(MKDIR_P) "$(DESTDIR)$(datadir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(datadir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(datadir)" || exit $$?; \ done uninstall-nodist_dataDATA: @$(NORMAL_UNINSTALL) @list='$(nodist_data_DATA)'; test -n "$(datadir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(datadir)'; $(am__uninstall_files_from_dir) # This directory's subdirectories are mostly independent; you can cd # into them and run 'make' without going through this Makefile. # To change the values of 'make' variables: instead of editing Makefiles, # (1) if the variable is set in 'config.status', edit 'config.status' # (which will cause the Makefiles to be regenerated when you run 'make'); # (2) otherwise, pass the desired values on the 'make' command line. $(am__recursive_targets): @fail=; \ if $(am__make_keepgoing); then \ failcom='fail=yes'; \ else \ failcom='exit 1'; \ fi; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ case "$@" in \ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ *) list='$(SUBDIRS)' ;; \ esac; \ for subdir in $$list; do \ echo "Making $$target in $$subdir"; \ if test "$$subdir" = "."; then \ dot_seen=yes; \ local_target="$$target-am"; \ else \ local_target="$$target"; \ fi; \ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ || eval $$failcom; \ done; \ if test "$$dot_seen" = "no"; then \ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ fi; test -z "$$fail" ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-recursive TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ include_option=--etags-include; \ empty_fix=.; \ else \ include_option=--include; \ empty_fix=; \ fi; \ list='$(SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ test ! -f $$subdir/TAGS || \ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ fi; \ done; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-recursive CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-recursive cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ $(am__make_dryrun) \ || test -d "$(distdir)/$$subdir" \ || $(MKDIR_P) "$(distdir)/$$subdir" \ || exit 1; \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ dir1=$$subdir; dir2="$(top_distdir)"; \ $(am__relativize); \ new_top_distdir=$$reldir; \ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ ($(am__cd) $$subdir && \ $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$$new_top_distdir" \ distdir="$$new_distdir" \ am__remove_distdir=: \ am__skip_length_check=: \ am__skip_mode_fix=: \ distdir) \ || exit 1; \ fi; \ done $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$(top_distdir)" distdir="$(distdir)" \ dist-hook check-am: all-am $(MAKE) $(AM_MAKEFLAGS) check-local check: check-recursive all-am: Makefile $(DATA) installdirs: installdirs-recursive installdirs-am: for dir in "$(DESTDIR)$(datadir)" "$(DESTDIR)$(datadir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-recursive install-exec: install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-recursive install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) clean: clean-recursive clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-recursive -rm -f Makefile distclean-am: clean-am distclean-generic distclean-tags dvi: dvi-recursive dvi-am: html: html-recursive html-am: info: info-recursive info-am: install-data-am: install-dist_dataDATA install-nodist_dataDATA install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: install-html: install-html-recursive install-html-am: install-info: install-info-recursive install-info-am: install-man: install-pdf: install-pdf-recursive install-pdf-am: install-ps: install-ps-recursive install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-recursive -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-recursive pdf-am: ps: ps-recursive ps-am: uninstall-am: uninstall-dist_dataDATA uninstall-nodist_dataDATA .MAKE: $(am__recursive_targets) check-am install-am install-strip .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ check-am check-local clean clean-generic clean-libtool \ cscopelist-am ctags ctags-am dist-hook distclean \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dist_dataDATA install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am install-man \ install-nodist_dataDATA install-pdf install-pdf-am install-ps \ install-ps-am install-strip installcheck installcheck-am \ installdirs installdirs-am maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am uninstall-dist_dataDATA uninstall-nodist_dataDATA .PRECIOUS: Makefile dist-hook: @$(distdir)/../tools/driver-list-format.sh check-local: @abs_top_builddir='$(abs_top_builddir)' abs_top_srcdir='$(abs_top_srcdir)' $(top_srcdir)/tools/driver-list-format.sh --check # NOTE: Due to portability, we do not use a GNU percent-wildcard extension. # We also have to export some variables that may be tainted by relative # paths when parsing the other makefile (e.g. MKDIR_P that may be defined # via expanded $(top_builddir)/install-sh): #%-spellchecked: % Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) # +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ cmdvartab-spellchecked: cmdvartab Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ spellcheck spellcheck-interactive spellcheck-sortdict: +$(MAKE) -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC="cmdvartab" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: nut-2.8.4/data/cmdvartab0000644000175000017500000004442015044656702012070 00000000000000# Network UPS Tools: variable and command descriptions # # This file is optional. You may delete it to save resources, but # clients will receive "Unavailable" for any description requests. # # *** NOTE *** : When updating this file, also update docs/nut-names.txt VARDESC ups.alarm "UPS alarms" VARDESC ups.status "UPS status" VARDESC ups.time "Internal UPS clock time" VARDESC ups.date "Internal UPS clock date" VARDESC ups.efficiency "Efficiency of the UPS" VARDESC ups.model "UPS model" VARDESC ups.mfr "UPS manufacturer" VARDESC ups.mfr.date "UPS manufacturing date" VARDESC ups.serial "UPS serial number" VARDESC ups.vendorid "Vendor ID for USB devices" VARDESC ups.productid "Product ID for USB devices" VARDESC ups.firmware "UPS firmware" VARDESC ups.firmware.aux "Auxiliary device firmware" VARDESC ups.temperature "UPS temperature (degrees C)" VARDESC ups.load "Load on UPS (percent of full)" VARDESC ups.load.energysave "Load on UPS that triggers energysave (percent)" VARDESC ups.load.high "Load when UPS switches to overload condition (percent)" VARDESC ups.id "UPS system identifier" VARDESC ups.delay.start "Interval to wait before (re)starting the load (seconds)" VARDESC ups.delay.reboot "Interval to wait before rebooting the UPS (seconds)" VARDESC ups.delay.shutdown "Interval to wait after shutdown with delay command (seconds)" VARDESC ups.timer.start "Time before the load will be started (seconds)" VARDESC ups.timer.reboot "Time before the load will be rebooted (seconds)" VARDESC ups.timer.shutdown "Time before the load will be shutdown (seconds)" VARDESC ups.test.interval "Interval between self tests (seconds)" VARDESC ups.test.result "Results of last self test" VARDESC ups.display.language "Language to use on front panel" VARDESC ups.contacts "UPS external contact sensors" VARDESC ups.power "Current value of apparent power (VA)" VARDESC ups.power.nominal "UPS power rating (VA)" VARDESC ups.realpower "Current value of real power (W)" VARDESC ups.realpower.nominal "UPS real power rating (W)" VARDESC ups.beeper.status "UPS beeper status" VARDESC ups.type "UPS type" VARDESC ups.start.auto "UPS starts when mains is (re)applied" VARDESC ups.start.battery "Allow to start UPS from battery" VARDESC ups.start.reboot "UPS reboots when power returns during shutdown delay" VARDESC ups.shutdown "Enable or disable UPS shutdown ability (poweroff)" VARDESC input.voltage "Input voltage (V)" VARDESC input.voltage.extended "Extended input voltage range" VARDESC input.voltage.maximum "Maximum incoming voltage seen (V)" VARDESC input.voltage.minimum "Minimum incoming voltage seen (V)" VARDESC input.voltage.status "Voltage status relative to the thresholds" VARDESC input.voltage.low.warning "Input voltage low warning threshold (V)" VARDESC input.voltage.low.critical "Input voltage low critical threshold (V)" VARDESC input.voltage.high.warning "Input voltage high warning threshold (V)" VARDESC input.voltage.high.critical "Input voltage high critical threshold (V)" VARDESC input.voltage.nominal "Nominal input voltage (V)" VARDESC input.transfer.reason "Reason for last transfer to battery" VARDESC input.transfer.low "Low voltage transfer point (V)" VARDESC input.transfer.high "High voltage transfer point (V)" VARDESC input.transfer.eco.low "Low voltage ECO transfer point (V)" VARDESC input.transfer.bypass.low "Low voltage Bypass transfer point (V)" VARDESC input.transfer.eco.high "High voltage ECO transfer point (V)" VARDESC input.transfer.bypass.high "High voltage Bypass transfer point (V)" VARDESC input.transfer.frequency.bypass.range "Frequency range Bypass transfer point (percent of nominal Hz)" VARDESC input.transfer.frequency.eco.range "Frequency range ECO transfer point (percent of nominal Hz)" VARDESC input.transfer.hysteresis "Threshold of switching protection modes, voltage transfer point (V)" VARDESC input.transfer.low.min "smallest settable low voltage transfer point (V)" VARDESC input.transfer.low.max "greatest settable low voltage transfer point (V)" VARDESC input.transfer.high.min "smallest settable high voltage transfer point (V)" VARDESC input.transfer.high.max "greatest settable high voltage transfer point (V)" VARDESC input.eco.switchable "Input High Efficiency (aka ECO) mode switch" VARDESC input.transfer.bypass.forced "Rule for allow auto Bypass switch (on/off) transfer modes (enabled or disabled)" VARDESC input.transfer.bypass.overload "Rule for auto transfer on Bypass when overload (enabled or disabled)" VARDESC input.transfer.bypass.outlimits "Rule for auto transfer on Bypass when out of tolerance (enabled or disabled)" VARDESC input.bypass.switchable "Input auto transfer on Bypass when overload or out of tolerance (enabled or disabled)" VARDESC input.bypass.switch.on "Put the UPS in Bypass mode" VARDESC input.bypass.switch.off "Take the UPS out of Bypass mode" VARDESC input.bypass.voltage "Input bypass voltage (V)" VARDESC input.bypass.frequency "Input bypass frequency (Hz)" VARDESC input.sensitivity "Input power sensitivity" VARDESC input.quality "Input power quality" VARDESC input.current "Input current (A)" VARDESC input.current.nominal "Nominal input current (A)" VARDESC input.current.status "Current status relative to the thresholds" VARDESC input.current.low.warning "Input current low warning threshold (A)" VARDESC input.current.low.critical "Input current low critical threshold (A)" VARDESC input.current.high.warning "Input current high warning threshold (A)" VARDESC input.current.high.critical "Input current high critical threshold (A)" VARDESC input.frequency "Input line frequency (Hz)" VARDESC input.frequency.extended "Extended input frequency range" VARDESC input.frequency.status "Frequency status" VARDESC input.frequency.nominal "Nominal input line frequency (Hz)" VARDESC input.frequency.low "Minimum input line frequency (Hz)" VARDESC input.frequency.high "Maximum input line frequency (Hz)" VARDESC input.transfer.boost.low "Low voltage boosting transfer point (V)" VARDESC input.transfer.boost.high "High voltage boosting transfer point (V)" VARDESC input.transfer.trim.low "Low voltage trimming transfer point (V)" VARDESC input.transfer.trim.high "High voltage trimming transfer point (V)" VARDESC input.transfer.delay "Delay before transfer to mains" VARDESC input.load "Load on (ePDU) input (percent of full)" VARDESC input.realpower "Current sum value of all (ePDU) phases real power (W)" VARDESC input.power "Current sum value of all (ePDU) phases apparent power (VA)" VARDESC input.source "The current input power source" VARDESC input.source.preferred "The preferred input power source" VARDESC output.voltage "Output voltage (V)" VARDESC output.voltage.nominal "Nominal output voltage (V)" VARDESC output.frequency "Output frequency (Hz)" VARDESC output.frequency.nominal "Nominal output frequency (Hz)" VARDESC output.current "Output current (A)" VARDESC output.current.nominal "Nominal output current (A)" VARDESC battery.charge "Battery charge (percent of full)" VARDESC battery.charge.approx "Rough approximation of battery charge" VARDESC battery.charge.low "Remaining battery level when UPS switches to LB (percent)" VARDESC battery.charge.restart "Minimum battery level for restart after power off (percent)" VARDESC battery.charge.warning "Battery level when UPS switches to Warning state (percent)" VARDESC battery.voltage "Battery voltage (V)" VARDESC battery.current "Battery current (A)" VARDESC battery.capacity "Battery capacity (Ah)" VARDESC battery.temperature "Battery temperature (degrees C)" VARDESC battery.voltage.nominal "Nominal battery voltage (V)" VARDESC battery.runtime "Battery runtime (seconds)" VARDESC battery.runtime.low "Remaining battery runtime when UPS switches to LB (seconds)" VARDESC battery.alarm.threshold "Battery alarm threshold" VARDESC battery.date "Battery change date" VARDESC battery.mfr.date "Battery manufacturing date" VARDESC battery.packs "Number of battery packs" VARDESC battery.packs.bad "Number of bad battery packs" VARDESC battery.type "Battery chemistry" VARDESC battery.protection "Prevent deep discharge of battery" VARDESC battery.energysave "Switch off when running on battery and no/low load" VARDESC battery.energysave.load "Switch off UPS if on battery and load level lower (percent)" VARDESC battery.energysave.delay "Delay before switch off UPS if on battery and load level low (min)" VARDESC battery.energysave.realpower "Switch off UPS if on battery and load level lower (Watts)" VARDESC battery.charger.status "Battery charger status" VARDESC battery.charger.type "Type of battery charger" VARDESC ambient.temperature "Ambient temperature (degrees C)" VARDESC ambient.temperature.alarm "Ambient temperature alarm is active" VARDESC ambient.temperature.status "Ambient temperature status relative to the configured thresholds" VARDESC ambient.temperature.alarm.maximum "Maximum allowed ambient temperature (degrees C)" VARDESC ambient.temperature.alarm.minimum "Minimum allowed ambient temperature (degrees C)" VARDESC ambient.temperature.alarm.enable "Enable ambient temperature alarm" VARDESC ambient.temperature.low "Temperature threshold low (degrees C)" VARDESC ambient.temperature.low.warning "Temperature threshold low warning (degrees C)" VARDESC ambient.temperature.low.critical "Temperature threshold low critical (degrees C)" VARDESC ambient.temperature.high "Temperature threshold high (degrees C)" VARDESC ambient.temperature.high.warning "Temperature threshold high warning (degrees C)" VARDESC ambient.temperature.high.critical "Temperature threshold high critical (degrees C)" VARDESC ambient.humidity "Ambient humidity (percent)" VARDESC ambient.humidity.alarm "Ambient humidity alarm is active" VARDESC ambient.humidity.status "Ambient humidity status relative to the configured thresholds" VARDESC ambient.humidity.alarm.maximum "Maximum allowed ambient humidity (percent)" VARDESC ambient.humidity.alarm.minimum "Minimum allowed ambient humidity (percent)" VARDESC ambient.humidity.alarm.enable "Enable ambient humidity alarm" VARDESC ambient.humidity.low "Ambient humidity threshold low (percent)" VARDESC ambient.humidity.low.warning "Ambient humidity threshold low warning (percent)" VARDESC ambient.humidity.low.critical "Ambient humidity threshold low critical (percent)" VARDESC ambient.humidity.high "Ambient humidity threshold high (percent)" VARDESC ambient.humidity.high.warning "Ambient humidity threshold high warning (percent)" VARDESC ambient.humidity.high.critical "Ambient humidity threshold high critical (percent)" VARDESC ambient.present "Ambient sensor presence" VARDESC ambient.contacts.1.status "State of the dry contact sensor 1" VARDESC ambient.contacts.2.status "State of the dry contact sensor 2" # FIXME: the outlet collection is indexed - solve with regexps? # # VARDESC outlet.[[:digit:]]+.id "Outlet system identifier ()" VARDESC outlet.id "Outlet system identifier" VARDESC outlet.desc "Outlet description" VARDESC outlet.switch "Outlet switch control" VARDESC outlet.status "Outlet switch status" VARDESC outlet.protect.status "Outlet protection status" VARDESC outlet.switchable "Outlet switch ability" VARDESC outlet.autoswitch.charge.low "Remaining battery level to power off this outlet (percent)" VARDESC outlet.delay.shutdown "Interval to wait before shutting down this outlet (seconds)" VARDESC outlet.delay.start "Interval to wait before restarting this outlet (seconds)" VARDESC outlet.1.id "Outlet system identifier" VARDESC outlet.1.desc "Outlet description" VARDESC outlet.1.switch "Outlet switch control" VARDESC outlet.1.status "Outlet switch status" VARDESC outlet.1.protect.status "Outlet protection status" VARDESC outlet.1.switchable "Outlet switch ability" VARDESC outlet.1.ecocontrol "Master Outlet used to automatically power off the slave outlets" VARDESC outlet.1.autoswitch.charge.low "Remaining battery level to power off this outlet (percent)" VARDESC outlet.1.delay.shutdown "Interval to wait before shutting down this outlet (seconds)" VARDESC outlet.1.delay.start "Interval to wait before restarting this outlet (seconds)" VARDESC outlet.1.designator "Outlet designator" VARDESC outlet.2.id "Outlet system identifier" VARDESC outlet.2.desc "Outlet description" VARDESC outlet.2.switch "Outlet switch control" VARDESC outlet.2.status "Outlet switch status" VARDESC outlet.2.protect.status "Outlet protection status" VARDESC outlet.2.switchable "Outlet switch ability" VARDESC outlet.2.ecocontrol "Master Outlet used to automatically power off the slave outlets" VARDESC outlet.2.autoswitch.charge.low "Remaining battery level to power off this outlet (percent)" VARDESC outlet.2.delay.shutdown "Interval to wait before shutting down this outlet (seconds)" VARDESC outlet.2.delay.start "Interval to wait before restarting this outlet (seconds)" VARDESC device.part "Device part number" VARDESC device.mfr "Device manufacturer" VARDESC device.model "Device model" VARDESC device.serial "Device serial number" VARDESC device.type "Device type" VARDESC device.description "Device description" VARDESC device.contact "Device administrator name" VARDESC device.location "Device physical location" VARDESC device.macaddr "Physical network address of the device" VARDESC device.uptime "Device uptime in seconds" VARDESC device.count "Total number of daisychained devices" VARDESC device.usb.version "Device USB version" VARDESC server.info "Server information" VARDESC server.version "Server version" VARDESC driver.name "Driver name" VARDESC driver.debug "Current debug verbosity level of the driver program" # Note: normally a `drivername -k` call is used during shutdowns, # and at that time the daemon instance of the driver must be stopped: VARDESC driver.flag.allow_killpower "Safety flip-switch to allow the driver daemon to send UPS shutdown command (accessible via driver.killpower)" VARDESC driver.version "Driver version - NUT release" VARDESC driver.version.internal "Internal driver version" VARDESC driver.version.usb "USB library version" VARDESC driver.version.data "Version of the internal data mapping, for generic drivers" VARDESC driver.state "Current state in driver's lifecycle" # FIXME: driver.parameter and driver.flag can have many possible members # # VARDESC driver.parameter.[[:alpha:]]+ "Driver parameter: " # VARDESC driver.flag.[[:alpha:]]+ "Driver flag: " CMDDESC driver.exit "Tell the driver daemon to just exit its program (so the caller or service management framework can restart it with new options)" CMDDESC driver.killpower "Tell the driver daemon to initiate UPS shutdown; should be unlocked with driver.flag.allow_killpower option or variable setting" CMDDESC driver.reload "Reload running driver configuration from the file system (only works for changes in some options)" CMDDESC driver.reload-or-error "Reload running driver configuration from the file system (only works for changes in some options); return an error if something changed and could not be applied live (so the caller can restart it with new options)" CMDDESC driver.reload-or-exit "Reload running driver configuration from the file system (only works for changes in some options); exit the running driver if something changed and could not be applied live (so service management framework can restart it with new options)" CMDDESC load.off "Turn off the load immediately" CMDDESC load.on "Turn on the load immediately" CMDDESC shutdown.default "Run the driver-defined UPS shutdown sequence (as opposed to user-configured 'sdcommands')" CMDDESC shutdown.return "Turn off the load and return when power is back" CMDDESC shutdown.stayoff "Turn off the load and remain off" CMDDESC shutdown.stop "Stop a shutdown in progress" CMDDESC shutdown.reboot "Shut down the load briefly while rebooting the UPS" CMDDESC shutdown.reboot.graceful "Delay briefly then shut down the load while rebooting the UPS" CMDDESC test.panel.start "Start testing the UPS panel" CMDDESC test.panel.stop "Stop a UPS panel test" CMDDESC test.failure.start "Start a simulated power failure" CMDDESC test.failure.stop "Stop simulating a power failure" CMDDESC test.battery.start "Start a battery test" CMDDESC test.battery.start.quick "Start a quick battery test" CMDDESC test.battery.start.deep "Start a deep battery test" CMDDESC test.battery.stop "Stop the battery test" CMDDESC test.system.start "Start a system test" CMDDESC calibrate.start "Start run time calibration" CMDDESC calibrate.stop "Stop run time calibration" CMDDESC bypass.start "Put the UPS in Bypass mode" CMDDESC bypass.stop "Take the UPS out of Bypass mode" CMDDESC experimental.ecomode.start "Put UPS in High Efficiency (aka ECO) mode" CMDDESC experimental.ecomode.stop "Take the UPS out of High Efficiency (aka ECO) mode" CMDDESC experimental.bypass.ecomode.start "Put UPS in Bypass mode then High Efficiency (aka ECO) mode" CMDDESC experimental.bypass.ecomode.stop "Take the UPS out of High Efficiency (aka ECO) mode after exiting Bypass mode" CMDDESC experimental.essmode.start "Put UPS in Energy Saver System (aka ESS) mode" CMDDESC experimental.essmode.stop "Take the UPS out of Energy Saver System (aka ESS) mode" CMDDESC experimental.test.beeper.start "Start testing the UPS beeper" CMDDESC experimental.test.beeper.stop "Stop a UPS beeper test" CMDDESC reset.input.minmax "Reset minimum and maximum input voltage status" CMDDESC reset.watchdog "Reset watchdog timer" CMDDESC beeper.on "Obsolete (use beeper.enable)" CMDDESC beeper.off "Obsolete (use beeper.disable or beeper.mute)" CMDDESC beeper.enable "Enable the UPS beeper" CMDDESC beeper.disable "Disable the UPS beeper" CMDDESC beeper.mute "Temporarily mute the UPS beeper" CMDDESC beeper.toggle "Toggle the UPS beeper" CMDDESC outlet.1.load.off "Turn off the load on outlet 1 immediately" CMDDESC outlet.1.load.on "Turn on the load on outlet 1 immediately" CMDDESC outlet.1.shutdown.return "Turn off the outlet 1 and return when power is back" CMDDESC outlet.2.load.off "Turn off the load on outlet 2 immediately" CMDDESC outlet.2.load.on "Turn on the load on outlet 2 immediately" CMDDESC outlet.2.shutdown.return "Turn off the outlet 2 and return when power is back" # The following two commands should *only* be defined when you need # to compose a 'shutdown.return' command by sending both a switch-off # with delay and a switch-on with delay command to the UPS. If this # can be done with a single command, use 'shutdown.return' instead. # Note that the switch-on with delay command *must not* turn on the # load if the UPS is on battery. # CMDDESC load.off.delay "Turn off the load with a delay (seconds)" CMDDESC load.on.delay "Turn on the load with a delay (seconds)" nut-2.8.4/data/Makefile.am0000644000175000017500000000337615044656702012243 00000000000000# Network UPS Tools: data SUBDIRS = html dist_data_DATA = cmdvartab nodist_data_DATA = driver.list EXTRA_DIST = evolution500.seq epdu-managed.dev dist-hook: @$(distdir)/../tools/driver-list-format.sh check-local: @abs_top_builddir='$(abs_top_builddir)' abs_top_srcdir='$(abs_top_srcdir)' $(top_srcdir)/tools/driver-list-format.sh --check # NOTE: Due to portability, we do not use a GNU percent-wildcard extension. # We also have to export some variables that may be tainted by relative # paths when parsing the other makefile (e.g. MKDIR_P that may be defined # via expanded $(top_builddir)/install-sh): #%-spellchecked: % Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) # +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ cmdvartab-spellchecked: cmdvartab Makefile.am $(top_srcdir)/docs/Makefile.am $(abs_srcdir)/$(NUT_SPELL_DICT) +$(MAKE) -s -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC_ONE="$<" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ spellcheck spellcheck-interactive spellcheck-sortdict: +$(MAKE) -f $(top_builddir)/docs/Makefile $(AM_MAKEFLAGS) MKDIR_P="$(MKDIR_P)" builddir="$(builddir)" srcdir="$(srcdir)" top_builddir="$(top_builddir)" top_srcdir="$(top_srcdir)" SPELLCHECK_SRC="cmdvartab" SPELLCHECK_SRCDIR="$(srcdir)" SPELLCHECK_BUILDDIR="$(builddir)" $@ MAINTAINERCLEANFILES = Makefile.in .dirstamp CLEANFILES = *.pdf *.html *-spellchecked *.tabbed nut-2.8.4/data/epdu-managed.dev0000644000175000017500000000317214670526611013227 00000000000000# dummy-ups example device definition file # # Generated using: # $ upsc ups@host > epdu-managed.dev device.mfr: EATON | Powerware device.model: DBQ10634/5 device.serial: ADO6750531 device.type: pdu driver.name: snmp-ups driver.parameter.pollinterval: 2 driver.parameter.port: somewhere.org driver.version: 2.3.0-1540MS driver.version.internal: 0.44 (mib: aphel_revelation 0.2) outlet.1.current: 0.00 outlet.1.current.maximum: 0.00 outlet.1.desc: Outlet 1 outlet.1.id: 1 outlet.1.power: 0.00 outlet.1.powerfactor: 0.05 outlet.1.realpower: 0.00 outlet.1.status: on outlet.1.switchable: 0.00 outlet.1.voltage: 247.00 outlet.2.current: 0.00 outlet.2.current.maximum: 0.16 outlet.2.desc: Outlet 2 outlet.2.id: 2 outlet.2.power: 0.00 outlet.2.powerfactor: 0.01 outlet.2.realpower: 0.00 outlet.2.status: on outlet.2.switchable: 1.00 outlet.2.voltage: 247.00 outlet.3.current: 0.00 outlet.3.current.maximum: 0.16 outlet.3.desc: Outlet 3 outlet.3.id: 3 outlet.3.power: 0.00 outlet.3.powerfactor: 0.13 outlet.3.realpower: 0.00 outlet.3.status: on outlet.3.switchable: 2.00 outlet.3.voltage: 247.00 outlet.4.current: 0.19 outlet.4.current.maximum: 0.56 outlet.4.desc: Outlet 4 outlet.4.id: 2 outlet.4.power: 46.00 outlet.4.powerfactor: 0.60 outlet.4.realpower: 28.00 outlet.4.status: on outlet.4.switchable: 3.00 outlet.4.voltage: 247.00 outlet.count: 4.00 outlet.current: 0.19 outlet.desc: All outlets outlet.id: 0 outlet.power: 46.00 outlet.realpower: 28.00 outlet.voltage: 247.00 ups.firmware: 01.01.00 ups.id: my_device234 ups.macaddr: ups.mfr: EATON | Powerware ups.model: DBQ10634/5 ups.serial: ADO6750531 ups.status: ups.temperature: 49.00 device.type: pdu nut-2.8.4/data/driver.list.in0000644000175000017500000034662215044656702013010 00000000000000# Network UPS Tools - @PACKAGE_VERSION@ - Hardware Compatibility List # version=2 # # This file is used for various purposes, like building the HTML compatibility # list or displaying information in NUT configuration tools. # # If you write a new driver, modify an existing one to add more support, # or just know about some equipment that isn't listed but should be, # please send us a patch to update this file. # # Format: # ======= # # # Details: # ======== # - device type: # "ups" for Uninterruptible Power Supply # "pdu" for Power Distribution Unit # "scd" for Solar Controller Device # "ats" for Automatic Transfer Switch # # - support level: a number from "1" to "5" (stars) meaning: # * protocol based on reverse engineering # ** based on fragments of publicly available protocol # *** based on publicly available protocol # **** vendor provided protocol # ***** vendor provided protocol and hardware # # - driver [parameters]: mention the driver(s) (separated by "or" if there are # several possibilities). Any mandatory parameter(s) must be referenced, as # they will be parsed by configuration helper software. # For example, genericups entries must mention the "upstype=nn" format. # # Duplicate text in the last field will be cooked out during the conversion # to HTML with ROWSPAN magic. They must be an exact match for this to work. # # The entry may be followed by comments. Be sure to not use double-quotes there! # # Fields must be double-quoted (except for optional trailing comment) and # separated by a single TAB character. An empty field value is thus just # two double-quotes surreounded by TABs. "2E" "ups" "2" "PS1000L" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut-ddl/issues/41 "2E" "ups" "2" "PS1000L" "serial" "nutdrv_qx" # https://github.com/networkupstools/nut-ddl/issues/41 "Ablerex" "ups" "2" "625L" "USB" "blazer_usb" "Ablerex" "ups" "2" "Hope Office 400/600" "" "blazer_ser" "Ablerex" "ups" "2" "MARS MS3000RT" "" "blazer_ser" "Ablerex" "ups" "2" "MS-RT" "" "blazer_ser" "Ablerex" "ups" "2" "MP series" "USB" "nutdrv_qx" "Ablerex" "ups" "2" "ARES Plus series" "USB" "nutdrv_qx" "Ablerex" "ups" "2" "MSII series" "USB" "nutdrv_qx" "Ablerex" "ups" "2" "MSIII series" "USB" "nutdrv_qx" "Ablerex" "ups" "2" "GRs series" "USB" "nutdrv_qx" "Ablerex" "ups" "2" "GRs Plus series" "USB" "nutdrv_qx" "Ablerex" "ups" "1" "(various)" "Serial" "nutdrv_hashx" # https://www.ablerex.eu/download/ "ActivePower" "ups" "2" "400VA" "" "blazer_ser" "ActivePower" "ups" "2" "1400VA" "" "blazer_ser" "ActivePower" "ups" "2" "2000VA" "" "blazer_ser" "Advice" "ups" "2" "TopGuard 2000" "" "blazer_ser" "Advice" "ups" "2" "Top V Pro 6-10K" "USB" "blazer_usb" # https://www.advice.co.il/en/advice-products/ups-systems/ups-online-systems/one-phase-ups-5k-10k/%D7%90%D7%9C-%D7%A4%D7%A1%D7%A7-%D7%90%D7%95%D7%9F-%D7%9C%D7%99%D7%99%D7%9F-top-v-pro-6-10k-detail https://github.com/networkupstools/nut/issues/744 "Advice" "ups" "2" "PRS850" "USB" "blazer_usb" "Advice" "ups" "2" "PRV700 Pro" "USB" "blazer_usb" "AEC" "ups" "1" "MiniGuard UPS 700" "Megatec M2501 cable" "genericups upstype=21" "AEG Power Solutions" "ups" "2" "PROTECT HOME" "" "blazer_ser or blazer_usb" "AEG Power Solutions" "ups" "3" "PROTECT NAS" "USB" "usbhid-ups" "AEG Power Solutions" "ups" "3" "PROTECT B" "USB" "usbhid-ups" "APC" "ups" "3" "APC AP9584 Serial-to-USB kit" "USB" "usbhid-ups" # Allows USB connections to Serial-port APC devices, https://github.com/networkupstools/nut/pull/181 "APC" "ups" "2" "Back-UPS 1200BR (Microsol)" "" "solis" "APC" "ups" "2" "Back-UPS BZ2200BI-BR (Microsol)" "" "solis" "APC" "ups" "1" "Back-UPS Pro" "" "apcsmart" "APC" "ups" "1" "Matrix-UPS" "" "apcsmart" "APC" "ups" "1" "Smart-UPS" "" "apcsmart" "APC" "ups" "1" "Smart-UPS SMT/SMX/SURTD" "Microlink models with RJ45 socket - they *require* AP9620 SmartSlot expansion card and smart cable" "apcsmart" "APC" "ups" "3" "Back-UPS Pro USB" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS BK650M2-CH" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/1970 "APC" "ups" "3" "Back-UPS (USB)" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS CS USB" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS RS USB" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS LS USB" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS ES/CyberFort 350" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS ES 850G2" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS BF500" "USB" "usbhid-ups" "APC" "ups" "3" "BACK-UPS XS LCD" "USB" "usbhid-ups" "APC" "ups" "3" "Back-UPS XS 1000M (Back-UPS Pro 1000, Model BX1000M)" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/139 "APC" "ups" "3" "Back-UPS BK****M2-CH Series (may need tweaks since 2023)" "USB" "usbhid-ups lbrb_log_delay_sec=N lbrb_log_delay_without_calibrating onlinedischarge_calibration" # https://github.com/networkupstools/nut/issues/3006 "APC" "ups" "3" "Back-UPS BX****MI Series (may need tweaks since 2023)" "USB" "usbhid-ups lbrb_log_delay_sec=N lbrb_log_delay_without_calibrating onlinedischarge_calibration" # https://github.com/networkupstools/nut/issues/2347 "APC" "ups" "3" "Back-UPS BVK****M2 Series (may need tweaks)" "USB" "usbhid-ups lbrb_log_delay_sec=N lbrb_log_delay_without_calibrating onlinedischarge_calibration" # https://github.com/networkupstools/nut/issues/2942 "APC" "ups" "3" "SMC2200BI-BR" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/557 "APC" "ups" "3" "Smart-UPS (USB)" "USB" "usbhid-ups" "APC" "ups" "3" "Smart-UPS 750 (SMT750I, USB)" "USB" "usbhid-ups" "APC" "ups" "3" "Smart-UPS 1500 (SMT1500I, USB)" "USB" "usbhid-ups" "APC" "ups" "3" "Smart-UPS X 750 (SMX750I, USB)" "USB" "usbhid-ups" "APC" "ups" "3" "Smart-UPS X 1500 (SMX1500I, USB)" "USB" "usbhid-ups" "APC" "ups" "3" "SMC2200BI-BR" "USB" "apc_modbus" # https://github.com/networkupstools/nut/issues/557 "APC" "ups" "3" "Smart-UPS (USB)" "USB" "apc_modbus" "APC" "ups" "3" "Smart-UPS 750 (SMT750I, USB)" "USB" "apc_modbus" "APC" "ups" "3" "Smart-UPS 1500 (SMT1500I, USB)" "USB" "apc_modbus" "APC" "ups" "3" "Smart-UPS X 750 (SMX750I, USB)" "USB" "apc_modbus" "APC" "ups" "3" "Smart-UPS X 1500 (SMX1500I, USB)" "USB" "apc_modbus" "APC" "ups" "3" "CS500" "USB" "usbhid-ups (limited data available)" # https://github.com/networkupstools/nut/issues/1776#issuecomment-1377784584 "APC" "ups" "1" "Back-UPS" "940-0095A/C cables" "genericups upstype=1" "APC" "ups" "1" "Back-UPS" "940-0020B/C cables" "genericups upstype=2" "APC" "ups" "1" "Back-UPS" "940-0023A cable" "genericups upstype=9" "APC" "ups" "1" "Back-UPS Office" "940-0119A cable" "genericups upstype=12" "APC" "ups" "1" "Back-UPS RS 500" "custom non-USB cable" "genericups upstype=20" "APC" "ups" "3" "Smart-UPS SUA 1000" "" "snmp-ups" "APC" "ups" "3" "Smart-UPS 3000" "" "snmp-ups" "APC" "ups" "3" "Smart-UPS 5000 RM (SUA5000RMI5U)" "" "snmp-ups" "APC" "ups" "3" "Smart-UPS RT XL" "AP9618 SNMP monitoring card" "snmp-ups" "APC" "ups" "3" "(various)" "AP9618 SNMP monitoring card" "snmp-ups" "APC" "ups" "3" "(various)" "AP9630 SNMP monitoring card" "snmp-ups privProtocol=AES" "APC" "ups" "3" "(various)" "APCUPSD-controlled devices" "apcupsd-ups" "APC" "pdu" "1" "Masterswitch" "940-0020 cable" "genericups upstype=12" "APC" "pdu" "1" "AP9210" "8 outlets" "powerman-pdu (experimental)" "APC" "pdu" "1" "AP79xx" "8 to 24 outlets" "powerman-pdu (experimental)" "APC" "pdu" "3" "(various APxxxx)" "SNMP monitoring card" "snmp-ups" "APC" "ats" "3" "ATS AP7724" "" "snmp-ups (experimental)" "Aphel" "pdu" "3" "various PDU" "" "snmp-ups (experimental)" "Apollo" "ups" "1" "1000A" "" "genericups upstype=4" "Apollo" "ups" "1" "1000F" "" "genericups upstype=4" "Apollo" "ups" "2" "850VA" "USB" "blazer_usb" "Appro" "pdu" "1" "SWPDU" "48 outlets" "powerman-pdu (experimental)" "ARES" "ups" "2" "AR265i" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 did not explicitly mention the driver parameters, but other reports in the discussion did "ARTronic" "ups" "2" "ARTon Millenium 1/2/3/6/10 kVA" "Serial" "blazer_ser" "ARTronic" "ups" "2" "ARTon Millenium 3.1 10/15/20 kVA" "Serial" "blazer_ser" "ARTronic" "ups" "2" "ARTon Titanium 6/10 kVA" "Serial" "blazer_ser" "ARTronic" "ups" "2" "ARTon Titanium 3.1 10/15/20 kVA" "Serial" "blazer_ser" "ARTronic" "ups" "2" "ARTon Optimum 1/2/3/6/10 kVA" "Serial" "blazer_ser" "ARTronic" "ups" "2" "ARTon Titanium Plus 1/2/3 kVA" "USB" "blazer_usb" "ARTronic" "ups" "2" "ARTon Platinium 6/10 kVA" "USB" "blazer_usb" "ARTronic" "ups" "2" "ARTon Platinium Combo 3.1 10/15/20 kVA" "USB" "blazer_usb" "ARTronic" "ups" "2" "ARTon Platinium RT 1/2/3/6/10 kVA" "USB" "blazer_usb" "Armac" "ups" "2" "R/2000I/PSW and PF1 series" "(USB ID 0925:1234)" "nutdrv_qx" "ASEM SPA" "ups" "5" "PB1300 UPS" "i2c" "asem" "Asium" "ups" "3" "P700" "USB" "blazer_usb" # http://www.asiumpower.com/Asium-ASIUM-P700-650VA-360W/dp/B009SMEQ10 "ATEK" "ups" "2" "Defensor 1K Tower / Rack" "USB" "blazer_usb" "ATEK" "ups" "2" "Defensor 2K Tower / Rack" "USB" "blazer_usb" "ATEK" "ups" "2" "Defensor 3K Tower / Rack" "USB" "blazer_usb" "ATEK" "ups" "2" "Defensor 6K Tower / Rack" "USB" "blazer_usb" "ATEK" "ups" "2" "Defensor 10K Tower / Rack" "USB" "blazer_usb" "Atlantis Land" "ups" "2" "A03-P826" "" "blazer_ser" "Atlantis Land" "ups" "2" "A03-P551" "USB" "blazer_usb langid_fix=0x0409" # http://www.atlantisland.it/pub/prodotti.php?famiglia=1&l1=7&l2=24&articolo=QTAzLVA1NTE= "Atlantis Land" "ups" "2" "HostPower 851 (A03-HP851)" "USB" "nutdrv_qx" "Atlantis Land" "ups" "2" "LinePower 1151 (A03-OP1151)" "Serial" "nutdrv_qx" "Atlantis Land" "ups" "2" "LinePower 1151 (A03-OP1151)" "USB" "nutdrv_qx" "Atlantis Land" "ups" "2" "OnePower 841+ (A03-P841)" "USB" "nutdrv_qx" "Atlantis Land" "ups" "2" "(various)" "Serial" "nutdrv_qx" "Atlantis Land" "ups" "2" "(various)" "USB" "nutdrv_qx" "Atlantis Land" "ups" "1" "A03-0P10002P-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P1002" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P1002XLN" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P1302-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P1502P" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P1502P-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P2002-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P2002P" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P2002P-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P3002P" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P3002P-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P3002XLN" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-0P6002P-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-HP1003" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-HP1503" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-HP2003" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-HP3003P" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-HP4003P" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-PDU1000-RC" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-S1000LE" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-S1000P" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-S120 (Rev.22.0)" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-S1200" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-S1501 (Rev.22.0)" "Serial" "nutdrv_hashx" "Atlantis Land" "ups" "1" "A03-S2001 (Rev.22.0)" "Serial" "nutdrv_hashx" "Aviem Systems" "ups" "2" "Aviem Power RT 1000-3000VA" "" "blazer_ser" "Aviem Systems" "ups" "2" "Aviem Pro 2000VA" "USB" "blazer_usb" # https://github.com/networkupstools/nut/issues/827 "Baytech" "pdu" "1" "RPC3" "8 outlets" "powerman-pdu (experimental)" "Baytech" "pdu" "1" "RPC3-20NC" "8 outlets" "powerman-pdu (experimental)" "Baytech" "pdu" "1" "RPC28-30NC" "20 outlets" "powerman-pdu (experimental)" "Baytech" "pdu" "3" "various RPC" "" "snmp-ups" "Belkin" "ups" "2" "Active Battery Backup BU30 series" "USB" "blazer_usb" "Belkin" "ups" "1" "Home Office F6H350-SER" "" "genericups upstype=7" "Belkin" "ups" "1" "Home Office F6H500-SER" "" "genericups upstype=7" "Belkin" "ups" "1" "Home Office F6H650-SER" "" "genericups upstype=7" "Belkin" "ups" "3" "F6H375-USB" "USB (<= 2005 models, vendor id: 050d)" "usbhid-ups" "Belkin" "ups" "2" "F6H375-USB" "USB (2007 models, vendor id: 0665)" "blazer_usb" "Belkin" "ups" "3" "Office Series F6C550-AVR" "USB" "usbhid-ups" "Belkin" "ups" "3" "Regulator PRO-USB" "USB (~2000, product id: 0f51)" "usbhid-ups" "Belkin" "ups" "2" "Regulator Pro" "F6C525-SER, F6C625-SER" "belkin" "Belkin" "ups" "1" "Resource" "" "genericups upstype=4" "Belkin" "ups" "2" "Small Enterprise F6C1500-TW-RK" "serial port" "belkin" "Belkin" "ups" "3" "Small Enterprise F6C1500-TW-RK" "USB" "usbhid-ups" "Belkin" "ups" "3" "Universal UPS F6C100-UNV" "USB" "usbhid-ups" "Belkin" "ups" "1" "Universal UPS F6C120-UNV" "serial port" "belkinunv" "Belkin" "ups" "3" "Universal UPS F6C120-UNV" "USB" "usbhid-ups" "Belkin" "ups" "1" "Universal UPS F6C800-UNV" "serial port" "belkinunv" "Belkin" "ups" "3" "Universal UPS F6C800-UNV" "USB" "usbhid-ups" "Belkin" "ups" "1" "Universal UPS F6C1100-UNV" "serial port (<= 2005 models)" "belkinunv" "Belkin" "ups" "3" "Universal UPS F6C1100-UNV" "USB (<= 2005 models, vendor id: 050d)" "usbhid-ups" "Belkin" "ups" "2" "Universal UPS F6C1100-UNV" "USB (2007 models, vendor id: 0665)" "blazer_usb" "Belkin" "ups" "3" "Universal UPS F6C1200-UNV" "USB (<= 2005 models, vendor id: 050d)" "usbhid-ups" "Belkin" "ups" "2" "Universal UPS F6C1200-UNV" "USB (2007 models, vendor id: 0665)" "blazer_usb" "Belkin" "ups" "2" "Universal UPS F6H350deUNV" "serial port" "blazer_ser" "Belkin" "ups" "2" "Universal UPS F6H350ukUNV" "serial port" "blazer_ser" "Belkin" "ups" "2" "Universal UPS F6H500ukUNV" "serial port" "blazer_ser" "Belkin" "ups" "2" "Universal UPS F6H650ukUNV" "serial port" "blazer_ser" "Belkin" "ups" "2" "F6S600auUSB" "USB" "blazer_usb" "Best Power" "ups" "1" "Fortress (older)" "" "bestfortress" "Best Power" "ups" "1" "Fortress (newer)" "" "blazer_ser or bestups" "Best Power" "ups" "1" "Fortress Telecom" "" "blazer_ser or bestups" "Best Power" "ups" "1" "Axxium Rackmount" "" "blazer_ser or bestups" "Best Power" "ups" "1" "Patriot Pro" "" "blazer_ser or bestups" "Best Power" "ups" "1" "Patriot Pro II" "" "blazer_ser or bestups" "Best Power" "ups" "1" "Patriot" "INT51 cable" "genericups upstype=6" "Best Power" "ups" "1" "Micro-Ferrups" "" "bestuferrups" "Best Power" "ups" "1" "Fortress/Ferrups" "f-command support" "bestfcom" "Bicker" "ups" "3" "UPSIC-1205" "" "bicker_ser" "Bicker" "ups" "3" "UPSIC-2403" "" "bicker_ser" "Bicker" "ups" "3" "DC2412-UPS" "" "bicker_ser" "Bicker" "ups" "3" "DC2412-UPS-LD" "" "bicker_ser" "Borri" "ups" "2" "B400-010-B/B400-020-B/B400-030-B/B400-010-C/B400-020-C/B400-030-C" "USB" "blazer_usb" "Borri" "ups" "2" "B400-R010-B/B400-R020-B/B400-R030-B/B400-R010-C/B400-R020-C/B400-R030-C" "USB" "blazer_usb" "Borri" "ups" "2" "B500-060-B/B500-100-B/B500-060-C/B500-100-C" "USB" "blazer_usb" "Borri" "ups" "2" "B500-R060-B/B500-R100-B" "USB" "blazer_usb" "Borri" "ups" "2" "B500EVO-100-B/B500EVO-200-B" "USB" "blazer_usb" "CABAC" "ups" "2" "UPS-1700DV2" "USB" "blazer_usb" "Chloride" "ups" "2" "Desk Power 650" "serial port" "blazer_ser" "Cito Power" "ups" "2" "CPG-SR1000" "" "blazer_ser" "Clary" "ups" "4" "ST-800" "" "gamatronic" "Compaq" "ups" "4" "T1500h" "" "upscode2 use_pre_lf" "Compaq" "ups" "4" "R3000h" "" "upscode2" "Compaq" "ups" "4" "R3000 XR" "" "bcmxcp" "Compaq" "ups" "4" "R5500 XR" "" "bcmxcp" "COVER ENERGY SA" "ups" "2" "COVER PRM 1K/2K/3K/6K/10K" "USB" "blazer_usb" "COVER ENERGY SA" "ups" "2" "COVER PRM 1K/2K/3K/6K/10K EC" "USB" "blazer_usb" "COVER ENERGY SA" "ups" "2" "COVER PRM 6K/10K PR" "USB" "blazer_usb" "CPC" "ups" "2" "RACK850VA" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 product=MEC0003 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 caveats at https://github.com/networkupstools/nut/issues/537 "Crown" "ups" "2" "CMU-SP1200IEC" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 caveats at https://github.com/networkupstools/nut/issues/1014 "Cyber Energy" "ups" "3" "Models with USB" "USB" "usbhid-ups" # https://alioth-lists.debian.net/pipermail/nut-upsdev/2024-February/007966.html https://alioth-lists.debian.net/pipermail/nut-upsdev/2024-June/008002.html "Cyber Energy" "ups" "1" "Models with Serial" "Serial" "nutdrv_hashx" # https://www.cyberenergy.com/en/Product/software "Cyber Power Systems" "ups" "1" "550SL" "" "genericups upstype=7" "Cyber Power Systems" "ups" "1" "725SL" "" "genericups upstype=7" "Cyber Power Systems" "ups" "1" "CPS1100AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS1200AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS1250AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS1500AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS1500AVR-HO" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS320AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS500AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS650AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS700AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS800AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS825VA" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS850AVR" "" "powerpanel" "Cyber Power Systems" "ups" "1" "CPS900AVR" "" "powerpanel" # http://www.cyberpowersystems.com/products/ups-systems/other-ups/CPS900AVR.html "Cyber Power Systems" "ups" "1" "PR2200" "" "powerpanel" "Cyber Power Systems" "ups" "1" "Power99" "" "genericups upstype=7" "Cyber Power Systems" "ups" "3" "AE550" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "BL1250U" "USB" "usbhid-ups" # https://www.cyberpowersystems.com/product/ups/battery-backup/bl1250u/ https://github.com/networkupstools/nut/issues/1012 "Cyber Power Systems" "ups" "3" "BR1000ELCD" "USB" "usbhid-ups" # https://www.cyberpower.com/eu/en/product/sku/BR1000ELCD https://github.com/networkupstools/nut/issues/552 "Cyber Power Systems" "ups" "3" "CP1350AVRLCD" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CP1500AVRLCD" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CP850PFCLCD" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/605 "Cyber Power Systems" "ups" "3" "CP1350PFCLCD" "USB" "usbhid-ups" # https://alioth-lists.debian.net/pipermail/nut-upsuser/2023-October/013441.html "Cyber Power Systems" "ups" "3" "CP1350EPFCLCD" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CP1500PFCLCD" "USB" "usbhid-ups" # https://www.cyberpowersystems.com/product/ups/cp1500pfclcd/ https://github.com/networkupstools/nut/issues/520 "Cyber Power Systems" "ups" "3" "CPJ500" "USB" "usbhid-ups" # https://www.cyberpower.com/jp/ja/product/sku/cpj500#downloads https://github.com/networkupstools/nut/issues/1403 "Cyber Power Systems" "ups" "3" "CP900AVR" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CPS685AVR" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CPS800AVR" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "2" "OL3000RMXL2U" "" "powerpanel" "Cyber Power Systems" "ups" "2" "PR3000E" "" "powerpanel" "Cyber Power Systems" "ups" "3" "Value 1500ELCD-RU" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "Value 400E" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "Value 600E" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "Value 800E" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "VP1200ELCD (ValueII_1200E)" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CP 1500C" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CP1000PFCLCD" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "CP1500EPFCLCD" "USB" "usbhid-ups" # http://www.cyberpower-eu.com/products/ups_systems/pfc-sinewave/cp1500epfclcd.htm "Cyber Power Systems" "ups" "3" "CP825AVR-G / LE825G" "USB" "usbhid-ups" # http://www.cyberpowersystems.com/products/ups-systems/retail-products/LE825G.html "Cyber Power Systems" "ups" "3" "EC350G" "USB" "usbhid-ups" # https://www.cyberpowersystems.com/products/ups/ecologic/ec350g "Cyber Power Systems" "ups" "3" "EC750G" "USB" "usbhid-ups" # https://www.cyberpowersystems.com/products/ups/desktop/ec750g "Cyber Power Systems" "ups" "3" "EC850LCD" "USB" "usbhid-ups" # https://www.cyberpowersystems.com/product/ups/ec850lcd/ https://github.com/networkupstools/nut/issues/622 "Cyber Power Systems" "ups" "3" "OR1500ERM1U" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/1338 "Cyber Power Systems" "ups" "3" "OR2200LCDRM2U" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "OR700LCDRM1U" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "OR500LCDRM1U" "USB" "usbhid-ups" # https://www.cyberpowersystems.com/product/ups/or500lcdrm1u/ https://github.com/networkupstools/nut/issues/578 "Cyber Power Systems" "ups" "3" "RT650EI" "USB" "usbhid-ups" # http://www.cyberpowersystems.de/produkte/backup-usv-serien/rt-serie.html https://github.com/networkupstools/nut/issues/453 "Cyber Power Systems" "ups" "3" "UT2200E" "USB" "usbhid-ups" # https://www.cyberpower.com/ww/en/product/sku/UT2200E https://github.com/networkupstools/nut/issues/556 "Cyber Power Systems" "ups" "3" "PR1500RT2U" "USB" "usbhid-ups" # https://www.cyberpowersystems.com/product/ups/new-smart-app-sinewave/pr1500rt2u/ https://github.com/networkupstools/nut/issues/1191 "Cyber Power Systems" "ups" "3" "PR6000LCDRTXL5U" "USB" "usbhid-ups" "Cyber Power Systems" "ups" "3" "PR2200LCDRT2U" "" "snmp-ups" "Cyber Power Systems" "ups" "3" "RMCARD100" "" "snmp-ups" "Cyber Power Systems" "ups" "3" "RMCARD201" "" "snmp-ups" "Cyber Power Systems" "ups" "3" "RMCARD202" "" "snmp-ups" "Cyber Power Systems" "ups" "3" "RMCARD205" "" "snmp-ups" "Cyber Power Systems" "ups" "3" "RMCARD301" "" "snmp-ups" "Cyclades" "pdu" "1" "PM8" "8 outlets" "powerman-pdu (experimental)" "Cyclades" "pdu" "1" "PM10" "10 outlets" "powerman-pdu (experimental)" "Dell" "ups" "5" "Tower 500W LV / HV" "Serial port" "mge-shut" "Dell" "ups" "5" "Rack/Tower 1000W LV / HV" "Serial port" "mge-shut" "Dell" "ups" "5" "Rack/Tower 1500W LV" "Serial port" "mge-shut" "Dell" "ups" "5" "Rack/Tower 1920W LV / HV" "Serial port" "mge-shut" "Dell" "ups" "5" "Rack/Tower 2300W LV" "Serial port" "mge-shut" "Dell" "ups" "5" "Rack/Tower 2700W LV / HV" "Serial port" "mge-shut" "Dell" "ups" "5" "Short Depth Rack 2700W Online LV / HV" "High Efficiency, Serial port" "mge-shut" "Dell" "ups" "5" "Rack 3750W High Efficiency Online HV" "Serial port" "mge-shut" "Dell" "ups" "5" "Rack 4200W High Efficiency Online HV" "Serial port" "mge-shut" "Dell" "ups" "5" "Rack 5600W HV" "Serial port" "mge-shut" "Dell" "ups" "5" "Tower 500W LV / HV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Rack/Tower 1000W LV / HV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Rack/Tower 1500W LV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Rack/Tower 1920W LV / HV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Rack/Tower 2300W LV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Rack/Tower 2700W LV / HV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Short Depth Rack 2700W Online LV / HV" "High Efficiency, USB port" "usbhid-ups" "Dell" "ups" "5" "Rack 3750W High Efficiency Online HV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Rack 4200W High Efficiency Online HV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Rack 5600W HV" "USB port" "usbhid-ups" "Dell" "ups" "5" "Various (SNMP mode)" "UPS Network Management Card" "snmp-ups" "Dell" "ups" "5" "Various (XML/HTTP mode)" "UPS Network Management Card" "netxml-ups (experimental)" "Delta" "ups" "1" "GES602N" "" "belkin" "Delta" "ups" "4" "Delta UPS Amplon R Series" "USB port" "usbhid-ups" "Deltec" "ups" "1" "PowerRite Pro II" "" "genericups upstype=15" "Deltec" "ups" "4" "PRM 450/700/1000/1500" "" "upscode2" "DEXP" "ups" "2" "MIX 850VA" "USB" "blazer_usb langid_fix=0x0409 runtimecal=240,100,720,50 default.battery.voltage.high=2.27 default.battery.voltage.low=1.72" # https://github.com/networkupstools/nut/issues/721 "DEXP" "ups" "2" "LCD EURO 1200VA" "USB" "driver=nutdrv_qx port=auto vendorid=0001 productid=0000 product=MEC0003 langid_fix=0x0409 protocol=hunnox subdriver=hunnox novendor norating noscanlangid default.battery.voltage.high=28.6 default.battery.voltage.low=21.4" # https://github.com/networkupstools/nut/pull/2839 "Digital Loggers" "pdu" "1" "LPC, EPCR2, DIN" "8 outlets" "powerman-pdu (experimental)" "DigiTECH" "ups" "2" "Computer 650VA" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 caveats at https://github.com/networkupstools/nut/issues/674 (may need longer pollinterval) "Digitus" "ups" "1" "DN-170014" "USB" "richcomm_usb" # http://www.digitus.info/en/products/professional-network/security-and-surveillance/power-supply/uninterrruptable-power-supplies/ups-uninterruptible-power-systems-dn-170014/section/prof/ "Digitus" "ups" "2" "DN-170020" "" "blazer_ser" "Digitus" "ups" "2" "DN-170040" "USB" "blazer_usb" # https://github.com/networkupstools/nut/issues/1251 "Digitus" "ups" "2" "DN-170041" "USB" "blazer_usb" # https://github.com/networkupstools/nut/issues/1251 "Digitus" "ups" "2" "DN-170040" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1251 "Digitus" "ups" "2" "DN-170041" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1251 "Digitus" "ups" "2" "DN-170076" "USB" "nutdrv_qx" # https://www.digitus.info/en/products/network-and-server-cabinets/power-supply/uninterruptible-power-supplies/dn-170076/ https://github.com/networkupstools/nut/issues/948 "Dynamix" "ups" "2" "UPS1700D" "" "blazer_ser" "Dynamix" "ups" "2" "UPS-650VA" "" "blazer_ser" "Dynamix" "ups" "2" "650VA/1000VA" "USB" "blazer_usb langid_fix=0x0409" "Dynex" "ups" "1" "975AVR" "" "genericups upstype=7" "Dynex" "ups" "3" "DX-800U" "USB" "usbhid-ups" "Eaton" "ups" "5" "3S" "USB" "usbhid-ups" "Eaton" "ups" "5" "Protection Station 500/650/800 VA" "USB" "usbhid-ups" "Eaton" "ups" "5" "Ellipse ECO 650/800/1200/1600 VA" "USB" "usbhid-ups" "Eaton" "ups" "5" "Ellipse ASR USBS 600/750/1000/1500 VA" "USB cable" "usbhid-ups" "Eaton" "ups" "5" "Ellipse MAX USBS 600/850/1100/1500 VA" "USB cable" "usbhid-ups" "Eaton" "ups" "5" "Ellipse PRO 650 VA" "USB cable" "usbhid-ups" "Eaton" "ups" "5" "Evolution 650/850/1150/1550/2000 VA" "USB port" "usbhid-ups" "Eaton" "ups" "5" "Evolution S 1250/1750/2500/3000 VA" "USB port" "usbhid-ups" "Eaton" "ups" "5" "EX 700/1000/1500 VA" "USB port" "usbhid-ups" "Eaton" "ups" "5" "EX 2200/3000/3000 XL VA" "USB port" "usbhid-ups" "Eaton" "ups" "5" "EX 1000 RT2U / 1500 RT2U" "USB port" "usbhid-ups" "Eaton" "ups" "5" "MX 5/8/10/15/20 kVA" "USB port" "usbhid-ups" "Eaton" "ups" "5" "5 PX" "USB port" "usbhid-ups" "Eaton" "ups" "5" "Nova AVR 625/1250" "USB" "usbhid-ups" "Eaton" "ups" "5" "5E650iUSB" "USB port" "usbhid-ups" "Eaton" "ups" "5" "5E1100iUSB" "USB port" "usbhid-ups" # http://powerquality.eaton.com/5E1100iUSB.aspx?CX&GUID=8D85FE66-3102-427C-8F33-B8D56BBDD4D3 "Eaton" "ups" "4" "5E2200" "USB port" "nutdrv_qx" "Eaton" "ups" "5" "5S" "USB port" "usbhid-ups" "Eaton" "ups" "5" "5SC" "USB port" "usbhid-ups" "Eaton" "ups" "5" "5P" "USB port" "usbhid-ups" "Eaton" "ups" "5" "9E" "USB port" "usbhid-ups" "Eaton" "ups" "5" "9SX" "USB port" "usbhid-ups" "Eaton" "ups" "5" "9PX" "USB port" "usbhid-ups" "Eaton" "ups" "5" "9PX Split Phase 6/8/10 kVA" "USB port" "usbhid-ups" "Eaton" "ups" "5" "Ellipse ASR USBS 600/750/1000/1500 VA" "Serial cable" "mge-shut" "Eaton" "ups" "5" "Ellipse MAX USBS 600/850/1100/1500 VA" "Serial cable" "mge-shut" "Eaton" "ups" "5" "Evolution 650/850/1150/1550/2000 VA" "Serial port" "mge-shut" "Eaton" "ups" "5" "Evolution S 1250/1750/2500/3000 VA" "Serial port" "mge-shut" "Eaton" "ups" "5" "EX 700/1000/1500 VA" "Serial port" "mge-shut" "Eaton" "ups" "5" "EX 2200/3000/3000 XL VA" "Serial port" "mge-shut" "Eaton" "ups" "5" "EX 1000 RT2U / 1500 RT2U" "Serial port" "mge-shut" "Eaton" "ups" "5" "MX 5/8/10/15/20 kVA" "Serial port" "mge-shut" "Eaton" "ups" "5" "5 PX" "Serial port" "mge-shut" "Eaton" "ups" "5" "EX RT 1:1 7/11 kVA" "" "mge-shut" "Eaton" "ups" "5" "EX RT 3:1 5/7/11 kVA" "" "mge-shut" "Eaton" "ups" "5" "5SC" "Serial port" "mge-shut" "Eaton" "ups" "5" "5P" "Serial port" "mge-shut" "Eaton" "ups" "5" "9SX" "Serial port" "mge-shut" "Eaton" "ups" "5" "9PX" "Serial port" "mge-shut" "Eaton" "ups" "5" "9PX 2000 RT" "USB port" "mge-shut" # https://github.com/networkupstools/nut/issues/540 "Eaton" "ups" "5" "9PX Split Phase 6/8/10 kVA" "Serial port" "mge-shut" "Eaton" "ups" "5" "9PX" "SNMP/Web card" "netxml-ups" "Eaton" "ups" "5" "9PX Split Phase 6/8/10 kVA" "SNMP/Web card" "netxml-ups" "Eaton" "ups" "5" "EX RT (XML/HTTP)" "NMC Transverse card (ref 66074)" "netxml-ups (experimental)" "Eaton" "ups" "5" "EX RT (SNMP)" "NMC Transverse card (ref 66074)" "snmp-ups (experimental)" "Eaton" "ups" "5" "E Series NV UPS 400-2000 VA" "USB" "blazer_usb" "Eaton" "ups" "5" "E Series DX UPS 1-20 kVA" "" "blazer_ser" # http://www.eaton.com/Eaton/ESeriesUPS/DXUPS/ "Eaton" "ups" "4" "NetUPS SE 450/700/1000/1500" "" "upscode2" "Eaton" "ups" "5" "BladeUPS (SNMP)" "ConnectUPS Web/SNMP Card" "snmp-ups (experimental)" "Eaton" "ups" "5" "various models (SNMP mode)" "Power Xpert Gateway UPS Card" "snmp-ups (experimental)" "Eaton" "ups" "5" "various models (XML/HTTP mode)" "NMC Minislot (ref 66102)" "netxml-ups (experimental)" "Eaton" "ups" "5" "various models (SNMP mode)" "NMC Minislot (ref 66102)" "snmp-ups (experimental)" "Eaton" "ups" "5" "various models (XML/HTTP mode)" "SNMP/Web Minislot card (ref 66244)" "netxml-ups (experimental)" "Eaton" "ups" "5" "various models (SNMP mode)" "SNMP/Web Minislot card (ref 66244)" "snmp-ups (experimental)" "Eaton" "ups" "5" "various models (SNMP mode)" "Eaton Gigabit Network Card (Network-M2)" "snmp-ups (experimental)" "Eaton" "ups" "5" "various models (serial mode)" "Management Card Contact (ref 66104)" "mge-shut or mge-utalk" "Eaton" "pdu" "5" "ePDU Managed" "" "snmp-ups" "Eaton" "pdu" "5" "ePDU Switched" "" "snmp-ups" "Eaton" "pdu" "5" "ePDU Monitored" "" "snmp-ups or netxml-ups" "Eaton" "ups" "5" "ePDU EMSV0001" "nLogic rebranded" "snmp-ups" "Eaton" "ups" "5" "Powerware 3105" "USB" "bcmxcp_usb" # http://powerquality.eaton.com/Products-services/Backup-Power-UPS/3105-eol.aspx "Eaton" "ups" "5" "Powerware 9125" "USB card" "bcmxcp_usb" "Eaton" "ups" "5" "Powerware 9130" "" "bcmxcp or usbhid-ups" "Eaton" "ups" "5" "Powerware 9140" "" "bcmxcp or usbhid-ups" "Eaton" "ups" "5" "Powerware 5130" "USB" "usbhid-ups" "Eaton" "ups" "5" "9395" "Serial port" "bcmxcp" "Eaton" "ups" "5" "Best Ferrups" "older ConnectUPS" "snmp-ups" "Eaton" "ups" "5" "ConnectUPS X / BD / E Slot" "Serial Pass-through mode" "bcmxcp" "Eaton" "ups" "5" "ConnectUPS X / BD / E Slot" "Network port" "snmp-ups" "Eaton" "ups" "5" "Management Card Contact" "Config 3 - Cable 66033" "genericups upstype=7" "Eaton" "ats" "5" "Eaton ATS16" "" "snmp-ups" "Eaton" "ats" "5" "Eaton ATS30" "" "snmp-ups" "Ecoflow" "ups" "3" "Delta 3 Plus" "USB" "usbhid-ups" "Ecoflow" "ups" "3" "River 3 Plus" "USB" "usbhid-ups" "Effekta" "ups" "2" "MI/MT/MH" "2502 cable" "blazer_ser" "Effekta" "ups" "2" "RM2000MH" "" "blazer_ser" "Electrys" "ups" "2" "UPS 2500" "" "nutdrv_qx or blazer_ser" "Elsist" "ups" "2" "Nemo2.0 160" "USB" "blazer_usb" # http://www.naicon.com/company/wp-content/uploads/2017/05/Manual-NEMO2.0-Ver.02-Eng.pdf https://github.com/networkupstools/nut/issues/719 "Emerson" "pdu" "3" "PM3000 metered & switched" "" "snmp-ups" "Energy Sistem" "ups" "2" "(various)" "" "blazer_ser" "Energy Technologies" "ups" "2" "DPK1/1-3" "Serial" "blazer_ser" # https://www.tensy.ru/podderzhka/dokumentatsiya/ibp-serii-dpk/ https://github.com/networkupstools/nut/issues/762 "ETA" "ups" "1" "mini+UPS" "WinNT/Upsoft cable" "genericups upstype=7" "ETA" "ups" "1" "mini+UPS PRO" "UPS Explorer cable" "etapro" "EUROCASE" "ups" "2" "EA200N 2000VA" "USB" "nutdrv_qx" # http://partis.cz/index.php?gid=2551 "EVER" "ups" "1" "NET DPC series" "Serial port" "everups" "EVER" "ups" "1" "AP Pro series" "Serial port" "everups" "EVER" "ups" "1" "625/1000" "" "safenet" "EVER" "ups" "2" "POWERLINE RT 1-3kVA series" "Serial port" "blazer_ser" "EVER" "ups" "2" "POWERLINE RT 6-10kVA series" "Serial port" "blazer_ser" "EVER" "ups" "2" "POWERLINE 11 series" "Serial port" "blazer_ser" "EVER" "ups" "2" "POWERLINE 31 series" "Serial port" "blazer_ser" "EVER" "ups" "2" "DUO II Pro series" "USB port" "blazer_usb" "EVER" "ups" "2" "POWERLINE RT 1-3kVA series" "USB port" "blazer_usb" "EVER" "ups" "2" "POWERLINE RT 6-10kVA series" "USB port" "blazer_usb" "EVER" "ups" "4" "ECO Pro AVR CDS series" "USB port" "usbhid-ups" "Exide" "ups" "1" "NetUPS SE" "" "genericups upstype=15" "Exide" "ups" "4" "NetUPS SE 450/700/1000/1500" "" "upscode2" "Fenton Technologies" "ups" "1" "PowerPal" "P-series" "safenet" "Fenton Technologies" "ups" "5" "PowerPal" "L-series" "blazer_ser" "Fenton Technologies" "ups" "5" "PowerOn" "" "blazer_ser" "Fenton Technologies" "ups" "5" "PowerPure" "" "blazer_ser" "Fairstone" "ups" "1" "L525/L625/L750" "" "safenet" "Fideltronik" "ups" "1" "Ares 700 and larger" "" "genericups upstype=6" "Fideltronik" "ups" "2" "LUPUS 500" "USB" "nutdrv_qx" "Fideltronik" "ups" "1" "Other Ares models" "" "genericups upstype=19" "Fideltronik INIGO" "ups" "2" "Viper 1200" "USB" "nutdrv_qx" # http://fideltronikinigo.com/viper/viper-1200/ "Fiskars" "ups" "4" "PowerRite MAX" "" "upscode2" "Fiskars" "ups" "4" "PowerServer 10" "" "upscode2" "Fiskars" "ups" "4" "PowerServer 30" "" "upscode2" "Fiskars" "ups" "4" "9200" "UPS Information Unit" "upscode2" "Flight Technic & International (FTUPS)" "ups" "2" "FT-1000BS" "Serial" "nutdrv_qx" "Flight Technic & International (FTUPS)" "ups" "2" "FT-1000BS" "USB" "nutdrv_qx" "Flight Technic & International (FTUPS)" "ups" "2" "FT-1000BS(T)" "Serial" "nutdrv_qx" "Flight Technic & International (FTUPS)" "ups" "2" "FT-1000BS(T)" "USB" "nutdrv_qx" "Flight Technic & International (FTUPS)" "ups" "2" "Smart On Line UPS 1KVA" "Serial" "nutdrv_qx" "Flight Technic & International (FTUPS)" "ups" "2" "Smart On Line UPS 1KVA" "USB" "nutdrv_qx" "Flight Technic & International (FTUPS)" "ups" "2" "(various)" "Serial" "nutdrv_qx" "Flight Technic & International (FTUPS)" "ups" "2" "(various)" "USB" "nutdrv_qx" "Forza Power Technologies" "ups" "2" "SL-1001" "USB" "blazer_usb" "Forza Power Technologies" "ups" "2" "FX-1500LCD" "USB" "blazer_usb" "FSP" "ups" "2" "EP650" "USB" "blazer_usb" "FSP" "ups" "2" "Fortron UPS Champ 1000 VA Tower" "USB" "blazer_usb" "FSP" "ups" "2" "Fortron UPS Champ 1000 VA Tower" "USB" "nutdrv_qx" "FSP" "ups" "2" "Fortron UPS Champ 2000 VA Tower" "USB" "blazer_usb" "FSP" "ups" "2" "Fortron UPS Champ 3000 VA Tower" "USB" "blazer_usb" "Gamatronic" "ups" "5" "All models with alarm interface" "" "genericups upstype=22" "Gamatronic" "ups" "2" "G-SmartCompact 2000" "" "blazer_ser" "Gamatronic" "ups" "5" "MP110/210" "" "gamatronic" "Gamatronic" "ups" "5" "MS-T" "" "gamatronic" "Gamatronic" "ups" "5" "MS" "" "gamatronic" "Gamatronic" "ups" "5" "µPS3/1" "" "gamatronic" "GE Digital Energy" "ups" "2" "EP Series" "USB" "blazer_usb" "GE Digital Energy" "ups" "2" "GT Series 1000/1500/2000/3000 VA Rack/Tower" "UL-version" "blazer_ser" "Geek Squad" "ups" "3" "GS1285U" "USB" "usbhid-ups" "Gemini" "ups" "1" "UPS625/UPS1000" "" "safenet" "Grafenthal" "ups" "3" "PR-3000-HS" "SNMP/Web Minislot card (ref 149G0006)" "snmp-ups" # http://grafenthal.de/produkte/usv/online/pr-hs-serie/pr-3000-hs/?L=3et8 "Greencell" "ups" "2" "2000VA" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1673 "Greencell" "ups" "2" "Micropower 600" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1080 "Greencell" "ups" "2" "Micropower 600" "USB" "blazer_usb" # https://github.com/networkupstools/nut/issues/1080 "Greencell" "ups" "2" "PowerProof 2000" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/2727 "Gtec" "ups" "2" "ZP120N-1K / ZP120N-1KS / ZP120N-2K / ZP120N-2KS / ZP120N-3K / ZP120N-3KS" "USB" "blazer_usb" "Gtec" "ups" "2" "ZP120N-6K / ZP120N-6KS / ZP120N-10K-11 / ZP120N-10KS-11" "USB" "blazer_usb" "Gtec" "ups" "2" "ZP120N-10K-31-00 / ZP120N-10K-31-07 / ZP120N-10K-31-09 / ZP120N-10K-31-99 / ZP120N-20K" "USB port" "blazer_usb" "Gtec" "ups" "2" "AP160N-1K / AP160LCD-1K-KS / AP160N-2K / AP160LCD-2K-KS / AP160N-3K / AP160LCD-3K-KS / AP160N-6K-PDU / AP160N-10K-PDU" "USB port" "blazer_usb" "Gtec" "ups" "2" "ZP120N-10K-31-00 / ZP120N-10K-31-07 / ZP120N-10K-31-09 / ZP120N-10K-31-99 / ZP120N-20K" "Serial port" "blazer_ser" "Gtec" "ups" "2" "AP160N-1K / AP160LCD-1K-KS / AP160N-2K / AP160LCD-2K-KS / AP160N-3K / AP160LCD-3K-KS / AP160N-6K-PDU / AP160N-10K-PDU" "Serial port" "blazer_ser" "Gtec" "ups" "3" "ZP120N" "USB" "nutdrv_qx with subdriver=gtec protocol=gtec" "Guardian" "ups" "2" "LCD 1500 AP (IGA1500LCD)" "Serial" "nutdrv_qx" "HP" "ups" "1" "PowerTrust 2997A" "HP 5061-2575 cable" "apcsmart" "HP" "ups" "3" "T750 G2" "Serial port" "bcmxcp" "HP" "ups" "3" "T1000 G3" "Serial port" "bcmxcp" "HP" "ups" "3" "T1500 G3" "Serial port" "bcmxcp" "HP" "ups" "3" "R1500 G2" "Serial port" "bcmxcp" "HP" "ups" "4" "R3000 XR" "" "bcmxcp" "HP" "ups" "4" "R5500 XR" "" "bcmxcp" "HP" "ups" "3" "T500 / T750" "older models, USB port" "bcmxcp_usb" "HP" "ups" "3" "R/T3000" "Serial port" "mge-shut" "HP" "ups" "3" "R5000 / R7000" "Serial port" "mge-shut" "HP" "ups" "3" "T750 INTL" "USB" "usbhid-ups" "HP" "ups" "3" "T1000 INTL" "USB" "usbhid-ups" "HP" "ups" "3" "T1500 INTL" "USB" "usbhid-ups" "HP" "ups" "3" "T750 G2" "USB port" "usbhid-ups" "HP" "ups" "3" "T1000 G3" "USB port" "usbhid-ups" "HP" "ups" "3" "T1500 G3" "USB port" "usbhid-ups" "HP" "ups" "3" "R1500 G2 INTL" "USB port" "usbhid-ups" "HP" "ups" "3" "R/T 2200 G2" "USB" "usbhid-ups" "HP" "ups" "3" "R/T3000" "USB port" "usbhid-ups" "HP" "ups" "3" "R5000 / R7000" "USB port" "usbhid-ups" "HP" "ups" "4" "Various (SNMP mode)" "HP UPS Management Module" "snmp-ups" "HP" "pdu" "1" "HP3488 Switch/Control Unit" "" "powerman-pdu (experimental)" "HPE" "pdu" "5" "Various (SNMP mode)" "" "snmp-ups" "HPE" "pdu" "5" "G2 Metered & Switched PDU" "" "snmp-ups" "Huawei" "ups" "4" "UPS5000-E" "" "snmp-ups" "Huawei" "ups" "3" "UPS2000-G and UPS2000-A series" "MODBUS (USB with Linux 5.12+, or Serial RS-232)" "huawei-ups2000" # https://github.com/networkupstools/nut/issues/1066 https://github.com/networkupstools/nut/pull/1198 https://github.com/networkupstools/nut/pull/954 https://github.com/networkupstools/nut/issues/1017 "Hunnox" "ups" "2" "HNX-850" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 "IBM" "ups" "5" "Various" "USB port" "usbhid-ups" "IBM" "ups" "5" "Various" "Serial port" "mge-shut" "IBM" "pdu" "1" "Blade Center Management Module" "15 outlets" "powerman-pdu (experimental)" "ICS" "pdu" "1" "8064 Ethernet Relay Interface" "16 outlets" "powerman-pdu (experimental)" "iDowell" "ups" "3" "iBox UPS" "USB" "usbhid-ups" "INELT" "ups" "2" "Monolith 1000LT" "" "blazer_ser" "INELT" "ups" "2" "Monolith 3000RT" "" "blazer_ser" "Inform" "ups" "1" "GUARD" "Line Interactive AP model" "powercom" "Inform" "ups" "2" "Guard S 1500AP" "" "blazer_ser" "Inform" "ups" "2" "Informer Compact 1000-2000-3000 VA" "" "blazer_ser" "Inform" "ups" "2" "Sinus SS 210" "" "blazer_ser" "Infosec" "ups" "2" "iPEL 350" "" "blazer_ser" "Infosec" "ups" "2" "iPEL 500" "" "blazer_ser" "Infosec" "ups" "2" "iPEL 750" "" "blazer_ser" "Infosec" "ups" "2" "iPEL 1000" "" "blazer_ser" "Infosec" "ups" "2" "500XP" "" "blazer_ser" "Infosec" "ups" "2" "X2, X3, X4, E2, E3, E4" "USB" "blazer_usb" "Infosec" "ups" "2" "XP 500" "USB" "blazer_usb" "Infosec" "ups" "2" "XP 1000" "" "blazer_ser" "Infosec" "ups" "1" "(various)" "Serial" "nutdrv_hashx" # https://www.infosec-ups.com/en/powermaster "IPAR" "ups" "2" "Mini Energy ME 800" "USB" "blazer_usb" "IPMI" "pdu" "1" "" "" "powerman-pdu (experimental)" "Ippon" "ups" "2" "Back Basic 850 Euro" "USB" "blazer_usb (experimental)" # https://github.com/networkupstools/nut/issues/802 "Ippon" "ups" "2" "Back Power Pro 400/500/600/700/800" "" "blazer_ser" "Ippon" "ups" "2" "Back Power Pro 400/500/600/700/800" "USB" "blazer_usb (experimental)" "Ippon" "ups" "2" "Back Comfo Pro 600/800" "" "blazer_ser" "Ippon" "ups" "2" "Back Comfo Pro 600/800" "USB" "blazer_usb (experimental)" "Ippon" "ups" "2" "Back Comfo Pro II 650/850/1050" "USB" "blazer_usb (experimental)" "Ippon" "ups" "2" "Smart Power Pro 1000/1400/2000" "" "blazer_ser" "Ippon" "ups" "2" "Smart Power Pro 1000/1400/2000" "USB" "blazer_usb (experimental)" "Ippon" "ups" "2" "Smart Power Pro II 1200/1600/2200" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 https://github.com/networkupstools/nut/issues/701 "Ippon" "ups" "2" "Smart Power Pro II Euro 1200/1600/2200" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 https://github.com/networkupstools/nut/issues/701 "Ippon" "ups" "2" "Pacific 1000/2000/3000" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Ampere 1000/1500/2000/3000 bl" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Innova RT 3/1 10K/10K compact/20K" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/2712 "Ippon" "ups" "2" "Innova RTB 1000/1500/2000/3000" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Innova TBE 1000/2000/3000" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Innova TB 1000/2000/3000" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Back Power Pro II 500/600/800" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Back Power Pro II Euro 650/850" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Kirpich 650/850/1050" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2702 "Ippon" "ups" "2" "Smart Winner 750/1000/1500/2000/3000" "" "blazer_ser" "Ippon" "ups" "2" "Smart Winner 750/1000/1500/2000/3000" "USB" "blazer_usb (experimental)" "Ippon" "ups" "2" "(various)" "" "blazer_ser" "Ippon" "ups" "2" "(various)" "USB" "blazer_usb" "Ippon" "ups" "2" "INNOVA RT 1K/1.5K/2K/3K" "USB" "blazer_usb" "Ippon" "ups" "2" "2049878 UPS Ippon Na+ TA 1000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2055083 UPS Ippon Na+ TAE 1000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049879 UPS Ippon Na+ TA 2000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2055084 UPS Ippon Na+ TAE 2000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049880 UPS Ippon Na+ TA 3000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2055085 UPS Ippon Na+ TAE 3000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049881 UPS Ippon Na+ TA 6K (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049882 UPS Ippon Na+ TA 10K (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049895 Battery for UPS Ippon NA+ TA 6/10K" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049883 UPS Ippon Na+ RTA 1000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049884 UPS Ippon Na+ RTA 2000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049885 UPS Ippon Na+ RTA 3000 (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049886 UPS Ippon Na+ RTA 6K (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049888 UPS Ippon Na+ RTA 10K (white)" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2058874 Battery for UPS Ippon NA+ RTA 2000" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049899 Battery for UPS Ippon NA+ RTA 3000" "Serial port" "blazer_ser" "Ippon" "ups" "2" "2049897 Battery for UPS Ippon NA+ RTA 6/10K" "Serial port" "blazer_ser" "IVT" "scd" "1" "SCD series" "" "ivtscd" "Jageson Technology" "ups" "1" "Jasuny USPS" "" "genericups upstype=4" "JAWAN" "ups" "2" "JW-UPSLC02" "USB" "blazer_usb" "Kanji" "ups" "1" "800 VA" "USB" "nutdrv_atcl_usb" "Kebo" "ups" "2" "1200D/D Series" "" "blazer_ser" "Kebo" "ups" "2" "UPS-1000D (UPS-1000VA)" "USB" "blazer_usb langid_fix=0x4095 subdriver=krauler" # https://github.com/networkupstools/nut/issues/981 "Kebo" "ups" "2" "UPS-650VA" "USB" "megatec_usb" "KOLFF" "ups" "2" "BLACK NOVA 1K/2K/3K/6K/10K/20K TOWER" "USB" "blazer_usb" "KOLFF" "ups" "2" "BLACK NOVA 1K/2K/3K/6K/10K/20K XL TOWER" "USB" "blazer_usb" "KOLFF" "ups" "2" "BLACK NOVA 1K/1.5K/2K/3K/6K/10K RACK" "USB" "blazer_usb" "KOLFF" "ups" "2" "BLACK NOVA 1K/1.5K/2K/3K/6K/10K XL RACK" "USB" "blazer_usb" "Krauler" "ups" "2" "UP-D1200VA" "USB" "blazer_usb" "Krauler" "ups" "2" "UP-M500VA" "USB" "blazer_usb" "Lacerda" "ups" "2" "New Orion 800VA" "USB" "blazer_usb" "LDLC" "ups" "2" "UPS-1200D" "USB" "blazer_usb langid_fix=0x4095" "Legrand" "ups" "2" "Daker DK" "Serial" "nutdrv_qx" "Legrand" "ups" "2" "Daker DK" "USB" "nutdrv_qx" "Legrand" "ups" "2" "Daker DK Plus" "Serial" "nutdrv_qx" "Legrand" "ups" "2" "Daker DK Plus" "USB" "nutdrv_qx" "Legrand" "ups" "2" "Keor Line RT" "Serial" "nutdrv_qx" "Legrand" "ups" "2" "Keor Line RT" "USB" "nutdrv_qx" "Legrand" "ups" "2" "Keor LP" "Serial" "nutdrv_qx" "Legrand" "ups" "2" "Keor Multiplug" "USB" "nutdrv_qx" # NOTE: As of 2023 reports, the 'NEW Keor Multiplug' is not supported (also by older vendor SW) "Legrand" "ups" "2" "Keor S" "Serial" "nutdrv_qx" "Legrand" "ups" "2" "Keor S" "USB" "nutdrv_qx" "Legrand" "ups" "3" "Keor PDU" "USB" "usbhid-ups" "Legrand" "ups" "3" "Keor SP" "USB" "usbhid-ups" "Legrand" "ups" "2" "Keor SPX" "USB" "nutdrv_qx" "Legrand" "ups" "4" "Megaline 1250" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 2500" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 3750" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 5000" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 5000 /2" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 6250 /2" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 7500 /2" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 8750 /2" "Serial" "metasys" "Legrand" "ups" "4" "Megaline 10000 /2" "Serial" "metasys" "Legrand" "ups" "2" "Niky" "Serial" "nutdrv_qx" "Legrand" "ups" "2" "Niky" "USB" "nutdrv_qx" "Legrand" "ups" "2" "Niky S" "Serial" "nutdrv_qx" "Legrand" "ups" "2" "Niky S" "USB" "nutdrv_qx" "Legrand" "ups" "4" "WHAD 800" "Serial" "metasys" "Legrand" "ups" "4" "WHAD 1000" "Serial" "metasys" "Legrand" "ups" "4" "WHAD 1250" "Serial" "metasys" "Legrand" "ups" "4" "WHAD 1500" "Serial" "metasys" "Legrand" "ups" "4" "WHAD 2000" "Serial" "metasys" "Legrand" "ups" "4" "WHAD 2500" "Serial" "metasys" "Legrand" "ups" "4" "WHAD CAB 1250" "Serial" "metasys" "Legrand" "ups" "4" "WHAD CAB 2500" "Serial" "metasys" "Legrand" "ups" "4" "WHAD HE 800" "Serial" "metasys" "Legrand" "ups" "4" "WHAD HE 1000" "Serial" "metasys" "Legrand" "ups" "4" "WHAD HE 1500" "Serial" "metasys" "Lestar" "ups" "2" "MD-800E" "" "blazer_ser" "Lexis" "ups" "2" "X-Power Tigra 1kVA" "" "blazer_ser or bestups" "Liebert" "ups" "2" "ITON 600VA" "" "blazer_ser" "Liebert" "ups" "5" "UPStation GXT2" "contact-closure cable" "liebert" "Liebert" "ups" "4" "GXE 1-3kVA" "Serial" "liebert-gxe (experimental)" "Liebert" "ups" "1" "GXT2-3000RT230" "" "liebert-esp2 (experimental)" "Liebert" "ups" "3" "GXT4-1500RT120" "USB" "usbhid-ups" # https://alioth-lists.debian.net/pipermail/nut-upsdev/2024-September/008013.html "Liebert" "ups" "3" "PowerSure Personal XT" "USB" "usbhid-ups" "Liebert" "ups" "3" "PowerSure PSA" "USB" "usbhid-ups" "Liebert" "ups" "3" "PowerSure PSA 500" "USB" "usbhid-ups" "Liebert" "ups" "3" "PowerSure PSA500MT3-230U" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/601 "Liebert" "ups" "3" "PowerSure PSI 1440" "USB" "usbhid-ups" # http://www.emersonnetworkpower.com/en-US/Products/ACPower/Pages/LiebertPowerSurePSILineInteractiveUPS10003000VA.aspx "LNXI" "pdu" "1" "Icebox" "10 outlets" "powerman-pdu (experimental)" "Lyonn" "ups" "2" "CTB-800V" "" "nutdrv_qx" "Lyonn" "ups" "2" "CTB-1200" "USB" "blazer_usb" "Masterguard" "ups" "1" "(various)" "" "masterguard" "MasterPower" "ups" "3" "MF-UPS650VA" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/2661 - Note there are two VendorID:ProductID for KSTAR making this device "Maxxtro" "ups" "2" "UPS 600 VA" "serial port" "blazer_ser" "Mecer" "ups" "2" "ME-1000-WTU" "USB" "nutdrv_qx" # http://www.comx-computers.co.za/download/mecer/ME-1000-WTU.pdf "Mecer" "ups" "2" "ME-2000" "" "blazer_ser" "Meta System" "ups" "4" "HF Line" "1..4 boards" "metasys" "Meta System" "ups" "4" "HF Line /2" "5..8 boards" "metasys" "Meta System" "ups" "4" "HF Millennium 810" "" "metasys" "Meta System" "ups" "4" "HF Millennium 820" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 910" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 920" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 930" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 940" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 950" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 960" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 970" "" "metasys" "Meta System" "ups" "4" "HF TOP Line 980" "" "metasys" "Meta System" "ups" "4" "ECO Network 750" "" "metasys" "Meta System" "ups" "4" "ECO Network 1000" "" "metasys" "Meta System" "ups" "4" "ECO Network 1050" "" "metasys" "Meta System" "ups" "4" "ECO Network 1500" "" "metasys" "Meta System" "ups" "4" "ECO Network 1800" "" "metasys" "Meta System" "ups" "4" "ECO Network 2000" "" "metasys" "Meta System" "ups" "4" "ECO Network 2100" "" "metasys" "Meta System" "ups" "4" "ECO Network 2500" "" "metasys" "Meta System" "ups" "4" "ECO Network 3000" "" "metasys" "Meta System" "ups" "4" "ECO 305" "" "metasys" "Meta System" "ups" "4" "ECO 308" "" "metasys" "Meta System" "ups" "4" "ECO 311" "" "metasys" "Meta System" "ups" "4" "ECO 511" "" "metasys" "Meta System" "ups" "4" "ECO 516" "" "metasys" "Meta System" "ups" "4" "ECO 519" "" "metasys" "Meta System" "ups" "4" "ECO 522" "" "metasys" "Meta System" "ups" "4" "ally HF 800" "" "metasys" "Meta System" "ups" "4" "ally HF 1000" "" "metasys" "Meta System" "ups" "4" "ally HF 1250" "" "metasys" "Meta System" "ups" "4" "ally HF 1600" "" "metasys" "Meta System" "ups" "4" "ally HF 2000" "" "metasys" "Meta System" "ups" "4" "ally HF 2500" "" "metasys" "Meta System" "ups" "4" "Megaline 1250" "" "metasys" "Meta System" "ups" "4" "Megaline 2500" "" "metasys" "Meta System" "ups" "4" "Megaline 3750" "" "metasys" "Meta System" "ups" "4" "Megaline 5000" "" "metasys" "Meta System" "ups" "4" "Megaline 6250" "" "metasys" "Meta System" "ups" "4" "Megaline 7500" "" "metasys" "Meta System" "ups" "4" "Megaline 8750" "" "metasys" "Meta System" "ups" "4" "Megaline 10000" "" "metasys" "Meta System" "ups" "4" "DHEA 1000" "Serial" "metasys" "Meta System" "ups" "4" "DHEA 1500" "Serial" "metasys" "MGE Office Protection Systems" "ups" "5" "Protection Center 500/675 VA" "USB" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Protection Station 500/650/800 VA" "USB" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Ellipse ASR USBS 600/750/1000/1500 VA" "USB cable" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Ellipse MAX USBS 600/850/1100/1500 VA" "USB cable" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Evolution 650/850/1150/1550/2000 VA" "USB port" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Evolution S 1250/1750/2500/3000 VA" "USB port" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Pulsar 700/1000/1500 VA" "USB port" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Pulsar M 2200/3000 VA" "USB port" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Pulsar MX 5/8/10/15/20 kVA" "USB port" "usbhid-ups" "MGE Office Protection Systems" "ups" "5" "Ellipse ASR USBS 600/750/1000/1500 VA" "Serial cable" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Ellipse MAX USBS 600/850/1100/1500 VA" "Serial cable" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Evolution 650/850/1150/1550/2000 VA" "Serial port" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Evolution S 1250/1750/2500/3000 VA" "Serial port" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Pulsar 700/1000/1500 VA" "Serial port" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Pulsar M 2200/3000 VA" "Serial port" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Pulsar MX 5/8/10/15/20 kVA" "Serial port" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Comet EX RT 1:1 7/11 kVA" "" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Comet EX RT 3:1 5/7/11 kVA" "" "mge-shut" "MGE Office Protection Systems" "ups" "5" "Comet EX RT (XML/HTTP)" "NMC Transverse card (ref 66074)" "netxml-ups (experimental)" "MGE Office Protection Systems" "ups" "5" "Comet EX RT (SNMP)" "NMC Transverse card (ref 66074)" "snmp-ups (experimental)" "MGE Office Protection Systems" "ups" "5" "various models (XML/HTTP mode)" "NMC Minislot (Ref 66102)" "netxml-ups (experimental)" "MGE Office Protection Systems" "ups" "5" "various models (SNMP mode)" "NMC Minislot (Ref 66102)" "snmp-ups (experimental)" "MGE Office Protection Systems" "ups" "5" "various models (XML/HTTP mode)" "SNMP/Web Minislot card (ref 66244)" "netxml-ups (experimental)" "MGE Office Protection Systems" "ups" "5" "various models (SNMP mode)" "SNMP/Web Minislot card (ref 66244)" "snmp-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "Comet EX RT" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Comet EX RT 3:1" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Protection Center 420" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Protection Center 500" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Protection Center 675" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "NOVA AVR 600 USB" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "NOVA AVR 1100 USB" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse USBS" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse USB" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse Premium USBS" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse Premium USB" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 600" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 750" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 1000" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 1500" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 600" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 850" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 1100" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 1500" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Evolution" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution 650" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution 850" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution 1150" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 1250" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution 1550" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 1750" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution 2000" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 2500" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 3000" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar M 2200" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar M 3000" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar M 3000 XL" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 700" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1000" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1500" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1000 RT2U" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1500 RT2U" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar MX 4000 RT" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Pulsar MX 5000 RT" "USB" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "Comet / Galaxy (USB)" "USB Card (ref 66067)" "usbhid-ups" "MGE UPS SYSTEMS" "ups" "5" "NOVA AVR 600 Serial" "" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "NOVA AVR 1100 Serial" "" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse USBS" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse S" "" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse Premium USBS" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Ellipse Premium S" "" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 600" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 750" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 1000" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse Office 1500" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 600" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 850" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 1100" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Ellipse MAX 1500" "Serial cable" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar EXtreme C / EX RT" "" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Comet EX RT" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Comet EX RT 3:1" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Esprit" "" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution 650" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution 850" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution 1150" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 1250" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution 1550" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 1750" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution 2000" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 2500" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Evolution S 3000" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar M 2200" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar M 3000" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar M 3000 XL" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 700" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1000" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1500" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1000 RT2U" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar 1500 RT2U" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar MX 4000 RT" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar MX 5000 RT" "Serial port" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar Evolution" "Serial port" "mge-shut or mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar EXtreme C" "" "mge-shut or mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar ES+" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar ESV+" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar SV" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar ESV" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar EX" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar EXL" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar PSX" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar SX" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Pulsar EXtreme" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Comet EXtreme" "" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Comet / Galaxy (Serial)" "Utalk Serial Card (ref 66060)" "mge-utalk" "MGE UPS SYSTEMS" "ups" "5" "Comet / Galaxy (Serial)" "HID COM Serial Card (ref 66066)" "mge-shut" "MGE UPS SYSTEMS" "ups" "5" "Pulsar / Comet / Galaxy (SNMP)" "SNMP/Web Transverse card (ref 66074)" "snmp-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "various models (XML/HTTP mode)" "NMC Minislot (Ref 66102)" "netxml-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "various models (SNMP mode)" "NMC Minislot (Ref 66102)" "snmp-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "Pulsar (XML/HTTP mode)" "SNMP/Web Minislot card (ref 66244)" "netxml-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "Pulsar (SNMP mode)" "SNMP/Web Minislot card (ref 66244)" "snmp-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "Pulsar / Comet / Galaxy (SNMP)" "SNMP card (ref 66062)" "snmp-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "Pulsar (SNMP)" "SNMP card (ref 66045)" "snmp-ups (experimental)" "MGE UPS SYSTEMS" "ups" "5" "UM-Link (SNMP)" "Not a UPS (ref 66850)" "snmp-ups (experimental)" "MicroDowell" "ups" "1" "B.Box BP 500" "" "powerpanel" "MicroDowell" "ups" "1" "B.Box BP 750" "" "powerpanel" "MicroDowell" "ups" "1" "B.Box BP 1000" "" "powerpanel" "MicroDowell" "ups" "1" "B.Box BP 1500" "" "powerpanel" "MicroDowell" "ups" "1" "B.Box LP 500" "" "genericups upstype=7" "MicroDowell" "ups" "5" "Enterprise B8" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise B10" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N8" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N11" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N15" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N20" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N22" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N30" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N40" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N50" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise N60" "" "microdowell" "MicroDowell" "ups" "5" "Enterprise HiBox ST" "" "microdowell" "Microline" "ups" "2" "C-Lion Innova RT 2K/3K" "USB" "blazer_usb" "Microline" "ups" "2" "C-Lion Innova RT 6K/10K (Parallel)" "USB" "blazer_usb" "Microline" "ups" "2" "C-Lion Innova Tower 6K/10K" "USB" "blazer_usb" "Microline" "ups" "2" "C-Lion Innova Combo 10K/20K (3/1)" "USB" "blazer_usb" "Micropower" "ups" "2" "LCD 1000" "USB" "blazer_usb" #"Micropower" "ups" "3" "0x09d6:0x0001" "USB" "usbhid-ups" # assuming, per https://github.com/networkupstools/nut/issues/2661 and https://alioth-lists.debian.net/pipermail/nut-upsuser/2023-April/013224.html "Microsol" "ups" "4" "Solis 1.0" "1000VA" "solis" "Microsol" "ups" "4" "Solis 1.5" "1500VA" "solis" "Microsol" "ups" "4" "Solis 2.0" "2000VA" "solis" "Microsol" "ups" "4" "Solis 3.0" "3000VA" "solis" "Microsol" "ups" "5" "Rhino 6.0" "6000VA" "rhino" "Microsol" "ups" "5" "Rhino 7.5" "7500VA" "rhino" "Microsol" "ups" "5" "Rhino 10.0" "10000VA" "rhino" "Microsol" "ups" "5" "Rhino 20.0" "20000VA" "rhino" "Minibox" "ups" "5" "openUPS Intelligent UPS" "USB port" "usbhid-ups" "Mustek" "ups" "2" "Powermust" "400VA Plus" "blazer_ser" "Mustek" "ups" "2" "Powermust" "600VA Plus" "blazer_ser" "Mustek" "ups" "2" "Powermust" "800VA Pro" "blazer_ser" "Mustek" "ups" "2" "Powermust" "1000VA Plus" "blazer_ser" "Mustek" "ups" "2" "Powermust" "1000VA USB" "blazer_usb" "Mustek" "ups" "2" "Powermust" "1400VA Plus" "blazer_ser" "Mustek" "ups" "2" "Powermust" "2000VA USB" "blazer_ser" "Mustek" "ups" "2" "Powermust Office 650" "USB" "blazer_usb" "Mustek" "ups" "2" "PowerMust 424 / 636 / 848" "USB" "blazer_usb" "Mustek" "ups" "2" "Yukai PowerMust" "1000 USB (PID: 5161)" "blazer_usb" "Mustek" "ups" "2" "Various" "" "blazer_ser" "NetVision" "ups" "3" "U4BC02CB00NY100" "" "snmp-ups" # https://github.com/networkupstools/nut/issues/1732 "Neus" "ups" "2" "400va / 600va" "" "blazer_ser" "NHS Sistemas de Energia" "ups" "5" "Expert C Online 6000" "" "gamatronic" # http://www.nhs.com.br/produtos_interna/id/TWpFeQ== "NHS Sistemas de Energia" "ups" "5" "Expert C Online 8000" "" "gamatronic" "NHS Sistemas de Energia" "ups" "5" "Expert C Online 10000" "" "gamatronic" "NHS Sistemas de Energia" "ups" "5" "Expert S Online 6000" "" "gamatronic" "NHS Sistemas de Energia" "ups" "5" "Expert S Online 8000" "" "gamatronic" "NHS Sistemas de Energia" "ups" "5" "Expert S Online 10000" "" "gamatronic" "NHS Sistemas de Energia" "ups" "5" "Expert S Online 10000" "" "gamatronic" "NHS Sistemas de Energia" "ups" "5" "Laser Senoidal 5000VA" "USB" "gamatronic" # http://www.nhs.com.br/produtos_interna/id/T0RrPQ== # Large block coming from https://github.com/networkupstools/nut/pulls/2692 : "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS COMPACT PLUS" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS COMPACT PLUS SENOIDAL" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS COMPACT PLUS RACK" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PREMIUM PDV" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PREMIUM PDV SENOIDAL" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PREMIUM 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PREMIUM 2200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PREMIUM SENOIDAL" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS LASER 2600VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS LASER 3300VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS LASER 2600VA ISOLADOR" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS LASER SENOIDAL" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS LASER ON-LINE" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS COMPACT PLUS 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "COMPACT PLUS SENOIDAL 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "COMPACT PLUS RACK 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM PDV 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM PDV SENOIDAL 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM 1500VA 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM 2200VA 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM SENOIDAL 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER 2600VA 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER 3300VA 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER 2600VA ISOLADOR 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV ONLINE 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "EXPERT ONLINE 2003" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "MINI 2" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "COMPACT PLUS 2" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ON-LINE" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV SENOIDAL 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV SENOIDAL 1000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 3750VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 5000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM SENOIDAL 2000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 3500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM PDV 1200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM 2200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER 2600VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER 3300VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "COMPACT PLUS SENOIDAL 700VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM ONLINE 2000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "EXPERT ONLINE 10000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 4200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS COMPACT PLUS EXTENDIDO 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 6000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER EXT 3300VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS COMPACT PLUS 1200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 3000VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 3500VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 4200VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 3000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 3750VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 5000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 6000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM ONLINE 2000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM ONLINE 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM ONLINE 1200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "COMPACT PLUS II MAX 1400VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM PDV MAX 2200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM PDV 3000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM SENOIDAL 2200VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER PRIME SENOIDAL 3200VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM RACK ONLINE 3000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM ONLINE 3000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 4000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 7500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE BIFASICO 5000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE BIFASICO 6000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE BIFASICO 7500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS MINI ST" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS MINI 120" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS MINI BIVOLT" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV 600" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS MINI MAX" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS MINI EXT" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS AUTONOMY PDV 4T" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS AUTONOMY PDV 8T" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS COMPACT PLUS RACK 1200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV SENOIDAL ISOLADOR 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PDV RACK 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PDV 1400VA S GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV SENOIDAL ISOLADOR 1500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER PRIME SENOIDAL ISOLADOR 2000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM SENOIDAL 2400VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS PDV 1400VA S 8T GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM ONLINE 2000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER PRIME ONLINE 2200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM RACK ONLINE 2200VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM SENOIDAL 2400VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 10000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE BIFASICO 10000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 3300VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 2600VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM SENOIDAL 3000VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PREMIUM SENOIDAL 2200VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE BIFASICO 4000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 12000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 8000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV SENOIDAL ISOLADOR 1000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "MINI SENOIDAL 500VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER SENOIDAL 5000VA GII" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "COMPACT PLUS SENOIDAL 1000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "QUAD_COM 80A" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "LASER ONLINE 5000VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "PDV SENOIDAL ISOLADOR 700VA" "Serial port" "nhs_ser" "NHS Sistemas Eletronicos LTDA" "ups" "2" "NHS UNKNOWN" "Serial port" "nhs_ser" "Nitram" "ups" "1" "Elite 500" "" "genericups upstype=8" "Nitram" "ups" "1" "Elite 2002" "" "genericups upstype=16" "Nitram" "ups" "1" "Elite 2005" "" "powerpanel" "nJoy" "ups" "2" "Keen 600" "USB" "blazer_ser port=/dev/ttyUSB0" # https://www.njoy.ro/UPS/keen-600 "nJoy" "ups" "2" "Keen 600" "USB" "nutdrv_qx port=/dev/ttyUSB0" # https://www.njoy.ro/UPS/keen-600 "nJoy" "ups" "3" "Aten PRO 3000" "SNMP" "snmp-ups" # At least basic status is served; https://www.njoy.global/product/aten-pro-3000 "Novex" "ups" "1" "NUPS-650" "USB" "blazer_usb protocol=megatec" # http://komp.1k.by/periphery-ups/novex/Novex_NUPS_650-130052.html "Numeric" "ups" "2" "3000 SW" "" "blazer_ser" "Numeric" "ups" "2" "Digital 800 plus" "USB" "nutdrv_qx or blazer_usb" "NUT" "ups" "5" "all supported NUT devices, through remote upsd" "" "dummy-ups" "NUT" "ups" "5" "Simulated devices" "" "dummy-ups" "Oneac" "ups" "1" "ON400" "advanced interface" "oneac" "Oneac" "ups" "1" "ON600" "advanced interface" "oneac" "Oneac" "ups" "1" "ON900" "advanced interface" "oneac" "Oneac" "ups" "1" "ON1300" "advanced interface" "oneac" "Oneac" "ups" "1" "EG Series" "advanced interface" "oneac" "Oneac" "ups" "1" "ON700" "advanced interface" "oneac" "Oneac" "ups" "1" "ON700XAU" "advanced interface" "oneac" "Oneac" "ups" "1" "ON700XIU" "advanced interface" "oneac" "Oneac" "ups" "1" "ON1000" "advanced interface" "oneac" "Oneac" "ups" "1" "ON1000XAU" "advanced interface" "oneac" "Oneac" "ups" "1" "ON1000XIU" "advanced interface" "oneac" "Oneac" "ups" "1" "ON1500" "advanced interface" "oneac" "Oneac" "ups" "1" "ON1500XAU" "advanced interface" "oneac" "Oneac" "ups" "1" "ON1500XIU" "advanced interface" "oneac" "Oneac" "ups" "1" "ON2000" "advanced interface" "oneac" "Oneac" "ups" "1" "ON2000XAU" "advanced interface" "oneac" "Oneac" "ups" "1" "ON2000XIU" "advanced interface" "oneac" "Online" "ups" "1" "P-Series" "" "genericups upstype=14" "Online" "ups" "2" "Zinto A" "USB" "blazer_usb" "Online" "ups" "1" "Zinto D" "" "optiups" "Online" "ups" "2" "Yunto YQ450" "USB" "blazer_usb" "Online" "ups" "2" "Xanto S700" "/dev/ttyUSB0" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1279 "OnLite" "ups" "2" "AQUA" "50" "blazer_ser" "Opti-UPS" "ups" "1" "PowerES" "420E" "optiups" "Opti-UPS" "ups" "1" "VS 575C" "type=OPTI" "powercom" "Opti-UPS" "ups" "1" "Power Series" "PS1500E" "blazer_usb" "Opti-UPS" "ups" "1" "Power Series" "PS1440RM" "optiups" "Orvaldi Power Protection" "ups" "2" "various" "not 400 or 600" "blazer_ser" "Orvaldi Power Protection" "ups" "2" "750 / 900SP" "USB" "blazer_usb" "Phasak" "ups" "2" "400VA / 600VA" "" "blazer_ser" "Phasak" "ups" "2" "9465 or P6N" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1187 => Voltronic-QS-Hex protocol detected "PhoenixContact" "ups" "4" "QUINT-UPS/24DC" "2320461" "phoenixcontact_modbus" #https://www.phoenixcontact.com/online/portal/us?uri=pxc-oc-itemdetail:pid=2320461 "PiJuice" "ups" "5" "PiJuice HAT" "" "pijuice" # https://github.com/PiSupply/PiJuice/issues/124 "PiJuice" "ups" "5" "PiJuice Zero pHAT" "" "pijuice" "Plexus" "ups" "2" "500VA" "USB" "blazer_usb" "Plexus" "ups" "2" "1000VA Pro" "USB" "blazer_usb" "Plexus" "ups" "1" "800 VA" "USB" "nutdrv_atcl_usb" "Powercom" "ups" "4" "SMK" "" "blazer_ser" "Powercom" "ups" "4" "SXL" "" "blazer_ser" "Powercom" "ups" "4" "ULT" "" "blazer_ser" "Powercom" "ups" "4" "Trust 425/625" "" "powercom" "Powercom" "ups" "4" "Advice Partner/King Pr750" "" "powercom" "Powercom" "ups" "4" "Black Knight PRO" "" "powercom" "Powercom" "ups" "5" "Black Knight PRO" "USB (2009 models, product id: 00a6)" "usbhid-ups (experimental)" "Powercom" "ups" "4" "Smart KING Pro (all Smart series)" "" "powercom" "Powercom" "ups" "5" "Smart KING Pro (all Smart series)" "USB (2009 models, product id: 00a3)" "usbhid-ups (experimental)" "Powercom" "ups" "4" "Imperial" "" "powercom" "Powercom" "ups" "5" "Imperial" "USB (2009 models, product id: 00a2)" "usbhid-ups (experimental)" "Powercom" "ups" "4" "Vanguard" "" "blazer_ser" "Powercom" "ups" "5" "Vanguard" "USB (2009 models, product id: 0004 or 00a5)" "usbhid-ups (experimental)" "Powercom" "ups" "4" "WOW" "USB (<= 2009 models, product id: 0002)" "powercom (requires 'usbserial' kernel module)" "Powercom" "ups" "5" "WOW" "USB (2009 models, product id: 00a4)" "usbhid-ups (experimental)" "Powercom" "ups" "4" "(various)" "USB (<= 2009 models, product id: 0002)" "powercom (requires 'usbserial' kernel module)" "Powercom" "ups" "5" "(various)" "USB (2009 models, product id: 00a?)" "usbhid-ups (experimental)" "Powercom" "ups" "5" "BNT-xxxAP" "USB (product id: 0004)" "usbhid-ups (experimental)" "Powercom" "ups" "3" "BNT-xxxAP" "USB (product id: 0001)" "usbhid-ups (experimental)" "Powercom" "ups" "3" "RPT-600AP" "USB" "usbhid-ups" # http://pcmups.com.tw/eA/html/product/show.php?num=226&root=13&kind=105&page=1&keyword= https://github.com/networkupstools/nut/issues/633 "Powercom" "ups" "3" "Raptor 2000" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/633 "Powercool" "ups" "1" "350VA to 1600VA" "USB" "nutdrv_atcl_usb" "Powercool" "ups" "2" "650VA" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 product=MEC0003 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 caveats at https://github.com/networkupstools/nut/issues/537 "Powercool" "ups" "2" "650VA" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 bus=001 product=MEC0003 protocol=hunnox langid_fix=0x0409 novendor norating noscanlangid" # https://github.com/networkupstools/nut/pull/638 caveats at https://github.com/networkupstools/nut/issues/537 "Powercool" "ups" "2" "1200VA" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 product=MEC0003 protocol=hunnox subdriver=hunnox langid_fix=0x0409 novendor norating noscanlangid" # https://github.com/networkupstools/nut/pull/1539 "Powercool" "ups" "2" "1500VA" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 product=MEC0003 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 caveats at https://github.com/networkupstools/nut/issues/537 - e.g. battery percentage is not being returned "Powercool" "ups" "2" "2000VA" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 product=MEC0003 protocol=hunnox langid_fix=0x0409 novendor noscanlangid" # https://github.com/networkupstools/nut/pull/638 caveats at https://github.com/networkupstools/nut/issues/537 "POWEREX" "ups" "2" "VI 1000 LED" "USB" "blazer_usb" "PowerGuard" "ups" "2" "PG-600" "" "blazer_ser" "PowerKinetics" "ups" "1" "9001" "" "genericups upstype=17" "PowerKinetics" "ups" "2" "BlackOut Buster" "" "blazer_ser" "PowerMan" "ups" "2" "RealSmart 800" "" "blazer_ser" "PowerMan" "ups" "2" "RealSmart 1000" "" "blazer_ser" "PowerMan" "ups" "1" "BackPro" "" "genericups upstype=4" "Powermatic" "ups" "2" "Cleanline L-1000C" "USB" "nutdrv_qx" # https://alioth-lists.debian.net/pipermail/nut-upsdev/2024-September/008015.html "PowerShield" "ups" "2" "Defender 1200VA" "USB" "blazer_usb" "PowerTech" "ups" "1" "Comp1000" "DTR cable power" "genericups upstype=3" "PowerTech" "ups" "2" "SMK-800" "" "blazer_ser" "Powervar" "ups" "5" "GTS Series" "USB" "powervar-cu" "Powervar" "ups" "5" "UPM Series" "USB" "powervar-cu" "Powervar" "ups" "5" "UPM Series" "Serial" "powervar-cs" "Powervar" "ups" "5" "UPM Series" "USB" "usbhid-ups" "PowerWalker" "ups" "2" "Line-Interactive VI 1000" "" "blazer_ser" "PowerWalker" "ups" "2" "Line-Interactive VI 400/800" "" "blazer_ser" "PowerWalker" "ups" "2" "Line-Interactive VI 600" "" "blazer_ser" "PowerWalker" "ups" "2" "Line-Interactive VI 600 SE" "USB" "blazer_usb" "PowerWalker" "ups" "2" "Line-Interactive VI 800 SE" "USB" "blazer_usb" "PowerWalker" "ups" "2" "Line-Interactive VI 1400" "USB" "blazer_usb" "PowerWalker" "ups" "2" "Line-Interactive VI 2000" "USB" "blazer_usb" "PowerWalker" "ups" "2" "Line-Interactive VI 850 LCD" "USB" "blazer_usb" "PowerWalker" "ups" "2" "Online VFI 1000RT/1500RT/2000RT/3000RT/6000RT/10000RT LCD" "USB" "blazer_usb" "PowerWalker" "ups" "2" "Line-Interactive VI 1000RT/1500RT/2000RT/3000RT LCD" "USB" "blazer_usb" "PowerWalker" "ups" "2" "VFI 1000 CG PF1" "" "nutdrv_qx" # https://powerwalker.com/?page=product&item=10122108&lang=en "PowerWalker" "ups" "3" "VFI 2000 TGS" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/560 and https://github.com/networkupstools/nut/pull/564 "PowerWalker" "ups" "3" "VI 650 SH" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/483 "PowerWalker" "ups" "3" "VI 650/850 SHL" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/646 "PowerWalker" "ups" "3" "VI 1200 SHL" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/1270 "PowerWalker" "ups" "3" "VI 2200 SHL" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/756 "PowerWalker" "ups" "3" "VI 1200 SH" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/646 "PowerWalker" "ups" "3" "VI 2200 SH" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/646 "PowerWalker" "ups" "3" "Basic VI 1000 SB" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/818 "PowerWalker" "ups" "3" "PR1500LCDRT2U" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/818 "PowerWalker" "ups" "2" "VI 3000 SCL" "USB" "blazer_usb" # https://github.com/networkupstools/nut/issues/971 "PowerWalker" "ups" "3" "VI 750T/HID" "USB" "usbhid-ups" # https://powerwalker.com/?page=select&cat=VI_THID&lang=en https://github.com/networkupstools/nut/issues/774 "PowerWalker" "ups" "1" "(various)" "Serial" "nutdrv_hashx" # https://powerwalker.com/software/ "Powerware" "ups" "4" "3110" "" "genericups upstype=7" "Powerware" "ups" "4" "3115" "" "genericups upstype=11" "Powerware" "ups" "4" "5119, 5125" "" "genericups upstype=15" "Powerware" "ups" "4" "5119 RM" "" "genericups upstype=20" "Powerware" "ups" "5" "5119 RM" "" "upscode2" "Powerware" "ups" "5" "PW3105" "USB" "bcmxcp_usb" "Powerware" "ups" "5" "PW5110" "USB" "bcmxcp_usb" "Powerware" "ups" "5" "PW5115" "Serial port" "bcmxcp" "Powerware" "ups" "5" "PW5115" "USB port" "bcmxcp_usb" "Powerware" "ups" "5" "PW5125" "" "bcmxcp" "Powerware" "ups" "5" "PW9120" "Serial port" "bcmxcp" "Powerware" "ups" "5" "PW9120" "USB port" "bcmxcp_usb" "Powerware" "ups" "5" "PW9125" "" "bcmxcp" "Powerware" "ups" "5" "PW9315" "3-phase" "bcmxcp" "Powerware" "ups" "5" "9110" "" "upscode2" "Powerware" "ups" "5" "9120" "" "upscode2" "Powerware" "ups" "5" "9150" "" "upscode2" "Powerware" "ups" "5" "9305" "" "upscode2" "Powerware" "ups" "5" "BladeUPS (SNMP)" "ConnectUPS Web/SNMP Card" "snmp-ups (experimental)" "Powerware" "ups" "5" "(various)" "ConnectUPS Web/SNMP card" "snmp-ups (experimental)" "Powerwell" "ups" "1" "PM525A/-625A/-800A/-1000A/-1250A" "" "safenet" "Phantom" "pdu" "1" "Rackable Systems" "1 outlets" "powerman-pdu (experimental)" "Raritan" "pdu" "3" "Intelligent PDU - Dominion PX" "no report, but should be supported" "snmp-ups (experimental)" "Raritan" "pdu" "3" "Metered PDU - Raritan PM" "no report, but should be supported" "snmp-ups (experimental)" "Raritan" "pdu" "3" "Switched PDU - Raritan RPC" "no report, but should be supported" "snmp-ups (experimental)" "Raritan" "pdu" "3" "Dominion PX2" "" "snmp-ups" "REDi" "ups" "2" "Blazer 400VA / 600VA / 800VA" "" "blazer_ser" "Repotec" "ups" "1" "RPF525/625/800/1000" "" "safenet" "Repotec" "ups" "1" "RPT-800A" "" "genericups upstype=13" "Repotec" "ups" "1" "RPT-162A" "" "genericups upstype=13" "Riello" "ups" "3" "Sentinel SDL 6000-7" "Netman Plus 102 SNMP Card" "snmp-ups" "Riello" "ups" "3" "Sentinel Dual SDH 1000-7" "Netman Plus 102 SNMP Card" "snmp-ups" "Riello" "ups" "4" "IDG 400/600/800/1200/1600" "USB" "riello_usb" "Riello" "ups" "4" "IPG 600/800" "USB" "riello_usb" "Riello" "ups" "5" "WPG 400/600/800" "USB" "riello_usb" "Riello" "ups" "5" "NPW 600/800/1000/1500/2000" "USB" "riello_usb" "Riello" "ups" "5" "NDG 800/1000/1500/2000" "USB" "riello_usb" "Riello" "ups" "5" "DVT 500/800/1100/1500/2000" "USB" "riello_usb" "Riello" "ups" "5" "DVR 500/800/1100" "USB" "riello_usb" "Riello" "ups" "5" "DVD 1500/2200/3000" "USB" "riello_usb" "Riello" "ups" "5" "VST 800/1100/1500/2000" "USB" "riello_usb" "Riello" "ups" "5" "VSR 800/1100" "USB" "riello_usb" "Riello" "ups" "5" "VSD 1100/1500/2200/3000" "USB" "riello_usb" "Riello" "ups" "5" "SEP 700/1000/1500/2200/3000" "USB" "riello_usb" "Riello" "ups" "5" "SDH 1000/1500/2200/3000" "USB" "riello_usb" "Riello" "ups" "5" "SDL 3300/4000/5000/6000/6500/8000/10000" "USB" "riello_usb" "Riello" "ups" "5" "SDU 4000/5000/6000/8000/10000" "USB" "riello_usb" "Riello" "ups" "5" "SPW" "USB" "riello_usb" "Riello" "ups" "5" "SPT" "USB" "riello_usb" "Riello" "ups" "5" "STW 5000/6000/8000/10000" "USB" "riello_usb" "Riello" "ups" "5" "S3M" "USB" "riello_usb" "Riello" "ups" "5" "S3T" "USB" "riello_usb" "Riello" "ups" "5" "NDG 800/1000/1500/2000" "" "riello_ser" "Riello" "ups" "5" "DVT 500/800/1100/1500/2000" "" "riello_ser" "Riello" "ups" "5" "DVR 500/800/1100" "" "riello_ser" "Riello" "ups" "5" "DVD 1500/2200/3000" "" "riello_ser" "Riello" "ups" "5" "VST 800/1100/1500/2000" "" "riello_ser" "Riello" "ups" "5" "VSR 800/1100" "" "riello_ser" "Riello" "ups" "5" "VSD 1100/1500/2200/3000" "" "riello_ser" "Riello" "ups" "5" "SEP 700/1000/1500/2200/3000" "" "riello_ser" "Riello" "ups" "5" "SDH 1000/1500/2200/3000" "" "riello_ser" "Riello" "ups" "5" "SDL 3300/4000/5000/6000/6500/8000/10000" "" "riello_ser" "Riello" "ups" "5" "SDU 4000/5000/6000/8000/10000" "" "riello_ser" "Riello" "ups" "5" "SPW" "" "riello_ser" "Riello" "ups" "5" "SPT" "" "riello_ser" "Riello" "ups" "5" "STW 5000/6000/8000/10000" "" "riello_ser" "Riello" "ups" "5" "S3M" "" "riello_ser" "Riello" "ups" "5" "S3T" "" "riello_ser" "Riello" "ups" "5" "MCT" "" "riello_ser" "Riello" "ups" "5" "MST" "" "riello_ser" "Riello" "ups" "5" "MCM" "" "riello_ser" "Riello" "ups" "5" "MCT" "" "riello_ser" "Riello" "ups" "5" "MHE" "" "riello_ser" "Riello" "ups" "5" "MHT" "" "riello_ser" "Riello" "ups" "5" "MPT" "" "riello_ser" "Riello" "ups" "5" "MPM" "" "riello_ser" "Riello" "ups" "5" "NXE" "" "riello_ser" "Riello" "ups" "3" "(various)" "Netman Plus 101 SNMP Box" "snmp-ups" "Riello" "ups" "3" "(various)" "Netman Plus 102 SNMP Card" "snmp-ups" "Riello" "ups" "3" "(various)" "Netman Plus 202 SNMP Card" "snmp-ups" "Riello" "ups" "3" "(various)" "Netman 204 SNMP Card" "snmp-ups" # Note: in https://github.com/networkupstools/nut/issues/1878 submitted not as 'Netman Plus', clarification requested "Riello" "ups" "3" "(various)" "Netman 208 SNMP Card" "snmp-ups" # Note: in https://github.com/networkupstools/nut/issues/1878 submitted not as 'Netman Plus', clarification requested "Right Power Technology" "ups" "1" "(various)" "Serial" "nutdrv_hashx" # https://www.rightpowerups.com.my/faq-download/ "Rocketfish" "ups" "3" "RF-1000VA / RF-1025VA" "USB" "usbhid-ups" "Rucelf" "ups" "2" "Rucelf UPOII-3000-96-EL" "" "blazer_ser" # http://www.rucelf.ua/en/catalog/upoii-3000-96-el/ "Salicru" "ups" "2" "SPS ONE 700VA" "USB" "blazer_usb" "Salicru" "ups" "2" "SPS ONE 900VA" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1623 "Salicru" "ups" "2" "SPS ONE 2000VA" "USB" "nutdrv_qx" # https://www.salicru.com/en/ups/sps-one.html https://github.com/networkupstools/nut/issues/554 "Salicru" "ups" "3" "SPS 650/850 HOME" "usb" "usbhid-ups (experimental)" "Salicru" "ups" "3" "SLC TWIN PRO2" "usb" "usbhid-ups (experimental)" # https://github.com/networkupstools/nut/issues/450 "Salicru" "ups" "3" "SLC-1500-TWIN PRO3" "usb" "usbhid-ups (experimental)" # https://github.com/networkupstools/nut/issues/1142 "Salicru" "ups" "3" "SLC TWINPRO3" "usb" "usbhid-ups (experimental)" "Salicru" "ups" "3" "SLC TWIN RT3" "usb" "usbhid-ups (experimental)" "Salicru" "ups" "3" "SPS 850 ADV T" "usb" "usbhid-ups (experimental)" # https://www.salicru.com/sps-850-adv-t.html https://github.com/networkupstools/nut/issues/1416 "Salicru" "ups" "3" "SPS 3000 ADV RT2" "usb" "usbhid-ups (experimental)" # https://www.salicru.com/sps-3000-adv-rt2.html "Salicru" "ups" "1" "(various)" "Serial" "nutdrv_hashx" # https://www.salicru.com/softwares-usb-rs-232.html "Santak" "ups" "2" "Castle C*K" "Serial" "blazer_ser" # https://github.com/networkupstools/nut/issues/1039 "Santak" "ups" "2" "MT*-PRO" "Serial" "blazer_ser" # https://github.com/networkupstools/nut/issues/1039 "Siemens" "ups" "4" "SITOP UPS500" "serial" "nutdrv_siemens_sitop (experimental, untested)" "Siemens" "ups" "4" "SITOP UPS500" "USB" "nutdrv_siemens_sitop (experimental)" "SKE" "ups" "2" "SK600" "USB" "nutdrv_qx port=auto vendorid=0001 productid=0000 bus=003" "SmartLabs" "pdu" "1" "2412S Power Line Modem" "for X10/Insteon" "powerman-pdu (experimental)" "SMS (Brazil)" "ups" "2" "Manager III" "" "blazer_ser" "SNR" "ups" "2" "SNR-UPS-LID-600" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-600-XPS" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-600-LED-C13" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-600-LED-C13-PRO" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-800" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-800-LED-С13" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-1000-XPS" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-1200" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-1500" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-2000" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-2000-XPS" "" "nutdrv_qx" "SNR" "ups" "2" "SNR-UPS-LID-3000-XPS" "" "nutdrv_qx" "SOLA" "ups" "1" "305" "cable INT-0025C" "genericups upstype=7" "SOLA" "ups" "1" "325" "" "blazer_ser or bestups" "SOLA" "ups" "1" "520" "" "blazer_ser or bestups" "SOLA" "ups" "1" "610" "use ID= in ups.conf" "blazer_ser or bestups" "SOLA" "ups" "1" "620" "" "blazer_ser or bestups" "SOLA" "ups" "4" "330" "" "blazer_ser" "SOLA/BASIC Mexico" "ups" "1" "various" "ISBMEX protocol" "isbmex" "Socomec Sicon" "ups" "2" "NeTYS-PE 600VA" "" "blazer_ser" "Socomec Sicon" "ups" "1" "Egys" "420 VA" "powercom" "Socomec Sicon" "ups" "3" "MASTERYS 3/3 SYSTEM 60 kVA" "Net Vision v5.05 SNMP card" "snmp-ups (experimental)" "Socomec Sicon" "ups" "3" "NETYS RT 1/1" "Net Vision SNMP card" "snmp-ups (experimental)" "Socomec Sicon" "ups" "3" "Netvision" "UPS equipped with Netvision WEB/SNMP card/external box" "snmp-ups (experimental)" "Soltec" "ups" "1" "Winmate 525/625/800/1000" "" "safenet" "Soyntec" "ups" "2" "Sekury C 500" "" "blazer_ser" "Soyntec" "ups" "2" "Sekury C 800" "" "blazer_ser" "SquareOne Power" "ups" "2" "QP1000" "" "blazer_ser" "StarPower" "ups" "1" "PCF-800VA" "USB" "richcomm_usb" # http://www.sako.com.cn/products01.asp?Id=29&proid=53 "Sun" "pdu" "1" "ILOM Management Module" "1 outlet" "powerman-pdu (experimental)" "SuperPower" "ups" "2" "HP360, Hope-550" "" "blazer_ser" "SVEN" "ups" "2" "Power Pro+ series" "USB" "blazer_usb (USB ID ffff:0000)" "SVEN" "ups" "2" "Power Pro+ series" "USB" "blazer_usb (USB ID 05b8:0000)" "SVEN" "ups" "1" "Power Pro+ series" "USB" "richcomm_usb (USB ID 0925:1234)" "SVEN" "ups" "2" "Power Smart RM 2000" "USB" "blazer_usb (USB ID 05b8:0000)" "Sweex" "ups" "1" "500/1000" "smart - shipped with SafeNet" "safenet" "Sweex" "ups" "1" "500/1000" "" "genericups upstype=7" "Sweex" "ups" "1" "1000" "USB" "richcomm_usb" "Sweex" "ups" "2" "(various)" "" "blazer_ser" "Sweex" "ups" "2" "INTELLIGENT UPS 1500VA P220" "USB" "blazer_usb (USB ID 0665:5161)" # http://www.sweex.com/en/notebook-pc-accessoires/ups/PP220/ "Syndome" "ups" "2" "Era 500VA" "USB" "blazer_usb" "Syndome" "ups" "3" "Atom LCD-1000" "USB" "usbhid-ups" # https://github.com/networkupstools/nut/issues/483 "Sysgration" "ups" "2" "UPGUARDS Pro650" "" "blazer_ser" "Talegent" "ups" "2" "Vitality 1KS/2KS/3KS/6KS/10KS" "Serial port" "blazer_ser" "Talegent" "ups" "2" "EBP6K-UP/EBP10K-UP" "Serial port" "blazer_ser" "Talegent" "ups" "2" "RT01S-36HV-Na" "Serial port" "blazer_ser" "Talegent" "ups" "2" "RT02S-72HV-Na" "Serial port" "blazer_ser" "Talegent" "ups" "2" "RT03S-96HV-Na" "Serial port" "blazer_ser" "Talegent" "ups" "2" "RT06H-192HVEBP6K/10K-RTPDU" "Serial port" "blazer_ser" "Talegent" "ups" "2" "RT10H-240HVEBP6K/10K-RTPDU" "Serial port" "blazer_ser" "Talegent" "ups" "2" "EBP2K-RT/EBP3K-RT/EBP6K/10K-RT" "Serial port" "blazer_ser" "Techly" "ups" "2" "1000VA" "USB" "nutdrv_qx (very little data available with subdriver/protocol=hunnox)" # https://github.com/networkupstools/nut/issues/2651 "Tecnoware" "ups" "2" "Easy Power 1200" "" "blazer_ser" "Tecnoware" "ups" "2" "UPS ERA LCD 0.65" "USB" "blazer_usb langid_fix=0x409" "Tecnoware" "ups" "2" "UPS ERA PLUS 1100" "USB" "blazer_usb" # https://www.tecnoware.com/Prodotti/FGCERAPL1100/ups-era-plus-1100.aspx https://github.com/networkupstools/nut/issues/747 "Tescom" "ups" "2" "LEO Plus LCD 1500A" "USB" "blazer_usb langid_fix=0x4095 subdriver=krauler" # https://github.com/networkupstools/nut/issues/981 "Texas Instruments" "ups" "5" "INA219" "hwmon" "hwmon_ina219" "Tripp Lite" "ups" "1" "(various)" "Lan 2.2 interface - black 73-0844 cable" "genericups upstype=5" "Tripp Lite" "ups" "3" "1500 LCD" "USB" "usbhid-ups" "Tripp Lite" "ups" "3" "AVR550U" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=3090 "Tripp Lite" "ups" "3" "AVR700U" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=4785 "Tripp Lite" "ups" "3" "AVR750U" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=3141 "Tripp Lite" "ups" "3" "AVR900U" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=3649 "Tripp Lite" "ups" "3" "AVR900UTAA" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4375 "Tripp Lite" "ups" "3" "AVRX550U" "USB (protocol 2009)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3079 "Tripp Lite" "ups" "3" "AVRX550UD" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=4620 "Tripp Lite" "ups" "3" "AVRX750U" "USB (protocol 2009)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=3190 "Tripp Lite" "ups" "3" "AVRX750UD" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=4755 "Tripp Lite" "ups" "3" "AVRX750UF" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=4756 "Tripp Lite" "ups" "3" "BC600SINE" "USB (protocol 2011)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4863 "Tripp Lite" "ups" "3" "BCPERS450" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4 "Tripp Lite" "ups" "3" "BCPRO600" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=931&txtModelID=5 "Tripp Lite" "ups" "3" "ECO350UPS" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=743&txtModelID=4149 "Tripp Lite" "ups" "3" "ECO550UPS" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=743&txtModelID=4148 "Tripp Lite" "ups" "3" "ECO650LCD" "USB (protocol 2011)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4861 "Tripp Lite" "ups" "3" "ECO750UPS" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=743&txtModelID=4147 "Tripp Lite" "ups" "3" "ECO850LCD" "USB (protocol 2011)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=743&txtModelID=4862 "Tripp Lite" "ups" "3" "HT850UPS" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3197 "Tripp Lite" "ups" "3" "HTR05-1U" "USB (protocol 3005)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3202 "Tripp Lite" "ups" "3" "HTR10-2U" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3343 "Tripp Lite" "ups" "3" "INTERNET350U" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=2663 "Tripp Lite" "ups" "3" "INTERNET550U" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=3063 "Tripp Lite" "ups" "3" "INTERNET600U" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=3033 "Tripp Lite" "ups" "3" "INTERNET750U" "USB (protocol 1007)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3142 "Tripp Lite" "ups" "3" "INTERNET900U" "USB (protocol 1007)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=3657 "Tripp Lite" "ups" "3" "INTERNETOFFICE500" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=11 "Tripp Lite" "ups" "1" "INTERNETOFFICE700" "USB (older; product ID: 0001)" "tripplite_usb" "Tripp Lite" "ups" "3" "INTERNETOFFICE700" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=930&txtModelID=14 "Tripp Lite" "ups" "3" "OMNI650LCD" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3195 "Tripp Lite" "ups" "3" "OMNI900LCD" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=3082 "Tripp Lite" "ups" "3" "OMNI1000LCD" "USB" "usbhid-ups" "Tripp Lite" "ups" "3" "OMNISMART300PNP" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=19 "Tripp Lite" "ups" "1" "OMNISMART500" "USB (older; product ID: 0001)" "tripplite_usb" "Tripp Lite" "ups" "3" "OMNISMART500" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=21 "Tripp Lite" "ups" "3" "OMNISMART700" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=23 "Tripp Lite" "ups" "2" "OMNIVSINT800" "USB (older; product ID: 0001)" "tripplite_usb" "Tripp Lite" "ups" "3" "OMNIVS800" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=2729 "Tripp Lite" "ups" "2" "OMNIVS1000" "USB (older; product ID: 0001)" "tripplite_usb" "Tripp Lite" "ups" "3" "OMNIVS1000" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=2656 "Tripp Lite" "ups" "1" "OMNIVS1500XL" "USB" "tripplite_usb" "Tripp Lite" "ups" "3" "POS500" "USB (protocol 2007)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3742 "Tripp Lite" "ups" "3" "SM2200RMDVTAA" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4648 "Tripp Lite" "ups" "1" "SmartUPS" "" "tripplite" "Tripp Lite" "ups" "1" "SmartOnline" "" "tripplitesu" "Tripp Lite" "ups" "1" "SMART550USB" "USB (older; product ID: 0001)" "tripplite_usb" "Tripp Lite" "ups" "3" "SMART550USB" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=2002 "Tripp Lite" "ups" "3" "SMART550USBWD" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=2591 "Tripp Lite" "ups" "1" "SMART700USB" "USB" "tripplite_usb" "Tripp Lite" "ups" "3" "SMART750RMXL2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3020 "Tripp Lite" "ups" "3" "SMART750SLT" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3007 "Tripp Lite" "ups" "3" "SMART750USB" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=2679 "Tripp Lite" "ups" "3" "SMART750XLA" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3820 "Tripp Lite" "ups" "3" "SMART1000LCD" "USB (protocol 2010)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=3071 "Tripp Lite" "ups" "3" "SMART1000RM2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=2657 "Tripp Lite" "ups" "3" "SMART1000RMXL2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=5262 "Tripp Lite" "ups" "3" "SMART1050SLT" "USB (protocol 3012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3253 "Tripp Lite" "ups" "3" "SMART1050SLTAA" "USB (protocol 3012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4389 "Tripp Lite" "ups" "3" "SMART1200LCD" "USB (protocol 2009)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3193 "Tripp Lite" "ups" "1" "SMART1500RM2U" "USB (older; product ID: 0001)" "tripplite_usb" "Tripp Lite" "ups" "3" "SMART1500CRMXL" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3826 "Tripp Lite" "ups" "3" "SMART1500LCD" "USB (protocol 2009)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=3151 "Tripp Lite" "ups" "3" "SMART1500LCDXL" "USB (protocol 2012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=4978 "Tripp Lite" "ups" "3" "SMART1500RM2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=2658 "Tripp Lite" "ups" "3" "SMART1500RM2UN" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=5424 "Tripp Lite" "ups" "3" "SMART1500RMXL2UA" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3982 "Tripp Lite" "ups" "3" "SMART1500RMXLN" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=5429 "Tripp Lite" "ups" "3" "SMART1500SLT" "USB (protocol 3012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3254 "Tripp Lite" "ups" "3" "SMART2200CRMXL" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3825 "Tripp Lite" "ups" "3" "SMART2200RM2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=4403 "Tripp Lite" "ups" "3" "SMART2200RM2UN" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=5428 "Tripp Lite" "ups" "1" "SMART2200RMXL2U" "USB (older; product ID: 0001)" "tripplite_usb (experimental)" "Tripp Lite" "ups" "3" "SMART2200RMXL2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3264 "Tripp Lite" "ups" "3" "SMART2200RMXL2UP" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=4672 "Tripp Lite" "ups" "3" "SMART2200RMXLN" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=5427 "Tripp Lite" "ups" "3" "SMART2200SLT" "USB (protocol 3013)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3489 "Tripp Lite" "ups" "3" "SMART2200SLTAA" "USB (protocol 3013)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4390 "Tripp Lite" "ups" "3" "SMART2500XLHG" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=5440 "Tripp Lite" "ups" "3" "SMART2600RM2U" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3024 "Tripp Lite" "ups" "3" "SMART3000CRMXL" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3824 "Tripp Lite" "ups" "3" "SMART3000RM2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3025 "Tripp Lite" "ups" "3" "SMART3000RM2UN" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=5426 "Tripp Lite" "ups" "3" "SMART3000RMOD2U" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=4249 "Tripp Lite" "ups" "3" "SMART3000RMXL2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=4418 "Tripp Lite" "ups" "3" "SMART3000RMXLN" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=5425 "Tripp Lite" "ups" "3" "SMART3000SLT" "USB (protocol 3013)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=3490 "Tripp Lite" "ups" "2" "SMART500RT1U" "USB (older; product ID 0001, protocol 3005)" "tripplite_usb" "Tripp Lite" "ups" "3" "SMART500RT1U" "USB (newer; protocol/product ID 3005)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=2853 "Tripp Lite" "ups" "3" "SMC15002URM" "USB (protocol 3015)" "usbhid-ups" # https://www.tripplite.com/smartpro-120v-1-5kva-1kw-line-interactive-sine-wave-ups-2u-rack-tower-lcd-usb-db9-8-outlets~SMC15002URM "Tripp Lite" "ups" "3" "SMX1000LCD" "USB (protocol 2005)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3200 "Tripp Lite" "ups" "3" "SMX1000RT2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=2798 "Tripp Lite" "ups" "3" "SMX1050SLT" "USB (protocol 3012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3249 "Tripp Lite" "ups" "3" "SMX1500LCD" "USB (protocol 2009)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=932&txtModelID=3303 "Tripp Lite" "ups" "3" "SMX1500SLT" "USB (protocol 3012)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3248 "Tripp Lite" "ups" "3" "SMX1500XLRT2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=2687 "Tripp Lite" "ups" "3" "SMX2200XLRT2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3251 "Tripp Lite" "ups" "3" "SMX3000RT2UTAA" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4396 "Tripp Lite" "ups" "3" "SMX3000XLRT2U" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=933&txtModelID=2694 "Tripp Lite" "ups" "3" "SMX3000XLRT2UA" "USB (protocol 3015)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=5658 "Tripp Lite" "ups" "3" "SMX500RT1U" "USB (older; product ID 0001, protocol 3005)" "tripplite_usb" # https://www.tripplite.com/support/product/part-number/SMX500RT1U https://github.com/networkupstools/nut/pull/584 "Tripp Lite" "ups" "3" "SMX500RT1U" "USB (newer; protocol/product ID 3005)" "usbhid-ups" # https://www.tripplite.com/support/product/part-number/SMX500RT1U "Tripp Lite" "ups" "3" "SMX750SLT" "USB (protocol 3014)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3021 "Tripp Lite" "ups" "3" "SU750RTXL2U" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3194 "Tripp Lite" "ups" "3" "SU750RTXLCD2U" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=5070 "Tripp Lite" "ups" "3" "SU750XL" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3299 "Tripp Lite" "ups" "3" "SU1000RTXL2UA" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=2948 "Tripp Lite" "ups" "3" "SU1000RTXLCD2U" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=745&txtModelID=4980 "Tripp Lite" "ups" "3" "SU1000XLA" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=3180 "Tripp Lite" "ups" "3" "SU1000XLCD" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=5320 "Tripp Lite" "ups" "3" "SU1500RTXL2UA (SmartOnline)" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=2949 "Tripp Lite" "ups" "3" "SU1500RTXLCD2U" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=745&txtModelID=5037 "Tripp Lite" "ups" "3" "SU1500XL" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=3300 "Tripp Lite" "ups" "3" "SU1500XLCD" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=744&txtModelID=5339 "Tripp Lite" "ups" "3" "SU2200RTXL2UA" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=2950 "Tripp Lite" "ups" "3" "SU2200RTXLCD2U" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=745&txtModelID=5069 "Tripp Lite" "ups" "3" "SU2200XLA" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=3594 "Tripp Lite" "ups" "3" "SU2200XLCD" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=744&txtModelID=5340 "Tripp Lite" "ups" "3" "SU3000RTXL2U" "USB (protocol 4005)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4210 "Tripp Lite" "ups" "3" "SU3000RTXL3U" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=3023 "Tripp Lite" "ups" "3" "SU3000RTXLCD3U" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=745&txtModelID=5071 "Tripp Lite" "ups" "3" "SU3000RTXR3U" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=3080 "Tripp Lite" "ups" "3" "SU3000RTXR3UHW" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=4976 "Tripp Lite" "ups" "3" "SU3000XL" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=3601 "Tripp Lite" "ups" "3" "SU3000XLCD" "USB (protocol 4004)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=744&txtModelID=5342 "Tripp Lite" "ups" "3" "SUINT1000RTXL2UA" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=3983 "Tripp Lite" "ups" "3" "SUINT1500RTXL2UA" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=2720 "Tripp Lite" "ups" "3" "SUINT2200RTXL2UA" "USB (protocol 4001)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtSeriesID=934&txtModelID=3970 "Tripp Lite" "ups" "3" "SUINT3000RTXL2U" "USB (protocol 4005)" "usbhid-ups" # http://www.tripplite.com/en/products/model.cfm?txtModelID=4523 "Trust" "ups" "2" "UPS 1000 Management PW-4105" "" "blazer_ser" "Trust" "ups" "2" "UPS 1200VA Management PW-4120M" "" "blazer_ser" "Trust" "ups" "2" "UPS 1300VA Management PW-4130M" "" "blazer_ser" "TS Shara" "ups" "4" "(various)" "" "nutdrv_qx" "UltraMax" "ups" "2" "1000SC" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1634 "UNITEK" "ups" "2" "ALPHA 500 IC" "" "blazer_ser" "UNITEK" "ups" "2" "Alpha 1000is" "" "blazer_ser" "UNITEK" "ups" "2" "Alpha 500" "" "blazer_ser" "UNITEK" "ups" "2" "Alpha 500 ipE" "" "blazer_ser" "UNITEK" "ups" "2" "Alpha650ipF" "USB" "blazer_usb" "UNITEK" "ups" "2" "Alpha650ipE" "USB" "blazer_usb" "UNITEK" "ups" "2" "Alpha 2600" "" "blazer_ser" "UNITEK" "ups" "2" "Alpha 1200Sx" "USB" "blazer_usb" "UNITEK" "ups" "2" "Alpha 1250xD" "USB" "blazer_usb" "UPSonic" "ups" "2" "CXR1000" "" "blazer_ser" "UPSonic" "ups" "1" "LAN Saver 600" "" "genericups upstype=0" "UPSonic" "ups" "1" "Power Guardian" "" "genericups upstype=7" "UPSonic" "ups" "2" "PrOffice 650" "USB" "blazer_usb" "UPSonic" "ups" "2" "DS-800" "USB" "blazer_usb" "UPSonic" "ups" "2" "IRT-3K 2U" "USB" "megatec_usb" # Worked in NUT 2.4.3 "UPSonic" "ups" "2" "IRT-3K 2U" "USB" "nutdrv_qx" # Should work since 2.8.0; protocol broken vs. strict checks in 2.7.4; https://github.com/networkupstools/nut/issues/441#issuecomment-1288238345 "V7" "ups" "2" "UPS1RM2U1500-1E" "USB" "blazer_usb" # http://www.v7world.com/uk/ups-1500va-rack-mount-2u-eu.html https://github.com/networkupstools/nut/issues/716 "Various" "ups" "4" "(various)" "SEC protocol" "gamatronic" "Various" "ups" "1" "(various)" "Generic RUPS model" "genericups upstype=4" "Various" "ups" "1" "(various)" "Generic RUPS 2000 (Megatec M2501 cable)" "genericups upstype=21" "Various" "ups" "2" "(various serial)" "Q1 / Megatec protocol" "blazer_ser" "Various" "ups" "2" "(various USB)" "Q1 / Megatec protocol" "blazer_usb" "Various" "ups" "2" "(various)" "PhoenixTec protocol" "blazer_ser or bestups" "Various" "ups" "3" "(various)" "SNMP - RFC 1628" "snmp-ups (experimental)" "Various" "ups" "1" "(various)" "Safenet software" "safenet" "Various" "ups" "2" "(Various USB)" "UPSilon 2000 software" "blazer_usb langid_fix=0x409" "Various" "ups" "2" "(Various serial)" "ViewPower software" "nutdrv_qx" "Various" "ups" "2" "(Various USB)" "ViewPower software" "nutdrv_qx" "Various" "ups" "2" "(Various serial)" "WinPower software" "blazer_ser" "Various" "ups" "2" "(Various USB)" "WinPower software" "blazer_usb" "Various" "ups" "2" "Various Innova T" "(USB ID 06da:0201)" "blazer_ser or blazer_usb" "Various" "ups" "2" "Various Innova RT" "(USB ID 06da:0005)" "blazer_ser or blazer_usb" "Various" "ups" "2" "Various Innova 3/1 T" "(USB ID 06da:0004)" "blazer_ser or blazer_usb" "Victron/IMV" "ups" "1" "(various)" "" "victronups" "Victron/IMV" "ups" "1" "Lite" "crack cable" "genericups upstype=10" "Viewsonic" "ups" "1" "PowerES" "420E" "optiups" "Visench" "ups" "1" "C1K" "(/dev/ttyCH341USB0 with USB ID 1a86:7523)" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/2395 : Visench C1K; mfr/model are strings of `2`'s; USB ID identifies as QinHeng Electronics CH340 serial converter chip "Vivaldi" "ups" "1" "EA200 LED" "USB" "richcomm_usb" "Voltronic Power" "ups" "2" "Apex 1KVA" "Serial" "nutdrv_qx" "Voltronic Power" "ups" "2" "Apex 1KVA" "USB" "nutdrv_qx" "Voltronic Power" "ups" "2" "Frigate TX 1KVA" "Serial" "nutdrv_qx" "Voltronic Power" "ups" "2" "Frigate TX 1KVA" "USB" "nutdrv_qx" "Voltronic Power" "ups" "2" "Galleon 1KVA" "Serial" "nutdrv_qx" "Voltronic Power" "ups" "2" "Galleon 1KVA" "USB" "nutdrv_qx" "Voltronic Power" "ups" "2" "Galleon X9-RT LCD-1-3K" "USB" "blazer_usb" # https://github.com/networkupstools/nut/issues/1251 "Voltronic Power" "ups" "2" "Galleon X9-RT LCD-1-3K" "USB" "nutdrv_qx" # https://github.com/networkupstools/nut/issues/1251 "Voltronic Power" "ups" "2" "Imperial 1KVA" "Serial" "nutdrv_qx" "Voltronic Power" "ups" "2" "Imperial 1KVA" "USB" "nutdrv_qx" "Voltronic Power" "ups" "2" "Prosine 800" "Serial" "nutdrv_qx" "Voltronic Power" "ups" "2" "Prosine 800" "USB" "nutdrv_qx" "Voltronic Power" "ups" "2" "Vesta LED 850VA" "USB" "nutdrv_qx" "Voltronic Power" "ups" "2" "(various)" "Serial" "nutdrv_qx" "Voltronic Power" "ups" "2" "(various)" "USB" "nutdrv_qx" "WinPower" "ups" "2" "CPM-800" "" "blazer_ser" "WTI" "pdu" "1" "RPS-10" "10 outlets" "powerman-pdu (experimental)" "WTI" "pdu" "1" "NPS" "8 outlets" "powerman-pdu (experimental)" nut-2.8.4/README.adoc0000644000175000017500000011265515000736161011052 00000000000000Network UPS Tools Overview ========================== // NOTE: No blank line here, document-header include processing should kick in! //GH_MARKUP_1095//ifdef::top_srcdir[] //GH_MARKUP_1095//include::{top_srcdir}docs/asciidoc-vars.conf[] //GH_MARKUP_1095//endif::top_srcdir[] //GH_MARKUP_1095//ifndef::top_srcdir[] //GH_MARKUP_1095//include::docs/asciidoc-vars.conf[] //GH_MARKUP_1095//endif::top_srcdir[] //GH_MARKUP_1095_INCLUDE_BEGIN//a6bd83d48 (2025-03-20) docs/asciidoc-vars.conf: document that linkdoc may have further args ifndef::asciidoc-vars-nut-included[] :asciidoc-vars-nut-included: true // NOTE: The big block of comments and definitions below comes from // NUT::docs/asciidoc-vars.conf and is included into top-level document // sources by maintenance recipes directly (`make maintainer-asciidocs`), // due to current limitations of the GitHub Web UI asciidoc renderer. // Hopefully it can be dropped in favor of compact include definitions // (see README.adoc for anticipated example) after this issue is resolved // on their side: // * https://github.com/github/markup/issues/1095 // // This file should be included into NUT documentation sources to consistently // define certain expandable attributes, with contents defined based on the // rendition target (e.g. GitHub Web UI, plain text, locally built HTML/PDF...) // Note that currently GitHub Web UI references lead to nut-website (as of // last built and published revision), not to neighboring documents in the // source browser (which would make sense for branch revisions, etc.) due // to certain complexity about referencing other-document sections with a // partially functional rendering engine there. Exploration and fixes are // welcome (actually working links like // https://github.com/networkupstools/nut/tree/master#installing or // https://github.com/networkupstools/nut/blob/master/UPGRADING.adoc#changes-from-274-to-280 // do seem promising)! // // Since the GitHub UI does not allow use of custom asciidoc configuration // files, or generally does not process the `include:` requests at this time, // clumsy expandable attributes had to be used (usually a set including a // prefix with meaningful name, and one or more separators and/or a suffix // with shortened names). For our classic documentation renditions, they // should resolve to properly defined macros from `docs/asciidoc.conf` // (usually named same as the variables defined here, for simplicity): // * `linksrcdoc` allows to refer to a source of documentation file // relative to the root of NUT code base. // * `linkdoc` allows to refer to a file under `docs/` directory (or // its nut-website rendition). // * `xref` substitutes the asciidoc shorthand '<< >>' syntax with // attributes that conditionally expand to: // - links on GitHub (references can point at most to a section of // level docs/common.xsl's ), or // - xref asciidoc macros when generating docs. // * `linksingledoc` guarantees that, when chunked HTML is generated, // the link always points to a non-chunked file. // * `linkman2` allows to support different names for the manpage and // the command shown. This is also needed to properly display links // to manpages in both GitHub and generated docs without defining an // attribute for each manpage. // * `linkmanext` and `linkmanext2` macros repeat the behavior of the default ones. // These macros are intended for system man pages (e.g. HTML links might lead // to a generic internet site, or possibly to a distro-provided library // online or locally). // // Optional attributes set by callers: // * `website-url` (defaulted below) may be used for "historic website" // snapshot builds... hopefully // * `website` is used as a boolean toggle in our recipes for nut-website // vs. offline documentation renditions // * `env-github` is used as a boolean toggle, set by GitHub Web-UI renderer // * `(top_)srcdir` and `(top_)builddir` can be set by `Makefile.am` // calling the `a2x` tool, since some of the files with the asciidoc // mark-up are only generated or post-processed during build and // (due to `make dist` restrictions) being build products, they may // not reside in same directory as static source text files which // reference or include them. Note that the non-`top` paths would // normally differ based on location of the `Makefile` involved // (e.g. workspace root, or the `docs`, or `docs/man` directories). // These variables are expected to be absolute paths, or ones relative // to asciidoc-selected `:base_dir`, and to end with a relevant path // separator, or be empty -- so in all cases letting the resulting // string resolve meaningfully in the filesystem during docs build. // // Please keep the remaining comments and definitions as one big block // so it does not become a series of empty paragraphs in the rendered // documents! // ifndef::website-url[] :website-url: https://www.networkupstools.org/ endif::website-url[] // ifndef::srcdir[] :srcdir: endif::srcdir[] // ifndef::builddir[] :builddir: endif::builddir[] // ifndef::top_srcdir[] :top_srcdir: endif::top_srcdir[] // ifndef::top_builddir[] :top_builddir: endif::top_builddir[] // // // Address links on GitHub vs. docs // (note: 'env-github' attribute is set on GitHub) // // - when generating docs: ifndef::env-github[] // * xref -> xref // syntax: {xref}{x-s}[] // -> xref:[] :xref: xref: :x-s: // * link to doc -> our macro // syntax: {linksrcdoc} // -> linksrcdoc:[] :linksrcdoc: linksrcdoc: // * link to doc -> our macro (optional 2/3/4 args) // syntax: {linkdoc}{ld-s}[{,{,{,}}}] // -> linkdoc:[{,{,{,}}}] :linkdoc: linkdoc: :ld-s: // * link to single doc -> our macro // syntax: {linksingledoc}{lsd-s}[] // -> linksingledoc:[] :linksingledoc: linksingledoc: :lsd-s: // * link to manpage -> our macro // syntax: {linkman2}{lm-s}{lm-c}{lm-e} // -> linkman2:[,] :linkman2: linkman2: :lm-s: [ :lm-c: , :lm-e: ] :linkmanext: https://www.die.net/search/?q= :linkmanext2: https://www.die.net/search/?q= endif::env-github[] // // - on GitHub: ifdef::env-github[] // In our normal builds, Makefile variables convey the needed paths // (used relatively below as `image:images/ci/...png` etc.) :imagesdir: docs // * xref -> link // syntax: {xref}{x-s}[] // In order for it to work, can reference at most a section of // level docs/common.xsl's // -> {website-url}docs/user-manual.chunked/.html[] :xref: {website-url}docs/user-manual.chunked/ :x-s: .html // * link to doc -> our macro // syntax: {linksrcdoc} // -> link:[] :linksrcdoc: link:{top_srcdir}/ // * link to doc -> link (FIXME: ignore or use 2/3/4 args; currently they are all pasted as contents!) // syntax: {linkdoc}{ld-s}[{,{,{,}}}] // -> {website-url}docs/.chunked/index.html[] :linkdoc: {website-url}docs/ :ld-s: .chunked/index.html // * link to single doc -> link // syntax: {linksingledoc}{lsd-s}[] // -> {website-url}docs/.html[] :linksingledoc: {website-url}docs/ :lsd-s: .html // * link to manpage -> link // syntax: {linkman2}{lm-s}{lm-c}{lm-e} // All the fields are mandatory. // -> {website-url}docs/man/.html[()] :linkman2: {website-url}docs/man/ :lm-s: .html[ :lm-c: ( :lm-e: )] :linkmanext: https://www.die.net/search/?q= :linkmanext2: https://www.die.net/search/?q= endif::env-github[] endif::asciidoc-vars-nut-included[] // //GH_MARKUP_1095_INCLUDE_END// Description ----------- Network UPS Tools is a collection of programs which provide a common interface for monitoring and administering UPS, PDU and SCD hardware. It uses a layered approach to connect all of the parts. Drivers are provided for a wide assortment of equipment. They understand the specific language of each device and map it back to a compatibility layer. This means both an expensive high end UPS, a simple "power strip" PDU, or any other power device can be handled transparently with a uniform management interface. This information is cached by the network server `upsd`, which then answers queries from the clients. upsd contains a number of access control features to limit the abilities of the clients. Only authorized hosts may monitor or control your hardware if you wish. Since the notion of monitoring over the network is built into the software, you can hang many systems off one large UPS, and they will all shut down together. You can also use NUT to power on, off or cycle your data center nodes, individually or globally through PDU outlets. Clients such as `upsmon` check on the status of the hardware and do things when necessary. The most important task is shutting down the operating system cleanly before the UPS runs out of power. Other programs are also provided to log information regularly, monitor status through your web browser, and more. NUT and the ecosystem --------------------- NUT comes pre-packaged for many operating systems and embedded in storage, automation or virtualization appliances, and is also often shipped as the software companion by several UPS vendors. Of course, it is quite normal and supported to build your own -- whether for an operating system which lacks it yet, or for an older distribution which lacks the current NUT version; whether to take advantage of new features or to troubleshoot a new UPS deployment with a debugger in hand. Given its core position at the heart of your systems' lifecycle, we make it a point to have current NUT building and running anywhere, especially where older releases did work before (including "abandonware" like the servers and OSes from the turn of millennium): if those boxes are still alive and in need of power protection, they should be able to get it. [TIP] ===== If you like how the NUT project helps protect your systems from power outages, please consider sponsoring or at least "starring" it on GitHub at https://github.com/networkupstools/nut/ - these stars are among metrics which the larger potential sponsors consider when choosing how to help FOSS projects. Keeping the lights shining in such a large non-regression build matrix is a big undertaking! ifndef::pdf_format[] image:https://api.star-history.com/svg?repos=networkupstools/nut&type=Date[link="https://star-history.com/#networkupstools/nut&Date" alt="NUT GitHub Star History Chart"] endif::pdf_format[] See <> for an overview of the shared effort. ===== As a FOSS project, for over a quarter of a century we welcome contributions of both core code (drivers and other features), build recipes and other integration elements to make it work on your favourite system, documentation revisions to make it more accessible to newcomers, as well as hardware vendor cooperation with first-hand driver and protocol submissions, and just about anything else you can think of. NUT Support Policy ~~~~~~~~~~~~~~~~~~ The Network UPS Tools project is a community-made open-source effort, primarily made and maintained by people donating their spare time. The support channels are likewise open, with preferred ones being link:https://github.com/networkupstools/nut/issues[the NUT project issue tracker on GitHub] and the NUT Users mailing list, as detailed at https://networkupstools.org/support.html page. Please keep in mind that any help is provided by community members just like yourself, as a best effort, and subject to their availability and experience. It is expected that you have read the Frequently Asked Questions, looked at the link:https://github.com/networkupstools/nut/wiki[NUT wiki], and have a good grasp about the three-layer design and programs involved in a running deployment of NUT, for a discussion to be constructive and efficient. Be patient, polite, and prepare to learn and provide information about your NUT deployment (version, configuration, OS...) and the device, to collect logs, and to answer any follow-up questions about your situation. Finally, note that NUT is packaged and delivered by packaging into numerous operating systems, appliances and monitoring projects, and may be bundled with third-party GUI clients. It may be wise of end-users to identify such cases and ask for help on the most-relevant forum (or several, including the NUT support channels). It is important to highlight that the NUT project releases have for a long time been essentially snapshots of better-tested code, and we do not normally issue patches to "hot-fix" any older releases. Any improvements of NUT itself are made in the current code base, same as any other feature development, so to receive desired fixes on your system (and/or to check that they do solve your particular issue), expect to be asked to build the recent development iteration from GitHub or work with your appliance vendor to get a software upgrade. Over time, downstream OS packaging or other integrations which use NUT, may issue patches as new package revisions, or new baseline versions of NUT, according to *their* release policies. It is not uncommon for distributions, especially "stable" flavours, to be a few years behind upstream projects. Installing ---------- If you are installing these programs for the first time, go read the {xref}_installation_instructions{x-s}[installation instructions] to find out how to do that. This document contains more information on what all of this stuff does. Upgrading --------- When upgrading from an older version, always check the {xref}Upgrading_notes{x-s}[upgrading notes] to see what may have changed. Compatibility issues and other changes will be listed there to ease the process. Configuring and using --------------------- Once NUT is installed, refer to the {xref}Configuration_notes{x-s}[configuration notes] for directions. Documentation ------------- This is just an overview of the software. You should read the man pages, included example configuration files, and auxiliary documentation for the parts that you intend to use. Network Information ------------------- These programs are designed to share information over the network. In the examples below, `localhost` is used as the hostname. This can also be an IP address or a fully qualified domain name. You can specify a port number if your upsd process runs on another port. In the case of the program `upsc`, to view the variables on the UPS called sparky on the `upsd` server running on the local machine, you'd do this: /usr/local/ups/bin/upsc sparky@localhost The default port number is 3493. You can change this with "configure --with-port" at compile-time. To make a client talk to upsd on a specific port, add it after the hostname with a colon, like this: /usr/local/ups/bin/upsc sparky@localhost:1234 This is handy when you have a mixed environment and some of the systems are on different ports. The general form for UPS identifiers is this: [@[:]] Keep this in mind when viewing the examples below. Manifest -------- This package is broken down into several categories: - *drivers* - These programs talk directly to your UPS hardware. - *server* - upsd serves data from the drivers to the network. - *clients* - They talk to upsd and do things with the status data. - *cgi-bin* - Special class of clients that you can use with your web server. - *scripts* - Contains various scripts, like the Perl and Python binding, integration bits and applications. Drivers ------- These programs provide support for specific UPS models. They understand the protocols and port specifications which define status information and convert it to a form that upsd can understand. To configure drivers, edit ups.conf. For this example, we'll have a UPS called "sparky" that uses the apcsmart driver and is connected to `/dev/ttyS1`. That's the second serial port on most Linux-based systems. The entry in `ups.conf` looks like this: [sparky] driver = apcsmart port = /dev/ttyS1 To start and stop drivers, use upsdrvctl of upsdrvsvcctl (installed on operating systems with a service management framework supported by NUT). By default, it will start or stop every UPS in the config file: /usr/local/ups/sbin/upsdrvctl start /usr/local/ups/sbin/upsdrvctl stop However, you can also just start or stop one by adding its name: /usr/local/ups/sbin/upsdrvctl start sparky /usr/local/ups/sbin/upsdrvctl stop sparky On operating systems with a supported service management framework, you might wrap your NUT drivers into individual services instances with: /usr/local/ups/sbin/upsdrvsvcctl resync and then manage those service instances with commands like: /usr/local/ups/sbin/upsdrvsvcctl start sparky /usr/local/ups/sbin/upsdrvsvcctl stop sparky To find the driver name for your device, refer to the section below called "HARDWARE SUPPORT TABLE". Extra Settings ~~~~~~~~~~~~~~ Some drivers may require additional settings to properly communicate with your hardware. If it doesn't detect your UPS by default, check the driver's man page or help (-h) to see which options are available. For example, the usbhid-ups driver allows you to use USB serial numbers to distinguish between units via the "serial" configuration option. To use this feature, just add another line to your ups.conf section for that UPS: [sparky] driver = usbhid-ups port = auto serial = 1234567890 Hardware Compatibility List ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The {xref}HCL{x-s}[Hardware Compatibility List] is available in the source directory ('nut-X.Y.Z/data/driver.list'), and is generally distributed with packages. For example, it is available on Debian systems as: /usr/share/nut/driver.list This table is also available link:{website-url}stable-hcl.html[online]. If your driver has vanished, see the {linksingledoc}FAQ{lsd-s}[FAQ] and {xref}Upgrading_notes{x-s}[Upgrading notes]. Generic Device Drivers ~~~~~~~~~~~~~~~~~~~~~~ NUT provides several generic drivers that support a variety of very similar models. - The `genericups` driver supports many serial models that use the same basic principle to communicate with the computer. This is known as "contact closure", and basically involves raising or lowering signals to indicate power status. + This type of UPS tends to be cheaper, and only provides the very simplest data about power and battery status. Advanced features like battery charge readings and such require a "smart" UPS and a driver which supports it. + See the {linkman2}genericups{lm-s}genericups{lm-c}8{lm-e} man page for more information. - The `usbhid-ups` driver attempts to communicate with USB HID Power Device Class (PDC) UPSes. These units generally implement the same basic protocol, with minor variations in the exact set of supported attributes. This driver also applies several correction factors when the UPS firmware reports values with incorrect scale factors. + See the {linkman2}usbhid-ups{lm-s}usbhid-ups{lm-c}8{lm-e} man page for more information. - The `nutdrv_qx` driver supports the Megatec / Q1 protocol that is used in many brands (Blazer, Energy Sistem, Fenton Technologies, Mustek, Voltronic Power and many others). + See the {linkman2}nutdrv_qx{lm-s}nutdrv_qx{lm-c}8{lm-e} man page for more information. - The `snmp-ups` driver handles various SNMP enabled devices, from many different manufacturers. In SNMP terms, `snmp-ups` is a manager, that monitors SNMP agents. + See the {linkman2}snmp-ups{lm-s}snmp-ups{lm-c}8{lm-e} man page for more information. - The `powerman-pdu` is a bridge to the PowerMan daemon, thus handling all PowerMan supported devices. The PowerMan project supports several serial and networked PDU, along with Blade and IPMI enabled servers. + See the {linkman2}powerman-pdu{lm-s}powerman-pdu{lm-c}8{lm-e} man page for more information. - The `apcupsd-ups` driver is a bridge to the Apcupsd daemon, thus handling all Apcupsd supported devices. The Apcupsd project supports many serial, USB and networked APC UPS. + See the {linkman2}apcupsd-ups{lm-s}apcupsd-ups{lm-c}8{lm-e} man page for more information. UPS Shutdowns ~~~~~~~~~~~~~ upsdrvctl can also shut down (power down) all of your UPS hardware. [WARNING] ========= If you play around with this command, expect your filesystems to die. Don't power off your computers unless they're ready for it: /usr/local/ups/sbin/upsdrvctl shutdown /usr/local/ups/sbin/upsdrvctl shutdown sparky ========= You should read the {xref}UPS_shutdown{x-s}[Configuring automatic UPS shutdowns] chapter to learn more about when to use this feature. If called at the wrong time, you may cause data loss by turning off a system with a filesystem mounted read-write. Power distribution unit management ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NUT also provides an advanced support for power distribution units. You should read the {xref}outlet_management{x-s}[NUT outlets management and PDU notes] chapter to learn more about when to use this feature. Network Server -------------- `upsd` is responsible for passing data from the drivers to the client programs via the network. It should be run immediately after `upsdrvctl` in your system's startup scripts. `upsd` should be kept running whenever possible, as it is the only source of status information for the monitoring clients like `upsmon`. Monitoring client ----------------- `upsmon` provides the essential feature that you expect to find in UPS monitoring software: safe shutdowns when the power fails. In the layered scheme of NUT software, it is a client. It has this separate section in the documentation since it is so important. You configure it by telling it about UPSes that you want to monitor in upsmon.conf. Each UPS can be defined as one of two possible types: a "primary" or "secondary". Primary ~~~~~~~ The monitored UPS possibly supplies power to this system running `upsmon`, but more importantly -- this system can manage the UPS (typically, this instance of `upsmon` runs on the same system as the `upsd` and driver(s)): it is capable and responsible for shutting it down when the battery is depleted (or in another approach, lingering to deplete it or to tell the UPS to reboot its load after too much time has elapsed and this system is still alive -- meaning wall power returned at a "wrong" moment). The shutdown of this (primary) system itself, as well as eventually an UPS shutdown, occurs after any secondary systems ordered to shut down first have disconnected, or a critical urgency threshold was passed. If your UPS is plugged directly into a system's serial or USB port, the `upsmon` process on that system should define its relation to that UPS as a primary. It may be more complicated for higher-end UPSes with a shared network management capability (typically via SNMP) or several serial/USB ports that can be used simultaneously, and depends on what vendors and drivers implement. Setups with several competing primaries (for redundancy) are technically possible, if each one runs its own full stack of NUT, but results can be random (currently NUT does not provide a way to coordinate several entities managing the same device). For a typical home user, there's one computer connected to one UPS. That means you would run on the same computer the whole NUT stack -- a suitable driver, `upsd`, and `upsmon` in primary mode. Secondary ~~~~~~~~~ The monitored UPS may supply power to the system running `upsmon` (or alternatively, it may be a monitoring station with zero PSUs fed by that UPS), but more importantly, this system can't manage the UPS -- e.g. shut it down directly (through a locally running NUT driver). Use this mode when you run multiple computers on the same UPS. Obviously, only one can be connected to the serial or USB port on a typical UPS, and that system is the primary. Everything else is a secondary. For a typical home user, there's one computer connected to one UPS. That means you run a driver, `upsd`, and `upsmon` in primary mode. Additional Information ~~~~~~~~~~~~~~~~~~~~~~ More information on configuring upsmon can be found in these places: - The {linkman2}upsmon{lm-s}upsmon{lm-c}8{lm-e} man page - {xref}BigServers{x-s}[Typical setups for big servers] - {xref}UPS_shutdown{x-s}[Configuring automatic UPS shutdowns] chapter - The stock `upsmon.conf` that comes with the package Clients ------- Clients talk to upsd over the network and do useful things with the data from the drivers. There are tools for command line access, and a few special clients which can be run through your web server as CGI programs. For more details on specific programs, refer to their man pages. upsc ~~~~ `upsc` is a simple client that will display the values of variables known to `upsd` and your UPS drivers. It will list every variable by default, or just one if you specify an additional argument. This can be useful in shell scripts for monitoring something without writing your own network code. `upsc` is a quick way to find out if your driver(s) and upsd are working together properly. Just run `upsc ` to see what's going on, i.e.: morbo:~$ upsc sparky@localhost ambient.humidity: 035.6 ambient.humidity.alarm.maximum: NO,NO ambient.humidity.alarm.minimum: NO,NO ambient.temperature: 25.14 ... If you are interested in writing a simple client that monitors `upsd`, the source code for `upsc` is a good way to learn about using the upsclient functions. See the {linkman2}upsc{lm-s}upsc{lm-c}8{lm-e} man page and {xref}nut-names{x-s}[NUT command and variable naming scheme] for more information. upslog ~~~~~~ `upslog` will write status information from `upsd` to a file at set intervals. You can use this to generate graphs or reports with other programs such as `gnuplot`. upsrw ~~~~~ `upsrw` allows you to display and change the read/write variables in your UPS hardware. Not all devices or drivers implement this, so this may not have any effect on your system. A driver that supports read/write variables will give results like this: ---- $ upsrw sparky@localhost ( many skipped ) [ups.test.interval] Interval between self tests Type: ENUM Option: "1209600" Option: "604800" SELECTED Option: "0" ( more skipped ) ---- On the other hand, one that doesn't support them won't print anything: ---- $ upsrw fenton@gearbox ( nothing ) ---- `upsrw` requires administrator powers to change settings in the hardware. Refer to {linkman2}upsd.users{lm-s}upsd.users{lm-c}5{lm-e} for information on defining users in `upsd`. upscmd ~~~~~~ Some UPS hardware and drivers support the notion of an instant command - a feature such as starting a battery test, or powering off the load. You can use upscmd to list or invoke instant commands if your hardware/drivers support them. Use the -l command to list them, like this: ---- $ upscmd -l sparky@localhost Instant commands supported on UPS [sparky@localhost]: load.on - Turn on the load immediately test.panel.start - Start testing the UPS panel calibrate.start - Start run time calibration calibrate.stop - Stop run time calibration ... ---- `upscmd` requires administrator powers to start instant commands. To define users and passwords in `upsd`, see {linkman2}upsd.users{lm-s}upsd.users{lm-c}5{lm-e}. CGI Programs ------------ The CGI programs are clients that run through your web server. They allow you to see UPS status and perform certain administrative commands from any web browser. Javascript and cookies are not required. These programs are not installed or compiled by default. To compile and install them, first run `configure --with-cgi`, then do `make` and `make install`. If you receive errors about "gd" during configure, go get it and install it before continuing. You can get the source here: - http://www.libgd.org/ In the event that you need libpng or zlib in order to compile gd, they can be found at these URLs: - http://www.libpng.org/pub/png/pngcode.html - http://www.zlib.net/ Access Restrictions ~~~~~~~~~~~~~~~~~~~ The CGI programs use hosts.conf to see if they are allowed to talk to a host. This keeps malicious visitors from creating queries from your web server to random hosts on the Internet. If you get error messages that say "Access to that host is not authorized", you're probably missing an entry in your hosts.conf. upsstats ~~~~~~~~ `upsstats` generates web pages from HTML templates, and plugs in status information in the right places. It looks like a distant relative of APC's old Powerchute interface. You can use it to monitor several systems or just focus on one. It also can generate IMG references to `upsimage`. upsimage ~~~~~~~~ This is usually called by upsstats via IMG SRC tags to draw either the utility or outgoing voltage, battery charge percent, or load percent. upsset ~~~~~~ `upsset` provides several useful administration functions through a web interface. You can use `upsset` to kick off instant commands on your UPS hardware like running a battery test. You can also use it to change variables in your UPS that accept user-specified values. Essentially, `upsset` provides the functions of `upsrw` and `upscmd`, but with a happy pointy-clicky interface. `upsset` will not run until you convince it that you have secured your system. You *must* secure your CGI path so that random interlopers can't run this program remotely. See the `upsset.conf` file. Once you have secured the directory, you can enable this program in that configuration file. It is not active by default. Version Numbering ----------------- The version numbers historically worked like this: if the middle number is odd, it's a development tree, otherwise it is the stable tree. The past stable trees were 1.0, 1.2, 1.4, 2.0, 2.2 and 2.4, with the latest such stable tree designated 2.6. The development trees were 1.1, 1.3, 1.5, 2.1 and 2.3. Since the 2.4 release, there is no real separate development branch anymore since the code is available through a revision control system (namely, Git -- or actually Subversion back then), development happens in feature branches that are eventually merged into the main trunk, and its snapshots become published releases. As a result, subsequent versions (2.7 and 2.8) were released without regard for even/odd values of the minor version component. Since 2.7 line of releases, sources are tracked in Git revision control system, with the project ecosystem being hosted on GitHub, and any code improvements or other contributions merged through common pull request approach and custom NUT CI testing on multiple platforms. Major release jumps are mostly due to large changes to the features list. There have also been a number of architectural changes which may not be noticeable to most users, but which can impact developers. Since NUT v2.8.2 or so, development iterations have additional version components, to account for the amount of commits on the main branch (`master`) since the last known Git tag, and amount of commits on the developed feature branch that are unique to it compared to main branch. This allows for a reasonably growing version of stable baseline and local development, so that experimental packages can be installed as upgrades (or well-exposed downgrades). While the NUT releases retain the semantic versioning three-component standard, interim builds (trunk snapshots and development branches) can expose a much more complex structure with the amount of commits in the trunk since last release, and amount of commits on the branch unique to it (not in the trunk). Additional data may include overall amount of commits in the current build since last release, and the git commit has identifier of the built code base. More details can be seen in `docs/nut-versioning.adoc` file in the NUT source code base. Backwards and Forwards Compatibility ------------------------------------ The network protocol for the current version of NUT should be backwards-compatible all the way back to version 1.4. A newer client should fail gracefully when querying an older server. If you need more details about cross-compatibility of older NUT releases (1.x vs. 2.x), please see the {xref}Project_History{x-s}[Project history] chapter. Support / Help / etc. --------------------- If you are in need of help, refer to the {xref}Support_Request{x-s}[Support instructions] in the user manual. Hacking / Development Info -------------------------- Additional documentation can be found in: - the {linkdoc}developer-guide{ld-s}[Developer Guide], - the {linkdoc}packager-guide{ld-s}[Packager Guide]. Acknowledgements / Contributions -------------------------------- The many people who have participated in creating and improving NUT are listed in the user manual {xref}Acknowledgements{x-s}[acknowledgements appendix]. [[acknowledgements-ci-ops]] We would like to highlight some organizations which provide continuous support to the NUT project (and many other FOSS projects) on technological and organizational sides, such as helping keep the donations transparent, NUT CI farm afloat, and public resources visible. Thanks for keeping the clocks ticking, day and night: //////////// FIXME: Use different (better-resolution) images for PDF rendering? FIXME: PDF cells seem to align weirdly, like setting the bottom of the first line of text to be on the same level as bottom of the image, or similar to that. NOTE: GitHub renderer (or CSS stack?) ignores style settings and squashes the logo column into a fixed-width monster with either our specified heights, or with teeny-tiny thumbnail magnitude images, so it is prettier to leave it as a "single-column table" by default. Grid/Frame settings are also ignored, but we can try our best anyway. NOTE: The classic asciidoc/a2x renderer seems to not support link/url options, but at least does not complain about them either. //////////// ifndef::env-github[] [frame="none",grid="none",cols="^.<1,<.<2"] endif::env-github[] ifdef::env-github[] [frame="none",grid="none",cols="<1*"] endif::env-github[] |=== | image:images/ci/GitHub-Mark-140pxW.png[alt="GitHub logo",width="140",height="140",link="https://github.com/"] | The link:https://github.com/networkupstools/["NetworkUPSTools" organization on GitHub] arranges a lot of things, including source code hosting for NUT itself and several related projects, team management, projects, issue and pull request discussions, sponsorship, nut-website rendering and hosting, some automated actions, and more... | image:images/ci/jenkins-nut-transparent-bg-140pxW.png[alt="Jenkins and NUT logo",width="139",height="104",link="https://www.jenkins.io/"] | The link:https://www.jenkins.io/[Jenkins CI] project and its huge plugin ecosystem provides the technological foundation for the largest island of the link:https://ci.networkupstools.org/[self-hosted NUT CI farm]. There is a fair amount of cross-pollination between the upstream project and community, and the development done originally for the NUT CI farm. See more at link:https://stories.jenkins.io/user-story/jenkins-is-the-way-for-networkupstools/[Jenkins is the way to build multi-platform NUT] article. | image:images/ci/fosshost_org_Host_Light_38px.png[alt="Fosshost logo",width="112",height="38"] | Fosshost provided virtual machines where the multi-platform NUT CI farm with a link:https://github.com/networkupstools/jenkins-dynamatrix/[jenkins-dynamatrix] link:https://github.com/networkupstools/nut/blob/master/Jenkinsfile-dynamatrix[setup] runs to arrange builds in numerous operating environments and a lot of toolkit versions and implementations. Some workers running on NUT community members' machines can also dial in to provide an example of their favourite platforms. Literally hundreds of NUT builds run for each iteration, to make sure NUT can always build and work everywhere. This allows us to ensure that NUT remains portable across two decades' worth of operating systems, compilers, script interpreters, tools and third-party dependencies. | image:images/ci/CircleCI_vertical_black_logo.png[alt="CircleCI logo",width="130",height="107",link="https://circleci.com/"] | The link:https://app.circleci.com/pipelines/github/networkupstools/nut/[CircleCI NUT pipeline] allows us to test NUT CI builds on MacOS. | image:images/ci/AppVeyor_logo-ar21.png[alt="AppVeyor logo",width="120",height="60",link="https://www.appveyor.com/"] | The link:https://ci.appveyor.com/project/nut-travis/nut/[AppVeyor NUT pipeline] allows us to test NUT CI builds on Windows (and publish preview tarballs with binaries). | image:images/ci/DO_Powered_by_Badge_blue_140pxW.png[alt="DigitalOcean logo",width="140",height="29",link="https://www.digitalocean.com/?refcode=d2fbf2b9e082&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge"] | The link:https://www.digitalocean.com/?refcode=d2fbf2b9e082&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge[DigitalOcean] droplets allow us to host NUT CI farm Jenkins controller and the build agents for multiple operating systems. | image:images/ci/gandi-ar21.png[alt="Gandi.Net logo",width="120",height="60",link="https://www.gandi.net/"] | link:https://www.gandi.net/[Gandi.Net] took up the costs of NUT DNS hosting. | image:images/ci/OC_logo_merged_140x26.png[alt="Open Collective logo",width="140",height="26",link="https://opencollective.com/"] | https://opencollective.com/networkupstools allows us to arrange monetary donations and spending, with public transparency of everything that happens. |=== nut-2.8.4/test-driver0000755000175000017500000001141715045354761011470 00000000000000#! /bin/sh # test-driver - basic testsuite driver script. scriptversion=2018-03-07.03; # UTC # Copyright (C) 2011-2021 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # This file is maintained in Automake, please report # bugs to or send patches to # . # Make unconditional expansion of undefined variables an error. This # helps a lot in preventing typo-related bugs. set -u usage_error () { echo "$0: $*" >&2 print_usage >&2 exit 2 } print_usage () { cat <"$log_file" "$@" >>"$log_file" 2>&1 estatus=$? if test $enable_hard_errors = no && test $estatus -eq 99; then tweaked_estatus=1 else tweaked_estatus=$estatus fi case $tweaked_estatus:$expect_failure in 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 0:*) col=$grn res=PASS recheck=no gcopy=no;; 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; *:*) col=$red res=FAIL recheck=yes gcopy=yes;; esac # Report the test outcome and exit status in the logs, so that one can # know whether the test passed or failed simply by looking at the '.log' # file, without the need of also peaking into the corresponding '.trs' # file (automake bug#11814). echo "$res $test_name (exit status: $estatus)" >>"$log_file" # Report outcome to console. echo "${col}${res}${std}: $test_name" # Register the test result, and other relevant metadata. echo ":test-result: $res" > $trs_file echo ":global-test-result: $res" >> $trs_file echo ":recheck: $recheck" >> $trs_file echo ":copy-in-global-log: $gcopy" >> $trs_file # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: nut-2.8.4/include/0000755000175000017500000000000015045366652010773 500000000000000nut-2.8.4/include/wincompat.h0000644000175000017500000002543715000736161013063 00000000000000#ifndef NUT_WINCOMPAT_H #define NUT_WINCOMPAT_H 1 /* Copyright (C) 2001 Andrew Delpha (delpha@computer.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, WRITE to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* This header is provided to map Windows system calls to be compatible with the NUT code. */ #include "common.h" #include #include "nut_stdint.h" /* Used in ifdef code blocks that were not yet implemented as part of * the NUT for Windows upstreaming as a first-class citizen code base. * For more details, see: * https://github.com/networkupstools/nut/wiki/NUT-for-Windows * https://github.com/orgs/networkupstools/projects/2/views/1 * https://github.com/networkupstools/nut/issues?q=+label%3AWindows-not-on-par-with-POSIX+sort%3Aupdated-desc+ */ #define NUT_WIN32_INCOMPLETE_DETAILED(str) upsdebugx(1, "%s:%" PRIiMAX "::%s() : this method was not fully ported for WIN32: %s", __FILE__, (intmax_t)__LINE__, __func__, NUT_STRARG(str)) #define NUT_WIN32_INCOMPLETE() upsdebugx(1, "%s:%" PRIiMAX "::%s() : this method was not fully ported for WIN32", __FILE__, (intmax_t)__LINE__, __func__) #define NUT_WIN32_INCOMPLETE_LOGWARN() upslogx(LOG_WARNING, "WARNING: %s:%" PRIiMAX "::%s() : this method was not fully ported for WIN32", __FILE__, (intmax_t)__LINE__, __func__) /* These use-cases need to be revised, maybe hushed later: */ #define NUT_WIN32_INCOMPLETE_MAYBE_NOT_APPLICABLE() NUT_WIN32_INCOMPLETE_DETAILED("may be not applicable to the platform") /* This value is defined in the error.h file of the libusb-win32 sources * FIXME: Should only be relevant for builds WITH_LIBUSB_0_1 - #ifdef it so? * Conflicts with e.g. /msys64/mingw64/include/errno.h which defines it as 138 */ #ifndef ETIMEDOUT # define ETIMEDOUT 116 #endif #define random() rand() typedef const char * uid_t; struct passwd { const char *pw_name; int pw_uid; /* Fake value, alwaus set to 0 */ }; uid_t getuid(void); struct passwd *getpwuid(uid_t uid); char *getpass( const char *prompt); #define system(a) win_system(a) #define sleep(n) Sleep(1000 * n) char * strtok_r(char *str, const char *delim, char **saveptr); char * filter_path(const char * source); /* Network compatibility */ /* This is conditional because read/write are generic in unix, and this will make them network specific */ #ifdef W32_NETWORK_CALL_OVERRIDE #define close(h) sktclose(h) #define read(h,b,s) sktread(h,b,s) #define write(h,b,s) sktwrite( h ,(char *) b , s ) #define connect(h,n,l) sktconnect(h,n,l) #endif #ifndef strcasecmp #define strcasecmp(a,b) _stricmp(a,b) #endif #ifndef snprintf #define snprintf _snprintf #endif #ifndef vsnprintf #define vsnprintf _vsnprintf #endif int sktconnect(int fh, struct sockaddr * name, int len); int sktread(int fh, char *buf, int size); int sktwrite(int fh, char *buf, int size); int sktclose(int fh); #if ! HAVE_INET_NTOP /* NOTE: This fallback can get used on systems that do have inet_ntop() * but their antivirus precluded the configure-script test program linking. * A symptom of that would be: * warning: 'inet_ntop' redeclared without dllimport attribute: * previous dllimport ignored [-Wattributes] * ...and adding the attributes would cause a conflict of private fallback * and system DLL symbols. So the lesser of two evils, we use fallback. * People who see the warning should however fix their build environment * and use the native OS-provided implementation ;) */ # if (0) /* Some old winapi? or just sloppy original commits? * Why is this here at all if there's something per ws2tcpip.h - * maybe should be configure-detected? */ const char* inet_ntop(int af, const void* src, char* dst, int cnt); # else const char* inet_ntop(int af, const void* src, char* dst, size_t /* socklen_t */ cnt); # endif #endif #if ! HAVE_INET_PTON int inet_pton(int af, const char *src, void *dst); #endif /* from the MSDN getaddrinfo documentation : */ #define EAI_AGAIN WSATRY_AGAIN #define EAI_BADFLAGS WSAEINVAL #define EAI_FAIL WSANO_RECOVERY #define EAI_FAMILY WSAEAFNOSUPPORT #define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY #define EAI_NONAME WSAHOST_NOT_FOUND #define EAI_SERVICE WSATYPE_NOT_FOUND #define EAI_SOCKTYPE WSAESOCKTNOSUPPORT /* not from MS docs : */ #define EAI_SYSTEM WSANO_RECOVERY #ifndef EAFNOSUPPORT # define EAFNOSUPPORT WSAEAFNOSUPPORT #endif /* "system" function */ int win_system(const char * command); /* syslog compatibility */ void syslog(int priority, const char *fmt, ...); extern const char * EventLogName; /* Signal emulation via named pipe */ typedef struct pipe_conn_s { HANDLE handle; OVERLAPPED overlapped; char buf[LARGEBUF]; struct pipe_conn_s *prev; struct pipe_conn_s *next; } pipe_conn_t; extern pipe_conn_t *pipe_connhead; extern OVERLAPPED pipe_connection_overlapped; void pipe_create(const char * pipe_name); void pipe_connect(); void pipe_disconnect(pipe_conn_t *conn); int pipe_ready(pipe_conn_t *conn); int send_to_named_pipe(const char * pipe_name, const char * data); #define COMMAND_FSD "COMMAND_FSD" #define COMMAND_STOP "COMMAND_STOP" #define COMMAND_RELOAD "COMMAND_RELOAD" /* serial function compatibility */ int w32_setcomm ( serial_handler_t * h, int * flags ); int w32_getcomm ( serial_handler_t * h, int * flags ); int tcsendbreak (serial_handler_t * sh, int duration); typedef unsigned char cc_t; typedef unsigned int speed_t; typedef unsigned int tcflag_t; #define NCCS 19 struct termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ cc_t c_cc[NCCS]; /* control characters */ speed_t c_ispeed; /* input speed */ speed_t c_ospeed; /* output speed */ }; serial_handler_t * w32_serial_open (const char *name, int flags); int w32_serial_close (serial_handler_t * sh); int w32_serial_write (serial_handler_t * sh, const void *ptr, size_t len); int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeout); int tcgetattr (serial_handler_t * sh, struct termios *t); int tcsetattr (serial_handler_t * sh, int action, const struct termios *t); int tcflush (serial_handler_t * sh, int queue); #define HAVE_CFSETISPEED void cfsetispeed(struct termios * t, speed_t speed); void cfsetospeed(struct termios * t, speed_t speed); speed_t cfgetispeed(const struct termios *t); speed_t cfgetospeed(const struct termios *t); #define _POSIX_VDISABLE '\0' /* c_cc characters */ #define VINTR 0 #define VQUIT 1 #define VERASE 2 #define VKILL 3 #define VEOF 4 #define VTIME 5 #define VMIN 6 #define VSWTC 7 #define VSTART 8 #define VSTOP 9 #define VSUSP 10 #define VEOL 11 #define VREPRINT 12 #define VDISCARD 13 #define VWERASE 14 #define VLNEXT 15 #define VEOL2 16 /* c_iflag bits */ #define IGNBRK 0000001 #define BRKINT 0000002 #define IGNPAR 0000004 #define PARMRK 0000010 #define INPCK 0000020 #define ISTRIP 0000040 #define INLCR 0000100 #define IGNCR 0000200 #define ICRNL 0000400 #define IUCLC 0001000 #define IXON 0002000 #define IXANY 0004000 #define IXOFF 0010000 #define IMAXBEL 0020000 #define IUTF8 0040000 /* c_oflag bits */ #define OPOST 0000001 #define OLCUC 0000002 #define ONLCR 0000004 #define OCRNL 0000010 #define ONOCR 0000020 #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 #define NLDLY 0000400 #define NL0 0000000 #define NL1 0000400 #define CRDLY 0003000 #define CR0 0000000 #define CR1 0001000 #define CR2 0002000 #define CR3 0003000 #define TABDLY 0014000 #define TAB0 0000000 #define TAB1 0004000 #define TAB2 0010000 #define TAB3 0014000 #define XTABS 0014000 #define BSDLY 0020000 #define BS0 0000000 #define BS1 0020000 #define VTDLY 0040000 #define VT0 0000000 #define VT1 0040000 #define FFDLY 0100000 #define FF0 0000000 #define FF1 0100000 /* c_cflag bit meaning */ #define CBAUD 0010017 #define B0 0000000 /* hang up */ #define B50 0000001 #define B75 0000002 #define B110 0000003 #define B134 0000004 #define B150 0000005 #define B200 0000006 #define B300 0000007 #define B600 0000010 #define B1200 0000011 #define B1800 0000012 #define B2400 0000013 #define B4800 0000014 #define B9600 0000015 #define B19200 0000016 #define B38400 0000017 #define EXTA B19200 #define EXTB B38400 #define CSIZE 0000060 #define CS5 0000000 #define CS6 0000020 #define CS7 0000040 #define CS8 0000060 #define CSTOPB 0000100 #define CREAD 0000200 #define PARENB 0000400 #define PARODD 0001000 #define HUPCL 0002000 #define CLOCAL 0004000 #define CBAUDEX 0010000 #define BOTHER 0010000 #define B57600 0010001 #define B115200 0010002 #define B230400 0010003 #define B460800 0010004 #define B500000 0010005 #define B576000 0010006 #define B921600 0010007 #define B1000000 0010010 #define B1152000 0010011 #define B1500000 0010012 #define B2000000 0010013 #define B2500000 0010014 #define B3000000 0010015 #define B3500000 0010016 #define B4000000 0010017 #define CIBAUD 002003600000 /* input baud rate */ #define CMSPAR 010000000000 /* mark or space (stick) parity */ #define CRTSCTS 020000000000 /* flow control */ #define IBSHIFT 16 /* Shift from CBAUD to CIBAUD */ /* c_lflag bits */ #define ISIG 0000001 #define ICANON 0000002 #define XCASE 0000004 #define ECHO 0000010 #define ECHOE 0000020 #define ECHOK 0000040 #define ECHONL 0000100 #define NOFLSH 0000200 #define TOSTOP 0000400 #define ECHOCTL 0001000 #define ECHOPRT 0002000 #define ECHOKE 0004000 #define FLUSHO 0010000 #define PENDIN 0040000 #define IEXTEN 0100000 /* tcflow() and TCXONC use these */ #define TCOOFF 0 #define TCOON 1 #define TCIOFF 2 #define TCION 3 /* tcflush() and TCFLSH use these */ #define TCIFLUSH 0 #define TCOFLUSH 1 #define TCIOFLUSH 2 /* tcsetattr uses these */ #define TCSANOW 0 #define TCSADRAIN 1 #define TCSAFLUSH 2 #define TIOCM_DTR 0x0001 #define TIOCM_RTS 0x0002 #define TIOCM_ST 0x0004 #define TIOCM_CTS MS_CTS_ON /* 0x0010*/ #define TIOCM_DSR MS_DSR_ON /* 0x0020*/ #define TIOCM_RNG MS_RING_ON /*0x0040*/ #define TIOCM_RI TIOCM_RNG /* at least that's the definition in Linux */ #define TIOCM_CD MS_RLSD_ON /*0x0080*/ #endif /* NUT_WINCOMPAT_H */ nut-2.8.4/include/nut_bool.h0000664000175000017500000000741715000733176012706 00000000000000/* * nut_bool.h - Network UPS Tools boolean type definitions * which should ensure a "nut_bool_t" name with * lower-case values "true" and "false" * * Inspired by earlier efforts and numerous definitions in NUT codebase. * Copyright (C) 2024 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_BOOL_H_SEEN #define NUT_BOOL_H_SEEN 1 #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif /* See also https://en.cppreference.com/w/cpp/header/cstdbool for more * info about what should be available where per standard approach. */ #ifdef __cplusplus # if defined HAVE_CSTDBOOL_H || defined HAVE_CSTDBOOL # include # else # ifdef HAVE_STDBOOL_H # include # endif # endif #else /* plain C */ # ifdef HAVE_STDBOOL_H # include # endif #endif /* Is the goal achieved by the system headers or compiler itself, * so we can just alias to existing type and its values? */ #if defined __bool_true_false_are_defined && __bool_true_false_are_defined typedef bool nut_bool_t; #elif defined FOUND__BOOL_TYPE && defined HAVE__BOOL_VALUE_LOWERCASE typedef FOUND__BOOL_TYPE nut_bool_t; #elif defined FOUND_BOOL_TYPE && defined HAVE_BOOL_VALUE_LOWERCASE typedef FOUND_BOOL_TYPE nut_bool_t; #elif defined FOUND_BOOLEAN_TYPE && defined HAVE_BOOLEAN_VALUE_LOWERCASE typedef FOUND_BOOLEAN_TYPE nut_bool_t; #elif defined FOUND_BOOL_T_TYPE && defined HAVE_BOOL_T_VALUE_LOWERCASE typedef FOUND_BOOL_T_TYPE nut_bool_t; #else /* Need a new type; can we use an enum with lower-case values? */ # if (defined true && defined false) || defined HAVE__BOOL_VALUE_LOWERCASE || defined HAVE_BOOL_VALUE_LOWERCASE || defined HAVE_BOOLEAN_VALUE_LOWERCASE || defined HAVE_BOOL_T_VALUE_LOWERCASE /* Lower-case true/false are known */ # if defined FOUND__BOOL_TYPE /* Got a C99 built-in mandated by the standard */ typedef FOUND__BOOL_TYPE nut_bool_t; # else typedef int nut_bool_t; # endif # elif defined FOUND__BOOL_VALUE_TRUE && defined FOUND__BOOL_VALUE_FALSE typedef enum nut_bool_enum { false = FOUND__BOOL_VALUE_FALSE, true = FOUND__BOOL_VALUE_TRUE } nut_bool_t; # elif defined FOUND_BOOL_VALUE_TRUE && defined FOUND_BOOL_VALUE_FALSE typedef enum nut_bool_enum { false = FOUND_BOOL_VALUE_FALSE, true = FOUND_BOOL_VALUE_TRUE } nut_bool_t; # elif defined FOUND_BOOLEAN_VALUE_TRUE && defined FOUND_BOOLEAN_VALUE_FALSE typedef enum nut_bool_enum { false = FOUND_BOOLEAN_VALUE_FALSE, true = FOUND_BOOLEAN_VALUE_TRUE } nut_bool_t; # elif defined FOUND_BOOL_T_VALUE_TRUE && defined FOUND_BOOL_T_VALUE_FALSE typedef enum nut_bool_enum { false = FOUND_BOOL_T_VALUE_FALSE, true = FOUND_BOOL_T_VALUE_TRUE } nut_bool_t; # else typedef enum nut_bool_enum { false = 0, true = 1 } nut_bool_t; # endif #endif #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_BOOL_H_SEEN */ nut-2.8.4/include/timehead.h0000644000175000017500000000630015000736161012626 00000000000000/* timehead.h - from the autoconf docs: sanely include the right time headers everywhere Copyright (C) 2001 Russell Kroll 2005 Arnaud Quette 2020-2025 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_TIMEHEAD_H_SEEN #define NUT_TIMEHEAD_H_SEEN 1 #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif #ifdef TIME_WITH_SYS_TIME # include # include #else # ifdef HAVE_SYS_TIME_H # include # else # include # endif #endif #ifndef HAVE_STRPTIME /* Use fallback implementation provided in e.g. libcommon(client).la: */ char * strptime(const char *buf, const char *fmt, struct tm *tm); #endif #if !(defined HAVE_LOCALTIME_R && HAVE_LOCALTIME_R) && !(defined HAVE_DECL_LOCALTIME_R && HAVE_DECL_LOCALTIME_R) # if (defined HAVE_LOCALTIME_S && HAVE_LOCALTIME_S) || (defined HAVE_DECL_LOCALTIME_S && HAVE_DECL_LOCALTIME_S) /* A bit of a silly trick, but should help on MSYS2 builds it seems * errno_t localtime_s(struct tm *_Tm, const time_t *_Time) */ # define localtime_r(timer, buf) (localtime_s(buf, timer) ? NULL : buf) # else # include /* memcpy */ static inline struct tm *localtime_r( const time_t *timer, struct tm *buf ) { /* Note NUT_WIN32_INCOMPLETE : not thread-safe per se! */ struct tm *tmp = localtime (timer); memcpy(buf, tmp, sizeof(struct tm)); return buf; } # endif #endif #if !(defined HAVE_GMTIME_R && HAVE_GMTIME_R) && !(defined HAVE_DECL_GMTIME_R && HAVE_DECL_GMTIME_R) # if (defined HAVE_GMTIME_S && HAVE_GMTIME_S) || (defined HAVE_DECL_GMTIME_S && HAVE_DECL_GMTIME_S) /* See comment above */ # define gmtime_r(timer, buf) (gmtime_s(buf, timer) ? NULL : buf) # else # include /* memcpy */ static inline struct tm *gmtime_r( const time_t *timer, struct tm *buf ) { /* Note NUT_WIN32_INCOMPLETE : not thread-safe per se! */ struct tm *tmp = gmtime (timer); memcpy(buf, tmp, sizeof(struct tm)); return buf; } # endif #endif #if !(defined HAVE_TIMEGM && HAVE_TIMEGM) && !(defined HAVE_DECL_TIMEGM && HAVE_DECL_TIMEGM) # if (defined HAVE__MKGMTIME && HAVE__MKGMTIME) || (defined HAVE_DECL__MKGMTIME && HAVE_DECL__MKGMTIME) # define timegm(tm) _mkgmtime(tm) # else # ifdef WANT_TIMEGM_FALLBACK /* use an implementation from fallbacks in NUT codebase */ # define timegm(tm) timegm_fallback(tm) # else # error "No fallback implementation for timegm" # endif # endif #endif #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_TIMEHEAD_H_SEEN */ nut-2.8.4/include/nutconf.hpp0000644000175000017500000033606015044656702013105 00000000000000/* nutconf.hpp - Nut configuration file manipulation API Copyright (C) 2012 Eaton Author: Emilien Kia Copyright (C) 2024-2025 NUT Community Author: Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUTCONF_H_SEEN #define NUTCONF_H_SEEN 1 #include "nutstream.hpp" #include #include #include #include #include #include #include #include #include #include /* See include/common.h for details behind this */ #ifndef NUT_UNUSED_VARIABLE #define NUT_UNUSED_VARIABLE(x) (void)(x) #endif #ifdef __cplusplus namespace nut { class NutParser; class NutConfigParser; class DefaultConfigParser; class GenericConfigParser; /** * Helper to specify if a configuration variable is set or not. * In addition of its value. */ template class Settable { protected: Type _value; bool _set; std::string errMsg_ENOTSET()const { static const std::string msg = "Can not retrieve a Settable value of " "an instance that was not assigned yet " "(or was last known cleared)"; return msg; } public: Settable():_set(false){} Settable(const Settable& val):_value(val._value), _set(val._set){} Settable(const Type& val):_value(val), _set(true){} /* Avoid implicit copy/move operator declarations */ Settable(Settable&&) = default; Settable& operator=(const Settable&) = default; Settable& operator=(Settable&&) = default; bool set()const{return _set;} void clear(){_set = false;} operator const Type&()const #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (!set()) throw std::invalid_argument(errMsg_ENOTSET()); return _value; } operator Type&() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (!set()) throw std::invalid_argument(errMsg_ENOTSET()); return _value; } const Type& operator *()const #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (!set()) throw std::invalid_argument(errMsg_ENOTSET()); return _value; } Type& operator *() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (!set()) throw std::invalid_argument(errMsg_ENOTSET()); return _value; } Settable& operator=(const Type& val){_value = val; _set = true; return *this;} bool operator==(const Settable& val)const { if(!set() && !val.set()) return false; else return (set() && val.set() && _value==val._value); } bool operator==(const Type& val)const #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if(!set()) return false; else try { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif // some compilers are concerned that Settable._value // may be queried as un-initialized here (for equality) // but we are supposed to rule that out with "if set()"... return _value == val; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED) #pragma GCC diagnostic pop #endif } catch(...) { throw std::invalid_argument(errMsg_ENOTSET()); } } }; /** * \brief Serialisable interface * * Classes that implement this interface provide way to serialize * and deserialize instances to/from streams. */ class Serialisable { protected: /** Formal constructor */ Serialisable() {} public: /** * \brief Deserializer * * \param istream Input stream * * \retval true in case of success * \retval false in case of read error */ virtual bool parseFrom(NutStream & istream) = 0; /** * \brief Serializer * * \param ostream Output stream * * \retval true in case of success * \retval false in case of write error */ virtual bool writeTo(NutStream & ostream) const = 0; /** Destructor */ virtual ~Serialisable(); }; // end of class Serialisable /** * \brief Mix a boolean (yes/no) or wider integer range */ class BoolInt { private: Settable b; Settable i; public: /** If set, its value specifies if we want i==0/1 to mean false/true * in value-equality and type-cast operators for int and bool types. * NOTE: If true, assignment from "0" and "1" strings sets the int * not bool stored value representation! * NOTE: Survives the clear() call which applies to stored value, * but would be reset by assignment from another BoolInt object. */ Settable bool01; /** Leave all contents un-set */ BoolInt() { clearWithBool01(); } BoolInt(const bool val) { *this = val; } BoolInt(const bool val, bool newBool01) { this->bool01 = newBool01; *this = val; } BoolInt(const int val) { *this = val; } BoolInt(const int val, bool newBool01) { this->bool01 = newBool01; *this = val; } BoolInt(const char* val) { *this = val; } BoolInt(const char* val, bool newBool01) { this->bool01 = newBool01; *this = val; } BoolInt(const std::string &val) { *this = val; } BoolInt(const std::string &val, bool newBool01) { this->bool01 = newBool01; *this = val; } BoolInt(const BoolInt& other) { *this = other; } BoolInt(const BoolInt& other, bool newBool01) { this->bool01 = newBool01; *this = other; this->bool01 = newBool01; } inline void clear() { i = 0; b = false; i.clear(); b.clear(); } inline void clearWithBool01() { clear(); bool01 = false; bool01.clear(); } inline BoolInt& operator=(const BoolInt& other) { clearWithBool01(); if (other.b.set()) b = other.b; if (other.i.set()) i = other.i; if (other.bool01.set()) bool01 = other.bool01; return *this; } inline BoolInt& operator=(BoolInt&& other) { clearWithBool01(); if (other.b.set()) b = other.b; if (other.i.set()) i = other.i; if (other.bool01.set()) bool01 = other.bool01; return *this; } inline BoolInt& operator=(int val) { clear(); i = val; return *this; } inline BoolInt& operator=(bool val) { clear(); b = val; return *this; } inline BoolInt& operator=(const char* s) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (!s) throw std::invalid_argument( "BoolInt value from string is is not supported"); std::string src(s); return (*this = src); } inline BoolInt& operator=(std::string src) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { static const Settable b0(false); static const Settable b1(true); // NOTE: Not a pointer, is not null at least if (src.empty()) throw std::invalid_argument( "BoolInt value from string is is not supported"); clear(); if ("false" == src) { b = b0; return *this; } if ("off" == src) { b = b0; return *this; } if ("0" == src) { if (bool01.set() && bool01 == false) { i = 0; } else { b = b0; } return *this; } if ("no" == src) { b = b0; return *this; } if ("true" == src) { b = b1; return *this; } if ("on" == src) { b = b1; return *this; } if ("1" == src) { if (bool01.set() && bool01 == false) { i = 1; } else { b = b1; } return *this; } if ("yes" == src) { b = b1; return *this; } if ("ok" == src) { b = b1; return *this; } std::stringstream ss(src); int result; if (ss >> result && ss.rdbuf()->in_avail() == 0) { // Conversion succeeded and all chars were read // (e.g. not a decimal number) i = result; #ifdef DEBUG std::cerr << "BoolInt assigned from '" << src << "': got int '" << result << "'" << " stream empty? " << ss.rdbuf()->in_avail() << std::endl; #endif return *this; } throw std::invalid_argument("BoolInt value from '" + src + "' string not understood as bool nor int"); } inline BoolInt& operator<<(bool other) { *this = other; return *this; } inline BoolInt& operator<<(int other) { *this = other; return *this; } inline BoolInt& operator<<(std::string other) { *this = other; return *this; } inline BoolInt& operator<<(const char* other) { *this = other; return *this; } inline bool operator==(const BoolInt& other)const { // Either direct values are set and then equal; optionally // else numeric values of int and bool are cross-equal. if (b.set() && other.b.set()) return (b == other.b); if (i.set() && other.i.set()) return (i == other.i); if ((bool01.set() && bool01 == true) || (!bool01.set() && other.bool01.set() && other.bool01 == true) ) { // false if at least one object has neither i nor b // values "set()", or if their numeric values do not // match up as 0 or 1 exactly vs. boolean values. #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif // some compilers are concerned that Settable._value // may be queried as un-initialized here (for 0/1 equality) // but we are supposed to rule that out with "if set()"... try { if (i.set() && other.b.set()) return ( (other.b && i == 1) || (!other.b && i == 0) ); } catch (...) {} try { if (b.set() && other.i.set()) return ( (b && other.i == 1) || (!b && other.i == 0) ); } catch (...) {} #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED) #pragma GCC diagnostic pop #endif } return false; } inline bool operator==(const bool other)const { if (b.set()) return (b == other); if (bool01.set() && bool01 == true) { if (i.set()) return ((other && i == 1) || (!other && i == 0)); } return false; } inline bool operator==(const int other)const { if (i.set()) return (i == other); if (bool01.set() && bool01 == true) { if (b.set()) return ((b && other == 1) || (!b && other == 0)); } return false; } inline bool operator==(const std::string other)const { BoolInt tmp; if (bool01.set()) tmp.bool01 = bool01; tmp = other; return (*this == tmp); } inline bool operator==(const char* s)const { if (!s) return false; std::string src(s); return (*this == src); } inline bool set()const #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (i.set() && b.set()) throw std::invalid_argument( "BoolInt value somehow got both bool and int values set"); return (i.set() || b.set()); } operator int() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (i.set()) return i; if (bool01.set() && bool01 == true) { if (b.set()) { /** Cause use of operator to avoid warnings like * "may be used uninitialized in this function" */ if (b == true) return 1; return 0; } } else { throw std::invalid_argument( "BoolInt value not set to int"); } throw std::invalid_argument( "BoolInt value not set, neither to bool nor to int"); } operator bool() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (b.set()) return b; if (bool01.set() && bool01 == true) { if (i.set()) { if (i == 0) return false; if (i == 1) return true; } } else { throw std::invalid_argument( "BoolInt value not set to bool"); } throw std::invalid_argument( "BoolInt value not set, neither to bool nor to int"); } inline std::string toString()const #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { if (b.set()) { if (b == true) return "yes"; return "no"; } if (i.set()) { if (bool01.set() && bool01 == true) { if (i == 0) return "no"; if (i == 1) return "yes"; } std::ostringstream ss; ss << i; return ss.str(); } throw std::invalid_argument( "BoolInt value not set, neither to bool nor to int"); } // FIXME: `std::string s = bi;` just won't work // but we can use `s = bi.toString()` or `cout << bi` operator std::string()const { return this->toString(); } operator std::string&()const { return *(new std::string(this->operator std::string())); } }; std::ostream& operator << (std::ostream &os, const BoolInt &bi); inline std::ostream& operator << (std::ostream &os, const BoolInt &bi) { return (os << bi.toString()); } /** * \brief Certificate Identification structure for NUT * * Contains a certificate name and database password */ struct CertIdent { Settable certName, certDbPass; inline bool operator==(const CertIdent& ident)const { return certName == ident.certName && certDbPass == ident.certDbPass; } inline bool set()const { return certName.set() && certDbPass.set(); } }; /** * \brief Certificate protected host structure for NUT * * Contains a host name, certificate name and option flags */ struct CertHost { Settable host, certName; nut::BoolInt certVerify, forceSsl; inline bool operator==(const CertHost& other)const { return certName == other.certName && host == other.host && certVerify == other.certVerify && forceSsl == other.forceSsl; } inline bool set()const { return certName.set() && host.set() && certVerify.set() && forceSsl.set(); } }; /** * NUT config parser. */ class NutParser { public: enum ParsingOption { OPTION_DEFAULT = 0, /** Colon character is considered as string character and not as specific token. Useful for IPv6 addresses */ OPTION_IGNORE_COLON = 1 }; NutParser(const char* buffer = nullptr, unsigned int options = OPTION_DEFAULT); NutParser(const std::string& buffer, unsigned int options = OPTION_DEFAULT); virtual ~NutParser(); /** Parsing configuration functions * \{ */ void setOptions(unsigned int options){_options = options;} unsigned int getOptions()const{return _options;} void setOptions(unsigned int options, bool set = true); void unsetOptions(unsigned int options){setOptions(options, false);} bool hasOptions(unsigned int options)const{return (_options&options) == options;} /** \} */ struct Token { enum TokenType { TOKEN_UNKNOWN = -1, TOKEN_NONE = 0, TOKEN_STRING = 1, TOKEN_QUOTED_STRING, TOKEN_COMMENT, TOKEN_BRACKET_OPEN, TOKEN_BRACKET_CLOSE, TOKEN_EQUAL, TOKEN_COLON, TOKEN_EOL } type; std::string str; Token():type(TOKEN_NONE),str(){} Token(TokenType type_arg, const std::string& str_arg=""):type(type_arg),str(str_arg){} Token(TokenType type_arg, char c):type(type_arg),str(1, c){} Token(const Token& tok):type(tok.type),str(tok.str){} /* Avoid implicit copy/move operator declarations */ Token(Token&&) = default; Token& operator=(const Token&) = default; Token& operator=(Token&&) = default; bool is(TokenType type_arg)const{return this->type==type_arg;} bool operator==(const Token& tok)const{return tok.type==type && tok.str==str;} operator bool()const{return type!=TOKEN_UNKNOWN && type!=TOKEN_NONE;} }; /** Parsing functions * \{ */ std::string parseCHARS(); std::string parseSTRCHARS(); Token parseToken(); std::list parseLine(); /** \} */ #ifndef UNITEST_MODE protected: #endif /* UNITEST_MODE */ size_t getPos()const; void setPos(size_t pos); char charAt(size_t pos)const; void pushPos(); size_t popPos(); void rewind(); void back(); char get(); char peek(); private: unsigned int _options; std::string _buffer; size_t _pos; std::vector _stack; }; typedef std::list ConfigParamList; struct GenericConfigSectionEntry { std::string name; ConfigParamList values; // std::string comment; }; struct GenericConfigSection { /** Section entries map */ typedef std::map EntryMap; std::string name; // std::string comment; EntryMap entries; const GenericConfigSectionEntry& operator [] (const std::string& varname)const{return entries.find(varname)->second;} GenericConfigSectionEntry& operator [] (const std::string& varname){return entries[varname];} bool empty()const; void clear(); }; class BaseConfiguration { friend class GenericConfigParser; public: virtual ~BaseConfiguration(); protected: virtual void setGenericConfigSection(const GenericConfigSection& section) = 0; }; class NutConfigParser : public NutParser { public: virtual void parseConfig(); /* Declared for cleaner overrides; arg ignored in current class */ virtual void parseConfig(BaseConfiguration* config); protected: NutConfigParser(const char* buffer = nullptr, unsigned int options = OPTION_DEFAULT); NutConfigParser(const std::string& buffer, unsigned int options = OPTION_DEFAULT); virtual void onParseBegin()=0; virtual void onParseComment(const std::string& comment)=0; virtual void onParseSectionName(const std::string& sectionName, const std::string& comment = "")=0; virtual void onParseDirective(const std::string& directiveName, char sep = 0, const ConfigParamList& values = ConfigParamList(), const std::string& comment = "")=0; virtual void onParseEnd()=0; }; class DefaultConfigParser : public NutConfigParser { public: DefaultConfigParser(const char* buffer = nullptr); DefaultConfigParser(const std::string& buffer); protected: virtual void onParseSection(const GenericConfigSection& section)=0; virtual void onParseBegin() override; virtual void onParseComment(const std::string& comment) override; virtual void onParseSectionName(const std::string& sectionName, const std::string& comment = "") override; virtual void onParseDirective(const std::string& directiveName, char sep = 0, const ConfigParamList& values = ConfigParamList(), const std::string& comment = "") override; virtual void onParseEnd() override; GenericConfigSection _section; ///> Currently parsed section }; class GenericConfigParser : public DefaultConfigParser { public: GenericConfigParser(const char* buffer = nullptr); GenericConfigParser(const std::string& buffer); virtual void parseConfig(BaseConfiguration* config) override; protected: virtual void onParseSection(const GenericConfigSection& section) override; BaseConfiguration* _config; }; class GenericConfiguration : public BaseConfiguration, public Serialisable { public: /** Sections map */ typedef std::map SectionMap; GenericConfiguration(){} virtual ~GenericConfiguration() override; void parseFromString(const std::string& str); /** Serialisable interface implementation \{ */ bool parseFrom(NutStream & istream) override; bool writeTo(NutStream & ostream) const override; /** \} */ // FIXME Let be public or set it as protected with public accessors ? SectionMap sections; const GenericConfigSection& operator[](const std::string& secname)const{return sections.find(secname)->second;} GenericConfigSection& operator[](const std::string& secname){return sections[secname];} protected: virtual void setGenericConfigSection(const GenericConfigSection& section) override; /** * \brief Configuration parameters getter * * \param[in] section Section name * \param[in] entry Entry name * \param[out] params Configuration parameters * \param[in] caseSensitive Use case-sensitive entry name matching? (default: true) * * \retval true if the entry was found * \retval false otherwise */ bool get(const std::string & section, const std::string & entry, ConfigParamList & params, bool caseSensitive = true) const; /** * \brief Global scope configuration parameters getter * * \param[in] entry Entry name * \param[out] params Configuration parameters * \param[in] caseSensitive Use case-sensitive entry name matching? (default: true) * * \retval true if the entry was found * \retval false otherwise */ inline bool get(const std::string & entry, ConfigParamList & params, bool caseSensitive = true) const { return get("", entry, params, caseSensitive); } /** * \brief Configuration parameters setter * * The section and entry are created unless they already exist. * * \param[in] section Section name * \param[in] entry Entry name * \param[in] params Configuration parameters */ void set(const std::string & section, const std::string & entry, const ConfigParamList & params); /** * \brief Global scope configuration parameters setter * * The entry is created unless it already exists. * * \param[in] entry Entry name * \param[in] params Configuration parameters */ inline void set(const std::string & entry, const ConfigParamList & params) { set("", entry, params); } /** * \brief Add configuration parameters * * The section and entry are created unless they already exist. * Current parameters are kept, the provided are added to the list end. * * \param[in] section Section name * \param[in] entry Entry name * \param[in] params Configuration parameters */ void add(const std::string & section, const std::string & entry, const ConfigParamList & params); /** * \brief Add global scope configuration parameters * * The entry is created unless they already exists. * Current parameters are kept, the provided are added to the list end. * * \param[in] entry Entry name * \param[in] params Configuration parameters */ inline void add(const std::string & entry, const ConfigParamList & params) { add("", entry, params); } /** * \brief Configuration parameters removal * * Removes the entry, only. * Does nothing if the section or the entry don't exist. * * \param section Section name * \param entry Entry name */ void remove(const std::string & section, const std::string & entry); /** * \brief Global scope configuration parameters removal * * Removes the entry, only. * Does nothing if the entry don't exist. * * \param entry Entry name */ inline void remove(const std::string & entry) { remove("", entry); } /** * \brief Configuration section removal * * Removes entire section (if exists). * * \param section Section name */ void removeSection(const std::string & section); /** Global scope configuration removal */ inline void removeGlobal() { removeSection(""); } /** * \brief Configuration string getter * * Empty string is returned if the section or entry doesn't exist. * * \param section Section name * \param entry Entry name * \param caseSensitive Use case-sensitive entry name matching? (default: true) * * \return Configuration parameter as string */ std::string getStr( const std::string & section, const std::string & entry, bool caseSensitive = true) const; /** * \brief Configuration string getter * * Empty string is returned if the section or entry doesn't exist. * * \param section Section name * \param entry Entry name (as C char array or string literal) * \param caseSensitive Use case-sensitive entry name matching? (default: true) * * \return Configuration parameter as string */ std::string getStr( const std::string & section, const char * entry, bool caseSensitive = true) const { std::string sEntry{entry}; return getStr(section, sEntry, caseSensitive); } /** * \brief Global scope configuration string getter * * Empty string is returned if the entry doesn't exist. * * \param entry Entry name * \param caseSensitive Use case-sensitive entry name matching? (default: true) * * \return Configuration parameter as string */ inline std::string getStr( const std::string & entry, bool caseSensitive = true) const { return getStr("", entry, caseSensitive); } /** * \brief Configuration string setter * * \param section Section name * \param entry Entry name * \param value Parameter value */ void setStr( const std::string & section, const std::string & entry, const std::string & value); /** * \brief Global scope configuration string setter * * \param entry Entry name * \param value Parameter value */ inline void setStr( const std::string & entry, const std::string & value) { setStr("", entry, value); } /** * \brief Configuration flag getter * * False is returned if the section or entry doesn't exist. * If a flag exists in configuration (any value is ignored), * it is effectively True. * * \param section Section name * \param entry Entry name * * \return Configuration parameter as boolean */ bool getFlag( const std::string & section, const std::string & entry) const; /** * \brief Global scope configuration flag getter * * False is returned if the entry doesn't exist. * If a flag exists in configuration (any value is ignored), * it is effectively True. * * \param entry Entry name * * \return Configuration parameter as boolean */ inline bool getFlag(const std::string & entry) const { return getFlag("", entry); } /** * \brief Configuration flag setter (mentioned == true) * * Note: to unset a flag, we just use remove() method. * * \param section Section name * \param entry Entry name */ void setFlag( const std::string & section, const std::string & entry, bool val = true); /** * \brief Global scope configuration flag setter (mentioned == true) * * Note: to unset a flag, we just use remove() method. * * \param entry Entry name */ inline void setFlag( const std::string & entry, bool val = true) { setFlag("", entry, val); } /** * \brief Configuration boolean option getter * * Value depends on original string representation of a setting. * * \param section Section name * \param entry Entry name * \param val Default value * * \return Configuration parameter as boolean (or the default if not defined) */ bool getBool( const std::string & section, const std::string & entry, bool val = false) const; /** * \brief Configuration boolean option getter * * Value depends on original string representation of a setting. * * \param section Section name * \param entry Entry name * \param val Default value * * \return Configuration parameter as boolean (or the default if not defined) */ // Avoid error: implicit conversion turns string literal // into bool: 'const char[7]' to 'bool' bool getBool( const std::string & section, const char * entry, bool val = false) const { return getBool(section, std::string(entry), val); } /** * \brief Global scope configuration boolean option getter * * Value depends on original string representation of a setting. * * \param entry Entry name * \param val Default value * * \return Configuration parameter as boolean (or the default if not defined) */ inline bool getBool(const std::string & entry, bool val = false) const { return getBool("", entry, val); } /** * \brief Configuration boolean option setter * * \param section Section name * \param entry Entry name * \param val Default value */ inline void setBool( const std::string & section, const std::string & entry, bool val = true) { setStr(section, entry, bool2str(val)); } /** * \brief Global scope configuration boolean option setter * * \param entry Entry name * \param val Default value */ inline void setBool( const std::string & entry, bool val = true) { setBool("", entry, val); } /** * \brief Configuration boolean option setter from a string * * \param section Section name * \param entry Entry name * \param val Default value */ inline void setBool( const std::string & section, const std::string & entry, const std::string & val = "true") { // Normalize: bool b = str2bool(val); setStr(section, entry, bool2str(b)); } /** * \brief Global scope configuration boolean option setter from a string * * \param entry Entry name * \param val Default value */ inline void setBool( const std::string & entry, const std::string & val = "true") { setBool("", entry, val); } /** * \brief Configuration number getter * * \param section Section name * \param entry Entry name * \param val Default value * * \return Configuration parameter as number (or the default if not defined) */ long long int getInt( const std::string & section, const std::string & entry, long long int val = 0) const; /** * \brief Global scope configuration number getter * * \param entry Entry name * \param val Default value * * \return Configuration parameter as number (or the default if not defined) */ inline long long int getInt(const std::string & entry, long long int val = 0) const { return getInt("", entry, val); } /** * \brief Configuration number setter * * \param section Section name * \param entry Entry name * \param val Default value */ void setInt( const std::string & section, const std::string & entry, long long int val); /** * \brief Global scope configuration number setter * * \param entry Entry name * \param val Default value */ inline void setInt( const std::string & entry, long long int val) { setInt("", entry, val); } /** * \brief Configuration number getter (hex value even if without leading "0x") * * \param section Section name * \param entry Entry name * \param val Default value * * \return Configuration parameter as number (or the default if not defined) */ long long int getIntHex( const std::string & section, const std::string & entry, long long int val = 0) const; /** * \brief Global scope configuration number getter (hex value even if without leading "0x") * * \param entry Entry name * \param val Default value * * \return Configuration parameter as number (or the default if not defined) */ inline long long int getIntHex(const std::string & entry, long long int val = 0) const { return getIntHex("", entry, val); } /** * \brief Configuration number setter (hex value even if without leading "0x") * * \param section Section name * \param entry Entry name * \param val Default value */ void setIntHex( const std::string & section, const std::string & entry, long long int val); /** * \brief Global scope configuration number setter (hex value even if without leading "0x") * * \param entry Entry name * \param val Default value */ inline void setIntHex( const std::string & entry, long long int val) { setIntHex("", entry, val); } /** * \brief Configuration floating-point number getter * * \param section Section name * \param entry Entry name * \param val Default value * * \return Configuration parameter as number (or the default if not defined) */ double getDouble( const std::string & section, const std::string & entry, double val = 0.0) const; /** * \brief Global scope configuration floating-point number getter * * \param entry Entry name * \param val Default value * * \return Configuration parameter as number (or the default if not defined) */ inline double getDouble(const std::string & entry, double val = 0.0) const { return getDouble("", entry, val); } /** * \brief Configuration floating-point number setter * * \param section Section name * \param entry Entry name * \param val Default value */ void setDouble( const std::string & section, const std::string & entry, double val); /** * \brief Global scope configuration floating-point number setter * * \param entry Entry name * \param val Default value */ inline void setDouble( const std::string & entry, double val) { setDouble("", entry, val); } /** * \brief Cast numeric type with range check * * Throws an exception on cast error. * * \param number Number * \param min Minimum * \param max Maximum * * \return \c number which was cast to target type */ template static T range_cast(long long int number, long long int min, long long int max) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::range_error) #endif { if (number < min) { std::stringstream e; e << "Failed to range-cast " << number << " (underflows " << min << ')'; throw std::range_error(e.str()); } if (number > max) { std::stringstream e; e << "Failed to range-cast " << number << " (overflows " << max << ')'; throw std::range_error(e.str()); } return static_cast(number); } /** * \brief Configuration mixed boolean/int option getter * * Value depends on original string representation of a setting. * * \param section Section name * \param entry Entry name * \param val Default value * * \return Configuration parameter as BoolInt type for original * values which have a boolean or integer-numeric meaning * (or the default if not defined) */ nut::BoolInt getBoolInt( const std::string & section, const std::string & entry, nut::BoolInt val = false) const; /** * \brief Global scope configuration mixed boolean/int option getter * * Value depends on original string representation of a setting. * * \param entry Entry name * \param val Default value * * \return Configuration parameter as BoolInt type for original * values which have a boolean or integer-numeric meaning * (or the default if not defined) */ inline nut::BoolInt getBoolInt(const std::string & entry, nut::BoolInt val = false) const { return getBoolInt("", entry, val); } /** * \brief Configuration mixed boolean/int option setter * * Input value types are auto-converted through BoolInt * type for sanity checks (e.g. throw exceptions for * invalid string contents) and are stored as strings * internally. * * \param section Section name * \param entry Entry name * \param val Default value */ inline void setBoolInt( const std::string & section, const std::string & entry, nut::BoolInt val = true) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::invalid_argument) #endif { setStr(section, entry, val); } /** * \brief Global scope configuration mixed boolean/int option setter * * \param entry Entry name * \param val Default value */ inline void setBoolInt( const std::string & entry, nut::BoolInt val = true) { setBoolInt("", entry, val); } /** * \brief Resolve string as Boolean value * * \param str String * * \retval true IFF the string expresses a known true value * \retval false otherwise (no errors emitted for bogus inputs) */ static bool str2bool(const std::string & str); /** * \brief Convert Boolean value to string * * \param val Boolean value * * \return \c val as string */ static const std::string & bool2str(bool val); }; // end of class GenericConfiguration class UpsmonConfiguration : public Serialisable { public: UpsmonConfiguration(); void parseFromString(const std::string& str); Settable debugMin, pollFailLogThrottleMax; Settable offDuration, oblbDuration, overDuration; Settable runAsUser, shutdownCmd, notifyCmd, powerDownFlag; /* yes|no (boolean) or a delay */ Settable shutdownExit; /* practically boolean, but in 0|1 written form (bool01 fiddling) */ Settable certVerify, forceSsl, alarmCritical; Settable certPath; CertIdent certIdent; std::list certHosts; Settable minSupplies, pollFreq, pollFreqAlert, hostSync; Settable deadTime, rbWarnTime, noCommWarnTime, finalDelay; enum NotifyFlag { NOTIFY_IGNORE = 0, NOTIFY_SYSLOG = 1, NOTIFY_WALL = 1 << 1, NOTIFY_EXEC = 1 << 2 }; enum NotifyType { NOTIFY_ONLINE = 0, NOTIFY_ONBATT, NOTIFY_LOWBATT, NOTIFY_FSD, NOTIFY_COMMOK, NOTIFY_COMMBAD, NOTIFY_SHUTDOWN, NOTIFY_REPLBATT, NOTIFY_NOCOMM, NOTIFY_NOPARENT, NOTIFY_CAL, NOTIFY_NOTCAL, NOTIFY_OFF, NOTIFY_NOTOFF, NOTIFY_BYPASS, NOTIFY_NOTBYPASS, NOTIFY_ECO, NOTIFY_NOTECO, NOTIFY_ALARM, NOTIFY_NOTALARM, NOTIFY_OVER, NOTIFY_NOTOVER, NOTIFY_TRIM, NOTIFY_NOTTRIM, NOTIFY_BOOST, NOTIFY_NOTBOOST, NOTIFY_OTHER = 28, NOTIFY_NOTOTHER, NOTIFY_SUSPEND_STARTING = 30, NOTIFY_SUSPEND_FINISHED, NOTIFY_TYPE_MAX }; static NotifyFlag NotifyFlagFromString(const std::string& str); static NotifyType NotifyTypeFromString(const std::string& str); Settable notifyFlags[NOTIFY_TYPE_MAX]; Settable notifyMessages[NOTIFY_TYPE_MAX]; struct Monitor { std::string upsname, hostname; uint16_t port; unsigned int powerValue; std::string username, password; bool isPrimary; }; std::list monitors; /** Serialisable interface implementation \{ */ bool parseFrom(NutStream & istream) override; bool writeTo(NutStream & ostream) const override; /** \} */ }; // end of class UpsmonConfiguration class UpsmonConfigParser : public NutConfigParser { public: UpsmonConfigParser(const char* buffer = nullptr); UpsmonConfigParser(const std::string& buffer); void parseUpsmonConfig(UpsmonConfiguration* config); protected: virtual void onParseBegin() override; virtual void onParseComment(const std::string& comment) override; virtual void onParseSectionName(const std::string& sectionName, const std::string& comment = "") override; virtual void onParseDirective(const std::string& directiveName, char sep = 0, const ConfigParamList& values = ConfigParamList(), const std::string& comment = "") override; virtual void onParseEnd() override; UpsmonConfiguration* _config; }; class NutConfiguration: public Serialisable { public: NutConfiguration(); void parseFromString(const std::string& str); enum NutMode { MODE_UNKNOWN = -1, MODE_NONE = 0, MODE_STANDALONE, MODE_NETSERVER, MODE_NETCLIENT, MODE_CONTROLLED, MODE_MANUAL, }; Settable mode; Settable allowNoDevice, allowNotAllListeners, poweroffQuiet; Settable upsdOptions, upsmonOptions; Settable poweroffWait; Settable debugLevel; static NutMode NutModeFromString(const std::string& str); /** Serialisable interface implementation \{ */ bool parseFrom(NutStream & istream) override; bool writeTo(NutStream & ostream) const override; /** \} */ }; class NutConfConfigParser : public NutConfigParser { public: NutConfConfigParser(const char* buffer = nullptr); NutConfConfigParser(const std::string& buffer); void parseNutConfConfig(NutConfiguration* config); protected: virtual void onParseBegin() override; virtual void onParseComment(const std::string& comment) override; virtual void onParseSectionName(const std::string& sectionName, const std::string& comment = "") override; virtual void onParseDirective(const std::string& directiveName, char sep = 0, const ConfigParamList& values = ConfigParamList(), const std::string& comment = "") override; virtual void onParseEnd() override; NutConfiguration* _config; }; class UpsdConfiguration : public Serialisable { public: UpsdConfiguration(); void parseFromString(const std::string& str); Settable debugMin; Settable maxAge, maxConn, trackingDelay, certRequestLevel; Settable statePath, certFile, certPath; Settable allowNoDevice, allowNotAllListeners, disableWeakSsl; struct Listen { std::string address; Settable port; inline bool operator==(const Listen& listen)const { return address == listen.address && port == listen.port; } }; std::list listens; CertIdent certIdent; /** Serialisable interface implementation \{ */ bool parseFrom(NutStream & istream) override; bool writeTo(NutStream & ostream) const override; /** \} */ }; class UpsdConfigParser : public NutConfigParser { public: UpsdConfigParser(const char* buffer = nullptr); UpsdConfigParser(const std::string& buffer); void parseUpsdConfig(UpsdConfiguration* config); protected: virtual void onParseBegin() override; virtual void onParseComment(const std::string& comment) override; virtual void onParseSectionName(const std::string& sectionName, const std::string& comment = "") override; virtual void onParseDirective(const std::string& directiveName, char sep = 0, const ConfigParamList& values = ConfigParamList(), const std::string& comment = "") override; virtual void onParseEnd() override; UpsdConfiguration* _config; }; /** UPS configuration */ class UpsConfiguration : public GenericConfiguration { /* Note: key words for ups.conf are well collected from sources * by augeas lens preparation scripts. Maintainers of this class * can consume that information like this to see key words in * context of their use in sources and documentation (omit the * `continue` in grep of `nutconf.hpp` to see details of ALL * keywords and not just those not yet covered by this class * (e.g. to verify handling as str/int/bool/flag... types): :; ( cd scripts/augeas && python ./gen-nutupsconf-aug.py.in ) :; grep -E '[=|] "' scripts/augeas/nutupsconf.aug.in | awk '{print $NF}' | tr -d '"' \ | while read O ; do echo "=== $O :" ; \ grep -w '"'"$O"'"' ./include/nutconf.hpp && continue ; \ { cd ./docs/man/ && grep -A10 -w "$O" *.txt || echo '!!! UNDOCUMENTED !!!' ; } ; \ echo "-----"; { cd ./drivers && grep -A10 -w '"'"$O"'"' *.{c,h} || echo '!!! NOT USED IN CODE !!!' ; } ; \ echo "-----"; echo "" ; done | less * Arrange found new keywords into two columns (first would be * "C names" camel-cased and expanded as deemed fit) and generate * lines for code blocks below as e.g.: :; while read C O ; do \ printf '\tinline std::string get%-45sconst { return getStr(ups, "%s"); }\n' \ "$C"'(const std::string & ups)' "$O"; \ printf '\tinline void set%-75s{ setStr(ups, "%-22s val); }\n' \ "$C"'(const std::string & ups, const std::string & val)' "$O"'",' ; \ done < nutupsconf-newnames.bool | sort */ public: /** Global configuration attributes getters and setters \{ */ inline std::string getChroot() const { return getStr("chroot"); } inline std::string getDriverPath() const { return getStr("driverpath"); } inline std::string getStatePath() const { return getStr("statepath", false); } // NOTE: accept it case-insensitively inline std::string getGroup() const { return getStr("group"); } inline std::string getSynchronous() const { return getStr("synchronous"); } inline std::string getUser() const { return getStr("user"); } // Flag - if exists then "true" inline bool getNoWait() const { return getFlag("nowait"); } inline long long int getDebugMin() const { return getInt("debug_min"); } inline long long int getLibusbDebug() const { return getInt("LIBUSB_DEBUG"); } inline long long int getMaxRetry() const { return getInt("maxretry"); } inline long long int getMaxStartDelay() const { return getInt("maxstartdelay"); } inline long long int getPollInterval() const { return getInt("pollinterval", 5); } // TODO: check the default inline long long int getRetryDelay() const { return getInt("retrydelay"); } inline void setChroot(const std::string & path) { setStr("chroot", path); } inline void setDriverPath(const std::string & path) { setStr("driverpath", path); } inline void setStatePath(const std::string & path) { setStr("statepath", path); } inline void setGroup(const std::string & group) { setStr("group", group); } inline void setSynchronous(const std::string & val) { setStr("synchronous", val); } inline void setUser(const std::string & user) { setStr("user", user); } inline void setNoWait(bool val = true) { setFlag("nowait", val); } inline void setDebugMin(long long int num) { setInt("debug_min", num); } inline void setLibusbDebug(long long int num) { setInt("LIBUSB_DEBUG", num); } inline void setMaxRetry(long long int num) { setInt("maxretry", num); } inline void setMaxStartDelay(long long int delay) { setInt("maxstartdelay", delay); } inline void setPollInterval(long long int interval) { setInt("pollinterval", interval); } inline void setRetryDelay(long long int delay) { setInt("retrydelay", delay); } /** \} */ /** Generic = getter */ inline std::string getKey(const std::string & ups, const std::string & key) const { return getStr(ups, key); } /** Generic = setter */ inline void setKey(const std::string & ups, const std::string & key, const std::string & val) { setStr(ups, key, val); } /** PUZZLE: What to do about "default.*" and "override.*" * settings that apply to anything (vars!) that follows? * Maybe nest the UpsConfiguration objects, and so query * e.g. upscfg.default.getBatteryNominalVoltage() ? * Or just keep that info in ConfigParamList per section * and wrap free-style queries? */ inline std::string getDefaultStr(const std::string & ups, const std::string & key) const { return getStr(ups, "default." + key); } inline long long int getDefaultInt(const std::string & ups, const std::string & key) const { return getInt(ups, "default." + key); } inline long long int getDefaultIntHex(const std::string & ups, const std::string & key) const { return getIntHex(ups, "default." + key); } inline bool getDefaultFlag(const std::string & ups, const std::string & key) const { return getFlag(ups, "default." + key); } inline bool getDefaultBool(const std::string & ups, const std::string & key) const { return getBool(ups, "default." + key); } inline nut::BoolInt getDefaultBoolInt(const std::string & ups, const std::string & key) const { return getBoolInt(ups, "default." + key); } inline double getDefaultDouble(const std::string & ups, const std::string & key) const { return getDouble(ups, "default." + key); } inline std::string getOverrideStr(const std::string & ups, const std::string & key) const { return getStr(ups, "override." + key); } inline long long int getOverrideInt(const std::string & ups, const std::string & key) const { return getInt(ups, "override." + key); } inline long long int getOverrideIntHex(const std::string & ups, const std::string & key) const { return getIntHex(ups, "override." + key); } inline bool getOverrideFlag(const std::string & ups, const std::string & key) const { return getFlag(ups, "override." + key); } inline bool getOverrideBool(const std::string & ups, const std::string & key) const { return getBool(ups, "override." + key); } inline nut::BoolInt getOverrideBoolInt(const std::string & ups, const std::string & key) const { return getBoolInt(ups, "override." + key); } inline double getOverrideDouble(const std::string & ups, const std::string & key) const { return getDouble(ups, "override." + key); } inline void setDefaultStr(const std::string & ups, const std::string & key, const std::string & val) { setStr(ups, "default." + key, val); } inline void setDefaultInt(const std::string & ups, const std::string & key, long long int val) { setInt(ups, "default." + key, val); } inline void setDefaultIntHex(const std::string & ups, const std::string & key, long long int val) { setIntHex(ups, "default." + key, val); } inline void setDefaultFlag(const std::string & ups, const std::string & key, bool val = true) { setFlag(ups, "default." + key, val); } inline void setDefaultBool(const std::string & ups, const std::string & key, bool val) { setBool(ups, "default." + key, val); } inline void setDefaultBoolInt(const std::string & ups, const std::string & key, nut::BoolInt val) { setBoolInt(ups, "default." + key, val); } inline void setDefaultDouble(const std::string & ups, const std::string & key, double val) { setDouble(ups, "default." + key, val); } inline void setOverrideStr(const std::string & ups, const std::string & key, const std::string & val) { setStr(ups, "override." + key, val); } inline void setOverrideInt(const std::string & ups, const std::string & key, long long int val) { setInt(ups, "override." + key, val); } inline void setOverrideIntHex(const std::string & ups, const std::string & key, long long int val) { setIntHex(ups, "override." + key, val); } inline void setOverrideFlag(const std::string & ups, const std::string & key, bool val = true) { setFlag(ups, "override." + key, val); } inline void setOverrideBool(const std::string & ups, const std::string & key, bool val) { setBool(ups, "override." + key, val); } inline void setOverrideBoolInt(const std::string & ups, const std::string & key, nut::BoolInt val) { setBoolInt(ups, "override." + key, val); } inline void setOverrideDouble(const std::string & ups, const std::string & key, double val) { setDouble(ups, "override." + key, val); } /** UPS-specific configuration attributes getters and setters \{ */ inline std::string getAuthPassword(const std::string & ups) const { return getStr(ups, "authPassword"); } inline std::string getAuthProtocol(const std::string & ups) const { return getStr(ups, "authProtocol"); } inline std::string getAuthType(const std::string & ups) const { return getStr(ups, "authtype"); } inline std::string getAWD(const std::string & ups) const { return getStr(ups, "awd"); } inline std::string getBatText(const std::string & ups) const { return getStr(ups, "battext"); } inline std::string getBus(const std::string & ups) const { return getStr(ups, "bus"); } inline std::string getCommunity(const std::string & ups) const { return getStr(ups, "community"); } inline std::string getDriver(const std::string & ups) const { return getStr(ups, "driver"); } inline std::string getDescription(const std::string & ups) const { return getStr(ups, "desc"); } inline std::string getFRUID(const std::string & ups) const { return getStr(ups, "fruid"); } inline std::string getGenericGPIO_Rules(const std::string & ups) const { return getStr(ups, "rules"); } inline std::string getGenericUPS_BYPASS(const std::string & ups) const { return getStr(ups, "BYPASS"); } inline std::string getGenericUPS_CP(const std::string & ups) const { return getStr(ups, "CP"); } inline std::string getGenericUPS_LB(const std::string & ups) const { return getStr(ups, "LB"); } inline std::string getGenericUPS_OL(const std::string & ups) const { return getStr(ups, "OL"); } inline std::string getGenericUPS_RB(const std::string & ups) const { return getStr(ups, "RB"); } inline std::string getGenericUPS_SD(const std::string & ups) const { return getStr(ups, "SD"); } inline std::string getGroup(const std::string & ups) const { return getStr(ups, "group"); } inline std::string getID(const std::string & ups) const { return getStr(ups, "ID"); } inline std::string getLoadStatus(const std::string & ups) const { return getStr(ups, "load.status"); } inline std::string getLogin(const std::string & ups) const { return getStr(ups, "login"); } inline std::string getLowBatt(const std::string & ups) const { return getStr(ups, "LowBatt"); } inline std::string getLowbatt(const std::string & ups) const { return getStr(ups, "lowbatt"); } inline std::string getManufacturer(const std::string & ups) const { return getStr(ups, "manufacturer"); } inline std::string getMethodOfFlowControl(const std::string & ups) const { return getStr(ups, "methodOfFlowControl"); } inline std::string getMIBs(const std::string & ups) const { return getStr(ups, "mibs"); } inline std::string getModbus_DeviceMfr(const std::string & ups) const { return getStr(ups, "device_mfr"); } inline std::string getModbus_DeviceModel(const std::string & ups) const { return getStr(ups, "device_model"); } inline std::string getModbus_Parity(const std::string & ups) const { return getStr(ups, "parity"); } inline std::string getModbus_PortType(const std::string & ups) const { return getStr(ups, "porttype"); } inline std::string getModbus_SerParity(const std::string & ups) const { return getStr(ups, "ser_parity"); } inline std::string getModel(const std::string & ups) const { return getStr(ups, "model"); } inline std::string getModelName(const std::string & ups) const { return getStr(ups, "modelname"); } inline std::string getNotification(const std::string & ups) const { return getStr(ups, "notification"); } inline std::string getPassword(const std::string & ups) const { return getStr(ups, "password"); } inline std::string getPort(const std::string & ups) const { return getStr(ups, "port"); } inline std::string getPrefix(const std::string & ups) const { return getStr(ups, "prefix"); } inline std::string getPrivPassword(const std::string & ups) const { return getStr(ups, "privPassword"); } inline std::string getPrivProtocol(const std::string & ups) const { return getStr(ups, "privProtocol"); } inline std::string getProduct(const std::string & ups) const { return getStr(ups, "product"); } inline std::string getProductID(const std::string & ups) const { return getStr(ups, "productid"); } inline std::string getProtocol(const std::string & ups) const { return getStr(ups, "protocol"); } inline std::string getRuntimeCal(const std::string & ups) const { return getStr(ups, "runtimecal"); } inline std::string getSDType(const std::string & ups) const { return getStr(ups, "sdtype"); } inline std::string getSecLevel(const std::string & ups) const { return getStr(ups, "secLevel"); } inline std::string getSecName(const std::string & ups) const { return getStr(ups, "secName"); } inline std::string getSensorID(const std::string & ups) const { return getStr(ups, "sensorid"); } inline std::string getSerial(const std::string & ups) const { return getStr(ups, "serial"); } inline std::string getSerialNumber(const std::string & ups) const { return getStr(ups, "serialnumber"); } inline std::string getShutdownArguments(const std::string & ups) const { return getStr(ups, "shutdownArguments"); } inline std::string getSNMPversion(const std::string & ups) const { return getStr(ups, "snmp_version"); } inline std::string getSubdriver(const std::string & ups) const { return getStr(ups, "subdriver"); } inline std::string getSynchronous(const std::string & ups) const { return getStr(ups, "synchronous"); } inline std::string getTtyMode(const std::string & ups) const { return getStr(ups, "ttymode"); } inline std::string getType(const std::string & ups) const { return getStr(ups, "type"); } inline std::string getUPStype(const std::string & ups) const { return getStr(ups, "upstype"); } inline std::string getUpsId(const std::string & ups) const { return getStr(ups, "upsid"); } inline std::string getUsbBusPort(const std::string & ups) const { return getStr(ups, "busport"); } inline std::string getUsbDevice(const std::string & ups) const { return getStr(ups, "device"); } inline std::string getUSD(const std::string & ups) const { return getStr(ups, "usd"); } inline std::string getUser(const std::string & ups) const { return getStr(ups, "user"); } inline std::string getUsername(const std::string & ups) const { return getStr(ups, "username"); } inline std::string getValidationSequence(const std::string & ups) const { return getStr(ups, "validationSequence"); } inline std::string getVendor(const std::string & ups) const { return getStr(ups, "vendor"); } inline std::string getVendorID(const std::string & ups) const { return getStr(ups, "vendorid"); } inline std::string getWorkRangeType(const std::string & ups) const { return getStr(ups, "work_range_type"); } inline std::string getWUGrace(const std::string & ups) const { return getStr(ups, "wugrace"); } // Items below are "unused" - mostly set in // drivers/nutdrv_qx_masterguard.c inline std::string getFault1(const std::string & ups) const { return getStr(ups, "fault_1"); } inline std::string getFault2(const std::string & ups) const { return getStr(ups, "fault_2"); } inline std::string getFault3(const std::string & ups) const { return getStr(ups, "fault_3"); } inline std::string getFault4(const std::string & ups) const { return getStr(ups, "fault_4"); } inline std::string getFault5(const std::string & ups) const { return getStr(ups, "fault_5"); } inline std::string getInputFaultVoltage(const std::string & ups) const { return getStr(ups, "input_fault_voltage"); } inline std::string getNominalCellVoltage(const std::string & ups) const { return getStr(ups, "nominal_cell_voltage"); } inline std::string getNumberOfBatteryCells(const std::string & ups)const { return getStr(ups, "number_of_battery_cells"); } inline std::string getOutputVoltages(const std::string & ups) const { return getStr(ups, "output_voltages"); } inline std::string getRechargeTime(const std::string & ups) const { return getStr(ups, "recharge_time"); } inline std::string getRuntimeFull(const std::string & ups) const { return getStr(ups, "runtime_full"); } inline std::string getRuntimeHalf(const std::string & ups) const { return getStr(ups, "runtime_half"); } inline std::string getSeries(const std::string & ups) const { return getStr(ups, "series"); } // Items below are essentially booleans (expected values // are "enabled/disabled") -- refactoring planned per // https://github.com/networkupstools/nut/issues/2421 inline std::string getAdvancedEcoMode(const std::string & ups) const { return getStr(ups, "advanced_eco_mode"); } inline std::string getAlarmControl(const std::string & ups) const { return getStr(ups, "alarm_control"); } inline std::string getBatteryAlarm(const std::string & ups) const { return getStr(ups, "battery_alarm"); } inline std::string getBatteryOpenStatusCheck(const std::string & ups)const { return getStr(ups, "battery_open_status_check"); } inline std::string getBypassAlarm(const std::string & ups) const { return getStr(ups, "bypass_alarm"); } inline std::string getBypassForbidding(const std::string & ups) const { return getStr(ups, "bypass_forbidding"); } inline std::string getBypassWhenOff(const std::string & ups) const { return getStr(ups, "bypass_when_off"); } inline std::string getConstantPhaseAngle(const std::string & ups) const { return getStr(ups, "constant_phase_angle"); } inline std::string getConverterMode(const std::string & ups) const { return getStr(ups, "converter_mode"); } inline std::string getEcoMode(const std::string & ups) const { return getStr(ups, "eco_mode"); } inline std::string getLimitedRuntimeOnBattery(const std::string & ups)const { return getStr(ups, "limited_runtime_on_battery"); } inline std::string getSiteFaultDetection(const std::string & ups) const { return getStr(ups, "site_fault_detection"); } inline long long int getAdvOrder(const std::string & ups) const { return getInt(ups, "advorder"); } // CHECKME inline long long int getAsem_HB(const std::string & ups) const { return getInt(ups, "hb"); } inline long long int getAsem_LB(const std::string & ups) const { return getInt(ups, "lb"); } inline long long int getBatteryNumber(const std::string & ups) const { return getInt(ups, "battery_number"); } inline long long int getBatteryPercentage(const std::string & ups) const { return getInt(ups, "batteryPercentage"); } // CHECKME inline long long int getBattVoltMult(const std::string & ups) const { return getInt(ups, "battvoltmult"); } // CHECKME inline long long int getBaudRate(const std::string & ups) const { return getInt(ups, "baud_rate"); } // CHECKME inline long long int getBaudrate(const std::string & ups) const { return getInt(ups, "baudrate"); } // CHECKME inline long long int getCablePower(const std::string & ups) const { return getInt(ups, "cablepower"); } // CHECKME inline long long int getChargeTime(const std::string & ups) const { return getInt(ups, "chargetime"); } // CHECKME inline long long int getDaysOff(const std::string & ups) const { return getInt(ups, "daysoff"); } // CHECKME inline long long int getDaySweek(const std::string & ups) const { return getInt(ups, "daysweek"); } // CHECKME inline long long int getDebugMin(const std::string & ups) const { return getInt(ups, "debug_min"); } inline long long int getLibusbDebug(const std::string & ups) const { return getInt(ups, "LIBUSB_DEBUG"); } inline long long int getFrequency(const std::string & ups) const { return getInt(ups, "frequency"); } // CHECKME inline long long int getHourOff(const std::string & ups) const { return getInt(ups, "houroff"); } // CHECKME inline long long int getHourOn(const std::string & ups) const { return getInt(ups, "houron"); } // CHECKME inline long long int getI2C_address(const std::string & ups) const { return getInt(ups, "i2c_address"); } inline long long int getIdleLoad(const std::string & ups) const { return getInt(ups, "idleload"); } // CHECKME inline long long int getInputTimeout(const std::string & ups) const { return getInt(ups, "input_timeout"); } // CHECKME inline long long int getInterruptPipeNoEventsTolerance(const std::string & ups) const { return getInt(ups, "interrupt_pipe_no_events_tolerance"); } inline long long int getInterruptSize(const std::string & ups) const { return getInt(ups, "interruptsize"); } inline long long int getLineVoltage(const std::string & ups) const { return getInt(ups, "linevoltage"); } // CHECKME inline long long int getLoadpercentage(const std::string & ups) const { return getInt(ups, "loadPercentage"); } // CHECKME inline long long int getMaxLoad(const std::string & ups) const { return getInt(ups, "max_load"); } // CHECKME inline long long int getMaxPollsWithoutData(const std::string & ups) const { return getInt(ups, "max_polls_without_data"); } inline long long int getMaxStartDelay(const std::string & ups) const { return getInt(ups, "maxstartdelay"); } inline long long int getMFR(const std::string & ups) const { return getInt(ups, "mfr"); } // CHECKME inline long long int getMinCharge(const std::string & ups) const { return getInt(ups, "mincharge"); } // CHECKME inline long long int getMinRuntime(const std::string & ups) const { return getInt(ups, "minruntime"); } // CHECKME inline long long int getModbus_ByteTimeoutSec(const std::string & ups) const { return getInt(ups, "mod_byte_to_s"); } inline long long int getModbus_ByteTimeoutUsec(const std::string & ups) const { return getInt(ups, "mod_byte_to_us"); } inline long long int getModbus_CHRG_addr(const std::string & ups) const { return getInt(ups, "CHRG_addr"); } inline long long int getModbus_CHRG_noro(const std::string & ups) const { return getInt(ups, "CHRG_noro"); } inline long long int getModbus_CHRG_regtype(const std::string & ups) const { return getInt(ups, "CHRG_regtype"); } inline long long int getModbus_DISCHRG_addr(const std::string & ups) const { return getInt(ups, "DISCHRG_addr"); } inline long long int getModbus_DISCHRG_noro(const std::string & ups) const { return getInt(ups, "DISCHRG_noro"); } inline long long int getModbus_DISCHRG_regtype(const std::string & ups) const { return getInt(ups, "DISCHRG_regtype"); } inline long long int getModbus_DataBits(const std::string & ups) const { return getInt(ups, "databits"); } inline long long int getModbus_DeviceSlaveId(const std::string & ups) const { return getInt(ups, "dev_slave_id"); } inline long long int getModbus_FSD_addr(const std::string & ups) const { return getInt(ups, "FSD_addr"); } inline long long int getModbus_FSD_noro(const std::string & ups) const { return getInt(ups, "FSD_noro"); } inline long long int getModbus_FSD_pulse_duration(const std::string & ups) const { return getInt(ups, "FSD_pulse_duration"); } inline long long int getModbus_FSD_regtype(const std::string & ups) const { return getInt(ups, "FSD_regtype"); } inline long long int getModbus_HB_addr(const std::string & ups) const { return getInt(ups, "HB_addr"); } inline long long int getModbus_HB_noro(const std::string & ups) const { return getInt(ups, "HB_noro"); } inline long long int getModbus_HB_regtype(const std::string & ups) const { return getInt(ups, "HB_regtype"); } inline long long int getModbus_LB_addr(const std::string & ups) const { return getInt(ups, "LB_addr"); } inline long long int getModbus_LB_noro(const std::string & ups) const { return getInt(ups, "LB_noro"); } inline long long int getModbus_LB_regtype(const std::string & ups) const { return getInt(ups, "LB_regtype"); } inline long long int getModbus_OB_addr(const std::string & ups) const { return getInt(ups, "OB_addr"); } inline long long int getModbus_OB_noro(const std::string & ups) const { return getInt(ups, "OB_noro"); } inline long long int getModbus_OB_regtype(const std::string & ups) const { return getInt(ups, "OB_regtype"); } inline long long int getModbus_OL_addr(const std::string & ups) const { return getInt(ups, "OL_addr"); } inline long long int getModbus_OL_noro(const std::string & ups) const { return getInt(ups, "OL_noro"); } inline long long int getModbus_OL_regtype(const std::string & ups) const { return getInt(ups, "OL_regtype"); } inline long long int getModbus_RB_addr(const std::string & ups) const { return getInt(ups, "RB_addr"); } inline long long int getModbus_RB_noro(const std::string & ups) const { return getInt(ups, "RB_noro"); } inline long long int getModbus_RB_regtype(const std::string & ups) const { return getInt(ups, "RB_regtype"); } inline long long int getModbus_ResponseTimeoutMsec(const std::string & ups)const { return getInt(ups, "response_timeout_ms"); } inline long long int getModbus_ResponseTimeoutSec(const std::string & ups) const { return getInt(ups, "mod_resp_to_s"); } inline long long int getModbus_ResponseTimeoutUsec(const std::string & ups)const { return getInt(ups, "mod_resp_to_us"); } inline long long int getModbus_RioSlaveId(const std::string & ups) const { return getInt(ups, "rio_slave_id"); } inline long long int getModbus_SerBaudRate(const std::string & ups) const { return getInt(ups, "ser_baud_rate"); } inline long long int getModbus_SerDataBit(const std::string & ups) const { return getInt(ups, "ser_data_bit"); } inline long long int getModbus_SerStopBit(const std::string & ups) const { return getInt(ups, "ser_stop_bit"); } inline long long int getModbus_SlaveId(const std::string & ups) const { return getInt(ups, "slaveid"); } inline long long int getModbus_StopBits(const std::string & ups) const { return getInt(ups, "stopbits"); } inline long long int getNomBattVolt(const std::string & ups) const { return getInt(ups, "nombattvolt"); } // CHECKME inline long long int getNumOfBytesFromUPS(const std::string & ups) const { return getInt(ups, "numOfBytesFromUPS"); } // CHECKME inline long long int getOffDelay(const std::string & ups) const { return getInt(ups, "OffDelay"); } // CHECKME inline long long int getOffdelay(const std::string & ups) const { return getInt(ups, "offdelay"); } // CHECKME inline long long int getOnDelay(const std::string & ups) const { return getInt(ups, "OnDelay"); } // CHECKME inline long long int getOndelay(const std::string & ups) const { return getInt(ups, "ondelay"); } // CHECKME inline long long int getOnlineDischargeLogThrottleHovercharge(const std::string & ups)const { return getInt(ups, "onlinedischarge_log_throttle_hovercharge"); } inline long long int getOnlineDischargeLogThrottleSec(const std::string & ups)const { return getInt(ups, "onlinedischarge_log_throttle_sec"); } inline long long int getOutputPace(const std::string & ups) const { return getInt(ups, "output_pace"); } // CHECKME inline long long int getOutputPhaseAngle(const std::string & ups) const { return getInt(ups, "output_phase_angle"); } inline long long int getPinsShutdownMode(const std::string & ups) const { return getInt(ups, "pins_shutdown_mode"); } inline long long int getPollFreq(const std::string & ups) const { return getInt(ups, "pollfreq"); } // CHECKME inline long long int getPowerUp(const std::string & ups) const { return getInt(ups, "powerup"); } // CHECKME inline long long int getPrgShut(const std::string & ups) const { return getInt(ups, "prgshut"); } // CHECKME inline long long int getRebootDelay(const std::string & ups) const { return getInt(ups, "rebootdelay"); } // CHECKME inline long long int getSDOrder(const std::string & ups) const { return getInt(ups, "sdorder"); } // TODO: Is that a number? inline long long int getSDtime(const std::string & ups) const { return getInt(ups, "sdtime"); } // CHECKME inline long long int getSemistaticFreq(const std::string & ups) const { return getInt(ups, "semistaticfreq"); } inline long long int getShutdownDelay(const std::string & ups) const { return getInt(ups, "shutdown_delay"); } // CHECKME inline long long int getShutdownDuration(const std::string & ups) const { return getInt(ups, "shutdown_duration"); } inline long long int getShutdownTimer(const std::string & ups) const { return getInt(ups, "shutdown_timer"); } inline long long int getSlaveAddress(const std::string & ups) const { return getInt(ups, "slave_address"); } inline long long int getSnmpRetries(const std::string & ups) const { return getInt(ups, "snmp_retries"); } inline long long int getSnmpTimeout(const std::string & ups) const { return getInt(ups, "snmp_timeout"); } inline long long int getStartDelay(const std::string & ups) const { return getInt(ups, "startdelay"); } // CHECKME inline long long int getTestTime(const std::string & ups) const { return getInt(ups, "testtime"); } // CHECKME inline long long int getTimeout(const std::string & ups) const { return getInt(ups, "timeout"); } // CHECKME inline long long int getUPSdelayShutdown(const std::string & ups) const { return getInt(ups, "ups.delay.shutdown"); } // CHECKME inline long long int getUPSdelayStart(const std::string & ups) const { return getInt(ups, "ups.delay.start"); } // CHECKME inline long long int getVoltage(const std::string & ups) const { return getInt(ups, "voltage"); } // CHECKME inline long long int getWaitBeforeReconnect(const std::string & ups) const { return getInt(ups, "waitbeforereconnect"); } /** belkinunv: both a flag (wait for AC power) and value (also wait for charge level) */ inline long long int getWait(const std::string & ups) const { return getInt(ups, "wait"); } /** May be a flag or a number; 0 is among valid values (default -1 for unset) */ inline long long int getUsbSetAltInterface(const std::string & ups) const { return getInt(ups, "usb_set_altinterface", -1); } // CHECKME // NUT specifies these as "hexnum" values (optionally with prefixed 0x but hex anyway) inline long long int getUsbConfigIndex(const std::string & ups) const { return getIntHex(ups, "usb_config_index"); } // CHECKME inline long long int getUsbHidDescIndex(const std::string & ups) const { return getIntHex(ups, "usb_hid_desc_index"); } // CHECKME inline long long int getUsbHidRepIndex(const std::string & ups) const { return getIntHex(ups, "usb_hid_rep_index"); } // CHECKME inline long long int getUsbHidEndpointIn(const std::string & ups) const { return getIntHex(ups, "usb_hid_ep_in"); } // CHECKME inline long long int getUsbHidEndpointOut(const std::string & ups) const { return getIntHex(ups, "usb_hid_ep_out"); } // CHECKME inline double getBatteryMax(const std::string & ups) const { return getDouble(ups, "battery_max"); } inline double getBatteryMin(const std::string & ups) const { return getDouble(ups, "battery_min"); } inline double getCSHackDelay(const std::string & ups) const { return getDouble(ups, "cshdelay"); } inline double getMaxBypassFreq(const std::string & ups) const { return getDouble(ups, "max_bypass_freq"); } inline double getMaxBypassVolt(const std::string & ups) const { return getDouble(ups, "max_bypass_volt"); } inline double getMinBypassFreq(const std::string & ups) const { return getDouble(ups, "min_bypass_freq"); } inline double getMinBypassVolt(const std::string & ups) const { return getDouble(ups, "min_bypass_volt"); } // Flag - if exists then "true" inline bool getCancelShutdown(const std::string & ups) const { return getFlag(ups, "CS"); } inline bool getDumbTerm(const std::string & ups) const { return getFlag(ups, "dumbterm"); } inline bool getExplore(const std::string & ups) const { return getFlag(ups, "explore"); } inline bool getFakeLowBatt(const std::string & ups) const { return getFlag(ups, "fake_lowbatt"); } inline bool getFlash(const std::string & ups) const { return getFlag(ups, "flash"); } inline bool getIgnoreLB(const std::string & ups) const { return getFlag(ups, "ignorelb"); } inline bool getNoHang(const std::string & ups) const { return getFlag(ups, "nohang"); } inline bool getNoRating(const std::string & ups) const { return getFlag(ups, "norating"); } inline bool getNoTransferOIDs(const std::string & ups) const { return getFlag(ups, "notransferoids"); } inline bool getNoVendor(const std::string & ups) const { return getFlag(ups, "novendor"); } inline bool getNoWarnNoImp(const std::string & ups) const { return getFlag(ups, "nowarn_noimp"); } inline bool getOldMAC(const std::string & ups) const { return getFlag(ups, "oldmac"); } inline bool getPollOnly(const std::string & ups) const { return getFlag(ups, "pollonly"); } inline bool getSilent(const std::string & ups) const { return getFlag(ups, "silent"); } inline bool getStatusOnly(const std::string & ups) const { return getFlag(ups, "status_only"); } inline bool getSubscribe(const std::string & ups) const { return getFlag(ups, "subscribe"); } inline bool getUseCRLF(const std::string & ups) const { return getFlag(ups, "use_crlf"); } inline bool getUsePreLF(const std::string & ups) const { return getFlag(ups, "use_pre_lf"); } inline bool getNolock(const std::string & ups) const { return getBool(ups, "nolock"); } inline bool getCable(const std::string & ups) const { return getBool(ups, "cable"); } inline bool getFullUpdate(const std::string & ups) const { return getBool(ups, "full_update"); } inline bool getLangIDfix(const std::string & ups) const { return getBool(ups, "langid_fix"); } inline bool getLoadOff(const std::string & ups) const { return getBool(ups, "load.off"); } inline bool getLoadOn(const std::string & ups) const { return getBool(ups, "load.on"); } inline void setAuthPassword(const std::string & ups, const std::string & auth_passwd) { setStr(ups, "authPassword", auth_passwd); } inline void setAuthProtocol(const std::string & ups, const std::string & auth_proto) { setStr(ups, "authProtocol", auth_proto); } inline void setAuthType(const std::string & ups, const std::string & authtype) { setStr(ups, "authtype", authtype); } inline void setAWD(const std::string & ups, const std::string & awd) { setStr(ups, "awd", awd); } inline void setBatText(const std::string & ups, const std::string & battext) { setStr(ups, "battext", battext); } inline void setBus(const std::string & ups, const std::string & bus) { setStr(ups, "bus", bus); } inline void setCommunity(const std::string & ups, const std::string & community) { setStr(ups, "community", community); } inline void setDriver(const std::string & ups, const std::string & driver) { setStr(ups, "driver", driver); } inline void setDescription(const std::string & ups, const std::string & desc) { setStr(ups, "desc", desc); } inline void setFRUID(const std::string & ups, const std::string & fruid) { setStr(ups, "fruid", fruid); } inline void setGenericGPIO_Rules(const std::string & ups, const std::string & val) { setStr(ups, "rules", val); } inline void setGenericUPS_BYPASS(const std::string & ups, const std::string & bypass) { setStr(ups, "BYPASS", bypass); } inline void setGenericUPS_CP(const std::string & ups, const std::string & cp) { setStr(ups, "CP", cp); } inline void setGenericUPS_LB(const std::string & ups, const std::string & lb) { setStr(ups, "LB", lb); } inline void setGenericUPS_OL(const std::string & ups, const std::string & ol) { setStr(ups, "OL", ol); } inline void setGenericUPS_RB(const std::string & ups, const std::string & rb) { setStr(ups, "RB", rb); } inline void setGenericUPS_SD(const std::string & ups, const std::string & sd) { setStr(ups, "SD", sd); } inline void setGroup(const std::string & ups, const std::string & group) { setStr(ups, "group", group); } inline void setLoadStatus(const std::string & ups, const std::string & load_status) { setStr(ups, "load.status", load_status); } inline void setLogin(const std::string & ups, const std::string & login) { setStr(ups, "login", login); } inline void setLowBatt(const std::string & ups, const std::string & lowbatt) { setStr(ups, "LowBatt", lowbatt); } inline void setLowbatt(const std::string & ups, const std::string & lowbatt) { setStr(ups, "lowbatt", lowbatt); } inline void setManufacturer(const std::string & ups, const std::string & manufacturer) { setStr(ups, "manufacturer", manufacturer); } inline void setMethodOfFlowControl(const std::string & ups, const std::string & method) { setStr(ups, "methodOfFlowControl", method); } inline void setMIBs(const std::string & ups, const std::string & mibs) { setStr(ups, "mibs", mibs); } inline void setModbus_DeviceMfr(const std::string & ups, const std::string & val) { setStr(ups, "device_mfr", val); } inline void setModbus_DeviceModel(const std::string & ups, const std::string & val) { setStr(ups, "device_model", val); } inline void setModbus_Parity(const std::string & ups, const std::string & val) { setStr(ups, "parity", val); } inline void setModbus_PortType(const std::string & ups, const std::string & val) { setStr(ups, "porttype", val); } inline void setModbus_SerParity(const std::string & ups, const std::string & val) { setStr(ups, "ser_parity", val); } inline void setModel(const std::string & ups, const std::string & model) { setStr(ups, "model", model); } inline void setModelName(const std::string & ups, const std::string & modelname) { setStr(ups, "modelname", modelname); } inline void setNotification(const std::string & ups, const std::string & notification) { setStr(ups, "notification", notification); } inline void setPassword(const std::string & ups, const std::string & password) { setStr(ups, "password", password); } inline void setPort(const std::string & ups, const std::string & port) { setStr(ups, "port", port); } inline void setPrefix(const std::string & ups, const std::string & prefix) { setStr(ups, "prefix", prefix); } inline void setPrivPassword(const std::string & ups, const std::string & priv_passwd) { setStr(ups, "privPassword", priv_passwd); } inline void setPrivProtocol(const std::string & ups, const std::string & priv_proto) { setStr(ups, "privProtocol", priv_proto); } inline void setProduct(const std::string & ups, const std::string & product) { setStr(ups, "product", product); } inline void setProductID(const std::string & ups, const std::string & productid) { setStr(ups, "productid", productid); } inline void setProtocol(const std::string & ups, const std::string & protocol) { setStr(ups, "protocol", protocol); } inline void setRuntimeCal(const std::string & ups, const std::string & runtimecal) { setStr(ups, "runtimecal", runtimecal); } inline void setSDtype(const std::string & ups, const std::string & sdtype) { setStr(ups, "sdtype", sdtype); } inline void setSecLevel(const std::string & ups, const std::string & sec_level) { setStr(ups, "secLevel", sec_level); } inline void setSecName(const std::string & ups, const std::string & sec_name) { setStr(ups, "secName", sec_name); } inline void setSensorID(const std::string & ups, const std::string & sensorid) { setStr(ups, "sensorid", sensorid); } inline void setSerial(const std::string & ups, const std::string & serial) { setStr(ups, "serial", serial); } inline void setSerialNumber(const std::string & ups, const std::string & serialnumber) { setStr(ups, "serialnumber", serialnumber); } inline void setShutdownArguments(const std::string & ups, const std::string & sd_args) { setStr(ups, "shutdownArguments", sd_args); } inline void setSNMPversion(const std::string & ups, const std::string & snmp_version) { setStr(ups, "snmp_version", snmp_version); } inline void setSubdriver(const std::string & ups, const std::string & subdriver) { setStr(ups, "subdriver", subdriver); } inline void setSynchronous(const std::string & ups, const std::string & synchronous) { setStr(ups, "synchronous", synchronous); } inline void setTtyMode(const std::string & ups, const std::string & val) { setStr(ups, "ttymode", val); } inline void setType(const std::string & ups, const std::string & type) { setStr(ups, "type", type); } inline void setUPStype(const std::string & ups, const std::string & upstype) { setStr(ups, "upstype", upstype); } inline void setUpsId(const std::string & ups, const std::string & val) { setStr(ups, "upsid", val); } inline void setUsbBusPort(const std::string & ups, const std::string & val) { setStr(ups, "busport", val); } inline void setUsbDevice(const std::string & ups, const std::string & val) { setStr(ups, "device", val); } inline void setUSD(const std::string & ups, const std::string & usd) { setStr(ups, "usd", usd); } inline void setUsername(const std::string & ups, const std::string & username) { setStr(ups, "username", username); } inline void setUser(const std::string & ups, const std::string & user) { setStr(ups, "user", user); } inline void setValidationSequence(const std::string & ups, const std::string & valid_seq) { setStr(ups, "validationSequence", valid_seq); } inline void setVendor(const std::string & ups, const std::string & vendor) { setStr(ups, "vendor", vendor); } inline void setVendorID(const std::string & ups, const std::string & vendorid) { setStr(ups, "vendorid", vendorid); } inline void setWorkRangeType(const std::string & ups, const std::string & val) { setStr(ups, "work_range_type", val); } inline void setWUGrace(const std::string & ups, const std::string & wugrace) { setStr(ups, "wugrace", wugrace); } inline void setADVorder(const std::string & ups, long long int advorder) { setInt(ups, "advorder", advorder); } // CHECKME inline void setAsem_HB(const std::string & ups, long long int val) { setInt(ups, "hb", val); } inline void setAsem_LB(const std::string & ups, long long int val) { setInt(ups, "lb", val); } inline void setBatteryNumber(const std::string & ups, long long int val) { setInt(ups, "battery_number", val); } inline void setBatteryPercentage(const std::string & ups, long long int batt) { setInt(ups, "batteryPercentage", batt); } // CHECKME inline void setBattVoltMult(const std::string & ups, long long int mult) { setInt(ups, "battvoltmult", mult); } // CHECKME inline void setBaudRate(const std::string & ups, long long int baud_rate) { setInt(ups, "baud_rate", baud_rate); } // CHECKME inline void setBaudrate(const std::string & ups, long long int baudrate) { setInt(ups, "baudrate", baudrate); } // CHECKME inline void setCablePower(const std::string & ups, long long int cablepower) { setInt(ups, "cablepower", cablepower); } // CHECKME inline void setChargeTime(const std::string & ups, long long int chargetime) { setInt(ups, "chargetime", chargetime); } // CHECKME inline void setDaysOff(const std::string & ups, long long int daysoff) { setInt(ups, "daysoff", daysoff); } // CHECKME inline void setDaysWeek(const std::string & ups, long long int daysweek) { setInt(ups, "daysweek", daysweek); } // CHECKME inline void setDebugMin(const std::string & ups, long long int val) { setInt(ups, "debug_min", val); } inline void setLibusbDebug(const std::string & ups, long long int val) { setInt(ups, "LIBUSB_DEBUG", val); } inline void setFrequency(const std::string & ups, long long int frequency) { setInt(ups, "frequency", frequency); } // CHECKME inline void setHourOff(const std::string & ups, long long int houroff) { setInt(ups, "houroff", houroff); } // CHECKME inline void setHourOn(const std::string & ups, long long int houron) { setInt(ups, "houron", houron); } // CHECKME inline void setI2C_address(const std::string & ups, long long int val) { setInt(ups, "i2c_address", val); } inline void setIdleLoad(const std::string & ups, long long int idleload) { setInt(ups, "idleload", idleload); } // CHECKME inline void setInputTimeout(const std::string & ups, long long int timeout) { setInt(ups, "input_timeout", timeout); } // CHECKME inline void setInterruptPipeNoEventsTolerance(const std::string & ups, long long int val) { setInt(ups, "interrupt_pipe_no_events_tolerance", val); } inline void setInterruptSize(const std::string & ups, long long int val) { setInt(ups, "interruptsize", val); } inline void setLineVoltage(const std::string & ups, long long int linevoltage) { setInt(ups, "linevoltage", linevoltage); } // CHECKME inline void setLoadpercentage(const std::string & ups, long long int load) { setInt(ups, "loadPercentage", load); } // CHECKME inline void setMaxLoad(const std::string & ups, long long int max_load) { setInt(ups, "max_load", max_load); } // CHECKME inline void setMaxPollsWithoutData(const std::string & ups, long long int val) { setInt(ups, "max_polls_without_data", val); } inline void setMaxStartDelay(const std::string & ups, long long int delay) { setInt(ups, "maxstartdelay", delay); } inline void setMFR(const std::string & ups, long long int mfr) { setInt(ups, "mfr", mfr); } // CHECKME inline void setMinCharge(const std::string & ups, long long int mincharge) { setInt(ups, "mincharge", mincharge); } // CHECKME inline void setMinRuntime(const std::string & ups, long long int minruntime) { setInt(ups, "minruntime", minruntime); } // CHECKME inline void setModbus_ByteTimeoutSec(const std::string & ups, long long int val) { setInt(ups, "mod_byte_to_s", val); } inline void setModbus_ByteTimeoutUsec(const std::string & ups, long long int val) { setInt(ups, "mod_byte_to_us", val); } inline void setModbus_CHRG_addr(const std::string & ups, long long int val) { setInt(ups, "CHRG_addr", val); } inline void setModbus_CHRG_noro(const std::string & ups, long long int val) { setInt(ups, "CHRG_noro", val); } inline void setModbus_CHRG_regtype(const std::string & ups, long long int val) { setInt(ups, "CHRG_regtype", val); } inline void setModbus_DISCHRG_addr(const std::string & ups, long long int val) { setInt(ups, "DISCHRG_addr", val); } inline void setModbus_DISCHRG_noro(const std::string & ups, long long int val) { setInt(ups, "DISCHRG_noro", val); } inline void setModbus_DISCHRG_regtype(const std::string & ups, long long int val) { setInt(ups, "DISCHRG_regtype", val); } inline void setModbus_DataBits(const std::string & ups, long long int val) { setInt(ups, "databits", val); } inline void setModbus_DeviceSlaveId(const std::string & ups, long long int val) { setInt(ups, "dev_slave_id", val); } inline void setModbus_FSD_addr(const std::string & ups, long long int val) { setInt(ups, "FSD_addr", val); } inline void setModbus_FSD_noro(const std::string & ups, long long int val) { setInt(ups, "FSD_noro", val); } inline void setModbus_FSD_pulse_duration(const std::string & ups, long long int val) { setInt(ups, "FSD_pulse_duration", val); } inline void setModbus_FSD_regtype(const std::string & ups, long long int val) { setInt(ups, "FSD_regtype", val); } inline void setModbus_HB_addr(const std::string & ups, long long int val) { setInt(ups, "HB_addr", val); } inline void setModbus_HB_noro(const std::string & ups, long long int val) { setInt(ups, "HB_noro", val); } inline void setModbus_HB_regtype(const std::string & ups, long long int val) { setInt(ups, "HB_regtype", val); } inline void setModbus_LB_addr(const std::string & ups, long long int val) { setInt(ups, "LB_addr", val); } inline void setModbus_LB_noro(const std::string & ups, long long int val) { setInt(ups, "LB_noro", val); } inline void setModbus_LB_regtype(const std::string & ups, long long int val) { setInt(ups, "LB_regtype", val); } inline void setModbus_OB_addr(const std::string & ups, long long int val) { setInt(ups, "OB_addr", val); } inline void setModbus_OB_noro(const std::string & ups, long long int val) { setInt(ups, "OB_noro", val); } inline void setModbus_OB_regtype(const std::string & ups, long long int val) { setInt(ups, "OB_regtype", val); } inline void setModbus_OL_addr(const std::string & ups, long long int val) { setInt(ups, "OL_addr", val); } inline void setModbus_OL_noro(const std::string & ups, long long int val) { setInt(ups, "OL_noro", val); } inline void setModbus_OL_regtype(const std::string & ups, long long int val) { setInt(ups, "OL_regtype", val); } inline void setModbus_RB_addr(const std::string & ups, long long int val) { setInt(ups, "RB_addr", val); } inline void setModbus_RB_noro(const std::string & ups, long long int val) { setInt(ups, "RB_noro", val); } inline void setModbus_RB_regtype(const std::string & ups, long long int val) { setInt(ups, "RB_regtype", val); } inline void setModbus_ResponseTimeoutMsec(const std::string & ups, long long int val) { setInt(ups, "response_timeout_ms", val); } inline void setModbus_ResponseTimeoutSec(const std::string & ups, long long int val) { setInt(ups, "mod_resp_to_s", val); } inline void setModbus_ResponseTimeoutUsec(const std::string & ups, long long int val) { setInt(ups, "mod_resp_to_us", val); } inline void setModbus_RioSlaveId(const std::string & ups, long long int val) { setInt(ups, "rio_slave_id", val); } inline void setModbus_SerBaudRate(const std::string & ups, long long int val) { setInt(ups, "ser_baud_rate", val); } inline void setModbus_SerDataBit(const std::string & ups, long long int val) { setInt(ups, "ser_data_bit", val); } inline void setModbus_SerStopBit(const std::string & ups, long long int val) { setInt(ups, "ser_stop_bit", val); } inline void setModbus_SlaveId(const std::string & ups, long long int val) { setInt(ups, "slaveid", val); } inline void setModbus_StopBits(const std::string & ups, long long int val) { setInt(ups, "stopbits", val); } inline void setNomBattVolt(const std::string & ups, long long int nombattvolt) { setInt(ups, "nombattvolt", nombattvolt); } // CHECKME inline void setNumOfBytesFromUPS(const std::string & ups, long long int bytes) { setInt(ups, "numOfBytesFromUPS", bytes); } // CHECKME inline void setOffDelay(const std::string & ups, long long int offdelay) { setInt(ups, "OffDelay", offdelay); } // CHECKME inline void setOffdelay(const std::string & ups, long long int offdelay) { setInt(ups, "offdelay", offdelay); } // CHECKME inline void setOnDelay(const std::string & ups, long long int ondelay) { setInt(ups, "OnDelay", ondelay); } // CHECKME inline void setOndelay(const std::string & ups, long long int ondelay) { setInt(ups, "ondelay", ondelay); } // CHECKME inline void setOnlineDischargeLogThrottleHovercharge(const std::string & ups, long long int val) { setInt(ups, "onlinedischarge_log_throttle_hovercharge", val); } inline void setOnlineDischargeLogThrottleSec(const std::string & ups, long long int val) { setInt(ups, "onlinedischarge_log_throttle_sec", val); } inline void setOutputPace(const std::string & ups, long long int output_pace) { setInt(ups, "output_pace", output_pace); } // CHECKME inline void setOutputPhaseAngle(const std::string & ups, long long int val) { setInt(ups, "output_phase_angle", val); } inline void setPinsShutdownMode(const std::string & ups, long long int val) { setInt(ups, "pins_shutdown_mode", val); } inline void setPollFreq(const std::string & ups, long long int pollfreq) { setInt(ups, "pollfreq", pollfreq); } // CHECKME inline void setPowerUp(const std::string & ups, long long int powerup) { setInt(ups, "powerup", powerup); } // CHECKME inline void setPrgShut(const std::string & ups, long long int prgshut) { setInt(ups, "prgshut", prgshut); } // CHECKME inline void setRebootDelay(const std::string & ups, long long int delay) { setInt(ups, "rebootdelay", delay); } // CHECKME inline void setSDtime(const std::string & ups, long long int sdtime) { setInt(ups, "sdtime", sdtime); } // CHECKME inline void setSDOrder(const std::string & ups, long long int ord) { setInt(ups, "sdorder", ord); } inline void setSemistaticFreq(const std::string & ups, long long int val) { setInt(ups, "semistaticfreq", val); } inline void setShutdownDelay(const std::string & ups, long long int delay) { setInt(ups, "shutdown_delay", delay); } // CHECKME inline void setShutdownDuration(const std::string & ups, long long int val) { setInt(ups, "shutdown_duration", val); } inline void setShutdownTimer(const std::string & ups, long long int val) { setInt(ups, "shutdown_timer", val); } inline void setSlaveAddress(const std::string & ups, long long int val) { setInt(ups, "slave_address", val); } inline void setSnmpRetries(const std::string & ups, long long int val) { setInt(ups, "snmp_retries", val); } inline void setSnmpTimeout(const std::string & ups, long long int val) { setInt(ups, "snmp_timeout", val); } inline void setStartDelay(const std::string & ups, long long int delay) { setInt(ups, "startdelay", delay); } // CHECKME inline void setTestTime(const std::string & ups, long long int testtime) { setInt(ups, "testtime", testtime); } // CHECKME inline void setTimeout(const std::string & ups, long long int timeout) { setInt(ups, "timeout", timeout); } // CHECKME inline void setUPSdelayShutdown(const std::string & ups, long long int delay) { setInt(ups, "ups.delay.shutdown", delay); } // CHECKME inline void setUPSdelayStart(const std::string & ups, long long int delay) { setInt(ups, "ups.delay.start", delay); } // CHECKME inline void setVoltage(const std::string & ups, long long int voltage) { setInt(ups, "voltage", voltage); } // CHECKME inline void setWaitBeforeReconnect(const std::string & ups, long long int val) { setInt(ups, "waitbeforereconnect", val); } // Items below are "unused" - mostly set in // drivers/nutdrv_qx_masterguard.c inline void setFault1(const std::string & ups, const std::string & val) { setStr(ups, "fault_1", val); } inline void setFault2(const std::string & ups, const std::string & val) { setStr(ups, "fault_2", val); } inline void setFault3(const std::string & ups, const std::string & val) { setStr(ups, "fault_3", val); } inline void setFault4(const std::string & ups, const std::string & val) { setStr(ups, "fault_4", val); } inline void setFault5(const std::string & ups, const std::string & val) { setStr(ups, "fault_5", val); } inline void setInputFaultVoltage(const std::string & ups, const std::string & val) { setStr(ups, "input_fault_voltage", val); } inline void setNominalCellVoltage(const std::string & ups, const std::string & val) { setStr(ups, "nominal_cell_voltage",val); } inline void setNumberOfBatteryCells(const std::string & ups, const std::string & val) { setStr(ups, "number_of_battery_cells", val); } inline void setOutputVoltages(const std::string & ups, const std::string & val) { setStr(ups, "output_voltages", val); } inline void setRechargeTime(const std::string & ups, const std::string & val) { setStr(ups, "recharge_time", val); } inline void setRuntimeFull(const std::string & ups, const std::string & val) { setStr(ups, "runtime_full", val); } inline void setRuntimeHalf(const std::string & ups, const std::string & val) { setStr(ups, "runtime_half", val); } inline void setSeries(const std::string & ups, const std::string & val) { setStr(ups, "series", val); } // Items below are essentially booleans (expected values // are "enabled/disabled") -- refactoring planned per // https://github.com/networkupstools/nut/issues/2421 inline void setAdvancedEcoMode(const std::string & ups, const std::string & val) { setStr(ups, "advanced_eco_mode", val); } inline void setAlarmControl(const std::string & ups, const std::string & val) { setStr(ups, "alarm_control", val); } inline void setBatteryAlarm(const std::string & ups, const std::string & val) { setStr(ups, "battery_alarm", val); } inline void setBatteryOpenStatusCheck(const std::string & ups, const std::string & val) { setStr(ups, "battery_open_status_check", val); } inline void setBypassAlarm(const std::string & ups, const std::string & val) { setStr(ups, "bypass_alarm", val); } inline void setBypassForbidding(const std::string & ups, const std::string & val) { setStr(ups, "bypass_forbidding", val); } inline void setBypassWhenOff(const std::string & ups, const std::string & val) { setStr(ups, "bypass_when_off", val); } inline void setConstantPhaseAngle(const std::string & ups, const std::string & val) { setStr(ups, "constant_phase_angle",val); } inline void setConverterMode(const std::string & ups, const std::string & val) { setStr(ups, "converter_mode", val); } inline void setEcoMode(const std::string & ups, const std::string & val) { setStr(ups, "eco_mode", val); } inline void setLimitedRuntimeOnBattery(const std::string & ups, const std::string & val) { setStr(ups, "limited_runtime_on_battery", val); } inline void setSiteFaultDetection(const std::string & ups, const std::string & val) { setStr(ups, "site_fault_detection",val); } /** belkinunv: both a flag (wait for AC power) and value (also wait for charge level) */ inline void setWait(const std::string & ups, long long int wait) { setInt(ups, "wait", wait); } // CHECKME /** May be a flag or a number; 0 is among valid values (default -1 for unset) */ inline void setUsbSetAltInterface(const std::string & ups, long long int val = 0) { if (val >= 0) { setInt(ups, "usb_set_altinterface", val); } else { remove(ups, "usb_set_altinterface"); } } // CHECKME // NUT specifies these as "hexnum" values (optionally with prefixed 0x but hex anyway) inline void setUsbConfigIndex(const std::string & ups, long long int val) { setIntHex(ups, "usb_config_index", val); } // CHECKME inline void setUsbHidDescIndex(const std::string & ups, long long int val) { setIntHex(ups, "usb_hid_desc_index", val); } // CHECKME inline void setUsbHidRepIndex(const std::string & ups, long long int val) { setIntHex(ups, "usb_hid_rep_index", val); } // CHECKME inline void setUsbHidEndpointIn(const std::string & ups, long long int val) { setIntHex(ups, "usb_hid_ep_in", val); } // CHECKME inline void setUsbHidEndpointOut(const std::string & ups, long long int val) { setIntHex(ups, "usb_hid_ep_out", val); } // CHECKME inline void setBatteryMax(const std::string & ups, double val) { setDouble(ups, "battery_max", val); } inline void setBatteryMin(const std::string & ups, double val) { setDouble(ups, "battery_min", val); } inline void setCSHackDelay(const std::string & ups, double val) { setDouble(ups, "cshdelay", val); } inline void setMaxBypassFreq(const std::string & ups, double val) { setDouble(ups, "max_bypass_freq", val); } inline void setMaxBypassVolt(const std::string & ups, double val) { setDouble(ups, "max_bypass_volt", val); } inline void setMinBypassFreq(const std::string & ups, double val) { setDouble(ups, "min_bypass_freq", val); } inline void setMinBypassVolt(const std::string & ups, double val) { setDouble(ups, "min_bypass_volt", val); } // Flag - if exists then "true"; remove() to "unset" => "false" inline void setCancelShutdown(const std::string & ups, bool set = true) { setFlag(ups, "CS", set); } inline void setDumbTerm(const std::string & ups, bool set = true) { setFlag(ups, "dumbterm", set); } inline void setExplore(const std::string & ups, bool set = true) { setFlag(ups, "explore", set); } inline void setFakeLowBatt(const std::string & ups, bool set = true) { setFlag(ups, "fake_lowbatt", set); } inline void setFlash(const std::string & ups, bool set = true) { setFlag(ups, "flash", set); } inline void setIgnoreLB(const std::string & ups, bool set = true) { setFlag(ups, "ignorelb", set); } inline void setNoHang(const std::string & ups, bool set = true) { setFlag(ups, "nohang", set); } inline void setNoRating(const std::string & ups, bool set = true) { setFlag(ups, "norating", set); } inline void setNoTransferOIDs(const std::string & ups, bool set = true) { setFlag(ups, "notransferoids", set); } inline void setNoVendor(const std::string & ups, bool set = true) { setFlag(ups, "novendor", set); } inline void setNoWarnNoImp(const std::string & ups, bool set = true) { setFlag(ups, "nowarn_noimp", set); } inline void setOldMAC(const std::string & ups, bool set = true) { setFlag(ups, "oldmac", set); } inline void setPollOnly(const std::string & ups, bool set = true) { setFlag(ups, "pollonly", set); } inline void setSilent(const std::string & ups, bool set = true) { setFlag(ups, "silent", set); } inline void setStatusOnly(const std::string & ups, bool set = true) { setFlag(ups, "status_only", set); } // aka OPTI_MINPOLL inline void setSubscribe(const std::string & ups, bool set = true) { setFlag(ups, "subscribe", set); } inline void setUseCRLF(const std::string & ups, bool set = true) { setFlag(ups, "use_crlf", set); } inline void setUsePreLF(const std::string & ups, bool set = true) { setFlag(ups, "use_pre_lf", set); } inline void setNolock(const std::string & ups, bool set = true) { setBool(ups, "nolock", set); } inline void setCable(const std::string & ups, bool set = true) { setBool(ups, "cable", set); } inline void setFullUpdate(const std::string & ups, bool set = true) { setBool(ups, "full_update", set); } inline void setLangIDfix(const std::string & ups, bool set = true) { setBool(ups, "langid_fix", set); } inline void setLoadOff(const std::string & ups, bool set = true) { setBool(ups, "load.off", set); } inline void setLoadOn(const std::string & ups, bool set = true) { setBool(ups, "load.on", set); } /** \} */ virtual ~UpsConfiguration() override; }; // end of class UpsConfiguration /** upsd users configuration */ class UpsdUsersConfiguration : public GenericConfiguration { public: /** upsmon mode */ typedef enum { UPSMON_UNDEF = 0, /**< Unknown mode */ UPSMON_PRIMARY, /**< Primary (legacy "Master") mode */ UPSMON_SECONDARY, /**< Secondary (legacy "Slave") mode */ } upsmon_mode_t; /** User-specific configuration attributes getters and setters \{ */ inline std::string getPassword(const std::string & user) const { return getStr(user, "password"); } /** Currently valid actions include "SET" and "FSD", * but the method does not constrain the values */ inline ConfigParamList getActions(const std::string & user) const { ConfigParamList actions; get(user, "actions", actions); return actions; } /** Valid commands are "ALL" or a list of specific commands * supported by the device (NUT driver dependent) */ inline ConfigParamList getInstantCommands(const std::string & user) const { ConfigParamList cmds; get(user, "instcmds", cmds); return cmds; } upsmon_mode_t getUpsmonMode() const; inline void setPassword(const std::string & user, const std::string & passwd) { setStr(user, "password", passwd); } inline void setActions(const std::string & user, const ConfigParamList & actions) { set(user, "actions", actions); } inline void setInstantCommands(const std::string & user, const ConfigParamList & cmds) { set(user, "instcmds", cmds); } inline void addActions(const std::string & user, const ConfigParamList & actions) { add(user, "actions", actions); } inline void addInstantCommands(const std::string & user, const ConfigParamList & cmds) { add(user, "instcmds", cmds); } /** * \brief upsmon mode setter * * Note that the UPSMON_UNDEF mode isn't allowed as parameter * (logically, if you set something, it shall be defined...) * * \param mode Mode */ /* TOTHINK: Do we need a writer (other method, optional parameter * to this one) for obsolete wordings of the upsmon mode? * Note: reader in the getter accepts both old and new values. */ void setUpsmonMode(upsmon_mode_t mode); /** \} */ /** Serialisable interface implementation overload \{ */ bool parseFrom(NutStream & istream) override; bool writeTo(NutStream & ostream) const override; /** \} */ }; // end of class UpsdUsersConfiguration } /* namespace nut */ #endif /* __cplusplus */ #endif /* NUTCONF_H_SEEN */ nut-2.8.4/include/nutipc.hpp0000644000175000017500000005611415000736161012720 00000000000000/* nutipc.hpp - NUT IPC Copyright (C) 2012 Eaton Author: Vaclav Krpec Copyright (C) 2024-2025 NUT Community Author: Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_NUTIPC_HPP #define NUT_NUTIPC_HPP #include #include #include #include #include #include #include extern "C" { #include #include #include #ifndef WIN32 # include #else /* WIN32 */ # include "wincompat.h" #endif /* WIN32 */ #ifdef HAVE_PTHREAD # include #endif } /* See include/common.h for details behind this */ #ifndef NUT_UNUSED_VARIABLE #define NUT_UNUSED_VARIABLE(x) (void)(x) #endif namespace nut { /** * Process-related information */ class Process { private: /** The type yields no instances */ Process() {} public: /** Get current process ID */ static pid_t getPID() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** Get parent process ID */ static pid_t getPPID() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * Process main routine functor prototype */ class Main { protected: /** Formal constructor */ Main() {} virtual ~Main(); public: /* Avoid implicit copy/move operator declarations */ Main(Main&&) = default; Main& operator=(const Main&) = default; //Main& operator=(Main&&) = default; /** Routine */ virtual int operator () () = 0; }; // end of class Main /** * Child process */ template class Child { private: pid_t m_pid; /**< Child PID */ bool m_exited; /**< Exited flag */ int m_exit_code; /**< Exit code */ public: /** * \brief Constructor of child process * * The constructor calls \c ::fork to create another child process. * The child executes \ref m_main functor instance operator \c (). * When the functor's \c () operator returns, the returned value * shall be used as the child exit code (and the child will exit). * * \param main Child process main routine */ Child(M main) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif ; /** Child PID */ inline pid_t getPID() const { return m_pid; } /** * \brief Wait for child process to exit * * The method blocks as long as the child runs. * It returns the child's exit code. * It throws an exception if executed twice * (or on other illogical usage). * * \return Child process exit code */ int wait() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error) #endif ; /** * \brief Child exit code getter * * \return Child exit code */ inline int exitCode() { return wait(); } /** * \brief Destructor * * The destructor shall wait for the child process * (unless already exited). */ ~Child() { wait(); } }; // end of class Child /** * External command executor */ class Executor: public Main { public: /** Command line arguments list */ typedef std::list Arguments; private: std::string m_bin; Arguments m_args; public: /** * \brief Constructor * * The binary path may be omitted; the implementation shall perform * the actions shell would do to search for the binary (i.e. check \c PATH * environment variable); * * Note that even option switches are command line arguments; * e.g. "tail -n 20" command has 2 arguments: "-n" and "20". * * \brief bin Binary to be executed * \brief args Command-line arguments to the binary */ Executor(const std::string & bin, const Arguments & args): m_bin(bin), m_args(args) {} /** * \brief Constructor * * This constructor form splits the command string specified * to the binary and its cmd-line arguments for the caller (by spaces). * * Note however, that the command must be a binary execution; if you want * to run a shell command, you must execute the shell, explicitly; e.g: * "/bin/sh -c ''" shall probably be what you want. * * \param command Command to be executed */ Executor(const std::string & command); /** Execution of the binary */ int operator () () #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif override; }; // end of class Executor /** * External command execution */ class Execution: public Child { public: /** * Constructor * * The binary path may be omitted; the implementation shall perform * the actions shell would do to search for the binary (i.e. check \c PATH * environment variable); * * \brief binary Binary to be executed * \brief arguments Command-line arguments to the binary */ Execution(const std::string & binary, const Executor::Arguments & arguments): Child(Executor(binary, arguments)) {} /** * Constructor * * This form of the constructor splits the command string specified * to the binary and its cmd-line arguments for the caller (by spaces). * * Note however, that the command must be a binary execution; if you want * to run a shell command, you must execute the shell, explicitly; e.g: * "/bin/sh -c ''" shall probably be what you want. * * \param command Command to be executed */ Execution(const std::string & command): Child(Executor(command)) {} }; // end of class Execution /** * \brief Execute command and wait for exit code * * \param binary Binary to be executed * \param arguments Command-line arguments to the binary * * \return Exit code */ static inline int execute(const std::string & binary, const Executor::Arguments & arguments) { Execution child(binary, arguments); return child.wait(); } /** * \brief Execute command and wait for exit code * * \param command Command to be executed * * \return Exit code */ static inline int execute(const std::string & command) { Execution child(command); return child.wait(); } }; // end of class Process template Process::Child::Child(M main) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif : m_pid(0), m_exited(false), m_exit_code(0) { #ifdef WIN32 NUT_UNUSED_VARIABLE(main); /* FIXME: Implement (for NUT processes) via pipes? * See e.g. upsdrvctl implementation. */ std::stringstream e; e << "Can't fork: not implemented on this platform yet"; /* NUT_WIN32_INCOMPLETE(); */ throw std::logic_error(e.str()); #else /* !WIN32 */ m_pid = ::fork(); if (!m_pid) ::exit(main()); #endif /* !WIN32 */ } template int Process::Child::wait() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error) #endif { #ifdef WIN32 /* FIXME: Implement (for NUT processes) via pipes? * See e.g. upsdrvctl implementation. */ std::stringstream e; e << "Can't wait for PID " << m_pid << ": not implemented on this platform yet"; /* NUT_WIN32_INCOMPLETE(); */ throw std::logic_error(e.str()); #else /* !WIN32 */ if (m_exited) return m_exit_code; pid_t wpid = ::waitpid(m_pid, &m_exit_code, 0); if (-1 == wpid) { int erno = errno; std::stringstream e; e << "Failed to wait for process " << m_pid << ": "; e << erno << ": " << strerror(erno); throw std::logic_error(e.str()); } m_exited = true; m_exit_code = WEXITSTATUS(m_exit_code); return m_exit_code; #endif /* !WIN32 */ } /** * POSIX signal * * For portability reasons, only mostly common subset of POSIX.1-2001 signals are supported. */ class Signal { public: /** Signals */ typedef enum { #ifndef WIN32 HUP = SIGHUP, /** Hangup */ INT = SIGINT, /** Interrupt */ QUIT = SIGQUIT, /** Quit */ ILL = SIGILL, /** Illegal Instruction */ TRAP = SIGTRAP, /** Trace/breakpoint trap */ ABORT = SIGABRT, /** Abort */ BUS = SIGBUS, /** Bus error (bad memory access) */ FPE = SIGFPE, /** Floating point exception */ KILL = SIGKILL, /** Kill (unmaskable) */ SEGV = SIGSEGV, /** Invalid memory reference */ PIPE = SIGPIPE, /** Broken pipe */ ALARM = SIGALRM, /** Alarm */ TERM = SIGTERM, /** Termination */ USER1 = SIGUSR1, /** User-defined signal 1 */ USER2 = SIGUSR2, /** User-defined signal 2 */ CHILD = SIGCHLD, /** Child stopped or terminated */ CONT = SIGCONT, /** Continue if stopped */ STOP = SIGSTOP, /** Stop process (unmaskable) */ TSTOP = SIGTSTP, /** Stop typed at TTY */ TTYIN = SIGTTIN, /** TTY input for background process */ TTYOUT = SIGTTOU, /** TTY output for background process */ PROF = SIGPROF, /** Profiling timer expired */ SYS = SIGSYS, /** Bad argument to routine */ URG = SIGURG, /** Urgent condition on socket */ VTALRM = SIGVTALRM, /** Virtual alarm clock */ XCPU = SIGXCPU, /** CPU time limit exceeded */ XFSZ = SIGXFSZ, /** File size limit exceeded */ #endif /* !WIN32 */ } enum_t; // end of typedef enum /** Signal list */ typedef std::list List; /** * \brief Signal handler * * Signal handler interface. */ class Handler { protected: /** Formal constructor */ Handler() {} public: /** * \brief Signal handler routine * * \param signal Signal */ virtual void operator () (enum_t signal) = 0; /** Formal destructor */ virtual ~Handler(); }; // end of class Handler private: /** Formal constructor */ Signal() {} public: /** Signal handler thread handle */ template class HandlerThread { friend class Signal; private: /** Control commands */ typedef enum { HT_QUIT = 0, /**< Shutdown the thread */ HT_SIGNAL = 1, /**< Signal obtained */ } command_t; /** Communication pipe */ static int s_comm_pipe[2]; /** POSIX thread */ pthread_t m_impl; /** * \brief Signal handler thread main routine * * The function synchronously read commands from the communication pipe. * It processes control commands on its own (e.g. the quit command). * It passes all signals to signal handler instance of \ref H * Which must implement the \ref Signal::Handler interface. * The handler is instantiated in scope of the routine. * It closes the communication pipe read end in reaction to * \ref HT_QUIT command. * * \param comm_pipe_read_end Communication pipe read end * * \retval N/A (the function never returns) */ static void * main(void * comm_pipe_read_end); /** * \brief Signal handler routine * * The actual signal handler routine executed by the OS when the process * obtains signal to be handled. * The function simply writes the signal number to the signal handler * thread communication pipe (as parameter of the \ref HT_SIGNAL command). * The signal handling itself (whatever necessary) shall be done * by the dedicated thread (to avoid possible re-entrance issues). * * Note that \c ::write is required to be an async-signal-safe function by * POSIX.1-2004; also note that up to \c PIPE_BUF bytes are written atomically * as required by IEEE Std 1003.1, 2004 Edition,\c PIPE_BUF being typically * hundreds of bytes at least (POSIX requires 512B, Linux provides whole 4KiB * page). * * \param signal Signal */ static void signalNotifier(int signal); public: /** * \brief Constructor * * At most one thread per handler instance may be created. * This limitation is both due sanity reasons (it wouldn't * make much sense to handle the same signal by multiple threads) * and because of the signal handler routine only has access * to one communication pipe write end (the static member). * This is actually the only technical reason of having the class * template (so that every instance has its own static comm. queue). * However, for different handler classes, multiple handling threads * may be created (if it makes sense) since these will be different * template instances and therefore will use different static * communication pipes. * If more than 1 instance creation is attempted, an exception is thrown. * * \param siglist List of signals that shall be handled by the thread */ HandlerThread(const Signal::List & siglist) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error, std::runtime_error) #endif ; /** * \brief Terminate the thread * * The method sends the signal handler thread the \ref QUIT signal. * It blocks until the thread is joined. * Closes the communication pipe write end. */ void quit() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif ; /** * \brief Destructor * * Forces the signal handler thread termination (unless already down). */ ~HandlerThread() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif ; }; // end of HandlerThread /** * \brief Send signal to a process * * An exception is thrown if the signal isn't implemented. * * \param signame Signal name * \param pid Process ID * * \retval 0 in case of success * \retval EPERM if the process doesn't have permission to send the signal * \retval ESRCH if the process (group) identified doesn't exist */ static int send(enum_t signame, pid_t pid) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error) #endif ; /** * \brief Send signal to a process identified via PID file * * An exception is thrown if the signal isn't implemented * or PID file read fails. * * \param signame Signal name * \param pid_file File containing process PID * * \retval 0 in case of success * \retval EPERM if the process doesn't have permission to send the signal * \retval ESRCH if the process (group) identified doesn't exist */ static int send(enum_t signame, const std::string & pid_file); }; // end of class Signal /** Initialization of the communication pipes */ template int Signal::HandlerThread::s_comm_pipe[2] = { -1, -1 }; template void * Signal::HandlerThread::main(void * comm_pipe_read_end) { int rfd = *(reinterpret_cast(comm_pipe_read_end)); H handler; for (;;) { fd_set rfds; FD_ZERO(&rfds); FD_SET(rfd, &rfds); // Poll on signal pipe // Note that a straightforward blocking read could be // also used. However, select allows specifying a // timeout, which could be useful in the future (but // is not used in the current code). int fdno = ::select(FD_SETSIZE, &rfds, nullptr, nullptr, nullptr); // -1 is an error, but EINTR means the system call was // interrupted. System calls are expected to be // interrupted on signal delivery; some systems // restart them, and some don't. Getting EINTR is // therefore not actually an error, and the standard // approach is to retry. if (-1 == fdno) { if (errno == EINTR) continue; std::stringstream e; e << "Poll on communication pipe read end "; e << rfd << " failed: " << errno; throw std::runtime_error(e.str()); } assert(1 == fdno); assert(FD_ISSET(rfd, &rfds)); // Read command int word; ssize_t read_out = ::read(rfd, &word, sizeof(word)); // TBD: again, how should we treat read error? if (-1 == read_out) { std::stringstream e; e << "Failed to read command from the command pipe: "; e << errno; throw std::runtime_error(e.str()); } // POSIX probably does not prohibit reading some but // not all of the multibyte message. However, it is // unlikely that an implementation using write and // read on int-sized or smaller objects will split // them. For now our strategy is to hope this does // not happen. assert(sizeof(word) == read_out); command_t command = static_cast(word); switch (command) { case HT_QUIT: // Close comm. pipe read end ::close(rfd); // Terminate thread ::pthread_exit(nullptr); case HT_SIGNAL: { // scoping // Read signal number read_out = ::read(rfd, &word, sizeof(word)); // TBD: again, how should we treat read error? if (-1 == read_out) { std::stringstream e; e << "Failed to read signal number "; e << "from the command pipe: " << errno; throw std::runtime_error(e.str()); } assert(sizeof(word) == read_out); Signal::enum_t sig = static_cast(word); // Handle signal handler(sig); } // scoping break; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* Must not occur thanks to enum. * But otherwise we can see * error: 'switch' missing 'default' label [-Werror,-Wswitch-default] * from some overly zealous compilers. */ default: throw std::logic_error("INTERNAL ERROR: Unexpected default case reached"); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } } // Pro-forma exception throw std::logic_error("INTERNAL ERROR: Unreachable code reached"); } /** * \brief Write command to command pipe * * \param fh Pipe writing end (file handle) * \param cmd Command * \param cmd_size Command size * * \retval 0 on success * \retval errno on error */ int sigPipeWriteCmd(int fh, void * cmd, size_t cmd_size) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif ; template void Signal::HandlerThread::signalNotifier(int signal) { int sig[2] = { static_cast(Signal::HandlerThread::HT_SIGNAL), }; sig[1] = signal; // TBD: The return value is silently ignored. // Either the write should've succeeded or the handling // thread is already coming down... sigPipeWriteCmd(s_comm_pipe[1], sig, sizeof(sig)); } template Signal::HandlerThread::HandlerThread(const Signal::List & siglist) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error, std::runtime_error) #endif { #ifdef WIN32 NUT_UNUSED_VARIABLE(siglist); /* FIXME: Implement (for NUT processes) via pipes? * See e.g. upsdrvctl implementation. */ std::stringstream e; e << "Can't prepare signal handling thread: not implemented on this platform yet"; /* NUT_WIN32_INCOMPLETE(); */ throw std::logic_error(e.str()); #else /* !WIN32 */ // At most one instance per process allowed if (-1 != s_comm_pipe[1]) throw std::logic_error( "Attempt to start a duplicate of signal handling thread detected"); // Create communication pipe if (::pipe(s_comm_pipe)) { std::stringstream e; e << "Failed to create communication pipe: " << errno; throw std::runtime_error(e.str()); } // Start the thread int status = ::pthread_create(&m_impl, nullptr, &main, s_comm_pipe); if (status) { std::stringstream e; e << "Failed to start the thread: " << status; throw std::runtime_error(e.str()); } // Register signals Signal::List::const_iterator sig = siglist.begin(); for (; sig != siglist.end(); ++sig) { struct sigaction action; ::memset(&action, 0, sizeof(action)); # ifdef sigemptyset // no :: here because macro sigemptyset(&action.sa_mask); # else ::sigemptyset(&action.sa_mask); # endif action.sa_handler = &signalNotifier; int signo = static_cast(*sig); // TBD: We might want to save the old handlers... status = ::sigaction(signo, &action, nullptr); if (status) { std::stringstream e; e << "Failed to register signal handler for signal "; e << signo << ": " << errno; throw std::runtime_error(e.str()); } } #endif /* !WIN32 */ } template void Signal::HandlerThread::quit() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { static int quit = static_cast(Signal::HandlerThread::HT_QUIT); sigPipeWriteCmd(s_comm_pipe[1], &quit, sizeof(quit)); int status = ::pthread_join(m_impl, nullptr); if (status) { std::stringstream e; e << "Failed to joint signal handling thread: " << status; throw std::runtime_error(e.str()); } if (::close(s_comm_pipe[1])) { std::stringstream e; e << "Failed to close communication pipe: " << errno; throw std::runtime_error(e.str()); } s_comm_pipe[1] = -1; } template Signal::HandlerThread::~HandlerThread #if (defined __clang__) #endif () #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { // Stop the thread unless already stopped if (-1 != s_comm_pipe[1]) quit(); } /** NUT-specific signal handling */ class NutSignal: public Signal { public: /** * \brief Send signal to a NUT process * * The function assembles process-specific PID file name and path * and calls \ref Signal::send. * * An exception is thrown if the signal isn't implemented * or PID file read fails. * * \param signame Signal name * \param process File containing process PID * * \retval 0 in case of success * \retval EPERM if the process doesn't have permission to send the signal * \retval ESRCH if the process (group) identified doesn't exist */ static int send(enum_t signame, const std::string & process); }; // end of class NutSignal } // end of namespace nut #endif /* end of #ifndef NUT_NUTIPC_H */ nut-2.8.4/include/nut_platform.h0000664000175000017500000001063115000733176013567 00000000000000/** * \brief Platform-specific checks * * The header performs checks to resolve the actual build platform. * It defines macra that may be later used to produce platform-tailored * code. * * Be careful when writing platform-specific code; avoid that if possible. * * References: * http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system * * \author Vaclav Krpec * \date 2012/10/12 */ #ifndef NUT_PLATFORM_H_SEEN #define NUT_PLATFORM_H_SEEN 1 /* * In case doxygen source doc isn't generated * (which is the case at time of writing this), * just check the doxygen-documented (i.e. "**" * prefixed) NUT_PLATFORM_* macra, below. */ /* Apple Mac OS X, iOS and Darwin */ #if (defined __APPLE__ && defined __MACH__) /** Apple OS based on Mach ukernel */ # define NUT_PLATFORM_APPLE_MACH /* https://stackoverflow.com/a/2339910/4715872 */ # ifndef SOEXT # define SOEXT ".dylib" # endif # include # if (defined TARGET_OS_EMBEDDED) /** iOS (implies \ref NUT_PLATFORM_APPLE_MACH) */ # define NUT_PLATFORM_APPLE_IOS # endif # if (defined TARGET_IPHONE_SIMULATOR) /** iOS simulator (implies \ref NUT_PLATFORM_APPLE_MACH) */ # define NUT_PLATFORM_APPLE_IOS_SIMULATOR # endif # if (defined TARGET_OS_IPHONE) /** iPhone (implies \ref NUT_PLATFORM_APPLE_MACH) */ # define NUT_PLATFORM_APPLE_IPHONE # endif # if (defined TARGET_OS_MAC) /** Mac OS X (implies \ref NUT_PLATFORM_APPLE_MACH) */ # define NUT_PLATFORM_APPLE_OSX # endif #endif /* * GCC AIX issue: __unix__ nor __unix are not defined in older GCC * Addressed in GCC 4.7.0, see * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39950 * Remove if no longer necessary */ #if (defined _AIX && !defined __unix__) # define __unix__ #endif /* Microsoft Windows */ #if (defined _WIN32 || defined _WIN64) /** Windows */ # define NUT_PLATFORM_MS_WINDOWS # ifndef SOEXT # define SOEXT ".dll" # endif # if (defined NTDDI_WIN8 && NTDDI_VERSION >= NTDDI_WIN8) /** Windows 8 */ # define NUT_PLATFORM_MS_WINDOWS8 # endif /* UNIX */ /* Note that Apple OSX doesn't define __unix__ nor __unix; are they ashamed or something? */ #elif (defined __unix__ || defined __unix || defined NUT_PLATFORM_APPLE_MACH) # include # include /** UNIX */ # define NUT_PLATFORM_UNIX # if (defined _POSIX_VERSION) /** POSIX (implies \ref NUT_PLATFORM_UNIX), expands to POSIX version */ # define NUT_PLATFORM_POSIX _POSIX_VERSION # endif # if (defined __linux__) /** Linux (implies \ref NUT_PLATFORM_UNIX) */ # define NUT_PLATFORM_LINUX # endif # if (defined __sun && defined __SVR4) /** Solaris (implies \ref NUT_PLATFORM_UNIX) */ # define NUT_PLATFORM_SOLARIS # endif # if (defined __hpux) /** Hewlett-Packard HP-UX (implies \ref NUT_PLATFORM_UNIX) */ # define NUT_PLATFORM_HPUX /* Note: depending on CPU arch and OS version, library file * name patterns here could have been "*.so" as well. * E.g. per * https://community.hpe.com/t5/operating-system-hp-ux/so-and-sl-files/td-p/3780528 * *.sl are used in PA-RISC (11.11) * *.so shared libraries are used in HP-UX 11.20 and upwards. * Integrity (Itanium-based) HPUX can use *.sl as well, * but it is not recommended, see ld(1) under -lx: * https://web.archive.org/web/20090925153446/http://docs.hp.com/en/B2355-60103/ld.1.html */ /* FIXME: May want to detect better the CPU or OS version * to decide the SOEXT here*/ # ifndef SOEXT # define SOEXT ".sl" # endif # endif # if (defined _AIX) /** AIX (implies \ref NUT_PLATFORM_UNIX) */ # define NUT_PLATFORM_AIX # endif /* Note that BSD is defined in sys/param.h */ # if (defined BSD) /** BSD (implies \ref NUT_PLATFORM_UNIX) */ # define NUT_PLATFORM_BSD # if (defined __DragonFly__) /** DragonFly (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */ # define NUT_PLATFORM_DRAGONFLY # elif (defined __FreeBSD__) /** FreeBSD (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */ # define NUT_PLATFORM_FREEBSD # elif (defined __OpenBSD__) /** OpenBSD (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */ # define NUT_PLATFORM_OPENBSD # elif (defined __NetBSD__) /** NetBSD (implies \ref NUT_PLATFORM_UNIX, \ref NUT_PLATFORM_BSD) */ # define NUT_PLATFORM_NETBSD # endif # endif #endif /* not WIN32, not MACOS, not HPUX... */ #ifndef SOEXT # define SOEXT ".so" #endif #endif /* NUT_PLATFORM_H_SEEN */ nut-2.8.4/include/str.h0000644000175000017500000001534415044656702011700 00000000000000/* str.h - Common string-related functions * * Copyright (C) * 2000 Russell Kroll * 2015 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUT_STR_H_SEEN #define NUT_STR_H_SEEN 1 #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif /* Some compilers and/or C libraries do not handle printf("%s", NULL) correctly */ #ifndef NUT_STRARG # if (defined REQUIRE_NUT_STRARG) && (REQUIRE_NUT_STRARG == 0) # define NUT_STRARG(x) (x) # else /* Is required, or not defined => err on safe side */ # define NUT_STRARG(x) (x?x:"(null)") # endif #endif /* Remove all * - leading and trailing (str_trim[_m]()) * - leading (str_ltrim[_m]()) * - trailing (str_rtrim[_m])) * instances of * - *character* (plain versions) * - each character in *characters* ('_m' versions) * from a string. * - *string*: null-terminated byte string from which characters are to be removed; * - *character*: character that has to be removed from *string*; * - *characters*: null-terminated byte string of characters to be removed from string. * Return: * - NULL, if *string* is NULL, otherwise * - *string* without the specified characters (upto an empty string). */ char *str_trim(char *string, const char character); char *str_trim_m(char *string, const char *characters); char *str_ltrim(char *string, const char character); char *str_ltrim_m(char *string, const char *characters); char *str_rtrim(char *string, const char character); char *str_rtrim_m(char *string, const char *characters); /* Remove all * - leading and trailing (str_trim_space()) * - leading (str_ltrim_space()) * - trailing (str_rtrim_space()) * spaces (as identified by isspace()) from a string. * - *string*: null-terminated byte string from which spaces are to be removed. * Return: * - NULL, if *string* is NULL, otherwise * - *string* without the specified spaces (upto an empty string). */ char *str_trim_space(char *string); char *str_ltrim_space(char *string); char *str_rtrim_space(char *string); /* Tell whether a string can be converted to a number of type str_is_[_strict](). * - *string*: the null-terminated byte string to check; * - *base*: the base the string must conform to. * The same restrictions of the corresponding str_to_[_strict]() functions apply. * If *string* can be converted to a valid number of type , return 1. * Otherwise, return 0 with errno set to: * - ENOMEM, if available memory is insufficient; * - EINVAL, if the value of *base* is not supported or no conversion could be performed; * - ERANGE, if the converted value would be out of the acceptable range of . */ int str_is_short(const char *string, const int base); int str_is_short_strict(const char *string, const int base); int str_is_ushort(const char *string, const int base); int str_is_ushort_strict(const char *string, const int base); int str_is_int(const char *string, const int base); int str_is_int_strict(const char *string, const int base); int str_is_uint(const char *string, const int base); int str_is_uint_strict(const char *string, const int base); int str_is_long(const char *string, const int base); int str_is_long_strict(const char *string, const int base); int str_is_ulong(const char *string, const int base); int str_is_ulong_strict(const char *string, const int base); int str_is_double(const char *string, const int base); int str_is_double_strict(const char *string, const int base); /* Convert a string to a number of type str_to_[_strict](). * - *string*: the null-terminated byte string to convert, * 'strict' versions' strings shall not contain spaces (as identified by isspace()), * - short, int, long: strtol()'s restrictions apply, * - ushort, uint, ulong: strtoul()'s restrictions apply, plus: * - plus ('+') and minus ('-') signs (and hence negative values) are not supported, * - double: strtod()'s restrictions apply, plus: * - infinity and nan are not supported, * - radix character (decimal point character) must be a period ('.'); * - *number*: a pointer to a that will be filled upon execution; * - *base*: the base the string must conform to, * - short, ushort, int, uint, long, ulong: acceptable values as in strtol()/strtoul(), * - double: 0 for auto-select, 10 or 16. * On success, return 1 with *number* being the result of the conversion of *string*. * On failure, return 0 with *number* being 0 and errno set to: * - ENOMEM, if available memory is insufficient; * - EINVAL, if the value of *base* is not supported or no conversion can be performed; * - ERANGE, if the converted value is out of the acceptable range of . */ int str_to_short(const char *string, short *number, const int base); int str_to_short_strict(const char *string, short *number, const int base); int str_to_ushort(const char *string, unsigned short *number, const int base); int str_to_ushort_strict(const char *string, unsigned short *number, const int base); int str_to_int(const char *string, int *number, const int base); int str_to_int_strict(const char *string, int *number, const int base); int str_to_uint(const char *string, unsigned int *number, const int base); int str_to_uint_strict(const char *string, unsigned int *number, const int base); int str_to_long(const char *string, long *number, const int base); int str_to_long_strict(const char *string, long *number, const int base); int str_to_ulong(const char *string, unsigned long *number, const int base); int str_to_ulong_strict(const char *string, unsigned long *number, const int base); int str_to_double(const char *string, double *number, const int base); int str_to_double_strict(const char *string, double *number, const int base); /* Return non-zero if string s ends exactly with suff * Note: s=NULL always fails the test; otherwise suff=NULL always matches */ int str_ends_with(const char *s, const char *suff); #ifndef HAVE_STRSEP /* Makefile should add the implem to libcommon(client).la */ char *strsep(char **stringp, const char *delim); #define HAVE_STRSEP 1 #endif #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_STR_H_SEEN */ nut-2.8.4/include/attribute.h0000644000175000017500000000461314670526611013067 00000000000000/* attribute.h - portability hacks for __attribute__ usage in other header files Copyright (C) 2001 Russell Kroll 2005 Arnaud Quette 2020 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_ATTRIBUTE_H_SEEN #define NUT_ATTRIBUTE_H_SEEN 1 /* To complicate matters, compilers with native support * for the keyword may expose or not expose it as a macro... * but for those that perform such courtesy, or are known * supporters, we can put up the flag. For others, someone * with those compilers should check and file PRs to NUT. */ #if (!defined HAVE___ATTRIBUTE__) || (HAVE___ATTRIBUTE__ == 0) # if ( defined(__GNUC__) && ( __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) ) ) || ( defined(__STRICT_ANSI__) && __STRICT_ANSI__ ) # ifndef __attribute__ # define __attribute__(x) # endif # ifndef HAVE___ATTRIBUTE__ # define HAVE___ATTRIBUTE__ 0 # endif # else # if defined(__clang__) || defined(__GNUC__) || defined(__SUNPRO_C) # ifndef HAVE___ATTRIBUTE__ # define HAVE___ATTRIBUTE__ 1 # endif # else # ifndef HAVE___ATTRIBUTE__ # define HAVE___ATTRIBUTE__ 0 # endif # endif # endif #endif #if (!defined HAVE___ATTRIBUTE__) || (HAVE___ATTRIBUTE__ == 0) # ifdef HAVE___ATTRIBUTE__UNUSED_ARG # undef HAVE___ATTRIBUTE__UNUSED_ARG # endif # ifdef HAVE___ATTRIBUTE__UNUSED_FUNC # undef HAVE___ATTRIBUTE__UNUSED_FUNC # endif # ifdef HAVE___ATTRIBUTE__NORETURN # undef HAVE___ATTRIBUTE__NORETURN # endif # ifdef HAVE___ATTRIBUTE__ # undef HAVE___ATTRIBUTE__ # endif #endif /* Other source files now can simply check for `ifdef HAVE___ATTRIBUTE__*` * as usual, and not bother about 0/1 values of the macro as well. */ #endif /* NUT_ATTRIBUTE_H_SEEN */ nut-2.8.4/include/Makefile.in0000644000175000017500000007601115045354760012762 00000000000000# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # Network UPS Tools: include VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ # Optionally deliverable as part of NUT public API: @WITH_DEV_TRUE@am__append_1 = parseconf.h @WITH_DEV_LIBNUTCONF_TRUE@@WITH_DEV_TRUE@am__append_2 = nutstream.hpp nutwriter.hpp nutipc.hpp nutconf.hpp @WITH_DEV_LIBNUTCONF_FALSE@@WITH_DEV_TRUE@am__append_3 = nutstream.hpp nutwriter.hpp nutipc.hpp nutconf.hpp @WITH_DEV_FALSE@am__append_4 = parseconf.h nutstream.hpp nutwriter.hpp \ @WITH_DEV_FALSE@ nutipc.hpp nutconf.hpp subdir = include ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_c___attribute__.m4 \ $(top_srcdir)/m4/ax_c_pragmas.m4 \ $(top_srcdir)/m4/ax_check_compile_flag.m4 \ $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/ax_realpath.m4 \ $(top_srcdir)/m4/ax_realpath_lib.m4 \ $(top_srcdir)/m4/ax_run_or_link_ifelse.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/m4/nut_arg_with.m4 \ $(top_srcdir)/m4/nut_check_asciidoc.m4 \ $(top_srcdir)/m4/nut_check_aspell.m4 \ $(top_srcdir)/m4/nut_check_bool.m4 \ $(top_srcdir)/m4/nut_check_cppcheck.m4 \ $(top_srcdir)/m4/nut_check_headers_windows.m4 \ $(top_srcdir)/m4/nut_check_libavahi.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libgpiod.m4 \ $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libmodbus.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libnss.m4 \ $(top_srcdir)/m4/nut_check_libopenssl.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ $(top_srcdir)/m4/nut_check_libregex.m4 \ $(top_srcdir)/m4/nut_check_libsystemd.m4 \ $(top_srcdir)/m4/nut_check_libusb.m4 \ $(top_srcdir)/m4/nut_check_libwrap.m4 \ $(top_srcdir)/m4/nut_check_os.m4 \ $(top_srcdir)/m4/nut_check_pkgconfig.m4 \ $(top_srcdir)/m4/nut_check_python.m4 \ $(top_srcdir)/m4/nut_check_socketlib.m4 \ $(top_srcdir)/m4/nut_compiler_family.m4 \ $(top_srcdir)/m4/nut_func_getnameinfo_argtypes.m4 \ $(top_srcdir)/m4/nut_report_feature.m4 \ $(top_srcdir)/m4/nut_stash_warnings.m4 \ $(top_srcdir)/m4/nut_type_socklen_t.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__dist_noinst_HEADERS_DIST) \ $(am__include_HEADERS_DIST) $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__dist_noinst_HEADERS_DIST = attribute.h common.h extstate.h proto.h \ state.h str.h timehead.h upsconf.h nut_bool.h nut_float.h \ nut_stdint.h nut_platform.h wincompat.h nutstream.hpp \ nutwriter.hpp nutipc.hpp nutconf.hpp parseconf.h am__include_HEADERS_DIST = parseconf.h nutstream.hpp nutwriter.hpp \ nutipc.hpp nutconf.hpp am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } am__installdirs = "$(DESTDIR)$(includedir)" HEADERS = $(dist_noinst_HEADERS) $(include_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \ config.h.in # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) A2X = @A2X@ ACLOCAL = @ACLOCAL@ ALTPIDPATH = @ALTPIDPATH@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ ASCIIDOC = @ASCIIDOC@ ASCIIDOC_LINKMANEXT_SECTION_REWRITE = @ASCIIDOC_LINKMANEXT_SECTION_REWRITE@ ASCIIDOC_TEMPLATE_LINKMANEXT = @ASCIIDOC_TEMPLATE_LINKMANEXT@ ASCIIDOC_TEMPLATE_LINKMANEXT2 = @ASCIIDOC_TEMPLATE_LINKMANEXT2@ ASPELL = @ASPELL@ ASPELL_FILTER_LIB_PATH = @ASPELL_FILTER_LIB_PATH@ ASPELL_FILTER_SHARE_PATH = @ASPELL_FILTER_SHARE_PATH@ ASPELL_FILTER_TEX_PATH = @ASPELL_FILTER_TEX_PATH@ AUGPARSE = @AUGPARSE@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BINDIR = @BINDIR@ BSDKVMPROCLIBS = @BSDKVMPROCLIBS@ CC = @CC@ CCACHE_BASEDIR = @CCACHE_BASEDIR@ CCACHE_DIR = @CCACHE_DIR@ CCACHE_NAMESPACE = @CCACHE_NAMESPACE@ CCACHE_PATH = @CCACHE_PATH@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CONFIG_CFLAGS = @CONFIG_CFLAGS@ CONFIG_CPPFLAGS = @CONFIG_CPPFLAGS@ CONFIG_CXXFLAGS = @CONFIG_CXXFLAGS@ CONFIG_FLAGS = @CONFIG_FLAGS@ CONFIG_LDFLAGS = @CONFIG_LDFLAGS@ CONFPATH = @CONFPATH@ CPP = @CPP@ CPPCHECK = @CPPCHECK@ CPPFLAGS = @CPPFLAGS@ CPPUNIT_CFLAGS = @CPPUNIT_CFLAGS@ CPPUNIT_LIBS = @CPPUNIT_LIBS@ CPPUNIT_NUT_CXXFLAGS = @CPPUNIT_NUT_CXXFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH = @CYGPATH@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DEPLOYED_DUMMYUPS = @DEPLOYED_DUMMYUPS@ DEPLOYED_UPSC = @DEPLOYED_UPSC@ DEPLOYED_UPSD = @DEPLOYED_UPSD@ DEPLOYED_UPSIMAGE = @DEPLOYED_UPSIMAGE@ DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DOC_CHECK_LIST = @DOC_CHECK_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ DRIVER_MAN_LIST = @DRIVER_MAN_LIST@ DRIVER_MAN_LIST_PAGES = @DRIVER_MAN_LIST_PAGES@ DRVPATH = @DRVPATH@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FORCE_NUT_VERSION = @FORCE_NUT_VERSION@ GDLIB_CONFIG = @GDLIB_CONFIG@ GETENT = @GETENT@ GITLOG_END_POINT = @GITLOG_END_POINT@ GITLOG_START_POINT = @GITLOG_START_POINT@ GREP = @GREP@ HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@ HAVE_WINSOCK2_H = @HAVE_WINSOCK2_H@ HAVE_WS2TCPIP_H = @HAVE_WS2TCPIP_H@ ID = @ID@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDD = @LDD@ LDFLAGS = @LDFLAGS@ LDFLAGS_NUT_RPATH = @LDFLAGS_NUT_RPATH@ LDFLAGS_NUT_RPATH_CXX = @LDFLAGS_NUT_RPATH_CXX@ LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@ LIBAVAHI_LIBS = @LIBAVAHI_LIBS@ LIBDIR = @LIBDIR@ LIBGD_CFLAGS = @LIBGD_CFLAGS@ LIBGD_LDFLAGS = @LIBGD_LDFLAGS@ LIBGPIO_CFLAGS = @LIBGPIO_CFLAGS@ LIBGPIO_LIBS = @LIBGPIO_LIBS@ LIBI2C_LIBS = @LIBI2C_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBMODBUS_CFLAGS = @LIBMODBUS_CFLAGS@ LIBMODBUS_LIBS = @LIBMODBUS_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ LIBNETSNMP_LIBS = @LIBNETSNMP_LIBS@ LIBOBJS = @LIBOBJS@ LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@ LIBPOWERMAN_LIBS = @LIBPOWERMAN_LIBS@ LIBREGEX_LIBS = @LIBREGEX_LIBS@ LIBS = @LIBS@ LIBSSL_CFLAGS = @LIBSSL_CFLAGS@ LIBSSL_LDFLAGS_RPATH = @LIBSSL_LDFLAGS_RPATH@ LIBSSL_LIBS = @LIBSSL_LIBS@ LIBSSL_REQUIRES = @LIBSSL_REQUIRES@ LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIBUSB_CFLAGS = @LIBUSB_CFLAGS@ LIBUSB_CONFIG = @LIBUSB_CONFIG@ LIBUSB_LIBS = @LIBUSB_LIBS@ LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@ LIBWRAP_LIBS = @LIBWRAP_LIBS@ LIPO = @LIPO@ LN_S = @LN_S@ LN_S_R = @LN_S_R@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MAN_DIR_AS_BASE = @MAN_DIR_AS_BASE@ MAN_SECTION_API = @MAN_SECTION_API@ MAN_SECTION_API_BASE = @MAN_SECTION_API_BASE@ MAN_SECTION_CFG = @MAN_SECTION_CFG@ MAN_SECTION_CFG_BASE = @MAN_SECTION_CFG_BASE@ MAN_SECTION_CMD_SYS = @MAN_SECTION_CMD_SYS@ MAN_SECTION_CMD_SYS_BASE = @MAN_SECTION_CMD_SYS_BASE@ MAN_SECTION_CMD_USR = @MAN_SECTION_CMD_USR@ MAN_SECTION_CMD_USR_BASE = @MAN_SECTION_CMD_USR_BASE@ MAN_SECTION_MISC = @MAN_SECTION_MISC@ MAN_SECTION_MISC_BASE = @MAN_SECTION_MISC_BASE@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ NETLIBS = @NETLIBS@ NETLIBS_GETADDRS = @NETLIBS_GETADDRS@ NET_SNMP_CONFIG = @NET_SNMP_CONFIG@ NM = @NM@ NMEDIT = @NMEDIT@ NUT_AM_EXPORT_CCACHE_BASEDIR = @NUT_AM_EXPORT_CCACHE_BASEDIR@ NUT_AM_EXPORT_CCACHE_DIR = @NUT_AM_EXPORT_CCACHE_DIR@ NUT_AM_EXPORT_CCACHE_NAMESPACE = @NUT_AM_EXPORT_CCACHE_NAMESPACE@ NUT_AM_EXPORT_CCACHE_PATH = @NUT_AM_EXPORT_CCACHE_PATH@ NUT_AM_MAKE_CAN_EXPORT = @NUT_AM_MAKE_CAN_EXPORT@ NUT_CONFIG_CFLAGS = @NUT_CONFIG_CFLAGS@ NUT_CONFIG_CPPFLAGS = @NUT_CONFIG_CPPFLAGS@ NUT_CONFIG_CXXFLAGS = @NUT_CONFIG_CXXFLAGS@ NUT_CONFIG_LDFLAGS = @NUT_CONFIG_LDFLAGS@ NUT_DATADIR = @NUT_DATADIR@ NUT_LIBEXECDIR = @NUT_LIBEXECDIR@ NUT_MANDIR = @NUT_MANDIR@ NUT_NETVERSION = @NUT_NETVERSION@ NUT_SOURCE_GITREV = @NUT_SOURCE_GITREV@ NUT_SOURCE_GITREV_IS_PRERELEASE = @NUT_SOURCE_GITREV_IS_PRERELEASE@ NUT_SOURCE_GITREV_IS_RELEASE = @NUT_SOURCE_GITREV_IS_RELEASE@ NUT_SOURCE_GITREV_NUMERIC = @NUT_SOURCE_GITREV_NUMERIC@ NUT_SOURCE_GITREV_SEMVER = @NUT_SOURCE_GITREV_SEMVER@ NUT_WEBSITE_BASE = @NUT_WEBSITE_BASE@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OS_NAME = @OS_NAME@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_DURING_CONFIGURE = @PATH_DURING_CONFIGURE@ PATH_SEPARATOR = @PATH_SEPARATOR@ PIDPATH = @PIDPATH@ PKGCONFIGDIR = @PKGCONFIGDIR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PORT = @PORT@ POWERDOWNFLAG = @POWERDOWNFLAG@ PREFIX = @PREFIX@ PWDTOOL = @PWDTOOL@ PYTHON = @PYTHON@ PYTHON2 = @PYTHON2@ PYTHON2_SITE_PACKAGES = @PYTHON2_SITE_PACKAGES@ PYTHON3 = @PYTHON3@ PYTHON3_SITE_PACKAGES = @PYTHON3_SITE_PACKAGES@ PYTHON_SITE_PACKAGES = @PYTHON_SITE_PACKAGES@ RANLIB = @RANLIB@ REALPATH = @REALPATH@ RUN_AS_GROUP = @RUN_AS_GROUP@ RUN_AS_USER = @RUN_AS_USER@ SBINDIR = @SBINDIR@ SED = @SED@ SEMLIBS = @SEMLIBS@ SERLIBS = @SERLIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ SOURCE_HIGHLIGHT = @SOURCE_HIGHLIGHT@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ SYSTEMCTL = @SYSTEMCTL@ SYSTEMD_ANALYZE_PROGRAM = @SYSTEMD_ANALYZE_PROGRAM@ SYSTEMD_DAEMON_ARGS_DRIVER = @SYSTEMD_DAEMON_ARGS_DRIVER@ SYSTEMD_DAEMON_ARGS_UPSD = @SYSTEMD_DAEMON_ARGS_UPSD@ SYSTEMD_DAEMON_ARGS_UPSLOG = @SYSTEMD_DAEMON_ARGS_UPSLOG@ SYSTEMD_DAEMON_ARGS_UPSMON = @SYSTEMD_DAEMON_ARGS_UPSMON@ SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER = @SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSD = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSD@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON@ SYSTEMD_DAEMON_TYPE_DRIVER = @SYSTEMD_DAEMON_TYPE_DRIVER@ SYSTEMD_DAEMON_TYPE_UPSD = @SYSTEMD_DAEMON_TYPE_UPSD@ SYSTEMD_DAEMON_TYPE_UPSLOG = @SYSTEMD_DAEMON_TYPE_UPSLOG@ SYSTEMD_DAEMON_TYPE_UPSMON = @SYSTEMD_DAEMON_TYPE_UPSMON@ SYSTEMD_DAEMON_WATCHDOG_DRIVER = @SYSTEMD_DAEMON_WATCHDOG_DRIVER@ SYSTEMD_DAEMON_WATCHDOG_UPSD = @SYSTEMD_DAEMON_WATCHDOG_UPSD@ SYSTEMD_DAEMON_WATCHDOG_UPSLOG = @SYSTEMD_DAEMON_WATCHDOG_UPSLOG@ SYSTEMD_DAEMON_WATCHDOG_UPSMON = @SYSTEMD_DAEMON_WATCHDOG_UPSMON@ SYSTEMD_SYSTEMCTL_PROGRAM = @SYSTEMD_SYSTEMCTL_PROGRAM@ SYSTEMD_TMPFILES_PROGRAM = @SYSTEMD_TMPFILES_PROGRAM@ TREE_VERSION = @TREE_VERSION@ VALGRIND = @VALGRIND@ VERSION = @VERSION@ WINDMC = @WINDMC@ WINDRES = @WINDRES@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ XMLLINT = @XMLLINT@ XSLTPROC = @XSLTPROC@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ ac_ct_LD = @ac_ct_LD@ ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ auglensdir = @auglensdir@ auglenstestsdir = @auglenstestsdir@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ cgiexecdir = @cgiexecdir@ datadir = @datadir@ datarootdir = @datarootdir@ devddir = @devddir@ docdir = @docdir@ driverexecdir = @driverexecdir@ dummy_PKG_CONFIG = @dummy_PKG_CONFIG@ dummy_PKG_CONFIG_CFLAGS = @dummy_PKG_CONFIG_CFLAGS@ dummy_PKG_CONFIG_LIBS = @dummy_PKG_CONFIG_LIBS@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ freebsdquirksdir = @freebsdquirksdir@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ hotplugdir = @hotplugdir@ htmldir = @htmldir@ htmldocdir = @htmldocdir@ htmlmandir = @htmlmandir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ now = @now@ nut_with_nut_monitor = @nut_with_nut_monitor@ nut_with_nut_monitor_desktop = @nut_with_nut_monitor_desktop@ nut_with_nut_monitor_dir = @nut_with_nut_monitor_dir@ nut_with_nut_monitor_py2gtk2 = @nut_with_nut_monitor_py2gtk2@ nut_with_nut_monitor_py3qt5 = @nut_with_nut_monitor_py3qt5@ nut_with_nut_monitor_py3qt6 = @nut_with_nut_monitor_py3qt6@ nut_with_pynut = @nut_with_pynut@ nut_with_pynut_py = @nut_with_pynut_py@ nut_with_pynut_py2 = @nut_with_pynut_py2@ nut_with_pynut_py3 = @nut_with_pynut_py3@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ systemdshutdowndir = @systemdshutdowndir@ systemdsystempresetdir = @systemdsystempresetdir@ systemdsystemunitdir = @systemdsystemunitdir@ systemdtmpfilesdir = @systemdtmpfilesdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ udevdir = @udevdir@ include_HEADERS = $(am__append_1) $(am__append_2) dist_noinst_HEADERS = attribute.h common.h extstate.h proto.h state.h \ str.h timehead.h upsconf.h nut_bool.h nut_float.h nut_stdint.h \ nut_platform.h wincompat.h $(am__append_3) $(am__append_4) # http://www.gnu.org/software/automake/manual/automake.html#Clean BUILT_SOURCES = nut_version.h CLEANFILES = nut_version.h nut_version.h.tmp* MAINTAINERCLEANFILES = Makefile.in .dirstamp all: $(BUILT_SOURCES) config.h $(MAKE) $(AM_MAKEFLAGS) all-am .SUFFIXES: $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu include/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu include/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): config.h: stamp-h1 @test -f $@ || rm -f stamp-h1 @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status @rm -f stamp-h1 cd $(top_builddir) && $(SHELL) ./config.status include/config.h $(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f stamp-h1 touch $@ distclean-hdr: -rm -f config.h stamp-h1 mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-includeHEADERS: $(include_HEADERS) @$(NORMAL_INSTALL) @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \ $(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \ fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ done | $(am__base_list) | \ while read files; do \ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \ $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \ done uninstall-includeHEADERS: @$(NORMAL_UNINSTALL) @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$(top_distdir)" distdir="$(distdir)" \ dist-hook check-am: all-am check: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) check-am all-am: Makefile $(HEADERS) config.h installdirs: for dir in "$(DESTDIR)$(includedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) install-am install-exec: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) clean: clean-am clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile distclean-am: clean-am distclean-generic distclean-hdr distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-includeHEADERS install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-includeHEADERS .MAKE: all check install install-am install-exec install-strip .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ clean-libtool cscopelist-am ctags ctags-am dist-hook distclean \ distclean-generic distclean-hdr distclean-libtool \ distclean-tags distdir dvi dvi-am html html-am info info-am \ install install-am install-data install-data-am install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-includeHEADERS install-info \ install-info-am install-man install-pdf install-pdf-am \ install-ps install-ps-am install-strip installcheck \ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am uninstall-includeHEADERS .PRECIOUS: Makefile # Export certain values for ccache which NUT ci_build.sh can customize, # to facilitate developer iteration re-runs of "make" later. # At least GNU and BSD make implementations are okay with this syntax. @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_NAMESPACE@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_BASEDIR@export CCACHE_BASEDIR=@CCACHE_BASEDIR@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_DIR@export CCACHE_DIR=@CCACHE_DIR@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_PATH@export CCACHE_PATH=@CCACHE_PATH@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_PATH@export PATH=@PATH_DURING_CONFIGURE@ # magic to include Git version information in NUT version string # (for builds not made from the tagged commit in a Git workspace) # NOTE: For pre-releases, SEMVER may differ from NUT_VERSION base # (e.g. a commit tagged as 2.8.3-rc5 can have its own NUT_VERSION based # on 2.8.2-something, but is assumed as a pre-release for 2.8.3 SEMVER) nut_version.h: @FORCE_NUT_VERSION@ @echo " GENERATE-HEADER $@" ; \ RES=0; \ GITREV="`$(top_srcdir)/tools/gitlog2version.sh`" || GITREV=""; \ GITREV_IS_RELEASE="`NUT_VERSION_QUERY=IS_RELEASE $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_IS_RELEASE="false"; \ GITREV_IS_PRERELEASE="`NUT_VERSION_QUERY=IS_PRERELEASE $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_IS_PRERELEASE="false"; \ GITREV_SEMVER="`NUT_VERSION_QUERY=SEMVER $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_SEMVER=""; \ { echo '/* Autogenerated file. Do not change. */' ; \ echo '/* This file was generated by "make". */' ; \ if [ -z "$$GITREV" ]; then \ NUT_VERSION="$(PACKAGE_VERSION)"; \ echo '/* The version number is set by AC_INIT in configure.ac. */' ; \ else \ NUT_VERSION="$$GITREV"; \ echo '/* The version number is determined by Git source commit hash' ; \ echo ' * and number of commits since the most recent Git tag (if not' ; \ echo ' * building the newest tagged commit itself - then just the tag).'; \ echo ' */' ; \ fi ; \ if [ -z "$$GITREV_SEMVER" ]; then \ GITREV_SEMVER="@NUT_SOURCE_GITREV_SEMVER@"; \ fi ; \ echo "#define NUT_VERSION_MACRO \"$$NUT_VERSION\"" ; \ echo "#define NUT_VERSION_SEMVER_MACRO \"$$GITREV_SEMVER\"" ; \ if $$GITREV_IS_RELEASE ; then \ echo "#define NUT_VERSION_IS_RELEASE 1" ; \ else \ echo "#define NUT_VERSION_IS_RELEASE 0" ; \ fi ; \ if $$GITREV_IS_PRERELEASE ; then \ echo "#define NUT_VERSION_IS_PRERELEASE 1" ; \ else \ echo "#define NUT_VERSION_IS_PRERELEASE 0" ; \ fi ; \ } > "$@.tmp.$$$$" && \ echo "NUT_VERSION: \"$$NUT_VERSION\" NUT_VERSION_IS_RELEASE:$$GITREV_IS_RELEASE NUT_VERSION_IS_PRERELEASE:$$GITREV_IS_PRERELEASE NUT_VERSION_SEMVER: \"$$GITREV_SEMVER\"" && \ if test -f "$@" && test -s "$@" ; then \ if cmp -s "$@.tmp.$$$$" "$@" ; then \ echo " GENERATE-HEADER $@ did not change" ; \ else \ echo " GENERATE-HEADER $@ got changed" ; \ cp "$@.tmp.$$$$" "$@" ; \ fi ; \ else \ echo " GENERATE-HEADER $@ was absent"; \ cp "$@.tmp.$$$$" "$@" ; \ fi \ || RES=$$? ; \ rm -f "$@.tmp.$$$$" ; \ exit $$RES FORCE: # counter part of BUILT_SOURCES: since nut_version is not a direct # deps of a local target, we must clean it by ourselves before the # distribution dist-hook: $(AM_V_at)rm -f $(distdir)/nut_version.h all-libs-local: nut_version.h # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: nut-2.8.4/include/common.h0000644000175000017500000007251215044667045012362 00000000000000/* common.h - prototypes for the common useful functions Copyright (C) 2000 Russell Kroll 2020-2025 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_COMMON_H_SEEN #define NUT_COMMON_H_SEEN 1 /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif #ifdef WIN32 # ifndef __POSIX_VISIBLE /* for fcntl() and its flags in MSYS2 */ # define __POSIX_VISIBLE 200809 # endif #endif /* WIN32 */ /* Need this on AIX when using xlc to get alloca */ #ifdef _AIX #pragma alloca #endif /* _AIX */ #include #include #include #include #include /* suseconds_t among other things */ #include #ifdef HAVE_SYS_SIGNAL_H #include #endif #ifdef HAVE_SIGNAL_H #include #endif #include #ifdef HAVE_STRINGS_H #include /* for strncasecmp() and strcasecmp() */ #endif #ifdef HAVE_STRING_H #include /* for strdup() and many others */ #endif #ifndef WIN32 # include #else /* WIN32 */ # include # include # include #endif /* WIN32 */ #ifdef NUT_WANT_INET_NTOP_XX /* We currently have a few consumers who should define this macro before * including common.h, while we do not want to encumber preprocessing the * majority of codebase with these headers and our (thread-unsafe) methods. */ # ifndef WIN32 # include # include # include # include # endif /* WIN32 */ #endif /* NUT_WANT_INET_NTOP_XX */ #include /* useconds_t */ #ifndef HAVE_USECONDS_T # define useconds_t unsigned long int #endif #ifndef HAVE_SUSECONDS_T /* Note: WIN32 may have this defined as just "long" which should * hopefully be identical to the definition below, which we test * in our configure script. See also struct timeval fields for a * platform, if in doubt. */ # define suseconds_t signed long int #endif #include #include "timehead.h" #include "attribute.h" #include "proto.h" #include "str.h" #if (defined HAVE_LIBREGEX && HAVE_LIBREGEX) # include #endif #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif /* POSIX requires these, and most but not all systems use same * magical numbers for the file descriptors... yep, not all do! */ #ifndef STDIN_FILENO # define STDIN_FILENO 0 /* standard input file descriptor */ #endif #ifndef STDOUT_FILENO # define STDOUT_FILENO 1 /* standard output file descriptor */ #endif #ifndef STDERR_FILENO # define STDERR_FILENO 2 /* standard error file descriptor */ #endif /* porting stuff for WIN32, used by serial and SHUT codebases */ #ifndef WIN32 /* Just match three macro groups defined for WIN32 */ /* Type of what file open() and close() use, * including pipes for driver-upsd communications: */ # define TYPE_FD int # define ERROR_FD (-1) # define VALID_FD(a) (a>=0) /* Type of what NUT serial/SHUT methods juggle: */ # define TYPE_FD_SER TYPE_FD # define ERROR_FD_SER ERROR_FD # define VALID_FD_SER(a) VALID_FD(a) /* Type of what socket() returns, mostly for networked code: */ # define TYPE_FD_SOCK TYPE_FD # define ERROR_FD_SOCK ERROR_FD # define VALID_FD_SOCK(a) VALID_FD(a) #else /* WIN32 */ /* Separate definitions of TYPE_FD, ERROR_FD, VALID_FD() macros * for usual file descriptors vs. types needed for serial port * work or for networking sockets. */ # define TYPE_FD HANDLE # define ERROR_FD (INVALID_HANDLE_VALUE) # define VALID_FD(a) (a!=INVALID_HANDLE_VALUE) # ifndef INVALID_SOCKET # define INVALID_SOCKET -1 # endif # define TYPE_FD_SOCK SOCKET # define ERROR_FD_SOCK INVALID_SOCKET # define VALID_FD_SOCK(a) (a!=INVALID_SOCKET) typedef struct serial_handler_s { HANDLE handle; OVERLAPPED io_status; int overlapped_armed; unsigned int vmin_; unsigned int vtime_; unsigned int r_binary; unsigned int w_binary; } serial_handler_t; # define TYPE_FD_SER serial_handler_t * # define ERROR_FD_SER (NULL) # define VALID_FD_SER(a) (a!=NULL) /* difftime returns erroneous value so we use this macro */ # undef difftime # define difftime(t1,t0) (double)(t1 - t0) #endif /* WIN32 */ /* Two uppercase letters are more readable than one exclamation */ #define INVALID_FD_SER(a) (!VALID_FD_SER(a)) #define INVALID_FD_SOCK(a) (!VALID_FD_SOCK(a)) #define INVALID_FD(a) (!VALID_FD(a)) #define SIZEOF_ARRAY(a) (sizeof(a) / sizeof(a[0])) extern const char *UPS_VERSION; /* Use in code to notify the developers and quiesce the compiler that * (for this codepath) the argument or variable is unused intentionally. * void f(int x) { * NUT_UNUSED_VARIABLE(x); * ... * } * * Note that solutions which mark up function arguments or employ this or * that __attribute__ proved not portable enough for wherever NUT builds. */ #define NUT_UNUSED_VARIABLE(x) (void)(x) /** @brief Default timeout (in seconds) for network operations, as used by `upsclient` and `nut-scanner`. */ #define DEFAULT_NETWORK_TIMEOUT 5 /** @brief Default timeout (in seconds) for retrieving the result of a `TRACKING`-enabled operation (e.g. `INSTCMD`, `SET VAR`). */ #define DEFAULT_TRACKING_TIMEOUT 10 /* Returns a pointer to static internal char[] buffer with current value * of NUT_VERSION_MACRO (aka char* UPS_VERSION) and its layman description * (e.g. a "release" or "development iteration after" a certain semantically * versioned release). Returns UPS_VERSION if failed to construct a better * description. Either way, should not be free()'d by caller and does not * have an end-of-line char of its own. */ const char *describe_NUT_VERSION_once(void); /* Return a buffer with a (possibly multiline) string that can be printed * as part of program help/usage message. Caller should not free() the buffer. * Optional "progconf" allows to suggest config file(s) to study as well. * NOTE: the string in buffer starts with text and ends with one EOL char. */ const char *suggest_doc_links(const char *progname, const char *progconf); /* For drivers that failed to start because they could not hold on to a * device, on systems where the nut-driver-enumerator could produce units * that conflict with a manually-launched driver program, suggest that * this may be the case. Has some work on systems where NDE can be used * (currently where SMF or SystemD were considered during build), no-op * on others. * We define this in one spot, to change conditions or wording easily. */ void suggest_NDE_conflict(void); /* Based on NUT_QUIET_INIT_BANNER envvar (present and empty or "true") * hide the NUT tool name+version banners; show them by default */ int banner_is_disabled(void); /* Some NUT programs have historically printed their banner at start-up * always, and so did not print one in help()/usage() or handling `-V` * like others did. Now that we have NUT_QUIET_INIT_BANNER, we need a * way to print that banner (regardless of the flag in some cases). * The "even_if_disabled" should be 0 for initial banner of those * programs (so the envvar would hide it), 1 -V case and 2 in -h case * (for a blank line after). As before, the banner is printed to stdout. * Returns the result of printf() involved. Remembers to not print again * if the earlier printf() was successful. */ int print_banner_once(const char *prog, int even_if_disabled); /* Normally we can (attempt to) use the syslog or Event Log (WIN32), * but environment variable NUT_DEBUG_SYSLOG allows to bypass it, and * perhaps keep daemons logging to stderr (e.g. in NUT Integration Test * suite to not pollute the OS logs, or in systemd where stderr and * syslog both go into the same journal). Returns: * 0 Not disabled (NUT_DEBUG_SYSLOG not set to a value below; unset or "default" * values are handled quietly, but others emit a warning) * 1 Disabled and background() keeps stderr attached (NUT_DEBUG_SYSLOG="stderr") * 2 Disabled and background() detaches stderr as usual (NUT_DEBUG_SYSLOG="none") */ int syslog_is_disabled(void); /* get the syslog ready for us */ void open_syslog(const char *progname); /* close ttys and become a daemon */ void background(void); /* do this here to keep pwd/grp stuff out of the main files */ struct passwd *get_user_pwent(const char *name); /* change to the user defined in the struct */ void become_user(struct passwd *pw); /* drop down into a directory and throw away pointers to the old path */ void chroot_start(const char *path); /* Try to identify process (program) name for the given PID, * return NULL if we can not for any reason (does not run, * no rights, do not know how to get it on current OS, etc.) * If the returned value is not NULL, caller should free() it. * Some implementation pieces borrowed from * https://man7.org/linux/man-pages/man2/readlink.2.html and * https://github.com/openbsd/src/blob/master/bin/ps/ps.c * NOTE: Very much platform-dependent! */ char * getprocname(pid_t pid); /* Determine the base name of specified progname (may be full path) * and the location of the last "." dot character in it for extension * (caller's len and dot populated only if pointers are not NULL). */ size_t parseprogbasename(char *buf, size_t buflen, const char *progname, size_t *pprogbasenamelen, size_t *pprogbasenamedot); /* If we can determine the binary path name of the specified "pid", * check if it matches the assumed name of the current program. * Returns: * -3 Skipped because NUT_IGNORE_CHECKPROCNAME is set * -2 Could not parse a program name (ok to proceed, * risky - but matches legacy behavior) * -1 Could not identify a program name (ok to proceed, * risky - but matches legacy behavior) * 0 Process name identified, does not seem to match * 1+ Process name identified, and seems to match with * varying precision * Generally speaking, if (checkprocname(...)) then ok to proceed */ int checkprocname(pid_t pid, const char *progname); /* compareprocname() does the bulk of work for checkprocname() * and returns same values. The "pid" argument is used for logging. * Generally speaking, if (compareprocname(...)) then ok to proceed */ int compareprocname(pid_t pid, const char *procname, const char *progname); /* Helper for the above methods and some others. If it returns true (1), * work about PID-name comparison should be quickly skipped. */ int checkprocname_ignored(const char *caller); /* write a pid file - is a full pathname *or* just the program name */ void writepid(const char *name); /* parses string buffer into a pid_t if it passes * a few sanity checks; returns -1 on error */ pid_t parsepid(const char *buf); /* send a signal to another running NUT process */ #ifndef WIN32 int sendsignal(const char *progname, int sig, int check_current_progname); #else /* WIN32 */ int sendsignal(const char *progname, const char * sig, int check_current_progname); #endif /* WIN32 */ int snprintfcat(char *dst, size_t size, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); /***************************************************************************** * String methods for space-separated token lists, used originally in dstate * * NOTE: These methods are also exposed by external API (via libupsclient.h) * * with the `upscli_` prefix, to ease third-party C NUT clients' parsing of * * `ups.status` et al. * *****************************************************************************/ /* Return non-zero if "string" contains "token" (case-sensitive), * either surrounded by space character(s) or start/end of "string", * or 0 if that token is not there, or if either string is NULL or empty. */ int str_contains_token(const char *string, const char *token); /* Add "token" to end of string "tgt", if it is not yet there * (prefix it with a space character if "tgt" is not empty). * Return 0 if already there, 1 if token was added successfully, * -1 if we needed to add it but it did not fit under the tgtsize limit, * -2 if either string was NULL or "token" was empty. * NOTE: If token contains space(s) inside, recurse to treat it * as several tokens to add independently. * Optionally calls "callback_always" (if not NULL) after checking * for spaces (and maybe recursing) and before checking if the token * is already there, and/or "callback_unique" (if not NULL) after * checking for uniqueness and going to add a newly seen token. * If such callback returns 0, abort the addition of token and return -3. */ int str_add_unique_token(char *tgt, size_t tgtsize, const char *token, int (*callback_always)(char *, size_t, const char *), int (*callback_unique)(char *, size_t, const char *) ); /* Report maximum platform value for the pid_t */ pid_t get_max_pid_t(void); /* send sig to pid after some sanity checks, returns * -1 for error, or zero for a successfully sent signal */ int sendsignalpid(pid_t pid, int sig, const char *progname, int check_current_progname); /* open and get the pid * returns zero or more for successfully retrieved value, * negative for errors: * -3 PID file not found * -2 PID file not parsable */ pid_t parsepidfile(const char *pidfn); #ifndef WIN32 /* use parsepidfile() to get the pid, then send it * returns zero for successfully sent signal, * negative for errors: * -3 PID file not found * -2 PID file not parsable * -1 Error sending signal * * if executable process with that pid has suitable progname * (specified or that of the current process, depending on args: * most daemons request to check_current_progname for their other * process instancees, but upsdrvctl which manages differently * named driver programs does not request it) */ int sendsignalfn(const char *pidfn, int sig, const char *progname, int check_current_progname); #else /* WIN32 */ /* No progname here - communications via named pipe */ int sendsignalfn(const char *pidfn, const char * sig, const char *progname_ignored, int check_current_progname_ignored); #endif /* WIN32 */ const char *xbasename(const char *file); /* enable writing upslog_with_errno() and upslogx() type messages to the syslog */ void syslogbit_set(void); /* Return the default path for the directory containing configuration files */ const char * confpath(void); /* Return the default path for the directory containing state files */ const char * dflt_statepath(void); /* Return the alternate path for pid files (non-root daemons) */ const char * altpidpath(void); /* Return the main path for pid files (root daemons like upsmon) */ const char * rootpidpath(void); /* Die with a standard message if socket filename is too long */ void check_unix_socket_filename(const char *fn); #ifdef NUT_WANT_INET_NTOP_XX /* NOT THREAD SAFE! * Helpers to convert one IP address to string from different structure types * Return pointer to internal buffer, or NULL and errno upon errors */ const char *inet_ntopSS(struct sockaddr_storage *s); const char *inet_ntopAI(struct addrinfo *ai); #endif /* NUT_WANT_INET_NTOP_XX */ /* Provide integration for systemd inhibitor interface (where available, * dummy code otherwise) implementing the pseudo-code example from * https://systemd.io/INHIBITOR_LOCKS/ * TODO: Potentially extensible to other frameworks with similar concepts?.. */ TYPE_FD Inhibit(const char *arg_what, const char *arg_who, const char *arg_why, const char *arg_mode); /* Let the service management framework proceed with its sleep mode */ void Uninhibit(TYPE_FD *fd_ptr); /* Check once if the system plans to sleep or is waking up: * -1 Same reply as before, whatever it was * 0 (false) Just after the sleep, at least as a bus signal * 1 (true) Before the sleep - we must process and un-block it */ int isPreparingForSleep(void); /* A couple of methods to reflect built-in (absent) or run-time (it depends) * support for monitoring that the OS goes to sleep and wakes up, and if we * can "inhibit" that going to sleep in order to do some house-keeping first. * -1 = do not know yet * 0 = not supported, do not bother asking in daemon loops * 1 = seems supported */ int isInhibitSupported(void); int isPreparingForSleepSupported(void); /* Send (daemon) state-change notifications to an * external service management framework such as systemd. * State types below are initially loosely modeled after * https://www.freedesktop.org/software/systemd/man/sd_notify.html */ typedef enum eupsnotify_state { NOTIFY_STATE_READY = 1, NOTIFY_STATE_READY_WITH_PID, NOTIFY_STATE_RELOADING, NOTIFY_STATE_STOPPING, NOTIFY_STATE_STATUS, /* Send a text message per "fmt" below */ NOTIFY_STATE_WATCHDOG /* Ping the framework that we are still alive */ } upsnotify_state_t; const char *str_upsnotify_state(upsnotify_state_t state); /* Note: here fmt may be null, then the STATUS message would not be sent/added */ int upsnotify(upsnotify_state_t state, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); /* upslog*() messages are sent to syslog always; * their life after that is out of NUT's control */ void upslog_with_errno(int priority, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); void upslogx(int priority, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); /* upsdebug*() messages are only logged if debugging * level is high enough. To speed up a bit (minimize * passing of ultimately ignored data trough the stack) * these are "hidden" implementations wrapped into * macros for earlier routine names spread around the * codebase, they would check debug level first and * only if logging should happen - call the routine * and pass around pointers and other data. */ void s_upsdebug_with_errno(int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); void s_upsdebugx(int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); void s_upsdebug_hex(int level, const char *msg, const void *buf, size_t len); void s_upsdebug_ascii(int level, const char *msg, const void *buf, size_t len); /* These macros should help avoid run-time overheads * passing data for messages nobody would ever see. * * Also NOTE: the "level" may be specified by callers in various ways, * e.g. as a "X ? Y : Z" style expression; to catch those expansions * transparently we hide them into parentheses as "(label)". * * For stricter C99 compatibility, all parameters specified to a macro * must be populated by caller (so we do not handle "fmt, args..." where * the args part may be skipped by caller because fmt is a fixed string). * Note it is then up to the caller (and compiler checks) that at least * one argument is provided, the format string (maybe fixed) -- as would * be required by the actual s_upsdebugx*() method after macro evaluation. */ #define upsdebug_with_errno(level, ...) \ do { if (nut_debug_level >= (level)) { s_upsdebug_with_errno((level), __VA_ARGS__); } } while(0) #define upsdebugx(level, ...) \ do { if (nut_debug_level >= (level)) { s_upsdebugx((level), __VA_ARGS__); } } while(0) #define upsdebug_hex(level, msg, buf, len) \ do { if (nut_debug_level >= (level)) { s_upsdebug_hex((level), msg, buf, len); } } while(0) #define upsdebug_ascii(level, msg, buf, len) \ do { if (nut_debug_level >= (level)) { s_upsdebug_ascii((level), msg, buf, len); } } while(0) void fatal_with_errno(int status, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__((noreturn)); void fatalx(int status, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))) __attribute__((noreturn)); /* Report CONFIG_FLAGS used for this build of NUT similarly to how * upsdebugx(1, ...) would do it, but not limiting the string length */ void nut_report_config_flags(void); /* Report search paths used by ltdl-augmented code to discover and * load shared binary object files at run-time (nut-scanner, DMF...) */ void upsdebugx_report_search_paths(int level, int report_search_paths_builtin); void nut_prepare_search_paths(void); /* Internal toggle for some NUT programs that deal with signal sending. * For a detailed rationale comment see common.c */ extern int nut_sendsignal_debug_level; #define NUT_SENDSIGNAL_DEBUG_LEVEL_DEFAULT 6 #define NUT_SENDSIGNAL_DEBUG_LEVEL_FOPEN_PIDFILE 5 #define NUT_SENDSIGNAL_DEBUG_LEVEL_KILL_SIG0PING 4 extern int nut_debug_level; extern int nut_log_level; void *xmalloc(size_t size); void *xcalloc(size_t number, size_t size); void *xrealloc(void *ptr, size_t size); char *xstrdup(const char *string); int vsnprintfcat(char *dst, size_t size, const char *fmt, va_list ap); int snprintfcat(char *dst, size_t size, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); /* Define a missing va_copy using __va_copy, if available: */ #ifndef HAVE_VA_COPY # ifdef HAVE___VA_COPY # define va_copy(dest, src) __va_copy(dest, src) # endif #endif /* Mitigate the inherent insecurity of dynamically constructed formatting * strings vs. a fixed vararg list with its amounts and types of variables * printed by this or that method and pre-compiled in the program. * Verbosity is passed to upsdebugx(); a negative value should keep it quiet * (e.g. when code deliberately checks for suitable formatting constraints). * Consumers like the *_dynamic() methods here and in dstate typically use * "1" to make errors in code visible with any effort to troubleshoot them. */ /* Verbosity built into the methods which call the *_formatting_*() and * pass this value as the verbosity variable argument. It is anticipated * that some custom builds can define it to e.g. 0 to see discrepancies * at run-time without enabling any debug verbosity: */ #ifndef NUT_DYNAMICFORMATTING_DEBUG_LEVEL # define NUT_DYNAMICFORMATTING_DEBUG_LEVEL 1 #endif /* Verbosity built into consumers that deliberately check the formatting * strings for this or that outcome and do not want noise in the log: */ #define NUT_DYNAMICFORMATTING_DEBUG_LEVEL_SILENT -1 char *minimize_formatting_string(char *buf, size_t buflen, const char *fmt, int verbosity); char *minimize_formatting_string_staticbuf(const char *fmt, int verbosity); int validate_formatting_string(const char *fmt_dynamic, const char *fmt_reference, int verbosity); int vsnprintfcat_dynamic(char *dst, size_t size, const char *fmt_dynamic, const char *fmt_reference, va_list va); int snprintfcat_dynamic(char *dst, size_t size, const char *fmt_dynamic, const char *fmt_reference, ...) __attribute__ ((__format__ (__printf__, 4, 5))); int vsnprintf_dynamic(char *dst, size_t size, const char *fmt_dynamic, const char *fmt_reference, va_list va); int snprintf_dynamic(char *dst, size_t size, const char *fmt_dynamic, const char *fmt_reference, ...) __attribute__ ((__format__ (__printf__, 4, 5))); /* Practical helper with a static buffer which we can use for setting * values as a "%s" string e.g. in calls to dstate_setinfo(), etc. * Sets buffer to empty string in case of errors. */ char * mkstr_dynamic(const char *fmt_dynamic, const char *fmt_reference, ...) __attribute__ ((__format__ (__printf__, 2, 3))); /**** REGEX helper methods ****/ /* helper function: version of strcmp that tolerates NULL * pointers. NULL is considered to come before all other strings * alphabetically. */ int strcmp_null(const char *s1, const char *s2); #if (defined HAVE_LIBREGEX && HAVE_LIBREGEX) /* Helper function for compiling a regular expression. On success, * store the compiled regular expression (or NULL) in *compiled, and * return 0. On error with errno set, return -1. If the supplied * regular expression is unparseable, return -2 (an error message can * then be retrieved with regerror(3)). Note that *compiled will be an * allocated value, and must be freed with regfree(), then free(), see * regex(3). As a special case, if regex==NULL, then set * *compiled=NULL (regular expression NULL is intended to match * anything). */ int compile_regex(regex_t **compiled, const char *regex, const int cflags); /* Helper function for regular expression matching. Check if the * entire string str (minus any initial and trailing whitespace) * matches the compiled regular expression preg. Return 1 if it * matches, 0 if not. Return -1 on error with errno set. Special * cases: if preg==NULL, it matches everything (no contraint). If * str==NULL, then it is treated as "". */ int match_regex(const regex_t *preg, const char *str); /* Helper function, similar to match_regex, but the argument being * matched is a (hexadecimal) number, rather than a string. It is * converted to a 4-digit hexadecimal string. */ int match_regex_hex(const regex_t *preg, const int n); #endif /* HAVE_LIBREGEX */ /* Note: different method signatures instead of TYPE_FD_SER due to "const" */ #ifndef WIN32 ssize_t select_read(const int fd, void *buf, const size_t buflen, const time_t d_sec, const suseconds_t d_usec); ssize_t select_write(const int fd, const void *buf, const size_t buflen, const time_t d_sec, const suseconds_t d_usec); #else /* WIN32 */ ssize_t select_read(serial_handler_t *fd, void *buf, const size_t buflen, const time_t d_sec, const suseconds_t d_usec); /* Note: currently not implemented de-facto for Win32 */ ssize_t select_write(serial_handler_t * fd, const void *buf, const size_t buflen, const time_t d_sec, const suseconds_t d_usec); #endif /* WIN32 */ char * get_libname(const char* base_libname); /* Buffer sizes used for various functions */ #define SMALLBUF 512 #define LARGEBUF 1024 /** @brief (Minimum) Size that a string must have to hold a UUID4 (i.e. UUID4 length + the terminating null character). */ #define UUID4_LEN 37 #define NUT_PATH_MAX SMALLBUF #if (defined(PATH_MAX)) && PATH_MAX > NUT_PATH_MAX # undef NUT_PATH_MAX # define NUT_PATH_MAX PATH_MAX #endif #if (defined(MAX_PATH)) && MAX_PATH > NUT_PATH_MAX /* PATH_MAX is the POSIX equivalent for Microsoft's MAX_PATH */ # undef NUT_PATH_MAX # define NUT_PATH_MAX MAX_PATH #endif #if (defined(UNIX_PATH_MAX)) && UNIX_PATH_MAX > NUT_PATH_MAX # undef NUT_PATH_MAX # define NUT_PATH_MAX UNIX_PATH_MAX #endif #if (defined(MAXPATHLEN)) && MAXPATHLEN > NUT_PATH_MAX # undef NUT_PATH_MAX # define NUT_PATH_MAX MAXPATHLEN #endif /* Provide declarations for getopt() global variables */ #ifdef NEED_GETOPT_H #include #else #ifdef NEED_GETOPT_DECLS extern char *optarg; extern int optind; #endif /* NEED_GETOPT_DECLS */ #endif /* HAVE_GETOPT_H */ /* logging flags: bitmask! */ #define UPSLOG_STDERR 0x0001 #define UPSLOG_SYSLOG 0x0002 #define UPSLOG_STDERR_ON_FATAL 0x0004 #define UPSLOG_SYSLOG_ON_FATAL 0x0008 #ifndef HAVE_SETEUID # define seteuid(x) setresuid(-1,x,-1) /* Works for HP-UX 10.20 */ # define setegid(x) setresgid(-1,x,-1) /* Works for HP-UX 10.20 */ #endif /* Several NUT programs define their set_exit_flag(int) methods * which accept a signal code or similar parameter. Commonly they * also accept a few negative values summarized below, to just * exit (typically after completing a processing loop) with one * of C standard exit codes. */ #define EF_EXIT_FAILURE -1 /* eventually exit(EXIT_FAILURE); */ #define EF_EXIT_SUCCESS -2 /* eventually exit(EXIT_SUCCESS); */ #ifdef WIN32 /* FIXME : this might not be the optimal mapping between syslog and ReportEvent*/ #define LOG_ERR EVENTLOG_ERROR_TYPE #define LOG_INFO EVENTLOG_INFORMATION_TYPE #define LOG_DEBUG EVENTLOG_WARNING_TYPE #define LOG_NOTICE EVENTLOG_INFORMATION_TYPE #define LOG_ALERT EVENTLOG_ERROR_TYPE #define LOG_WARNING EVENTLOG_WARNING_TYPE #define LOG_CRIT EVENTLOG_ERROR_TYPE #define LOG_EMERG EVENTLOG_ERROR_TYPE #define closelog() #define SVCNAME TEXT("Network UPS Tools") #define EVENTLOG_PIPE_NAME TEXT("nut") #define UPSMON_PIPE_NAME TEXT("upsmon") #define UPSD_PIPE_NAME TEXT("upsd") char * getfullpath(char * relative_path); #define PATH_ETC "\\..\\etc" #define PATH_VAR_RUN "\\..\\var\\run" #define PATH_SHARE "\\..\\share" #define PATH_BIN "\\..\\bin" #define PATH_SBIN "\\..\\sbin" #define PATH_LIB "\\..\\lib" #endif /* WIN32*/ /* Return a difference of two timevals as a floating-point number */ double difftimeval(struct timeval x, struct timeval y); #if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC) && HAVE_CLOCK_GETTIME && HAVE_CLOCK_MONOTONIC double difftimespec(struct timespec x, struct timespec y); #endif #ifndef HAVE_USLEEP /* int __cdecl usleep(unsigned int useconds); */ /* Note: if we'd need to define an useconds_t for obscure systems, * it should be an int capable of string 0..1000000 value range, * so probably unsigned long int */ int __cdecl usleep(useconds_t useconds); #endif /* HAVE_USLEEP */ #ifndef HAVE_STRNLEN size_t strnlen(const char *s, size_t maxlen); #endif /* Not all platforms support the flag; this method abstracts * its use (or not) to simplify calls in the actual codebase */ /* TODO NUT_WIN32_INCOMPLETE? : Extend for TYPE_FD and WIN32 eventually? */ void set_close_on_exec(int fd); #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_COMMON_H_SEEN */ nut-2.8.4/include/nut_stdint.h0000664000175000017500000001140115000733176013244 00000000000000/* * nut_stdint.h - Network UPS Tools sets of integer types having specified widths * * Copyright (C) 2011 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_STDINT_H_SEEN #define NUT_STDINT_H_SEEN 1 /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 #endif #ifndef __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS 1 #endif #if defined HAVE_INTTYPES_H # include #endif #if defined HAVE_STDINT_H # include #endif #if defined HAVE_LIMITS_H # include #endif #ifndef SIZE_MAX #define SIZE_MAX ((size_t)(-1LL)) #endif #ifndef SSIZE_MAX #define SSIZE_MAX ((ssize_t)(-1LL)) #endif /* Printing format for size_t and ssize_t */ #ifndef PRIuSIZE # ifdef PRIsize # define PRIuSIZE PRIsize # else # if defined(__MINGW32__) || defined (WIN32) # define PRIuSIZE "llu" # else # define PRIuSIZE "zu" # endif # endif #endif #ifndef PRIxSIZE # if defined(__MINGW32__) || defined (WIN32) # define PRIxSIZE "llx" # else # define PRIxSIZE "zx" # endif #endif /* Note: Windows headers are known to define at least "d" values, * so macros below revolve around that and not "i" directly */ #ifndef PRIiSIZE # ifdef PRIssize # define PRIiSIZE PRIssize # else # ifdef PRIdSIZE # define PRIiSIZE PRIdSIZE # else # if defined(__MINGW32__) || defined (WIN32) # define PRIiSIZE "lld" # else # define PRIiSIZE "zd" # endif # define PRIdSIZE PRIiSIZE # endif # endif #else # ifndef PRIdSIZE # define PRIdSIZE PRIiSIZE # endif #endif /* format for size_t and ssize_t */ /* Printing format for uintmax_t and intmax_t */ #ifndef PRIuMAX # if defined(__MINGW32__) || defined (WIN32) # if (SIZEOF_VOID_P == 8) # ifdef PRIu64 # define PRIuMAX PRIu64 # else /* assume new enough compiler and standard, and no Windows %I64 etc... check "%ll" support via configure? */ # define PRIuMAX "llu" # endif # endif # if (SIZEOF_VOID_P == 4) # ifdef PRIu32 # define PRIuMAX PRIu32 # else /* assume new enough compiler and standard, and no Windows %I64 etc... check "%ll" support via configure? */ # define PRIuMAX "lu" # endif # endif # else /* assume new enough compiler and standard... check "%j" support via configure? */ # define PRIuMAX "ju" # endif #endif /* format for uintmax_t and intmax_t */ #ifndef PRIdMAX # ifdef PRIiMAX # define PRIdMAX PRIiMAX # else # if defined(__MINGW32__) || defined (WIN32) # if (SIZEOF_VOID_P == 8) # ifdef PRId64 # define PRIdMAX PRId64 # else /* assume new enough compiler and standard, and no Windows %I64 etc... check "%ll" support via configure? */ # define PRIdMAX "lld" # endif # endif # if (SIZEOF_VOID_P == 4) # ifdef PRId32 # define PRIdMAX PRId32 # else /* assume new enough compiler and standard, and no Windows %I64 etc... check "%ll" support via configure? */ # define PRIdMAX "ld" # endif # endif # else /* assume new enough compiler and standard... check "%j" support via configure? */ # define PRIdMAX "jd" # endif # define PRIiMAX PRIdMAX # endif #else # ifndef PRIiMAX # define PRIiMAX PRIdMAX # endif #endif /* format for uintmax_t and intmax_t */ #ifndef PRIxMAX # if defined(__MINGW32__) || defined (WIN32) # if (SIZEOF_VOID_P == 8) # ifdef PRIx64 # define PRIxMAX PRIx64 # else /* assume new enough compiler and standard, and no Windows %I64 etc... check "%ll" support via configure? */ # define PRIxMAX "llx" # endif # endif # if (SIZEOF_VOID_P == 4) # ifdef PRIx32 # define PRIxMAX PRIx32 # else /* assume new enough compiler and standard, and no Windows %I64 etc... check "%ll" support via configure? */ # define PRIxMAX "lx" # endif # endif # else /* assume new enough compiler and standard... check "%j" support via configure? */ # define PRIxMAX "jx" # endif #endif /* format for uintmax_t and intmax_t */ #endif /* NUT_STDINT_H_SEEN */ nut-2.8.4/include/extstate.h0000644000175000017500000000363414670526611012727 00000000000000/* extstate.h - external state structures used by things like upsd Copyright (C) 2001 Russell Kroll 2005 Arnaud Quette 2007 Peter Selinger 2008 Arjen de Korte 2013 Emilien Kia 2020 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_EXTSTATE_H_SEEN #define NUT_EXTSTATE_H_SEEN 1 #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif /* this could be made dynamic if someone really needs more than this... */ #define ST_MAX_VALUE_LEN 256 /* state tree flags */ #define ST_FLAG_NONE 0x0000 #define ST_FLAG_RW 0x0001 #define ST_FLAG_STRING 0x0002 /* not STRING implies NUMBER */ #define ST_FLAG_NUMBER 0x0004 #define ST_FLAG_IMMUTABLE 0x0008 /* list of possible ENUM values */ typedef struct enum_s { char *val; struct enum_s *next; } enum_t; /* RANGE boundaries */ typedef struct range_s { int min; int max; struct range_s *next; } range_t; /* list of instant commands */ typedef struct cmdlist_s { char *name; struct cmdlist_s *next; } cmdlist_t; #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_EXTSTATE_H_SEEN */ nut-2.8.4/include/parseconf.h0000664000175000017500000000550715000733176013043 00000000000000/* parseconf.h - state machine-driven dynamic configuration file parser Copyright (C) 2002 Russell Kroll This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef PARSECONF_H_SEEN #define PARSECONF_H_SEEN 1 #include /* Not including nut_stdint.h because this is part of end-user API */ #if defined HAVE_INTTYPES_H # include #endif #if defined HAVE_STDINT_H # include #endif #if defined HAVE_LIMITS_H # include #endif #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif #define PCONF_CTX_t_MAGIC 0x00726630 #define PCONF_ERR_LEN 256 /* conservative defaults: use at most 16 KB for parsing any given line */ #define PCONF_DEFAULT_ARG_LIMIT 32 #define PCONF_DEFAULT_WORDLEN_LIMIT 512 typedef struct { FILE *f; /* stream to current file */ int state; /* current parser state */ int ch; /* last character read */ char **arglist; /* array of pointers to words */ size_t *argsize; /* list of sizes for realloc */ size_t numargs; /* max usable in arglist */ size_t maxargs; /* for reallocing arglist */ char *wordbuf; /* accumulator for current word */ char *wordptr; /* where next char goes in word */ size_t wordbufsize; /* for reallocing wordbuf */ int linenum; /* for good error reporting */ int error; /* set when an error occurred */ char errmsg[PCONF_ERR_LEN]; /* local buffer for errors */ void (*errhandler)(const char *); /* user's error handler */ int magic; /* buffer validity check */ /* these may be redefined by the caller to customize memory use */ size_t arg_limit; /* halts growth of arglist */ size_t wordlen_limit; /* halts growth of any wordbuf */ } PCONF_CTX_t; int pconf_init(PCONF_CTX_t *ctx, void errhandler(const char *)); int pconf_file_begin(PCONF_CTX_t *ctx, const char *fn); int pconf_file_next(PCONF_CTX_t *ctx); int pconf_parse_error(PCONF_CTX_t *ctx); int pconf_line(PCONF_CTX_t *ctx, const char *line); void pconf_finish(PCONF_CTX_t *ctx); char *pconf_encode(const char *src, char *dest, size_t destsize); int pconf_char(PCONF_CTX_t *ctx, char ch); #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* PARSECONF_H_SEEN */ nut-2.8.4/include/nutstream.hpp0000644000175000017500000007174515000736161013447 00000000000000/* nutstream.hpp - NUT stream Copyright (C) 2012 Eaton Author: Vaclav Krpec Copyright (C) 2024-2025 NUT Community Author: Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef nut_nutstream_h #define nut_nutstream_h #ifdef __cplusplus #include #include #include #include #include extern "C" { #include #include #include #ifndef WIN32 # include #else /* WIN32 */ # if HAVE_WINSOCK2_H # include # endif # if HAVE_WS2TCPIP_H # include # endif /* Using a private implementation in nutstream.cpp * similar to nutclient.cpp; do not call wincompat.h! * FIXME: refactor to reuse the C++ adaptation? */ #endif /* WIN32 */ } /* See include/common.h for details behind this */ #ifndef NUT_UNUSED_VARIABLE #define NUT_UNUSED_VARIABLE(x) (void)(x) #endif namespace nut { /** * \brief Data stream interface * * The interface provides character-based streamed I/O. */ class NutStream { public: /** Data store status */ typedef enum { NUTS_OK = 0, /** Operation successful */ NUTS_EOF, /** End of stream reached */ NUTS_ERROR, /** Error occurred */ } status_t; protected: /** Formal constructor */ NutStream() {} public: /** * \brief Get one character from current position * * The method provides character from current position * in the data store. * The position is not shifted (see \ref readChar for * current character consumption). * * The operation is synchronous (the call blocks if necessary). * * \param[out] ch Character * * \retval NUTS_OK on success, * \retval NUTS_EOF on end of stream, * \retval NUTS_ERROR on read error */ virtual status_t getChar(char & ch) = 0; /** * \brief Consume current character * * The method shifts position in the stream. * It shall never block (if the position gets * past-the-end of currently available data, * subsequent call to \ref getChar will block). */ virtual void readChar() = 0; /** * \brief Read characters from the stream till EoF * * The method may be used to synchronously read * whole (rest of) stream. * Note that implementation may block flow. * * \retval NUTS_OK on success, * \retval NUTS_ERROR on read error */ virtual status_t getString(std::string & str) = 0; /** * \brief Put one character to the stream end * * \param[in] ch Character * * \retval NUTS_OK on success, * \retval NUTS_ERROR on write error */ virtual status_t putChar(char ch) = 0; /** * \brief Put string to the stream end * * \param[in] str String * * \retval NUTS_OK on success, * \retval NUTS_ERROR on write error */ virtual status_t putString(const std::string & str) = 0; /** * \brief Put data to the stream end * * The difference between \ref putString and this method * is that it is able to serialize also data containing * null characters. * * \param[in] data Data * * \retval NUTS_OK on success, * \retval NUTS_ERROR on write error */ virtual status_t putData(const std::string & data) = 0; /** * \brief Flush output buffers for the stream being written * * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true if flush succeeded * \retval false if flush failed */ virtual bool flush(int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif = 0; /** * \brief Flush output buffers for the stream being written * * \retval true if flush succeeded * \retval false if flush failed */ virtual bool flush() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif = 0; /** Flush output buffers for the file (or throw exception) */ virtual void flushx() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif = 0; /** Formal destructor */ virtual ~NutStream(); }; // end of class NutStream /** Memory stream */ class NutMemory: public NutStream { private: /** Implementation */ std::string m_impl; /** Position in implementation */ size_t m_pos; public: /** Constructor */ NutMemory(): m_pos(0) {} /** * \brief Constructor * * \param str Init value */ NutMemory(const std::string & str): m_impl(str), m_pos(0) {} // NutStream interface implementation status_t getChar(char & ch) override; void readChar() override; status_t getString(std::string & str) override; status_t putChar(char ch) override; status_t putString(const std::string & str) override; status_t putData(const std::string & data) override; // No-op for this class: inline bool flush (int & err_code, std::string & err_msg) override { NUT_UNUSED_VARIABLE(err_code); NUT_UNUSED_VARIABLE(err_msg); return true; } inline bool flush() override {return true;} inline void flushx() override {} }; // end of class NutMemory /** File stream */ class NutFile: public NutStream { public: /** Access mode */ typedef enum { /** Read-only, initial pos. is at the beginning */ READ_ONLY = 0, /** Write-only, with creation, clears the file if exists */ WRITE_ONLY, /** Read-write, initial pos. is at the beginning */ READ_WRITE, /** As previous, but with creation, clears the file if exists */ READ_WRITE_CLEAR, /** Read & write to end, with creation, init. pos: beginning/end for r/w */ READ_APPEND, /** Write only, with creation, initial position is at the end */ APPEND_ONLY, } access_t; /** Unnamed temp. file constructor flag */ typedef enum { ANONYMOUS, /** Anonymous temp. file flag */ } anonymous_t; private: /** Temporary files directory */ static const std::string m_tmp_dir; /** File name */ const std::string m_name; /** Implementation */ FILE *m_impl; /** Current character cache */ char m_current_ch; /** Current character cache status */ bool m_current_ch_valid; /** * \brief Convert enum access_t mode values to strings * for standard library methods * * Throws an exception on unexpected input (should never * happen with proper enum usage). * * \return Non-null "const char *" string */ const char *strAccessMode(access_t mode) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif ; public: /** Constructor * * \param[in] name File name */ NutFile(const std::string & name): m_name(name), m_impl(nullptr), m_current_ch('\0'), m_current_ch_valid(false) {} /** * \brief Temporary file constructor (with open) * * Anonymous temp. file (with automatic destruction) will be created. */ NutFile(anonymous_t); /** * \brief Detected temporary path name getter * * \return Path name */ inline static const std::string & tmp_dir() { return m_tmp_dir; } /** * \brief OS-dependent path separator character(s) * * \return Path separator */ inline static const std::string & path_sep() { static std::string pathsep = #ifdef WIN32 /* FIXME NUT_WIN32_INCOMPLETE : Actually modern Windows supports both slashes */ "\\"; #else /* !WIN32 */ "/"; #endif /* !WIN32 */ return pathsep; } /** * \brief File name getter * * \return File name */ inline const std::string & name() const { return m_name; } /** * \brief Check whether file exists * * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true IFF the file exists * \retval false otherwise */ bool exists(int & err_code, std::string & err_msg) const #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Check whether file exists * * \retval true IFF the file exists * \retval false otherwise */ inline bool exists() const #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return exists(ec, em); } /** * \brief Check whether file exists (or throw exception) * * \retval true IFF the file exists * \retval false otherwise */ inline bool existsx() const #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (exists(ec, em)) return true; if (ENOENT == ec || ENOTDIR == ec) return false; std::stringstream e; e << "Failed to check file " << m_name << " existence: " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Open file * * \param[in] mode File open mode * \param[out] err_code Error code * \param[out] err-msg Error message * * \retval true if open succeeded * \retval false if open failed */ bool open(access_t mode, int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Open file * * \param[in] mode File open mode (read-only by default) * * \retval true if open succeeded * \retval false if open failed */ inline bool open(access_t mode = READ_ONLY) { int ec; std::string em; return open(mode, ec, em); } /** * \brief Open file (or throw exception) * * \param[in] mode File open mode (read-only by default) * * \retval true if open succeeded * \retval false if open failed */ inline void openx(access_t mode = READ_ONLY) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (open(mode, ec, em)) return; std::stringstream e; e << "Failed to open file " << m_name << ": " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Flush output buffers for the file * * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true if flush succeeded * \retval false if flush failed */ bool flush(int & err_code, std::string & err_msg) override #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Flush output buffers for the file * * \retval true if flush succeeded * \retval false if flush failed */ inline bool flush() override #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return flush(ec, em); } /** Flush output buffers for the file (or throw exception) */ inline void flushx() override #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (flush(ec, em)) return; std::stringstream e; e << "Failed to flush file " << m_name << ": " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Close file * * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true if close succeeded * \retval false if close failed */ bool close(int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Close file * * \retval true if close succeeded * \retval false if close failed */ inline bool close() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return close(ec, em); } /** Close file (or throw exception) */ inline void closex() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (close(ec, em)) return; std::stringstream e; e << "Failed to close file " << m_name << ": " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Remove file * * \param[out] err_code Error code * \param[out] err-msg Error message * * \retval true if \c unlink succeeded * \retval false if \c unlink failed */ bool remove(int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Remove file * * \retval true if \c unlink succeeded * \retval false if \c unlink failed */ inline bool remove() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return remove(ec, em); } /** Remove file (or throw exception) */ inline void removex() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (remove(ec, em)) return; std::stringstream e; e << "Failed to remove file " << m_name << ": " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Constructor (with open) * * Opens the file, throws exception on open error. * * \param[in] name File name * \param[in] mode File open mode */ NutFile(const std::string & name, access_t mode); /** * \brief Temporary file constructor (with open) * * Opens file in \ref m_tmp_dir. * Throws exception on open error. * Note that for temporary files, non-creation modes * don't make sense (and will result in throwing an exception). * * \param[in] name File name * \param[in] mode File open mode (r/w by default) */ NutFile(access_t mode = READ_WRITE_CLEAR); // NutStream interface implementation status_t getChar(char & ch) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; void readChar() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; status_t getString(std::string & str) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; status_t putChar(char ch) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; status_t putString(const std::string & str) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; status_t putData(const std::string & data) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; /** Destructor (closes the file) */ ~NutFile() override; private: /** * \brief Copy constructor * * TODO: Copying is forbidden (for now). * If required, it may be enabled, using fdup. * * \param orig Original file */ NutFile(const NutFile & orig) #if (defined __cplusplus) && (__cplusplus >= 201100) __attribute__((noreturn)) #endif { NUT_UNUSED_VARIABLE(orig); throw std::logic_error("NOT IMPLEMENTED"); } /** * \brief Assignment * * TODO: Assignment is forbidden (for now). * See copy constructor for implementation notes * (and don't forget to destroy left value, properly). * * \param rval Right value */ NutFile & operator = (const NutFile & rval) #if (defined __cplusplus) && (__cplusplus >= 201100) __attribute__((noreturn)) #endif { NUT_UNUSED_VARIABLE(rval); throw std::logic_error("NOT IMPLEMENTED"); } }; // end of class NutFile /** Socket stream */ class NutSocket: public NutStream { public: /** Socket domain */ typedef enum { NUTSOCKD_UNIX = AF_UNIX, /** Unix */ NUTSOCKD_INETv4 = AF_INET, /** IPv4 */ NUTSOCKD_INETv6 = AF_INET6, /** IPv6 */ NUTSOCKD_UNDEFINED = -1 } domain_t; /** Socket type */ typedef enum { NUTSOCKT_STREAM = SOCK_STREAM, /** Stream */ NUTSOCKT_DGRAM = SOCK_DGRAM, /** Datagram */ NUTSOCKT_UNDEFINED = -1 } type_t; /** Socket protocol */ typedef enum { NUTSOCKP_IMPLICIT = 0, /** Implicit protocol for chosen type */ } proto_t; /** Socket address */ class Address { friend class NutSocket; private: /** Implementation */ struct sockaddr *m_sock_addr; /** Length */ socklen_t m_length; /** * \brief Invalid address constructor * * Invalid address may be produced e.g. by failed DNS resolving. */ Address(): m_sock_addr(nullptr), m_length(0) {} /** * \brief Initialize UNIX socket address * * \param addr UNIX socket address * \param path Pathname */ static void init_unix(Address & addr, const std::string & path); /** * \brief Initialize IPv4 address * * \param addr IPv4 address * \param qb Byte quadruplet (MSB is at index 0) * \param port Port number */ static void init_ipv4(Address & addr, const std::vector & qb, uint16_t port); /** * \brief Initialize IPv6 address * * \param addr IPv6 address * \param hb 16 bytes of the address (MSB is at index 0) * \param port Port number */ static void init_ipv6(Address & addr, const std::vector & hb, uint16_t port); public: /** * \brief Check address validity * * \retval true if the address is valid * \retval false otherwise */ inline bool valid() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { return nullptr != m_sock_addr; } /** * \brief UNIX socket address constructor * * \param path Pathname */ Address(const std::string & path) { init_unix(*this, path); } /** * \brief IPv4 address constructor * * \param msb Most significant byte * \param msb2 Second most significant byte * \param lsb2 Second least significant byte * \param lsb Least significant byte * \param port Port number */ Address(unsigned char msb, unsigned char msb2, unsigned char lsb2, unsigned char lsb, uint16_t port); /** * \brief IP address constructor * * Creates either IPv4 or IPv6 address (depending on * how many bytes are provided via the \c bytes argument). * Throws an exception if the byte-count is invalid. * * \param bytes 4 or 16 address bytes (MSB is at index 0) * \param port Port number */ Address(const std::vector & bytes, uint16_t port) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error) #endif ; /** * \brief Copy constructor * * \param orig Original address */ Address(const Address & orig); /** * \brief Stringifisation * * \return String representation of the address */ std::string str() const; /** Stringification */ inline operator std::string() const { return str(); } /** Destructor */ ~Address(); }; // end of class Address /** Flag for socket constructor of accepted connection */ typedef enum { ACCEPT /** Accept flag */ } accept_flag_t; private: /** Socket implementation */ int m_impl; domain_t m_domain; type_t m_type; /** Current character cache */ char m_current_ch; /** Current character cache status */ bool m_current_ch_valid; /** * \brief Accept client connection on a listen socket * * \param[out] sock Socket * \param[in] listen_sock Listen socket * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true on success * \retval false otherwise */ static bool accept( NutSocket & sock, const NutSocket & listen_sock, int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error) #endif ; /** * \brief Accept client connection on a listen socket * * \param[out] sock Socket * \param[in] listen_sock Listen socket * * \retval true on success * \retval false otherwise */ inline static bool accept( NutSocket & sock, const NutSocket & listen_sock) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error) #endif { int ec; std::string em; return accept(sock, listen_sock, ec, em); } /** * \brief Accept client connection (or throw exception) * * \param[out] sock Socket * \param[in] listen_sock Listen socket */ inline static void acceptx( NutSocket & sock, const NutSocket & listen_sock) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::logic_error, std::runtime_error) #endif { int ec; std::string em; if (accept(sock, listen_sock, ec, em)) return; std::stringstream e; e << "Failed to accept connection: " << ec << ": " << em; throw std::runtime_error(e.str()); } public: /** * \brief Socket valid check * * \retval true if the socket is initialized * \retval false otherwise */ inline bool valid() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { return -1 != m_impl; } /** * \brief Constructor * * \param dom Socket domain * \param type Socket type * \param proto Socket protocol */ NutSocket( domain_t dom = NUTSOCKD_INETv4, type_t type = NUTSOCKT_STREAM, proto_t proto = NUTSOCKP_IMPLICIT); /** * \brief Accepted client socket constructor * * Accepts connection on a listen socket. * If the argument isn't a listen socket, exception is thrown. * The call will block until either there's an incoming connection * or the listening socket is closed or there's an error. * * \param listen_sock Listening socket */ NutSocket(accept_flag_t, const NutSocket & listen_sock, int & err_code, std::string & err_msg): m_impl(-1), m_domain(NUTSOCKD_UNDEFINED), m_type(NUTSOCKT_UNDEFINED), m_current_ch('\0'), m_current_ch_valid(false) { accept(*this, listen_sock, err_code, err_msg); } /** * \brief Accepted client socket constructor * * Accepts connection on a listen socket. * * \param listen_sock Listening socket */ NutSocket(accept_flag_t, const NutSocket & listen_sock): m_impl(-1), m_domain(NUTSOCKD_UNDEFINED), m_type(NUTSOCKT_UNDEFINED), m_current_ch('\0'), m_current_ch_valid(false) { accept(*this, listen_sock); } /** * \brief Bind socket to an address * * \param[in] addr Socket address * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true on success * \retval false on error */ bool bind(const Address & addr, int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Bind socket to an address * * \param addr Socket address * * \retval true on success * \retval false on error */ inline bool bind(const Address & addr) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return bind(addr, ec, em); } /** * \brief Bind socket to an address (or throw exception) * * \param addr Socket address */ inline void bindx(const Address & addr) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (bind(addr, ec, em)) return; std::stringstream e; e << "Failed to bind socket to address " << addr.str() << ": " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Listen on a socket * * The function sets TCP listen socket. * * \param[in] backlog Limit of pending connections * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true on success * \retval false on error */ bool listen(int backlog, int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Listen on socket * * \param[in] backlog Limit of pending connections * * \retval true on success * \retval false on error */ inline bool listen(int backlog) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return listen(backlog, ec, em); } /** * \brief Listen on socket (or throw an exception) * * \param[in] backlog Limit of pending connections */ inline void listenx(int backlog) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (listen(backlog, ec, em)) return; std::stringstream e; e << "Failed to listen on socket: " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Connect to a listen socket * * \param[in] addr Remote address * \param[out] err_code Error code * \param[out] err_msg Error message * * \retval true on success * \retval false on error */ bool connect(const Address & addr, int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Connect to a listen socket * * \param[in] addr Remote address * * \retval true on success * \retval false on error */ inline bool connect(const Address & addr) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return connect(addr, ec, em); } /** * \brief Connect to a listen socket (or throw an exception) * * \param[in] addr Remote address */ inline void connectx(const Address & addr) #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (connect(addr, ec, em)) return; std::stringstream e; e << "Failed to connect socket: " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Flush output data into socket * * \param[out] err_code Error code * \param[out] err-msg Error message * * \retval true if flush succeeded * \retval false if flush failed */ bool flush(int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; /** * \brief Flush output data into socket * * \retval true if flush succeeded * \retval false if flush failed */ inline bool flush() override #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return flush(ec, em); } /** Flush output data into socket (or throw exception) */ inline void flushx() override #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (flush(ec, em)) return; std::stringstream e; e << "Failed to flush socket " << m_impl << ": " << ec << ": " << em; throw std::runtime_error(e.str()); } /** * \brief Close socket * * \param[out] err_code Error code * \param[out] err-msg Error message * * \retval true if close succeeded * \retval false if close failed */ bool close(int & err_code, std::string & err_msg) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif ; /** * \brief Close socket * * \retval true if close succeeded * \retval false if close failed */ inline bool close() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif { int ec; std::string em; return close(ec, em); } /** Close socket (or throw exception) */ inline void closex() #if (defined __cplusplus) && (__cplusplus < 201100) throw(std::runtime_error) #endif { int ec; std::string em; if (close(ec, em)) return; std::stringstream e; e << "Failed to close socket " << m_impl << ": " << ec << ": " << em; throw std::runtime_error(e.str()); } // NutStream interface implementation status_t getChar(char & ch) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; void readChar() #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; status_t getString(std::string & str) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; status_t putChar(char ch) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; status_t putString(const std::string & str) #if (defined __cplusplus) && (__cplusplus < 201100) throw() #endif override; inline status_t putData(const std::string & data) override { return putString(data); // no difference on sockets } /** Destructor (closes socket if necessary) */ ~NutSocket() override; private: /** * \brief Copy constructor * * TODO: Copying is forbidden (for now). * If required, it may be enabled, using dup. * * \param orig Original file */ NutSocket(const NutSocket & orig) #if (defined __cplusplus) && (__cplusplus >= 201100) __attribute__((noreturn)) #endif { NUT_UNUSED_VARIABLE(orig); throw std::logic_error("NOT IMPLEMENTED"); } /** * \brief Assignment * * TODO: Assignment is forbidden (for now). * See copy constructor for implementation notes * (and don't forget to destroy left value, properly). * * \param rval Right value */ NutSocket & operator = (const NutSocket & rval) { NUT_UNUSED_VARIABLE(rval); throw std::logic_error("NOT IMPLEMENTED"); } }; // end of class NutSocket } // end of namespace nut #endif /* __cplusplus */ #endif /* end of #ifndef nut_nutstream_h */ nut-2.8.4/include/Makefile.am0000644000175000017500000001052015044656702012742 00000000000000# Network UPS Tools: include # Export certain values for ccache which NUT ci_build.sh can customize, # to facilitate developer iteration re-runs of "make" later. # At least GNU and BSD make implementations are okay with this syntax. @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_NAMESPACE@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_BASEDIR@export CCACHE_BASEDIR=@CCACHE_BASEDIR@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_DIR@export CCACHE_DIR=@CCACHE_DIR@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_PATH@export CCACHE_PATH=@CCACHE_PATH@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_PATH@export PATH=@PATH_DURING_CONFIGURE@ include_HEADERS = dist_noinst_HEADERS = \ attribute.h common.h extstate.h proto.h \ state.h str.h timehead.h upsconf.h \ nut_bool.h nut_float.h nut_stdint.h nut_platform.h \ wincompat.h # Optionally deliverable as part of NUT public API: if WITH_DEV include_HEADERS += parseconf.h if WITH_DEV_LIBNUTCONF include_HEADERS += nutstream.hpp nutwriter.hpp nutipc.hpp nutconf.hpp else !WITH_DEV_LIBNUTCONF dist_noinst_HEADERS += nutstream.hpp nutwriter.hpp nutipc.hpp nutconf.hpp endif !WITH_DEV_LIBNUTCONF else !WITH_DEV dist_noinst_HEADERS += parseconf.h dist_noinst_HEADERS += nutstream.hpp nutwriter.hpp nutipc.hpp nutconf.hpp endif !WITH_DEV # http://www.gnu.org/software/automake/manual/automake.html#Clean BUILT_SOURCES = nut_version.h CLEANFILES = nut_version.h nut_version.h.tmp* MAINTAINERCLEANFILES = Makefile.in .dirstamp # magic to include Git version information in NUT version string # (for builds not made from the tagged commit in a Git workspace) # NOTE: For pre-releases, SEMVER may differ from NUT_VERSION base # (e.g. a commit tagged as 2.8.3-rc5 can have its own NUT_VERSION based # on 2.8.2-something, but is assumed as a pre-release for 2.8.3 SEMVER) nut_version.h: @FORCE_NUT_VERSION@ @echo " GENERATE-HEADER $@" ; \ RES=0; \ GITREV="`$(top_srcdir)/tools/gitlog2version.sh`" || GITREV=""; \ GITREV_IS_RELEASE="`NUT_VERSION_QUERY=IS_RELEASE $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_IS_RELEASE="false"; \ GITREV_IS_PRERELEASE="`NUT_VERSION_QUERY=IS_PRERELEASE $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_IS_PRERELEASE="false"; \ GITREV_SEMVER="`NUT_VERSION_QUERY=SEMVER $(top_srcdir)/tools/gitlog2version.sh 2>/dev/null`" || GITREV_SEMVER=""; \ { echo '/* Autogenerated file. Do not change. */' ; \ echo '/* This file was generated by "make". */' ; \ if [ -z "$$GITREV" ]; then \ NUT_VERSION="$(PACKAGE_VERSION)"; \ echo '/* The version number is set by AC_INIT in configure.ac. */' ; \ else \ NUT_VERSION="$$GITREV"; \ echo '/* The version number is determined by Git source commit hash' ; \ echo ' * and number of commits since the most recent Git tag (if not' ; \ echo ' * building the newest tagged commit itself - then just the tag).'; \ echo ' */' ; \ fi ; \ if [ -z "$$GITREV_SEMVER" ]; then \ GITREV_SEMVER="@NUT_SOURCE_GITREV_SEMVER@"; \ fi ; \ echo "#define NUT_VERSION_MACRO \"$$NUT_VERSION\"" ; \ echo "#define NUT_VERSION_SEMVER_MACRO \"$$GITREV_SEMVER\"" ; \ if $$GITREV_IS_RELEASE ; then \ echo "#define NUT_VERSION_IS_RELEASE 1" ; \ else \ echo "#define NUT_VERSION_IS_RELEASE 0" ; \ fi ; \ if $$GITREV_IS_PRERELEASE ; then \ echo "#define NUT_VERSION_IS_PRERELEASE 1" ; \ else \ echo "#define NUT_VERSION_IS_PRERELEASE 0" ; \ fi ; \ } > "$@.tmp.$$$$" && \ echo "NUT_VERSION: \"$$NUT_VERSION\" NUT_VERSION_IS_RELEASE:$$GITREV_IS_RELEASE NUT_VERSION_IS_PRERELEASE:$$GITREV_IS_PRERELEASE NUT_VERSION_SEMVER: \"$$GITREV_SEMVER\"" && \ if test -f "$@" && test -s "$@" ; then \ if cmp -s "$@.tmp.$$$$" "$@" ; then \ echo " GENERATE-HEADER $@ did not change" ; \ else \ echo " GENERATE-HEADER $@ got changed" ; \ cp "$@.tmp.$$$$" "$@" ; \ fi ; \ else \ echo " GENERATE-HEADER $@ was absent"; \ cp "$@.tmp.$$$$" "$@" ; \ fi \ || RES=$$? ; \ rm -f "$@.tmp.$$$$" ; \ exit $$RES FORCE: # counter part of BUILT_SOURCES: since nut_version is not a direct # deps of a local target, we must clean it by ourselves before the # distribution dist-hook: $(AM_V_at)rm -f $(distdir)/nut_version.h all-libs-local: nut_version.h nut-2.8.4/include/nutwriter.hpp0000644000175000017500000002412715000736161013460 00000000000000/* nutwriter.hpp - NUT writer Copyright (C) 2012 Eaton Author: Vaclav Krpec Copyright (C) 2024-2025 NUT Community Author: Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef nut_nutwriter_h #define nut_nutwriter_h #ifdef __cplusplus #include "nutstream.hpp" #include "nutconf.hpp" #include namespace nut { /** * \brief NUT stream writer */ class NutWriter { public: /** NUT writer status */ typedef enum { NUTW_OK = 0, /** Writing successful */ NUTW_ERROR, /** Writing failed */ } status_t; // end of typedef enum */ protected: /** EoL separator */ static const std::string & eol; /** Output stream (by reference) */ NutStream & m_output_stream; public: /** * \brief Constructor * * Creates the writer. * The \c ostream parameter provides the writer reference * to an existing output stream; note that the stream * must exist throughout whole the writer's life. * * TBD: * The stream might actually be passed either by value * (\c NutStream implementations would have to support * copying, though, which is not implemented at the moment) * or using reference counting mechanism (smart pointers etc). * The latter is perhaps a better choice (if the stream existence * dependency is a considerable issue). * * \param ostream Output stream */ NutWriter(NutStream & ostream): m_output_stream(ostream) {} /** * \brief Write to output stream * * The method writes the provided string to the output stream. * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ inline status_t write(const std::string & str) { NutStream::status_t status = m_output_stream.putString(str); return NutStream::NUTS_OK == status ? NUTW_OK : NUTW_ERROR; } /** * \brief Write to output stream * * The method writes the provided string to the output stream. * An exception is thrown on error. */ inline void writex(const std::string & str) { NutStream::status_t status = m_output_stream.putString(str); if (NutStream::NUTS_OK != status) { std::stringstream e; e << "Failed to write to output stream: " << status; throw std::runtime_error(e.str()); } } protected: /** * \brief Write (prefixed) lines * * The method splits string to lines (by EoL) and prefix them * with specified string upon writing. * * \param str String (multi-line) * \param pref Prefix * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ status_t writeEachLine(const std::string & str, const std::string & pref); }; // end of class NutWriter /** * \brief NUT configuration writer interface (generic) */ class NutConfigWriter: public NutWriter { protected: /** Formal constructor */ NutConfigWriter(NutStream & ostream): NutWriter(ostream) {} public: /** * \brief Write comment * * \param str Comment string * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ virtual status_t writeComment(const std::string & str) = 0; /** * \brief Write section name * * \param name Section name * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ virtual status_t writeSectionName(const std::string & name) = 0; /** * \brief Write directive * * \param str Directive string * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ virtual status_t writeDirective(const std::string & str) = 0; /** Virtual destructor */ virtual ~NutConfigWriter(); }; // end of class NutConfigWriter /** * \brief NUT section-less configuration writer specialization * * Partial implementation of \ref NutConfigWriter for section-less * configuration files. */ class SectionlessConfigWriter: public NutConfigWriter { protected: /** * \brief Constructor * * \param ostream Output stream */ SectionlessConfigWriter(NutStream & ostream): NutConfigWriter(ostream) {} public: // Partial \ref NutConfigWriter interface implementation status_t writeDirective(const std::string & str) override; status_t writeComment(const std::string & str) override; private: // Section name writing is forbidden (no sections) status_t writeSectionName(const std::string & name) override; }; // end of class SectionlessConfigWriter /** * \brief \c nut.conf configuration file serializer */ class NutConfConfigWriter: public SectionlessConfigWriter { public: /** * \brief Constructor * * \param ostream Output stream */ NutConfConfigWriter(NutStream & ostream): SectionlessConfigWriter(ostream) {} /** * \brief Serialize configuration container * * \param config Configuration * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ status_t writeConfig(const NutConfiguration & config); /* Ensure an out-of-line method to avoid "weak-vtables" warning */ virtual ~NutConfConfigWriter() override; }; // end of class NutConfConfigWriter /** * \brief \c upsmon.conf configuration file serializer */ class UpsmonConfigWriter: public SectionlessConfigWriter { public: /** * \brief Constructor * * \param ostream Output stream */ UpsmonConfigWriter(NutStream & ostream): SectionlessConfigWriter(ostream) {} /** * \brief Serialize configuration container * * \param config Configuration * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ status_t writeConfig(const UpsmonConfiguration & config); /* Ensure an out-of-line method to avoid "weak-vtables" warning */ virtual ~UpsmonConfigWriter() override; }; // end of class UpsmonConfigWriter /** * \brief \c upsd.conf configuration file serializer */ class UpsdConfigWriter: public SectionlessConfigWriter { public: /** * \brief Constructor * * \param ostream Output stream */ UpsdConfigWriter(NutStream & ostream): SectionlessConfigWriter(ostream) {} /** * \brief Serialize configuration container * * \param config Configuration * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ status_t writeConfig(const UpsdConfiguration & config); /* Ensure an out-of-line method to avoid "weak-vtables" warning */ virtual ~UpsdConfigWriter() override; }; // end of class UpsdConfigWriter /** * \brief NUT default configuration writer ancestor * * Implements the \ref NutConfigWriter interface * and adds \c writeSection prototype to be implemented * by descendants. */ class DefaultConfigWriter: public NutConfigWriter { protected: /** * \brief Constructor * * \param ostream Output stream */ DefaultConfigWriter(NutStream & ostream): NutConfigWriter(ostream) {} public: // \ref NutConfigWriter interface implementation status_t writeComment(const std::string & str) override; status_t writeSectionName(const std::string & name) override; status_t writeDirective(const std::string & str) override; /** * \brief Write configuration section * * Serialize generic configuration section. * * \param section Configuration section * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ virtual status_t writeSection(const GenericConfigSection & section) = 0; }; // end of class DefaultConfigWriter /** * \brief NUT generic configuration writer * * Base configuration file serializer. * Implements the \ref DefaultConfigWriter \c writeSection method * and adds \c writeConfig routine for configuration file serialization. */ class GenericConfigWriter: public DefaultConfigWriter { protected: /** Default indentation of the key/value pair in section entry */ static const std::string s_default_section_entry_indent; /** Default separator of the key/value pair in section entry */ static const std::string s_default_section_entry_separator; /** * \brief Section entry serializer * * \param entry Section entry * \param indent Indentation * \param kv_sep Key/value separator * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ status_t writeSectionEntry( const GenericConfigSectionEntry & entry, const std::string & indent = s_default_section_entry_indent, const std::string & kv_sep = s_default_section_entry_separator); public: /** * \brief Constructor * * \param ostream Output stream */ GenericConfigWriter(NutStream & ostream): DefaultConfigWriter(ostream) {} // Section serializer implementation status_t writeSection(const GenericConfigSection & section) override; /** * \brief Base configuration serializer * * \param config Base configuration * * \retval NUTW_OK on success * \retval NUTW_ERROR otherwise */ status_t writeConfig(const GenericConfiguration & config); }; // end of class GenericConfigWriter /** * \brief NUT upsd.users configuration file writer * * upsd.users configuration file serializer. * Overloads the generic section serializer because of the upsmon section, * which contains an anomalous upsmon (master|slave) directive. */ class UpsdUsersConfigWriter: public GenericConfigWriter { public: /** * \brief Constructor * * \param ostream Output stream */ UpsdUsersConfigWriter(NutStream & ostream): GenericConfigWriter(ostream) {} // Section serializer overload status_t writeSection(const GenericConfigSection & section) override; }; // end of class UpsdUsersConfigWriter } // end of namespace nut #endif /* __cplusplus */ #endif /* end of #ifndef nut_nutwriter_h */ nut-2.8.4/include/upsconf.h0000644000175000017500000000301114777753337012547 00000000000000/* upsconf.h - prototypes for upsconf.c Copyright (C) 2001 Russell Kroll 2005 Arnaud Quette 2013 Emilien Kia 2020 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_UPSCONF_H_SEEN #define NUT_UPSCONF_H_SEEN 1 #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif /* callback function from read_upsconf */ void do_upsconf_args(char *upsname, char *var, char *val); /* open the ups.conf, parse it, and call back do_upsconf_args() * returns -1 (or aborts the program) in case of errors; * returns 1 if processing finished successfully * See also reload_flag support in main.c for live-reload feature */ int read_upsconf(int fatal_errors); #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_UPSCONF_H_SEEN */ nut-2.8.4/include/config.h.in0000644000175000017500000016074515045354757012756 00000000000000/* include/config.h.in. Generated from configure.ac by autoheader. */ /* NUT build directory when the build was configured */ #undef ABS_TOP_BUILDDIR /* NUT source directory when the build was configured */ #undef ABS_TOP_SRCDIR /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD /* Path for pid files of processes not running as root */ #undef ALTPIDPATH /* host env spec we built on */ #undef AUTOTOOLS_BUILD_ALIAS /* host OS short spec we built on */ #undef AUTOTOOLS_BUILD_SHORT_ALIAS /* host env spec we run on */ #undef AUTOTOOLS_HOST_ALIAS /* host OS short spec we run on */ #undef AUTOTOOLS_HOST_SHORT_ALIAS /* host env spec we built for */ #undef AUTOTOOLS_TARGET_ALIAS /* host OS short spec we built for */ #undef AUTOTOOLS_TARGET_SHORT_ALIAS /* Default path for user executables */ #undef BINDIR /* ccache namespace tag (if ccache is used and new enough) */ #undef CCACHE_NAMESPACE /* Compact version of C compiler */ #undef CC_VERSION /* Default path for CGI programs */ #undef CGIPATH /* Flags passed to configure script */ #undef CONFIG_FLAGS /* Default path for configuration files */ #undef CONFPATH /* Compact version of C preprocessor */ #undef CPP_VERSION /* Define processor type */ #undef CPU_TYPE /* Define to 1 if your C++ compiler doesn't accept -c and -o together. */ #undef CXX_NO_MINUS_C_MINUS_O /* Compact version of C++ compiler */ #undef CXX_VERSION /* Default path for UPS drivers */ #undef DRVPATH /* Define to nothing if C supports flexible array members, and to 1 if it does not. That way, with a declaration like `struct s { int n; double d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99 compilers. When computing the size of such an object, don't use 'sizeof (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)' instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with MSVC and with C++ compilers. */ #undef FLEXIBLE_ARRAY_MEMBER /* String spelling of boolean type implementation */ #undef FOUND_BOOLEAN_IMPLEM_STR /* C spelling of boolean type */ #undef FOUND_BOOLEAN_TYPE /* C spelling of boolean type false value */ #undef FOUND_BOOLEAN_VALUE_FALSE /* C spelling of boolean type true value */ #undef FOUND_BOOLEAN_VALUE_TRUE /* String spelling of bool type implementation */ #undef FOUND_BOOL_IMPLEM_STR /* C spelling of bool type */ #undef FOUND_BOOL_TYPE /* String spelling of bool_t type implementation */ #undef FOUND_BOOL_T_IMPLEM_STR /* C spelling of bool_t type */ #undef FOUND_BOOL_T_TYPE /* C spelling of bool_t type false value */ #undef FOUND_BOOL_T_VALUE_FALSE /* C spelling of bool_t type true value */ #undef FOUND_BOOL_T_VALUE_TRUE /* C spelling of bool type false value */ #undef FOUND_BOOL_VALUE_FALSE /* C spelling of bool type true value */ #undef FOUND_BOOL_VALUE_TRUE /* String spelling of _Bool type implementation */ #undef FOUND__BOOL_IMPLEM_STR /* C spelling of _Bool type */ #undef FOUND__BOOL_TYPE /* C spelling of _Bool type false value */ #undef FOUND__BOOL_VALUE_FALSE /* C spelling of _Bool type true value */ #undef FOUND__BOOL_VALUE_TRUE /* Define to the type of arg 1 for getnameinfo. */ #undef GETNAMEINFO_TYPE_ARG1 /* Define to the type of arg 2 for getnameinfo. */ #undef GETNAMEINFO_TYPE_ARG2 /* Define to the type of args 4 and 6 for getnameinfo. */ #undef GETNAMEINFO_TYPE_ARG46 /* Define to the type of arg 7 for getnameinfo. */ #undef GETNAMEINFO_TYPE_ARG7 /* Define to 1 if you have the `abs' function. */ #undef HAVE_ABS /* Define to 1 if you have the `abs_val' function. */ #undef HAVE_ABS_VAL /* Define to 1 if you have the `atexit' function. */ #undef HAVE_ATEXIT /* Define to 1 if you have the header file. */ #undef HAVE_AVAHI_CLIENT_CLIENT_H /* Define to 1 if you have the `avahi_client_new' function. */ #undef HAVE_AVAHI_CLIENT_NEW /* Define to 1 if you have the header file. */ #undef HAVE_AVAHI_COMMON_MALLOC_H /* Define to 1 if you have the `avahi_free' function. */ #undef HAVE_AVAHI_FREE /* Boolean type ${FOUND_BOOLEAN_TYPE} is defined as an enum with specific values allowed */ #undef HAVE_BOOLEAN_IMPLEM_ENUM /* Boolean type ${FOUND_BOOLEAN_TYPE} is defined as a general-purpose number type (int) */ #undef HAVE_BOOLEAN_IMPLEM_INT /* Boolean values of ${FOUND_BOOLEAN_TYPE} are defined as a preprocessor macro (type/implem is questionable) */ #undef HAVE_BOOLEAN_IMPLEM_MACRO /* Name of ${FOUND_BOOLEAN_TYPE} is defined as camel-case token */ #undef HAVE_BOOLEAN_TYPE_CAMELCASE /* Name of ${FOUND_BOOLEAN_TYPE} is defined as lower-case token */ #undef HAVE_BOOLEAN_TYPE_LOWERCASE /* Name of ${FOUND_BOOLEAN_TYPE} is defined as upper-case token */ #undef HAVE_BOOLEAN_TYPE_UPPERCASE /* Boolean values of ${FOUND_BOOLEAN_TYPE} are defined as camel-case tokens */ #undef HAVE_BOOLEAN_VALUE_CAMELCASE /* Boolean values of ${FOUND_BOOLEAN_TYPE} are defined as lower-case tokens */ #undef HAVE_BOOLEAN_VALUE_LOWERCASE /* Boolean values of ${FOUND_BOOLEAN_TYPE} are defined as upper-case tokens */ #undef HAVE_BOOLEAN_VALUE_UPPERCASE /* Boolean type ${FOUND_BOOL_TYPE} is defined as an enum with specific values allowed */ #undef HAVE_BOOL_IMPLEM_ENUM /* Boolean type ${FOUND_BOOL_TYPE} is defined as a general-purpose number type (int) */ #undef HAVE_BOOL_IMPLEM_INT /* Boolean values of ${FOUND_BOOL_TYPE} are defined as a preprocessor macro (type/implem is questionable) */ #undef HAVE_BOOL_IMPLEM_MACRO /* Name of ${FOUND_BOOL_TYPE} is defined as camel-case token */ #undef HAVE_BOOL_TYPE_CAMELCASE /* Name of ${FOUND_BOOL_TYPE} is defined as lower-case token */ #undef HAVE_BOOL_TYPE_LOWERCASE /* Name of ${FOUND_BOOL_TYPE} is defined as upper-case token */ #undef HAVE_BOOL_TYPE_UPPERCASE /* Boolean type ${FOUND_BOOL_T_TYPE} is defined as an enum with specific values allowed */ #undef HAVE_BOOL_T_IMPLEM_ENUM /* Boolean type ${FOUND_BOOL_T_TYPE} is defined as a general-purpose number type (int) */ #undef HAVE_BOOL_T_IMPLEM_INT /* Boolean values of ${FOUND_BOOL_T_TYPE} are defined as a preprocessor macro (type/implem is questionable) */ #undef HAVE_BOOL_T_IMPLEM_MACRO /* Name of ${FOUND_BOOL_T_TYPE} is defined as camel-case token */ #undef HAVE_BOOL_T_TYPE_CAMELCASE /* Name of ${FOUND_BOOL_T_TYPE} is defined as lower-case token */ #undef HAVE_BOOL_T_TYPE_LOWERCASE /* Name of ${FOUND_BOOL_T_TYPE} is defined as upper-case token */ #undef HAVE_BOOL_T_TYPE_UPPERCASE /* Boolean values of ${FOUND_BOOL_T_TYPE} are defined as camel-case tokens */ #undef HAVE_BOOL_T_VALUE_CAMELCASE /* Boolean values of ${FOUND_BOOL_T_TYPE} are defined as lower-case tokens */ #undef HAVE_BOOL_T_VALUE_LOWERCASE /* Boolean values of ${FOUND_BOOL_T_TYPE} are defined as upper-case tokens */ #undef HAVE_BOOL_T_VALUE_UPPERCASE /* Boolean values of ${FOUND_BOOL_TYPE} are defined as camel-case tokens */ #undef HAVE_BOOL_VALUE_CAMELCASE /* Boolean values of ${FOUND_BOOL_TYPE} are defined as lower-case tokens */ #undef HAVE_BOOL_VALUE_LOWERCASE /* Boolean values of ${FOUND_BOOL_TYPE} are defined as upper-case tokens */ #undef HAVE_BOOL_VALUE_UPPERCASE /* Define to 1 if you have the `cfsetispeed' function. */ #undef HAVE_CFSETISPEED /* defined if standard library has, and C standard allows, the clock_gettime(clkid,ts) method */ #undef HAVE_CLOCK_GETTIME /* defined if standard library has, and C standard allows, the CLOCK_MONOTONIC macro or token */ #undef HAVE_CLOCK_MONOTONIC /* Define to enable CPPUNIT tests */ #undef HAVE_CPPUNIT /* Define to 1 if you have the header file. */ #undef HAVE_CSTDBOOL /* Define to enable C++11 support */ #undef HAVE_CXX11 /* Define to 1 if C supports variable-length arrays. */ #undef HAVE_C_VARARRAYS /* Define to 1 if you have the declaration of `fabs', and to 0 if you don't. */ #undef HAVE_DECL_FABS /* Define to 1 if you have the declaration of `fabsf', and to 0 if you don't. */ #undef HAVE_DECL_FABSF /* Define to 1 if you have the declaration of `fabsl', and to 0 if you don't. */ #undef HAVE_DECL_FABSL /* Define to 1 if you have the declaration of `gmtime_r', and to 0 if you don't. */ #undef HAVE_DECL_GMTIME_R /* Define to 1 if you have the declaration of `gmtime_s', and to 0 if you don't. */ #undef HAVE_DECL_GMTIME_S /* Define to 1 if you have the declaration of `i2c_smbus_access', and to 0 if you don't. */ #undef HAVE_DECL_I2C_SMBUS_ACCESS /* Define to 1 if you have the declaration of `i2c_smbus_read_block_data', and to 0 if you don't. */ #undef HAVE_DECL_I2C_SMBUS_READ_BLOCK_DATA /* Define to 1 if you have the declaration of `i2c_smbus_read_byte_data', and to 0 if you don't. */ #undef HAVE_DECL_I2C_SMBUS_READ_BYTE_DATA /* Define to 1 if you have the declaration of `i2c_smbus_read_word_data', and to 0 if you don't. */ #undef HAVE_DECL_I2C_SMBUS_READ_WORD_DATA /* Define to 1 if you have the declaration of `i2c_smbus_write_byte_data', and to 0 if you don't. */ #undef HAVE_DECL_I2C_SMBUS_WRITE_BYTE_DATA /* Define to 1 if you have the declaration of `i2c_smbus_write_word_data', and to 0 if you don't. */ #undef HAVE_DECL_I2C_SMBUS_WRITE_WORD_DATA /* Define to 1 if you have the declaration of `localtime_r', and to 0 if you don't. */ #undef HAVE_DECL_LOCALTIME_R /* Define to 1 if you have the declaration of `localtime_s', and to 0 if you don't. */ #undef HAVE_DECL_LOCALTIME_S /* Define to 1 if you have the declaration of `LOG_UPTO', and to 0 if you don't. */ #undef HAVE_DECL_LOG_UPTO /* Define to 1 if you have the declaration of `optind', and to 0 if you don't. */ #undef HAVE_DECL_OPTIND /* Define to 1 if you have the declaration of `pow10', and to 0 if you don't. */ #undef HAVE_DECL_POW10 /* Define to 1 if you have the declaration of `realpath', and to 0 if you don't. */ #undef HAVE_DECL_REALPATH /* Define to 1 if you have the declaration of `regcomp', and to 0 if you don't. */ #undef HAVE_DECL_REGCOMP /* Define to 1 if you have the declaration of `regexec', and to 0 if you don't. */ #undef HAVE_DECL_REGEXEC /* Define to 1 if you have the declaration of `round', and to 0 if you don't. */ #undef HAVE_DECL_ROUND /* Define to 1 if you have the declaration of `timegm', and to 0 if you don't. */ #undef HAVE_DECL_TIMEGM /* Define to 1 if you have the declaration of `uu_lock', and to 0 if you don't. */ #undef HAVE_DECL_UU_LOCK /* Define to 1 if you have the declaration of `_mkgmtime', and to 0 if you don't. */ #undef HAVE_DECL__MKGMTIME /* Define to 1 if you have the declaration of `__FUNCTION__', and to 0 if you don't. */ #undef HAVE_DECL___FUNCTION__ /* Define to 1 if you have the declaration of `__func__', and to 0 if you don't. */ #undef HAVE_DECL___FUNC__ /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H /* Define to 1 if you have the `dup' function. */ #undef HAVE_DUP /* Define to 1 if you have the `dup2' function. */ #undef HAVE_DUP2 /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H /* Define to 1 if you have the `fcvt' function. */ #undef HAVE_FCVT /* Define to 1 if you have the `fcvtl' function. */ #undef HAVE_FCVTL /* Define to 1 if you have the `fileno' function. */ #undef HAVE_FILENO /* Define to 1 if you have . */ #undef HAVE_FLOAT_H /* Define to 1 if you have the `flock' function. */ #undef HAVE_FLOCK /* Define if FreeIPMI support is available */ #undef HAVE_FREEIPMI /* Define if FreeIPMI 1.1.X / 1.2.X support is available */ #undef HAVE_FREEIPMI_11X_12X /* Define to 1 if you have the header file. */ #undef HAVE_FREEIPMI_FREEIPMI_H /* Define if FreeIPMI monitoring support is available */ #undef HAVE_FREEIPMI_MONITORING /* Define to 1 if you have the header file. */ #undef HAVE_GDFONTMB_H /* Define to 1 if you have the header file. */ #undef HAVE_GD_H /* defined if system has the GetAdaptersAddresses() method */ #undef HAVE_GETADAPTERSADDRESSES /* defined if system has the GetAdaptersInfo() method */ #undef HAVE_GETADAPTERSINFO /* Define to 1 if you have the `getifaddrs' function. */ #undef HAVE_GETIFADDRS /* Define to 1 if you have the header file. */ #undef HAVE_GETOPT_H /* Define to 1 if you have the `getopt_long' function. */ #undef HAVE_GETOPT_LONG /* Define to 1 if you have the `getpassphrase' function. */ #undef HAVE_GETPASSPHRASE /* Define to 1 if you have the `gmtime_r' function. */ #undef HAVE_GMTIME_R /* Define to 1 if you have the `gmtime_s' function. */ #undef HAVE_GMTIME_S /* Define to 1 if you have the `gpiod_chip_close' function. */ #undef HAVE_GPIOD_CHIP_CLOSE /* Define to 1 if you have the `gpiod_chip_open' function. */ #undef HAVE_GPIOD_CHIP_OPEN /* Define to 1 if you have the `gpiod_chip_open_by_name' function. */ #undef HAVE_GPIOD_CHIP_OPEN_BY_NAME /* Define to 1 if you have the header file. */ #undef HAVE_GPIOD_H /* Define to 1 if you have the header file. */ #undef HAVE_IFADDRS_H /* defined if system has the inet_ntop() method */ #undef HAVE_INET_NTOP /* defined if system has the inet_pton() method */ #undef HAVE_INET_PTON /* Define to 1 if you have the `init_snmp' function. */ #undef HAVE_INIT_SNMP /* Define to 1 if the system has the type `intmax_t'. */ #undef HAVE_INTMAX_T /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the iphlpapi.h header file. */ #undef HAVE_IPHLPAPI_H /* Define to 1 if you have the header file. */ #undef HAVE_IPMI_MONITORING_H /* Define if you have Boutell's libgd installed */ #undef HAVE_LIBGD /* Define to enable libltdl support */ #undef HAVE_LIBLTDL /* Define to 1 if you have the header file. */ #undef HAVE_LIBPOWERMAN_H /* Define to 1 for build where we can support general regex matching. */ #undef HAVE_LIBREGEX /* Define to 1 if you have the `libusb_detach_kernel_driver' function. */ #undef HAVE_LIBUSB_DETACH_KERNEL_DRIVER /* Define to 1 if you have the `libusb_detach_kernel_driver_np' function. */ #undef HAVE_LIBUSB_DETACH_KERNEL_DRIVER_NP /* Define to 1 if you have the `libusb_get_port_number' function. */ #undef HAVE_LIBUSB_GET_PORT_NUMBER /* Define to 1 if you have the header file. */ #undef HAVE_LIBUSB_H /* Define to 1 if you have the `libusb_init' function. */ #undef HAVE_LIBUSB_INIT /* Define to 1 if you have the `libusb_kernel_driver_active' function. */ #undef HAVE_LIBUSB_KERNEL_DRIVER_ACTIVE /* Define to 1 if you have the `libusb_set_auto_detach_kernel_driver' function. */ #undef HAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVER /* Define to 1 if you have the `libusb_strerror' function. */ #undef HAVE_LIBUSB_STRERROR /* defined if we have libs, includes and methods for BSD KVM process info */ #undef HAVE_LIB_BSD_KVM_PROC /* defined if we have libs, includes and methods for Solaris/illumos process info */ #undef HAVE_LIB_ILLUMOS_PROC /* Define to 1 if you have . */ #undef HAVE_LIMITS_H /* Define to 1 if you have . */ #undef HAVE_LINUX_I2C_DEV_H /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_SERIAL_H /* Define to 1 if you have . */ #undef HAVE_LINUX_SMBUS_H /* Define to 1 if you have the `localtime_r' function. */ #undef HAVE_LOCALTIME_R /* Define to 1 if you have the `localtime_s' function. */ #undef HAVE_LOCALTIME_S /* Define to 1 if you have the `lockf' function. */ #undef HAVE_LOCKF /* Define to 1 if the system has the type `long double'. */ #undef HAVE_LONG_DOUBLE /* Define to 1 if the system has the type `long long int'. */ #undef HAVE_LONG_LONG_INT /* Define to 1 if you have the header file. */ #undef HAVE_LTDL_H /* Define to 1 if you have the header file. */ #undef HAVE_LUSB0_USB_H /* Define to 1 if you have . */ #undef HAVE_MATH_H /* Define to 1 if you have the header file. */ #undef HAVE_MINIX_CONFIG_H /* Define to 1 if you have the header file. */ #undef HAVE_MODBUS_H /* Define to 1 if you have the `modbus_new_rtu' function. */ #undef HAVE_MODBUS_NEW_RTU /* Define to 1 if you have the `modbus_new_rtu_usb' function. */ #undef HAVE_MODBUS_NEW_RTU_USB /* Define to 1 if you have the `modbus_new_tcp' function. */ #undef HAVE_MODBUS_NEW_TCP /* Define to 1 if you have the `modbus_set_byte_timeout' function. */ #undef HAVE_MODBUS_SET_BYTE_TIMEOUT /* Define to 1 if you have the `modbus_set_response_timeout' function. */ #undef HAVE_MODBUS_SET_RESPONSE_TIMEOUT /* Define to 1 if you have the header file. */ #undef HAVE_NETDB_H /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_IN_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_IF_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_SNMP_NET_SNMP_CONFIG_H /* Define to 1 if you have the header file. */ #undef HAVE_NET_SNMP_NET_SNMP_INCLUDES_H /* Define to 1 if you have the `ne_set_connect_timeout' function. */ #undef HAVE_NE_SET_CONNECT_TIMEOUT /* Define to 1 if you have the `ne_sock_connect_timeout' function. */ #undef HAVE_NE_SOCK_CONNECT_TIMEOUT /* Define to 1 if you have the header file. */ #undef HAVE_NE_XMLREQ_H /* Define to 1 if you have the `ne_xml_dispatch_request' function. */ #undef HAVE_NE_XML_DISPATCH_REQUEST /* Define to 1 if you have the header file. */ #undef HAVE_NSS_H /* Define to 1 if you have the `NSS_Init' function. */ #undef HAVE_NSS_INIT /* Define to 1 if you have the `on_exit' function. */ #undef HAVE_ON_EXIT /* Define to 1 if you have the header file. */ #undef HAVE_OPENSSL_SSL_H /* Define to 1 if you have the `pm_connect' function. */ #undef HAVE_PM_CONNECT /* Define to 1 if you have . */ #undef HAVE_POLL_H /* define if your compiler has pragmas for GCC diagnostic ignored "-Wc++98-compat(-pedantic)" and for push-pop support */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_CXX98_COMPAT /* define if your compiler has pragmas for GCC diagnostic ignored "-Wc++98-compat(-pedantic)" and for push-pop support (outside function bodies) */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_CXX98_COMPAT_BESIDEFUNC /* define if your compiler has pragmas for GCC diagnostic ignored "-Wformat-nonliteral" or "-Wformat-security" and for push-pop support */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL /* define if your compiler has pragmas for GCC diagnostic ignored "-Wformat-nonliteral" or "-Wformat-security" and for push-pop support (outside function bodies) */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL_BESIDEFUNC /* define if your compiler has pragmas for GCC diagnostic ignored "-Wformat-truncation" or "-Werror=stringop-truncation" and for push-pop support */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION /* define if your compiler has pragmas for GCC diagnostic ignored "-Wformat-truncation" or "-Werror=stringop-truncation" and for push-pop support (outside function bodies) */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION_BESIDEFUNC /* define if your compiler has pragmas for GCC diagnostic ignored "-Wunreachable-code(-break)" and for push-pop support */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE /* define if your compiler has pragmas for GCC diagnostic ignored "-Wunreachable-code(-break)" and for push-pop support (outside function bodies) */ #undef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_BESIDEFUNC /* define if your compiler has #pragma clang diagnostic ignored "-Wdeprecated-declarations" */ #undef HAVE_PRAGMA_CLANG_DIAGNOSTIC_IGNORED_DEPRECATED_DECLARATIONS /* define if your compiler has #pragma clang diagnostic ignored "-Wdeprecated-declarations" (outside functions) */ #undef HAVE_PRAGMA_CLANG_DIAGNOSTIC_IGNORED_DEPRECATED_DECLARATIONS_BESIDEFUNC /* define if your compiler has #pragma clang diagnostic ignored "-Wunreachable-code-return" */ #undef HAVE_PRAGMA_CLANG_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_RETURN /* define if your compiler has #pragma clang diagnostic ignored "-Wunreachable-code-return" (outside functions) */ #undef HAVE_PRAGMA_CLANG_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_RETURN_BESIDEFUNC /* define if your compiler has #pragma clang diagnostic push and pop */ #undef HAVE_PRAGMA_CLANG_DIAGNOSTIC_PUSH_POP /* define if your compiler has #pragma clang diagnostic push and pop outside function bodies */ #undef HAVE_PRAGMA_CLANG_DIAGNOSTIC_PUSH_POP_BESIDEFUNC /* define if your compiler has #pragma clang diagnostic push and pop inside function bodies */ #undef HAVE_PRAGMA_CLANG_DIAGNOSTIC_PUSH_POP_INSIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Waddress" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ADDRESS /* define if your compiler has #pragma GCC diagnostic ignored "-Waddress" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ADDRESS_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Warray-bounds" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ARRAY_BOUNDS /* define if your compiler has #pragma GCC diagnostic ignored "-Warray-bounds" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ARRAY_BOUNDS_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wassign-enum" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ASSIGN_ENUM /* define if your compiler has #pragma GCC diagnostic ignored "-Wassign-enum" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ASSIGN_ENUM_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wcast-align" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN /* define if your compiler has #pragma GCC diagnostic ignored "-Wcast-align" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_ALIGN_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wcast-function-type-strict" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_FUNCTION_TYPE_STRICT /* define if your compiler has #pragma GCC diagnostic ignored "-Wcast-function-type-strict" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CAST_FUNCTION_TYPE_STRICT_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wcovered-switch-default" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT /* define if your compiler has #pragma GCC diagnostic ignored "-Wcovered-switch-default" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wc++98-compat" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CXX98_COMPAT /* define if your compiler has #pragma GCC diagnostic ignored "-Wc++98-compat" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CXX98_COMPAT_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wc++98-compat-pedantic" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CXX98_COMPAT_PEDANTIC /* define if your compiler has #pragma GCC diagnostic ignored "-Wc++98-compat-pedantic" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_CXX98_COMPAT_PEDANTIC_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wdeprecated-declarations" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_DEPRECATED_DECLARATIONS /* define if your compiler has #pragma GCC diagnostic ignored "-Wdeprecated-dynamic-exception-spec" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_DEPRECATED_DYNAMIC_EXCEPTION_SPEC_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wexit-time-destructors" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_EXIT_TIME_DESTRUCTORS /* define if your compiler has #pragma GCC diagnostic ignored "-Wexit-time-destructors" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_EXIT_TIME_DESTRUCTORS_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wextra-semi" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_EXTRA_SEMI_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wextra-semi-stmt" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_EXTRA_SEMI_STMT /* define if your compiler has #pragma GCC diagnostic ignored "-Wextra-semi-stmt" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_EXTRA_SEMI_STMT_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-extra-args" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_EXTRA_ARGS /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-extra-args" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_EXTRA_ARGS_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-nonliteral" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-nonliteral" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-overflow" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_OVERFLOW /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-overflow" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_OVERFLOW_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-security" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-security" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-truncation" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION /* define if your compiler has #pragma GCC diagnostic ignored "-Wformat-truncation" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wglobal-constructors" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_GLOBAL_CONSTRUCTORS /* define if your compiler has #pragma GCC diagnostic ignored "-Wglobal-constructors" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_GLOBAL_CONSTRUCTORS_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED /* define if your compiler has #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_MAYBE_UNINITIALIZED_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wold-style-cast" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_OLD_STYLE_CAST_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wpedantic" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_PEDANTIC /* define if your compiler has #pragma GCC diagnostic ignored "-Wpedantic" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_PEDANTIC_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wsign-compare" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_SIGN_COMPARE /* define if your compiler has #pragma GCC diagnostic ignored "-Wsign-compare" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_SIGN_COMPARE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wsign-conversion" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_SIGN_CONVERSION /* define if your compiler has #pragma GCC diagnostic ignored "-Wsign-conversion" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_SIGN_CONVERSION_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wstrict-prototypes" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRICT_PROTOTYPES /* define if your compiler has #pragma GCC diagnostic ignored "-Wstrict-prototypes" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRICT_PROTOTYPES_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wstringop-truncation" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRINGOP_TRUNCATION /* define if your compiler has #pragma GCC diagnostic ignored "-Wstringop-truncation" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRINGOP_TRUNCATION_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wsuggest-destructor-override" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_SUGGEST_DESTRUCTOR_OVERRIDE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wsuggest-override" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_SUGGEST_OVERRIDE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-compare" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-compare" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-type-limit-compare" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-type-limit-compare" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE /* define if your compiler has #pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wtype-limits" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS /* define if your compiler has #pragma GCC diagnostic ignored "-Wtype-limits" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wunreachable-code" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE /* define if your compiler has #pragma GCC diagnostic ignored "-Wunreachable-code" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wunreachable-code-break" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_BREAK /* define if your compiler has #pragma GCC diagnostic ignored "-Wunreachable-code-break" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_BREAK_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wunreachable-code-return" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_RETURN /* define if your compiler has #pragma GCC diagnostic ignored "-Wunreachable-code-return" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_RETURN_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wunused-function" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNUSED_FUNCTION /* define if your compiler has #pragma GCC diagnostic ignored "-Wunused-parameter" */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNUSED_PARAMETER /* define if your compiler has #pragma GCC diagnostic ignored "-Wweak-vtables" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_WEAK_VTABLES_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" (outside functions) */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ZERO_AS_NULL_POINTER_CONSTANT_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic push and pop */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP /* define if your compiler has #pragma GCC diagnostic push and pop outside function bodies */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC /* define if your compiler has #pragma GCC diagnostic push and pop inside function bodies */ #undef HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC /* Define to enable pthread support code */ #undef HAVE_PTHREAD /* Define to enable pthread_tryjoin support code */ #undef HAVE_PTHREAD_TRYJOIN /* Define to 1 if you have the `readlink' function. */ #undef HAVE_READLINK /* Define to 1 if you have . */ #undef HAVE_REGEX_H /* Define to 1 if you have the `sd_booted' function. */ #undef HAVE_SD_BOOTED /* Define to 1 if you have the `sd_bus_call_method' function. */ #undef HAVE_SD_BUS_CALL_METHOD /* Define to 1 if you have the `sd_bus_default_system' function. */ #undef HAVE_SD_BUS_DEFAULT_SYSTEM /* Define to 1 if you have the `sd_bus_error_free' function. */ #undef HAVE_SD_BUS_ERROR_FREE /* Define to 1 if you have the `sd_bus_flush_close_unref' function. */ #undef HAVE_SD_BUS_FLUSH_CLOSE_UNREF /* Define to 1 if you have the `sd_bus_get_property_trivial' function. */ #undef HAVE_SD_BUS_GET_PROPERTY_TRIVIAL /* Define to 1 if you have the `sd_bus_message_read_basic' function. */ #undef HAVE_SD_BUS_MESSAGE_READ_BASIC /* Define to 1 if you have the `sd_bus_message_unref' function. */ #undef HAVE_SD_BUS_MESSAGE_UNREF /* Define to 1 if you have the `sd_bus_open_system' function. */ #undef HAVE_SD_BUS_OPEN_SYSTEM /* Define to 1 if you have the `sd_bus_open_system_with_description' function. */ #undef HAVE_SD_BUS_OPEN_SYSTEM_WITH_DESCRIPTION /* Define to 1 if you have the `sd_bus_set_description' function. */ #undef HAVE_SD_BUS_SET_DESCRIPTION /* Define to 1 if you have the `sd_notify' function. */ #undef HAVE_SD_NOTIFY /* Define to 1 if you have the `sd_notify_barrier' function. */ #undef HAVE_SD_NOTIFY_BARRIER /* Define to 1 if you have the `sd_watchdog_enabled' function. */ #undef HAVE_SD_WATCHDOG_ENABLED /* Define to 1 if you have . */ #undef HAVE_SEMAPHORE_H /* Define to 1 if you have with usable sem_t, sem_open() and sem_close() for named semaphores. */ #undef HAVE_SEMAPHORE_NAMED /* Define to 1 if you have with usable sem_t, sem_init() and sem_destroy() for unnamed semaphores. */ #undef HAVE_SEMAPHORE_UNNAMED /* Define to 1 if you have the `setenv' function. */ #undef HAVE_SETENV /* Define to 1 if you have the `seteuid' function. */ #undef HAVE_SETEUID /* Define to 1 if you have the `setlogmask' function. */ #undef HAVE_SETLOGMASK /* Define to 1 if you have the `setsid' function. */ #undef HAVE_SETSID /* Define to 1 if you have the `sigaction' function. */ #undef HAVE_SIGACTION /* Define to 1 if you have the `sigemptyset' function. */ #undef HAVE_SIGEMPTYSET /* Define to 1 if you have . */ #undef HAVE_SIGNAL_H /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF /* Define to 1 if you have the `SSL_CTX_new' function. */ #undef HAVE_SSL_CTX_NEW /* Define to 1 if you have the header file. */ #undef HAVE_SSL_H /* Define to 1 if you have the header file. */ #undef HAVE_STDARG_H /* Define to 1 if you have the header file. */ #undef HAVE_STDBOOL_H /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the header file. */ #undef HAVE_STDIO_H /* Define to 1 if you have . */ #undef HAVE_STDLIB_H /* defined if standard library has, and C standard allows, the strcasecmp(s1,s2) method */ #undef HAVE_STRCASECMP /* defined if standard library has, and C standard allows, the strcasestr(s1,s2) method */ #undef HAVE_STRCASESTR /* defined if standard library has, and C standard allows, the strdup(s) method */ #undef HAVE_STRDUP /* Define to 1 if you have the `strerror' function. */ #undef HAVE_STRERROR /* Define to 1 if you have . */ #undef HAVE_STRINGS_H /* Define to 1 if you have . */ #undef HAVE_STRING_H /* defined if standard library has, and C standard allows, the strlwr(s1,s2) method */ #undef HAVE_STRLWR /* defined if standard library has, and C standard allows, the strncasecmp(s1,s2,n) method */ #undef HAVE_STRNCASECMP /* defined if standard library has, and C standard allows, the strnlen(s1,s2) method */ #undef HAVE_STRNLEN /* defined if standard library has, and C standard allows, the strptime(s1,s2,tm) method */ #undef HAVE_STRPTIME /* defined if standard library has, and C standard allows, the strsep(s1,s2) method */ #undef HAVE_STRSEP /* defined if standard library has, and C standard allows, the strstr(s1,s2) method */ #undef HAVE_STRSTR /* Define to 1 if you have the `strtof' function. */ #undef HAVE_STRTOF /* Define to 1 if you have the `strtok_r' function. */ #undef HAVE_STRTOK_R /* defined if system has the struct pollfd type */ #undef HAVE_STRUCT_POLLFD /* defined if standard library has, and C standard allows, the suseconds_t type */ #undef HAVE_SUSECONDS_T /* Define to consider basic systemd support (provide units and configuration files) */ #undef HAVE_SYSTEMD /* Define to 1 if you have the header file. */ #undef HAVE_SYSTEMD_SD_BUS_H /* Define to 1 if you have the header file. */ #undef HAVE_SYSTEMD_SD_DAEMON_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MODEM_H /* Define to 1 if you have with usable struct rlimit and getrlimit(). */ #undef HAVE_SYS_RESOURCE_H /* Define to 1 if you have . */ #undef HAVE_SYS_SELECT_H /* Define to 1 if you have . */ #undef HAVE_SYS_SIGNAL_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_SOCKET_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TERMIOS_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TIME_H /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the header file. */ #undef HAVE_TCPD_H /* Define to 1 if you have the `tcsendbreak' function. */ #undef HAVE_TCSENDBREAK /* Define to 1 if you have the header file. */ #undef HAVE_TERMIOS_H /* Define to 1 if you have the `timegm' function. */ #undef HAVE_TIMEGM /* Define to 1 if you have the header file. */ #undef HAVE_TIME_H /* Define to 1 if the system has the type `uintmax_t'. */ #undef HAVE_UINTMAX_T /* Define to 1 if you have . */ #undef HAVE_UNISTD_H /* Define to 1 if you have the `unsetenv' function. */ #undef HAVE_UNSETENV /* Define to 1 if the system has the type `unsigned long long int'. */ #undef HAVE_UNSIGNED_LONG_LONG_INT /* Define to 1 if you have the `usb_detach_kernel_driver_np' function. */ #undef HAVE_USB_DETACH_KERNEL_DRIVER_NP /* Define to 1 if you have the header file. */ #undef HAVE_USB_H /* Define to 1 if you have the `usb_init' function. */ #undef HAVE_USB_INIT /* defined if standard library has, and C standard allows, the useconds_t type */ #undef HAVE_USECONDS_T /* defined if standard library has, and C standard allows, the usleep(us) method */ #undef HAVE_USLEEP /* Use uu_lock for locking (FreeBSD) */ #undef HAVE_UU_LOCK /* Define to 1 if you have the header file. */ #undef HAVE_VARARGS_H /* defined if va_copy(dest,src) is available */ #undef HAVE_VA_COPY /* defined if va_copy or __va_copy is available */ #undef HAVE_VA_COPY_VARIANT /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF /* Define to 1 if you have the header file. */ #undef HAVE_WCHAR_H /* Define to 1 if you have the windows.h header file. */ #undef HAVE_WINDOWS_H /* Define to 1 if you have the header file. */ #undef HAVE_WINSOCK2_H /* Define to enable libwrap support */ #undef HAVE_WRAP /* Define to 1 if you have the header file. */ #undef HAVE_WS2TCPIP_H /* Boolean type ${FOUND__BOOL_TYPE} is defined as an enum with specific values allowed */ #undef HAVE__BOOL_IMPLEM_ENUM /* Boolean type ${FOUND__BOOL_TYPE} is defined as a general-purpose number type (int) */ #undef HAVE__BOOL_IMPLEM_INT /* Boolean values of ${FOUND__BOOL_TYPE} are defined as a preprocessor macro (type/implem is questionable) */ #undef HAVE__BOOL_IMPLEM_MACRO /* Name of ${FOUND__BOOL_TYPE} is defined as camel-case token */ #undef HAVE__BOOL_TYPE_CAMELCASE /* Name of ${FOUND__BOOL_TYPE} is defined as lower-case token */ #undef HAVE__BOOL_TYPE_LOWERCASE /* Name of ${FOUND__BOOL_TYPE} is defined as upper-case token */ #undef HAVE__BOOL_TYPE_UPPERCASE /* Boolean values of ${FOUND__BOOL_TYPE} are defined as camel-case tokens */ #undef HAVE__BOOL_VALUE_CAMELCASE /* Boolean values of ${FOUND__BOOL_TYPE} are defined as lower-case tokens */ #undef HAVE__BOOL_VALUE_LOWERCASE /* Boolean values of ${FOUND__BOOL_TYPE} are defined as upper-case tokens */ #undef HAVE__BOOL_VALUE_UPPERCASE /* Define to 1 if you have the `_mkgmtime' function. */ #undef HAVE__MKGMTIME /* define if your compiler has __attribute__ */ #undef HAVE___ATTRIBUTE__ /* define if your compiler has __attribute__((noreturn)) */ #undef HAVE___ATTRIBUTE__NORETURN /* define if your compiler has __attribute__((unused)) for function arguments */ #undef HAVE___ATTRIBUTE__UNUSED_ARG /* define if your compiler has __attribute__((unused)) for functions */ #undef HAVE___ATTRIBUTE__UNUSED_FUNC /* defined if __va_copy(dest,src) is available */ #undef HAVE___VA_COPY /* Default path for HTML files (CGI templates) */ #undef HTMLPATH /* Default path for system libraries */ #undef LIBDIR /* Default path for system exec-libraries */ #undef LIBEXECDIR /* Desired syslog facility - see syslog(3) */ #undef LOG_FACILITY /* Define to the sub-directory where libtool stores uninstalled libraries. */ #undef LT_OBJDIR /* are platform man directories named by base number (yes) or full section name (no) */ #undef MAN_DIR_AS_BASE /* man page section for library APIs */ #undef MAN_SECTION_API /* base (number only) man page section for library APIs */ #undef MAN_SECTION_API_BASE /* man page section for configuration files */ #undef MAN_SECTION_CFG /* base (number only) man page section for configuration files */ #undef MAN_SECTION_CFG_BASE /* man page section for system management commands */ #undef MAN_SECTION_CMD_SYS /* base (number only) man page section for system management commands */ #undef MAN_SECTION_CMD_SYS_BASE /* man page section for user commands */ #undef MAN_SECTION_CMD_USR /* base (number only) man page section for user commands */ #undef MAN_SECTION_CMD_USR_BASE /* man page section for overviews, conventions, and miscellaneous */ #undef MAN_SECTION_MISC /* base (number only) man page section for overviews, conventions, and miscellaneous */ #undef MAN_SECTION_MISC_BASE /* host multiarch spec we build for (as suggested by compiler being used) */ #undef MULTIARCH_TARGET_ALIAS /* Define to use explicit getopt declarations */ #undef NEED_GETOPT_DECLS /* Define if getopt.h is needed */ #undef NEED_GETOPT_H /* Default path for data files */ #undef NUT_DATADIR /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_DRAFT_BLUMENTHAL_AES_04 /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmAES128PrivProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmAES192PrivProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmAES256PrivProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmDESPrivProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmHMAC192SHA256AuthProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmHMAC256SHA384AuthProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmHMAC384SHA512AuthProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmHMACMD5AuthProtocol /* Variable or macro by this name is not resolvable */ #undef NUT_HAVE_LIBNETSNMP_usmHMACSHA1AuthProtocol /* Default path for man page files */ #undef NUT_MANDIR /* Define to use libmodbus USB backend */ #undef NUT_MODBUS_HAS_USB /* Define to let the libmodbus linking type be known for troubleshooting */ #undef NUT_MODBUS_LINKTYPE_STR /* ${COMMENT} */ #undef NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32 /* ${COMMENT} */ #undef NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32_cast_timeval_fields /* ${COMMENT} */ #undef NUT_MODBUS_TIMEOUT_ARG_timeval /* ${COMMENT} */ #undef NUT_MODBUS_TIMEOUT_ARG_timeval_numeric_fields /* NUT network protocol version */ #undef NUT_NETVERSION /* Documentation website base URL, no trailing slash */ #undef NUT_WEBSITE_BASE /* Name of package */ #undef PACKAGE /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Path for pid files of processes running as root */ #undef PIDPATH /* Port for network communications */ #undef PORT /* Default installation prefix path */ #undef PREFIX /* Define to 0 if your libc can printf("%s", NULL) sanely, or to 1 if your libc requires workarounds to print NULL values. */ #undef REQUIRE_NUT_STRARG /* Group membership of user to switch to if started as root */ #undef RUN_AS_GROUP /* User to switch to if started as root */ #undef RUN_AS_USER /* Default path for system executables */ #undef SBINDIR /* The size of `void *', as computed by sizeof. */ #undef SIZEOF_VOID_P /* Base file name of dynamic library on build system */ #undef SOFILE_LIBAVAHI /* Base file name of dynamic library on build system */ #undef SOFILE_LIBFREEIPMI /* Base file name of dynamic library on build system */ #undef SOFILE_LIBNEON /* Base file name of dynamic library on build system */ #undef SOFILE_LIBNETSNMP /* Base file name of dynamic library on build system */ #undef SOFILE_LIBUSB0 /* Base file name of dynamic library on build system */ #undef SOFILE_LIBUSB1 /* Path to dynamic library on build system */ #undef SOPATH_LIBAVAHI /* Path to dynamic library on build system */ #undef SOPATH_LIBFREEIPMI /* Path to dynamic library on build system */ #undef SOPATH_LIBNEON /* Path to dynamic library on build system */ #undef SOPATH_LIBNETSNMP /* Path to dynamic library on build system */ #undef SOPATH_LIBUSB0 /* Path to dynamic library on build system */ #undef SOPATH_LIBUSB1 /* Path for UPS driver state files */ #undef STATEPATH /* Define to 1 if all of the C90 standard headers exist (not just the ones required in a freestanding environment). This macro is provided for backward compatibility; new code need not use it. */ #undef STDC_HEADERS /* Define to 1 for Sun version of the libusb. */ #undef SUN_LIBUSB /* Define to 1 if you can safely include both and . This macro is deemed obsolete by autotools. */ #undef TIME_WITH_SYS_TIME /* NUT tree version */ #undef TREE_VERSION /* Enable extensions on AIX 3, Interix. */ #ifndef _ALL_SOURCE # undef _ALL_SOURCE #endif /* Enable general extensions on macOS. */ #ifndef _DARWIN_C_SOURCE # undef _DARWIN_C_SOURCE #endif /* Enable general extensions on Solaris. */ #ifndef __EXTENSIONS__ # undef __EXTENSIONS__ #endif /* Enable GNU extensions on systems that have them. */ #ifndef _GNU_SOURCE # undef _GNU_SOURCE #endif /* Enable X/Open compliant socket functions that do not require linking with -lxnet on HP-UX 11.11. */ #ifndef _HPUX_ALT_XOPEN_SOCKET_API # undef _HPUX_ALT_XOPEN_SOCKET_API #endif /* Identify the host operating system as Minix. This macro does not affect the system headers' behavior. A future release of Autoconf may stop defining this macro. */ #ifndef _MINIX # undef _MINIX #endif /* Enable general extensions on NetBSD. Enable NetBSD compatibility extensions on Minix. */ #ifndef _NETBSD_SOURCE # undef _NETBSD_SOURCE #endif /* Enable OpenBSD compatibility extensions on NetBSD. Oddly enough, this does nothing on OpenBSD. */ #ifndef _OPENBSD_SOURCE # undef _OPENBSD_SOURCE #endif /* Define to 1 if needed for POSIX-compatible behavior. */ #ifndef _POSIX_SOURCE # undef _POSIX_SOURCE #endif /* Define to 2 if needed for POSIX-compatible behavior. */ #ifndef _POSIX_1_SOURCE # undef _POSIX_1_SOURCE #endif /* Enable POSIX-compatible threading on Solaris. */ #ifndef _POSIX_PTHREAD_SEMANTICS # undef _POSIX_PTHREAD_SEMANTICS #endif /* Enable extensions specified by ISO/IEC TS 18661-5:2014. */ #ifndef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ # undef __STDC_WANT_IEC_60559_ATTRIBS_EXT__ #endif /* Enable extensions specified by ISO/IEC TS 18661-1:2014. */ #ifndef __STDC_WANT_IEC_60559_BFP_EXT__ # undef __STDC_WANT_IEC_60559_BFP_EXT__ #endif /* Enable extensions specified by ISO/IEC TS 18661-2:2015. */ #ifndef __STDC_WANT_IEC_60559_DFP_EXT__ # undef __STDC_WANT_IEC_60559_DFP_EXT__ #endif /* Enable extensions specified by ISO/IEC TS 18661-4:2015. */ #ifndef __STDC_WANT_IEC_60559_FUNCS_EXT__ # undef __STDC_WANT_IEC_60559_FUNCS_EXT__ #endif /* Enable extensions specified by ISO/IEC TS 18661-3:2015. */ #ifndef __STDC_WANT_IEC_60559_TYPES_EXT__ # undef __STDC_WANT_IEC_60559_TYPES_EXT__ #endif /* Enable extensions specified by ISO/IEC TR 24731-2:2010. */ #ifndef __STDC_WANT_LIB_EXT2__ # undef __STDC_WANT_LIB_EXT2__ #endif /* Enable extensions specified by ISO/IEC 24747:2009. */ #ifndef __STDC_WANT_MATH_SPEC_FUNCS__ # undef __STDC_WANT_MATH_SPEC_FUNCS__ #endif /* Enable extensions on HP NonStop. */ #ifndef _TANDEM_SOURCE # undef _TANDEM_SOURCE #endif /* Enable X/Open extensions. Define to 500 only if necessary to make mbstate_t available. */ #ifndef _XOPEN_SOURCE # undef _XOPEN_SOURCE #endif /* Version number of package */ #undef VERSION /* Defined if we want to use timegm_fallback() */ #undef WANT_TIMEGM_FALLBACK /* Define if WSAStartup is needed. */ #undef WINDOWS_SOCKETS /* Define to enable Asciidoc support */ #undef WITH_ASCIIDOC /* Define to enable Avahi support */ #undef WITH_AVAHI /* Define to enable CGI (HTTP) support */ #undef WITH_CGI /* Define to enable development files support */ #undef WITH_DEV /* Define to enable delivery of libnutconf developer files */ #undef WITH_DEV_LIBNUTCONF /* Define to enable overall documentation generation */ #undef WITH_DOCS /* Define to enable IPMI support using FreeIPMI */ #undef WITH_FREEIPMI /* Define to enable GPIO support */ #undef WITH_GPIO /* Define to enable IPMI support */ #undef WITH_IPMI /* Define libgpio C API version generation */ #undef WITH_LIBGPIO_VERSION /* Define libgpio C API version generation as string */ #undef WITH_LIBGPIO_VERSION_STR /* Define to enable libltdl (Libtool dlopen abstraction) support */ #undef WITH_LIBLTDL /* Define to enable Powerman PDU support */ #undef WITH_LIBPOWERMAN /* Define to build with tighter systemd support (sd_notify etc) */ #undef WITH_LIBSYSTEMD /* Define as 1 if we can use systemd inhibitor interface here */ #undef WITH_LIBSYSTEMD_INHIBITOR /* Define to 1 for version 0.1 of the libusb (via pkg-config or libusb-config). */ #undef WITH_LIBUSB_0_1 /* Define to 1 for version 1.0 of the libusb (via pkg-config). */ #undef WITH_LIBUSB_1_0 /* Define to enable I2C support */ #undef WITH_LINUX_I2C /* Define to enable Mac OS X meta-driver */ #undef WITH_MACOSX /* Define to enable Modbus support */ #undef WITH_MODBUS /* Define to enable Neon HTTP support */ #undef WITH_NEON /* Define to enable SSL support using Mozilla NSS */ #undef WITH_NSS /* Define to enable nutconf tool support */ #undef WITH_NUTCONF /* Define to enable NUT-Monitor desktop application installation */ #undef WITH_NUT_MONITOR /* Define to enable nut-scanner tool support */ #undef WITH_NUT_SCANNER /* Define to enable SSL support using OpenSSL */ #undef WITH_OPENSSL /* Define to enable PyNUT module installation */ #undef WITH_PYNUT /* Define to enable serial support */ #undef WITH_SERIAL /* Define to enable SNMP support */ #undef WITH_SNMP /* Define to use SNMP support with a statically linked libnetsnmp */ #undef WITH_SNMP_STATIC /* Define to consider basic SMF support (provide units and configuration files) */ #undef WITH_SOLARIS_SMF /* Define to enable documentation spell checking as part of default checks */ #undef WITH_SPELLCHECK /* Define to enable SSL */ #undef WITH_SSL /* Define to enable data points discovered during subdriver generation but not mapped to nut-names yet */ #undef WITH_UNMAPPED_DATA_POINTS /* Define to enable USB support */ #undef WITH_USB /* Define to 1 for libusb versions where we can support "busport" USB matching value. */ #undef WITH_USB_BUSPORT /* Define to enable libwrap (tcp-wrappers) support */ #undef WITH_WRAP /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD # if defined __BIG_ENDIAN__ # define WORDS_BIGENDIAN 1 # endif #else # ifndef WORDS_BIGENDIAN # undef WORDS_BIGENDIAN # endif #endif /* Define for Solaris 2.5.1 so the uint32_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT32_T /* Define for Solaris 2.5.1 so the uint64_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT64_T /* Define for Solaris 2.5.1 so the uint8_t typedef from , , or is not used. If the typedef were allowed, the #define below would cause a syntax error. */ #undef _UINT8_T /* Define to 1 if C does not support variable-length arrays, and if the compiler does not already define this. */ #undef __STDC_NO_VLA__ /* Replace missing __func__ declaration */ #undef __func__ /* Define to `__inline__' or `__inline' if that's what the C compiler calls it, or to nothing if 'inline' is not supported under any name. */ #ifndef __cplusplus #undef inline #endif /* Define to the type of a signed integer type of width exactly 16 bits if such a type exists and the standard includes do not define it. */ #undef int16_t /* Define to the type of a signed integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ #undef int32_t /* Define to the type of a signed integer type of width exactly 64 bits if such a type exists and the standard includes do not define it. */ #undef int64_t /* Define to the type of a signed integer type of width exactly 8 bits if such a type exists and the standard includes do not define it. */ #undef int8_t /* Define to the widest signed integer type if and do not define. */ #undef intmax_t /* Define to `unsigned int' if does not define. */ #undef size_t /* type to use in place of socklen_t if not defined */ #undef socklen_t /* Define to `int' if does not define. */ #undef ssize_t /* Define to the type of an unsigned integer type of width exactly 16 bits if such a type exists and the standard includes do not define it. */ #undef uint16_t /* Define to the type of an unsigned integer type of width exactly 32 bits if such a type exists and the standard includes do not define it. */ #undef uint32_t /* Define to the type of an unsigned integer type of width exactly 64 bits if such a type exists and the standard includes do not define it. */ #undef uint64_t /* Define to the type of an unsigned integer type of width exactly 8 bits if such a type exists and the standard includes do not define it. */ #undef uint8_t /* Define to the widest unsigned integer type if and do not define. */ #undef uintmax_t nut-2.8.4/include/proto.h0000644000175000017500000000742315044656702012232 00000000000000/* proto.h - fill in the gaps about prototypes and definitions for portability Copyright (C) 2001 Russell Kroll 2005 Arnaud Quette 2006 Peter Selinger 2013 Emilien Kia 2020 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_PROTO_H_SEEN #define NUT_PROTO_H_SEEN 1 /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif #include "attribute.h" #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) /* Define this as a fall through, HAVE_STDARG_H is probably already set */ #ifndef HAVE_VARARGS_H #define HAVE_VARARGS_H #endif /* varargs declarations: */ #if defined(HAVE_STDARG_H) # include # define HAVE_STDARGS /* let's hope that works everywhere (mj) */ # define VA_LOCAL_DECL va_list ap # define VA_START(f) va_start(ap, f) # define VA_SHIFT(v,t) ; /* no-op for ANSI */ # define VA_END va_end(ap) #else # if defined(HAVE_VARARGS_H) # include # undef HAVE_STDARGS # define VA_LOCAL_DECL va_list ap # define VA_START(f) va_start(ap) /* f is ignored! */ # define VA_SHIFT(v,t) v = va_arg(ap,t) # define VA_END va_end(ap) # else /*XX ** NO VARARGS ** XX*/ # endif #endif #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif #if !defined (HAVE_SNPRINTF) || defined (__Lynx__) int snprintf (char *str, size_t count, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); #endif #if !defined (HAVE_VSNPRINTF) int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); #endif #endif #ifndef HAVE_SETENV int nut_setenv(const char *name, const char *value, int overwrite); static inline int setenv(const char *name, const char *value, int overwrite) { return nut_setenv(name, value, overwrite); } #endif #ifndef HAVE_UNSETENV int nut_unsetenv(const char *name); static inline int unsetenv(const char *name) { return nut_unsetenv(name); } #endif #ifdef __hpux #ifdef HAVE_SYS_MODEM_H #include #endif /* See sys/termio.h and sys/modem.h The following serial bits are not defined by HPUX. The numbers are octal like I found in BSD. TIOCM_ST is used in genericups.[ch] for the Powerware 3115. These defines make it compile, but I have no idea if it works. */ #define TIOCM_LE 0001 /* line enable */ #define TIOCM_ST 0010 /* secondary transmit */ #define TIOCM_SR 0020 /* secondary receive */ #endif #ifdef HAVE_GETPASSPHRASE #define GETPASS getpassphrase #else #define GETPASS getpass #endif #ifdef __Lynx__ /* Missing prototypes on LynxOS */ int seteuid(uid_t); int vprintf(const char *, va_list); int putenv(char *); #endif #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_PROTO_H_SEEN */ nut-2.8.4/include/nut_float.h0000664000175000017500000000511415000733176013050 00000000000000/* * nut_float.h - Network UPS Tools include files for floating point routines * and ways to compare if non-integers are close enough to assume equal * * Copyright (C) 2020 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_FLOAT_H_SEEN #define NUT_FLOAT_H_SEEN 1 /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif #if defined HAVE_FLOAT_H # include #endif #if defined HAVE_MATH_H # include #endif /* Modern compilers frown upon direct comparisons of floating point numbers * since their imprecise internal representations can misfire, and really we * care if they are indiscernably close. To aviod warnings like -Wfloat-equal * we prefer to compare with methods defined below. Note: despite the "floating" * name, fabs() seems to be defined over doubles or wider types, e.g.: * double fabs(double x); * float fabsf(float x); * long double fabsl(long double x); * To be on the safer side, we compare the difference to be smaller or equal to * the Epsilon for the respective numeric type, in order to be equivalent to a * zero for our needs. Various libs define it as "the next representable number * after 1.0 which is not equal to 1.0" for the discrete maths involved; no talk * about exactly comparing it to zero or whether it is the smallest representable * non-zero value... */ #define f_equal(x, y) ( fabsf((float)(x) - (float)(y)) <= FLT_EPSILON ) #define d_equal(x, y) ( fabs((double)(x) - (double)(y)) <= DBL_EPSILON ) #define ld_equal(x, y) ( fabsl((long double)(x) - (long double)(y)) <= LDBL_EPSILON ) #ifndef HAVE_STRTOF /* Use fallback from libcommon */ float strtof(const char *nptr, char **endptr); #endif #endif /* NUT_FLOAT_H_SEEN */ nut-2.8.4/include/state.h0000664000175000017500000000634515000733176012204 00000000000000/* state.h - Network UPS Tools common state management functions Copyright (C) 2003 Russell Kroll 2012 Arnaud Quette This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_STATE_H_SEEN #define NUT_STATE_H_SEEN 1 #include "extstate.h" #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif #define ST_SOCK_BUF_LEN 512 #include "timehead.h" #if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC) && HAVE_CLOCK_GETTIME && HAVE_CLOCK_MONOTONIC typedef struct timespec st_tree_timespec_t; #else typedef struct timeval st_tree_timespec_t; #endif typedef struct st_tree_s { char *var; char *val; /* points to raw or safe */ char *raw; /* raw data from caller */ size_t rawsize; char *safe; /* safe data from pconf_encode */ size_t safesize; int flags; long aux; /* When was this entry last written (meaning that * val/raw/safe, flags, aux, enum or range value * was added, changed or deleted)? */ st_tree_timespec_t lastset; struct enum_s *enum_list; struct range_s *range_list; struct st_tree_s *left; struct st_tree_s *right; } st_tree_t; int state_get_timestamp(st_tree_timespec_t *now); int st_tree_node_compare_timestamp(const st_tree_t *node, const st_tree_timespec_t *cutoff); int state_setinfo(st_tree_t **nptr, const char *var, const char *val); int state_addenum(st_tree_t *root, const char *var, const char *val); int state_addrange(st_tree_t *root, const char *var, const int min, const int max); int state_setaux(st_tree_t *root, const char *var, const char *auxs); const char *state_getinfo(st_tree_t *root, const char *var); int state_getflags(st_tree_t *root, const char *var); long state_getaux(st_tree_t *root, const char *var); const enum_t *state_getenumlist(st_tree_t *root, const char *var); const range_t *state_getrangelist(st_tree_t *root, const char *var); void state_setflags(st_tree_t *root, const char *var, size_t numflags, char **flags); int state_addcmd(cmdlist_t **list, const char *cmd); void state_infofree(st_tree_t *node); void state_cmdfree(cmdlist_t *list); int state_delcmd(cmdlist_t **list, const char *cmd); int state_delinfo(st_tree_t **root, const char *var); int state_delinfo_olderthan(st_tree_t **root, const char *var, const st_tree_timespec_t *cutoff); int state_delenum(st_tree_t *root, const char *var, const char *val); int state_delrange(st_tree_t *root, const char *var, const int min, const int max); st_tree_t *state_tree_find(st_tree_t *node, const char *var); #ifdef __cplusplus /* *INDENT-OFF* */ } /* *INDENT-ON* */ #endif #endif /* NUT_STATE_H_SEEN */ nut-2.8.4/INSTALL.nut.adoc0000644000175000017500000011304015044656702012027 00000000000000Installation instructions ========================= // NOTE: No blank line here, document-header include processing should kick in! //GH_MARKUP_1095//ifdef::top_srcdir[] //GH_MARKUP_1095//include::{top_srcdir}docs/asciidoc-vars.conf[] //GH_MARKUP_1095//endif::top_srcdir[] //GH_MARKUP_1095//ifndef::top_srcdir[] //GH_MARKUP_1095//include::docs/asciidoc-vars.conf[] //GH_MARKUP_1095//endif::top_srcdir[] //GH_MARKUP_1095_INCLUDE_BEGIN//a6bd83d48 (2025-03-20) docs/asciidoc-vars.conf: document that linkdoc may have further args ifndef::asciidoc-vars-nut-included[] :asciidoc-vars-nut-included: true // NOTE: The big block of comments and definitions below comes from // NUT::docs/asciidoc-vars.conf and is included into top-level document // sources by maintenance recipes directly (`make maintainer-asciidocs`), // due to current limitations of the GitHub Web UI asciidoc renderer. // Hopefully it can be dropped in favor of compact include definitions // (see README.adoc for anticipated example) after this issue is resolved // on their side: // * https://github.com/github/markup/issues/1095 // // This file should be included into NUT documentation sources to consistently // define certain expandable attributes, with contents defined based on the // rendition target (e.g. GitHub Web UI, plain text, locally built HTML/PDF...) // Note that currently GitHub Web UI references lead to nut-website (as of // last built and published revision), not to neighboring documents in the // source browser (which would make sense for branch revisions, etc.) due // to certain complexity about referencing other-document sections with a // partially functional rendering engine there. Exploration and fixes are // welcome (actually working links like // https://github.com/networkupstools/nut/tree/master#installing or // https://github.com/networkupstools/nut/blob/master/UPGRADING.adoc#changes-from-274-to-280 // do seem promising)! // // Since the GitHub UI does not allow use of custom asciidoc configuration // files, or generally does not process the `include:` requests at this time, // clumsy expandable attributes had to be used (usually a set including a // prefix with meaningful name, and one or more separators and/or a suffix // with shortened names). For our classic documentation renditions, they // should resolve to properly defined macros from `docs/asciidoc.conf` // (usually named same as the variables defined here, for simplicity): // * `linksrcdoc` allows to refer to a source of documentation file // relative to the root of NUT code base. // * `linkdoc` allows to refer to a file under `docs/` directory (or // its nut-website rendition). // * `xref` substitutes the asciidoc shorthand '<< >>' syntax with // attributes that conditionally expand to: // - links on GitHub (references can point at most to a section of // level docs/common.xsl's ), or // - xref asciidoc macros when generating docs. // * `linksingledoc` guarantees that, when chunked HTML is generated, // the link always points to a non-chunked file. // * `linkman2` allows to support different names for the manpage and // the command shown. This is also needed to properly display links // to manpages in both GitHub and generated docs without defining an // attribute for each manpage. // * `linkmanext` and `linkmanext2` macros repeat the behavior of the default ones. // These macros are intended for system man pages (e.g. HTML links might lead // to a generic internet site, or possibly to a distro-provided library // online or locally). // // Optional attributes set by callers: // * `website-url` (defaulted below) may be used for "historic website" // snapshot builds... hopefully // * `website` is used as a boolean toggle in our recipes for nut-website // vs. offline documentation renditions // * `env-github` is used as a boolean toggle, set by GitHub Web-UI renderer // * `(top_)srcdir` and `(top_)builddir` can be set by `Makefile.am` // calling the `a2x` tool, since some of the files with the asciidoc // mark-up are only generated or post-processed during build and // (due to `make dist` restrictions) being build products, they may // not reside in same directory as static source text files which // reference or include them. Note that the non-`top` paths would // normally differ based on location of the `Makefile` involved // (e.g. workspace root, or the `docs`, or `docs/man` directories). // These variables are expected to be absolute paths, or ones relative // to asciidoc-selected `:base_dir`, and to end with a relevant path // separator, or be empty -- so in all cases letting the resulting // string resolve meaningfully in the filesystem during docs build. // // Please keep the remaining comments and definitions as one big block // so it does not become a series of empty paragraphs in the rendered // documents! // ifndef::website-url[] :website-url: https://www.networkupstools.org/ endif::website-url[] // ifndef::srcdir[] :srcdir: endif::srcdir[] // ifndef::builddir[] :builddir: endif::builddir[] // ifndef::top_srcdir[] :top_srcdir: endif::top_srcdir[] // ifndef::top_builddir[] :top_builddir: endif::top_builddir[] // // // Address links on GitHub vs. docs // (note: 'env-github' attribute is set on GitHub) // // - when generating docs: ifndef::env-github[] // * xref -> xref // syntax: {xref}{x-s}[] // -> xref:[] :xref: xref: :x-s: // * link to doc -> our macro // syntax: {linksrcdoc} // -> linksrcdoc:[] :linksrcdoc: linksrcdoc: // * link to doc -> our macro (optional 2/3/4 args) // syntax: {linkdoc}{ld-s}[{,{,{,}}}] // -> linkdoc:[{,{,{,}}}] :linkdoc: linkdoc: :ld-s: // * link to single doc -> our macro // syntax: {linksingledoc}{lsd-s}[] // -> linksingledoc:[] :linksingledoc: linksingledoc: :lsd-s: // * link to manpage -> our macro // syntax: {linkman2}{lm-s}{lm-c}{lm-e} // -> linkman2:[,] :linkman2: linkman2: :lm-s: [ :lm-c: , :lm-e: ] :linkmanext: https://www.die.net/search/?q= :linkmanext2: https://www.die.net/search/?q= endif::env-github[] // // - on GitHub: ifdef::env-github[] // In our normal builds, Makefile variables convey the needed paths // (used relatively below as `image:images/ci/...png` etc.) :imagesdir: docs // * xref -> link // syntax: {xref}{x-s}[] // In order for it to work, can reference at most a section of // level docs/common.xsl's // -> {website-url}docs/user-manual.chunked/.html[] :xref: {website-url}docs/user-manual.chunked/ :x-s: .html // * link to doc -> our macro // syntax: {linksrcdoc} // -> link:[] :linksrcdoc: link:{top_srcdir}/ // * link to doc -> link (FIXME: ignore or use 2/3/4 args; currently they are all pasted as contents!) // syntax: {linkdoc}{ld-s}[{,{,{,}}}] // -> {website-url}docs/.chunked/index.html[] :linkdoc: {website-url}docs/ :ld-s: .chunked/index.html // * link to single doc -> link // syntax: {linksingledoc}{lsd-s}[] // -> {website-url}docs/.html[] :linksingledoc: {website-url}docs/ :lsd-s: .html // * link to manpage -> link // syntax: {linkman2}{lm-s}{lm-c}{lm-e} // All the fields are mandatory. // -> {website-url}docs/man/.html[()] :linkman2: {website-url}docs/man/ :lm-s: .html[ :lm-c: ( :lm-e: )] :linkmanext: https://www.die.net/search/?q= :linkmanext2: https://www.die.net/search/?q= endif::env-github[] endif::asciidoc-vars-nut-included[] // //GH_MARKUP_1095_INCLUDE_END// This chapter describes the various methods for installing Network UPS Tools. Whenever it is possible, prefer <>. Packagers have done an excellent and hard work at improving NUT integration into their operating system. On the other hand, distributions and appliances tend to package "official releases" of projects such as NUT, and so do not deliver latest and greatest fixes, new drivers, bugs and other features. Stable distributions also tend to deliver minor fixes to the version of third-party software (like NUT) a particular release of the operating system has initially delivered, so those release lines can be years behind development in terms of new features (or bug fixes, if they are not trivial to patch into the old code base snapshot used to create the package). [[Installing_source]] Installing from source ---------------------- These are the essential steps for compiling and installing this software from distribution archives (usually "release tarballs") which include a pre-built copy of the `configure` script and some other generated source files. To build NUT from a Git checkout you may need some additional tools (referenced just a bit below) and run `./autogen.sh` to generate the needed files. For common developer iterations, porting to new platforms, or in-place testing, running the `./ci_build.sh` script can be helpful. The "<>" section details some more hints about such workflow, including some `systemd` integration. The NUT linkdoc:packager-guide[Packager Guide], which presents the best practices for installing and integrating NUT, is also a good reading. The {linkdoc}qa-guide{ld-s}[NUT Quality Assurance Guide,NUT_Config_Prereqs,docs/config-prereqs.txt] document suggests prerequisite packages with tools and dependencies available and needed to build and test as much as possible of NUT on numerous platforms, written from perspective of CI testing (if you are interested in getting updated drivers for a particular device, you might select a sub-set of those suggestions). NOTE: This "Config Prereqs" document for latest NUT iteration can be found at https://github.com/networkupstools/nut/blob/master/docs/config-prereqs.txt or as `docs/config-prereqs.txt` in your build workspace (from Git or tarball). [NOTE] .Keep in mind that... ================================================================================ - the paths shown below are the default values you get by just calling configure by itself. If you have used --prefix or similar, things will be different. Also, if you didn't install this program from source yourself, the paths will probably have a number of differences. - by default, your system probably won't find the man pages, since they install to /usr/local/ups/man. You can fix this by editing your MANPATH, or just do this: man -M /usr/local/ups/man - if your favorite system offers up to date binary packages, you should always prefer these over a source installation (unless there are known deficiencies in the package or one is too obsolete). Along with the known advantages of such systems for installation, upgrade and removal, there are many integration issues that have been addressed. ================================================================================ Prepare your system ~~~~~~~~~~~~~~~~~~~~ System User creation ^^^^^^^^^^^^^^^^^^^^ Create at least one system user and a group for running this software. You might call them "ups" and "nut". The exact names aren't important as long as you are consistent. The process for doing this varies from one system to the next, and explaining how to add users is beyond the scope of this document. For the purposes of this document, the user name and group name will be 'ups' and 'nut' respectively. Be sure the new user is a member of the new group! If you forget to do this, you will have problems later on when you try to start upsd. Build and install ~~~~~~~~~~~~~~~~~ NOTE: See also <>. [[Configuration]] Configuration ^^^^^^^^^^^^^ Configure the source tree for your system. Add the '--with-user' and '--with-group' switch to set the user name and group that you created above. ./configure --with-user=ups --with-group=nut If you need any other switches for configure, add them here. For example: * to build and install USB drivers, add '--with-usb' (note that you need to install libusb development package or files). * to build and install SNMP drivers, add '--with-snmp' (note that you need to install libsnmp development package or files). * to build and install CGI scripts, add '--with-cgi'. See <> from the User Manual, docs/configure.txt or './configure --help' for all the available options. If you alter paths with additional switches, be sure to use those new paths while reading the rest of the steps. Reference: <> from the User Manual. Build the programs ^^^^^^^^^^^^^^^^^^ make This will build the NUT client and server programs and the selected drivers. It will also build any other features that were selected during <> step above. NOTE: NUT is regularly tested with GNU, BSD and Sun implementations of `make`. Installation ^^^^^^^^^^^^ [NOTE] ===================================================================== You should now gain privileges for installing software if necessary, e.g.: su - or prefix installation (not build/check!) commands with `sudo`, e.g.: sudo make install ... ===================================================================== [NOTE] ===================================================================== If you install NUT for direct consumption on the system that has just built it from source, you might be aided for some of the steps listed and explained below by running (as `root`): make install-as-root This should not only install the software, but also create directories such as the state path, assign ownership and access permissions to certain directories and sample configuration files which NUT user and/or group accounts should be able to read and/or write, and, on some platforms, also (re-)start the NUT daemons/services. See above "System User creation", that should be done first! ===================================================================== Install the files to a system level directory: make install This will install the compiled programs and man pages, as well as some data files required by NUT. Any optional features selected during configuration will also be installed. This will also install sample versions of the NUT configuration files. Sample files are installed with names like ups.conf.sample so they will not overwrite any existing real config files you may have created. If you are packaging this software, then you will probably want to use the DESTDIR variable to redirect the build into another place, also known as a "prototype directory" or a "staging area", i.e.: make DESTDIR=/tmp/package install make DESTDIR=/tmp/package install-conf [[StatePath]] State path creation ^^^^^^^^^^^^^^^^^^^ NOTE: See above about `make install-as-root`, if you use that -- skip this step here. Create the state path directory for the driver(s) and server to use for storing UPS status data and other auxiliary files, and make it group-writable by the group of the system user you created, e.g.: mkdir -p /var/state/ups chmod 0770 /var/state/ups chown root:nut /var/state/ups [[Ownership]] Ownership and permissions ^^^^^^^^^^^^^^^^^^^^^^^^^ Set ownership data and permissions on your serial or USB ports that go to your UPS hardware. Be sure to limit access to just the user you created earlier. These examples assume the second serial port (ttyS1) on a typical Slackware system. On FreeBSD, that would be cuaa1. Serial ports vary greatly, so yours may be called something else. chmod 0660 /dev/ttyS1 chown root:nut /dev/ttyS1 //////////////////////////////////////////////////////////////////////////////// FIXME: TBR //////////////////////////////////////////////////////////////////////////////// The setup for USB ports is slightly more complicated. Device files for USB devices, such as /proc/bus/usb/002/001, are usually created "on the fly" when a device is plugged in, and disappear when the device is disconnected. Moreover, the names of these device files can change randomly. To set up the correct permissions for the USB device, you may need to set up (operating system dependent) hotplugging scripts. Sample scripts and information are provided in the scripts/hotplug and scripts/udev directories. For most users, the hotplugging scripts will be installed automatically by "make install". (If you want to try if a driver works without setting up hotplugging, you can add the "-u root" option to upsd, upsmon, and drivers; this should allow you to follow the below instructions. However, don't forget to set up the correct permissions later!). NOTE: If you are using something like udev or devd, make sure these permissions stay set across a reboot. If they revert to the old values, your drivers may fail to start. You are now ready to configure NUT, and start testing and using it. You can jump directly to the <>. [[Installing_inplace]] Building NUT for in-place upgrades or non-disruptive tests ---------------------------------------------------------- NOTE: The NUT GitHub Wiki article at https://github.com/networkupstools/nut/wiki/Building-NUT-for-in%E2%80%90place-upgrades-or-non%E2%80%90disruptive-tests may contain some more hints as contributed by the community. Overview ~~~~~~~~ Since late 2022/early 2023 NUT codebase supports "in-place" builds which try their best to discover the configuration of an earlier build (configuration and run-time paths and OS accounts involved, maybe an exact configuration if stored in deployed binaries). This optional mode is primarily intended for several use-cases: * Test recent GitHub "master" branch or a proposed PR to see if it solves a practical problem for a particular user; * Replace an existing deployment, e.g. if OS-provided packages deliver obsolete code, to use newer NUT locally in "production mode". - In such cases ideally get your distribution, NAS vendor, etc. to provide current NUT -- and benefit from a better integrated and tested product. Note that "just testing" often involves building the codebase and new drivers or tools in question, and running them right from the build workspace (without installing into the system and so risking an unpredictable-stability state). In case of testing new driver builds, note that you would need to stop the normally running instances to free up the communications resources (USB/serial ports, etc.), run the new driver program in data-dump mode, and restart the normal systems operations. Such tests still benefit from matching the build configuration to what is already deployed, in order to request same configuration files and system access permissions (e.g. to own device nodes for physical-media ports involved, and to read the production configuration files). Pre-requisites ^^^^^^^^^^^^^^ The {linkdoc}qa-guide{ld-s}[NUT Quality Assurance Guide,NUT_Config_Prereqs,docs/config-prereqs.txt] document details tools and dependencies that were added on NUT CI build environments, which now cover many operating systems. This should provide a decent starting point for the build on yours (PRs to update the document are welcome!) Note that unlike distribution tarballs, Git sources do not include a `configure` script and some other files -- these should be generated by running `autogen.sh` (or `ci_build.sh` that calls it). Getting the right sources ^^^^^^^^^^^^^^^^^^^^^^^^^ To build the current tip of development iterations (usually after PR merges that passed CI, reviews and/or other tests), just clone the NUT repository and "master" branch should get checked out by default (also can request that explicitly, per example posted below). If you want to quickly test a particular pull request, see the link on top of the PR page that says `... wants to merge ... from : ...` and copy the proposed-source URL of that "from" part. For example, in some PR this says `jimklimov:issue-1234` and links to `https://github.com/jimklimov/nut/tree/issue-1234`. For manual git-cloning, just paste that URL into the shell and replace the `/tree/` with "`-b`" CLI option for branch selection; it also helps to keep the workspace directory name dedicated to that PR, like this: :; cd /tmp ### Checkout https://github.com/jimklimov/nut/tree/issue-1234 :; git clone https://github.com/jimklimov/nut -b issue-1234 nut-issue-1234 :; cd nut-issue-1234 ### OPTIONALLY fetch known git tags, so semantic versions look better :; git fetch --tags --all ### Proceed with build (common instructions below) Testing with CI helper ~~~~~~~~~~~~~~~~~~~~~~ NOTE: This uses the `ci_build.sh` script to arrange some rituals and settings, in this case primarily to default the choice of drivers to auto-detection of what can be built, and to skip building documentation. Also note that this script supports many other scenarios for CI and developers, managed by `BUILD_TYPE` and other environment variables, which are not explored here. An "in-place" _testing_ build and run would probably go along these lines: :; cd /tmp :; git clone -b master https://github.com/networkupstools/nut :; cd nut ### OPTIONALLY fetch known git tags, so semantic versions look better :; git fetch --tags --all ### Proceed with build :; ./ci_build.sh inplace ### Temporarily stop your original drivers :; ./drivers/nutdrv_qx -a DEVNAME_FROM_UPS_CONF -d1 -DDDDDD \ # -x override...=... -x subdriver=... ### Can start back your original drivers ### Analyze and/or post back the data-dump [NOTE] ====== To probe a device for which you do not have an `ups.conf` section yet, you must specify `-s name` and all config options (including `port`) on command-line with `-x` arguments, e.g.: :; ./drivers/nutdrv_qx -s temp-ups \ -d1 -DDDDDD -x port=auto \ -x vendorid=... -x productid=... \ -x subdriver=... ====== Replacing a NUT deployment ~~~~~~~~~~~~~~~~~~~~~~~~~~ While `ci_build.sh inplace` can be a viable option for preparation of local builds, you may want to have precise control over `configure` options (e.g. choice of required drivers, or enabled documentation). A sound starting point would be to track down packaging recipes used by your distribution (e.g. link:https://src.fedoraproject.org/rpms/nut/blob/rawhide/f/nut.spec[RPM spec] or link:https://salsa.debian.org/debian/nut/-/blob/debian/debian/rules[DEB rules] files, etc.) to detail the same paths if you intend to replace those, and copy the parameters for `configure` script from there -- especially if your system is not currently running NUT v2.8.1 or newer (which embeds this information to facilitate in-place upgrade rebuilds). Note that the primary focus of in-place automated configuration mode is about critical run-time options, such as OS user accounts, configuration location and state/PID paths, so it alone might not replace your driver binaries that the package would put into an obscure location like `/lib/nut`. It would however install init-scripts or systemd units that would refer to new locations specified by the current build, so such old binaries would just consume disk space but not run. It is recommended to first try installing into a prototyping area, so you can review which files get delivered and perhaps which locations you may have to tune for a more tightly tailored replacement of an older (packaged) installation, in case whole swathes of files that you expect to be present in the current system (libraries, drivers, docs) are not getting installed by the new build into same path names: ---- :; rm -rf /tmp/nut ; make DESTDIR=/tmp/nut install -j 8 :; (cd /tmp/nut && find . | sort) | while read N ; \ do [ -e "/$N" ] || echo "=== MISSING: /$N" >&2 ; done ---- Replacing any NUT deployment ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NOTE: For deployments on OSes with `systemd` see the next section. This goes similar to usual build and install from Git: :; cd /tmp :; git clone https://github.com/networkupstools/nut :; cd nut ### OPTIONALLY fetch known git tags, so semantic versions look better :; git fetch --tags --all ### Proceed with build :; ./autogen.sh :; ./configure --enable-inplace-runtime # --maybe-some-other-options :; make -j 4 all && make -j 4 check && sudo make install Note that `make install` does not currently handle all the nuances that packaging installation scripts would, such as customizing filesystem object ownership, daemon restarts, etc. or even creating locations like `/var/state/ups` and `/var/run/nut` as part of the `make` target (but e.g. the delivered `systemd-tmpfiles` configuration can handle that for a large part of the audience). This aspect is tracked as link:https://github.com/networkupstools/nut/issues/1298[issue #1298] At this point you should revise the locations for PID files (e.g. `/var/run/nut`) and pipe files (e.g. `/var/state/ups`) that they exist and permissions remain suitable for NUT run-time user selected by your configuration, and typically stop your original NUT drivers, data-server (upsd) and upsmon, and restart them using the new binaries. Replacing a systemd-enabled NUT deployment ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For modern Linux distributions with `systemd` this replacement procedure could be enhanced like below, to also re-enable services (creating proper symlinks) and to get them started: :; cd /tmp :; git clone https://github.com/networkupstools/nut :; cd nut ### OPTIONALLY fetch known git tags, so semantic versions look better :; git fetch --tags --all ### Proceed with build :; ./autogen.sh :; ./configure --enable-inplace-runtime # --maybe-some-other-options :; make -j 4 all && make -j 4 check && \ { sudo systemctl stop nut-monitor nut-server || true ; } && \ { sudo systemctl stop nut-driver.service || true ; } && \ { sudo systemctl stop nut-driver.target || true ; } && \ { sudo systemctl stop nut.target || true ; } && \ sudo make install && \ sudo systemctl daemon-reload && \ sudo systemd-tmpfiles --create && \ sudo systemctl disable nut.target nut-driver.target \ nut-monitor nut-server nut-driver-enumerator.path \ nut-driver-enumerator.service && \ sudo systemctl enable nut.target nut-driver.target \ nut-monitor nut-server nut-driver-enumerator.path \ nut-driver-enumerator.service && \ { sudo systemctl restart udev || true ; } && \ sudo systemctl restart nut-driver-enumerator.service \ nut-monitor nut-server Note the several attempts to stop old service units -- naming did change from 2.7.4 and older releases, through 2.8.0, and up to current codebase. Most of the NUT units are now `WantedBy=nut.target` (which is in turn `WantedBy=multi-user.target` and so bound to system startup). You should only `systemctl enable` those units you need on this system -- this allows it to not start the daemons you do not need (e.g. not run `upsd` NUT data server on systems which are only `upsmon secondary` clients). The `nut-driver-enumerator` units (and corresponding shell script) are part of a new feature introduced in NUT 2.8.0, which automatically discovers `ups.conf` sections and changes to their contents, and manages instances of a `nut-driver@.service` definition. You may also have to restart (or reload if supported) some system services if your updates impact them, like `udev` for updates USB support (note also link:https://github.com/networkupstools/nut/pull/1342[PR #1342] regarding the change from `udev.rules` to `udev.hwdb` file with NUT v2.8.0 or later -- you may have to remove the older file manually). Iterating with a systemd deployment ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ If you are regularly building NUT from GitHub "master" branch, or iterating local development branches of your own, you *may* get away with shorter constructs to just restart the services after installing newly built files (if you know there were no changes to unit file definitions and dependencies), e.g.: :; cd /tmp :; git clone https://github.com/networkupstools/nut :; cd nut :; git checkout -b issue-1234 ### your PR branch name, arbitrary ### OPTIONALLY fetch known git tags, so semantic versions look better :; git fetch --tags --all ### Proceed with build :; ./autogen.sh :; ./configure --enable-inplace-runtime # --maybe-some-other-options ### Iterate your code changes (e.g. PR draft), build and install with: :; make -j 4 all && make -j 4 check && \ sudo make install && \ sudo systemctl daemon-reload && \ sudo systemd-tmpfiles --create && \ sudo systemctl restart \ nut-driver-enumerator.service nut-monitor nut-server Note that to contribute your work back to upstream NUT codebase, you would need to create a "fork" of https://github.com/networkupstools/nut on GitHub, then `git remote add USERNAME https://github.com/USERNAME/nut`, maybe refresh the workspace index with `git fetch --all`, and finally `git push USERNAME` (possibly follow further instructions from `git` tooling) to create the pull request. For more details, see `docs/developers.txt` in NUT sources. Next steps after an in-place upgrade ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can jump directly to the <> if you need to revise the settings for your new NUT version, take advantage of new configuration options, etc. Check the {linksrcdoc}NEWS.adoc[] and {linksrcdoc}UPGRADING.adoc[] files in your checked-out Git workspace to review features that should be present in your new build. [[Installing_packages]] Installing from packages ------------------------ This chapter describes the specific installation steps when using binary packages that exist on various major systems. [[Debian]] Debian, Ubuntu and other derivatives ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NOTE: NUT is packaged and well maintained in these systems. The official Debian packager used to be part of the NUT Team. Using your preferred method (apt-get, aptitude, Synaptic, ...), install the 'nut' package, and optionally the following: - 'nut-cgi', if you need the CGI (HTML) option, - 'nut-snmp', if you need the snmp-ups driver, - 'nut-xml', for the netxml-ups driver, - 'nut-powerman-pdu', to control the PowerMan daemon (PDU management) - 'nut-dev', if you need the development files. //////////////////////////////////////////////////////////////////////////////// - nut-client //////////////////////////////////////////////////////////////////////////////// Configuration files are located in /etc/nut. linkman:nut.conf[5] must be edited to be able to invoke /etc/init.d/nut NOTE: Ubuntu users can access the APT URL installation by clicking on link:apt://nut[this link]. [[Mandriva]] Mandriva ~~~~~~~~ NOTE: NUT is packaged and well maintained in these systems. The official Mandriva packager is part of the NUT Team. Using your preferred method (urpmi, RPMdrake, ...), install one of the two below packages: - 'nut-server' if you have a 'standalone' or 'netserver' installation, - 'nut' if you have a 'netclient' installation. Optionally, you can also install the following: - 'nut-cgi', if you need the CGI (HTML) option, - 'nut-devel', if you need the development files. [[SUSE]] SUSE / openSUSE ~~~~~~~~~~~~~~~ NOTE: NUT is packaged and well maintained in these systems. The official SUSE packager is part of the NUT Team. Install the 'nut-classic' package, and optionally the following: - 'nut-drivers-net', if you need the snmp-ups or the netxml-ups drivers, - 'nut-cgi', if you need the CGI (HTML) option, - 'nut-devel', if you need the development files, NOTE: SUSE and openSUSE users can use the link:http://software.opensuse.org/search?baseproject=ALL&p=1&q=nut[one-click install method] to install NUT. [[RedHat]] Red Hat, Fedora and CentOS ~~~~~~~~~~~~~~~~~~~~~~~~~~ NOTE: NUT is packaged and well maintained in these systems. The official Red Hat packager is part of the NUT Team. Using your preferred method (yum, Add/Remove Software, ...), install one of the two below packages: - 'nut' if you have a 'standalone' or 'netserver' installation, - 'nut-client' if you have a 'netclient' installation. Optionally, you can also install the following: - 'nut-cgi', if you need the CGI (HTML) option, - 'nut-xml', if you need the netxml-ups driver, - 'nut-devel', if you need the development files. [[FreeBSD]] FreeBSD ~~~~~~~ You can either install NUT as a binary package or as a port. Binary package ^^^^^^^^^^^^^^ To install NUT as a package execute: # pkg install nut Port ^^^^ The port is located under +sysutils/nut+. Use +make config+ to select configuration options, e.g. to build the optional CGI scripts. To install it, use: # make install clean USB UPS on FreeBSD ^^^^^^^^^^^^^^^^^^ For USB UPS devices the NUT package/port installs devd rules in +/usr/local/etc/devd/nut-usb.conf+ to set USB device permissions. 'devd' needs to be restarted for these rules to apply: # service devd restart (Re-)connect the device after restarting 'devd' and check that the USB device has the proper permissions. Check the last entries of the system message buffer. You should find an entry like: # dmesg | tail [...] ugen0.2: at usbus0 The device file must be owned by group +uucp+ and must be group read-/writable. In the example from above this would be # ls -Ll /dev/ugen0.2 crw-rw---- 1 root uucp 0xa5 Mar 12 10:33 /dev/ugen0.2 If the permissions are not correct, verify that your device is registered in +/usr/local/etc/devd/nut-usb.conf+. The vendor and product id can be found using: # usbconfig -u 0 -a 2 dump_device_desc where +-u+ specifies the USB bus number and +-a+ specifies the USB device index. [[Windows]] Windows ~~~~~~~ Windows binary package ^^^^^^^^^^^^^^^^^^^^^^ [NOTE] ====== NUT binary package built for Windows platform was last issued for a much older codebase (using NUT v2.6.5 as a baseline). While the current state of the codebase you are looking at aims to refresh the effort of delivering NUT on Windows, the aim at the moment is to help developers build and modernize it after a decade of blissful slumber, and packages are not being regularly produced yet. Functionality of such builds varies a lot depending on build environment used. This effort is generally tracked at https://github.com/orgs/networkupstools/projects/2/views/1 and help would be welcome! It should currently be possible to build the codebase in native Windows with MSYS2/MinGW and cross-building from Linux with mingw (preferably in a Debian/Ubuntu container). Refer to link:docs/config-prereqs.txt[Prerequisites for building NUT on different OSes] and link:scripts/Windows/README.adoc[scripts/Windows/README.adoc file] for respective build environment preparation instructions. Note that to use NUT for Windows, non-system dependency DLL files must be located in same directory as each EXE file that uses them. This can be accomplished for FOSS libraries (copying them from the build environment) by calling `make install-win-bundle DESTDIR=/some/valid/location` easily. Archives with binaries built by recent iterations of continuous integration jobs should be available for exploration on the respective CI platforms. ====== *Information below may be currently obsolete, but the NUT project wishes it to become actual and factual again :)* NUT binary package built for Windows platform comes in a `.msi` file. If you are using Windows 95, 98 or Me, you should install link:http://www.microsoft.com/downloads/en/details.aspx?familyid=cebbacd8-c094-4255-b702-de3bb768148f&displaylang=en[Windows Installer 2.0] from Microsoft site. If you are using Windows 2000 or NT 4.0, you can link:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=4b6140f9-2d36-4977-8fa1-6f8a0f5dca8f&DisplayLang=en[download it here]. Newer Windows releases should include the Windows Installer natively. Run `NUT-Installer.msi` and follow the wizard indications. If you plan to use an UPS which is locally connected to an USB port, you have to install link:https://sourceforge.net/projects/libusb-win32/files/[libUSB-win32] on your system. Then you must install your device via libusb's "Inf Wizard". NOTE: If you intend to build from source, relevant sources may be available at https://github.com/mcuee/libusb-win32 and keep in mind that it is a variant of libusb-0.1. Current NUT supports libusb-1.0 as well, and that project should have Windows support out of the box (but it was not explored for NUT yet). If you have selected default directory, all configuration files are located in `C:\Program Files\NUT\ups\etc` Building for Windows ^^^^^^^^^^^^^^^^^^^^ For suggestions about setting up the NUT build environment variants for Windows, please see link:docs/config-prereqs.txt and/or link:scripts/Windows/README.adoc files. Note this is rather experimental at this point. If using USB drivers, such as `usbhid-ups`, `nutdrv_qx` or `blazer_usb`, you may benefit from the link:http://zadig.akeo.ie/[Zadig] tool to pin the low-level drivers needed for LibUSB and further NUT to interact with the hardware. Otherwise, OS-provided (e.g. "HID Battery") or third-party drivers may attach and "steal" bytes from the data stream needed by LibUSB rendering it invalid. NOTE: For more details, see link:https://github.com/networkupstools/nut/issues/1690[NUT issue #1690] and the link:https://github.com/networkupstools/nut/wiki/NUT-for-Windows[NUT for Windows] article on NUT GitHub Wiki. Runtime configuration ~~~~~~~~~~~~~~~~~~~~~ You are now ready to configure NUT, and start testing and using it. You can jump directly to the <>. nut-2.8.4/drivers/0000755000175000017500000000000015045366653011027 500000000000000nut-2.8.4/drivers/mge-utalk.c0000644000175000017500000006760015044656702013006 00000000000000/* mge-utalk.c - monitor MGE UPS for NUT with UTalk protocol * * Copyright (C) 2002 - 2005 * Arnaud Quette * Hans Ekkehard Plesser * Martin Loyer * Patrick Agrain * Nicholas Reilly * Dave Abbott * Marek Kralewski * * This driver is a collaborative effort by the above people, * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * IMPLEMENTATION DETAILS * * Not all UTalk models provide all possible information, settings and commands. * mge-utalk checks on startup which variables and commands are available from * the UPS, and re-reads these regularly. Thus, startup is a bit slow, but this * should not matter much. * * mge-utalk.h defines a struct array that tells the driver how to read * variables from the UPS and publish them as NUT data. * * "ups.status" variable is not included in this array, since it contains * information that requires several calls to the UPS and more advanced analysis * of the reponses. The function get_ups_status does this job. * * Note that MGE enumerates the status "bits" from right to left, * i.e., if buf[] contains the reponse to command "Ss" (read system status), * then buf[0] contains "bit" Ss.1.7 (General alarm), while buf[7] contains * "bit" Ss.1.0 (Load unprotected). * * enable_ups_comm() is called before each attempt to read/write data * from/to the UPS to re synchronise the communication. */ #include "config.h" /* must be the first header */ #include #ifndef WIN32 #include #endif /* !WIN32 */ #include "timehead.h" #include "main.h" #include "serial.h" #include "mge-utalk.h" #include "nut_stdint.h" /* --------------------------------------------------------------- */ /* Define "technical" constants */ /* --------------------------------------------------------------- */ #define DRIVER_NAME "MGE UPS SYSTEMS/U-Talk driver" #define DRIVER_VERSION "0.99" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Arnaud Quette \n" \ "Hans Ekkehard Plesser \n" \ "Martin Loyer \n" \ "Patrick Agrain \n" \ "Nicholas Reilly \n" \ "Dave Abbott \n" \ "Marek Kralewski ", DRV_STABLE, { NULL } }; /* delay after sending each char to UPS (in MICROSECONDS) */ #define MGE_CHAR_DELAY 0 /* delay after command, before reading UPS reply (in MICROSECONDS) */ #define MGE_REPLY_DELAY 1000 /* delay after enable_ups_comm */ #define MGE_CONNECT_DELAY 500000 #define MGE_COMMAND_ENDCHAR "\r\n" /* some UPS need \r and \n */ #define MGE_REPLY_ENDCHAR '\r' #define MGE_REPLY_IGNCHAR "\r\n" #define MAXTRIES 10 /* max number of connect tries */ #define BUFFLEN 256 #define SD_RETURN 0 #define SD_STAYOFF 1 static int sdtype = SD_RETURN; static time_t lastpoll; /* Timestamp the last polling */ /* --------------------------------------------------------------- */ /* Structure with information about UPS */ /* --------------------------------------------------------------- */ static struct { int MultTab; int LowBatt; /* percent */ int OnDelay; /* minutes */ int OffDelay; /* seconds */ } mge_ups = { 0, DEFAULT_LOWBATT, DEFAULT_ONDELAY, DEFAULT_OFFDELAY }; /* --------------------------------------------------------------- */ /* Declaration of internal functions */ /* --------------------------------------------------------------- */ static int instcmd(const char *cmdname, const char *extra); static int setvar(const char *varname, const char *val); static void enable_ups_comm(void); static void disable_ups_comm(void); static void extract_info(const char *buf, const mge_info_item_t *mge, char *infostr, size_t infolen); static const char *info_variable_cmd(const char *type); static bool_t info_variable_ok(const char *type); static int get_ups_status(void); static ssize_t mge_command(char *reply, size_t replylen, const char *fmt, ...); /* --------------------------------------------------------------- */ /* UPS Driver Functions */ /* --------------------------------------------------------------- */ void upsdrv_makevartable(void) { char temp[BUFFLEN]; snprintf(temp, sizeof(temp), "Low battery level, in %% (default = %3d)", DEFAULT_LOWBATT); addvar (VAR_VALUE, "LowBatt", temp); snprintf(temp, sizeof(temp), "Delay before startup, in minutes (default = %3d)", DEFAULT_ONDELAY); addvar (VAR_VALUE, "OnDelay", temp); snprintf(temp, sizeof(temp), "Delay before shutdown, in seconds (default = %3d)", DEFAULT_OFFDELAY); addvar (VAR_VALUE, "OffDelay", temp); addvar(VAR_FLAG, "oldmac", "Enable Oldworld Apple Macintosh support"); } /* --------------------------------------------------------------- */ void upsdrv_initups(void) { char buf[BUFFLEN]; #ifndef WIN32 int RTS = TIOCM_RTS; #endif /* !WIN32 */ upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); /* read command line/conf variable that affect comm. */ #ifndef WIN32 if (testvar ("oldmac")) RTS = ~TIOCM_RTS; /* Init serial line */ ioctl(upsfd, TIOCMBIC, &RTS); #else /* WIN32 */ if (testvar ("oldmac")) { EscapeCommFunction(((serial_handler_t *)upsfd)->handle,CLRRTS); } else { EscapeCommFunction(((serial_handler_t *)upsfd)->handle,SETRTS); } #endif /* WIN32 */ enable_ups_comm(); /* Try to set "Low Battery Level" (if supported and given) */ if (getval ("lowbatt")) { mge_ups.LowBatt = atoi (getval ("lowbatt")); /* Set the value in the UPS */ mge_command(buf, sizeof(buf), "Bl %d", mge_ups.LowBatt); if(!strcmp(buf, "OK")) upsdebugx(1, "Low Battery Level set to %d%%", mge_ups.LowBatt); else upsdebugx(1, "initups: Low Battery Level cannot be set"); } /* Try to set "ON delay" (if supported and given) */ if (getval ("ondelay")) { mge_ups.OnDelay = atoi (getval ("ondelay")); /* Set the value in the UPS */ mge_command(buf, sizeof(buf), "Sm %d", mge_ups.OnDelay); if(!strcmp(buf, "OK")) upsdebugx(1, "ON delay set to %d min", mge_ups.OnDelay); else upsdebugx(1, "initups: OnDelay unavailable"); } /* Try to set "OFF delay" (if supported and given) */ if (getval ("offdelay")) { mge_ups.OffDelay = atoi (getval ("offdelay")); /* Set the value in the UPS */ mge_command(buf, sizeof(buf), "Sn %d", mge_ups.OffDelay); if(!strcmp(buf, "OK")) upsdebugx(1, "OFF delay set to %d sec", mge_ups.OffDelay); else upsdebugx(1, "initups: OffDelay unavailable"); } } /* --------------------------------------------------------------- */ void upsdrv_initinfo(void) { char buf[BUFFLEN]; const char *model = NULL; char *firmware = NULL; char *p; char *v = NULL; /* for parsing Si output, get Version ID */ int table; int tries; int status_ok = 0; ssize_t bytes_rcvd; int si_data1 = 0; int si_data2 = 0; mge_info_item_t *item; models_name_t *model_info; mge_model_info_t *legacy_model; char infostr[32]; ssize_t chars_rcvd; /* manufacturer -------------------------------------------- */ dstate_setinfo("ups.mfr", "MGE UPS SYSTEMS"); /* loop until we have at status */ tries = 0; do { printf("."); /* get model information in ASCII string form: */ bytes_rcvd = mge_command(buf, sizeof(buf), "Si 1"); if(bytes_rcvd > 0 && buf[0] != '?') { dstate_setinfo("ups.id", "%s", buf); /* raw id */ model = buf; p = strrchr(buf, ' '); if ( p != NULL ) { *p = '\0'; firmware = p+1; } if( firmware && strlen(firmware) < 1 ) firmware = NULL; /* no firmware information */ /* Parsing model names table */ for ( model_info = Si1_models_names ; model_info->basename != NULL ; model_info++ ) { if(!strcasecmp(model_info->basename, model)) { model = model_info->finalname; upsdebugx(1, "initinfo: UPS model == >%s<", model); break; } } } else { upsdebugx(1, "initinfo: 'Si 1' unavailable, switching to 'Si' command"); /* get model information, numbered form, : */ bytes_rcvd = mge_command(buf, sizeof(buf), "Si"); if(bytes_rcvd > 0 && buf[0] != '?') { upsdebugx(1, "initinfo: Si == >%s<", buf); printf("\nCAUTION : This is an older model. It may not support too much polling.\nPlease read man mge-utalk and use pollinterval\n"); p = strchr(buf, ' '); if ( p != NULL ) { *p = '\0'; si_data1 = atoi(buf); v = p+1; p = strchr(v, ' '); } if ( p != NULL ) { *p = '\0'; si_data2 = atoi(v); } /* Parsing legacy model table in order to find it */ for ( legacy_model = mge_model ; legacy_model->name != NULL ; legacy_model++ ) { if(legacy_model->Data1 == si_data1 && legacy_model->Data2 == si_data2){ model = legacy_model->name; upsdebugx(1, "initinfo: UPS model == >%s<", model); break; } } if( model == NULL ) printf("No model found by that model and version ID\nPlease contact us with UPS model, name and reminder info\nReminder info : Data1=%i , Data2=%i\n", si_data1, si_data2); } } if ( model ) { upsdebugx(2, "Got model name: %s", model); /* deal with truncated model names */ if (!strncmp(model, "Evolutio", 8)) { dstate_setinfo("ups.model", "Evolution %i", atoi(strchr(model, ' '))); } else { dstate_setinfo("ups.model", "%s", model); } } if (firmware && firmware[0] != '\0') dstate_setinfo("ups.firmware", "%s", firmware); else dstate_setinfo("ups.firmware", "unknown"); /* multiplier table */ /* */ bytes_rcvd = mge_command(buf, sizeof(buf), "Ai"); if (bytes_rcvd > 0 && buf[0] != '?') { p = strchr(buf, ' '); if ( p != NULL ) { table = atoi(p + 1); if ( 0 < table && table < 4 ) mge_ups.MultTab = table; } } /* status --- try only system status, to get the really important * information (OL, OB, LB); all else is added later by updateinfo */ status_ok = get_ups_status(); } while ( (!status_ok) && (tries++ < MAXTRIES) && (exit_flag != 1) ); if ( tries == MAXTRIES && !status_ok ) fatalx(EXIT_FAILURE, "Could not get status from UPS."); if ( mge_ups.MultTab == 0 ) upslogx(LOG_WARNING, "Could not get multiplier table: using raw readings."); /* all other variables ------------------------------------ */ for ( item = mge_info ; item->type != NULL ; item++ ) { /* Check if we are asked to stop (reactivity++) */ if (exit_flag != 0) return; /* send request, read answer */ chars_rcvd = mge_command(buf, sizeof(buf), item->cmd); if ( chars_rcvd < 1 || buf[0] == '?' ) { item->ok = FALSE; upsdebugx(1, "initinfo: %s unavailable", item->type); } else { item->ok = TRUE; extract_info(buf, item, infostr, sizeof(infostr)); dstate_setinfo(item->type, "%s", infostr); dstate_setflags(item->type, item->flags); upsdebugx(1, "initinfo: %s == >%s<", item->type, infostr); /* Set max length for strings */ if (item->flags & ST_FLAG_STRING) dstate_setaux(item->type, item->length); } } /* for item */ /* store timestamp */ lastpoll = time(NULL); /* commands ----------------------------------------------- */ /* FIXME: check if available before adding! */ dstate_addcmd("load.off"); dstate_addcmd("load.on"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); dstate_addcmd("test.panel.start"); dstate_addcmd("test.battery.start"); dstate_addcmd("bypass.start"); dstate_addcmd("bypass.stop"); /* install handlers */ upsh.setvar = setvar; upsh.instcmd = instcmd; printf("Detected %s on %s\n", dstate_getinfo("ups.model"), device_path); } /* --------------------------------------------------------------- */ void upsdrv_updateinfo(void) { char buf[BUFFLEN]; char infostr[32]; int status_ok; ssize_t bytes_rcvd; mge_info_item_t *item; /* make sure that communication is enabled */ enable_ups_comm(); /* update status */ status_ok = get_ups_status(); /* only sys status is critical */ if ( !status_ok ) { upslogx(LOG_NOTICE, "updateinfo: Cannot update system status"); /* try to re enable communication */ disable_ups_comm(); enable_ups_comm(); } else { dstate_dataok(); } /* Don't overload old units (at startup) */ if ( time(NULL) <= (lastpoll + poll_interval) ) return; /* update all other ok variables */ for ( item = mge_info ; item->type != NULL ; item++ ) { /* Check if we are asked to stop (reactivity++) */ if (exit_flag != 0) return; if ( item->ok ) { /* send request, read answer */ bytes_rcvd = mge_command(buf, sizeof(buf), item->cmd); if ( bytes_rcvd > 0 && buf[0] != '?' ) { extract_info(buf, item, infostr, sizeof(infostr)); dstate_setinfo(item->type, "%s", infostr); upsdebugx(2, "updateinfo: %s == >%s<", item->type, infostr); dstate_dataok(); } else { upslogx(LOG_NOTICE, "updateinfo: Cannot update %s", item->type); /* try to re enable communication */ disable_ups_comm(); enable_ups_comm(); } } /* if item->ok */ } /* store timestamp */ lastpoll = time(NULL); } /* --------------------------------------------------------------- */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ char buf[BUFFLEN]; /* static time_t lastcmd = 0; */ /* We can enter this method either by handling of INSTCMD (whether it * was called by user, or by ourselves here via loop method), or by * handling of `drivername -k`. Avoid infinite loops with this flag * here and with handling_instcmd_shutdown above. */ static char already_shutting_down = 0; if (already_shutting_down) return; already_shutting_down = 1; /* Here we are if handling explicit INSTCMD to shut down, * or this method was called and works to handle default * "sdcommands", or is recursively called with a custom * value of "sdcommands" pointing here. */ memset(buf, 0, sizeof(buf)); if (sdtype == SD_RETURN) { /* enable automatic restart */ mge_command(buf, sizeof(buf), "Sx 5"); upslogx(LOG_INFO, "UPS response to Automatic Restart was %s", buf); } /* Only call the effective shutoff if restart is ok, * or if we need (caller asked for) only a stayoff... */ if (!strcmp(buf, "OK") || (sdtype == SD_STAYOFF)) { /* shutdown UPS */ mge_command(buf, sizeof(buf), "Sx 0"); upslogx(LOG_INFO, "UPS response to Shutdown was %s", buf); } /* if(strcmp(buf, "OK")) */ if (handling_upsdrv_shutdown > 0) { /* call the cleanup to disable/close the comm link */ upsdrv_cleanup(); } else { /* Reset the flags if driver is not going down */ already_shutting_down = 0; } } /* --------------------------------------------------------------- */ void upsdrv_help(void) { } /* --------------------------------------------------------------- */ /* Internal Functions */ /* --------------------------------------------------------------- */ /* handler for commands to be sent to UPS */ int instcmd(const char *cmdname, const char *extra) { char temp[BUFFLEN]; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); /* Start battery test */ if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); mge_command(temp, sizeof(temp), "Bx 1"); upsdebugx(2, "UPS response to %s was %s", cmdname, temp); if(strcmp(temp, "OK")) return STAT_INSTCMD_UNKNOWN; else return STAT_INSTCMD_HANDLED; } /* Start front panel test */ if (!strcasecmp(cmdname, "test.panel.start")) { mge_command(temp, sizeof(temp), "Sx 129"); upsdebugx(2, "UPS response to %s was %s", cmdname, temp); if(strcmp(temp, "OK")) return STAT_INSTCMD_UNKNOWN; else return STAT_INSTCMD_HANDLED; } /* Shutdown UPS */ if (!strcasecmp(cmdname, "shutdown.stayoff")) { sdtype = SD_STAYOFF; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); upsdrv_shutdown(); } if (!strcasecmp(cmdname, "shutdown.return")) { sdtype = SD_RETURN; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); upsdrv_shutdown(); } /* Power Off [all] plugs */ if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* TODO: Powershare (per plug) control */ mge_command(temp, sizeof(temp), "Wy 65535"); upsdebugx(2, "UPS response to Select All Plugs was %s", temp); if(strcmp(temp, "OK")) return STAT_INSTCMD_UNKNOWN; else { mge_command(temp, sizeof(temp), "Wx 0"); upsdebugx(2, "UPS response to %s was %s", cmdname, temp); if(strcmp(temp, "OK")) return STAT_INSTCMD_UNKNOWN; else return STAT_INSTCMD_HANDLED; } } /* Power On all plugs */ if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); /* TODO: add per plug control */ mge_command(temp, sizeof(temp), "Wy 65535"); upsdebugx(2, "UPS response to Select All Plugs was %s", temp); if(strcmp(temp, "OK")) return STAT_INSTCMD_UNKNOWN; else { mge_command(temp, sizeof(temp), "Wx 1"); upsdebugx(2, "UPS response to %s was %s", cmdname, temp); if(strcmp(temp, "OK")) return STAT_INSTCMD_UNKNOWN; else return STAT_INSTCMD_HANDLED; } } /* Switch on/off Maintenance Bypass */ if ((!strcasecmp(cmdname, "bypass.start")) || (!strcasecmp(cmdname, "bypass.stop"))) { /* TODO: add control on bypass value */ /* read maintenance bypass status */ upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if(mge_command(temp, sizeof(temp), "Ps") > 0) { if (temp[0] == '1') { /* Disable Maintenance Bypass */ mge_command(temp, sizeof(temp), "Px 2"); upsdebugx(2, "UPS response to Select All Plugs was %s", temp); } else { /* Enable Maintenance Bypass */ mge_command(temp, sizeof(temp), "Px 3"); } upsdebugx(2, "UPS response to %s was %s", cmdname, temp); if(strcmp(temp, "OK")) return STAT_INSTCMD_UNKNOWN; else return STAT_INSTCMD_HANDLED; } } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } /* --------------------------------------------------------------- */ /* handler for settable variables in UPS*/ int setvar(const char *varname, const char *val) { char temp[BUFFLEN]; char cmd[15]; upsdebug_SET_STARTING(varname, val); /* TODO : add some controls */ if(info_variable_ok(varname)) { /* format command */ snprintf(cmd, sizeof(cmd), "%s", info_variable_cmd(varname)); sprintf(strchr(cmd, '?'), "%s", val); /* Execute command */ mge_command(temp, sizeof(temp), cmd); upslogx(LOG_INFO, "setvar: UPS response to Set %s to %s was %s", varname, val, temp); return STAT_SET_HANDLED; } upsdebugx(1, "setvar: Variable %s not supported by UPS", varname); upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } /* --------------------------------------------------------------- */ /* disable communication with UPS to avoid interference with * kernel serial init at boot time (ie with V24 init) */ static void disable_ups_comm(void) { upsdebugx(1, "disable_ups_comm()"); ser_flush_in(upsfd, "?\r\n", 0); usleep(MGE_CONNECT_DELAY); mge_command(NULL, 0, "Ax 0"); } /* enable communication with UPS */ static void enable_ups_comm(void) { char buf[8]; /* send Z twice --- speeds up re-connect */ mge_command(NULL, 0, "Z"); mge_command(NULL, 0, "Z"); /* only enable communication if needed! */ if ( mge_command(buf, 8, "Si") <= 0) { mge_command(NULL, 0, "Ax 1"); usleep(MGE_CONNECT_DELAY); } ser_flush_in(upsfd, "?\r\n", nut_debug_level); } /* --------------------------------------------------------------- */ /* extract information from buffer in: buf : reply from UPS item : INFO item queried out: infostr: to be placed in INFO_ variable NOTE: buf="?" must be handled before calling extract_info buf is changed inspite of const !!!!! */ static void extract_info(const char *buf, const mge_info_item_t *item, char *infostr, size_t infolen) { /* initialize info string */ infostr[0] = '\0'; #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used locally with * fixed strings from the mge_info[] mapping table */ /* write into infostr with proper formatting */ if ( strpbrk(item->fmt, "feEgG") ) { /* float */ snprintf(infostr, infolen, item->fmt, multiplier[mge_ups.MultTab][item->unit] * atof(buf)); } else if ( strpbrk(item->fmt, "dioxXuc") ) { /* int */ snprintf(infostr, infolen, item->fmt, (int) (multiplier[mge_ups.MultTab][item->unit] * atof(buf))); } else { snprintf(infostr, infolen, item->fmt, buf); } #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif } /* --------------------------------------------------------------- */ /* get system status, at least: OB, OL, LB calls set_status appropriately tries MAXTRIES times returns non-nil if successful NOTE: MGE counts bytes/chars the opposite way as C, see mge-utalk manpage. If status commands send two data items, these are separated by a space, so the elements of the second item are in buf[16..9]. */ static int get_ups_status(void) { char buf[BUFFLEN]; int rb_set= FALSE; /* has RB flag been set ? */ int over_set= FALSE; /* has OVER flag been set ? */ int tries = 0; int ok = FALSE; ssize_t bytes_rcvd = 0; do { /* Check if we are asked to stop (reactivity++) */ if (exit_flag != 0) return FALSE; /* must clear alarm and status buffers before each round */ alarm_init(); status_init(); /* system status */ /* FIXME: some old units sometimes return "Syst Stat >1<" resulting in an temporary OB status */ bytes_rcvd = mge_command(buf, sizeof(buf), "Ss"); upsdebugx(1, "Syst Stat >%s<", buf); if ( bytes_rcvd > 0 && strlen(buf) > 7 ) { ok = TRUE; if (buf[6] == '1') { over_set = TRUE; status_set("OVER"); } if (buf[5] == '1') status_set("OB"); else status_set("OL"); if (buf[4] == '1') status_set("LB"); if (buf[3] == '1') { rb_set = TRUE; status_set("RB"); } /* buf[2] not used */ if (buf[1] == '1') alarm_set("COMMFAULT"); /* self-invented */ /* FIXME: better to call datastale()?! */ if (buf[0] == '1') alarm_set("DEVICEALARM"); /* self-invented */ } /* if strlen */ /* battery status */ mge_command(buf, sizeof(buf), "Bs"); upsdebugx(1, "Batt Stat >%s<", buf); if ( strlen(buf) > 7 ) { if ( !rb_set && ( buf[7] == '1' || buf[3] == '1' ) ) status_set("RB"); if (buf[1] == '1') status_set("CHRG"); if (buf[0] == '1') status_set("DISCHRG"); } /* if strlen */ /* load status */ mge_command(buf, sizeof(buf), "Ls"); upsdebugx(1, "Load Stat >%s<", buf); if ( strlen(buf) > 7 ) { if (buf[4] == '1') status_set("BOOST"); if ( !over_set && ( buf[3] == '1' ) ) status_set("OVER"); if (buf[2] == '1') status_set("TRIM"); } /* if strlen */ if ( strlen(buf) > 15 ) { /* second "byte", skip */ if (buf[16] == '1') { status_set("OB"); status_set("LB"); } /* FIXME: to be checked (MUST be buf[8]) !! */ /* if ( !(buf[9] == '1') ) */ /* This is not the OFF status! if ( !(buf[8] == '1') ) status_set("OFF"); */ } /* if strlen */ /* Bypass status */ mge_command(buf, sizeof(buf), "Ps"); upsdebugx(1, "Bypass Stat >%s<", buf); if ( strlen(buf) > 7 ) { /* FIXME: extend ups.status for BYPASS: */ /* Manual Bypass */ if (buf[7] == '1') status_set("BYPASS"); /* Automatic Bypass */ if (buf[6] == '1') status_set("BYPASS"); } /* if strlen */ } while ( !ok && tries++ < MAXTRIES ); alarm_commit(); status_commit(); return ok; } /* --------------------------------------------------------------- */ /* return proper variable "ok" given INFO_ type */ static bool_t info_variable_ok(const char *type) { mge_info_item_t *item = mge_info ; while ( strcasecmp(item->type, type )) item++; return item->ok; } /* --------------------------------------------------------------- */ /* return proper variable "cmd" given INFO_ type */ static const char *info_variable_cmd(const char *type) { mge_info_item_t *item = mge_info ; while ( strcasecmp(item->type, type )) item++; return item->cmd; } /* --------------------------------------------------------------- */ /* send command to UPS and read reply if requested reply : buffer for reply, NULL if no reply expected replylen: length of buffer reply fmt : format string, followed by optional data for command returns : no of chars received, -1 if error */ static ssize_t mge_command(char *reply, size_t replylen, const char *fmt, ...) { const char *p; char command[BUFFLEN]; ssize_t bytes_sent = 0; ssize_t bytes_rcvd = 0; int ret; va_list ap; /* build command string */ va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used locally with * fixed strings (and args) quite intensively */ ret = vsnprintf(command, sizeof(command), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif if ((ret < 1) || (ret >= (int) sizeof(command))) upsdebugx(4, "mge_command: command truncated"); va_end(ap); /* Delay a bit to avoid overlap of a previous answer (500 ms), as per * http://old.networkupstools.org/protocols/mge/9261zwfa.pdf § 6.1. Timings */ usleep(500000); /* flush received, unread data */ tcflush(upsfd, TCIFLUSH); /* send command */ for (p = command; *p; p++) { if ( isprint((unsigned char)*p & 0xFF) ) upsdebugx(4, "mge_command: sending [%c]", *p); else upsdebugx(4, "mge_command: sending [%02X]", *p); if (write(upsfd, p, 1) != 1) return -1; bytes_sent++; usleep(MGE_CHAR_DELAY); } /* send terminating string */ for (p = MGE_COMMAND_ENDCHAR; *p; p++) { if ( isprint((unsigned char)*p & 0xFF) ) upsdebugx(4, "mge_command: sending [%c]", *p); else upsdebugx(4, "mge_command: sending [%02X]", *p); if (write(upsfd, p, 1) != 1) return -1; bytes_sent++; usleep(MGE_CHAR_DELAY); } if ( !reply ) return bytes_rcvd; else usleep(MGE_REPLY_DELAY); bytes_rcvd = ser_get_line(upsfd, reply, replylen, MGE_REPLY_ENDCHAR, MGE_REPLY_IGNCHAR, 3, 0); upsdebugx(4, "mge_command: sent %" PRIiSIZE ", received %" PRIiSIZE " byte(s)", bytes_sent, bytes_rcvd); return bytes_rcvd; } void upsdrv_cleanup(void) { upsdebugx(1, "cleaning up"); disable_ups_comm(); ser_close(upsfd, device_path); } nut-2.8.4/drivers/everups.c0000644000175000017500000001272315044656702012605 00000000000000/* everups.c - support for Ever UPS models (serial) Copyright (C) 2001 Bartek Szady This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "serial.h" #define DRIVER_NAME "Ever UPS driver (serial)" #define DRIVER_VERSION "0.08" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Bartek Szady ", DRV_STABLE, { NULL } }; static unsigned char upstype = 0; /* Forward decls */ static int instcmd(const char *cmdname, const char *extra); static void init_serial(void) { ser_set_dtr(upsfd, 0); ser_set_rts(upsfd, 0); } static int Code(int tries) { unsigned char cRecv; do { ser_send_char(upsfd, 208); ser_get_char(upsfd, &cRecv, 3, 0); if (cRecv==208) return 1; } while (--tries>0); return 0; } static int InitUpsType(void) { if (Code(1)) { ser_send_char(upsfd, 173); ser_get_char(upsfd, &upstype, 3, 0); return 1; } else return 0; } static const char *GetTypeUpsName(void) { switch(upstype) { case 67: return "NET 500-DPC"; case 68: return "NET 700-DPC"; case 69: return "NET 1000-DPC"; case 70: return "NET 1400-DPC"; case 71: return "NET 2200-DPC"; case 73: return "NET 700-DPC (new)"; case 74: return "NET 1000-DPC (new)"; case 75: return "NET 1400-DPC (new)"; case 76: return "NET 500-DPC (new)"; case 81: return "AP 450-PRO"; case 82: return "AP 650-PRO"; default: return "Unknown"; } } void upsdrv_initinfo(void) { dstate_setinfo("ups.mfr", "Ever"); dstate_setinfo("ups.model", "%s", GetTypeUpsName()); /* commands ----------------------------------------------- */ /* FIXME: Check with the device what our instcmd * (nee upsdrv_shutdown() contents) actually does! */ dstate_addcmd("load.off"); /* install handlers */ upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { int battery=0,standby=0; unsigned char recBuf[2]; unsigned long acuV; unsigned long lineV; double fVal; if (!Code(2)) { upslog_with_errno(LOG_INFO, "Code failed"); dstate_datastale(); return; } /*Line status*/ ser_send_char(upsfd, 175); ser_get_char(upsfd, recBuf, 3, 0); if ((recBuf[0] & 1) !=0) standby=1; else battery=(recBuf[0] &4) !=0; if (Code(1)) { /*Accumulator voltage value*/ ser_send_char(upsfd, 189); ser_get_char(upsfd, recBuf, 3, 0); acuV=((unsigned long)recBuf[0])*150; acuV/=255; } else { upslog_with_errno(LOG_INFO, "Code failed"); dstate_datastale(); return; } if (Code(1)) { /*Line voltage*/ ser_send_char(upsfd, 245); ser_get_buf_len(upsfd, recBuf, 2, 3, 0); if ( upstype > 72 && upstype < 77) lineV=(recBuf[0]*100+recBuf[1]*25600)/352; else lineV=(recBuf[0]*100+recBuf[1]*25600)/372; } else { upslog_with_errno(LOG_INFO, "Code failed"); dstate_datastale(); return; } status_init(); if (battery && acuV<105) status_set("LB"); /* low battery */ if (battery) status_set("OB"); /* on battery */ else status_set("OL"); /* on line */ status_commit(); dstate_setinfo("input.voltage", "%03lu", lineV); dstate_setinfo("battery.voltage", "%03.2f", (double)acuV /10.0); fVal=((double)acuV-95.0)*100.0; if (standby) fVal/=(135.5-95.0); else fVal/=(124.5-95.0); if (fVal>100) fVal=100; else if (fVal<0) fVal=0; dstate_setinfo("battery.charge", "%03.1f", fVal); dstate_dataok(); } /* handler for commands to be sent to UPS */ static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); /* FIXME: Which one is this - "load.off", * "shutdown.stayoff" or "shutdown.return"? */ /* Shutdown UPS */ if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if (!Code(2)) { upslog_with_errno(LOG_INSTCMD_UNKNOWN, "Code failed"); return STAT_INSTCMD_UNKNOWN; } ser_send_char(upsfd, 28); ser_send_char(upsfd, 1); /* 1.28 sec */ if (!Code(1)) { upslog_with_errno(LOG_INSTCMD_UNKNOWN, "Code failed"); return STAT_INSTCMD_UNKNOWN; } ser_send_char(upsfd, 13); ser_send_char(upsfd, 8); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = do_loop_shutdown_commands("load.off", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B300); init_serial(); InitUpsType(); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/serial.h0000644000175000017500000000760315000736161012367 00000000000000#ifndef SERIAL_H_SEEN #define SERIAL_H_SEEN 1 /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif #include "attribute.h" #include "common.h" /* for TYPE_FD_SER, possibly fallback suseconds_t */ #ifndef WIN32 # if defined(HAVE_SYS_TERMIOS_H) # include /* for speed_t */ # else # include # endif /* HAVE_SYS_TERMIOS_H */ #else /* WIN32 */ # include "wincompat.h" #endif /* WIN32 */ #include /* for usleep() and useconds_t, latter also might be via */ #include #if defined(HAVE_SYS_SELECT_H) #include /* for suseconds_t */ #endif /* limit the amount of spew that goes in the syslog when we lose the UPS */ #define SER_ERR_LIMIT 10 /* start limiting after 10 in a row */ #define SER_ERR_RATE 100 /* then only print every 100th error */ /* porting stuff for WIN32 */ #ifdef WIN32 /* TODO : support "open" flags */ # define O_NONBLOCK 0 # define O_NOCTTY 0 /* Builds on Windows MSYS2 environment did not recognize this macro: */ # ifndef TIOCM_ST # define TIOCM_ST 0x008 # endif #endif /* WIN32 */ TYPE_FD_SER ser_open_nf(const char *port); TYPE_FD_SER ser_open(const char *port); int ser_set_speed(TYPE_FD_SER fd, const char *port, speed_t speed); int ser_set_speed_nf(TYPE_FD_SER fd, const char *port, speed_t speed); /* set the state of modem control lines */ int ser_set_dtr(TYPE_FD_SER fd, int state); int ser_set_rts(TYPE_FD_SER fd, int state); /* get the status of modem control lines */ int ser_get_dsr(TYPE_FD_SER fd); int ser_get_cts(TYPE_FD_SER fd); int ser_get_dcd(TYPE_FD_SER fd); int ser_close(TYPE_FD_SER fd, const char *port); ssize_t ser_send_char(TYPE_FD_SER fd, unsigned char ch); /* send the results of the format string with d_usec delay after each char */ ssize_t ser_send_pace(TYPE_FD_SER fd, useconds_t d_usec, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); /* send the results of the format string with no delay */ ssize_t ser_send(TYPE_FD_SER fd, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); /* send buflen bytes from buf with no delay */ ssize_t ser_send_buf(TYPE_FD_SER fd, const void *buf, size_t buflen); /* send buflen bytes from buf with d_usec delay after each char */ ssize_t ser_send_buf_pace(TYPE_FD_SER fd, useconds_t d_usec, const void *buf, size_t buflen); ssize_t ser_get_char(TYPE_FD_SER fd, void *ch, time_t d_sec, useconds_t d_usec); ssize_t ser_get_buf(TYPE_FD_SER fd, void *buf, size_t buflen, time_t d_sec, useconds_t d_usec); /* keep reading until buflen bytes are received or a timeout occurs */ ssize_t ser_get_buf_len(TYPE_FD_SER fd, void *buf, size_t buflen, time_t d_sec, useconds_t d_usec); /* reads a line up to , discarding anything else that may follow, with callouts to the handler if anything matches the alertset */ ssize_t ser_get_line_alert(TYPE_FD_SER fd, void *buf, size_t buflen, char endchar, const char *ignset, const char *alertset, void handler (char ch), time_t d_sec, useconds_t d_usec); /* as above, only with no alertset handling (just a wrapper) */ ssize_t ser_get_line(TYPE_FD_SER fd, void *buf, size_t buflen, char endchar, const char *ignset, time_t d_sec, useconds_t d_usec); ssize_t ser_flush_in(TYPE_FD_SER fd, const char *ignset, int verbose); int ser_flush_io(TYPE_FD_SER fd); /* unified failure reporting: call these often */ void ser_comm_fail(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2))); void ser_comm_good(void); #ifdef WIN32 #define open(a,b) w32_serial_open(a,b) #define close(a) w32_serial_close(a) #define read(a,b,c) w32_serial_read(a,b,c,INFINITE) #define write(a,b,c) w32_serial_write(a,b,c) #endif /* WIN32 */ #endif /* SERIAL_H_SEEN */ nut-2.8.4/drivers/riello.c0000664000175000017500000006053715000733176012403 00000000000000/* * riello.c: driver core for Riello protocol based UPSes * * Documents describing the protocol implemented by this driver can be * found online at: * * https://www.networkupstools.org/protocols/riello/PSGPSER-0104.pdf * https://www.networkupstools.org/protocols/riello/PSSENTR-0100.pdf * * Copyright (C) 2012 - Elio Parisi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Reference of the derivative work: blazer driver */ #include "config.h" /* must be the first header */ #include "common.h" /* for upsdebugx() etc */ #include #include "main.h" #include "riello.h" static uint8_t foundheader = 0; uint16_t buf_ptr_length; uint8_t wait_packet = 0; uint8_t foundnak = 0; uint8_t foundbadcrc = 0; uint8_t commbyte; uint8_t requestSENTR; static unsigned char LAST_DATA[6]; uint16_t riello_calc_CRC(uint8_t type, uint8_t *buff, uint16_t size, uint8_t checksum) { uint16_t i; uint16_t pom, CRC_Word; CRC_Word = 0; switch (type) { case DEV_RIELLOSENTRY: CRC_Word = 0; if (size == 101) { for (i=0; i<100; i++) CRC_Word += buff[i]; } else { for (i=0; i> 4); CRC_Word = (CRC_Word >> 8) ^ pom; buff++; } } else { CRC_Word = 0; for (i=1; iIdentification, &buffer[7], 16); data->Identification[16] = 0; memcpy(data->ModelStr, &buffer[23], 16); data->ModelStr[16] = 0; data->ModelStr[15] = 0; memcpy(data->Version, &buffer[39], 12); data->Version[12] = 0; memcpy(data->Identif_bytes, &buffer[51], 12); data->Identif_bytes[11] = 0; data->NumBat = data->Identif_bytes[7] - 0x30; } void riello_parse_gn(uint8_t* buffer, TRielloData* data) { uint16_t pom_word; uint32_t pom_long; uint8_t j; j = 7; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); if (data->Identif_bytes[0] != '1') pom_long/=100; assert (pom_long < UINT16_MAX); data->NomPowerKVA = (uint16_t)pom_long; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); if (data->Identif_bytes[0] != '1') pom_long/=100; assert (pom_long < UINT16_MAX); data->NomPowerKW = (uint16_t)pom_long; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->NomUbat = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->NomBatCap = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->NominalUout = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->NomFout = pom_word; } void riello_parse_rs(uint8_t* buffer, TRielloData* data, uint8_t numread) { uint16_t pom_word; uint8_t j; j = 7; memcpy(data->StatusCode, &buffer[j], 5); data->StatusCode[5] = 0; data->Boost = riello_test_bit(&buffer[j], 9); data->Buck = riello_test_bit(&buffer[j], 8); data->LockUPS = riello_test_bit(&buffer[j], 2); j+=5; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Finp = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Uinp1 = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); if (!riello_test_bit(&data->StatusCode[0], 3)) pom_word = 0; data->Fout = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Uout1 = pom_word; pom_word = (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Pout1 = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Fbypass = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Ubypass1 = pom_word; pom_word = (buffer[j++]-0x30)*4096; pom_word += (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Ubat = pom_word; pom_word = (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->BatCap = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->BatTime = pom_word; if (data->BatTime == 0xfff) data->BatTime = 0xffff; pom_word = (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Tsystem = pom_word; if (numread > 42) { pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Uinp2 = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Uinp3 = pom_word; } else { data->Uinp2 = 0; data->Uinp3 = 0; } if (numread > 48) { pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Uout2 = pom_word; pom_word = (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Pout2 = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Ubypass2 = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Uout3 = pom_word; pom_word = (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Pout3 = pom_word; pom_word = (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Ubypass3 = pom_word; } else { data->Uout2 = 0; data->Pout2 = 0; data->Ubypass2 = 0; data->Uout3 = 0; data->Pout3 = 0; data->Ubypass3 = 0; } } void riello_parse_re(uint8_t* buffer, TRielloData* data) { uint16_t pom_word; uint32_t pom_long; uint8_t j; j = 23; data->Iinp1 = 0xFFFF; data->Iinp2 = 0xFFFF; data->Iinp3 = 0xFFFF; pom_word = (buffer[j++]-0x30)*4096; pom_word += (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Iout1 = pom_word; pom_word = (buffer[j++]-0x30)*4096; pom_word += (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Iout2 = pom_word; pom_word = (buffer[j++]-0x30)*4096; pom_word += (buffer[j++]-0x30)*256; pom_word += (buffer[j++]-0x30)*16; pom_word += (buffer[j++]-0x30); data->Iout3 = pom_word; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); data->Pout1W = pom_long; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); data->Pout2W = pom_long; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); data->Pout3W = pom_long; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); data->Pout1VA = pom_long; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); data->Pout2VA = pom_long; pom_long = (buffer[j++]-0x30)*65536; pom_long += (buffer[j++]-0x30)*4096; pom_long += (buffer[j++]-0x30)*256; pom_long += (buffer[j++]-0x30)*16; pom_long += (buffer[j++]-0x30); data->Pout3VA = pom_long; } void riello_parse_rc(uint8_t* buffer, TRielloData* data) { uint8_t j, i; j = 7; for (i = 0; i < 22; i++, j+=2) { data->StatusCodeT[i] = (char)(buffer[j+1]-0x30); data->StatusCodeT[i] |= ((buffer[j]-0x30) << 4); } data->StatusCodeT[23] = 0; data->StatusCodeT[24] = 0; } void riello_parse_sentr(uint8_t* buffer, TRielloData* data) { uint32_t pom; data->Model = buffer[2]+256*buffer[3]; if (data->Model < 3000) { if ((data->Model % 10) >= 4) { if (buffer[100] & 0x01) requestSENTR = SENTR_EXT176; else requestSENTR = SENTR_ALSO240; } else requestSENTR = SENTR_ONLY192; data->NomPowerKVA = data->Model/10; } else { if (((data->Model-3000) % 10) >= 4) { if (buffer[100] & 0x01) requestSENTR = SENTR_EXT176; else requestSENTR = SENTR_ALSO240; } else requestSENTR = SENTR_ONLY192; data->NomPowerKVA = (data->Model-3000)/10; } if (buffer[76] & 0x08) data->NomPowerKW = ((data->NomPowerKVA * 1000) * 9 / 10) / 1000; else data->NomPowerKW = ((data->NomPowerKVA * 1000) * 8 / 10) / 1000; data->NomPowerKVA *= 1000; data->NomPowerKW *= 1000; if (data->Model < 3000) data->Identif_bytes[0] = '3'; else data->Identif_bytes[0] = '4'; data->Identif_bytes[1] = '3'; data->Identif_bytes[6] = '2'; data->SWversion = buffer[4]+256*buffer[5]; data->Version[0] = (char)(uint8_t)(48 + ((data->SWversion / 1000) % 10)); data->Version[1] = (char)(uint8_t)(48 + ((data->SWversion / 100) % 10)); data->Version[2] = '.'; data->Version[3] = (char)(uint8_t)(48 + ((data->SWversion / 10) % 10)); data->Version[4] = (char)(uint8_t)(48 + (data->SWversion % 10)); if (data->Model < 3000) pom = data->Model*100; else pom = (data->Model-3000)*100; if (buffer[0] == SENTR_EXT176) { data->Uinp1 = (buffer[117]+buffer[118]*256)/10; data->Uinp2 = (buffer[119]+buffer[120]*256)/10; data->Uinp3 = (buffer[121]+buffer[122]*256)/10; data->Iinp1 = (buffer[123]+buffer[124]*256)/10; data->Iinp2 = (buffer[125]+buffer[126]*256)/10; data->Iinp3 = (buffer[127]+buffer[128]*256)/10; data->Finp = buffer[41]+256*buffer[42]; data->Uout1 = (buffer[135]+buffer[136]*256)/10; data->Uout2 = (buffer[137]+buffer[138]*256)/10; data->Uout3 = (buffer[139]+buffer[140]*256)/10; data->Iout1 = (buffer[141]+buffer[142]*256)/10; data->Iout2 = (buffer[143]+buffer[144]*256)/10; data->Iout3 = (buffer[145]+buffer[146]*256)/10; data->Pout1 = buffer[62]; data->Pout2 = buffer[63]; data->Pout3 = buffer[64]; data->Ipout1 = buffer[65]*3; } else { data->Uinp1 = buffer[35]*230/100; data->Uinp2 = buffer[36]*230/100; data->Uinp3 = buffer[37]*230/100; /* TODO: Range-check the casts to uint16_t? */ data->Iinp1 = (uint16_t)(((pom/690)*buffer[38])/100); data->Iinp2 = (uint16_t)(((pom/690)*buffer[39])/100); data->Iinp3 = (uint16_t)(((pom/690)*buffer[40])/100); data->Finp = buffer[41]+256*buffer[42]; if (buffer[79] & 0x80) { data->Uout1 = buffer[59]*2; data->Uout2 = buffer[60]*2; data->Uout3 = buffer[61]*2; } else { data->Uout1 = buffer[59]; data->Uout2 = buffer[60]; data->Uout3 = buffer[61]; } if (buffer[73]) { /* FIXME: Wondering how the addition below works for uint8_t[] buffer... */ /* TODO: Range-check the casts to uint16_t? */ if (buffer[73] < 100) buffer[73]+=256; if (data->Model < 3000) /* singlephase */ data->Iout1 = (uint16_t)(((pom/buffer[73])*buffer[62])/100); else data->Iout1 = (uint16_t)(((pom/buffer[73])*buffer[62])/100/3); data->Iout2 = (uint16_t)(((pom/buffer[73])*buffer[63])/100/3); data->Iout3 = (uint16_t)(((pom/buffer[73])*buffer[64])/100/3); } else { data->Iout1 = 0; data->Iout2 = 0; data->Iout3 = 0; } if ((data->Model & 0x0007) < 4) { data->Iout1 *= 0.9; data->Iout2 *= 0.9; data->Iout3 *= 0.9; } data->Pout1 = buffer[62]; data->Pout2 = buffer[63]; data->Pout3 = buffer[64]; data->Ipout1 = buffer[65]*3; } if (data->Model < 3000) { data->Ipout2 = 0; data->Ipout3 = 0; } else { data->Ipout2 = buffer[66]*3; data->Ipout3 = buffer[67]*3; } data->Fout = buffer[68]+256*buffer[69]; data->BatTime = buffer[6]+256*buffer[7]; data->BatCap = buffer[8]; if ((buffer[0] == SENTR_ALSO240) || (buffer[0] == SENTR_EXT176)) { if (buffer[100] & 0x80) data->Ubat = buffer[43]+256*buffer[44]; else { if (buffer[44] < buffer[43]) data->Ubat = buffer[44]*2; else data->Ubat = buffer[43]*2; } } else data->Ubat = buffer[43]+256*buffer[44]; data->Ubat *= 10; data->Ibat = buffer[45]+256*buffer[46]; if (!buffer[47]) data->Ibat = data->Ibat*10; data->Tsystem = buffer[48]; data->NomBatCap = buffer[74]+256*buffer[75]; switch (buffer[0]) { case SENTR_EXT176: data->Ubypass1 = (buffer[129]+buffer[130]*256)/10; data->Ubypass2 = (buffer[131]+buffer[132]*256)/10; data->Ubypass3 = (buffer[133]+buffer[134]*256)/10; data->Fbypass = buffer[57]+256*buffer[58]; break; case SENTR_ALSO240: data->Ubypass1 = buffer[51]*2; data->Ubypass2 = buffer[53]*2; data->Ubypass3 = buffer[55]*2; data->Fbypass = buffer[57]+256*buffer[58]; break; default: data->Ubypass1 = buffer[51]+256*buffer[52]; data->Ubypass2 = buffer[53]+256*buffer[54]; data->Ubypass3 = buffer[55]+256*buffer[56]; data->Fbypass = buffer[57]+256*buffer[58]; break; } data->StatusCode[0] = 0x08; data->StatusCode[1] = 0x00; data->StatusCode[2] = 0x00; data->StatusCode[3] = 0x00; data->StatusCode[4] = 0x00; /* Overload if (riello_test_bit(&DevData.StatusCode[4], 2)) */ if (buffer[31] & 128) data->StatusCode[4] |= 0x04; /* Bypass if (riello_test_bit(&DevData.StatusCode[1], 3)) */ if (((buffer[31] & 2) || (riello_test_bit(&buffer[32], 0)) || (riello_test_bit(&buffer[32], 12)) || (riello_test_bit(&buffer[32], 13)) || (riello_test_bit(&buffer[32], 14))) && (!(buffer[34] & 8))) data->StatusCode[1] |= 0x08; /* AC Fail if (riello_test_bit(&DevData.StatusCode[0], 1)) */ if (buffer[31] & 8) data->StatusCode[0] |= 0x02; /* LowBatt if ((riello_test_bit(&DevData.StatusCode[0], 1)) && (riello_test_bit(&DevData.StatusCode[0], 0))) */ if (buffer[31] & 16) { if (buffer[31] & 8) { data->StatusCode[0] |= 0x02; data->StatusCode[0] |= 0x01; } } /* Standby if (!riello_test_bit(&DevData.StatusCode[0], 3)) */ if ((buffer[22] & 2) || (buffer[34] & 4) || (buffer[34] & 8)) data->StatusCode[0] &= 0xF7; /* Battery bad (Replace battery) if (riello_test_bit(&DevData.StatusCode[2], 0)) */ if (buffer[31] & 0x40) data->StatusCode[2] |= 0x01; } void riello_init_serial(void) { wait_packet = 1; buf_ptr_length = 0; foundbadcrc = 0; foundnak = 0; } uint8_t riello_header(uint8_t type, uint8_t a, uint8_t* length) { LAST_DATA[0] = LAST_DATA[1]; LAST_DATA[1] = LAST_DATA[2]; LAST_DATA[2] = LAST_DATA[3]; LAST_DATA[3] = LAST_DATA[4]; LAST_DATA[4] = LAST_DATA[5]; LAST_DATA[5] = (uint8_t) a; switch (type) { case DEV_RIELLOSENTRY: if (((LAST_DATA[4]>=192) && (LAST_DATA[5]==103)) || ((LAST_DATA[4]==176) && (LAST_DATA[5]==164))) { *length = LAST_DATA[5]; return(1); } break; case DEV_RIELLOGPSER: if ((buf_ptr_length==0) && (LAST_DATA[5]>0x20) && (LAST_DATA[4]==0x2)) return(1); break; default: break; } return(0); } uint8_t riello_tail(uint8_t type, uint8_t length) { uint8_t number; switch (type) { case DEV_RIELLOSENTRY: number = length; if (buf_ptr_length >= number) return(1); break; case DEV_RIELLOGPSER: if (LAST_DATA[5] == 0x03) return(1); break; default: break; } return(0); } uint8_t riello_test_nak(uint8_t type, uint8_t* buffer) { switch (type) { case DEV_RIELLOGPSER: if (buffer[3] == 0x15) return(1); break; default: break; } return(0); } void riello_parse_serialport(uint8_t typedev, uint8_t* buffer, uint8_t checksum) { static uint8_t actual_char, int_i; static uint8_t length; actual_char = commbyte; if ((riello_header(typedev, actual_char, &length)) && (!foundheader)) { upsdebugx(5,"Header detected: LAST_DATA:%X,%X,%X,%X,%X,%X buf_ptr:%i \n\r", LAST_DATA[0], LAST_DATA[1], LAST_DATA[2], LAST_DATA[3], LAST_DATA[4], LAST_DATA[5], buf_ptr_length); foundheader = 1; buf_ptr_length = 1; memset(buffer, 0, BUFFER_SIZE); buffer[0] = LAST_DATA[4]; } if ((foundheader) && (buf_ptr_length < BUFFER_SIZE)) buffer[buf_ptr_length++] = actual_char; if ((foundheader) && (riello_tail(typedev, length))) { upsdebugx(5,"\n\rEnd detected: LAST_DATA:%X,%X,%X,%X,%X,%X buf_ptr:%i \n\r", LAST_DATA[0], LAST_DATA[1], LAST_DATA[2], LAST_DATA[3], LAST_DATA[4], LAST_DATA[5], buf_ptr_length); foundheader = 0; for (int_i=0; int_i<6; int_i++) LAST_DATA[int_i] = 0; if (riello_test_nak(typedev, buffer)) { wait_packet = 0; foundnak = 1; } if (riello_test_crc(typedev, buffer, buf_ptr_length, checksum)) { wait_packet = 0; foundbadcrc = 1; } else { wait_packet = 0; foundbadcrc = 0; } } } nut-2.8.4/drivers/snmp-ups-helpers.c0000644000175000017500000000722715044656702014341 00000000000000/* snmp-ups-helpers.c - Shared helper functions and data mapping tables * for NUT Generic SNMP driver core * * Copyright (C) * 2015 - 2021 Eaton (author: Arnaud Quette ) * 2016 - 2021 Eaton (author: Jim Klimov ) * * Sponsored by Eaton * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* NUT SNMP common functions */ #include "common.h" /* includes "config.h" which must be the first header */ /* #include "config.h" #include "main.h" #include "nut_float.h" #include "nut_stdint.h" */ #include "snmp-ups.h" #include "timehead.h" /* time.h => strptime() */ #include /* for isprint() */ /*********************************************************************** * Subdrivers shared helpers functions * Code below is primarily used in snmp-ups driver, but may be part * of other compilation units, so separated into a stand-alone file **********************************************************************/ static char su_scratch_buf[255]; /* Temperature handling, to convert back to Celsius */ int temperature_unit = TEMPERATURE_UNKNOWN; /* Convert a US formated date (mm/dd/yyyy) to an ISO 8601 Calendar date (yyyy-mm-dd) */ const char *su_usdate_to_isodate_info_fun(void *raw_date) { const char *usdate = (char *)raw_date; struct tm tm; memset(&tm, 0, sizeof(struct tm)); memset(&su_scratch_buf, 0, sizeof(su_scratch_buf)); upsdebugx(3, "%s: US date = %s", __func__, usdate); /* Try to convert from US date string to time */ /* Note strptime returns NULL upon failure, and a ptr to the last null char of the string upon success. Just try blindly the conversion! */ strptime(usdate, "%m/%d/%Y", &tm); if (strftime(su_scratch_buf, 254, "%F", &tm) != 0) { upsdebugx(3, "%s: successfully reformated: %s", __func__, su_scratch_buf); return su_scratch_buf; } return NULL; } info_lkp_t su_convert_to_iso_date_info[] = { /* array index = FUNMAP_USDATE_TO_ISODATE: */ info_lkp_fun_vp2s(1, "dummy", su_usdate_to_isodate_info_fun), info_lkp_sentinel }; /* Process temperature value according to 'temperature_unit' */ const char *su_temperature_read_fun(void *raw_snmp_value) { const long snmp_value = *((long*)raw_snmp_value); long celsius_value = snmp_value; memset(su_scratch_buf, 0, sizeof(su_scratch_buf)); switch (temperature_unit) { case TEMPERATURE_KELVIN: celsius_value = (snmp_value / 10) - 273.15; snprintf(su_scratch_buf, sizeof(su_scratch_buf), "%.1ld", celsius_value); break; case TEMPERATURE_CELSIUS: snprintf(su_scratch_buf, sizeof(su_scratch_buf), "%.1ld", (snmp_value / 10)); break; case TEMPERATURE_FAHRENHEIT: celsius_value = (((snmp_value / 10) - 32) * 5) / 9; snprintf(su_scratch_buf, sizeof(su_scratch_buf), "%.1ld", celsius_value); break; case TEMPERATURE_UNKNOWN: default: upsdebugx(1, "%s: not a known temperature unit for conversion!", __func__); break; } upsdebugx(2, "%s: %.1ld => %s", __func__, (snmp_value / 10), su_scratch_buf); return su_scratch_buf; } nut-2.8.4/drivers/powerp-bin.h0000644000175000017500000000210614670526611013174 00000000000000/* * powerp-bin.h - Model specific data/definitions for CyberPower text/binary * protocol UPSes * * Copyright (C) * 2007 Doug Reynolds * 2007-2008 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef POWERP_BIN_H #define POWERP_BIN_H #include "powerpanel.h" extern subdriver_t powpan_binary; #endif /* POWERP_BIN_H */ nut-2.8.4/drivers/nutdrv_qx_q2.h0000644000175000017500000000172615000736161013544 00000000000000/* nutdrv_qx_q2.h - Subdriver for Q2 Megatec protocol variant * * Copyright (C) * 2024 Viktor Drobot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_Q2_H #define NUTDRV_QX_Q2_H #include "nutdrv_qx.h" extern subdriver_t q2_subdriver; #endif /* NUTDRV_QX_Q2_H */ nut-2.8.4/drivers/bcmxcp.h0000644000175000017500000011574014777753336012415 00000000000000/* * bcmxcp.h -- header for BCM/XCP module */ #ifndef NUT_BCMXCP_H_SEEN #define NUT_BCMXCP_H_SEEN 1 #include "timehead.h" /* Have to wait at least 0,25 sec max 16 sec */ /* 1 second is too short for PW9120 (leads to communication errors). So we set it to 2 seconds */ #define PW_SLEEP 2 #define PW_MAX_TRY 3 /* How many times we try to send data. */ #define PW_COMMAND_START_BYTE (unsigned char)0xAB #define PW_LAST_SEQ (unsigned char)0x80 /* bit flag to indicate final sequence */ #define PW_SEQ_MASK (unsigned char)0x7F /* bit mask to extract just the sequence # */ #define PW_HEADER_LENGTH 4 /* Size of response header */ #define PW_ANSWER_MAX_SIZE 256 /* No Autorisation required */ #define PW_ID_BLOCK_REQ (unsigned char)0x31 /* Model name, ... length 1 */ #define PW_EVENT_HISTORY_LOG_REQ (unsigned char)0x32 /* List alarms that have occurred. length 1 */ #define PW_STATUS_REQ (unsigned char)0x33 /* On Line, On Bypass, ... length 1-2 */ #define PW_METER_BLOCK_REQ (unsigned char)0x34 /* Current UPS status (Load, utility,...) length 1 */ #define PW_CUR_ALARM_REQ (unsigned char)0x35 /* Current alarm and event request. length 1 */ #define PW_CONFIG_BLOCK_REQ (unsigned char)0x36 /* Model serial#, ... length 1 */ #define PW_UTILITY_STATISTICS_BLOCK_REQ (unsigned char)0x38 /* List utility power quality. length 1 */ #define PW_WAVEFORM_BLOCK_REQ (unsigned char)0x3A /* Sampled waveform data. length 7 */ #define PW_BATTERY_REQ (unsigned char)0x3B /* Charging, floating, ... length 1 */ #define PW_LIMIT_BLOCK_REQ (unsigned char)0x3C /* Configuration (Bypass thresholds,...). length 1 */ #define PW_TEST_RESULT_REQ (unsigned char)0x3F /* Get the results for a system test. length 1 */ #define PW_COMMAND_LIST_REQ (unsigned char)0x40 /* Available commands. length 1 */ #define PW_OUT_MON_BLOCK_REQ (unsigned char)0x41 /* Outlet monitor request length 1 */ #define PW_COM_CAP_REQ (unsigned char)0x42 /* Request communication capabilities. length 2 */ #define PW_UPS_TOP_DATA_REQ (unsigned char)0x43 /* Request ups topology data requset. length 1 */ #define PW_COM_PORT_LIST_BLOCK_REQ (unsigned char)0x44 /* Request communication port list. length 1 */ #define PW_REQUEST_SCRATCHPAD_DATA_REQ (unsigned char)0x45 /* Request data from scratchpad. length 2*/ /* Need autorisation before these commands */ #define PW_GO_TO_BYPASS (unsigned char)0x88 /* Transfer load from inverter to bypass. length 1 or 3 */ #define PW_UPS_ON (unsigned char)0x89 /* UPS on command. length 1-2 */ #define PW_LOAD_OFF_RESTART (unsigned char)0x8A /* Delayed LoadPowerOff & Restart command. length 2-4 */ #define PW_UPS_OFF (unsigned char)0x8B /* UPS off command. length 1-2 */ #define PW_DECREMENT_OUTPUT_VOLTAGE (unsigned char)0x8C /* Decrease output voltage. length 1 */ #define PW_INCREMENT_OUTPUT_VOLTAGE (unsigned char)0x8D /* Increase output voltage. length 1 */ #define PW_SET_TIME_AND_DATE (unsigned char)0x90 /* Set the real-time clock inside UPS. length 8 */ #define PW_UPS_ON_TIME (unsigned char)0x91 /* Scheduled UPS on in n minutes. length 3-4 */ #define PW_UPS_ON_AT_TIME (unsigned char)0x92 /* Schedule UPS on at specified date and time. length 7-8 */ #define PW_UPS_OFF_TIME (unsigned char)0x93 /* Scheduled UPS off in n minutes. length 3-4 */ #define PW_UPS_OFF_AT_TIME (unsigned char)0x94 /* Schedule UPS off at specified date and time. length 7-8 */ #define PW_SET_CONF_COMMAND (unsigned char)0x95 /* Set configuration command. length 4 */ #define PW_SET_OUTLET_COMMAND (unsigned char)0x97 /* Set outlet parameter command length 5. not in 5115 */ #define PW_SET_COM_COMMAND (unsigned char)0x98 /* Set communication parameter command. length 5 */ #define PW_SET_SCRATHPAD_SECTOR (unsigned char)0x99 /* Write data to scratchpad. length 3 or 18 */ #define PW_SET_POWER_STRATEGY (unsigned char)0x9A /* Set the power strategy. length 2 */ #define PW_SET_REQ_ONLY_MODE (unsigned char)0xA0 /* Set request only mode command. length 1 */ #define PW_SET_UNREQUESTED_MODE (unsigned char)0xA1 /* Set unrequested mode command. length 1 */ #define PW_INIT_BAT_TEST (unsigned char)0xB1 /* Initiate battery test command. length 3 */ #define PW_INIT_SYS_TEST (unsigned char)0xB2 /* Initiate general system test command. length 2 */ #define PW_SELECT_SUBMODULE (unsigned char)0xCE /* Select a sub module. length 2-7 */ #define PW_AUTHORIZATION_CODE (unsigned char)0xCF /* Authorization code. length 4 or 7 */ /* Define the XCP system test */ #define PW_SYS_TEST_GENERAL (unsigned char)0x01 /* Initiate General system Test */ #define PW_SYS_TEST_SCHEDULE_BATTERY_COMMISSION (unsigned char)0x02 /* Schedule Battery Commissioning Test */ #define PW_SYS_TEST_ALTERNATE_AC_INPUT (unsigned char)0x03 /* Test Alternate AC Input */ #define PW_SYS_TEST_FLASH_LIGHTS (unsigned char)0x04 /* Flash the Lights Test */ #define PW_SYS_TEST_REPORT_CAPABILITIES (unsigned char)0xFF /* Report Systems Test Capabilities */ /* Outlet operations */ #define PW_ALL_OUTLETS 0 #define PW_AUTO_OFF_DELAY 1 #define PW_AUTO_ON_DELAY 2 /* 0 means Abort countdown */ #define PW_TURN_OFF_DELAY 3 #define PW_TURN_ON_DELAY 4 /* Config vars*/ #define PW_CONF_BYPASS_FREQ_DEV_LIMIT 0x01 #define PW_CONF_LOW_DEV_LIMIT 0x02 #define PW_CONF_HIGH_DEV_LIMIT 0x03 #define PW_CONF_PHASE_DEV_LIMIT 0x04 #define PW_CONF_LOW_BATT 0x05 #define PW_CONF_BEEPER 0x06 #define PW_CONF_RETURN_DELAY 0x07 #define PW_CONF_RETURN_CAP 0x08 #define PW_CONF_MAX_TEMP 0x0a #define PW_CONF_NOMINAL_OUT_VOLTAGE 0x0b #define PW_CONF_SLEEP_TH_LOAD 0x0d #define PW_CONF_SLEEP_DELAY 0x0e #define PW_CONF_BATT_STRINGS 0x0f #define PW_CONF_REQ 0xff /* Config block offsets */ #define BCMXCP_CONFIG_BLOCK_MACHINE_TYPE_CODE 0 #define BCMXCP_CONFIG_BLOCK_MODEL_NUMBER 2 #define BCMXCP_CONFIG_BLOCK_MODEL_CONF_WORD 4 #define BCMXCP_CONFIG_BLOCK_INPUT_FREQ_DEV_LIMIT 6 #define BCMXCP_CONFIG_BLOCK_NOMINAL_OUTPUT_VOLTAGE 8 #define BCMXCP_CONFIG_BLOCK_NOMINAL_OUTPUT_FREQ 10 #define BCMXCP_CONFIG_BLOCK_OUTPUT_PHASE_ANGLE 12 #define BCMXCP_CONFIG_BLOCK_HW_MODULES_INSTALLED_WORD1 14 #define BCMXCP_CONFIG_BLOCK_HW_MODULES_INSTALLED_BYTE3 16 /* KEEP THIS UNTILL PARSING OK. USE THIS BYTE. */ #define BCMXCP_CONFIG_BLOCK_HW_MODULES_INSTALLED_WORD2 16 #define BCMXCP_CONFIG_BLOCK_HW_MODULES_INSTALLED_WORD3 18 #define BCMXCP_CONFIG_BLOCK_HW_MODULES_INSTALLED_WORD4 20 #define BCMXCP_CONFIG_BLOCK_BATTERY_DATA_WORD1 22 /* Undefined at this time.*/ #define BCMXCP_CONFIG_BLOCK_BATTERY_DATA_WORD2 24 /* Per cell inverter shutdown voltage at full rated load. (volt/cell)* 100 */ #define BCMXCP_CONFIG_BLOCK_BATTERY_DATA_WORD3 26 /* LOW BYTE Number of battery strings. HIGH BYTE undefined at this time.*/ #define BCMXCP_CONFIG_BLOCK_EXTENDED_BLOCK_LENGTH 47 #define BCMXCP_CONFIG_BLOCK_PART_NUMBER 48 #define BCMXCP_CONFIG_BLOCK_SERIAL_NUMBER 64 /*Battery block offsets*/ #define BCMXCP_BATTDATA_BLOCK_BATT_TEST_STATUS 0 #define BCMXCP_BATTDATA_BLOCK_BATT_VOLTS_T1 1 #define BCMXCP_BATTDATA_BLOCK_BATT_VOLTS_T2 5 #define BCMXCP_BATTDATA_BLOCK_TEST_DURATION 9 #define BCMXCP_BATTDATA_BLOCK_UTIL_VOLT 10 #define BCMXCP_BATTDATA_BLOCK_INPUT_CURRENT 14 #define BCMXCP_BATTDATA_BLOCK_NUMBER_OF_STRINGS 18 /*BATT_TEST_STATUS for external strings (1 byte each) if BCMXCP_BATTDATA_BLOCK_NUMBER_OF_STRINGS == 0 no external test statuses at all*/ /*next - number of ABM Statuses - at least 1 for internal batteries*/ /* Index for Extende Limits block offsets */ #define BCMXCP_EXT_LIMITS_BLOCK_NOMINAL_INPUT_VOLTAGE 0 #define BCMXCP_EXT_LIMITS_BLOCK_NOMINAL_INPUT_FREQ 2 #define BCMXCP_EXT_LIMITS_BLOCK_NOMINAL_TRUE_POWER 4 #define BCMXCP_EXT_LIMITS_BLOCK_COMM_SPEC_VERSION 6 #define BCMXCP_EXT_LIMITS_BLOCK_FREQ_DEV_LIMIT 8 #define BCMXCP_EXT_LIMITS_BLOCK_VOLTAGE_LOW_DEV_LIMIT 10 #define BCMXCP_EXT_LIMITS_BLOCK_VOLTAGE_HIGE_DEV_LIMIT 12 #define BCMXCP_EXT_LIMITS_BLOCK_PHASE_DEV_LIMIT 14 #define BCMXCP_EXT_LIMITS_BLOCK_LOW_BATT_WARNING 16 #define BCMXCP_EXT_LIMITS_BLOCK_HORN_STATUS 17 #define BCMXCP_EXT_LIMITS_BLOCK_MIN_INPUT_VOLTAGE 18 #define BCMXCP_EXT_LIMITS_BLOCK_MAX_INPUT_VOLTAGE 20 #define BCMXCP_EXT_LIMITS_BLOCK_RETURN_STAB_DELAY 22 #define BCMXCP_EXT_LIMITS_BLOCK_BATT_CAPACITY_RETURN 24 #define BCMXCP_EXT_LIMITS_BLOCK_AMBIENT_TEMP_LOW 25 #define BCMXCP_EXT_LIMITS_BLOCK_AMBIENT_TEMP_HIGE 26 #define BCMXCP_EXT_LIMITS_BLOCK_SLEEP_TH_LOAD 29 #define BCMXCP_EXT_LIMITS_BLOCK_SLEEP_DELAY 30 /* Indexes for meter map */ #define BCMXCP_METER_MAP_OUTPUT_VOLTS_AB 0 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VOLTS_BC 1 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VOLTS_CA 2 /* mapped */ #define BCMXCP_METER_MAP_INPUT_VOLTS_AB 3 /* mapped */ #define BCMXCP_METER_MAP_INPUT_VOLTS_BC 4 /* mapped */ #define BCMXCP_METER_MAP_INPUT_VOLTS_CA 5 /* mapped */ #define BCMXCP_METER_MAP_INVERTER_VOLTS_AB 6 #define BCMXCP_METER_MAP_INVERTER_VOLTS_BC 7 #define BCMXCP_METER_MAP_INVERTER_VOLTS_CA 8 #define BCMXCP_METER_MAP_BYPASS_VOLTS_AB 9 #define BCMXCP_METER_MAP_BYPASS_VOLTS_BC 10 #define BCMXCP_METER_MAP_BYPASS_VOLTS_CA 11 #define BCMXCP_METER_MAP_MAIN_LOGIC_POWER 12 #define BCMXCP_METER_MAP_SECONDARY_V_PLUS_POWER 13 #define BCMXCP_METER_MAP_SECONDARY_V_MINUS_POWER 14 #define BCMXCP_METER_MAP_INVERTER_AVG_CURRENT_PHASE_A 15 #define BCMXCP_METER_MAP_INVERTER_AVG_CURRENT_PHASE_B 16 #define BCMXCP_METER_MAP_INVERTER_AVG_CURRENT_PHASE_C 17 #define BCMXCP_METER_MAP_INPUT_CURRENT_PHASE_A 18 /* mapped */ #define BCMXCP_METER_MAP_INPUT_CURRENT_PHASE_B 19 /* mapped */ #define BCMXCP_METER_MAP_INPUT_CURRENT_PHASE_C 20 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_WATTS 21 #define BCMXCP_METER_MAP_INPUT_WATTS 22 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VA 23 /* mapped */ #define BCMXCP_METER_MAP_INPUT_VA 24 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_POWER_FACTOR 25 /* mapped */ #define BCMXCP_METER_MAP_INPUT_POWER_FACTOR 26 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_FREQUENCY 27 /* mapped */ #define BCMXCP_METER_MAP_INPUT_FREQUENCY 28 /* mapped */ #define BCMXCP_METER_MAP_INVERTER_FREQUENCY 29 #define BCMXCP_METER_MAP_BYPASS_FREQUENCY 30 /* mapped */ #define BCMXCP_METER_MAP_DC_LINK_VOLTS_DC 31 #define BCMXCP_METER_MAP_BATTERY_CURRENT 32 /* mapped */ #define BCMXCP_METER_MAP_BATTERY_VOLTAGE 33 /* mapped */ #define BCMXCP_METER_MAP_PERCENT_BATTERY_LEFT 34 /* mapped */ #define BCMXCP_METER_MAP_BATTERY_TIME_REMAINING 35 /* mapped */ #define BCMXCP_METER_MAP_BATTERY_CHARGE_TIME 36 #define BCMXCP_METER_MAP_PEAK_INVERTER_CURRENT_PHASE_A 37 #define BCMXCP_METER_MAP_PEAK_INVERTER_CURRENT_PHASE_B 38 #define BCMXCP_METER_MAP_PEAK_INVERTER_CURRENT_PHASE_C 39 #define BCMXCP_METER_MAP_AVG_INPUT_CURRENT_3_PHASE_SUM 40 #define BCMXCP_METER_MAP_BATTERY_DCUV_BAR_CHART 41 /* mapped */ #define BCMXCP_METER_MAP_INPUT_CURRENT_BAR_CHART 42 #define BCMXCP_METER_MAP_LOW_BATTERY_WARNING_V_BAR_CHART 43 /* mapped */ #define BCMXCP_METER_MAP_DC_VOLTS_BAR_CHART 44 #define BCMXCP_METER_MAP_BATTERY_CHARGING_CURRENT_BAR_CHART 45 #define BCMXCP_METER_MAP_BATTERY_DISCHARGING_CURRENT_BAR_CHART 46 /* mapped */ #define BCMXCP_METER_MAP_PERCENT_LOAD_PHASE_A 47 /* mapped */ #define BCMXCP_METER_MAP_PERCENT_LOAD_PHASE_B 48 /* mapped */ #define BCMXCP_METER_MAP_PERCENT_LOAD_PHASE_C 49 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VA_PHASE_A 50 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VA_PHASE_B 51 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VA_PHASE_C 52 /* mapped */ #define BCMXCP_METER_MAP_BYPASS_VOLTS_PHASE_A 53 /* mapped */ #define BCMXCP_METER_MAP_BYPASS_VOLTS_PHASE_B 54 /* mapped */ #define BCMXCP_METER_MAP_BYPASS_VOLTS_PHASE_C 55 /* mapped */ #define BCMXCP_METER_MAP_INPUT_VOLTS_PHASE_A 56 /* mapped */ #define BCMXCP_METER_MAP_INPUT_VOLTS_PHASE_B 57 /* mapped */ #define BCMXCP_METER_MAP_INPUT_VOLTS_PHASE_C 58 /* mapped */ #define BCMXCP_METER_MAP_INVERTER_VOLTS_PHASE_A 59 #define BCMXCP_METER_MAP_INVERTER_VOLTS_PHASE_B 60 #define BCMXCP_METER_MAP_INVERTER_VOLTS_PHASE_C 61 #define BCMXCP_METER_MAP_AMBIENT_TEMPERATURE 62 /* mapped */ #define BCMXCP_METER_MAP_HEATSINK_TEMPERATURE 63 /* mapped */ #define BCMXCP_METER_MAP_POWER_SUPPLY_TEMPERATURE 64 /* mapped */ #define BCMXCP_METER_MAP_LOAD_CURRENT_PHASE_A 65 /* mapped */ #define BCMXCP_METER_MAP_LOAD_CURRENT_PHASE_B 66 /* mapped */ #define BCMXCP_METER_MAP_LOAD_CURRENT_PHASE_C 67 /* mapped */ #define BCMXCP_METER_MAP_LOAD_CURRENT_PHASE_A_BAR_CHART 68 /* mapped */ #define BCMXCP_METER_MAP_LOAD_CURRENT_PHASE_B_BAR_CHART 69 /* mapped */ #define BCMXCP_METER_MAP_LOAD_CURRENT_PHASE_C_BAR_CHART 70 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VA_BAR_CHART 71 /* mapped */ #define BCMXCP_METER_MAP_DATE 72 /* mapped */ #define BCMXCP_METER_MAP_TIME 73 /* mapped */ #define BCMXCP_METER_MAP_POSITIVE_DC_LINK_RAIL_VOLTAGE 74 #define BCMXCP_METER_MAP_NEGATIVE_DC_LINK_RAIL_VOLTAGE 75 #define BCMXCP_METER_MAP_AUTO_BALANCE_VOLTAGE_DC 76 #define BCMXCP_METER_MAP_BATTERY_TEMPERATURE 77 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VOLTS_A 78 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VOLTS_B 79 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_VOLTS_C 80 /* mapped */ #define BCMXCP_METER_MAP_NEUTRAL_CURRENT 81 #define BCMXCP_METER_MAP_OUTPUT_WATTS_PHASE_A 82 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_WATTS_PHASE_B 83 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_WATTS_PHASE_C 84 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_WATTS_PHASE_A_B_C_BAR_CHART 85 /* mapped */ #define BCMXCP_METER_MAP_RECTIFIER_DC_CURRENT 86 #define BCMXCP_METER_MAP_POSITIVE_BATTERY_VOLTAGE 87 #define BCMXCP_METER_MAP_NEGATIVE_BATTERY_VOLTAGE 88 #define BCMXCP_METER_MAP_POSITIVE_BATTERY_CURRENT 89 #define BCMXCP_METER_MAP_NEGATIVE_BATTERY_CURRENT 90 #define BCMXCP_METER_MAP_LINE_EVENT_COUNTER 91 /* mapped */ #define BCMXCP_METER_MAP_OUTPUT_V1_PERCENT 92 #define BCMXCP_METER_MAP_OUTPUT_V2_PERCENT 93 #define BCMXCP_METER_MAP_OUTPUT_V3_PERCENT 94 #define BCMXCP_METER_MAP_OUTPUT_I1_PERCENT 95 #define BCMXCP_METER_MAP_OUTPUT_I2_PERCENT 96 #define BCMXCP_METER_MAP_OUTPUT_I3_PERCENT 97 #define BCMXCP_METER_MAP_INPUT_V1_PERCENT 98 #define BCMXCP_METER_MAP_INPUT_V2_PERCENT 99 #define BCMXCP_METER_MAP_INPUT_V3_PERCENT 100 #define BCMXCP_METER_MAP_INPUT_I1_PERCENT 101 #define BCMXCP_METER_MAP_INPUT_I2_PERCENT 102 #define BCMXCP_METER_MAP_INPUT_I3_PERCENT 103 #define BCMXCP_METER_MAP_GROUND_CURRENT 104 #define BCMXCP_METER_MAP_OUTPUT_CREST_FACTOR_L1 105 #define BCMXCP_METER_MAP_OUTPUT_CREST_FACTOR_L2 106 #define BCMXCP_METER_MAP_OUTPUT_CREST_FACTOR_L3 107 #define BCMXCP_METER_MAP_OUTPUT_KW_HOUR 108 #define BCMXCP_METER_MAP_INPUT_VOLTAGE_THD_LINE1 109 #define BCMXCP_METER_MAP_INPUT_VOLTAGE_THD_LINE2 110 #define BCMXCP_METER_MAP_INPUT_VOLTAGE_THD_LINE3 111 #define BCMXCP_METER_MAP_INPUT_CURRENT_THD_LINE1 112 #define BCMXCP_METER_MAP_INPUT_CURRENT_THD_LINE2 113 #define BCMXCP_METER_MAP_INPUT_CURRENT_THD_LINE3 114 #define BCMXCP_METER_MAP_OUTPUT_VOLTAGE_THD_LINE1 115 #define BCMXCP_METER_MAP_OUTPUT_VOLTAGE_THD_LINE2 116 #define BCMXCP_METER_MAP_OUTPUT_VOLTAGE_THD_LINE3 117 #define BCMXCP_METER_MAP_OUTPUT_CURRENT_THD_LINE1 118 #define BCMXCP_METER_MAP_OUTPUT_CURRENT_THD_LINE2 119 #define BCMXCP_METER_MAP_OUTPUT_CURRENT_THD_LINE3 120 #define BCMXCP_METER_MAP_INPUT_CREST_FACTOR_L1 121 #define BCMXCP_METER_MAP_INPUT_CREST_FACTOR_L2 122 #define BCMXCP_METER_MAP_INPUT_CREST_FACTOR_L3 123 #define BCMXCP_METER_MAP_INPUT_KW_HOUR 124 #define BCMXCP_METER_MAP_BATTERY_LIFE_REMAINING 125 #define BCMXCP_METER_MAP_SECONDARY_NEUTRAL_CURRENT 126 #define BCMXCP_METER_MAP_SECONDARY_GROUND_CURRENT 127 #define BCMXCP_METER_MAP_HOURS_OF_OPERATION 128 /* Indexes for alarm map */ #define BCMXCP_ALARM_INVERTER_AC_OVER_VOLTAGE 0 #define BCMXCP_ALARM_INVERTER_AC_UNDER_VOLTAGE 1 #define BCMXCP_ALARM_INVERTER_OVER_OR_UNDER_FREQ 2 #define BCMXCP_ALARM_BYPASS_AC_OVER_VOLTAGE 3 #define BCMXCP_ALARM_BYPASS_AC_UNDER_VOLTAGE 4 #define BCMXCP_ALARM_BYPASS_OVER_OR_UNDER_FREQ 5 #define BCMXCP_ALARM_INPUT_AC_OVER_VOLTAGE 6 #define BCMXCP_ALARM_INPUT_AC_UNDER_VOLTAGE 7 #define BCMXCP_ALARM_INPUT_UNDER_OR_OVER_FREQ 8 #define BCMXCP_ALARM_OUTPUT_OVER_VOLTAGE 9 #define BCMXCP_ALARM_OUTPUT_UNDER_VOLTAGE 10 #define BCMXCP_ALARM_OUTPUT_UNDER_OR_OVER_FREQ 11 #define BCMXCP_ALARM_REMOTE_EMERGENCY_PWR_OFF 12 #define BCMXCP_ALARM_REMOTE_GO_TO_BYPASS 13 #define BCMXCP_ALARM_BUILDING_ALARM_6 14 #define BCMXCP_ALARM_BUILDING_ALARM_5 15 #define BCMXCP_ALARM_BUILDING_ALARM_4 16 #define BCMXCP_ALARM_BUILDING_ALARM_3 17 #define BCMXCP_ALARM_BUILDING_ALARM_2 18 #define BCMXCP_ALARM_BUILDING_ALARM_1 19 #define BCMXCP_ALARM_STATIC_SWITCH_OVER_TEMP 20 #define BCMXCP_ALARM_CHARGER_OVER_TEMP 21 #define BCMXCP_ALARM_CHARGER_LOGIC_PWR_FAIL 22 #define BCMXCP_ALARM_CHARGER_OVER_VOLTAGE_OR_CURRENT 23 #define BCMXCP_ALARM_INVERTER_OVER_TEMP 24 #define BCMXCP_ALARM_OUTPUT_OVERLOAD 25 #define BCMXCP_ALARM_RECTIFIER_INPUT_OVER_CURRENT 26 #define BCMXCP_ALARM_INVERTER_OUTPUT_OVER_CURRENT 27 #define BCMXCP_ALARM_DC_LINK_OVER_VOLTAGE 28 #define BCMXCP_ALARM_DC_LINK_UNDER_VOLTAGE 29 #define BCMXCP_ALARM_RECTIFIER_FAILED 30 #define BCMXCP_ALARM_INVERTER_FAULT 31 #define BCMXCP_ALARM_BATTERY_CONNECTOR_FAIL 32 #define BCMXCP_ALARM_BYPASS_BREAKER_FAIL 33 #define BCMXCP_ALARM_CHARGER_FAIL 34 #define BCMXCP_ALARM_RAMP_UP_FAILED 35 #define BCMXCP_ALARM_STATIC_SWITCH_FAILED 36 #define BCMXCP_ALARM_ANALOG_AD_REF_FAIL 37 #define BCMXCP_ALARM_BYPASS_UNCALIBRATED 38 #define BCMXCP_ALARM_RECTIFIER_UNCALIBRATED 39 #define BCMXCP_ALARM_OUTPUT_UNCALIBRATED 40 #define BCMXCP_ALARM_INVERTER_UNCALIBRATED 41 #define BCMXCP_ALARM_DC_VOLT_UNCALIBRATED 42 #define BCMXCP_ALARM_OUTPUT_CURRENT_UNCALIBRATED 43 #define BCMXCP_ALARM_RECTIFIER_CURRENT_UNCALIBRATED 44 #define BCMXCP_ALARM_BATTERY_CURRENT_UNCALIBRATED 45 #define BCMXCP_ALARM_INVERTER_ON_OFF_STAT_FAIL 46 #define BCMXCP_ALARM_BATTERY_CURRENT_LIMIT 47 #define BCMXCP_ALARM_INVERTER_STARTUP_FAIL 48 #define BCMXCP_ALARM_ANALOG_BOARD_AD_STAT_FAIL 49 #define BCMXCP_ALARM_OUTPUT_CURRENT_OVER_100 50 #define BCMXCP_ALARM_BATTERY_GROUND_FAULT 51 #define BCMXCP_ALARM_WAITING_FOR_CHARGER_SYNC 52 #define BCMXCP_ALARM_NV_RAM_FAIL 53 #define BCMXCP_ALARM_ANALOG_BOARD_AD_TIMEOUT 54 #define BCMXCP_ALARM_SHUTDOWN_IMMINENT 55 #define BCMXCP_ALARM_BATTERY_LOW 56 #define BCMXCP_ALARM_UTILITY_FAIL 57 #define BCMXCP_ALARM_OUTPUT_SHORT_CIRCUIT 58 #define BCMXCP_ALARM_UTILITY_NOT_PRESENT 59 #define BCMXCP_ALARM_FULL_TIME_CHARGING 60 #define BCMXCP_ALARM_FAST_BYPASS_COMMAND 61 #define BCMXCP_ALARM_AD_ERROR 62 #define BCMXCP_ALARM_INTERNAL_COM_FAIL 63 #define BCMXCP_ALARM_RECTIFIER_SELFTEST_FAIL 64 #define BCMXCP_ALARM_RECTIFIER_EEPROM_FAIL 65 #define BCMXCP_ALARM_RECTIFIER_EPROM_FAIL 66 #define BCMXCP_ALARM_INPUT_LINE_VOLTAGE_LOSS 67 #define BCMXCP_ALARM_BATTERY_DC_OVER_VOLTAGE 68 #define BCMXCP_ALARM_POWER_SUPPLY_OVER_TEMP 69 #define BCMXCP_ALARM_POWER_SUPPLY_FAIL 70 #define BCMXCP_ALARM_POWER_SUPPLY_5V_FAIL 71 #define BCMXCP_ALARM_POWER_SUPPLY_12V_FAIL 72 #define BCMXCP_ALARM_HEATSINK_OVER_TEMP 73 #define BCMXCP_ALARM_HEATSINK_TEMP_SENSOR_FAIL 74 #define BCMXCP_ALARM_RECTIFIER_CURRENT_OVER_125 75 #define BCMXCP_ALARM_RECTIFIER_FAULT_INTERRUPT_FAIL 76 #define BCMXCP_ALARM_RECTIFIER_POWER_CAPACITOR_FAIL 77 #define BCMXCP_ALARM_RECTIFIER_POWER_CAPASITOR_FAIL 77 /* Legacy - typo */ #define BCMXCP_ALARM_INVERTER_PROGRAM_STACK_ERROR 78 #define BCMXCP_ALARM_INVERTER_BOARD_SELFTEST_FAIL 79 #define BCMXCP_ALARM_INVERTER_AD_SELFTEST_FAIL 80 #define BCMXCP_ALARM_INVERTER_RAM_SELFTEST_FAIL 81 #define BCMXCP_ALARM_NV_MEMORY_CHECKSUM_FAIL 82 #define BCMXCP_ALARM_PROGRAM_CHECKSUM_FAIL 83 #define BCMXCP_ALARM_INVERTER_CPU_SELFTEST_FAIL 84 #define BCMXCP_ALARM_NETWORK_NOT_RESPONDING 85 #define BCMXCP_ALARM_FRONT_PANEL_SELFTEST_FAIL 86 #define BCMXCP_ALARM_NODE_EEPROM_VERIFICATION_ERROR 87 #define BCMXCP_ALARM_OUTPUT_AC_OVER_VOLT_TEST_FAIL 88 #define BCMXCP_ALARM_OUTPUT_DC_OVER_VOLTAGE 89 #define BCMXCP_ALARM_INPUT_PHASE_ROTATION_ERROR 90 #define BCMXCP_ALARM_INVERTER_RAMP_UP_TEST_FAILED 91 #define BCMXCP_ALARM_INVERTER_OFF_COMMAND 92 #define BCMXCP_ALARM_INVERTER_ON_COMMAND 93 #define BCMXCP_ALARM_TO_BYPASS_COMMAND 94 #define BCMXCP_ALARM_FROM_BYPASS_COMMAND 95 #define BCMXCP_ALARM_AUTO_MODE_COMMAND 96 #define BCMXCP_ALARM_EMERGENCY_SHUTDOWN_COMMAND 97 #define BCMXCP_ALARM_SETUP_SWITCH_OPEN 98 #define BCMXCP_ALARM_INVERTER_OVER_VOLT_INT 99 #define BCMXCP_ALARM_INVERTER_UNDER_VOLT_INT 100 #define BCMXCP_ALARM_ABSOLUTE_DCOV_ACOV 101 #define BCMXCP_ALARM_PHASE_A_CURRENT_LIMIT 102 #define BCMXCP_ALARM_PHASE_B_CURRENT_LIMIT 103 #define BCMXCP_ALARM_PHASE_C_CURRENT_LIMIT 104 #define BCMXCP_ALARM_BYPASS_NOT_AVAILABLE 105 #define BCMXCP_ALARM_RECTIFIER_BREAKER_OPEN 106 #define BCMXCP_ALARM_BATTERY_CONTACTOR_OPEN 107 #define BCMXCP_ALARM_INVERTER_CONTACTOR_OPEN 108 #define BCMXCP_ALARM_BYPASS_BREAKER_OPEN 109 #define BCMXCP_ALARM_INV_BOARD_ACOV_INT_TEST_FAIL 110 #define BCMXCP_ALARM_INVERTER_OVER_TEMP_TRIP 111 #define BCMXCP_ALARM_INV_BOARD_ACUV_INT_TEST_FAIL 112 #define BCMXCP_ALARM_INVERTER_VOLTAGE_FEEDBACK_ERROR 113 #define BCMXCP_ALARM_DC_UNDER_VOLTAGE_TIMEOUT 114 #define BCMXCP_ALARM_AC_UNDER_VOLTAGE_TIMEOUT 115 #define BCMXCP_ALARM_DC_UNDER_VOLTAGE_WHILE_CHARGE 116 #define BCMXCP_ALARM_INVERTER_VOLTAGE_BIAS_ERROR 117 #define BCMXCP_ALARM_RECTIFIER_PHASE_ROTATION 118 #define BCMXCP_ALARM_BYPASS_PHASER_ROTATION 119 #define BCMXCP_ALARM_SYSTEM_INTERFACE_BOARD_FAIL 120 #define BCMXCP_ALARM_PARALLEL_BOARD_FAIL 121 #define BCMXCP_ALARM_LOST_LOAD_SHARING_PHASE_A 122 #define BCMXCP_ALARM_LOST_LOAD_SHARING_PHASE_B 123 #define BCMXCP_ALARM_LOST_LOAD_SHARING_PHASE_C 124 #define BCMXCP_ALARM_DC_OVER_VOLTAGE_TIMEOUT 125 #define BCMXCP_ALARM_BATTERY_TOTALLY_DISCHARGED 126 #define BCMXCP_ALARM_INVERTER_PHASE_BIAS_ERROR 127 #define BCMXCP_ALARM_INVERTER_VOLTAGE_BIAS_ERROR_2 128 #define BCMXCP_ALARM_DC_LINK_BLEED_COMPLETE 129 #define BCMXCP_ALARM_LARGE_CHARGER_INPUT_CURRENT 130 #define BCMXCP_ALARM_INV_VOLT_TOO_LOW_FOR_RAMP_LEVEL 131 #define BCMXCP_ALARM_LOSS_OF_REDUNDANCY 132 #define BCMXCP_ALARM_LOSS_OF_SYNC_BUS 133 #define BCMXCP_ALARM_RECTIFIER_BREAKER_SHUNT_TRIP 134 #define BCMXCP_ALARM_LOSS_OF_CHARGER_SYNC 135 #define BCMXCP_ALARM_INVERTER_LOW_LEVEL_TEST_TIMEOUT 136 #define BCMXCP_ALARM_OUTPUT_BREAKER_OPEN 137 #define BCMXCP_ALARM_CONTROL_POWER_ON 138 #define BCMXCP_ALARM_INVERTER_ON 139 #define BCMXCP_ALARM_CHARGER_ON 140 #define BCMXCP_ALARM_BYPASS_ON 141 #define BCMXCP_ALARM_BYPASS_POWER_LOSS 142 #define BCMXCP_ALARM_ON_MANUAL_BYPASS 143 #define BCMXCP_ALARM_BYPASS_MANUAL_TURN_OFF 144 #define BCMXCP_ALARM_INVERTER_BLEEDING_DC_LINK_VOLT 145 #define BCMXCP_ALARM_CPU_ISR_ERROR 146 #define BCMXCP_ALARM_SYSTEM_ISR_RESTART 147 #define BCMXCP_ALARM_PARALLEL_DC 148 #define BCMXCP_ALARM_BATTERY_NEEDS_SERVICE 149 #define BCMXCP_ALARM_BATTERY_CHARGING 150 #define BCMXCP_ALARM_BATTERY_NOT_CHARGED 151 #define BCMXCP_ALARM_DISABLED_BATTERY_TIME 152 #define BCMXCP_ALARM_SERIES_7000_ENABLE 153 #define BCMXCP_ALARM_OTHER_UPS_ON 154 #define BCMXCP_ALARM_PARALLEL_INVERTER 155 #define BCMXCP_ALARM_UPS_IN_PARALLEL 156 #define BCMXCP_ALARM_OUTPUT_BREAKER_REALY_FAIL 157 #define BCMXCP_ALARM_CONTROL_POWER_OFF 158 #define BCMXCP_ALARM_LEVEL_2_OVERLOAD_PHASE_A 159 #define BCMXCP_ALARM_LEVEL_2_OVERLOAD_PHASE_B 160 #define BCMXCP_ALARM_LEVEL_2_OVERLOAD_PHASE_C 161 #define BCMXCP_ALARM_LEVEL_3_OVERLOAD_PHASE_A 162 #define BCMXCP_ALARM_LEVEL_3_OVERLOAD_PHASE_B 163 #define BCMXCP_ALARM_LEVEL_3_OVERLOAD_PHASE_C 164 #define BCMXCP_ALARM_LEVEL_4_OVERLOAD_PHASE_A 165 #define BCMXCP_ALARM_LEVEL_4_OVERLOAD_PHASE_B 166 #define BCMXCP_ALARM_LEVEL_4_OVERLOAD_PHASE_C 167 #define BCMXCP_ALARM_UPS_ON_BATTERY 168 #define BCMXCP_ALARM_UPS_ON_BYPASS 169 #define BCMXCP_ALARM_LOAD_DUMPED 170 #define BCMXCP_ALARM_LOAD_ON_INVERTER 171 #define BCMXCP_ALARM_UPS_ON_COMMAND 172 #define BCMXCP_ALARM_UPS_OFF_COMMAND 173 #define BCMXCP_ALARM_LOW_BATTERY_SHUTDOWN 174 #define BCMXCP_ALARM_AUTO_ON_ENABLED 175 #define BCMXCP_ALARM_SOFTWARE_INCOMPABILITY_DETECTED 176 #define BCMXCP_ALARM_INVERTER_TEMP_SENSOR_FAILED 177 #define BCMXCP_ALARM_DC_START_OCCURED 178 #define BCMXCP_ALARM_IN_PARALLEL_OPERATION 179 #define BCMXCP_ALARM_SYNCING_TO_BYPASS 180 #define BCMXCP_ALARM_RAMPING_UPS_UP 181 #define BCMXCP_ALARM_INVERTER_ON_DELAY 182 #define BCMXCP_ALARM_CHARGER_ON_DELAY 183 #define BCMXCP_ALARM_WAITING_FOR_UTIL_INPUT 184 #define BCMXCP_ALARM_CLOSE_BYPASS_BREAKER 185 #define BCMXCP_ALARM_TEMPORARY_BYPASS_OPERATION 186 #define BCMXCP_ALARM_SYNCING_TO_OUTPUT 187 #define BCMXCP_ALARM_BYPASS_FAILURE 188 #define BCMXCP_ALARM_AUTO_OFF_COMMAND_EXECUTED 189 #define BCMXCP_ALARM_AUTO_ON_COMMAND_EXECUTED 190 #define BCMXCP_ALARM_BATTERY_TEST_FAILED 191 #define BCMXCP_ALARM_FUSE_FAIL 192 #define BCMXCP_ALARM_FAN_FAIL 193 #define BCMXCP_ALARM_SITE_WIRING_FAULT 194 #define BCMXCP_ALARM_BACKFEED_CONTACTOR_FAIL 195 #define BCMXCP_ALARM_ON_BUCK 196 #define BCMXCP_ALARM_ON_BOOST 197 #define BCMXCP_ALARM_ON_DOUBLE_BOOST 198 #define BCMXCP_ALARM_BATTERIES_DISCONNECTED 199 #define BCMXCP_ALARM_UPS_CABINET_OVER_TEMP 200 #define BCMXCP_ALARM_TRANSFORMER_OVER_TEMP 201 #define BCMXCP_ALARM_AMBIENT_UNDER_TEMP 202 #define BCMXCP_ALARM_AMBIENT_OVER_TEMP 203 #define BCMXCP_ALARM_CABINET_DOOR_OPEN 204 #define BCMXCP_ALARM_CABINET_DOOR_OPEN_VOLT_PRESENT 205 #define BCMXCP_ALARM_AUTO_SHUTDOWN_PENDING 206 #define BCMXCP_ALARM_TAP_SWITCHING_REALY_PENDING 207 #define BCMXCP_ALARM_UNABLE_TO_CHARGE_BATTERIES 208 #define BCMXCP_ALARM_STARTUP_FAILURE_CHECK_EPO 209 #define BCMXCP_ALARM_AUTOMATIC_STARTUP_PENDING 210 #define BCMXCP_ALARM_MODEM_FAILED 211 #define BCMXCP_ALARM_INCOMING_MODEM_CALL_STARTED 212 #define BCMXCP_ALARM_OUTGOING_MODEM_CALL_STARTED 213 #define BCMXCP_ALARM_MODEM_CONNECTION_ESTABLISHED 214 #define BCMXCP_ALARM_MODEM_CALL_COMPLETED_SUCCESS 215 #define BCMXCP_ALARM_MODEM_CALL_COMPLETED_FAIL 216 #define BCMXCP_ALARM_INPUT_BREAKER_FAIL 217 #define BCMXCP_ALARM_SYSINIT_IN_PROGRESS 218 #define BCMXCP_ALARM_AUTOCALIBRATION_FAIL 219 #define BCMXCP_ALARM_SELECTIVE_TRIP_OF_MODULE 220 #define BCMXCP_ALARM_INVERTER_OUTPUT_FAILURE 221 #define BCMXCP_ALARM_ABNORMAL_OUTPUT_VOLT_AT_STARTUP 222 #define BCMXCP_ALARM_RECTIFIER_OVER_TEMP 223 #define BCMXCP_ALARM_CONFIG_ERROR 224 #define BCMXCP_ALARM_REDUNDANCY_LOSS_DUE_TO_OVERLOAD 225 #define BCMXCP_ALARM_ON_ALTERNATE_AC_SOURCE 226 #define BCMXCP_ALARM_IN_HIGH_EFFICIENCY_MODE 227 #define BCMXCP_ALARM_SYSTEM_NOTICE_ACTIVE 228 #define BCMXCP_ALARM_SYSTEM_ALARM_ACTIVE 229 #define BCMXCP_ALARM_ALTERNATE_POWER_SOURCE_NOT_AVAILABLE 230 #define BCMXCP_ALARM_CURRENT_BALANCE_FAILURE 231 #define BCMXCP_ALARM_CHECK_AIR_FILTER 232 #define BCMXCP_ALARM_SUBSYSTEM_NOTICE_ACTIVE 233 #define BCMXCP_ALARM_SUBSYSTEM_ALARM_ACTIVE 234 #define BCMXCP_ALARM_CHARGER_ON_COMMAND 235 #define BCMXCP_ALARM_CHARGER_OFF_COMMAND 236 #define BCMXCP_ALARM_UPS_NORMAL 237 #define BCMXCP_ALARM_INVERTER_PHASE_ROTATION 238 #define BCMXCP_ALARM_UPS_OFF 239 #define BCMXCP_ALARM_EXTERNAL_COMMUNICATION_FAILURE 240 #define BCMXCP_ALARM_BATTERY_TEST_INPROGRESS 256 #define BCMXCP_ALARM_SYSTEM_TEST_INPROGRESS 257 #define BCMXCP_ALARM_BATTERY_TEST_ABORTED 258 #define BCMXCP_COMMAND_MAP_MAX 208 /* Max no of entries in BCM/XCP meter map (adjusted upwards to nearest multi of 8) */ #define BCMXCP_METER_MAP_MAX 136 /* Max no of entries in BCM/XCP meter map (adjusted upwards to nearest multi of 8) */ #define BCMXCP_ALARM_MAP_MAX 264 /* Max no of entries in BCM/XCP alarm map (adjusted upwards to nearest multi of 8) */ /* Return codes for XCP ACK block responses */ #define BCMXCP_RETURN_ACCEPTED 0x31 /* Accepted and executed (or execution in progress) */ #define BCMXCP_RETURN_NOT_IMPLEMENTED 0x32 /* Recognized but not implemented */ #define BCMXCP_RETURN_BUSY 0x33 /* Recognized but not currently able to execute (busy) */ #define BCMXCP_RETURN_UNRECOGNISED 0x34 /* Unrecognized -- e.g., command byte not in valid range, or command has been corrupted (bad checksum) */ #define BCMXCP_RETURN_PARAMETER_OUT_OF_RANGE 0x35 /* Command recognized, but its Parameter value is out of range */ #define BCMXCP_RETURN_INVALID_PARAMETER 0x36 /* Command recognized, but its Parameter is invalid (e.g., no such parameter, bad Outlet number) */ #define BCMXCP_RETURN_ACCEPTED_PARAMETER_ADJUST 0x37 /* Accepted, with parameter adjusted to nearest good value */ /*#define BCMXCP_RETURN_READONLY 0x38 */ /* Parameter is Read-only - cannot be written (at this privilege level) (this is not listed in spec document */ /* UPS status */ #define BCMXCP_STATUS_ONLINE 0x50 #define BCMXCP_STATUS_ONBATTERY 0xf0 #define BCMXCP_STATUS_OVERLOAD 0xe0 #define BCMXCP_STATUS_TRIM 0x63 #define BCMXCP_STATUS_BOOST1 0x61 #define BCMXCP_STATUS_BOOST2 0x62 #define BCMXCP_STATUS_BYPASS 0x60 #define BCMXCP_STATUS_OFF 0x10 /* UPS topology block info */ #define BCMXCP_TOPOLOGY_NONE 0x0000 /* None; use the Table of Elements */ #define BCMXCP_TOPOLOGY_OFFLINE_SWITCHER_1P 0x0010 /* Off-line switcher, Single Phase */ #define BCMXCP_TOPOLOGY_LINEINT_UPS_1P 0x0020 /* Line-Interactive UPS, Single Phase */ #define BCMXCP_TOPOLOGY_LINEINT_UPS_2P 0x0021 /* Line-Interactive UPS, Two Phase */ #define BCMXCP_TOPOLOGY_LINEINT_UPS_3P 0x0022 /* Line-Interactive UPS, Three Phase */ #define BCMXCP_TOPOLOGY_DUAL_AC_ONLINE_UPS_1P 0x0030 /* Dual AC Input, On-Line UPS, Single Phase */ #define BCMXCP_TOPOLOGY_DUAL_AC_ONLINE_UPS_2P 0x0031 /* Dual AC Input, On-Line UPS, Two Phase */ #define BCMXCP_TOPOLOGY_DUAL_AC_ONLINE_UPS_3P 0x0032 /* Dual AC Input, On-Line UPS, Three Phase */ #define BCMXCP_TOPOLOGY_ONLINE_UPS_1P 0x0040 /* On-Line UPS, Single Phase */ #define BCMXCP_TOPOLOGY_ONLINE_UPS_2P 0x0041 /* On-Line UPS, Two Phase */ #define BCMXCP_TOPOLOGY_ONLINE_UPS_3P 0x0042 /* On-Line UPS, Three Phase */ #define BCMXCP_TOPOLOGY_PARA_REDUND_ONLINE_UPS_1P 0x0050 /* Parallel Redundant On-Line UPS, Single Phase */ #define BCMXCP_TOPOLOGY_PARA_REDUND_ONLINE_UPS_2P 0x0051 /* Parallel Redundant On-Line UPS, Two Phase */ #define BCMXCP_TOPOLOGY_PARA_REDUND_ONLINE_UPS_3P 0x0052 /* Parallel Redundant On-Line UPS, Three Phase */ #define BCMXCP_TOPOLOGY_PARA_CAPACITY_ONLINE_UPS_1P 0x0060 /* Parallel for Capacity On-Line UPS, Single Phase */ #define BCMXCP_TOPOLOGY_PARA_CAPACITY_ONLINE_UPS_2P 0x0061 /* Parallel for Capacity On-Line UPS, Two Phase */ #define BCMXCP_TOPOLOGY_PARA_CAPACITY_ONLINE_UPS_3P 0x0062 /* Parallel for Capacity On-Line UPS, Three Phase */ #define BCMXCP_TOPOLOGY_SYSTEM_BYPASS_MODULE_3P 0x0102 /* System Bypass Module, Three Phase */ #define BCMXCP_TOPOLOGY_HOT_TIE_CABINET_3P 0x0122 /* Hot-Tie Cabinet, Three Phase */ #define BCMXCP_TOPOLOGY_OUTLET_CONTROLLER_1P 0x0200 /* Outlet Controller, Single Phase */ #define BCMXCP_TOPOLOGY_DUAL_AC_STATIC_SWITCH_3P 0x0222 /* Dual AC Input Static Switch Module, 3 Phase */ typedef struct { /* Entry in BCM/XCP - UPS mapping table */ const char *command_desc; /* Description of this command */ unsigned char command_byte; /* The command byte for this command, 0 = not supported */ } BCMXCP_COMMAND_MAP_ENTRY_t; extern BCMXCP_COMMAND_MAP_ENTRY_t bcmxcp_command_map[BCMXCP_COMMAND_MAP_MAX]; typedef struct { /* Entry in BCM/XCP - UPS - NUT mapping table */ const char *nut_entity; /* The NUT variable name */ unsigned char format; /* The format of the data - float, long etc */ unsigned int meter_block_index; /* The position of this meter in the UPS meter block */ } BCMXCP_METER_MAP_ENTRY_t; extern BCMXCP_METER_MAP_ENTRY_t bcmxcp_meter_map[BCMXCP_METER_MAP_MAX]; typedef struct { /* Entry in BCM/XCP - UPS mapping table */ int alarm_block_index; /* Index of this alarm in alarm block. -1 = not existing */ const char *alarm_desc; /* Description of this alarm */ } BCMXCP_ALARM_MAP_ENTRY_t; extern BCMXCP_ALARM_MAP_ENTRY_t bcmxcp_alarm_map[BCMXCP_ALARM_MAP_MAX]; typedef struct { /* A place to store status info and other data not for NUT */ unsigned char topology_mask; /* Configuration block byte 16, masks valid status bits */ unsigned int lowbatt; /* Seconds of runtime left left when LB alarm is set */ unsigned int shutdowndelay; /* Shutdown delay in seconds, from ups.conf */ int alarm_on_battery; /* On Battery alarm active? */ int alarm_low_battery; /* Battery Low alarm active? */ int alarm_replace_battery; /* Battery needs replacement! */ } BCMXCP_STATUS_t; extern BCMXCP_STATUS_t bcmxcp_status; int checksum_test(const unsigned char*); unsigned char calc_checksum(const unsigned char *buf); /* from usbhid-ups.h */ typedef struct { const long xcp_value; /* XCP value */ const char *nut_value; /* NUT value */ const char *(*fun)(double xcp_value); /* optional XCP to NUT mapping */ double (*nuf)(const char *nut_value); /* optional NUT to HID mapping */ } info_lkp_t; /* use explicit booleans */ #ifndef FALSE typedef enum ebool { FALSE, TRUE } bool_t; #else typedef int bool_t; #endif #endif /* NUT_BCMXCP_H_SEEN */ nut-2.8.4/drivers/bestuferrups.c0000644000175000017500000003541315044656702013646 00000000000000/* bestuferrups.c - model specific routines for Best Power Micro-Ferrups This module is a 40% rewritten mangle of the bestfort module by Grant, which is a 75% rewritten mangle of the bestups module by Russell. It has no test battery command since my ME3100 does this by itself. (same as Grant's driver in this respect) Support for model RE added by Tim Thompson (7/22/04) Copyright (C) 2002 Andreas Wrede Copyright (C) 2000 John Stone Copyright (C) 2000 Grant Taylor Copyright (C) 1999 Russell Kroll This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "serial.h" #define DRIVER_NAME "Best Ferrups Series ME/RE/MD driver" #define DRIVER_VERSION "0.08" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Andreas Wrede \n" \ "John Stone \n" \ "Grant Taylor \n" \ "Russell Kroll \n" \ "Tim Thompson", DRV_BETA, /* FIXME: STABLE? */ { NULL } }; #define ENDCHAR '\r' #define IGNCHARS "\012" /* UPS Model Codes */ #define UNKNOWN 100 #define ME3100 200 #define MD1KVA 300 /* Software version P5.05 dated 05/18/89 */ #define RE1800 400 #include #include #include static int debugging = 0; /* Blob of UPS configuration data from the formatconfig string */ static struct { int valid; /* set to 1 when this is filled in */ float idealbvolts; /* various interestin battery voltages */ float fullvolts; float emptyvolts; int va; /* capacity of UPS in Volt-Amps */ int watts; /* capacity of UPS in watts */ int model; /* enumerated model type */ } fc; /* Forward decls */ static int instcmd(const char *cmdname, const char *extra); /* Set up all the funky shared memory stuff used to communicate with upsd */ void upsdrv_initinfo (void) { /* now set up room for all future variables that are supported */ dstate_setinfo("ups.mfr", "%s", "Best Power"); switch(fc.model) { case ME3100: dstate_setinfo("ups.model", "Micro Ferrups (ME) %d", fc.va); break; case MD1KVA: dstate_setinfo("ups.model", "Micro Ferrups (MD) %d", fc.va); break; case RE1800: dstate_setinfo("ups.model", "Micro Ferrups (RE) %d", fc.va); break; default: fatalx(EXIT_FAILURE, "UPS model not matched!"); /* Will never get here, upsdrv_initups() will catch */ } fprintf(stderr, "Best Power %s detected\n", dstate_getinfo("ups.model")); fprintf(stderr, "Battery voltages %5.1f nominal, %5.1f full, %5.1f empty\n", fc.idealbvolts, fc.fullvolts, fc.emptyvolts); /* commands ----------------------------------------------- */ dstate_addcmd("shutdown.return"); /* install handlers */ upsh.instcmd = instcmd; } /* Debugging display from kermit: ---------------------------------------------------- time^M^M^JFeb 20, 22:13:32^M^J^M^J=>id^M^JUnit ID "ME3.1K12345"^M^J^M^J=> ---------------------------------------------------- */ static ssize_t execute(const char *cmd, char *result, size_t resultsize) { ssize_t ret; char buf[256]; ser_send(upsfd, "%s", cmd); ser_get_line(upsfd, buf, sizeof(buf), '\012', "", 3, 0); ret = ser_get_line(upsfd, result, resultsize, '\015', "\012", 3, 0); ser_get_line(upsfd, buf, sizeof(buf), '>', "", 3, 0); return ret; } void upsdrv_updateinfo(void) { char fstring[512]; if (! fc.valid) { fprintf(stderr, "upsupdate run before ups_ident() read ups config\n"); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #endif /* NOTE: This assert() always fails because of "0": * error: will never be executed [-Werror,-Wunreachable-code] * ((0) ? (void) (0) : __assert_fail ("0", "bestuferrups.c", 138, __PRETTY_FUNCTION__)); * ^ */ assert(0); #ifdef __clang__ #pragma clang diagnostic pop #endif #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic pop #endif } if (execute("f\r", fstring, sizeof(fstring)) > 0) { int inverter=0, charger=0, vin=0, vout=0, btimeleft=0, linestat=0, alstat=0, vaout=0; double ampsout=0.0, vbatt=0.0, battpercent=0.0, loadpercent=0.0, hstemp=0.0, acfreq=0.0, ambtemp=0.0; char tmp[16]; /* Inverter status: 0=off 1=on */ memcpy(tmp, fstring+16, 2); tmp[2] = '\0'; inverter = atoi(tmp); /* Charger status: 0=off 1=on */ memcpy(tmp, fstring+18, 2); tmp[2] = '\0'; charger = atoi(tmp); /* Input Voltage. integer number */ memcpy(tmp, fstring+24, 4); tmp[4] = '\0'; vin = atoi(tmp); /* Output Voltage. integer number */ memcpy(tmp, fstring+28, 4); tmp[4] = '\0'; vout = atoi(tmp); /* Iout: int times 10 */ memcpy(tmp, fstring+36, 4); tmp[4] = '\0'; ampsout = ((double)(atoi(tmp)) / 10.0); /* Battery voltage: int times 10 */ memcpy(tmp, fstring+50, 4); tmp[4] = '\0'; vbatt = ((double)(atoi(tmp)) / 10.0); /* Volt-amps out: int */ memcpy(tmp, fstring+40, 6); tmp[6] = '\0'; vaout = atoi(tmp); /* Line status. Bitmask */ memcpy(tmp, fstring+72, 2); tmp[2] = '\0'; linestat = atoi(tmp); /* Alarm status reg 1. Bitmask */ memcpy(tmp, fstring+20, 2); tmp[2] = '\0'; alstat = atoi(tmp); /* Alarm status reg 2. Bitmask */ memcpy(tmp, fstring+22, 2); tmp[2] = '\0'; alstat = alstat | (atoi(tmp) << 8); /* AC line frequency */ memcpy(tmp, fstring+54, 4); tmp[4]= '\0'; acfreq = ((double)(atoi(tmp)) / 100.0); /* Runtime remaining */ memcpy(tmp, fstring+58, 4); tmp[4]= '\0'; btimeleft = atoi(tmp); /* UPS Temperature */ memcpy(tmp, fstring+62, 4); tmp[4]= '\0'; ambtemp = (double)(atoi(tmp)); /* Percent Load */ switch(fc.model) { case ME3100: if (execute("d 16\r", fstring, sizeof(fstring)) > 0) { int l; sscanf(fstring, "16 FullLoad%% %d", &l); loadpercent = (double) l; } break; case RE1800: if (execute("d 16\r", fstring, sizeof(fstring)) > 0) { int l; sscanf(fstring, "16 FullLoad%% %d", &l); loadpercent = (double) l; } if (execute("d 12\r", fstring, sizeof(fstring)) > 0) { int l; sscanf(fstring, "12 HS Temp %dC", &l); hstemp = (double) l; } break; case MD1KVA: if (execute("d 22\r", fstring, sizeof(fstring)) > 0) { int l; sscanf(fstring, "22 FullLoad%% %d", &l); loadpercent = (double) l; } break; default: /* Will never happen, caught in upsdrv_initups() */ fatalx(EXIT_FAILURE, "Unknown model in upsdrv_updateinfo()"); } /* Compute battery percent left based on battery voltages. */ battpercent = ((vbatt - fc.emptyvolts) / (fc.fullvolts - fc.emptyvolts) * 100.0); if (battpercent < 0.0) battpercent = 0.0; else if (battpercent > 100.0) battpercent = 100.0; /* Compute status string */ { int lowbatt, overload, replacebatt, boosting, trimming; lowbatt = alstat & (1<<1); overload = alstat & (1<<6); replacebatt = alstat & (1<<10); boosting = inverter && (linestat & (1<<2)) && (vin < 115); trimming = inverter && (linestat & (1<<2)) && (vin > 115); status_init(); if (inverter) status_set("OB"); else status_set("OL"); if (lowbatt) status_set("LB"); if (trimming) status_set("TRIM"); if (boosting) status_set("BOOST"); if (replacebatt) status_set("RB"); if (overload) status_set("OVER"); status_commit(); } /* FIXME: change to upsdebugx() and friends */ if (debugging) { fprintf(stderr, "Poll: inverter %d charger %d vin %d vout %d vaout %d btimeleft %d\n", inverter, charger, vin, vout, vaout, btimeleft); fprintf(stderr, " ampsout %5.1f vbatt %5.1f batpcnt %5.1f loadpcnt %5.1f upstemp %5.1f acfreq %5.2f ambtemp %5.1f\n", ampsout, vbatt, battpercent, loadpercent, hstemp, acfreq, ambtemp); } /* Stuff information into info structures */ dstate_setinfo("input.voltage", "%05.1f", (double)vin); dstate_setinfo("output.voltage", "%05.1f", (double)vout); dstate_setinfo("battery.charge", "%02.1f", battpercent); dstate_setinfo("ups.load", "%02.1f", loadpercent); dstate_setinfo("battery.voltage", "%02.1f", vbatt); dstate_setinfo("input.frequency", "%05.2f", (double)acfreq); dstate_setinfo("ups.temperature", "%05.1f", (double)hstemp); dstate_setinfo("battery.runtime", "%d", btimeleft); dstate_setinfo("ambient.temperature", "%05.1f", (double)ambtemp); dstate_dataok(); /* Tim: With out this return, it always falls over to the datastate() at the end of the function */ return; } else { dstate_datastale(); } /* if (execute("f\r", fstring, sizeof(fstring)) > 0) */ dstate_datastale(); return; } static void ups_sync(void) { char buf[256]; printf ("Syncing: "); fflush (stdout); /* A bit better sanity might be good here. As is, we expect the human to observe the time being totally not a time. */ if (execute("time\r", buf, sizeof(buf)) > 0) { fprintf(stderr, "UPS Time: %s\n", buf); } else { fatalx(EXIT_FAILURE, "Error connecting to UPS"); } } /* handler for commands to be sent to UPS */ static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* NB: hard-wired password */ ser_send(upsfd, "pw377\r"); /* power off in 1 second and restart when line power returns */ ser_send(upsfd, "off 1 a\r"); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } /* power down the attached load immediately */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = do_loop_shutdown_commands("shutdown.return", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { } void upsdrv_help(void) { } static void sync_serial(void) { char buffer[10]; ser_send(upsfd, "\r"); ser_get_line(upsfd, buffer, sizeof(buffer), '\r', "\012", 3, 0); ser_get_line(upsfd, buffer, sizeof(buffer), ENDCHAR, IGNCHARS, 3, 0); while (ser_get_line(upsfd, buffer, sizeof(buffer), '>', "\012", 3, 0) <= 0) { ser_send(upsfd, "\r"); } } /* Begin code stolen from bestups.c */ static void setup_serial(void) { struct termios tio; if (tcgetattr(upsfd, &tio) == -1) fatal_with_errno(EXIT_FAILURE, "tcgetattr"); tio.c_iflag = IXON | IXOFF; tio.c_oflag = 0; tio.c_cflag = (CS8 | CREAD | HUPCL | CLOCAL); tio.c_lflag = 0; tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; #ifdef HAVE_CFSETISPEED cfsetispeed(&tio, B1200); /* baud change here */ cfsetospeed(&tio, B1200); #else #error This system lacks cfsetispeed() and has no other means to set the speed #endif if (tcsetattr(upsfd, TCSANOW, &tio) == -1) fatal_with_errno(EXIT_FAILURE, "tcsetattr"); /* end code stolen from bestups.c */ sync_serial(); } void upsdrv_initups (void) { char temp[256], fcstring[512]; upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B1200); setup_serial(); ups_sync(); fc.model = UNKNOWN; /* Obtain Model */ if (execute("id\r", fcstring, sizeof(fcstring)) < 1) { fatalx(EXIT_FAILURE, "Failed execute in ups_ident()"); } /* response is a one-line packed string starting with $ */ if (memcmp(fcstring, "Unit", 4)) { fatalx(EXIT_FAILURE, "Bad response from formatconfig command in ups_ident()\n" "id: %s\n", fcstring ); } /* FIXME: upsdebugx() */ if (debugging) fprintf(stderr, "id: %s\n", fcstring); /* chars 4:2 are a two-digit ascii hex enumerated model code */ memcpy(temp, fcstring+9, 2); temp[2] = '\0'; if (memcmp(temp, "ME", 2) == 0) { fc.model = ME3100; } else if ((memcmp(temp, "RE", 2) == 0)) { fc.model = RE1800; } else if (memcmp(temp, "C1", 2) == 0) { /* Better way to identify unit is using "d 15\r", which results in "15 M# MD1KVA", "id\r" yields "Unit ID "C1K03588"" */ fc.model = MD1KVA; } switch(fc.model) { case ME3100: fc.va = 3100; fc.watts = 2200; /* determine shutdown battery voltage */ if (execute("d 29\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "29 LowBat %f", &fc.emptyvolts); } /* determine fully charged battery voltage */ if (execute("d 31\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "31 HiBatt %f", &fc.fullvolts); } fc.fullvolts = 54.20; /* determine "ideal" voltage by a guess */ fc.idealbvolts = ((fc.fullvolts - fc.emptyvolts) * 0.7) + fc.emptyvolts; break; case RE1800: fc.va = 1800; fc.watts = 1200; /* determine shutdown battery voltage */ if (execute("d 29\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "29 LowBat %f", &fc.emptyvolts); } /* determine fully charged battery voltage */ if (execute("d 31\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "31 HiBatt %f", &fc.fullvolts); } fc.fullvolts = 54.20; /* determine "ideal" voltage by a guess */ fc.idealbvolts = ((fc.fullvolts - fc.emptyvolts) * 0.7) + fc.emptyvolts; break; case MD1KVA: fc.va = 1100; fc.watts = 770; /* Approximate, based on 0.7 power factor */ /* determine shutdown battery voltage */ if (execute("d 27\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "27 LowBatt %f", &fc.emptyvolts); } /* determine fully charged battery voltage */ if (execute("d 28\r", fcstring, sizeof(fcstring)) > 0) { sscanf(fcstring, "28 Hi Batt %f", &fc.fullvolts); } fc.fullvolts = 13.70; /* determine "ideal" voltage by a guess */ fc.idealbvolts = ((fc.fullvolts - fc.emptyvolts) * 0.7) + fc.emptyvolts; break; default: fatalx(EXIT_FAILURE, "Unknown model %s in ups_ident()", temp); } fc.valid = 1; return; } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/nutdrv_qx_ablerex.h0000644000175000017500000000206015044656702014646 00000000000000/* nutdrv_qx_ablerex.h - Subdriver for Ablerex Qx protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * 2021 Ablerex Software * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_ABLEREX_H #define NUTDRV_QX_ABLEREX_H #include "nutdrv_qx.h" extern subdriver_t ablerex_subdriver; #endif /* NUTDRV_QX_ABLEREX_H */ nut-2.8.4/drivers/nutdrv_qx_bestups.h0000644000175000017500000000176314670526611014721 00000000000000/* nutdrv_qx_bestups.h - Subdriver for Best Power/Sola Australia UPSes * * Copyright (C) * 2014 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_BESTUPS_H #define NUTDRV_QX_BESTUPS_H #include "nutdrv_qx.h" extern subdriver_t bestups_subdriver; #endif /* NUTDRV_QX_BESTUPS_H */ nut-2.8.4/drivers/ietf-mib.h0000644000175000017500000000025314670526611012607 00000000000000#ifndef IETF_MIB_H #define IETF_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t ietf; extern mib2nut_info_t tripplite_ietf; #endif /* IETF_MIB_H */ nut-2.8.4/drivers/salicru-hid.h0000644000175000017500000000217014777753337013336 00000000000000/* salicru-hid.h - subdriver to monitor Salicru USB/HID devices with NUT * * Copyright (C) * 2003 - 2009 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef SALICRU_HID_H #define SALICRU_HID_H #include "usbhid-ups.h" extern subdriver_t salicru_subdriver; #endif /* SALICRU_HID_H */ nut-2.8.4/drivers/bestpower-mib.h0000644000175000017500000000023114670526611013666 00000000000000#ifndef BESTPOWER_MIB_H #define BESTPOWER_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t bestpower; #endif /* BESTPOWER_MIB_H */ nut-2.8.4/drivers/nutdrv_qx_innovart31.h0000664000175000017500000000176615000733203015226 00000000000000/* nutdrv_qx_innovart31.h - Subdriver for INNOVA RT 3/1 UPSes * * Copyright (C) * 2024 Viktor Drobot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_INNOVART31_H #define NUTDRV_QX_INNOVART31_H #include "nutdrv_qx.h" extern subdriver_t innovart31_subdriver; #endif /* NUTDRV_QX_INNOVART31_H */ nut-2.8.4/drivers/cyberpower-mib.c0000644000175000017500000002512515000601404014017 00000000000000/* cyberpower-mib.c - data to monitor Cyberpower RMCARD * * Copyright (C) 2010 - Eric Schultz * * derived (i.e. basically copied and modified) of bestpower by: * Copyright (C) 2010 - Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "cyberpower-mib.h" #define CYBERPOWER_MIB_VERSION "0.55" #define CYBERPOWER_OID_MODEL_NAME ".1.3.6.1.4.1.3808.1.1.1.1.1.1.0" /* CPS-MIB::ups */ #define CYBERPOWER_SYSOID ".1.3.6.1.4.1.3808.1.1.1" /* Per https://github.com/networkupstools/nut/issues/1997 * some CPS devices offer the shorter vendor OID as sysOID */ #define CYBERPOWER_SYSOID2 ".1.3.6.1.4.1.3808" /* https://www.cyberpowersystems.com/products/software/mib-files/ */ /* Per CPS MIB 2.9 upsBaseOutputStatus OBJECT-TYPE: */ static info_lkp_t cyberpower_power_status[] = { info_lkp_default(2, "OL"), /* onLine */ info_lkp_default(3, "OB"), /* onBattery */ info_lkp_default(4, "OL BOOST"), /* onBoost */ info_lkp_default(5, "OFF"), /* onSleep */ info_lkp_default(6, "OFF"), /* off */ info_lkp_default(7, "OL"), /* rebooting */ info_lkp_default(8, "OL"), /* onECO */ info_lkp_default(9, "OL BYPASS"), /* onBypass */ info_lkp_default(10, "OL TRIM"), /* onBuck */ info_lkp_default(11, "OL OVER"), /* onOverload */ /* Note: a "NULL" string must be last due to snmp-ups.c parser logic */ info_lkp_default(1, "NULL"), /* unknown */ info_lkp_sentinel }; static info_lkp_t cyberpower_battery_status[] = { info_lkp_default(1, ""), /* unknown */ info_lkp_default(2, ""), /* batteryNormal */ info_lkp_default(3, "LB"), /* batteryLow */ info_lkp_sentinel }; static info_lkp_t cyberpower_cal_status[] = { info_lkp_default(1, ""), /* Calibration Successful */ info_lkp_default(2, ""), /* Calibration Invalid */ info_lkp_default(3, "CAL"), /* Calibration in progress */ info_lkp_sentinel }; static info_lkp_t cyberpower_battrepl_status[] = { info_lkp_default(1, ""), /* No battery needs replacing */ info_lkp_default(2, "RB"), /* Batteries need to be replaced */ info_lkp_sentinel }; static info_lkp_t cyberpower_ups_alarm_info[] = { info_lkp_default(1, ""), /* Normal */ info_lkp_default(2, "Temperature too high!"), /* Overheat */ info_lkp_default(3, "Internal UPS fault!"), /* Hardware Fault */ info_lkp_sentinel }; static info_lkp_t cyberpower_transfer_reasons[] = { info_lkp_default(1, "noTransfer"), info_lkp_default(2, "highLineVoltage"), info_lkp_default(3, "brownout"), info_lkp_default(4, "selfTest"), info_lkp_sentinel }; static info_lkp_t cyberpower_testdiag_results[] = { info_lkp_default(1, "Ok"), info_lkp_default(2, "Failed"), info_lkp_default(3, "InvalidTest"), info_lkp_default(4, "TestInProgress"), info_lkp_sentinel }; /* Snmp2NUT lookup table for CyberPower MIB */ static snmp_info_t cyberpower_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "ups", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "CYBERPOWER", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, CYBERPOWER_OID_MODEL_NAME, "CyberPower", SU_FLAG_STATIC, NULL), snmp_info_default("ups.id", ST_FLAG_STRING | ST_FLAG_RW, 8, ".1.3.6.1.4.1.3808.1.1.1.1.1.2.0", "", SU_FLAG_OK | SU_FLAG_STATIC, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.1.2.3.0", "", SU_FLAG_STATIC, NULL), snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.1.2.1.0", "", SU_FLAG_STATIC, NULL), snmp_info_default("ups.mfr.date", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.1.2.2.0", "", 0, NULL), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.4.1.1.0", "", SU_FLAG_OK | SU_STATUS_PWR, &cyberpower_power_status[0]), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.2.1.1.0", "", SU_FLAG_OK | SU_STATUS_BATT, &cyberpower_battery_status[0]), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.7.2.7.0", "", SU_FLAG_OK | SU_STATUS_CAL, &cyberpower_cal_status[0]), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.2.2.5.0", "", SU_FLAG_OK | SU_STATUS_RB, &cyberpower_battrepl_status[0]), snmp_info_default("ups.load", 0, 1.0, ".1.3.6.1.4.1.3808.1.1.1.4.2.3.0", "", 0, NULL), snmp_info_default("ups.temperature", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.10.2.0", "", SU_FLAG_OK, NULL), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.10.1.0", "", SU_FLAG_OK, &cyberpower_ups_alarm_info[0]), /* Battery runtime is expressed in seconds */ snmp_info_default("battery.runtime", 0, 1.0, ".1.3.6.1.4.1.3808.1.1.1.2.2.4.0", "", 0, NULL), /* The elapsed time in seconds since the * UPS has switched to battery power */ snmp_info_default("battery.runtime.elapsed", 0, 1.0, ".1.3.6.1.4.1.3808.1.1.1.2.1.2.0", "", 0, NULL), /* Different generations/models reported "battery.voltage" by different OIDs: */ snmp_info_default("battery.voltage", 0, 0.1, ".1.3.6.1.2.1.33.1.2.5.0", "", 0, NULL), snmp_info_default("battery.voltage", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.2.2.2.0", "", 0, NULL), snmp_info_default("battery.voltage.nominal", 0, 1.0, ".1.3.6.1.4.1.3808.1.1.1.2.2.8.0", "", 0, NULL), /* Different generations/models reported "battery.current" by different OIDs: */ snmp_info_default("battery.current", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.4.2.4.0", "", 0, NULL), snmp_info_default("battery.current", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.2.2.7.0", "", 0, NULL), snmp_info_default("battery.charge", 0, 1.0, ".1.3.6.1.4.1.3808.1.1.1.2.2.1.0", "", 0, NULL), snmp_info_default("battery.temperature", 0, 1.0, ".1.3.6.1.4.1.3808.1.1.1.2.2.3.0", "", 0, NULL), /* upsBaseBatteryLastReplaceDate */ snmp_info_default("battery.date", ST_FLAG_STRING, 8, ".1.3.6.1.4.1.3808.1.1.1.2.1.3.0", "", SU_FLAG_OK | SU_FLAG_SEMI_STATIC, NULL), snmp_info_default("input.voltage", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.3.2.1.0", "", 0, NULL), snmp_info_default("input.frequency", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.3.2.4.0", "", 0, NULL), /* upsAdvanceInputLineFailCause */ snmp_info_default("input.transfer.reason", ST_FLAG_STRING, 1, ".1.3.6.1.4.1.3808.1.1.1.3.2.5.0", "", SU_TYPE_INT | SU_FLAG_OK, &cyberpower_transfer_reasons[0]), snmp_info_default("output.voltage", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.4.2.1.0", "", 0, NULL), snmp_info_default("output.frequency", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.4.2.2.0", "", 0, NULL), snmp_info_default("output.current", 0, 0.1, ".1.3.6.1.4.1.3808.1.1.1.4.2.4.0", "", 0, NULL), /* Delays affecting instant commands */ /* upsAdvanceConfigReturnDelay */ snmp_info_default("ups.delay.start", ST_FLAG_RW, 1.0, ".1.3.6.1.4.1.3808.1.1.1.5.2.9.0", "0", SU_FLAG_OK | SU_TYPE_TIME, NULL), /* Not provided by CPS-MIB */ snmp_info_default("ups.delay.reboot", 0, 1.0, NULL, "0", SU_FLAG_OK | SU_FLAG_ABSENT, NULL), /* upsAdvanceConfigSleepDelay */ snmp_info_default("ups.delay.shutdown", ST_FLAG_RW, 1.0, ".1.3.6.1.4.1.3808.1.1.1.5.2.11.0", "60", SU_FLAG_OK | SU_TYPE_TIME, NULL), /* instant commands. */ /* upsAdvanceControlUpsOff */ snmp_info_default("load.off", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.6.2.1.0", "2", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* upsAdvanceControlTurnOnUPS */ snmp_info_default("load.on", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.6.2.6.0", "2", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* upsAdvanceControlUpsOff */ snmp_info_default("shutdown.stayoff", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.6.2.6.0", "3", SU_TYPE_CMD | SU_FLAG_OK, NULL), #if 0 /* upsBaseControlConserveBattery - note that this command * is not suitable here because it puts ups to sleep only * in battery mode. If power is restored during the shutdown * process, the command is not executed by ups hardware. */ snmp_info_default("shutdown.return", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.6.1.1.0", "2", SU_TYPE_CMD | SU_FLAG_OK, NULL), #endif /* upsAdvanceControlUpsSleep */ snmp_info_default("shutdown.return", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.6.2.3.0", "3", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* upsAdvanceControlSimulatePowerFail */ snmp_info_default("test.failure.start", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.6.2.4.0", "2", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* upsAdvanceTestIndicators */ snmp_info_default("test.panel.start", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.7.2.5.0", "2", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* upsAdvanceTestDiagnostics */ snmp_info_default("test.battery.start", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.7.2.2.0", "2", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* upsAdvanceTestRuntimeCalibration */ snmp_info_default("calibrate.start", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.7.2.6.0", "2", SU_TYPE_CMD | SU_FLAG_OK, NULL), snmp_info_default("calibrate.stop", 0, 1, ".1.3.6.1.4.1.3808.1.1.1.7.2.6.0", "3", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* upsAdvanceTestLastDiagnosticsDate */ snmp_info_default("ups.test.date", ST_FLAG_STRING, 8, ".1.3.6.1.4.1.3808.1.1.1.7.2.4.0", "", SU_FLAG_OK | SU_FLAG_SEMI_STATIC, NULL), /* upsAdvanceTestDiagnosticsResults */ snmp_info_default("ups.test.result", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.3808.1.1.1.7.2.3.0", "", SU_FLAG_OK, &cyberpower_testdiag_results[0]), /* end of structure. */ snmp_info_sentinel } ; mib2nut_info_t cyberpower = { "cyberpower", CYBERPOWER_MIB_VERSION, NULL, CYBERPOWER_OID_MODEL_NAME, cyberpower_mib, CYBERPOWER_SYSOID, NULL }; mib2nut_info_t cyberpower2 = { "cyberpower", CYBERPOWER_MIB_VERSION, NULL, CYBERPOWER_OID_MODEL_NAME, cyberpower_mib, CYBERPOWER_SYSOID2, NULL }; nut-2.8.4/drivers/safenet.c0000644000175000017500000003201415044656702012534 00000000000000/* * safenet.c - model specific routines for following units: * * - Fairstone L525/-625/-750 * - Fenton P400/-600/-800 * - Gemini UPS625/-1000 * - Powerwell PM525A/-625A/-800A/-1000A/-1250A * - Repotec RPF525/-625/-800/-1000 * - Soltec Winmate 525/625/800/1000 * - Sweex 500/1000 * - others using SafeNet software and serial interface * * Status: * 20081102/Revision 1.41 - Arjen de Korte * - allow more time for reading reply to command * 20081106/Revision 1.5 - Arjen de Korte * - changed communication with UPS * - improved handling of battery & system test * 20081228/Revision 1.6 - Arjen de Korte * - add ondelay and offdelay * * Copyright (C) 2003-2008 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "serial.h" #include "safenet.h" #define DRIVER_NAME "Generic SafeNet UPS driver" #define DRIVER_VERSION "1.83" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Arjen de Korte ", DRV_STABLE, { NULL } }; /* * Here we keep the last known status of the UPS */ static union { char reply[10]; struct safenet status; } ups; static long ondelay = 1; /* minutes */ static long offdelay = 30; /* seconds */ static int safenet_command(const char *command) { char reply[32]; size_t i; ssize_t ret; /* * Get rid of whatever is in the in- and output buffers. */ ser_flush_io(upsfd); /* * Send the command and read back the status line. When we just send * a status polling command, it will return the actual status. */ ret = ser_send(upsfd, "%s", command); if (ret < 0) { upsdebug_with_errno(3, "send"); return -1; } if (ret == 0) { upsdebug_with_errno(3, "send: timeout"); return -1; } upsdebugx(3, "send: %.*s", (int)strcspn(command, "\r"), command); /* * Read the reply from the UPS. */ ret = ser_get_buf(upsfd, reply, sizeof(reply), 1, 0); if (ret < 0) { upsdebug_with_errno(3, "read"); return -1; } if (ret == 0) { upsdebugx(3, "read: timeout"); return -1; } upsdebugx(3, "read: %.*s", (int)strcspn(reply, "\r"), reply); /* * We check if the reply looks like a valid status. */ if ((ret != 12) || (reply[0] != '$') || (strspn(reply+1, "AB") != 10)) { return -1; } for (i = 0; i < 10; i++) { ups.reply[i] = ((reply[i+1] == 'B') ? 1 : 0); } return 0; } static void safenet_update(void) { status_init(); if (ups.status.onbattery) { status_set("OB"); } else { status_set("OL"); } if (ups.status.batterylow) { status_set("LB"); } if (ups.status.overload) { status_set("OVER"); } if (ups.status.batteryfail) { status_set("RB"); } if (ups.status.systemtest) { status_set("CAL"); } alarm_init(); if (ups.status.systemfail) { alarm_set("System selftest fail!"); } alarm_commit(); status_commit(); } static int instcmd(const char *cmdname, const char *extra) { if (!strcasecmp(cmdname, "beeper.off")) { /* compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.off' command has been renamed to 'beeper.mute' for this driver"); return instcmd("beeper.mute", NULL); } if (!strcasecmp(cmdname, "beeper.on")) { /* compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.on' command has been renamed to 'beeper.enable'"); return instcmd("beeper.enable", NULL); } /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); /* * Start the UPS selftest */ if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if (safenet_command(COM_BATT_TEST)) { return STAT_INSTCMD_FAILED; } else { return STAT_INSTCMD_HANDLED; } } /* * Stop the UPS selftest */ if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if (safenet_command(COM_STOP_TEST)) { return STAT_INSTCMD_FAILED; } else { return STAT_INSTCMD_HANDLED; } } /* * Start simulated mains failure */ if (!strcasecmp (cmdname, "test.failure.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if (safenet_command(COM_MAINS_TEST)) { return STAT_INSTCMD_FAILED; } else { return STAT_INSTCMD_HANDLED; } } /* * Stop simulated mains failure */ if (!strcasecmp (cmdname, "test.failure.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if (safenet_command(COM_STOP_TEST)) { return STAT_INSTCMD_FAILED; } else { return STAT_INSTCMD_HANDLED; } } /* * If beeper is off, toggle beeper state (so it should be ON after this) */ if (!strcasecmp(cmdname, "beeper.enable")) { if (ups.status.silenced && safenet_command(COM_TOGGLE_BEEP)) { return STAT_INSTCMD_FAILED; } else { return STAT_INSTCMD_HANDLED; } } /* * If beeper is not off, toggle beeper state (so it should be OFF after this) * Unfortunately, this only mutes the beeper, it turns back on for the next * event automatically (no way to stop this, besides side cutters) */ if (!strcasecmp(cmdname, "beeper.mute")) { if (!ups.status.silenced && safenet_command(COM_TOGGLE_BEEP)) { return STAT_INSTCMD_FAILED; } else { return STAT_INSTCMD_HANDLED; } } /* * Toggle beeper state unconditionally */ if (!strcasecmp(cmdname, "beeper.toggle")) { if (safenet_command(COM_TOGGLE_BEEP)) { return STAT_INSTCMD_FAILED; } else { return STAT_INSTCMD_HANDLED; } } /* * Shutdown and wait for the power to return */ if (!strcasecmp(cmdname, "shutdown.return")) { char command[] = SHUTDOWN_RETURN; command[4] += ((offdelay % 1000) / 100); command[5] += ((offdelay % 100) / 10); command[6] += (offdelay % 10); upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); safenet_command(command); return STAT_INSTCMD_HANDLED; } /* * Shutdown and reboot */ if (!strcasecmp(cmdname, "shutdown.reboot")) { char command[] = SHUTDOWN_REBOOT; command[3] += ((offdelay % 1000) / 100); command[4] += ((offdelay % 100) / 10); command[5] += (offdelay % 10); command[7] += ((ondelay % 10000) / 1000); command[8] += ((ondelay % 1000) / 100); command[9] += ((ondelay % 100) / 10); command[10] += (ondelay % 10); upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); safenet_command(command); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_initinfo(void) { int retry = 3; char *v; usleep(100000); /* * Very crude hardware detection. If an UPS is attached, it will set DSR * to 1. Bail out if it isn't. */ if (!ser_get_dsr(upsfd)) { fatalx(EXIT_FAILURE, "Serial cable problem or nothing attached to %s", device_path); } /* * Initialize the serial interface of the UPS by sending the magic * string. If it does not respond with a valid status reply, * display an error message and give up. */ while (safenet_command(COM_INITIALIZE)) { if (--retry) { continue; } fatalx(EXIT_FAILURE, "SafeNet protocol compatible UPS not found on %s", device_path); } /* * Read the commandline settings for the following parameters, since we can't * autodetect them. */ dstate_setinfo("ups.mfr", "%s", ((v = getval("manufacturer")) != NULL) ? v : "unknown"); dstate_setinfo("ups.model", "%s", ((v = getval("modelname")) != NULL) ? v : "unknown"); dstate_setinfo("ups.serial", "%s", ((v = getval("serialnumber")) != NULL) ? v : "unknown"); dstate_setinfo("ups.delay.start", "%ld", 60 * ondelay); dstate_setinfo("ups.delay.shutdown", "%ld", offdelay); /* * These are the instant commands we support. */ dstate_addcmd ("test.battery.start"); dstate_addcmd ("test.battery.stop"); dstate_addcmd ("test.failure.start"); dstate_addcmd ("test.failure.stop"); dstate_addcmd ("beeper.on"); dstate_addcmd ("beeper.off"); dstate_addcmd ("beeper.enable"); dstate_addcmd ("beeper.mute"); dstate_addcmd ("beeper.toggle"); dstate_addcmd ("shutdown.return"); dstate_addcmd ("shutdown.reboot"); upsh.instcmd = instcmd; } /* * The status polling commands are *almost* random. Whatever the reason * is, there is a certain pattern in them. The first character after the * start character 'Z' determines how many positions there are between * that character and the single 'L' character that's in each command (A=0, * B=1,...,J=9). The rest is filled with random (?) data [A...J]. But why? * No idea. The UPS *does* check if the polling commands match this format. * And as the SafeNet software uses "random" polling commands, so do we. * * Note: if you don't use ASCII, the characters will be different! */ void upsdrv_updateinfo(void) { char command[] = COM_POLL_STAT; int i; static int retry = 0; /* * Fill the command portion with random characters from the range * [A...J]. */ for (i = 1; i < 12; i++) { command[i] = (random() % 10) + 'A'; } /* * Find which character must be an 'L' and put it there. */ command[command[1]-'A'+2] = 'L'; /* * Do a status poll. */ if (safenet_command(command)) { ser_comm_fail("Status read failed"); if (retry < 2) { retry++; } else { dstate_datastale(); } return; } ser_comm_good(); retry = 0; if (ups.status.systemtest && ups.status.batterylow) { /* * Don't update status after stopping battery test, to * allow UPS to update the status flags (OB+LB glitch) */ if (safenet_command(COM_STOP_TEST)) { upslogx(LOG_WARNING, "Can't terminate battery test!"); } else { upslogx(LOG_INFO, "Battery test finished"); return; } } safenet_update(); dstate_dataok(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int retry = 3; /* * Since we may have arrived here before the hardware is initialized, * try to initialize it here. * * Initialize the serial interface of the UPS by sending the magic * string. If it does not respond with a valid status reply, * display an error message and give up. */ while (safenet_command(COM_INITIALIZE)) { if (--retry) { continue; } upslogx(LOG_ERR, "SafeNet protocol compatible UPS not found on %s", device_path); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); return; } /* * Since the UPS will happily restart on battery, we must use a * different shutdown command depending on the line status, so * we need to check the status of the UPS here. */ if (ups.status.onbattery) { instcmd("shutdown.return", NULL); } else { instcmd("shutdown.reboot", NULL); } } void upsdrv_help(void) { } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "manufacturer", "manufacturer [unknown]"); addvar(VAR_VALUE, "modelname", "modelname [unknown]"); addvar(VAR_VALUE, "serialnumber", "serialnumber [unknown]"); addvar(VAR_VALUE, "ondelay", "Delay before UPS startup (minutes)"); addvar(VAR_VALUE, "offdelay", "Delay before UPS shutdown (seconds)"); } void upsdrv_initups(void) { struct termios tio; const char *val; /* * Open and lock the serial port and set the speed to 1200 baud. */ upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B1200); if (tcgetattr(upsfd, &tio)) { fatal_with_errno(EXIT_FAILURE, "tcgetattr"); } /* * Use canonical mode input processing (to read reply line) */ tio.c_lflag |= ICANON; /* Canonical input (erase and kill processing) */ tio.c_cc[VEOF] = _POSIX_VDISABLE; tio.c_cc[VEOL] = '\r'; tio.c_cc[VERASE] = _POSIX_VDISABLE; tio.c_cc[VINTR] = _POSIX_VDISABLE; tio.c_cc[VKILL] = _POSIX_VDISABLE; tio.c_cc[VQUIT] = _POSIX_VDISABLE; tio.c_cc[VSUSP] = _POSIX_VDISABLE; tio.c_cc[VSTART] = _POSIX_VDISABLE; tio.c_cc[VSTOP] = _POSIX_VDISABLE; if (tcsetattr(upsfd, TCSANOW, &tio)) { fatal_with_errno(EXIT_FAILURE, "tcsetattr"); } /* * Set DTR and clear RTS to provide power for the serial interface. */ ser_set_dtr(upsfd, 1); ser_set_rts(upsfd, 0); val = getval("ondelay"); if (val) { ondelay = strtol(val, NULL, 10); } if ((ondelay < 0) || (ondelay > 9999)) { fatalx(EXIT_FAILURE, "Start delay '%ld' out of range [0..9999]", ondelay); } val = getval("offdelay"); if (val) { offdelay = strtol(val, NULL, 10); } if ((offdelay < 0) || (offdelay > 999)) { fatalx(EXIT_FAILURE, "Shutdown delay '%ld' out of range [0..999]", offdelay); } } void upsdrv_cleanup(void) { ser_set_dtr(upsfd, 0); ser_close(upsfd, device_path); } nut-2.8.4/drivers/generic_modbus.h0000644000175000017500000000526014777753336014121 00000000000000/* generic_modbus.h - Driver for generic UPS connected via modbus RIO * * Copyright (C) * 2021 Dimitris Economou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUT_GENERIC_MODBUS_H #define NUT_GENERIC_MODBUS_H /* UPS device details */ #define DEVICE_MFR "UNKNOWN" #define DEVICE_MODEL "unknown" /* serial access parameters */ #define BAUD_RATE 9600 #define PARITY 'N' #define DATA_BIT 8 #define STOP_BIT 1 /* * modbus response and byte timeouts * us: 1 - 999999 */ #define MODRESP_TIMEOUT_s 0 #define MODRESP_TIMEOUT_us 200000 #define MODBYTE_TIMEOUT_s 0 #define MODBYTE_TIMEOUT_us 50000 /* modbus access parameters */ #define MODBUS_SLAVE_ID 5 /* shutdown repeat on error */ #define FSD_REPEAT_CNT 3 /* shutdown repeat interval in ms */ #define FSD_REPEAT_INTRV 1500 /* definition of register type */ enum regtype { COIL = 0, INPUT_B, INPUT_R, HOLDING }; typedef enum regtype regtype_t; /* UPS device state enum */ enum devstate { OL_T = 0, OB_T, LB_T, HB_T, RB_T, CHRG_T, DISCHRG_T, BYPASS_T, CAL_T, OFF_T, OVER_T, TRIM_T, BOOST_T, FSD_T }; typedef enum devstate devstate_t; /* UPS state signal attributes */ struct sigattr { int addr; /* register address */ regtype_t type; /* register type */ int noro; /* 1: normally open contact 0: normally closed contact. */ /* noro is used to indicate the logical ON or OFF in regard of the contact state. if noro is set to 1 then ON corresponds to an open contact */ }; typedef struct sigattr sigattr_t; #define NUMOF_SIG_STATES 14 #define NOTUSED -1 /* define the duration of the shutdown pulse */ #define SHTDOWN_PULSE_DURATION NOTUSED /* * associate PULS signals to NUT device states * * Ready contact <--> 1:HB, 0:CHRG * Buffering contact <--> 1:OB, 0:OL * Battery-low <--> 1:LB * Replace Battery <--> 1:RB * Inhibit buffering <--> 1:FSD */ #endif /* NUT_GENERIC_MODBUS_H */ nut-2.8.4/drivers/nutdrv_qx_megatec-old.c0000644000175000017500000001501414777753337015421 00000000000000/* nutdrv_qx_megatec-old.c - Subdriver for Megatec/old protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_megatec-old.h" #define MEGATEC_OLD_VERSION "Megatec/old 0.08" /* qx2nut lookup table */ static item_t megatec_old_qx2nut[] = { /* * > [D\r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000\r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ { "input.voltage", 0, NULL, "D\r", "", 47, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.voltage.fault", 0, NULL, "D\r", "", 47, '(', "", 7, 11, "%.1f", 0, NULL, NULL, NULL }, { "output.voltage", 0, NULL, "D\r", "", 47, '(', "", 13, 17, "%.1f", 0, NULL, NULL, NULL }, { "ups.load", 0, NULL, "D\r", "", 47, '(', "", 19, 21, "%.0f", 0, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "D\r", "", 47, '(', "", 23, 26, "%.1f", 0, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "D\r", "", 47, '(', "", 28, 31, "%.2f", 0, NULL, NULL, qx_multiply_battvolt }, { "ups.temperature", 0, NULL, "D\r", "", 47, '(', "", 33, 36, "%.1f", 0, NULL, NULL, NULL }, /* Status bits */ { "ups.status", 0, NULL, "D\r", "", 47, '(', "", 38, 38, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Utility Fail (Immediate) */ { "ups.status", 0, NULL, "D\r", "", 47, '(', "", 39, 39, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Battery Low */ { "ups.status", 0, NULL, "D\r", "", 47, '(', "", 40, 40, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Bypass/Boost or Buck Active */ { "ups.alarm", 0, NULL, "D\r", "", 47, '(', "", 41, 41, NULL, 0, NULL, NULL, blazer_process_status_bits }, /* UPS Failed */ { "ups.type", 0, NULL, "D\r", "", 47, '(', "", 42, 42, "%s", QX_FLAG_STATIC, NULL, NULL, blazer_process_status_bits }, /* UPS Type */ { "ups.status", 0, NULL, "D\r", "", 47, '(', "", 43, 43, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Test in Progress */ { "ups.status", 0, NULL, "D\r", "", 47, '(', "", 44, 44, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Shutdown Active */ { "ups.beeper.status", 0, NULL, "D\r", "", 47, '(', "", 45, 45, "%s", 0, NULL, NULL, blazer_process_status_bits }, /* Beeper status */ /* * > [F\r] * < [#220.0 000 024.0 50.0\r] * 0123456789012345678901 * 0 1 2 */ { "input.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 1, 5, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.current.nominal", 0, NULL, "F\r", "", 22, '#', "", 7, 9, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "battery.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 11, 15, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.frequency.nominal", 0, NULL, "F\r", "", 22, '#', "", 17, 20, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, /* * > [I\r] * < [#------------- ------ VT12046Q \r] * 012345678901234567890123456789012345678 * 0 1 2 3 */ { "device.mfr", 0, NULL, "I\r", "", 39, '#', "", 1, 15, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "device.model", 0, NULL, "I\r", "", 39, '#', "", 17, 26, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "ups.firmware", 0, NULL, "I\r", "", 39, '#', "", 28, 37, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* Instant commands */ { "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%sR0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, blazer_r_ondelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_ONDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, blazer_r_offdelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_OFFDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* Testing table */ #ifdef TESTING static testing_t megatec_old_testing[] = { { "D\r", "(215.0 195.0 230.0 014 49.0 22.7 30.0 00000000\r", -1 }, { "F\r", "#230.0 000 024.0 50.0\r", -1 }, { "I\r", "#NOT_A_LIVE_UPS TESTING TESTING \r", -1 }, { "Q\r", "", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0000\r", "", -1 }, { "T04\r", "", -1 }, { "TL\r", "", -1 }, { "T\r", "", -1 }, { "CT\r", "", -1 }, { NULL } }; #endif /* TESTING */ /* Subdriver-specific initups */ static void megatec_old_initups(void) { blazer_initups(megatec_old_qx2nut); } /* Subdriver interface */ subdriver_t megatec_old_subdriver = { MEGATEC_OLD_VERSION, blazer_claim_light, megatec_old_qx2nut, megatec_old_initups, NULL, blazer_makevartable, "ACK", NULL, #ifdef TESTING megatec_old_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/upsdrvctl.c0000644000175000017500000015417115021264277013143 00000000000000/* upsdrvctl.c - UPS driver controller Copyright (C) 2001 Russell Kroll 2005 - 2017 Arnaud Quette 2017 - 2025 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be the first header */ #include #include #include #include #include #ifndef WIN32 #include #else /* WIN32 */ #include "wincompat.h" #endif /* WIN32 */ #include "proto.h" #include "common.h" #include "upsconf.h" #include "attribute.h" #include "nut_stdint.h" #include "main.h" #include "upsdrvquery.h" typedef struct { char *upsname; char *driver; char *port; int sdorder; int maxstartdelay; int maxretry; int retrydelay; int exceeded_timeout; #ifndef WIN32 pid_t pid; #else /* WIN32 */ int pid; /* for WIN32 used just as a flag that this UPS was started by this tool in this run */ #endif /* WIN32 */ void *next; } ups_t; static ups_t *upstable = NULL; static int upscount = 0; static int maxsdorder = 0, testmode = 0, exec_error = 0, exec_timeout = 0; /* Should we wait for driver (1) or "parallelize" drivers start (0) */ static int waitfordrivers = 1; /* timer - keeps us from getting stuck if a driver hangs * NOTE: Default value is also documented in man page */ static int maxstartdelay = 75; /* counter - try that many time(s) to start the driver if it fails to * Named "retry" but is actually a max attempts count, should be at least 1. * NOTE: Default value is also documented in man page */ static int maxretry = 1; /* timer - delay between each restart attempt of the driver(s) * NOTE: Default value is also documented in man page */ static int retrydelay = 5; /* Directory where driver executables live */ static char *driverpath = NULL; /* passthrough to the drivers: chroot path and new user name; signal/command */ static char *pt_root = NULL, *pt_user = NULL, *pt_cmd = NULL; /* flag to pass nut_debug_level to launched drivers (as their -D... args) */ static int nut_debug_level_passthrough = 0; static int nut_foreground_passthrough = -1; /* Keep track of requested operation (function pointer) */ static void (*command)(const ups_t *) = NULL; /* signal handling */ int exit_flag = 0; #ifndef WIN32 static int reload_flag = 0; static time_t last_dangerous_reload = 0; #endif /* !WIN32 */ #ifndef WIN32 static int signal_flag = 0; #else /* WIN32 */ static char *signal_flag = NULL; #endif /* WIN32 */ void do_upsconf_args(char *arg_upsname, char *var, char *val) { ups_t *tmp, *last; /* handle global declarations */ if (!arg_upsname) { if (!strcmp(var, "maxstartdelay")) maxstartdelay = atoi(val); if (!strcmp(var, "driverpath")) { free(driverpath); driverpath = xstrdup(val); } if (!strcmp(var, "maxretry")) { maxretry = atoi(val); if (maxretry < 0) { upsdebugx(0, "NOTE: invalid 'maxretry' setting ignored: %s", NUT_STRARG(val)); maxretry = 1; } } if (!strcmp(var, "retrydelay")) retrydelay = atoi(val); if (!strcmp(var, "nowait")) { char * s = getenv("NUT_IGNORE_NOWAIT"); if (s && !strcmp(s, "true")) { upsdebugx(0, "NOTE: 'nowait' setting ignored due to NUT_IGNORE_NOWAIT envvar"); } else { waitfordrivers = 0; } } /* ignore anything else - it's probably for main */ return; } last = tmp = upstable; while (tmp) { last = tmp; if (!strcmp(tmp->upsname, arg_upsname)) { if (!strcmp(var, "driver")) tmp->driver = xstrdup(val); if (!strcmp(var, "port")) tmp->port = xstrdup(val); if (!strcmp(var, "maxstartdelay")) tmp->maxstartdelay = atoi(val); if (!strcmp(var, "maxretry")) { tmp->maxretry = atoi(val); if (maxretry < 0) { upsdebugx(0, "NOTE: invalid 'maxretry' setting ignored for %s: %s", tmp->upsname, NUT_STRARG(val)); tmp->maxretry = -1; /* use global value by default */ } } if (!strcmp(var, "retrydelay")) tmp->retrydelay = atoi(val); if (!strcmp(var, "sdorder")) { tmp->sdorder = atoi(val); if (tmp->sdorder > maxsdorder) maxsdorder = tmp->sdorder; } return; } tmp = tmp->next; } tmp = xmalloc(sizeof(ups_t)); tmp->upsname = xstrdup(arg_upsname); tmp->driver = NULL; tmp->port = NULL; tmp->pid = -1; tmp->next = NULL; tmp->sdorder = 0; tmp->maxstartdelay = -1; /* use global value by default */ tmp->maxretry = -1; /* use global value by default */ tmp->retrydelay = -1; /* use global value by default */ tmp->exceeded_timeout = 0; if (!strcmp(var, "driver")) tmp->driver = xstrdup(val); if (!strcmp(var, "port")) tmp->port = xstrdup(val); if (last) last->next = tmp; else upstable = tmp; } static void signal_driver_cmd(const ups_t *ups, #ifndef WIN32 int cmd #else /* WIN32 */ const char *cmd #endif /* WIN32 */ ) { #ifndef WIN32 /* TODO: implement WIN32: https://github.com/networkupstools/nut/issues/1916 * Currently the codepath is not implemented below */ char pidfn[NUT_PATH_MAX + 1]; #endif /* !WIN32 */ int ret; #ifndef WIN32 if (cmd == SIGCMD_RELOAD_OR_ERROR || cmd == SIGCMD_EXIT) #else /* WIN32 */ if (cmd && (!strcmp(cmd, SIGCMD_RELOAD_OR_ERROR) || !strcmp(cmd, SIGCMD_EXIT))) #endif /* WIN32 */ { /* not a signal, use socket protocol */ char buf[LARGEBUF], cmdbuf[LARGEBUF]; struct timeval tv; char *cmdname = NULL; #ifndef WIN32 if (cmd == SIGCMD_RELOAD_OR_ERROR) #else /* WIN32 */ if (!strcmp(cmd, SIGCMD_RELOAD_OR_ERROR)) #endif /* WIN32 */ cmdname = "reload-or-error"; else #ifndef WIN32 if (cmd == SIGCMD_EXIT) #else /* WIN32 */ if (!strcmp(cmd, SIGCMD_EXIT)) #endif /* WIN32 */ cmdname = "exit"; upsdebugx(1, "Signalling UPS [%s]: driver.%s", ups->upsname, NUT_STRARG(cmdname)); if (testmode || !cmdname) return; /* Post the query and wait for reply */ /* FIXME: coordinate with pollfreq? */ tv.tv_sec = 15; tv.tv_usec = 0; snprintf(cmdbuf, sizeof(cmdbuf), "INSTCMD driver.%s\n", cmdname); ret = upsdrvquery_oneshot(ups->driver, ups->upsname, cmdbuf, buf, sizeof(buf), &tv); if (ret < 0) { goto socket_error; } else { upslogx(LOG_INFO, "Request for driver to %s returned code %d", cmdname, ret); if (ret != STAT_INSTCMD_HANDLED) exec_error++; /* TODO: Propagate "ret" to caller, eventually CLI exit-code? */ } return; socket_error: upslog_with_errno(LOG_ERR, "Socket dialog with the other driver instance"); exec_error++; return; } #ifndef WIN32 /* TODO: implement WIN32: https://github.com/networkupstools/nut/issues/1916 */ /* NUT_WIN32_INCOMPLETE : handle generally signalling the UPS */ /* Real signals */ # ifndef WIN32 upsdebugx(1, "Signalling UPS [%s]: %d (%s)", ups->upsname, cmd, strsignal(cmd)); # else /* WIN32 */ upsdebugx(1, "Signalling UPS [%s]: %s", ups->upsname, cmd); # endif /* WIN32 */ # ifndef WIN32 if (ups->pid == -1) { struct stat fs; snprintf(pidfn, sizeof(pidfn), "%s/%s-%s.pid", altpidpath(), ups->driver, ups->upsname); ret = stat(pidfn, &fs); if ((ret != 0) && (ups->port != NULL)) { upslog_with_errno(LOG_ERR, "Can't open %s", pidfn); snprintf(pidfn, sizeof(pidfn), "%s/%s-%s.pid", altpidpath(), ups->driver, xbasename(ups->port)); ret = stat(pidfn, &fs); } if (ret != 0) { upslog_with_errno(LOG_ERR, "Can't open %s either", pidfn); exec_error++; return; } } else { /* We started the driver in this run of upsdrvctl * tool, stayed foregrounded, and now are singnalling * the driver(s) tracked by this process. * NOTE: Not a filename here, but using same variable * name makes the code below simpler to maintain. */ snprintf(pidfn, sizeof(pidfn), "PID %" PRIdMAX, (intmax_t)ups->pid); } # else /* WIN32 */ snprintf(pidfn, sizeof(pidfn), "%s-%s", ups->driver, ups->upsname); # endif /* WIN32 */ upsdebugx(2, "Sending signal to %s", pidfn); if (testmode) return; /* Hush the fopen(pidfile) message but let "real errors" be seen */ nut_sendsignal_debug_level = NUT_SENDSIGNAL_DEBUG_LEVEL_KILL_SIG0PING - 1; # ifndef WIN32 if (ups->pid == -1) { ret = sendsignalfn(pidfn, cmd, ups->driver, 0); } else { ret = sendsignalpid(ups->pid, cmd, ups->driver, 0); /* reap zombie if this child died */ if (waitpid(ups->pid, NULL, WNOHANG) == ups->pid) { upslog_with_errno(LOG_WARNING, "Child process %s exited; signal return code is %d", pidfn, ret); } } # else /* WIN32 */ ret = sendsignal(pidfn, cmd, 0); # endif /* WIN32 */ /* Restore the signal errors verbosity */ nut_sendsignal_debug_level = NUT_SENDSIGNAL_DEBUG_LEVEL_DEFAULT; if (ret < 0) { upslog_with_errno(LOG_ERR, "Signalling %s failed: %d", pidfn, ret); exec_error++; } #else /* WIN32 */ NUT_WIN32_INCOMPLETE_LOGWARN(); #endif /* WIN32: https://github.com/networkupstools/nut/issues/1916 */ } /* handle generally signalling the UPS with recently raised signal */ static void signal_driver(const ups_t *ups) { signal_driver_cmd(ups, signal_flag); } /* handle sending the signal */ static void stop_driver(const ups_t *ups) { char pidfn[NUT_PATH_MAX + 1]; int ret, i; upsdebugx(1, "Stopping UPS: %s", ups->upsname); #ifndef WIN32 if (ups->pid == -1) { struct stat fs; snprintf(pidfn, sizeof(pidfn), "%s/%s-%s.pid", altpidpath(), ups->driver, ups->upsname); ret = stat(pidfn, &fs); if ((ret != 0) && (ups->port != NULL)) { upslog_with_errno(LOG_ERR, "Can't open %s", pidfn); snprintf(pidfn, sizeof(pidfn), "%s/%s-%s.pid", altpidpath(), ups->driver, xbasename(ups->port)); ret = stat(pidfn, &fs); } if (ret != 0) { upslog_with_errno(LOG_ERR, "Can't open %s either", pidfn); exec_error++; return; } } else { /* We started the driver in this run of upsdrvctl * tool, stayed foregrounded, and now are exiting. * NOTE: Not a filename here, but using same variable * name makes the code below simpler to maintain. */ snprintf(pidfn, sizeof(pidfn), "PID %" PRIdMAX, (intmax_t)ups->pid); } #else /* WIN32 */ snprintf(pidfn, sizeof(pidfn), "%s-%s", ups->driver, ups->upsname); #endif /* WIN32 */ upsdebugx(2, "Sending signal to %s", pidfn); if (testmode) return; /* Hush the fopen(pidfile) message but let "real errors" be seen */ nut_sendsignal_debug_level = NUT_SENDSIGNAL_DEBUG_LEVEL_KILL_SIG0PING - 1; #ifndef WIN32 if (ups->pid == -1) { ret = sendsignalfn(pidfn, SIGTERM, ups->driver, 0); } else { ret = sendsignalpid(ups->pid, SIGTERM, ups->driver, 0); /* reap zombie if this child died */ if (waitpid(ups->pid, NULL, WNOHANG) == ups->pid) { goto clean_return; } } #else /* WIN32 */ ret = sendsignal(pidfn, COMMAND_STOP, 0); #endif /* WIN32 */ if (ret < 0) { #ifndef WIN32 upsdebugx(2, "SIGTERM to %s failed, retrying with SIGKILL", pidfn); if (ups->pid == -1) { ret = sendsignalfn(pidfn, SIGKILL, ups->driver, 0); } else { ret = sendsignalpid(ups->pid, SIGKILL, ups->driver, 0); /* reap zombie if this child died */ if (waitpid(ups->pid, NULL, WNOHANG) == ups->pid) { goto clean_return; } } #else /* WIN32 */ upsdebugx(2, "Stopping %s failed, retrying again", pidfn); ret = sendsignal(pidfn, COMMAND_STOP, 0); #endif /* WIN32 */ if (ret < 0) { upslog_with_errno(LOG_ERR, "Stopping %s failed", pidfn); exec_error++; goto clean_return; } } for (i = 0; i < 5 ; i++) { #ifndef WIN32 if (ups->pid == -1) { ret = sendsignalfn(pidfn, 0, ups->driver, 0); } else { /* reap zombie if this child died */ if (waitpid(ups->pid, NULL, WNOHANG) == ups->pid) { goto clean_return; } ret = sendsignalpid(ups->pid, 0, ups->driver, 0); } #else /* WIN32 */ ret = sendsignalfn(pidfn, 0, ups->driver, 0); #endif /* WIN32 */ if (ret != 0) { upsdebugx(2, "Sending signal to %s failed, driver is finally down or wrongly owned", pidfn); goto clean_return; } sleep(1); } #ifndef WIN32 upslog_with_errno(LOG_ERR, "Stopping %s failed, retrying harder", pidfn); if (ups->pid == -1) { ret = sendsignalfn(pidfn, SIGKILL, ups->driver, 0); } else { /* reap zombie if this child died */ if (waitpid(ups->pid, NULL, WNOHANG) == ups->pid) { goto clean_return; } ret = sendsignalpid(ups->pid, SIGKILL, ups->driver, 0); } #else /* WIN32 */ upslog_with_errno(LOG_ERR, "Stopping %s failed, retrying again", pidfn); ret = sendsignal(pidfn, COMMAND_STOP, 0); #endif /* WIN32 */ if (ret == 0) { for (i = 0; i < 5 ; i++) { #ifndef WIN32 if (ups->pid == -1) { ret = sendsignalfn(pidfn, 0, ups->driver, 0); } else { /* reap zombie if this child died */ if (waitpid(ups->pid, NULL, WNOHANG) == ups->pid) { goto clean_return; } ret = sendsignalpid(ups->pid, 0, ups->driver, 0); } #else /* WIN32 */ ret = sendsignalfn(pidfn, 0, ups->driver, 0); #endif /* WIN32 */ if (ret != 0) { upsdebugx(2, "Sending signal to %s failed, driver is finally down or wrongly owned", pidfn); /* While a TERMinated driver cleans up, * a stuck and KILLed one does not, so: */ if (ups->pid == -1) { unlink(pidfn); } goto clean_return; } sleep(1); } } upslog_with_errno(LOG_ERR, "Stopping %s failed", pidfn); exec_error++; clean_return: /* Restore the signal errors verbosity */ nut_sendsignal_debug_level = NUT_SENDSIGNAL_DEBUG_LEVEL_DEFAULT; } void set_exit_flag(const int sig) { exit_flag = sig; } static void set_signal_flag(const #ifndef WIN32 int #else /* WIN32 */ char * #endif /* WIN32 */ sig ) { /* non-const, so some casting trickery */ signal_flag = ( #ifndef WIN32 int #else /* WIN32 */ char * #endif /* WIN32 */ )sig; } static void reset_signal_flag(void) { #ifndef WIN32 set_signal_flag(0); #else /* WIN32 */ set_signal_flag(NULL); #endif /* WIN32 */ } #ifndef WIN32 /* TODO NUT_WIN32_INCOMPLETE : Equivalent for WIN32 - see SIGCMD_RELOAD in upsd and upsmon */ static void set_reload_flag(const #ifndef WIN32 int #else /* WIN32 */ char * #endif /* WIN32 */ sig ) { set_signal_flag(sig); switch (sig) { case SIGCMD_RELOAD_OR_EXIT: /* SIGUSR1 */ /* reload-or-exit (this driver instance may die) */ reload_flag = 2; break; # ifdef SIGCMD_RELOAD_OR_RESTART case SIGCMD_RELOAD_OR_RESTART: /* SIGUSR2 */ /* reload-or-restart (this driver instance may recycle itself) */ /* FIXME: Not implemented yet */ reload_flag = 3; break; # endif case SIGCMD_EXIT: /* Not even a signal, but a socket protocol action */ reload_flag = 15; break; case SIGCMD_RELOAD: /* SIGHUP */ case SIGCMD_RELOAD_OR_ERROR: /* Not even a signal, but a socket protocol action */ default: /* reload what we can, log what needs a restart so skipped */ reload_flag = 1; } upsdebugx(1, "%s: raising reload flag due to signal %d (%s) => reload_flag=%d", __func__, sig, strsignal(sig), reload_flag); } #endif /* !WIN32 */ static void setup_signals(void) { #ifndef WIN32 struct sigaction sa; #endif /* !WIN32 */ set_exit_flag(0); reset_signal_flag(); #ifndef WIN32 /* Keep in sync with signal handling in drivers/main.c */ sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = set_exit_flag; sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRICT_PROTOTYPES) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wstrict-prototypes" #endif sa.sa_handler = SIG_IGN; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRICT_PROTOTYPES) # pragma GCC diagnostic pop #endif sigaction(SIGPIPE, &sa, NULL); /* handle reloading */ sa.sa_handler = set_reload_flag; sigaction(SIGCMD_RELOAD, &sa, NULL); /* SIGHUP */ sigaction(SIGCMD_RELOAD_OR_EXIT, &sa, NULL); /* SIGUSR1 */ # ifdef SIGCMD_RELOAD_OR_RESTART /* FIXME: Want SIGCMD_RELOAD_OR_RESTART implemented */ sigaction(SIGCMD_RELOAD_OR_RESTART, &sa, NULL); /* SIGUSR2 */ # endif # ifdef SIGCMD_DATA_DUMP /* handle run-time data dump (may be limited to non-backgrounding lifetimes) */ sa.sa_handler = set_signal_flag; sigaction(SIGCMD_DATA_DUMP, &sa, NULL); /* SIGURG or SIGWINCH something else on obscure systems */ # endif #else /* WIN32 */ NUT_WIN32_INCOMPLETE_MAYBE_NOT_APPLICABLE(); #endif /* WIN32 */ } #ifndef WIN32 static void waitpid_timeout(const int sig) { NUT_UNUSED_VARIABLE(sig); /* do nothing */ return; } #endif /* !WIN32 */ /* print out a command line at the given debug level. */ static void debugcmdline(int level, const char *msg, char *const argv[]) { char cmdline[LARGEBUF]; snprintf(cmdline, sizeof(cmdline), "%s", msg); while (*argv) { snprintfcat(cmdline, sizeof(cmdline), " %s", *argv++); } upsdebugx(level, "%s", cmdline); } static void forkexec(char *const argv[], const ups_t *ups) { #ifndef WIN32 int ret; if (nut_foreground_passthrough > 0 && upscount == 1) { upsdebugx(1, "Starting the only driver with explicitly " "requested foregrounding mode, not forking"); } else { pid_t pid, waitret; pid = fork(); if (pid < 0) fatal_with_errno(EXIT_FAILURE, "fork"); if (pid != 0) { /* parent */ int wstat; struct sigaction sa; /* work around const for this one... */ int *pupid = (int *)&(ups->pid); int *puexectimeout = (int *)&(ups->exceeded_timeout); *pupid = pid; *puexectimeout = 0; /* Handle "parallel" drivers startup */ if (waitfordrivers == 0) { upsdebugx(2, "'nowait' set, continuing..."); return; } if (nut_foreground_passthrough > 0 && upscount > 1) { /* Let upsdrvctl fork to run its numerous children * but without further forking on their side - so * not waiting for them to complete start-ups. */ upsdebugx(1, "Starting driver with explicitly " "requested foregrounding mode: will not " "wait for it to fork and detach, continuing..."); return; } if (nut_foreground_passthrough != 0 && nut_debug_level > 0 && nut_debug_level_passthrough > 0 ) { upsdebugx(2, "Starting driver with debug but " "without explicit backgrounding: " "will not wait for it to fork and " "detach, continuing..."); return; } sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = waitpid_timeout; sigaction(SIGALRM, &sa, NULL); /* Use the local maxstartdelay, if available */ if (ups->maxstartdelay != -1) { if (ups->maxstartdelay >= 0) alarm((unsigned int)ups->maxstartdelay); } else { /* Otherwise, use the global (or default) value */ if (maxstartdelay >= 0) alarm((unsigned int)maxstartdelay); } waitret = waitpid(pid, &wstat, 0); alarm(0); if (waitret == -1) { upslogx(LOG_WARNING, "Startup timer elapsed, continuing..."); exec_timeout++; *puexectimeout = 1; return; } if (WIFEXITED(wstat) == 0) { upslogx(LOG_WARNING, "Driver exited abnormally"); exec_error++; return; } /* the rest only work when WIFEXITED is nonzero */ if (WEXITSTATUS(wstat) != 0) { upslogx(LOG_WARNING, "Driver failed to start" " (exit status=%d)", WEXITSTATUS(wstat)); exec_error++; return; } if (WIFSIGNALED(wstat)) { upslog_with_errno(LOG_WARNING, "Driver died after signal %d", WTERMSIG(wstat)); exec_error++; } return; } } /* child or foreground mode (no fork) */ ret = execv(argv[0], argv); /* shouldn't get here normally */ upsdebugx(1, "%s: execv returned %d", __func__, ret); fatal_with_errno(EXIT_FAILURE, "execv"); #else /* WIN32 */ BOOL ret; DWORD res; DWORD exit_code = 0; char commandline[SMALLBUF]; STARTUPINFO StartupInfo; PROCESS_INFORMATION ProcessInformation; int i = 1; memset(&StartupInfo, 0, sizeof(STARTUPINFO)); /* the command line is made of the driver name followed by args */ snprintf(commandline, sizeof(commandline), "%s", ups->driver); while (argv[i] != NULL) { snprintfcat(commandline, sizeof(commandline), " %s", argv[i]); i++; } ret = CreateProcess( argv[0], commandline, NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP, NULL, NULL, &StartupInfo, &ProcessInformation ); if (ret == 0) { fatal_with_errno(EXIT_FAILURE, "execv"); } /* Wait a bit then look at driver process. * Unlike under Linux, Windows spawn drivers directly. If the driver is alive, all is OK. * An optimization can probably be implemented to prevent waiting so much time when all is OK. */ res = WaitForSingleObject(ProcessInformation.hProcess, (ups->maxstartdelay!=-1?ups->maxstartdelay:maxstartdelay)*1000); if (res != WAIT_TIMEOUT) { GetExitCodeProcess( ProcessInformation.hProcess, &exit_code ); upslogx(LOG_WARNING, "Driver failed to start (exit status=%d)", ret); exec_error++; return; } else { /* work around const for this one... */ int *pupid = (int *)&(ups->pid); int *puexectimeout = (int *)&(ups->exceeded_timeout); *pupid = 0; /* For WIN32, just a flag (not "-1" has a meaning) */ *puexectimeout = 1; } return; #endif /* WIN32 */ } static void list_driver(const ups_t *ups) { /* Just a short report: one config section name per line */ printf("%s\n", ups->upsname); } static void status_driver(const ups_t *ups) { /* TODO: Options (global static) for details of configuration like * the driver name, serial, etc. or even current life-cycle status * (e.g. valid PID existence, data query via socket protocol...) */ static int headerShown = 0; #ifndef WIN32 char pidfn[NUT_PATH_MAX + 1]; int cmdret = -1; #endif /* !WIN32 */ char bufPid[LARGEBUF], *pidStrFromSocket = NULL, bufStatus[LARGEBUF], *statusStrFromSocket = NULL; int pidAlive = -1, qretPing = -1, qretPid = -1, qretStatus = -1, nudl = nut_upsdrvquery_debug_level, nsdl = nut_sendsignal_debug_level; pid_t pidFromFile = -1, pidFromSocket = -1; struct timeval tv; udq_pipe_conn_t *conn; if (!ups) { upsdebugx(1, "%s: skip due to ups==null", __func__); return; } /* Hush the fopen(pidfile) message but let "real errors" be seen */ nut_sendsignal_debug_level = NUT_SENDSIGNAL_DEBUG_LEVEL_KILL_SIG0PING - 1; #ifndef WIN32 snprintf(pidfn, sizeof(pidfn), "%s/%s-%s.pid", altpidpath(), ups->driver, ups->upsname); pidFromFile = parsepidfile(pidfn); if (pidFromFile >= 0) { /* this method actively reports errors, if any */ cmdret = sendsignalpid(pidFromFile, 0, ups->driver, 1); /* returns zero for a successfully sent signal */ if (cmdret == 0) pidAlive = 1; } upsdebugx(4, "%s: pidfn=%s pidFromFile=%" PRIiMAX " cmdret=%d pidAlive=%d", __func__, pidfn, (intmax_t)pidFromFile, cmdret, pidAlive); #else /* WIN32 */ /* // FIXME: We actually have no probing signals over pipe so far, // and sending 0 (NULL here) is proven unsafe // Instead we will try below with PID learned from pipe snprintf(pidfn, sizeof(pidfn), "%s-%s", ups->driver, ups->upsname); cmdret = sendsignal(pidfn, COMMAND_RELOAD, 1); upsdebugx(4, "%s: pipe pidfn=%s cmdret=%d", __func__, pidfn, cmdret); */ NUT_WIN32_INCOMPLETE_DETAILED("no probing signals over pipe yet"); #endif /* WIN32 */ /* Hush the fopen(socketfile) in upsdrvquery_connect_drvname_upsname() */ nut_upsdrvquery_debug_level = 0; conn = upsdrvquery_connect_drvname_upsname(ups->driver, ups->upsname); nut_upsdrvquery_debug_level = nudl; if (conn && VALID_FD(conn->sockfd)) { upsdebugx(3, "%s: connected", __func__); /* Post the query and wait for reply */ /* FIXME: coordinate with pollfreq? */ tv.tv_sec = 3; tv.tv_usec = 0; memset(bufPid, 0, sizeof(bufPid)); /* Involves a PING/PONG check, and more; * returns -1 on error */ upsdebugx(3, "%s: upsdrvquery_prepare", __func__); qretPing = upsdrvquery_prepare(conn, tv); if (qretPing >= 0) { qretPing = STAT_INSTCMD_HANDLED; /* No TRACKING in queries below */ memset(bufPid, 0, sizeof(bufPid)); upsdebugx(3, "%s: upsdrvquery_write GETPID", __func__); if (upsdrvquery_write(conn, "GETPID\n") >= 0 && (qretPid = upsdrvquery_read_timeout(conn, tv)) >= 1 && (!strncmp(conn->buf, "PID ", 4)) ) { size_t l; upsdebugx(4, "%s: upsdrvquery_read GETPID", __func__); snprintf(bufPid, sizeof(bufPid), "%s", conn->buf + 4); upsdebugx(4, "%s: upsdrvquery_read GETPID 2", __func__); l = strlen(bufPid); pidStrFromSocket = bufPid; if (bufPid[l - 1] == '\n') bufPid[l - 1] = '\0'; qretPid = STAT_INSTCMD_HANDLED; pidFromSocket = parsepid(pidStrFromSocket); if (errno != 0) pidFromSocket = -1; } else { /* query failed or returned not a PID */ qretPid = -1; } } if (qretPid == STAT_INSTCMD_HANDLED) { memset(bufStatus, 0, sizeof(bufStatus)); #ifdef WIN32 /* Allow a new read to happen later */ conn->newread = 1; #endif /* WIN32 */ upsdebugx(3, "%s: upsdrvquery_write DUMPSTATUS", __func__); if (upsdrvquery_write(conn, "DUMPSTATUS\n") >= 0 && (qretStatus = upsdrvquery_read_timeout(conn, tv)) >= 1 ) { char *buf; upsdebugx(4, "%s: upsdrvquery_read DUMPSTATUS", __func__); /* save before strtok mangles it */ snprintf(bufStatus, sizeof(bufStatus), "%s", conn->buf); upsdebugx(4, "%s: upsdrvquery_read DUMPSTATUS 2", __func__); for (buf = strtok(bufStatus, "\n"); buf; buf = strtok(NULL, "\n")) { if (statusStrFromSocket) { /* New loop, NUL byte was set if needed */ break; } if (!strncmp(buf, "SETINFO ups.status ", 19)) { statusStrFromSocket = buf + 19; qretStatus = STAT_INSTCMD_HANDLED; /* continue to loop, to clear '\n' to '\0' */ } if (!strncmp(buf, "DUMPDONE\n", 9)) { /* New loop, NUL byte was set if needed */ break; } } } else { /* query failed or did not return SETINFO ups.status ... */ qretStatus = -1; } } } else { upsdebugx(3, "%s: not connected", __func__); } upsdebugx(3, "%s: close socket", __func__); upsdrvquery_close(conn); if (conn) { upsdebugx(4, "%s: free socket", __func__); free(conn); conn = NULL; } if (pidFromFile < 0 && pidFromSocket >= 0) { upsdebugx(3, "%s: PID was not available from a file, but was " "from Socket Protocol; check if it is alive instead", __func__); pidAlive = checkprocname(pidFromSocket, ups->driver); upsdebugx(4, "%s: pidFromSocket=%" PRIiMAX " pidAlive=%d", __func__, (intmax_t)pidFromSocket, pidAlive); } else if (pidAlive < 0 && pidFromSocket >= 0 && (pidFromFile != pidFromSocket)) { upsdebugx(3, "%s: PID value was available from a file, but was " "not found running or valid; another one is available " "from Socket Protocol; check if it is alive instead", __func__); pidAlive = checkprocname(pidFromSocket, ups->driver); upsdebugx(4, "%s: pidFromSocket=%" PRIiMAX " pidAlive=%d", __func__, (intmax_t)pidFromSocket, pidAlive); } /* Complete any cached (error) writes before the next lines, * more so on WIN32 */ fflush(stderr); fflush(stdout); usleep(1000); if (!headerShown) { printf("%-11s\t%11s\t%s\t%s\t%s\t%s\t%s\n", "UPSNAME", "UPSDRV", "RUNNING", "PF_PID", "S_RESPONSIVE", "S_PID", "S_STATUS" ); headerShown = 1; } upsdebugx(2, "%s: raw values: pidAlive=%d " "pidFromFile=%" PRIiMAX " pidFromSocket=%" PRIiMAX " " "qretPing=%d qretPid=%d qretStatus=%d", __func__, pidAlive, (intmax_t)(pidFromFile), (intmax_t)(pidFromSocket), qretPing, qretPid, qretStatus ); printf("%-11s\t%11s\t%s\t%" PRIiMAX "\t%s\t%s\t%s\n", ups->upsname, ups->driver, ((pidFromFile < 0 && pidFromSocket < 0) || (pidAlive < 0) ? "N/A" : (pidAlive > 0 ? "RUNNING" : "STOPPED")), (intmax_t)(pidFromFile), ((qretPing == STAT_INSTCMD_HANDLED) ? "RESPONSIVE" : "NOT_RESPONSIVE"), (pidStrFromSocket ? pidStrFromSocket : "N/A"), ((qretStatus == STAT_INSTCMD_HANDLED) ? NUT_STRARG(statusStrFromSocket) : "") ); fflush(stdout); nut_sendsignal_debug_level = nsdl; } static void start_driver(const ups_t *ups) { char *argv[10]; char dfn[NUT_PATH_MAX + 1], dbg[SMALLBUF]; int ret, arg = 0; int initial_exec_error = exec_error, initial_exec_timeout = exec_timeout, drv_maxretry = maxretry, drv_retrydelay = retrydelay; struct stat fs; upsdebugx(1, "Starting UPS: %s", ups->upsname); /* Use the local retry settings, if available */ if (ups->retrydelay >= 0) { drv_retrydelay = ups->retrydelay; } if (ups->maxretry >= 0) { drv_maxretry = ups->maxretry; } #ifndef WIN32 snprintf(dfn, sizeof(dfn), "%s/%s", driverpath, ups->driver); #else /* WIN32 */ snprintf(dfn, sizeof(dfn), "%s/%s.exe", driverpath, ups->driver); #endif /* WIN32 */ ret = stat(dfn, &fs); if (ret < 0) fatal_with_errno(EXIT_FAILURE, "Can't start %s", dfn); argv[arg++] = dfn; if (nut_debug_level_passthrough > 0 && nut_debug_level > 0 && sizeof(dbg) > 3 ) { size_t d, m; /* cut-off point: buffer size or requested debug level */ m = sizeof(dbg) - 1; /* leave a place for '\0' */ #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wtautological-compare" # pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif /* Different platforms, different sizes, none fits all... */ /* can we fit this many 'D's? */ if ((uintmax_t)SIZE_MAX > (uintmax_t)nut_debug_level /* else can't assign, requested debug level is huge */ && (size_t)nut_debug_level + 1 < m ) { #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif /* need even fewer (leave a place for '-'): */ m = (size_t)nut_debug_level + 1; } else { upsdebugx(1, "Requested debugging level %d is too " "high for pass-through args, truncated to %" PRIuSIZE, nut_debug_level, (m - 1) /* count off '-' (and '\0' already) chars */ ); } dbg[0] = '-'; for (d = 1; d < m ; d++) { dbg[d] = 'D'; } dbg[d] = '\0'; argv[arg++] = dbg; } /* Default: -1, FG/BG depends on debugging level */ /* send_all_drivers() also warns if got many drivers to handle * and foreground mode - it won't loop really */ switch (nut_foreground_passthrough) { case 0: argv[arg++] = (char *)"-B"; /* FIXME: cast away const */ break; case 1: argv[arg++] = (char *)"-F"; /* FIXME: cast away const */ break; case 2: argv[arg++] = (char *)"-FF"; /* FIXME: cast away const */ break; default: if (nut_debug_level_passthrough > 0 && nut_debug_level > 0 ) { upsdebugx(1, "WARNING: Requested a debugging level " "but not explicitly a backgrounding mode - " "driver may never try to fork away; however " "the upsdrvctl tool will fork it and not wait."); } } argv[arg++] = (char *)"-a"; /* FIXME: cast away const */ argv[arg++] = ups->upsname; /* stick on the chroot / user args if given to us */ if (pt_root) { argv[arg++] = (char *)"-r"; /* FIXME: cast away const */ argv[arg++] = pt_root; } if (pt_user) { argv[arg++] = (char *)"-u"; /* FIXME: cast away const */ argv[arg++] = pt_user; } /* tie it off */ argv[arg++] = NULL; while (drv_maxretry > 0) { int cur_exec_error = exec_error; int cur_exec_timeout = exec_timeout; upsdebugx(2, "%i remaining attempts", drv_maxretry); debugcmdline(2, "exec: ", argv); drv_maxretry--; if (!testmode) { forkexec(argv, ups); } /* driver command succeeded */ if (cur_exec_error == exec_error && cur_exec_timeout == exec_timeout) { drv_maxretry = 0; exec_error = initial_exec_error; exec_timeout = initial_exec_timeout; } else { /* otherwise, retry if still needed */ if (drv_maxretry > 0) if (drv_retrydelay >= 0) sleep ((unsigned int)drv_retrydelay); } } } static void help(const char *progname) __attribute__((noreturn)); static void help(const char *arg_progname) { print_banner_once(arg_progname, 2); printf("UPS driver controller: Starts and stops UPS drivers via ups.conf.\n\n"); printf("usage: %s [OPTIONS] (start | stop | shutdown | status) []\n\n", arg_progname); printf("usage: %s [OPTIONS] (list | -l) []\n\n", arg_progname); printf("usage: %s [OPTIONS] -c []\n\n", arg_progname); printf("Common options:\n"); printf(" -h display this help\n"); printf(" -r drivers will chroot to \n"); printf(" -t testing mode - prints actions without doing them\n"); printf(" -u drivers started will switch from root to \n"); printf(" -D raise debugging level\n"); printf(" -d pass debugging level from upsdrvctl to driver\n"); printf(" -F driver stays foregrounded even if no debugging is enabled\n"); printf(" -FF driver stays foregrounded and still saves the PID file\n"); printf(" -B driver(s) stay backgrounded even if debugging is bumped\n"); printf("\nListing known driver(s):\n"); printf(" -l | list list all device driver confgurations that can be managed\n"); printf(" -l | list only try to list the specified device driver confgurations\n"); printf(" (error out if the device name is unresolved)\n"); printf("\nSignalling a running driver:\n"); printf(" -c send via signal to running driver(s)\n"); printf(" supported commands:\n"); #ifndef WIN32 /* FIXME: port event loop from upsd/upsmon to allow messaging fellow drivers in WIN32 builds: https://github.com/networkupstools/nut/issues/1916 */ printf(" - data-dump: if the driver still has STDOUT attached (maybe\n"); printf(" to log), dump its currently collected information there\n"); printf(" - reload: re-read configuration files, ignoring changed\n"); printf(" values which require a driver restart (can not be changed\n"); printf(" on the fly)\n"); #endif /* !WIN32 */ printf(" - reload-or-error: re-read configuration files, ignoring but\n"); printf(" counting changed values which require a driver restart (can\n"); printf(" not be changed on the fly), and return a success/fail code\n"); printf(" based on that count, so the caller can decide the fate of\n"); printf(" the currently running driver instance\n"); #ifndef WIN32 /* FIXME: port event loop from upsd/upsmon to allow messaging fellow drivers in WIN32 builds: https://github.com/networkupstools/nut/issues/1916 */ # ifdef SIGCMD_RELOAD_OR_RESTART printf(" - reload-or-restart: re-read configuration files (close the\n"); printf(" old driver instance device connection if needed, and have\n"); printf(" it effectively restart)\n"); # endif printf(" - reload-or-exit: re-read configuration files (exit the old\n"); printf(" driver instance if needed, so an external caller like the\n"); printf(" systemd or SMF frameworks would start another copy)\n"); #endif /* !WIN32 */ printf(" - exit: tell the currently running driver instance to just exit\n"); printf(" (so an external caller like the new driver instance, or the\n"); printf(" systemd or SMF frameworks would start another copy)\n"); printf("\nDriver life cycle options:\n"); printf(" start start all UPS drivers in ups.conf\n"); printf(" start only start driver for UPS \n"); printf(" stop stop all UPS drivers in ups.conf\n"); printf(" stop only stop driver for UPS \n"); printf(" shutdown shutdown all UPS drivers in ups.conf\n"); printf(" shutdown only shutdown UPS \n"); printf(" status query status for all UPS drivers in ups.conf\n"); printf(" status only query status for driver for UPS \n"); printf(" Fields: UPSNAME UPSDRV RUNNING PF_PID S_RESPONSIVE S_PID S_STATUS\n"); printf(" (PF_* = according to PID file, if any; S_* = via socket protocol)\n"); printf("\n%s", suggest_doc_links(arg_progname, "ups.conf")); #if (defined(WITH_SOLARIS_SMF) && WITH_SOLARIS_SMF) || (defined(HAVE_SYSTEMD) && HAVE_SYSTEMD) printf("NOTE: On this system you should prefer upsdrvsvcctl and nut-driver-enumerator\n"); #endif exit(EXIT_SUCCESS); } static void shutdown_driver(const ups_t *ups) { char *argv[9]; char dfn[NUT_PATH_MAX + 1]; int arg = 0; upsdebugx(1, "Shutdown UPS: %s", ups->upsname); #ifndef WIN32 snprintf(dfn, sizeof(dfn), "%s/%s", driverpath, ups->driver); #else /* WIN32 */ snprintf(dfn, sizeof(dfn), "%s/%s.exe", driverpath, ups->driver); #endif /* WIN32 */ argv[arg++] = dfn; argv[arg++] = (char *)"-a"; /* FIXME: cast away const */ argv[arg++] = ups->upsname; argv[arg++] = (char *)"-k"; /* FIXME: cast away const */ /* stick on the chroot / user args if given to us */ if (pt_root) { argv[arg++] = (char *)"-r"; /* FIXME: cast away const */ argv[arg++] = pt_root; } if (pt_user) { argv[arg++] = (char *)"-u"; /* FIXME: cast away const */ argv[arg++] = pt_user; } argv[arg++] = NULL; debugcmdline(2, "exec: ", argv); if (!testmode) { forkexec(argv, ups); } } static void send_one_driver(void (*command_func)(const ups_t *), const char *arg_upsname) { ups_t *ups = upstable; if (!ups) fatalx(EXIT_FAILURE, "Error: no UPS definitions found in ups.conf!\n"); exec_error = 0; exec_timeout = 0; while (ups) { if (!strcmp(ups->upsname, arg_upsname)) { command_func(ups); return; } ups = ups->next; } fatalx(EXIT_FAILURE, "UPS %s not found in ups.conf", arg_upsname); } /* walk UPS table and send command to all UPSes according to sdorder */ static void send_all_drivers(void (*command_func)(const ups_t *)) { ups_t *ups = upstable; int i; if (!ups) fatalx(EXIT_FAILURE, "Error: no UPS definitions found in ups.conf"); exec_error = 0; exec_timeout = 0; if (command_func == &list_driver || command_func == &status_driver) { while (ups) { command_func(ups); ups = ups->next; } fflush(stdout); return; } if (command_func != &shutdown_driver) { /* e.g. start_driver or stop_driver */ /* Only warn when relevant - got more than one device to start */ if (command_func == &start_driver && ups->next && ( (nut_foreground_passthrough > 0) || (nut_foreground_passthrough != 0 && nut_debug_level > 0 && nut_debug_level_passthrough > 0) ) ) { upslogx(LOG_WARNING, "Starting \"all\" drivers but requested the %s! " "This request will not wait for driver(s) to complete " "their initialization%s.", (nut_foreground_passthrough > 0 ? "foreground mode" : "debug mode without backgrounding"), (nut_foreground_passthrough > 0 ? ", but upsdrvctl tool will stay foregrounded" : "") ); } while (ups) { command_func(ups); ups = ups->next; } return; } /* Orderly processing of shutdowns */ for (i = 0; i <= maxsdorder; i++) { while (ups) { if (ups->sdorder == i) command_func(ups); ups = ups->next; } } } static void exit_cleanup(void) { ups_t *tmp, *next; upsdebugx(1, "Completed the job of upsdrvctl tool, cleaning up and exiting now"); tmp = upstable; if (command == &start_driver && upscount > 0 && nut_foreground_passthrough > 0 ) { /* First stop the drivers, if any are running */ while (tmp) { next = tmp->next; if (tmp->pid != -1) { stop_driver(tmp); } tmp = next; } } tmp = upstable; while (tmp) { next = tmp->next; free(tmp->driver); free(tmp->port); free(tmp->upsname); free(tmp); tmp = next; } free(driverpath); upsdebugx(1, "Completed the job of upsdrvctl tool, clean-up finished, exiting now"); } int main(int argc, char **argv) { int i, lastarg = 0; char *prog, *command_name = NULL, progdesc[LARGEBUF]; prog = argv[0]; /* Historically special banner*/ snprintf(progdesc, sizeof(progdesc), "%s - UPS driver controller", xbasename(prog)); print_banner_once(progdesc, 0); while ((i = getopt(argc, argv, "+htu:r:DdFBVc:l")) != -1) { switch(i) { case 'r': pt_root = optarg; break; case 't': testmode = 1; break; case 'u': pt_user = optarg; break; case 'V': /* just show the version and optional * CONFIG_FLAGS banner if available */ print_banner_once(progdesc, 1); nut_report_config_flags(); exit(EXIT_SUCCESS); case 'D': nut_debug_level++; break; case 'd': nut_debug_level_passthrough = 1; break; case 'F': if (nut_foreground_passthrough > 0) { /* specified twice to save PID file anyway */ nut_foreground_passthrough = 2; } else { nut_foreground_passthrough = 1; } break; case 'B': nut_foreground_passthrough = 0; break; case 'c': if (command || pt_cmd) { fatalx(EXIT_FAILURE, "Error: only one command per run can be " "sent with option -%c. Try -h for help.", i); } command = &signal_driver; command_name = "signal"; if (!strncmp(optarg, "reload-or-error", strlen(optarg))) { signal_flag = SIGCMD_RELOAD_OR_ERROR; } else if (!strncmp(optarg, "exit", strlen(optarg))) { signal_flag = SIGCMD_EXIT; } #ifndef WIN32 /* FIXME: port event loop from upsd/upsmon to allow messaging fellow drivers in WIN32 builds: https://github.com/networkupstools/nut/issues/1916 */ else if (!strncmp(optarg, "dump", strlen(optarg))) { signal_flag = SIGCMD_DATA_DUMP; } else if (!strncmp(optarg, "data-dump", strlen(optarg))) { signal_flag = SIGCMD_DATA_DUMP; } else if (!strncmp(optarg, "reload", strlen(optarg))) { signal_flag = SIGCMD_RELOAD; } else # ifdef SIGCMD_RELOAD_OR_RESTART if (!strncmp(optarg, "reload-or-restart", strlen(optarg))) { signal_flag = SIGCMD_RELOAD_OR_RESTART; } else # endif if (!strncmp(optarg, "reload-or-exit", strlen(optarg))) { signal_flag = SIGCMD_RELOAD_OR_EXIT; } #else /* WIN32 */ /* https://github.com/networkupstools/nut/issues/1916 */ NUT_WIN32_INCOMPLETE_DETAILED("driver.reload* instant commands"); #endif /* WIN32 */ /* bad command given */ if (!signal_flag) { fatalx(EXIT_FAILURE, "Error: unknown argument to option -%c. Try -h for help.", i); } pt_cmd = optarg; #ifndef WIN32 if (signal_flag > 0) upsdebugx(1, "Will send signal %d (%s) for command '%s' " "to already-running driver (if any) and exit", signal_flag, strsignal(signal_flag), optarg); else upsdebugx(1, "Will send request for command '%s' (internal code %d) " "to already-running driver (if any) and exit", optarg, signal_flag); #else /* WIN32 */ upsdebugx(1, "Will send request '%s' for command '%s' " "to already-running driver (if any) and exit", signal_flag, optarg); #endif /* WIN32 */ break; case 'l': command = &list_driver; command_name = "list"; break; case 'h': default: /* not progdesc, shows details of its own */ help(prog); } } { /* scoping */ char *s = getenv("NUT_DEBUG_LEVEL"); int l; if (s && str_to_int(s, &l, 10)) { if (l > 0 && nut_debug_level < 1) { upslogx(LOG_INFO, "Defaulting debug verbosity to NUT_DEBUG_LEVEL=%d " "since none was requested by command-line options", l); nut_debug_level = l; } /* else follow -D settings */ } /* else nothing to bother about */ } argc -= optind; argv += optind; /* We expect maybe command (if not signalling above) and maybe UPS name */ if (!command && argc < 1) help(prog); if (testmode) { printf("*** Testing mode: not calling exec/kill/signal\n"); if (nut_debug_level < 2) nut_debug_level = 2; } /* Note: argv is incremented above, so [0] is currently the next * CLI keyword after options */ if (!command) { if (!strcmp(argv[0], "start")) { command = &start_driver; command_name = argv[0]; } else if (!strcmp(argv[0], "stop")) { command = &stop_driver; command_name = argv[0]; } else if (!strcmp(argv[0], "shutdown")) { command = &shutdown_driver; command_name = argv[0]; } else if (!strcmp(argv[0], "list")) { command = &list_driver; command_name = argv[0]; } else if (!strcmp(argv[0], "status")) { command = &status_driver; command_name = argv[0]; } lastarg = 1; } if (!command) fatalx(EXIT_FAILURE, "Error: unrecognized command [%s]", argv[0]); if (nut_debug_level_passthrough == 0 && (command == &start_driver || command == &shutdown_driver)) { upsdebugx(2, "\n" "If you're not a NUT core developer, chances are that you're told to enable debugging\n" "to see why a driver isn't working for you. We're sorry for the confusion, but this is\n" "the 'upsdrvctl' wrapper, not the driver you're interested in.\n\n" "Below you'll find one or more lines starting with 'exec:' followed by an absolute\n" "path to the driver binary and some command line option. This is what the driver\n" "starts and you need to copy and paste that line and append the debug flags to that\n" "line (less the 'exec:' prefix).\n\n" "Alternately, provide an additional '-d' (lower-case) parameter to 'upsdrvctl' to\n" "pass its current debug level to the launched driver, and '-B' keeps it backgrounded.\n"); } #ifndef WIN32 driverpath = xstrdup(DRVPATH); /* set default */ #else /* WIN32 */ driverpath = getfullpath(NULL); /* Relative path in WIN32 */ #endif /* WIN32 */ atexit(exit_cleanup); read_upsconf(1); if (argc == lastarg) { ups_t *tmp = upstable; upscount = 0; while (tmp) { tmp = tmp->next; upscount++; } upsdebugx(1, "upsdrvctl commanding all drivers (%d found): %s", upscount, (pt_cmd ? pt_cmd : NUT_STRARG(command_name))); send_all_drivers(command); } else if (argc == (lastarg + 1)) { upscount = 1; upsdebugx(1, "upsdrvctl commanding one driver (%s): %s", argv[lastarg], (pt_cmd ? pt_cmd : NUT_STRARG(command_name))); send_one_driver(command, argv[lastarg]); } else { fatalx(EXIT_FAILURE, "Error: extra arguments left on command line\n" "(common options should be before a command and UPS name)"); } #if (defined(WITH_SOLARIS_SMF) && WITH_SOLARIS_SMF) || (defined(HAVE_SYSTEMD) && HAVE_SYSTEMD) if (!getenv("NUT_QUIET_INIT_NDE_WARNING") && (command == &start_driver || command == &stop_driver || command == &shutdown_driver) ) { # if (defined(WITH_SOLARIS_SMF) && WITH_SOLARIS_SMF) char *fwk = "SMF"; # else # if (defined(HAVE_SYSTEMD) && HAVE_SYSTEMD) char *fwk = "systemd"; # endif # endif upslogx(LOG_WARNING, "WARNING: %s was called directly on a system with %s support.\n" " Please consider using 'upsdrvsvcctl' instead, to avoid conflicts with\n" " nut-driver service instances prepared by 'nut-driver-enumerator'!", prog, fwk); upsdebugx(1, "For more details see https://github.com/networkupstools/nut/wiki/nut%%E2%%80%%90driver%%E2%%80%%90enumerator-(NDE)"); upsdebugx(1, "To silence this warning export NUT_QUIET_INIT_NDE_WARNING with any value"); } #endif /* Note that the numeric value here is not precise (it reflects * the number of "timeouts" which grows with amount of drivers * and retries. Below we re-check each driver to convert the * value into some amount of known failures (or succeses). */ if (exec_timeout) { #ifndef WIN32 ups_t *tmp = upstable; #endif /* !WIN32 */ upsdebugx(1, "upsdrvctl: got some timeouts with preceding operations, revising them now"); #ifndef WIN32 while (tmp) { if (tmp->exceeded_timeout && tmp->pid) { /* reap zombie if this child died, and * get info if we know how it went (or * still goes) */ int wstat; pid_t waitret = waitpid(tmp->pid, &wstat, WNOHANG); upsdebugx(1, "Driver [%s] PID %" PRIdMAX " initially exceeded " "maxstartdelay %d sec but now waitpid() returns %" PRIdMAX " and status bits 0x%.*X", tmp->upsname, (intmax_t)tmp->pid, (tmp->maxstartdelay!=-1?tmp->maxstartdelay:maxstartdelay), (intmax_t)waitret, (int)(2*sizeof(wstat)), (unsigned int)wstat); if (waitret == tmp->pid) { upsdebugx(1, "Driver [%s] PID %" PRIdMAX " initially exceeded " "maxstartdelay %d sec but has finished by now", tmp->upsname, (intmax_t)tmp->pid, (tmp->maxstartdelay!=-1?tmp->maxstartdelay:maxstartdelay)); tmp->exceeded_timeout = 0; } else if (waitret == 0) { /* Special behavior for WNOHANG */ upslogx(LOG_WARNING, "Driver [%s] PID %" PRIdMAX " initially exceeded " "maxstartdelay %d sec and is still starting", tmp->upsname, (intmax_t)tmp->pid, (tmp->maxstartdelay!=-1?tmp->maxstartdelay:maxstartdelay)); /* TOTHINK: Should this "timeout" cause an error * exit code, if this is the only problem? * Maybe as a special case - if this is the only * driver (dedicated starter) vs. start-all? * if (argc != (lastarg + 1)) ... * or if (upscount == 1) ... */ exec_error++; } else if (waitret == -1) { upslog_with_errno(LOG_WARNING, "Driver [%s] PID %" PRIdMAX " initially exceeded " "maxstartdelay %d sec and we got an error asking it again", tmp->upsname, (intmax_t)tmp->pid, (tmp->maxstartdelay!=-1?tmp->maxstartdelay:maxstartdelay)); exec_error++; } else if (WIFEXITED(wstat) == 0) { upslogx(LOG_WARNING, "Driver [%s] PID %" PRIdMAX " initially exceeded " "maxstartdelay %d sec and has exited abnormally by now", tmp->upsname, (intmax_t)tmp->pid, (tmp->maxstartdelay!=-1?tmp->maxstartdelay:maxstartdelay)); exec_error++; } else /* the rest only work when WIFEXITED is nonzero */ if (WEXITSTATUS(wstat) != 0) { upslogx(LOG_WARNING, "Driver [%s] PID %" PRIdMAX " initially exceeded " "maxstartdelay %d sec and has failed to start by now " "(exit status=%d)", tmp->upsname, (intmax_t)tmp->pid, (tmp->maxstartdelay!=-1?tmp->maxstartdelay:maxstartdelay), WEXITSTATUS(wstat)); exec_error++; } else if (WIFSIGNALED(wstat)) { upslog_with_errno(LOG_WARNING, "Driver [%s] PID %" PRIdMAX " initially exceeded " "maxstartdelay %d sec and has died after signal %d by now", tmp->upsname, (intmax_t)tmp->pid, (tmp->maxstartdelay!=-1?tmp->maxstartdelay:maxstartdelay), WTERMSIG(wstat)); exec_error++; } } tmp = tmp->next; } #else /* WIN32 */ /* TOTHINK: Is there something we can do on the platform? */ exec_error++; #endif /* WIN32 */ } if (exec_error) { upsdebugx(1, "upsdrvctl: got some errors with preceding operations, exiting with failure now"); exit(EXIT_FAILURE); } if (command == &start_driver && upscount > 0 && nut_foreground_passthrough > 0 ) { /* Note: for a single started driver, we just * exec() it and should not even get here */ upsdebugx(1, "upsdrvctl: was asked for explicit foregrounding - " "not exiting now (driver startup was completed)"); /* raise exit_flag upon SIGTERM, Ctrl+C, etc. */ setup_signals(); while (!exit_flag) { #ifndef WIN32 /* FIXME : NUT_WIN32_INCOMPLETE */ ups_t *tmp = upstable, *next; /* Track if any child process has stopped (due to * an error, normal exit, signal...) to kill others * and exit the tool - with error if applicable. */ while (tmp) { next = tmp->next; if (tmp->pid != -1) { int status; if (waitpid(tmp->pid, &status, WNOHANG) == tmp->pid) { if (WIFEXITED(status)) { int es = WEXITSTATUS(status); time_t now; double elapsed; time(&now); elapsed = difftime(now, last_dangerous_reload); if (elapsed < 60 || (es - 128) == SIGCMD_RELOAD_OR_EXIT # ifdef SIGCMD_RELOAD_OR_RESTART || (es - 128) == SIGCMD_RELOAD_OR_RESTART # endif ) { /* Arbitrary but generous time to handle * a reload including driver loop lag */ upsdebugx(1, "Driver [%s] for [%s] exited " "soon after reload-or-exit or " "similar signal, restarting it", tmp->driver, tmp->upsname); tmp->pid = -1; start_driver(tmp); } else { /* Quit without excuses, recycle myself */ upsdebugx(1, "Driver [%s] for [%s] exited " "inexplicably with code %d, aborting", tmp->driver, tmp->upsname, es); if (last_dangerous_reload) upsdebugx(1, "Last 'dangerous' signal " "was processed %f sec ago", elapsed); exit_flag = -1; tmp->pid = -1; } } } } tmp = next; } if (exit_flag == -1) { fatalx(EXIT_FAILURE, "At least one tracked driver running " "in foreground mode has exited, stopping upsdrvctl " "(and other tracked drivers) so the bundle can be " "restarted by system properly"); /* NOTE: Users really should run one driver per instance, * wrapped in services where available */ } if (signal_flag) { upsdebugx(1, "upsdrvctl: handling signal: starting"); if (signal_flag == SIGCMD_RELOAD_OR_EXIT # ifdef SIGCMD_RELOAD_OR_RESTART || signal_flag == SIGCMD_RELOAD_OR_RESTART # endif ) time(&last_dangerous_reload); tmp = upstable; while (tmp) { next = tmp->next; signal_driver(tmp); tmp = next; } reset_signal_flag(); upsdebugx(1, "upsdrvctl: handling signal: finished"); } #endif /* !WIN32 */ sleep(1); } } upsdebugx(1, "upsdrvctl: successfully finished"); exit(EXIT_SUCCESS); } nut-2.8.4/drivers/nut-ipmi.h0000644000175000017500000000471214777753337012700 00000000000000/* nut-ipmi.h - Abstract IPMI interface, to allow using different IPMI backends * * Copyright (C) 2011 - Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUT_IPMI_H #define NUT_IPMI_H typedef enum { PSU_STATUS_UNKNOWN = 1, PSU_PRESENT, /* = status OL */ PSU_ABSENT, /* = status stale */ PSU_POWER_FAILURE /* = status OFF */ } psu_status_t; #ifdef HAVE_FREEIPMI_11X_12X /* args 8, 9, 10, 11 of ipmi_fru_multirecord_power_supply_information() */ typedef int input_voltage_range_t; #else /* args 8, 9, 10, 11 of ipmi_fru_parse_multirecord_power_supply_information() */ typedef unsigned int input_voltage_range_t; #endif /* Abstract structure to store information */ typedef struct IPMIDevice_s { int ipmi_id; /* FRU ID */ char* manufacturer; /* Manufacturer Name */ char* product; /* Product Name */ char* serial; /* Product serial number */ char* part; /* Part Number */ char* date; /* Manufacturing Date/Time */ int overall_capacity; /* realpower.nominal? */ input_voltage_range_t input_minvoltage; input_voltage_range_t input_maxvoltage; int input_minfreq; int input_maxfreq; int voltage; /* psu.voltage or device.voltage */ unsigned int sensors_count; /* number of sensors IDs in sensors_id_list */ unsigned int sensors_id_list[20]; /* ID of sensors linked to this FRU */ /* measurements... */ int status; /* values from psu_status_t */ double input_voltage; double input_current; double temperature; } IPMIDevice_t; /* Generic functions, to implement in the backends */ int nut_ipmi_open(int ipmi_id, IPMIDevice_t *ipmi_dev); void nut_ipmi_close(void); int nut_ipmi_monitoring_init(void); int nut_ipmi_get_sensors_status(IPMIDevice_t *ipmi_dev); #endif /* NUT_IPMI_H */ nut-2.8.4/drivers/apc-mib.h0000644000175000017500000000023214777753336012436 00000000000000#ifndef APC_MIB_H #define APC_MIB_H #include "main.h" #include "snmp-ups.h" #include "apc-iem-mib.h" extern mib2nut_info_t apc; #endif /* APC_MIB_H */ nut-2.8.4/drivers/apcsmart-old.h0000644000175000017500000002241315000736161013472 00000000000000/* apcsmart.h - command table for APC smart protocol units Copyright (C) 1999 Russell Kroll (C) 2000 Nigel Metheringham This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_APCSMART_OLD_H_SEEN #define NUT_APCSMART_OLD_H_SEEN 1 #include #ifndef WIN32 #include #endif /* !WIN32 */ #include "serial.h" #include "timehead.h" #define APC_TABLE_VERSION "version 2.2" /* Basic UPS reply line structure */ #define ENDCHAR 10 /* APC ends responses with LF */ /* characters ignored by default */ #define IGNCHARS "\015+$|!~%?=#&" /* special characters to ignore */ /* these one is used only during startup, due to ^Z sending certain characters such as # */ #define MINIGNCHARS "\015+$|!" /* minimum set of special characters to ignore */ /* normal polls: characters we don't want to parse (including a few alerts) */ #define POLL_IGNORE "\015&|" /* alert characters we care about - OL, OB, LB, not LB, RB, OVER, not OVER */ #define POLL_ALERT "$!%+#?=" #define UPSDELAY 50000 /* slow down multicharacter commands */ #define CMDLONGDELAY 1500000 /* some commands need a 1.5s gap for safety */ #define SER_WAIT_SEC 3 /* wait up to 3.0 sec for ser_get calls */ #define SER_WAIT_USEC 0 /* dangerous instant commands must be reconfirmed within a 12 second window */ #define MINCMDTIME 3 #define MAXCMDTIME 15 /* it only does two strings, and they're both the same length */ #define APC_STRLEN 8 /* --------------- */ /* status bits */ #define APC_STAT_CAL 1L /* calibration */ #define APC_STAT_TRIM 2L /* SmartTrim */ #define APC_STAT_BOOST 4L /* SmartBoost */ #define APC_STAT_OL 8L /* on line */ #define APC_STAT_OB 16L /* on battery */ #define APC_STAT_OVER 32L /* overload */ #define APC_STAT_LB 64L /* low battery */ #define APC_STAT_RB 128L /* replace battery */ /* serial protocol: special commands - initialization and such */ #define APC_STATUS 'Q' #define APC_GOSMART 'Y' #define APC_GODUMB 'R' #define APC_CMDSET 'a' #define APC_CAPABILITY 26 /* ^Z */ #define APC_NEXTVAL '-' /* --------------- */ /* Driver command table flag values */ #define APC_POLL 0x0001 /* Poll this variable regularly */ #define APC_PRESENT 0x0004 /* Capability seen on this UPS */ #define APC_RW 0x0010 /* read-write variable */ #define APC_ENUM 0x0020 /* enumerated type */ #define APC_STRING 0x0040 /* string */ #define APC_NASTY 0x0100 /* Nasty command - take care */ #define APC_REPEAT 0x0200 /* Command needs sending twice */ #define APC_FORMATMASK 0xFF0000 /* Mask for apc data formats */ #define APC_F_PERCENT 0x020000 /* Data in a percent format */ #define APC_F_VOLT 0x030000 /* Data in a voltage format */ #define APC_F_AMP 0x040000 /* Data in a current/amp format */ #define APC_F_CELSIUS 0x050000 /* Data in a temp/C format */ #define APC_F_HEX 0x060000 /* Data in a hex number format */ #define APC_F_DEC 0x070000 /* Data in a decimal format */ #define APC_F_SECONDS 0x100000 /* Time in seconds */ #define APC_F_MINUTES 0x110000 /* Time in minutes */ #define APC_F_HOURS 0x120000 /* Time in hours */ #define APC_F_REASON 0x130000 /* Reason of transfer */ #define APC_F_LEAVE 0 /* Just pass this through */ typedef struct { const char *name; /* the variable name */ unsigned int flags; /* various flags */ unsigned char cmd; /* command character */ } apc_vartab_t; static apc_vartab_t apc_vartab[] = { { "ups.firmware.old", 0, 'V' }, { "ups.firmware", 0, 'b' }, { "ups.firmware.aux", 0, 'v' }, { "ups.model", 0, 0x01 }, { "ups.serial", 0, 'n' }, { "ups.mfr.date", 0, 'm' }, { "ups.temperature", APC_POLL|APC_F_CELSIUS, 'C' }, { "ups.load", APC_POLL|APC_F_PERCENT, 'P' }, { "ups.test.interval", APC_F_HOURS, 'E' }, { "ups.test.result", APC_POLL, 'X' }, { "ups.delay.start", APC_F_SECONDS, 'r' }, { "ups.delay.shutdown", APC_F_SECONDS, 'p' }, { "ups.id", APC_STRING, 'c' }, { "ups.contacts", APC_POLL|APC_F_HEX, 'i' }, { "ups.display.language", 0, 0x0C }, { "input.voltage", APC_POLL|APC_F_VOLT, 'L' }, { "input.frequency", APC_POLL|APC_F_DEC, 'F' }, { "input.sensitivity", 0, 's' }, { "input.quality", APC_POLL|APC_F_HEX, '9' }, { "input.transfer.low", APC_F_VOLT, 'l' }, { "input.transfer.high", APC_F_VOLT, 'u' }, { "input.transfer.reason", APC_POLL|APC_F_REASON, 'G' }, { "input.voltage.maximum", APC_POLL|APC_F_VOLT, 'M' }, { "input.voltage.minimum", APC_POLL|APC_F_VOLT, 'N' }, { "output.current", APC_POLL|APC_F_AMP, '/' }, { "output.voltage", APC_POLL|APC_F_VOLT, 'O' }, { "output.voltage.nominal", APC_F_VOLT, 'o' }, { "ambient.humidity", APC_POLL|APC_F_PERCENT, 'h' }, { "ambient.humidity.high", APC_F_PERCENT, '{' }, { "ambient.humidity.low", APC_F_PERCENT, '}' }, { "ambient.temperature", APC_POLL|APC_F_CELSIUS, 't' }, { "ambient.temperature.high", APC_F_CELSIUS, '[' }, { "ambient.temperature.low", APC_F_CELSIUS, ']' }, { "battery.date", APC_STRING, 'x' }, { "battery.charge", APC_POLL|APC_F_PERCENT, 'f' }, { "battery.charge.restart", APC_F_PERCENT, 'e' }, { "battery.voltage", APC_POLL|APC_F_VOLT, 'B' }, { "battery.voltage.nominal", 0, 'g' }, { "battery.runtime", APC_POLL|APC_F_MINUTES, 'j' }, { "battery.runtime.low", APC_F_MINUTES, 'q' }, { "battery.packs", APC_F_DEC, '>' }, { "battery.packs.bad", APC_F_DEC, '<' }, { "battery.alarm.threshold", 0, 'k' }, /* todo: I = alarm enable (hex field) - split into alarm.n.enable J = alarm status (hex field) - split into alarm.n.status 0x15 = output voltage selection (APC_F_VOLT) 0x5C = load power (APC_POLL|APC_F_PERCENT) */ {NULL, 0, 0}, }; /* ------ instant commands ------ */ #define APC_CMD_FPTEST 'A' #define APC_CMD_CALTOGGLE 'D' #define APC_CMD_SHUTDOWN 'K' #define APC_CMD_SOFTDOWN 'S' #define APC_CMD_GRACEDOWN '@' #define APC_CMD_SIMPWF 'U' #define APC_CMD_BTESTTOGGLE 'W' #define APC_CMD_OFF 'Z' #define APC_CMD_ON 0x0E /* ^N */ #define APC_CMD_BYPTOGGLE '^' typedef struct { const char *name; int flags; unsigned char cmd; } apc_cmdtab_t; static apc_cmdtab_t apc_cmdtab[] = { { "load.off", APC_NASTY|APC_REPEAT, APC_CMD_OFF }, { "load.on", APC_REPEAT, APC_CMD_ON }, { "test.panel.start", 0, APC_CMD_FPTEST }, { "test.failure.start", 0, APC_CMD_SIMPWF }, { "test.battery.start", 0, APC_CMD_BTESTTOGGLE }, { "test.battery.stop", 0, APC_CMD_BTESTTOGGLE }, { "shutdown.return.grace", APC_NASTY, APC_CMD_GRACEDOWN }, { "shutdown.return", APC_NASTY, APC_CMD_SOFTDOWN }, { "shutdown.stayoff", APC_NASTY|APC_REPEAT, APC_CMD_SHUTDOWN }, { "calibrate.start", 0, APC_CMD_CALTOGGLE }, { "calibrate.stop", 0, APC_CMD_CALTOGGLE }, { "bypass.start", 0, APC_CMD_BYPTOGGLE }, { "bypass.stop", 0, APC_CMD_BYPTOGGLE }, { NULL, 0, 0 } }; /* compatibility with hardware that doesn't do APC_CMDSET ('a') */ static struct { const char *firmware; const char *cmdchars; int flags; } compat_tab[] = { /* APC Matrix */ { "0XI", "789ABCDEFGKLMNOPQRSTUVWXYZcefgjklmnopqrsuwxz/<>\\^\014\026", 0 }, { "0XM", "789ABCDEFGKLMNOPQRSTUVWXYZcefgjklmnopqrsuwxz/<>\\^\014\026", 0 }, { "0ZI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 }, { "5UI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 }, { "5ZM", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz/<>", 0 }, /* APC600 */ { "6QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "6QI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "6TD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "6TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, /* SmartUPS 900 */ { "7QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "7QI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "7TD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "7TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, /* SmartUPS 900I */ { "7II", "79ABCEFGKLMNOPQSUVWXYZcfg", 0 }, /* SmartUPS 2000I */ { "9II", "79ABCEFGKLMNOPQSUVWXYZcfg", 0 }, { "9GI", "79ABCEFGKLMNOPQSUVWXYZcfg", 0 }, /* SmartUPS 1250 */ { "8QD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "8QI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "8TD", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, { "8TI", "79ABCDEFGKLMNOPQRSUVWXYZcefgjklmnopqrsuxz", 0 }, /* CS 350 */ { "5.4.D", "\1ABPQRSUYbdfgjmnx9", 0 }, /* Smart-UPS 600 */ { "D9", "789ABCEFGKLMNOPQRSUVWXYZ", 0 }, { "D8", "789ABCEFGKLMNOPQRSUVWXYZ", 0 }, { "D7", "789ABCEFGKLMNOPQRSUVWXYZ", 0 }, { "D6", "789ABCEFGKLMNOPQRSUVWXYZ", 0 }, { "D5", "789ABCEFGKLMNOPQRSUVWXYZ", 0 }, { "D4", "789ABCEFGKLMNOPQRSUVWXYZ", 0 }, { NULL, NULL, 0 }, }; #endif /* NUT_APCSMART_OLD_H_SEEN */ nut-2.8.4/drivers/upsdrvquery.h0000644000175000017500000000533415044656702013532 00000000000000/* upsdrvquery.h - a single query shot over a driver socket, tracked until a response arrives, returning that line and closing a connection Copyright (C) 2023-2025 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_UPSDRVQUERY_H_SEEN #define NUT_UPSDRVQUERY_H_SEEN 1 #include "common.h" /* TYPE_FD etc. */ #include "timehead.h" typedef struct udq_pipe_conn_s { TYPE_FD sockfd; #ifdef WIN32 OVERLAPPED overlapped; int newread; /* Set to 1 to start a new ReadFile, forget old buf */ #endif /* WIN32 */ char buf[LARGEBUF]; char sockfn[NUT_PATH_MAX + 1]; } udq_pipe_conn_t; udq_pipe_conn_t *upsdrvquery_connect(const char *sockfn); udq_pipe_conn_t *upsdrvquery_connect_drvname_upsname(const char *drvname, const char *upsname); void upsdrvquery_close(udq_pipe_conn_t *conn); ssize_t upsdrvquery_read_timeout(udq_pipe_conn_t *conn, struct timeval tv); ssize_t upsdrvquery_write(udq_pipe_conn_t *conn, const char *buf); ssize_t upsdrvquery_prepare(udq_pipe_conn_t *conn, struct timeval tv); ssize_t upsdrvquery_request(udq_pipe_conn_t *conn, struct timeval tv, const char *query); ssize_t upsdrvquery_restore_broadcast(udq_pipe_conn_t *conn); /* if buf != NULL, last reply is copied there */ ssize_t upsdrvquery_oneshot(const char *drvname, const char *upsname, const char *query, char *buf, const size_t bufsz, struct timeval *tv); ssize_t upsdrvquery_oneshot_sockfn(const char *sockfn, const char *query, char *buf, const size_t bufsz, struct timeval *tv); /* One-shot using an existing connection (caller must close + free connection) */ ssize_t upsdrvquery_oneshot_conn(udq_pipe_conn_t *conn, const char *query, char *buf, const size_t bufsz, struct timeval *tv); /* Internal toggle for some NUT programs that deal with Unix socket chatter. * For a detailed rationale comment see upsdrvquery.c */ extern int nut_upsdrvquery_debug_level; #define NUT_UPSDRVQUERY_DEBUG_LEVEL_DEFAULT 6 #define NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT 5 #define NUT_UPSDRVQUERY_DEBUG_LEVEL_DIALOG 4 #endif /* NUT_UPSDRVQUERY_H_SEEN */ nut-2.8.4/drivers/microsol-common.c0000644000175000017500000005525215044656702014235 00000000000000/* microsol-common.c - common framework for Microsol Solis-based UPS hardware Copyright (C) 2004 Silvino B. Magalhães 2019 Roberto Panerai Velloso 2021 Ygor A. S. Regados This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2021/03/19 - Version 0.70 - Initial release, based on solis driver */ #include "main.h" /* Includes "config.h", must be first */ #include #include #include #include "serial.h" #include "nut_float.h" #include "nut_stdint.h" #include "microsol-common.h" #include "timehead.h" #define false 0 #define true 1 #define RESP_END 0xFE #define ENDCHAR 13 /* replies end with CR */ /* solis commands */ #define CMD_UPSCONT 0xCC #define CMD_SHUT 0xDD #define CMD_SHUTRET 0xDE #define CMD_EVENT 0xCE #define CMD_DUMP 0xCD #define M_UNKN "Unknown solis model" #define NO_SOLIS "Solis not detected! aborting ..." #define UPS_DATE "UPS Date %4d/%02d/%02d" #define SYS_DATE "System Date %4d/%02d/%02d day of week %s" #define ERR_PACK "Wrong package" #define NO_EVENT "No events" #define UPS_TIME "UPS internal Time %0d:%02d:%02d" #define PRG_DAYS "Programming Shutdown Sun Mon Tue Wed Thu Fri Sat" #define PRG_ONON "External shutdown programming active" #define PRG_ONOU "Internal shutdown programming active" #define TIME_OFF "UPS Time power off %02d:%02d" #define TIME_ON "UPS Time power on %02d:%02d" #define PRG_ONOF "Shutdown programming not activated" #define TODAY_DD "Shutdown today at %02d:%02d" #define SHUT_NOW "Shutdown now!" #define FMT_DAYS " %d %d %d %d %d %d %d" /* Date, time and programming group */ static int const BASE_YEAR = 1998; /* Note: code below uses relative "unsigned char" years */ static int device_day, device_month, device_year; static int device_hour, device_minute, device_second; static int power_off_hour, power_off_minute; static int power_on_hour, power_on_minute; static uint8_t device_days_on = 0, device_days_off = 0, days_to_shutdown = 0; static int isprogram = 0, progshut = 0, prgups = 0; static int hourshut, minshut; static int host_year, host_month, host_day; static int host_week; static int host_hour, host_minute, host_second; /* buffers */ unsigned char received_packet[PACKET_SIZE]; /* Identification */ const char *model_name; unsigned int ups_model; bool_t input_220v, output_220v; /* logical */ bool_t detected = 0; bool_t line_unpowered, overheat; bool_t overload, critical_battery, inverter_working; static bool_t recharging; static bool_t packet_parsed = false; double input_voltage, input_current, input_frequency; double output_voltage, output_current, output_frequency; double input_low_limit, input_high_limit; int battery_extension; double battery_voltage, battery_charge; double temperature; double apparent_power, real_power, ups_load; int load_power_factor, nominal_power; /** * Convert standard days string to firmware format * This is needed because UPS sends binary date rotated * from current week day (first bit = current day) */ static char *convert_days(char *cop) { static char alt[8]; int ish, fim; /* FIXME? Are range-checks needed for values more than 6? wire noise etc? */ if (host_week == 6) ish = 0; else ish = 1 + host_week; fim = 7 - ish; /* rotate left only 7 bits */ if (fim > 0) { memcpy(alt, &cop[ish], (size_t)fim); } else { fatalx(EXIT_FAILURE, "%s: value out of range: %d (%d)", __func__, fim, ish); } if (ish > 0) memcpy(&alt[fim], cop, (size_t)ish); alt[7] = 0; /* string terminator */ return alt; } /** Convert bitstring (e.g. 1100101) to binary */ static uint8_t bitstring_to_binary(char *binStr) { uint8_t result = 0; unsigned int i; for (i = 0; i < 7; ++i) { char ch = binStr[i]; if (ch == '1' || ch == '0') result += ((ch - '0') << (6 - i)); else return 0; } return result; } /** * Revert firmware format to standard string binary days * This is needed because UPS sends binary date rotated * from current week day (first bit = current day) */ static uint8_t revert_days(unsigned char firmware_week) { char ordered_week[8]; int i; for (i = 0; i < (6 - host_week); ++i) ordered_week[i] = (firmware_week >> (5 - host_week - i)) & 0x01; for (i = 0; i < host_week + 1; ++i) ordered_week[i + (6 - host_week)] = (firmware_week >> (6 - i)) & 0x01; for (i = 0; i < 7; i++) ordered_week[i] += '0'; ordered_week[7] = 0; /* string terminator */ return bitstring_to_binary(ordered_week); } /** Parse time string from parameters and store their values */ static bool_t set_schedule_time(char *hour, bool_t off_time) { int string_hour, string_minute; if ((strlen(hour) != 5) || (sscanf(hour, "%d:%d", &string_hour, &string_minute) != 2)) return 0; if (off_time) { power_off_hour = string_hour; power_off_minute = string_minute; } else { power_on_hour = string_hour; power_on_minute = string_minute; } return 1; } /** Send immediate shutdown command to UPS */ static void send_shutdown(void) { unsigned int i; for (i = 0; i < 10; i++) ser_send_char(upsfd, CMD_SHUT); upslogx(LOG_NOTICE, "UPS shutdown command sent"); } /** Store clock updates and shutdown schedules to UPS */ static void save_ups_config(void) { unsigned int i; int checksum = 0; unsigned char configuration_packet[12]; /* Prepare configuration packet */ /* FIXME? Check for overflows with int => char truncations? */ configuration_packet[0] = (unsigned char)0xCF; configuration_packet[1] = (unsigned char)host_hour; configuration_packet[2] = (unsigned char)host_minute; configuration_packet[3] = (unsigned char)host_second; configuration_packet[4] = (unsigned char)power_on_hour; configuration_packet[5] = (unsigned char)power_on_minute; configuration_packet[6] = (unsigned char)power_off_hour; configuration_packet[7] = (unsigned char)power_off_minute; configuration_packet[8] = (unsigned char)(host_week << 5); configuration_packet[8] = (unsigned char)configuration_packet[8] | (unsigned char)host_day; configuration_packet[9] = (unsigned char)(host_month << 4); configuration_packet[9] = (unsigned char)configuration_packet[9] | (unsigned char)(host_year - BASE_YEAR); configuration_packet[10] = (unsigned char)device_days_off; /* MSB zero */ configuration_packet[10] = configuration_packet[10] & (~(0x80)); /* Calculate packet content checksum */ for (i = 0; i < 11; i++) { checksum += configuration_packet[i]; } /* FIXME? Does truncation to char have same effect as %256 ? */ configuration_packet[11] = (unsigned char)(checksum % 256); /* Send final packet and checksum to serial port */ for (i = 0; i < 12; i++) { ser_send_char(upsfd, configuration_packet[i]); } } /** Log shut-down schedule data stored in UPS */ static void print_info(void) { /* sunday, monday, tuesday, wednesday, thursday, friday, saturday */ char week_days[7] = { 0, 0, 0, 0, 0, 0, 0 }; unsigned int i; upslogx(LOG_NOTICE, UPS_DATE, device_year, device_month, device_day); upslogx(LOG_NOTICE, UPS_TIME, device_hour, device_minute, device_second); if (prgups > 0) { /* this is the string to binary standard */ for (i = 0; i < 7; i++) { week_days[i] = (days_to_shutdown >> (6 - i)) & 0x01; } if (prgups == 3) upslogx(LOG_NOTICE, PRG_ONOU); else upslogx(LOG_NOTICE, PRG_ONON); upslogx(LOG_NOTICE, TIME_ON, power_on_hour, power_on_minute); upslogx(LOG_NOTICE, TIME_OFF, power_off_hour, power_off_minute); upslogx(LOG_NOTICE, PRG_DAYS); upslogx(LOG_NOTICE, FMT_DAYS, week_days[0], week_days[1], week_days[2], week_days[3], week_days[4], week_days[5], week_days[6]); } else { upslogx(LOG_NOTICE, PRG_ONOF); } } /** Parses received packet with UPS readings and configuration. */ static void scan_received_pack(void) { /* UPS internal time */ device_year = (received_packet[19] & 0x0F) + BASE_YEAR; device_month = (received_packet[19] & 0xF0) >> 4; device_day = (received_packet[18] & 0x1F); device_hour = received_packet[11]; device_minute = received_packet[10]; device_second = received_packet[9]; /* UPS power cycle schedule if in programmed shutdown mode */ if (prgups == 3) { device_days_on = received_packet[17]; days_to_shutdown = revert_days(device_days_on); /* Automatic UPS power-off time */ power_off_hour = received_packet[15]; power_off_minute = received_packet[16]; /* Automatic UPS power-on time */ power_on_hour = received_packet[13]; power_on_minute = received_packet[14]; } /* These UPS have 110V- or 220V-output models */ if ((0x01 & received_packet[20]) == 0x01) { output_220v = 1; } /* UPS state flags */ critical_battery = (0x04 & received_packet[20]) == 0x04; inverter_working = (0x08 & received_packet[20]) == 0x08; overheat = (0x10 & received_packet[20]) == 0x10; line_unpowered = (0x20 & received_packet[20]) == 0x20; overload = (0x80 & received_packet[20]) == 0x80; recharging = (0x02 & received_packet[20]) == 0x02; if (line_unpowered) { recharging = false; } /* Check if input voltage is 110V or 220V */ if ((0x40 & received_packet[20]) == 0x40) { input_220v = 1; } else { input_220v = 0; } /* Internal battery temperature */ temperature = 0x7F & received_packet[4]; if (0x80 & received_packet[4]) { temperature -= 128; } /* Parse model-specific data (current and voltages). * Doing it here as these values are used for the next calculations. */ scan_received_pack_model_specific(); ups_load = (apparent_power / nominal_power) * 100.0; if (battery_charge > 100.0) { battery_charge = 100.0; } else if (battery_charge < 0.0) { battery_charge = 0.0; } output_frequency = 60; if (!inverter_working) { output_voltage = 0; output_frequency = 0; } if (!line_unpowered && inverter_working) output_frequency = input_frequency; if (apparent_power < 0) load_power_factor = 0; else { if (d_equal(apparent_power, 0)) load_power_factor = 100; else load_power_factor = ((real_power / apparent_power) * 100); if (load_power_factor > 100) { load_power_factor = 100; } } /* input 110V or 220v */ if (input_220v == 0) { input_low_limit = 75; input_high_limit = 150; } else { input_low_limit = 150; input_high_limit = 300; } } /** * Start processing of received packets * * Packet format: 25-bytes binary structure * Byte 1: Packet type/UPS model * Byte 2: Output voltage data * Byte 3: Input voltage data * Byte 4: Battery voltage data * Byte 5: UPS temperature data * Byte 6: Output current data * Byte 7: Electrical relay setup * Byte 8-9: Real power data * Byte 10: UPS clock - seconds * Byte 11: UPS clock - minutes * Byte 12: UPS clock - hours * Byte 13: Zero * Byte 14: UPS scheduler - power-on hour * Byte 15: UPS scheduler - power-on minute * Byte 16: UPS scheduler - power-off hour * Byte 17: UPS scheduler - power-off minute * Byte 18: UPS scheduler - weekdays * Byte 19: UPS clock - day of month * Byte 20: UPS clock - year (since 1998) (left 4 bits) and month (right 4 bits) * Byte 21: UPS flags (power status, battery status, overload, overheat, nominal input voltage, nominal output voltage) * Byte 22-23: Input frequency data * Byte 24: Packet checksum * Byte 25: Packet delimiter, always 0xFE */ static void comm_receive(const unsigned char *bufptr, size_t size) { size_t i; if (size == PACKET_SIZE) { int checksum = 0; upsdebug_hex(3, "comm_receive: bufptr", bufptr, size); /* Calculate packet checksum */ for (i = 0; i < PACKET_SIZE - 2; i++) { checksum += bufptr[i]; } checksum = checksum % 256; upsdebugx(4, "%s: calculated checksum = 0x%02x, bufptr[23] = 0x%02x", __func__, (unsigned int)checksum, bufptr[23]); /* Only proceed if checksum matches and packet delimiter is found */ if (checksum == bufptr[23] && bufptr[24] == 254) { upsdebugx(4, "%s: valid packet received", __func__); memcpy(received_packet, bufptr, PACKET_SIZE); if ((received_packet[0] & 0xF0) == 0xA0 || (received_packet[0] & 0xF0) == 0xB0) { /* If UPS still not detected, compare with available lists */ if (!detected) { ups_model = received_packet[0]; detected = true; } if (!ups_model_defined()) { upslogx(LOG_DEBUG, M_UNKN); } scan_received_pack(); } } } } /** Refresh host time variables */ static void refresh_host_time(void) { const time_t epoch = time(NULL); struct tm now; localtime_r(&epoch, &now); host_year = now.tm_year + 1900; host_month = now.tm_mon + 1; host_day = now.tm_mday; host_week = now.tm_wday; host_hour = now.tm_hour; host_minute = now.tm_min; host_second = now.tm_sec; } /** Query shut-down schedule configuration */ static void setup_poweroff_schedule(void) { bool_t i1 = 0, i2 = 0; char *daysoff; refresh_host_time(); if (testvar("prgshut")) { prgups = atoi(getval("prgshut")); } if (prgups > 0 && prgups < 3) { if (testvar("daysweek")) { device_days_on = bitstring_to_binary(convert_days(getval("daysweek"))); } if (testvar("daysoff")) { daysoff = getval("daysoff"); days_to_shutdown = bitstring_to_binary(daysoff); device_days_off = bitstring_to_binary(convert_days(daysoff)); } if (testvar("houron")) { i1 = set_schedule_time(getval("houron"), 0); } if (testvar("houroff")) { i2 = set_schedule_time(getval("houroff"), 1); } if (i1 && i2 && (device_days_on > 0)) { isprogram = 1; /* If configured to shut-down UPS, push schedule to internal configuration */ if (prgups == 2) { save_ups_config(); } } else { if (i2 == 1 && device_days_off > 0) { isprogram = 1; device_days_on = device_days_off; } } } } /** Check shut-down schedule and sets system to shut down if needed */ static void check_shutdown_schedule(void) { bool_t is_shutdown_day = 0; if (isprogram || prgups == 3) { refresh_host_time(); is_shutdown_day = (days_to_shutdown >> (6 - host_week)) & 0x01; if (is_shutdown_day) { upslogx(LOG_NOTICE, TODAY_DD, hourshut, minshut); if (host_hour == hourshut && host_minute >= minshut) { upslogx(LOG_NOTICE, SHUT_NOW); progshut = 1; } } } } /** Resynchronizes packet boundaries */ static void resynchronize_packet(void) { unsigned char sync_received_byte = 0; unsigned short i; /* Flush serial port buffers */ ser_flush_io(upsfd); upsdebugx(3, "%s: Synchronizing packet boundaries...", __func__); /* * - Read until end-of-response character (0xFE): * read up to 3 packets in size before giving up * synchronizing with the device. */ for (i = 0; i < PACKET_SIZE * 3 && sync_received_byte != RESP_END; i++) { ser_get_char(upsfd, &sync_received_byte, 3, 0); } /* If no packet boundary was found, terminate communication */ if (sync_received_byte != RESP_END) { fatalx(EXIT_FAILURE, NO_SOLIS); } } /** Synchronize packet receiving and setup basic variables */ static void get_base_info(void) { unsigned char packet[PACKET_SIZE]; ssize_t tam; if (testvar("battext")) { battery_extension = atoi(getval("battext")); } setup_poweroff_schedule(); /* dummy read attempt to sync - throw it out */ upsdebugx(3, "%s: sending CMD_UPSCONT and ENDCHAR", __func__); ser_send(upsfd, "%c%c", CMD_UPSCONT, ENDCHAR); resynchronize_packet (); upsdebugx(4, "%s: requesting %d bytes from ser_get_buf_len()", __func__, PACKET_SIZE); tam = ser_get_buf_len(upsfd, packet, PACKET_SIZE, 3, 0); upsdebugx(2, "%s: received %" PRIiSIZE " bytes from ser_get_buf_len()", __func__, tam); if (tam > 0 && nut_debug_level >= 4) { upsdebug_hex(4, "received from ser_get_buf_len()", packet, (size_t)tam); } comm_receive(packet, (size_t)tam); if (!detected) { fatalx(EXIT_FAILURE, NO_SOLIS); } set_ups_model(); /* Setup power-off times */ if (prgups != 0) { if (prgups == 1) { /* If only this host is meant to be powered off, use proper time. */ hourshut = power_off_hour; minshut = power_off_minute; } else { /* If the UPS is to be powered off too, give * a 5-minute grace time to shutdown hosts */ if (power_off_minute < 5) { if (power_off_hour > 1) hourshut = power_off_hour - 1; else hourshut = 23; minshut = 60 - (5 - power_off_minute); } else { hourshut = power_off_hour; minshut = power_off_minute - 5; } } } /* manufacturer */ dstate_setinfo("ups.mfr", "%s", "APC"); dstate_setinfo("ups.model", "%s", model_name); dstate_setinfo("input.transfer.low", "%03.1f", input_low_limit); dstate_setinfo("input.transfer.high", "%03.1f", input_high_limit); dstate_addcmd("shutdown.return"); /* CMD_SHUTRET */ dstate_addcmd("shutdown.stayoff"); /* CMD_SHUT */ upslogx(LOG_NOTICE, "Detected %s on %s", dstate_getinfo("ups.model"), device_path); print_info(); } /** Retrieves new packet from serial connection and parses it */ static void get_updated_info(void) { unsigned char temp[256]; ssize_t tam; check_shutdown_schedule(); /* get update package */ temp[0] = 0; /* flush temp buffer */ upsdebugx(3, "%s: requesting %d bytes from ser_get_buf_len()", __func__, PACKET_SIZE); tam = ser_get_buf_len(upsfd, temp, PACKET_SIZE, 3, 0); upsdebugx(2, "%s: received %" PRIiSIZE " bytes from ser_get_buf_len()", __func__, tam); if (tam > 0 && nut_debug_level >= 4) upsdebug_hex(4, "received from ser_get_buf_len()", temp, (size_t)tam); packet_parsed = false; if (temp[24] == RESP_END) { /* Packet boundary found, process packet */ comm_receive(temp, (size_t)tam); packet_parsed = true; } else { /* Malformed packet received, possible boundary desynchronization. */ upsdebugx(3, "%s: Malformed packet received, trying to resynchronize...", __func__); resynchronize_packet (); } } static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); /* Power-cycle UPS */ if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ser_send_char(upsfd, CMD_SHUTRET); /* 0xDE */ return STAT_INSTCMD_HANDLED; } /* Power-off UPS */ if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ser_send_char(upsfd, CMD_SHUT); /* 0xDD */ return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_initinfo(void) { get_base_info(); upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { get_updated_info(); if (packet_parsed) { dstate_setinfo("battery.charge", "%03.1f", battery_charge); dstate_setinfo("battery.voltage", "%02.1f", battery_voltage); dstate_setinfo("input.frequency", "%2.1f", input_frequency); dstate_setinfo("input.voltage", "%03.1f", input_voltage); dstate_setinfo("output.current", "%03.1f", output_current); dstate_setinfo("output.power", "%03.1f", apparent_power); dstate_setinfo("output.powerfactor", "%0.2f", load_power_factor / 100.0); dstate_setinfo("output.realpower", "%03.1f", real_power); dstate_setinfo("output.voltage", "%03.1f", output_voltage); dstate_setinfo("ups.temperature", "%2.2f", temperature); dstate_setinfo("ups.load", "%03.1f", ups_load); status_init(); if (!line_unpowered) { status_set("OL"); /* On line */ } else { status_set("OB"); /* On battery */ } if (overload) { status_set("OVER"); /* Overload */ } if (overheat) { status_set("OVERHEAT"); /* Overheat */ } if (recharging) { status_set("CHRG"); /* Charging battery */ } if (critical_battery) { status_set("LB"); /* Critically low battery */ } if (progshut) { /* Software-based shutdown now */ if (prgups == 2) send_shutdown(); /* Send command to shutdown UPS in 4-5 minutes */ /* Workaround for triggering servers' power-off before UPS power-off */ status_set("LB"); } status_commit(); dstate_dataok(); } else { /* * If no packet was processed, report data as stale. * Most likely to be fixed on next received packet. */ dstate_datastale (); } } /*! @brief Power down the attached load immediately. * Basic idea: find out line status and send appropriate command. * - on battery: send normal shutdown, UPS will return by itself on utility * - on line: send shutdown+return, UPS will cycle and return soon. */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ if (!line_unpowered) { /* on line */ upslogx(LOG_NOTICE, "On line, sending power cycle command..."); ser_send_char(upsfd, CMD_SHUTRET); } else { upslogx(LOG_NOTICE, "On battery, sending power off command..."); ser_send_char(upsfd, CMD_SHUT); } } void upsdrv_help(void) { printf("\nAPC/Microsol options\n\n"); printf(" Battery extension (AH)\n"); printf(" battext = 80\n\n"); printf(" Scheduled UPS power on/off\n"); printf(" prgshut = 0 (default, no scheduled shutdown)\n"); printf(" prgshut = 1 (software-based shutdown schedule without UPS power-off)\n"); printf(" prgshut = 2 (software-based shutdown schedule with UPS power-off)\n"); printf(" prgshut = 3 (internal UPS shutdown schedule)\n\n"); printf(" Schedule configuration:\n"); printf(" daysweek = 1010101 (power on days)\n"); printf(" daysoff = 1010101 (power off days)\n"); printf(" where each digit is a day from sun...sat with 0 = off and 1 = on\n\n"); printf(" houron = hh:mm hh = hour 0-23 mm = minute 0-59 separated with :\n"); printf(" houroff = hh:mm hh = hour 0-23 mm = minute 0-59 separated with :\n"); printf(" where houron is power-on hour and houroff is shutdown and power-off hour\n\n"); printf(" Use daysweek and houron to programming and save UPS power on/off\n"); printf(" These are valid only if prgshut = 2 or 3\n"); } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "battext", "Battery extension (0-80AH)"); addvar(VAR_VALUE, "prgshut", "Scheduled power-off mode (0-3)"); addvar(VAR_VALUE, "daysweek", "Days of week for UPS shutdown"); addvar(VAR_VALUE, "daysoff", "Days of week for driver-induced shutdown"); addvar(VAR_VALUE, "houron", "Power on hour (hh:mm)"); addvar(VAR_VALUE, "houroff", "Power off hour (hh:mm)"); } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B9600); ser_set_dtr(upsfd, 1); ser_set_rts(upsfd, 0); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/powercom.h0000644000175000017500000000647615000736161012752 00000000000000/* * powercom.h - defines for the newpowercom.c driver * * Copyrights: * (C) 2002 Simon Rozman * (C) 1999 Peter Bieringer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUT_POWERCOM_H_SEEN #define NUT_POWERCOM_H_SEEN 1 /* C-libary includes */ #include #include #ifndef WIN32 #include #endif /* !WIN32 */ #include /* nut includes */ #include "serial.h" #include "nut_stdint.h" #include "timehead.h" /* supported types */ struct type { const char *name; unsigned char num_of_bytes_from_ups; struct method_of_flow_control { const char *name; void (*setup_flow_control)(void); } flowControl; struct validation_byte { unsigned int index_of_byte, required_value; /* An example might explain the intention better then prose. * Suppose we want to validate the data with: * powercom_raw_data[5] == 0x80 * then we will set index_of_byte to 5U and required_value to * 0x80U: { 5U, 0x80U }. */ } validation[3]; /* The validation array is of length 3 because 3 is longest * validation sequence for any type. */ /* Some UPSs must have a minutes and a seconds arguments for * the COUNTER commands while others are known to work with the * seconds argument alone. */ struct delay_for_power_kill { unsigned char delay[2]; /* { minutes, seconds } */ unsigned char minutesShouldBeUsed; /* 'n' in case the minutes value, which is delay[0], should * be skipped and not sent to the UPS. */ } shutdown_arguments; /* parameters to calculate input and output freq., one pair used for * both input and output functions: * The pair [0],[1] defines parameters for 1/(A*x+B) to calculate freq. * from raw data 'x'. */ float freq[2]; /* parameters to calculate load %, two pairs for each type: * First pair [0],[1] defines the parameters for A*x+B to calculate load * from raw data when offline and the second pair [2],[3] is used when * online */ float loadpct[4]; /* parameters to calculate battery %, five parameters for each type: * First three params [0],[1],[2] defines the parameters for A*x+B*y+C to calculate * battery % (x is raw data, y is load %) when offline. * Fourth and fifth parameters [3],[4] are used to calculate D*x+E when online. */ float battpct[5]; /* parameters to calculate utility and output voltage, two pairs for * each type: * First pair [0],[1] defines the parameters for A*x+B to calculate utility * from raw data when line voltage is >=220 and the second pair [2],[3] * is used otherwise. */ float voltage[4]; }; #endif /* NUT_POWERCOM_H_SEEN */ nut-2.8.4/drivers/pijuice.c0000644000175000017500000005606515044656702012553 00000000000000/* pijuice.c Driver for the PiJuice HAT (www.pijuice.com), addressed via i2c. Copyright (C) 2019 Andrew Anderson This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include #include "nut_stdint.h" #define DRIVER_NAME "PiJuice UPS driver" #define DRIVER_VERSION "0.15" /* * Linux I2C userland is a bit of a mess until distros refresh to * the i2c-tools 4.x release that profides i2c/smbus.h for userspace * instead of (re)using linux/i2c-dev.h, which conflicts with a * kernel header of the same name. * * See: * https://i2c.wiki.kernel.org/index.php/Plans_for_I2C_Tools_4 */ #if HAVE_LINUX_SMBUS_H # include #endif #if HAVE_LINUX_I2C_DEV_H # include /* for I2C_SLAVE */ # if !HAVE_LINUX_SMBUS_H # ifndef I2C_FUNC_I2C # include # endif # endif #endif /* Forward decls */ static int instcmd(const char *cmdname, const char *extra); /* * i2c-tools pre-4.0 has a userspace header with a name that conflicts * with a kernel header, so it may be ignored/removed by distributions * when packaging i2c-tools. * * This will cause the driver to be un-buildable on certain * configurations, so include the necessary bits here to handle this * situation. */ #if WITH_LINUX_I2C # if !HAVE_DECL_I2C_SMBUS_ACCESS static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command, int size, union i2c_smbus_data *data) { struct i2c_smbus_ioctl_data args; __s32 err; args.read_write = read_write; args.command = command; args.size = size; args.data = data; err = ioctl(file, I2C_SMBUS, &args); if (err == -1) err = -errno; return err; } # endif # if !HAVE_DECL_I2C_SMBUS_READ_BYTE_DATA static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command) { union i2c_smbus_data data; int err; if ((err = i2c_smbus_access(file, I2C_SMBUS_READ, command, I2C_SMBUS_BYTE_DATA, &data)) < 0) return err; else return 0x0FF & data.byte; } # endif # if !HAVE_DECL_I2C_SMBUS_WRITE_BYTE_DATA static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value) { union i2c_smbus_data data; int err; data.byte = value; if ((err = i2c_smbus_access(file, I2C_SMBUS_WRITE, command, I2C_SMBUS_BYTE_DATA, &data)) < 0) return err; else return 0x0FF & data.byte; } # endif # if !HAVE_DECL_I2C_SMBUS_READ_WORD_DATA static inline __s32 i2c_smbus_read_word_data(int file, __u8 command) { union i2c_smbus_data data; int err; if ((err = i2c_smbus_access(file, I2C_SMBUS_READ, command, I2C_SMBUS_WORD_DATA, &data)) < 0) return err; else return 0x0FFFF & data.word; } # endif # if !HAVE_DECL_I2C_SMBUS_WRITE_WORD_DATA static inline __s32 i2c_smbus_write_word_data(int file, __u8 command, __u16 value) { union i2c_smbus_data data; int err; data.word = value; if ((err = i2c_smbus_access(file, I2C_SMBUS_WRITE, command, I2C_SMBUS_WORD_DATA, &data)) < 0) return err; else return 0x0FFFF & data.word; } # endif # if !HAVE_DECL_I2C_SMBUS_READ_BLOCK_DATA static inline __u8* i2c_smbus_read_i2c_block_data(int file, __u8 command, __u8 length, __u8 *values) { union i2c_smbus_data data; int err; if ( length > I2C_SMBUS_BLOCK_MAX) { length = I2C_SMBUS_BLOCK_MAX; } data.block[0] = length; memcpy(data.block + 1, values, length); if ((err = i2c_smbus_access(file, I2C_SMBUS_READ, command, I2C_SMBUS_I2C_BLOCK_DATA, &data)) < 0) return NULL; else memcpy(values, &data.block[1], data.block[0]); return values; } # endif #endif /* if WITH_LINUX_I2C */ #define STATUS_CMD 0x40 #define CHARGE_LEVEL_CMD 0x41 #define CHARGE_LEVEL_HI_RES_CMD 0x42 #define FAULT_EVENT_CMD 0x44 #define BUTTON_EVENT_CMD 0x45 #define BATTERY_TEMPERATURE_CMD 0x47 #define BATTERY_VOLTAGE_CMD 0x49 #define BATTERY_CURRENT_CMD 0x4b #define IO_VOLTAGE_CMD 0x4d #define IO_CURRENT_CMD 0x4f #define CHARGING_CONFIG_CMD 0x51 #define BATTERY_PROFILE_ID_CMD 0x52 #define BATTERY_PROFILE_CMD 0x53 #define BATTERY_EXT_PROFILE_CMD 0x54 #define BATTERY_TEMP_SENSE_CONFIG_CMD 0x5D #define POWER_INPUTS_CONFIG_CMD 0x5E #define RUN_PIN_CONFIG_CMD 0x5F #define POWER_REGULATOR_CONFIG_CMD 0x60 #define WATCHDOG_ACTIVATION_CMD 0x61 #define POWER_OFF_CMD 0x62 #define WAKEUP_ON_CHARGE_CMD 0x63 #define SYSTEM_POWER_SWITCH_CTRL_CMD 0x64 #define LED_STATE_CMD 0x66 #define LED_BLINK_CMD 0x68 #define LED_CONFIGURATION_CMD 0x6A #define BUTTON_CONFIGURATION_CMD 0x6E #define IO1_CONFIGURATION_CMD 0x72 #define IO1_PIN_ACCESS_CMD 0x75 #define IO2_CONFIGURATION_CMD 0x77 #define IO2_PIN_ACCESS_CMD 0x7A #define I2C_ADDRESS_CMD 0x7C #define ID_EEPROM_WRITE_PROTECT_CTRL_CMD 0x7E #define ID_EEPROM_ADDRESS_CMD 0x7F #define RTC_TIME_CMD 0xB0 #define RTC_ALARM_CMD 0xB9 #define RTC_CTRL_STATUS_CMD 0xC2 #define RESET_TO_DEFAULT_CMD 0xF0 #define FIRMWARE_VERSION_CMD 0xFD #define BATT_NORMAL 0 #define BATT_CHARGING_FROM_IN 1 #define BATT_CHARGING_FROM_5V 2 #define BATT_NOT_PRESENT 3 #define POWER_NOT_PRESENT 0 #define POWER_BAD 1 #define POWER_WEAK 2 #define POWER_PRESENT 3 #define LOW_BATTERY_THRESHOLD 25.0 #define HIGH_BATTERY_THRESHOLD 75.0 #define NOMINAL_BATTERY_VOLTAGE 4.18 static uint8_t i2c_address = 0x14; static uint8_t shutdown_delay = 30; /* * Flags used to indicate a change in power status */ static uint8_t usb_power = 0; static uint8_t gpio_power = 0; static uint8_t battery_power = 0; /* * Smooth out i2c read errors by holding the most recent * battery charge level reading */ static float battery_charge_level = 0; /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Andrew Anderson ", DRV_EXPERIMENTAL, { NULL } }; /* The macros below all write into a "data" variable defined by the routine * scope which calls them, with respective type of uint8_t for "byte" and * uint16_t for "word" macros. Native i2c functions operate with __s32 type * (currently, signed 32-bit ints?) with negative values for error returns. * Note: some manpages refer to "s32" while headers on my and CI systems use * a "__s32" type. Maybe this is something to determine in configure script? * Code below was fixed to convert the valid values and avoid compiler * warnings about comparing whether unsigned ints happened to be negative. */ #define I2C_READ_BYTE(fd, cmd, label) \ { \ __s32 sData; \ if ((sData = i2c_smbus_read_byte_data(upsfd, cmd)) < 0 ) { \ upsdebugx(2, "Failure reading the i2c bus [%s]", label); \ return; \ } ; \ data = (uint8_t) sData; \ } #define I2C_WRITE_BYTE(fd, cmd, value, label) \ { \ if ( i2c_smbus_write_byte_data(upsfd, cmd, value) < 0 ) { \ upsdebugx(2, "Failure writing to the i2c bus [%s]", label); \ return; \ } ; \ } #define I2C_READ_WORD(fd, cmd, label) \ { \ __s32 sData; \ if ((sData = i2c_smbus_read_word_data(upsfd, cmd)) < 0 ) { \ upsdebugx(2, "Failure reading the i2c bus [%s]", label); \ return; \ } ; \ data = (uint16_t) sData; \ } #define I2C_READ_BLOCK(fd, cmd, size, block, label) \ if ((i2c_smbus_read_i2c_block_data(upsfd, cmd, size, block)) < 0 ) { \ upsdebugx(2, "Failure reading the i2c bus [%s]", label); \ return; \ } static inline int open_i2c_bus(char *path, uint8_t addr) { int file; if ((file = open(path, O_RDWR)) < 0) { fatal_with_errno(EXIT_FAILURE, "Failed to open the i2c bus on %s", path); } if (ioctl(file, I2C_SLAVE, addr) < 0) { fatal_with_errno(EXIT_FAILURE, "Failed to acquire the i2c bus and/or talk to the UPS"); } return file; } static void get_charge_level_hi_res(void) { uint8_t cmd = CHARGE_LEVEL_HI_RES_CMD; uint16_t data; upsdebugx( 3, __func__ ); I2C_READ_WORD( upsfd, cmd, __func__ ) /* * Use an external variable to allow for missed i2c bus * reads; the charge level data may be slightly stale, * but no other options seem reasonable: * * 1) store 0 * Leads to a false report of a depleted battery, possibly * triggering an immediate shutdown if on battery power only * 2) store -1 * Adds a lot of logic to "skip" over negative charge levels, * which effectively accomplishes the same thing * 3) retry the read immediately * Could tie up the i2c bus and make matters exponentially worse */ battery_charge_level = data / 10.0; upsdebugx( 1, "Battery Charge Level: %02.1f%%", battery_charge_level ); dstate_setinfo( "battery.charge", "%02.1f", battery_charge_level ); } static void get_status(void) { uint8_t cmd = STATUS_CMD, data, batteryStatus, powerInput, powerInput5vIo; upsdebugx( 3, __func__ ); I2C_READ_BYTE( upsfd, cmd, __func__ ) batteryStatus = data >> 2 & 0x03; switch( batteryStatus ) { case BATT_NORMAL: upsdebugx( 1, "Battery Status: Normal" ); dstate_setinfo( "battery.packs", "%d", 1 ); dstate_setinfo( "battery.packs.bad", "%d", 0 ); break; case BATT_CHARGING_FROM_IN: upsdebugx( 1, "Battery Status: Charging from IN" ); dstate_setinfo( "battery.packs", "%d", 1 ); dstate_setinfo( "battery.packs.bad", "%d", 0 ); break; case BATT_CHARGING_FROM_5V: upsdebugx( 1, "Battery Status: Charging from 5V" ); dstate_setinfo( "battery.packs", "%d", 1 ); dstate_setinfo( "battery.packs.bad", "%d", 0 ); break; case BATT_NOT_PRESENT: upsdebugx( 1, "Battery Status: Not Present" ); dstate_setinfo( "battery.packs", "%d", 0 ); dstate_setinfo( "battery.packs.bad", "%d", 1 ); break; default: upsdebugx( 1, "battery.status: UNKNOWN" ); } powerInput = data >> 4 & 0x03; switch( powerInput ) { case POWER_NOT_PRESENT: upsdebugx( 1, "Power Input: Not Present" ); break; case POWER_BAD: upsdebugx( 1, "Power Input: Bad" ); break; case POWER_WEAK: upsdebugx( 1, "Power Input: Weak" ); break; case POWER_PRESENT: upsdebugx( 1, "Power Input: Present" ); break; default: upsdebugx( 1, "Power Input: UNKNOWN" ); } powerInput5vIo = data >> 6 & 0x03; switch( powerInput5vIo ) { case POWER_NOT_PRESENT : upsdebugx(1, "Power Input 5v: Not Present"); break; case POWER_BAD: upsdebugx(1, "Power Input 5v: Bad"); break; case POWER_WEAK: upsdebugx(1, "Power Input 5v: Weak"); break; case POWER_PRESENT: upsdebugx(1, "Power Input 5v: Present"); break; default: upsdebugx(1, "Power Input 5v: UNKNOWN"); } if ( batteryStatus == BATT_NORMAL || batteryStatus == BATT_CHARGING_FROM_IN || batteryStatus == BATT_CHARGING_FROM_5V ) { get_charge_level_hi_res(); if ( battery_charge_level <= LOW_BATTERY_THRESHOLD ) { upsdebugx( 1, "Battery Charge Status: LOW" ); status_set("LB"); } else if ( battery_charge_level > HIGH_BATTERY_THRESHOLD ) { upsdebugx( 1, "Battery Charge Status: HIGH" ); status_set("HB"); } } else if ( batteryStatus == BATT_NOT_PRESENT ) { status_set("RB"); } if ( batteryStatus <= BATT_NOT_PRESENT && powerInput <= POWER_PRESENT && powerInput5vIo <= POWER_PRESENT ) { if ( powerInput == POWER_NOT_PRESENT && ( powerInput5vIo != POWER_NOT_PRESENT )) { if ( usb_power != 1 || gpio_power != 0 ) { upslogx( LOG_NOTICE, "On USB power" ); } usb_power = 1; gpio_power = 0; battery_power = 0; upsdebugx( 1, "On USB power [%d:%d:%d]", usb_power, gpio_power, battery_power ); status_set("OL"); if ( batteryStatus == BATT_CHARGING_FROM_5V ) { status_set("CHRG"); upsdebugx( 1, "Battery Charger Status: charging" ); dstate_setinfo( "battery.charger.status", "%s", "charging" ); } else if ( batteryStatus == BATT_NORMAL ) { upsdebugx( 1, "Battery Charger Status: resting" ); dstate_setinfo( "battery.charger.status", "%s", "resting" ); } } else if ( powerInput5vIo == POWER_NOT_PRESENT && ( powerInput != POWER_NOT_PRESENT && powerInput <= POWER_PRESENT )) { if ( gpio_power != 1 || usb_power != 0 ) { upslogx( LOG_NOTICE, "On 5V_GPIO power" ); } usb_power = 0; gpio_power = 1; battery_power = 0; upsdebugx( 1, "On 5V_GPIO power [%d:%d:%d]", usb_power, gpio_power, battery_power ); status_set("OL"); if ( batteryStatus == BATT_CHARGING_FROM_IN ) { status_set("CHRG"); upsdebugx( 1, "Battery Charger Status: charging" ); dstate_setinfo( "battery.charger.status", "%s", "charging" ); } else if ( batteryStatus == BATT_NORMAL ) { upsdebugx( 1, "Battery Charger Status: resting" ); dstate_setinfo( "battery.charger.status", "%s", "resting" ); } } else if ( ( powerInput != POWER_NOT_PRESENT && powerInput <= POWER_PRESENT ) && ( powerInput5vIo != POWER_NOT_PRESENT && powerInput5vIo <= POWER_PRESENT )) { if ( usb_power != 1 || gpio_power != 1 ) { upslogx( LOG_NOTICE, "On USB and 5V_GPIO power" ); } usb_power = 1; gpio_power = 1; battery_power = 0; upsdebugx( 1, "On USB and 5V_GPIO power [%d:%d:%d]", usb_power, gpio_power, battery_power ); status_set("OL"); if ( batteryStatus == BATT_CHARGING_FROM_IN ) { status_set("CHRG"); upsdebugx( 1, "Battery Charger Status: charging" ); dstate_setinfo("battery.charger.status", "%s", "charging"); } else if ( batteryStatus == BATT_NORMAL ) { upsdebugx( 1, "Battery Charger Status: resting" ); dstate_setinfo( "battery.charger.status", "%s", "resting" ); } } else if ( powerInput == POWER_NOT_PRESENT && powerInput5vIo == POWER_NOT_PRESENT ) { if ( usb_power != 0 || gpio_power != 0 ) { upslogx( LOG_NOTICE, "On Battery power" ); } usb_power = 0; gpio_power = 0; battery_power = 1; upsdebugx( 1, "On Battery power [%d:%d:%d]", usb_power, gpio_power, battery_power ); status_set("OB"); status_set("DISCHRG"); } } } static void get_battery_temperature(void) { uint8_t cmd = BATTERY_TEMPERATURE_CMD; int16_t data; upsdebugx( 3, __func__ ); I2C_READ_WORD( upsfd, cmd, __func__ ) upsdebugx( 1, "Battery Temperature: %d°C", data ); dstate_setinfo( "battery.temperature", "%d", data ); } static void get_battery_voltage(void) { uint8_t cmd = BATTERY_VOLTAGE_CMD; int16_t data; upsdebugx( 3, __func__ ); I2C_READ_WORD( upsfd, cmd, __func__ ) upsdebugx( 1, "Battery Voltage: %0.3fV", data / 1000.0 ); dstate_setinfo( "battery.voltage", "%0.3f", data / 1000.0 ); } static void get_battery_current(void) { uint8_t cmd = BATTERY_CURRENT_CMD; int16_t data; upsdebugx( 3, __func__ ); /* * The reported current can actually be negative, so we cannot * check for I2C failure by looking for negative values */ data = i2c_smbus_read_word_data(upsfd, cmd); if ( data & ( 1 << 15 ) ) { data = data - ( 1 << 16 ); } upsdebugx( 1, "Battery Current: %0.3fA", data / 1000.0 ); dstate_setinfo( "battery.current", "%0.3f", data / 1000.0 ); } static void get_io_voltage(void) { uint8_t cmd = IO_VOLTAGE_CMD; int16_t data; upsdebugx( 3, __func__ ); I2C_READ_WORD( upsfd, cmd, __func__ ) upsdebugx( 1, "Input Voltage: %.3fV", data / 1000.0 ); dstate_setinfo( "input.voltage", "%.3f", data / 1000.0 ); } static void get_io_current(void) { uint8_t cmd = IO_CURRENT_CMD; int16_t data; upsdebugx( 3, __func__ ); /* * The reported current can actually be negative, so we cannot * check for I2C failure by looking for negative values */ data = i2c_smbus_read_word_data(upsfd, cmd); if ( data & ( 1 << 15 ) ) { data = data - ( 1 << 16 ); } upsdebugx( 1, "Input Current: %.3fA", data / 1000.0 ); dstate_setinfo( "input.current", "%.3f", data / 1000.0 ); } static void get_firmware_version(void) { uint8_t cmd = FIRMWARE_VERSION_CMD; uint16_t data; uint8_t major, minor; upsdebugx( 3, __func__ ); I2C_READ_WORD( upsfd, cmd, __func__ ) major = data >> 4; minor = ( data << 4 & 0xf0 ) >> 4; if (( major != 1 ) || ( minor > 3 )) { upslogx( LOG_WARNING, "Unknown Firmware release: %d.%d", major, minor ); } upsdebugx( 1, "UPS Firmware Version: %d.%d", major, minor ); dstate_setinfo( "ups.firmware", "%d.%d", major, minor ); } static void get_battery_profile(void) { uint8_t cmd = BATTERY_PROFILE_CMD; __u8 block[I2C_SMBUS_BLOCK_MAX]; upsdebugx( 3, __func__ ); I2C_READ_BLOCK( upsfd, cmd, 14, block, __func__ ) upsdebugx( 1, "Battery Capacity: %0.3fAh", ( block[1] << 8 | block[0] ) / 1000.0 ); dstate_setinfo( "battery.capacity", "%0.3f", ( block[1] << 8 | block[0] ) / 1000.0 ); } static void get_battery_profile_ext(void) { uint8_t cmd = BATTERY_EXT_PROFILE_CMD; __u8 block[I2C_SMBUS_BLOCK_MAX]; upsdebugx( 3, __func__ ); I2C_READ_BLOCK( upsfd, cmd, 17, block, __func__ ) switch( block[0] & 0xFF00 ) { case 0: upsdebugx( 1, "Battery Chemistry: LiPO" ); dstate_setinfo( "battery.type", "%s", "LiPO" ); break; case 1: upsdebugx( 1, "Battery Chemistry: LiFePO4" ); dstate_setinfo( "battery.type", "%s", "LiFePO4" ); break; default: upsdebugx( 1, "Battery Chemistry: UNKNOWN" ); dstate_setinfo( "battery.type", "%s", "UNKNOWN" ); } } static void get_power_off(void) { uint8_t cmd = POWER_OFF_CMD; uint8_t data; upsdebugx( 3, __func__ ); I2C_READ_BYTE( upsfd, cmd, __func__ ) if ( data == 255 ) { upsdebugx( 1, "Power Off: DISABLED" ); } else if ( data <= 250 ) { upsdebugx( 1, "Power Off: %d Seconds", data ); } } static void set_power_off(void) { uint8_t cmd = POWER_OFF_CMD; upsdebugx( 3, __func__ ); /* * Acceptable values for shutdown_delay are 1-250, * use 0/255 to clear a scheduled power off command */ if ( shutdown_delay > 250 ) { upslogx( LOG_WARNING, "shutdown delay of >250 seconds requested, shortening to 250 seconds" ); shutdown_delay = 250; } if ( shutdown_delay == 0 ) { upslogx( LOG_WARNING, "shutdown delay of 0 seconds requested, using 1 second instead" ); shutdown_delay = 1; } I2C_WRITE_BYTE( upsfd, cmd, shutdown_delay, __func__ ) } static void get_time(void) { uint8_t cmd = RTC_TIME_CMD; __u8 block[I2C_SMBUS_BLOCK_MAX]; uint8_t second, minute, hour, day, month, subsecond; uint16_t year; upsdebugx( 3, __func__ ); I2C_READ_BLOCK( upsfd, cmd, 9, block, __func__ ) second = (( (block[0] >> 4 ) & 0x07) * 10 ) + ( block[0] & 0x0F ); minute = (( (block[1] >> 4 ) & 0x07) * 10 ) + ( block[1] & 0x0F ); hour = (( (block[2] >> 4 ) & 0x03) * 10 ) + ( block[2] & 0x0F ); day = (( (block[4] >> 4 ) & 0x03) * 10 ) + ( block[4] & 0x0F ); month = (( (block[5] >> 4 ) & 0x01) * 10 ) + ( block[5] & 0x0F ); year = (( (block[6] >> 4 ) & 0x0F) * 10 ) + ( block[6] & 0x0F ) + 2000; subsecond = block[7] * 100 / 256; upsdebugx( 1, "UPS Time: %02d:%02d:%02d.%02d", hour, minute, second, subsecond ); dstate_setinfo( "ups.time", "%02d:%02d:%02d.%02d", hour, minute, second, subsecond ); upsdebugx( 1, "UPS Date: %04d-%02d-%02d", year, month, day ); dstate_setinfo( "ups.date", "%04d-%02d-%02d", year, month, day ); } static void get_i2c_address(void) { uint8_t cmd = I2C_ADDRESS_CMD; uint8_t data; upsdebugx( 3, __func__ ); I2C_READ_BYTE( upsfd, cmd, __func__ ) upsdebugx( 1, "I2C Address: 0x%0x", data ); if ( data == i2c_address ) { upsdebugx( 1, "Found device '0x%0x' on port '%s'", (unsigned int) i2c_address, device_path ); } else { fatalx( EXIT_FAILURE, "Could not find PiJuice HAT at I2C address 0x%0x", i2c_address ); } } void upsdrv_initinfo(void) { dstate_setinfo( "ups.mfr", "%s", "PiJuice" ); dstate_setinfo( "ups.type", "%s", "HAT" ); /* note: for a transition period, these data are redundant */ dstate_setinfo( "device.mfr", "%s", "PiJuice" ); dstate_setinfo( "device.type", "%s", "HAT" ); upsdebugx( 1, "Low Battery Threshold: %0.0f%%", LOW_BATTERY_THRESHOLD ); dstate_setinfo( "battery.charge.low", "%0.0f", LOW_BATTERY_THRESHOLD ); upsdebugx( 1, "Nominal Battery Voltage: %0.3fV", NOMINAL_BATTERY_VOLTAGE ); dstate_setinfo( "battery.voltage.nominal", "%0.3f", NOMINAL_BATTERY_VOLTAGE ); get_i2c_address(); get_battery_profile(); get_battery_profile_ext(); /* commands ----------------------------------------------- */ /* FIXME: Check with the device what our instcmd * (nee upsdrv_shutdown() contents) actually does! */ dstate_addcmd("shutdown.stayoff"); /* install handlers */ upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { status_init(); get_status(); get_battery_temperature(); get_battery_voltage(); get_battery_current(); get_io_voltage(); get_io_current(); get_time(); get_power_off(); status_commit(); dstate_dataok(); } /* handler for commands to be sent to UPS */ static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); /* FIXME: Which one is this - "load.off", * "shutdown.stayoff" or "shutdown.return"? */ /* Shutdown UPS */ if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); set_power_off(); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* FIXME: Check with the device what our instcmd * (nee upsdrv_shutdown() contents) actually does! */ int ret = do_loop_shutdown_commands("shutdown.stayoff", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } void upsdrv_help(void) { printf("\nThe default I2C address is 20 [0x14]\n"); printf("\n"); } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "i2c_address", "Override i2c address setting"); } void upsdrv_initups(void) { upsfd = open_i2c_bus( device_path, i2c_address ); /* probe ups type */ get_firmware_version(); /* get variables and flags from the command line */ if (getval("i2c_address")) i2c_address = atoi(getval("i2c_address")); } void upsdrv_cleanup(void) { close(upsfd); } nut-2.8.4/drivers/raritan-pdu-mib.c0000644000175000017500000001567015000601404014070 00000000000000/* raritan-mib.c - data to monitor Raritan PDUs (Basic and Complex) * * Copyright (C) 2008-2019 * Arnaud Quette * * Sponsored by Eaton * and MGE Office Protection Systems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "raritan-pdu-mib.h" #define RARITAN_MIB_VERSION "0.80" /* Raritan MIB * this one uses the same MIB as Eaton Revelation, * but with a different entry point */ #define RARITAN_BASE_OID ".1.3.6.1.4.1.13742" #define RARITAN_SYSOID RARITAN_BASE_OID #define RARITAN_OID_MODEL_NAME ".1.3.6.1.4.1.13742.1.1.12.0" #define DO_OFF "0" #define DO_ON "1" #define DO_CYCLE "2" static info_lkp_t raritan_pdu_outlet_status_info[] = { info_lkp_default(-1, "error"), info_lkp_default(0, "off"), info_lkp_default(1, "on"), info_lkp_default(2, "cycling"), /* transitional status */ info_lkp_sentinel }; /* Snmp2NUT lookup table for Raritan MIB */ static snmp_info_t raritan_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Raritan", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.1.12.0", "Generic SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.1.2.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.macaddr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.1.6.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* UPS page */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Raritan", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.1.12.0", "Generic SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.id", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.1.13.0", "unknown", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.1.2.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.1.1.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.temperature", 0, 1, ".1.3.6.1.4.1.13742.1.3.1.5.0", NULL, 0, NULL), /* Outlet page */ snmp_info_default("outlet.id", 0, 1, NULL, "0", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, NULL, "All outlets", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.count", 0, 1, ".1.3.6.1.4.1.13742.1.2.1.0", "0", 0, NULL), snmp_info_default("outlet.current", 0, 0.001, ".1.3.6.1.4.1.13742.1.3.1.1" ".0", NULL, 0, NULL), snmp_info_default("outlet.voltage", 0, 0.001, ".1.3.6.1.4.1.13742.1.3.1.2" ".0", NULL, 0, NULL), snmp_info_default("outlet.realpower", 0, 1.0, ".1.3.6.1.4.1.13742.1.3.1.3" ".0", NULL, 0, NULL), snmp_info_default("outlet.power", 0, 1.0, ".1.3.6.1.4.1.13742.1.3.1.4" ".0", NULL, 0, NULL), /* outlet template definition * Caution: the index of the data start at 0, while the name is +1 * ie outlet.1 => .0 */ snmp_info_default("outlet.%i.switchable", 0, 1, ".1.3.6.1.4.1.13742.1.2.2.1.1.%i", "yes", SU_FLAG_STATIC | SU_OUTLET, NULL), snmp_info_default("outlet.%i.id", 0, 1, NULL, "%i", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK | SU_OUTLET, NULL), snmp_info_default("outlet.%i.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.2.2.1.2.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.13742.1.2.2.1.3.%i", NULL, SU_FLAG_OK | SU_OUTLET, &raritan_pdu_outlet_status_info[0]), snmp_info_default("outlet.%i.current", 0, 0.001, ".1.3.6.1.4.1.13742.1.2.2.1.4.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.current.maximum", 0, 0.001, ".1.3.6.1.4.1.13742.1.2.2.1.5.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.realpower", 0, 1.0, ".1.3.6.1.4.1.13742.1.2.2.1.7.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.voltage", 0, 1.0, ".1.3.6.1.4.1.13742.1.2.2.1.6.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.powerfactor", 0, 0.01, ".1.3.6.1.4.1.13742.1.2.2.1.9.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.power", 0, 1.0, ".1.3.6.1.4.1.13742.1.2.2.1.8.%i", NULL, SU_OUTLET, NULL), /* FIXME: * - delay for startup/shutdown sequence * - support for Ambient page temperatureSensorCount" src="snmp:$sysoid.2.1.0 ambient.temperature src="snmp:$sysoid.2.2.1.3.$indiceSensor => seems dumb! ambient.humidity src="snmp:$sysoid.2.4.1.3.$indiceSensor */ /* instant commands. */ /* Note that load.cycle might be replaced by / mapped on shutdown.reboot */ /* no counterpart found! snmp_info_default("outlet.load.off", 0, 1, ".1.3.6.1.4.1.13742.1.2.2.1.3.0", DO_OFF, SU_TYPE_CMD, NULL), snmp_info_default("outlet.load.on", 0, 1, ".1.3.6.1.4.1.13742.1.2.2.1.3.0", DO_ON, SU_TYPE_CMD, NULL), snmp_info_default("outlet.load.cycle", 0, 1, ".1.3.6.1.4.1.13742.1.2.2.1.3.0", DO_CYCLE, SU_TYPE_CMD, NULL), */ snmp_info_default("outlet.%i.load.off", 0, 1, ".1.3.6.1.4.1.13742.1.2.2.1.3.%i", DO_OFF, SU_TYPE_CMD | SU_OUTLET, NULL), snmp_info_default("outlet.%i.load.on", 0, 1, ".1.3.6.1.4.1.13742.1.2.2.1.3.%i", DO_ON, SU_TYPE_CMD | SU_OUTLET, NULL), snmp_info_default("outlet.%i.load.cycle", 0, 1, ".1.3.6.1.4.1.13742.1.2.2.1.3.%i", DO_CYCLE, SU_TYPE_CMD | SU_OUTLET, NULL), /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t raritan = { "raritan", RARITAN_MIB_VERSION, NULL, RARITAN_OID_MODEL_NAME, raritan_mib, RARITAN_SYSOID, NULL }; nut-2.8.4/drivers/eaton-ups-pwnm2-mib.h0000644000175000017500000000025614777753336014655 00000000000000#ifndef EATON_UPS_PWNM2_MIB_H #define EATON_UPS_PWNM2_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t eaton_pw_nm2; #endif /* EATON_UPS_PWNM2_MIB_H */ nut-2.8.4/drivers/upsdrvquery.c0000644000175000017500000005335315044656702013531 00000000000000/* upsdrvquery.c - a single query shot over a driver socket, tracked until a response arrives, returning that line and closing a connection Copyright (C) 2023-2025 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be the first header */ #include #include #include #include #include #include #ifndef WIN32 #include #include #include #else /* WIN32 */ #include "wincompat.h" #endif /* WIN32 */ #include "common.h" #include "upsdrvquery.h" #include "nut_stdint.h" /* Normally the upsdrvquery*() methods call upslogx() to report issues * such as failed fopen() of Unix socket file, or a dialog timeout or * different error. * In a few cases we call these methods opportunistically, and so if * they fail - we do not care enough to raise a lot of "scary noise"; * the caller can take care of logging as/if needed. * This variable and its values are a bit of internal detail between * certain NUT programs to hush the low-level reports when they are * not being otherwise debugged (e.g. nut_debug_level < 1). * Default value allows all those messages to appear. */ int nut_upsdrvquery_debug_level = NUT_UPSDRVQUERY_DEBUG_LEVEL_DEFAULT; udq_pipe_conn_t *upsdrvquery_connect(const char *sockfn) { udq_pipe_conn_t *conn = (udq_pipe_conn_t*)xcalloc(1, sizeof(udq_pipe_conn_t)); /* Code borrowed from our numerous sock_connect() implems */ #ifndef WIN32 struct sockaddr_un sa; ssize_t ret; memset(&sa, '\0', sizeof(sa)); sa.sun_family = AF_UNIX; snprintf(sa.sun_path, sizeof(sa.sun_path), "%s", sockfn); conn->sockfd = socket(AF_UNIX, SOCK_STREAM, 0); if (conn->sockfd < 0) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "open socket"); free(conn); return NULL; } if (connect(conn->sockfd, (struct sockaddr *) &sa, sizeof(sa)) < 0) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "connect to driver socket at %s", sockfn); close(conn->sockfd); free(conn); return NULL; } ret = fcntl(conn->sockfd, F_GETFL, 0); if (ret < 0) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "fcntl get on driver socket %s failed", sockfn); close(conn->sockfd); free(conn); return NULL; } if (fcntl(conn->sockfd, F_SETFL, ret | O_NDELAY) < 0) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "fcntl set O_NDELAY on driver socket %s failed", sockfn); close(conn->sockfd); free(conn); return NULL; } #else /* WIN32 */ BOOL result = WaitNamedPipe(sockfn, NMPWAIT_USE_DEFAULT_WAIT); if (result == FALSE) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "WaitNamedPipe : %d\n", GetLastError()); return NULL; } conn->sockfd = CreateFile( sockfn, /* pipe name */ GENERIC_READ | /* read and write access */ GENERIC_WRITE, 0, /* no sharing */ NULL, /* default security attributes FIXME */ OPEN_EXISTING, /* opens existing pipe */ FILE_FLAG_OVERLAPPED, /* enable async IO */ NULL); /* no template file */ if (conn->sockfd == INVALID_HANDLE_VALUE) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "CreateFile : %d\n", GetLastError()); free(conn); return NULL; } memset(&(conn->overlapped), 0, sizeof(conn->overlapped)); conn->overlapped.hEvent = CreateEvent( NULL, /* Security */ FALSE, /* auto-reset */ FALSE, /* initial state = non signaled */ NULL /* no name */ ); if (conn->overlapped.hEvent == NULL) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslogx(LOG_ERR, "Can't create event for reading event log"); free(conn); return NULL; } memset(conn->buf, 0, sizeof(conn->buf)); /* Start a read IO so we could wait on the event associated with it * Requires the persistent buffer for the connection */ upsdebugx(6, "%s: Queue initial async read", __func__); ReadFile(conn->sockfd, conn->buf, sizeof(conn->buf) - 1, /* -1 to be sure to have a trailing 0 */ NULL, &conn->overlapped); conn->newread = 0; #endif /* WIN32 */ /* Just for fun: stash the name */ if (snprintf(conn->sockfn, sizeof(conn->sockfn), "%s", sockfn) < 0) conn->sockfn[0] = '\0'; return conn; } udq_pipe_conn_t *upsdrvquery_connect_drvname_upsname(const char *drvname, const char *upsname) { char sockname[NUT_PATH_MAX + 1]; #ifndef WIN32 struct stat fs; snprintf(sockname, sizeof(sockname), "%s/%s-%s", dflt_statepath(), drvname, upsname); check_unix_socket_filename(sockname); if (stat(sockname, &fs)) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "Can't open %s", sockname); return NULL; } #else /* WIN32 */ snprintf(sockname, sizeof(sockname), "\\\\.\\pipe\\%s-%s", drvname, upsname); #endif /* WIN32 */ return upsdrvquery_connect(sockname); } void upsdrvquery_close(udq_pipe_conn_t *conn) { #ifdef WIN32 int loggedOut = 0; #endif /* WIN32 */ if (!conn) return; if (VALID_FD(conn->sockfd)) { int nudl = nut_upsdrvquery_debug_level; ssize_t ret; upsdebugx(5, "%s: closing driver socket, try to say goodbye", __func__); ret = upsdrvquery_write(conn, "LOGOUT\n"); if (7 <= ret) { upsdebugx(5, "%s: okay", __func__); #ifdef WIN32 loggedOut = 1; #endif /* WIN32 */ usleep(1000000); } else { upsdebugx(5, "%s: must have been closed on the other side", __func__); } nut_upsdrvquery_debug_level = nudl; } #ifndef WIN32 if (VALID_FD(conn->sockfd)) close(conn->sockfd); #else /* WIN32 */ if (VALID_FD(conn->overlapped.hEvent)) { CloseHandle(conn->overlapped.hEvent); } memset(&(conn->overlapped), 0, sizeof(conn->overlapped)); if (VALID_FD(conn->sockfd)) { if (DisconnectNamedPipe(conn->sockfd) == 0 && !loggedOut) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslogx(LOG_ERR, "DisconnectNamedPipe error : %d", (int)GetLastError()); } CloseHandle(conn->sockfd); } conn->newread = 0; #endif /* WIN32 */ conn->sockfd = ERROR_FD; memset(conn->buf, 0, sizeof(conn->buf)); memset(conn->sockfn, 0, sizeof(conn->sockfn)); /* caller should free the conn */ } ssize_t upsdrvquery_read_timeout(udq_pipe_conn_t *conn, struct timeval tv) { ssize_t ret; #ifndef WIN32 fd_set rfds; #else /* WIN32 */ DWORD bytesRead = 0; BOOL res = FALSE; struct timeval start, now, presleep; #endif /* WIN32 */ upsdebugx(5, "%s: tv={sec=%" PRIiMAX ", usec=%06" PRIiMAX "}%s", __func__, (intmax_t)tv.tv_sec, (intmax_t)tv.tv_usec, tv.tv_sec < 0 || tv.tv_usec < 0 ? " (unlimited timeout)" : "" ); if (!conn || INVALID_FD(conn->sockfd)) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "socket not initialized"); return -1; } #ifndef WIN32 FD_ZERO(&rfds); FD_SET(conn->sockfd, &rfds); if (select(conn->sockfd + 1, &rfds, NULL, NULL, tv.tv_sec < 0 || tv.tv_usec < 0 ? NULL : &tv) < 0) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_DIALOG) upslog_with_errno(LOG_ERR, "select with socket"); /* upsdrvquery_close(conn); */ return -1; } if (!FD_ISSET(conn->sockfd, &rfds)) { upsdebugx(5, "%s: received nothing from driver socket", __func__); return -2; /* timed out, no info */ } memset(conn->buf, 0, sizeof(conn->buf)); ret = read(conn->sockfd, conn->buf, sizeof(conn->buf)); #else /* WIN32 */ /* if (nut_debug_level > 0 || nut_upsdrvquery_debug_level > 0) upslog_with_errno(LOG_ERR, "Support for this platform is not currently implemented"); return -1; */ /* Is GetLastError() required to move on if pipe has more data? * if (GetLastError() == ERROR_IO_PENDING) { */ if (conn->newread) { upsdebugx(6, "%s: Restart async read", __func__); memset(conn->buf, 0, sizeof(conn->buf)); ReadFile(conn->sockfd, conn->buf, sizeof(conn->buf) - 1, NULL, &(conn->overlapped)); conn->newread = 0; } gettimeofday(&start, NULL); while (res == FALSE /*&& bytesRead == 0*/) { res = GetOverlappedResult(conn->sockfd, &conn->overlapped, &bytesRead, FALSE); if (res != FALSE /*|| bytesRead != 0*/) break; if (tv.tv_sec < 1 && tv.tv_usec < 1) { upsdebugx(5, "%s: pipe read error (no incoming data), proceeding now", __func__); break; } upsdebugx(6, "%s: pipe read error, still waiting for data", __func__); /* Throttle down a bit, 0.1 sec (10^5 * 10^-6) should do it conveniently */ gettimeofday(&presleep, NULL); usleep(100000); /* obsoleted in win32, so follow up below */ gettimeofday(&now, NULL); /* NOTE: This code may report a "diff=1.-894714 (0.105286)" * which looks bogus, but for troubleshooting we don't care */ upsdebugx(7, "%s: presleep=%ld.%06ld now=%ld.%06ld diff=%4.0f.%06ld (%f)", __func__, presleep.tv_sec, presleep.tv_usec, now.tv_sec, now.tv_usec, difftime(now.tv_sec, presleep.tv_sec), (long)(now.tv_usec - presleep.tv_usec), difftimeval(now, presleep) ); /* accept shorter delays, Windows does not guarantee a minimum sleep it seems */ if (difftimeval(now, presleep) < 0.05) { /* https://stackoverflow.com/a/17283549 */ HANDLE timer; LARGE_INTEGER ft; /* SetWaitableTimer() uses 100 nanosecond intervals, * and a negative value indicates relative time: */ ft.QuadPart = -(10*100000); /* 100 msec */ timer = CreateWaitableTimer(NULL, TRUE, NULL); SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); WaitForSingleObject(timer, INFINITE); CloseHandle(timer); gettimeofday(&now, NULL); upsdebugx(7, "%s: presleep=%ld.%06ld now=%ld.%06ld diff=%4.0f.%06ld (%f)", __func__, presleep.tv_sec, presleep.tv_usec, now.tv_sec, now.tv_usec, difftime(now.tv_sec, presleep.tv_sec), (long)(now.tv_usec - presleep.tv_usec), difftimeval(now, presleep) ); } /* If nothing was honored, doze off for a whole second */ if (difftimeval(now, presleep) < 0.05) { sleep(1); gettimeofday(&now, NULL); upsdebugx(7, "%s: presleep=%ld.%06ld now=%ld.%06ld diff=%4.0f.%06ld (%f)", __func__, presleep.tv_sec, presleep.tv_usec, now.tv_sec, now.tv_usec, difftime(now.tv_sec, presleep.tv_sec), (long)(now.tv_usec - presleep.tv_usec), difftimeval(now, presleep) ); } if (difftimeval(now, start) > (tv.tv_sec + 0.000001 * tv.tv_usec)) { upsdebugx(5, "%s: pipe read error, timeout exceeded", __func__); break; } } if (res != FALSE) ret = (ssize_t)bytesRead; else ret = -1; #endif /* WIN32 */ if (ret > 0) { size_t len = (size_t)ret > sizeof(conn->buf) ? sizeof(conn->buf) : (size_t)ret; upsdebugx(5, "%s: received %" PRIiMAX " bytes from driver socket: %.*s", __func__, (intmax_t)ret, (int)len, conn->buf); if (conn->buf[0] == '\0') { upsdebug_hex(5, "payload starts with zero byte: ", conn->buf, len); } } else { upsdebugx(6, "%s: received %" PRIiMAX " bytes from driver socket: ", __func__, (intmax_t)ret); } return ret; } ssize_t upsdrvquery_write(udq_pipe_conn_t *conn, const char *buf) { size_t buflen = strlen(buf); #ifndef WIN32 ssize_t ret; #else /* WIN32 */ DWORD bytesWritten = 0; BOOL result = FALSE; #endif /* WIN32 */ upsdebugx(5, "%s: write to driver socket: %s", __func__, buf); if (!conn || INVALID_FD(conn->sockfd)) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT) upslog_with_errno(LOG_ERR, "socket not initialized"); return -1; } #ifndef WIN32 ret = write(conn->sockfd, buf, buflen); if (ret < 0 || ret != (int)buflen) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_DIALOG) upslog_with_errno(LOG_ERR, "Write to socket %d failed", conn->sockfd); goto socket_error; } return ret; #else /* WIN32 */ result = WriteFile(conn->sockfd, buf, buflen, &bytesWritten, NULL); if (result == 0 || bytesWritten != (DWORD)buflen) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_DIALOG) upslog_with_errno(LOG_ERR, "Write to handle %p failed", conn->sockfd); goto socket_error; } return (ssize_t)bytesWritten; #endif /* WIN32 */ socket_error: /*upsdrvquery_close(conn);*/ return -1; } ssize_t upsdrvquery_prepare(udq_pipe_conn_t *conn, struct timeval tv) { struct timeval start, now; if (!conn || INVALID_FD(conn->sockfd)) return -1; /* Avoid noise */ if (upsdrvquery_write(conn, "NOBROADCAST\n") < 0) goto socket_error; if (tv.tv_sec < 1 && tv.tv_usec < 1) { upsdebugx(5, "%s: proclaiming readiness for tracked commands without flush of server messages", __func__); return 1; } /* flush incoming, if any */ gettimeofday(&start, NULL); if (upsdrvquery_write(conn, "PING\n") < 0) goto socket_error; upsdebugx(5, "%s: waiting for a while to flush server messages", __func__); while (1) { char *buf; upsdrvquery_read_timeout(conn, tv); gettimeofday(&now, NULL); if (difftimeval(now, start) > ((double)(tv.tv_sec) + 0.000001 * (double)(tv.tv_usec))) { upsdebugx(5, "%s: requested timeout expired", __func__); break; } /* Await a PONG for quick confirmation of achieved quietness * (should only happen after the driver handled NOBROADCAST) */ #ifdef WIN32 /* Allow a new read to happen later */ conn->newread = 1; #endif /* WIN32 */ buf = conn->buf; while (buf && *buf) { if (!strncmp(buf, "PONG\n", 5)) { upsdebugx(5, "%s: got expected PONG", __func__); goto finish; } buf = strchr(buf, '\n'); if (buf) { /* upsdebugx(5, "%s: trying next line of multi-line response: %s", __func__, buf); */ buf++; /* skip EOL char */ } } /* Diminishing timeouts for read() */ tv.tv_usec -= (suseconds_t)(difftimeval(now, start)); while (tv.tv_usec < 0) { tv.tv_sec--; tv.tv_usec = 1000000 + tv.tv_usec; /* Note it is negative */ } if (tv.tv_sec <= 0 && tv.tv_usec <= 0) { upsdebugx(5, "%s: requested timeout expired", __func__); break; } } /* Check that we can have a civilized dialog -- * nope, this one is for network protocol * * FIXME: strcmp(conn->buf, "ON") -> buf is NOT null terminated! * The above FIXME is not the reason this block is/was commented out. */ /* if (upsdrvquery_write(conn, "GET TRACKING\n") < 0) goto socket_error; if (upsdrvquery_read_timeout(conn, tv) < 1) goto socket_error; if (strcmp(conn->buf, "ON")) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_DIALOG) upslog_with_errno(LOG_ERR, "Driver does not have TRACKING support enabled"); goto socket_error; } */ finish: upsdebugx(5, "%s: ready for tracked commands", __func__); return 1; socket_error: /* upsdrvquery_close(conn); */ return -1; } ssize_t upsdrvquery_restore_broadcast(udq_pipe_conn_t *conn) { if (!conn || INVALID_FD(conn->sockfd)) return -1; if (upsdrvquery_write(conn, "BROADCAST 1\n") < 0) { if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_DIALOG) { upslog_with_errno(LOG_ERR, "%s: could not restore broadcast, write to socket [%d] failed", __func__, conn->sockfd); } return -1; } upsdebugx(5, "%s: restored broadcast for connection on socket [%d]", __func__, conn->sockfd); return 1; } /* UUID v4 basic implementation * Note: 'dest' must be at least `UUID4_LEN` long */ #define UUID4_BYTESIZE 16 static int upsdrvquery_nut_uuid_v4(char *uuid_str) { size_t i; uint8_t nut_uuid[UUID4_BYTESIZE]; if (!uuid_str) return 0; for (i = 0; i < UUID4_BYTESIZE; i++) nut_uuid[i] = (uint8_t)rand() + (uint8_t)rand(); /* set variant and version */ nut_uuid[6] = (nut_uuid[6] & 0x0F) | 0x40; nut_uuid[8] = (nut_uuid[8] & 0x3F) | 0x80; return snprintf(uuid_str, UUID4_LEN, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", nut_uuid[0], nut_uuid[1], nut_uuid[2], nut_uuid[3], nut_uuid[4], nut_uuid[5], nut_uuid[6], nut_uuid[7], nut_uuid[8], nut_uuid[9], nut_uuid[10], nut_uuid[11], nut_uuid[12], nut_uuid[13], nut_uuid[14], nut_uuid[15]); } ssize_t upsdrvquery_request( udq_pipe_conn_t *conn, struct timeval tv, const char *query ) { /* Assume TRACKING works; post a socket-protocol * query to driver and return whatever it says */ char qbuf[LARGEBUF]; size_t qlen; char tracking_id[UUID4_LEN]; struct timeval start, now; if (!conn || INVALID_FD(conn->sockfd)) return -1; if (snprintf(qbuf, sizeof(qbuf), "%s", query) < 0) goto socket_error; qlen = strlen(qbuf); while (qlen > 0 && qbuf[qlen - 1] == '\n') { qbuf[qlen - 1] = '\0'; qlen--; } upsdrvquery_nut_uuid_v4(tracking_id); if (snprintf(qbuf + qlen, sizeof(qbuf) - qlen, " TRACKING %s\n", tracking_id) < 0) goto socket_error; /* Post the query and wait for reply */ if (upsdrvquery_write(conn, qbuf) < 0) goto socket_error; if (tv.tv_sec < 1 && tv.tv_usec < 1) { upsdebugx(1, "%s: will wait indefinitely for response to %s", __func__, query); } else { while (tv.tv_usec >= 1000000) { tv.tv_usec -= 1000000; tv.tv_sec++; } upsdebugx(5, "%s: will wait up to %" PRIiMAX ".%06" PRIiMAX " sec for response to %s", __func__, (intmax_t)tv.tv_sec, (intmax_t)tv.tv_usec, query); } gettimeofday(&start, NULL); while (1) { char *buf; if (upsdrvquery_read_timeout(conn, tv) < 1) goto socket_error; #ifdef WIN32 /* Allow a new read to happen later */ conn->newread = 1; #endif /* WIN32 */ buf = conn->buf; while (buf && *buf) { if (!strncmp(buf, "TRACKING ", 9) && !strncmp(buf + 9, tracking_id, UUID4_LEN - 1) ) { int ret; size_t offset = 9 + UUID4_LEN; if (sscanf(buf + offset, " %d", &ret) < 1) { upsdebugx(5, "%s: sscanf failed at offset %" PRIuSIZE " (char '%c')", __func__, offset, buf[offset]); goto socket_error; } upsdebugx(5, "%s: parsed out command status: %d", __func__, ret); return ret; } else { upsdebugx(5, "%s: response did not have expected format", __func__); /* Maybe a rogue send-to-all? */ } buf = strchr(buf, '\n'); if (buf) { upsdebugx(5, "%s: trying next line of multi-line response: %s", __func__, buf); buf++; /* skip EOL char */ } } gettimeofday(&now, NULL); if (tv.tv_sec < 1 && tv.tv_usec < 1) { if ( ((long)(difftimeval(now, start))) % 60 == 0 ) upsdebugx(5, "%s: waiting indefinitely for response to %s", __func__, query); sleep(1); continue; } if (difftimeval(now, start) > ((double)(tv.tv_sec) + 0.000001 * (double)(tv.tv_usec))) { upsdebugx(5, "%s: timed out waiting for expected response", __func__); return -1; } } socket_error: /* upsdrvquery_close(conn); */ return -1; } ssize_t upsdrvquery_oneshot( const char *drvname, const char *upsname, const char *query, char *buf, const size_t bufsz, struct timeval *ptv ) { udq_pipe_conn_t *conn = upsdrvquery_connect_drvname_upsname(drvname, upsname); ssize_t ret; if (!conn || INVALID_FD(conn->sockfd)) return -1; ret = upsdrvquery_oneshot_conn(conn, query, buf, bufsz, ptv); upsdrvquery_close(conn); free(conn); return ret; } ssize_t upsdrvquery_oneshot_sockfn( const char *sockfn, const char *query, char *buf, const size_t bufsz, struct timeval *ptv ) { udq_pipe_conn_t *conn = upsdrvquery_connect(sockfn); ssize_t ret; if (!conn || INVALID_FD(conn->sockfd)) return -1; ret = upsdrvquery_oneshot_conn(conn, query, buf, bufsz, ptv); upsdrvquery_close(conn); free(conn); return ret; } /* One-shot using an existing connection (caller must close + free connection) */ ssize_t upsdrvquery_oneshot_conn( udq_pipe_conn_t *conn, const char *query, char *buf, const size_t bufsz, struct timeval *ptv ) { struct timeval tv; ssize_t ret; if (!conn || INVALID_FD(conn->sockfd)) return -1; /* This depends on driver looping delay, polling frequency, * being blocked on other commands, etc. Number so far is * arbitrary and optimistic. A non-zero setting causes a * long initial silence to flush incoming buffers after * the NOBROADCAST. In practice, we do not expect messages * from dstate::send_to_all() to be a nuisance, since we * have just connected and posted the NOBROADCAST so there * is little chance that something appears in that short * time. Also now we know to ignore replies that are not * TRACKING */ tv.tv_sec = 3; tv.tv_usec = 0; /* Here we have a fragile simplistic parser that * expects one line replies to a specific command, * so want to rule out the noise. */ if (upsdrvquery_prepare(conn, tv) < 0) { ret = -1; goto finish; } if (ptv) { tv.tv_sec = ptv->tv_sec; tv.tv_usec = ptv->tv_usec; } else { tv.tv_sec = 5; tv.tv_usec = 0; } if ((ret = upsdrvquery_request(conn, tv, query)) < 0) { ret = -1; goto finish; } if (buf) { size_t len = strnlen(conn->buf, sizeof(conn->buf)); snprintf(buf, bufsz, "%.*s", (int)len, conn->buf); } finish: upsdrvquery_restore_broadcast(conn); /* best effort */ return ret; } nut-2.8.4/drivers/eaton-pdu-pulizzi-mib.h0000644000175000017500000000241114670526611015256 00000000000000/* eaton-pdu-pulizzi-mib.h - subdriver to monitor Eaton ePDU SNMP devices with NUT * * Copyright (C) * 2010 Arjen de Korte * 2011 - 2012 Arnaud Quette * 2017 Arnaud Quette * 2017 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef EATON_EPDU_PULIZZI_MIB_H #define EATON_EPDU_PULIZZI_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t pulizzi_switched1; extern mib2nut_info_t pulizzi_switched2; #endif /* EATON_EPDU_PULIZZI_MIB_H */ nut-2.8.4/drivers/bestpower-mib.c0000644000175000017500000000721515000601404013650 00000000000000/* bestpower-mib.c - data to monitor Eaton Best Power Ferrups * using earlier version of the ConnectUPS * * Copyright (C) 2010 - Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "bestpower-mib.h" #define BESTPOWER_MIB_VERSION "0.40" #define BESTPOWER_OID_MODEL_NAME ".1.3.6.1.4.1.2947.1.1.2.0" /* * http://powerquality.eaton.com/Support/Software-Drivers/Downloads/connectivity-firmware/bestpwr2.mib */ /* TODO: find the right sysOID for this MIB * #define BESTPOWER_SYSOID ".1.3.6.1.4.1.2947???" */ #define BESTPOWER_SYSOID BESTPOWER_OID_MODEL_NAME static info_lkp_t bestpower_power_status[] = { info_lkp_default(1, "OL"), info_lkp_default(2, "OB"), info_lkp_sentinel }; /* Snmp2NUT lookup table for Best Power MIB */ static snmp_info_t bestpower_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "ups", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "EATON", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /*.1.3.6.1.4.1.2947.1.1.1.0 = STRING: "Ferrups" .1.3.6.1.4.1.2947.1.1.2.0 = STRING: "FE850VA"*/ snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, BESTPOWER_OID_MODEL_NAME, "Best Ferrups", SU_FLAG_STATIC, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2947.1.1.5.0", "", SU_FLAG_STATIC, NULL), snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2947.1.1.7.0", "", SU_FLAG_STATIC, NULL), snmp_info_default("ups.power", 0, 1, ".1.3.6.1.4.1.2947.1.1.3.0", "", 0, NULL), snmp_info_default("ups.mfr.date", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2947.1.1.8.0", "", 0, NULL), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2947.1.2.1.0", "", 0 /*SU_STATUS_PWR*/, &bestpower_power_status[0]), /* Battery runtime is expressed in minutes */ snmp_info_default("battery.runtime", 0, 60.0, ".1.3.6.1.4.1.2947.1.2.3.0", "", 0, NULL), /* The elapsed time in seconds since the * UPS has switched to battery power */ snmp_info_default("battery.runtime.elapsed", 0, 1.0, ".1.3.6.1.4.1.2947.1.2.2.0", "", 0, NULL), snmp_info_default("battery.voltage", 0, 0.1, ".1.3.6.1.4.1.2947.1.2.4.0", "", 0, NULL), snmp_info_default("battery.current", 0, 0.1, ".1.3.6.1.4.1.2947.1.2.5.0", "", 0, NULL), /* end of structure. */ snmp_info_sentinel } ; mib2nut_info_t bestpower = { "bestpower", BESTPOWER_MIB_VERSION, NULL, BESTPOWER_OID_MODEL_NAME, bestpower_mib, BESTPOWER_SYSOID, NULL }; nut-2.8.4/drivers/blazer.h0000644000175000017500000000365614777753336012422 00000000000000/* * blazer.h: defines/macros for Megatec/Q1 protocol based UPSes * * OBSOLETION WARNING: Please to not base new development on this * codebase, instead create a new subdriver for nutdrv_qx which * generally covers all Megatec/Qx protocol family and aggregates * device support from such legacy drivers over time. * * A document describing the protocol implemented by this driver can be * found online at "https://www.networkupstools.org/protocols/megatec.html". * * Copyright (C) 2008 - Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef BLAZER_H #define BLAZER_H #define MAXTRIES 3 /* * The driver core will do all the protocol handling and provides * the following (interface independent) parts already * * upsdrv_updateinfo() * upsdrv_shutdown() * * Communication with the UPS is done through blazer_command() of which * the prototype is declared below. It shall send a command and reads * a reply if buf is not a NULL pointer and buflen > 0. * * Returns < 0 on error, 0 on timeout and the number of bytes send/read on * success. */ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen); void blazer_makevartable(void); void blazer_initups(void); void blazer_initinfo(void); #endif /* BLAZER_H */ nut-2.8.4/drivers/mge-utalk.h0000664000175000017500000002220615000733176012777 00000000000000/* mge-utalk.h - monitor MGE UPS for NUT with UTalk protocol * * Copyright (C) 2002 - 2005 * Arnaud Quette & * Hans Ekkehard Plesser * Martin Loyer * Patrick Agrain * Nicholas Reilly * Dave Abbott * Marek Kralewski * * This driver is a collaborative effort by the above people, * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUT_MGE_UTALK_H_SEEN #define NUT_MGE_UTALK_H_SEEN 1 /* --------------------------------------------------------------- */ /* Default Values for UPS Variables */ /* --------------------------------------------------------------- */ #define DEFAULT_LOWBATT 30 /* low battery level, in % */ /* delay between return of utility power and powering up of load (in MINUTES) */ #define DEFAULT_ONDELAY 1 #define DEFAULT_OFFDELAY 20 /* delay before power off, in SECONDS */ #define MIN_CONFIRM_TIME 3 /* shutdown must be confirmed in */ #define MAX_CONFIRM_TIME 15 /* this interval */ /* --------------------------------------------------------------- */ /* Model Name formating entries */ /* --------------------------------------------------------------- */ typedef struct { const char *basename; /* as returned by Si 1 */ const char *finalname; } models_name_t; static models_name_t Si1_models_names [] = { /* Pulsar EX */ { "Pulsar EX7", "Pulsar EX 7" }, { "Pulsar EX10", "Pulsar EX 10" }, { "Pulsar EX15", "Pulsar EX 15" }, { "Pulsar EX20", "Pulsar EX 20" }, { "Pulsar EX30", "Pulsar EX 30" }, { "Pulsar EX40", "Pulsar EX 40" }, /* Pulsar ES+ */ { "Pulsar ES2+", "Pulsar ES 2+" }, { "Pulsar ES5+", "Pulsar ES 5+" }, /* Pulsar ESV+ */ { "Pulsar ESV5+", "Pulsar ESV 5+" }, { "Pulsar ESV8+", "Pulsar ESV 8+" }, { "Pulsar ESV11+", "Pulsar ESV 11+" }, { "Pulsar ESV14+", "Pulsar ESV 14+" }, { "Pulsar ESV22+", "Pulsar ESV 22+" }, /* Pulsar EXtreme */ { "EXTREME 1500", "Pulsar EXtreme 1500" }, { "EXTREME 2000", "Pulsar EXtreme 2000" }, { "EXTREME 2500", "Pulsar EXtreme 2500" }, { "EXTREME 3000", "Pulsar EXtreme 3000" }, /* Comet EXtreme */ { "EXTREME 4.5", "Comet EXtreme 4.5" }, { "EXTREME 6", "Comet EXtreme 6" }, { "EXTREME 9", "Comet EXtreme 9" }, { "EXTREME 12", "Comet EXtreme 12" }, /* Comet */ { "COMET 5", "Comet 5" }, { "COMET 7", "Comet 7.5" }, { "COMET 10", "Comet 10" }, { "COMET 15", "Comet 15" }, { "COMET 20", "Comet 20" }, { "COMET 30", "Comet 30" }, { "COMET 12", "Comet 12" }, { "COMET 18", "Comet 18" }, { "COMET 24", "Comet 24" }, { "COMET 36", "Comet 36" }, /* FIXME: complete with Pulsar ?EL 2/4/7?, EXL, SX, PSX/CSX, Evolution?,... */ /* end of structure. */ { NULL, "Generic UTalk model" } }; /* --------------------------------------------------------------- */ /* Model Information for legacy models */ /* --------------------------------------------------------------- */ /* Structure defining how to get name and model for a particular Si output * This is for older UPS (Pulsar ESV,SV) which don't support Plug'n'Play 'Si 1' command */ typedef struct { int Data1; /* Data1, Family model */ int Data2; /* Data2, Type */ /* Data3, SoftLevel is not implemented here, while it's always null or zero.*/ const char *name; /* ASCII model name (like 'Si 1' output */ } mge_model_info_t; /* Array containing Model information for legacy models * NOTE: * - Array is terminated by element with type NULL. */ static mge_model_info_t mge_model[] = { /* Pulsar SV page */ { 3000, 5, "Pulsar SV3" }, { 3000, 6, "Pulsar SV5/8/11" }, { 3000, 7, "Pulsar SV3" }, { 3000, 8, "Pulsar SV5/8" }, { 3000, 10, "Pulsar SV11/ESV13" }, /* Pulsar ESV page */ { 3000, 11, "Pulsar ESV17" }, { 3000, 12, "Pulsar ESV20" }, { 3000, 13, "Pulsar ESV13" }, { 3000, 14, "Pulsar ESV17" }, { 3000, 15, "Pulsar ESV20" }, { 3000, 17, "Pulsar ESV8" }, /* Pulsar ESV+ compatibility (though these support Si1) */ { 3000, 51, "Pulsar ESV 11+" }, { 0, 0, NULL } }; /* --------------------------------------------------------------- */ /* Multiplier Tables */ /* --------------------------------------------------------------- */ /* First index : Table number, fetched with "Ai" command * Second index: unit, as in enum above * NOTE: * - to make the table index the same as the MGE table number, * dummy table row multiplier[0][] is inserted * - unit MIN2SEC is used to convert values in minutes sent by * the UPS (WAKEDELAY) to seconds * - the final column corresponds to unit NONE */ /* units in multiplier table */ typedef enum eunits { VOLT = 0, AMPERE, HERTZ, VOLTAMP, WATT, DEGCELS, MIN2SEC, NONE } units_t; static const double multiplier[4][8] = { /* V A Hz VA W C MIN2SEC NONE */ { 1 , 1 , 1 , 1, 1, 1, 60, 1 }, { 1 , 1 , 0.1 , 1000, 1000, 1, 60, 1 }, { 0.01, 0.01, 1 , 1, 1, 1, 60, 1 }, { 1 , 0.01, 0.1 , 1, 1, 1, 60, 1 } }; /* --------------------------------------------------------------- */ /* Explicit Booleans */ /* --------------------------------------------------------------- */ /* use explicit booleans */ #ifdef FALSE # undef FALSE #endif /* FALSE */ #ifdef TRUE # undef TRUE #endif /* TRUE */ typedef enum ebool { FALSE=0, TRUE } bool_t; /* --------------------------------------------------------------- */ /* Query Commands and their Mapping to INFO_ Variables */ /* --------------------------------------------------------------- */ /* Structure defining how to query UPS for a variable and write information to INFO structure. */ typedef struct { const char *type; /* INFO_* element */ int flags; /* INFO-element flags to set in addinfo */ int length; /* INFO-element length of strings */ const char *cmd; /* UPS command string to requets element */ const char *fmt; /* printf format string for INFO entry */ units_t unit; /* unit of measurement, or NONE */ bool_t ok; /* flag indicating if item is available */ } mge_info_item_t; /* Array containing information to translate between UTalk and NUT info * NOTE: * - Array is terminated by element with type NULL. * - Essential INFO items (_MFR, _MODEL, _FIRMWARE, _STATUS) are * handled separately. * - Array is NOT const, since "ok" can be changed. */ static mge_info_item_t mge_info[] = { /* Battery page */ { "battery.charge", 0, 0, "Bl", "%05.1f", NONE, TRUE }, { "battery.runtime", 0, 0, "Bn", "%05d", NONE, TRUE }, { "battery.voltage", 0, 0, "Bv", "%05.1f", VOLT, TRUE }, { "battery.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 2, "Bl ?", "%02d", NONE, TRUE }, { "battery.voltage.nominal", 0, 0, "Bv ?", "%05.1f", VOLT, TRUE }, /* UPS page */ { "ups.temperature", 0, 0, "St", "%05.1f", DEGCELS, TRUE }, { "ups.load", 0, 0, "Ll", "%05.1f", NONE, TRUE }, { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 5, "Sm ?", "%03d", NONE, TRUE }, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 5, "Sn ?", "%03d", NONE, TRUE }, { "ups.test.interval", ST_FLAG_RW | ST_FLAG_STRING, 5, "Bp ?", "%03d", NONE, TRUE }, /* Output page */ { "output.voltage", 0, 0, "Lv", "%05.1f", VOLT, TRUE }, { "output.current", 0, 0, "Lc", "%05.1f", AMPERE, TRUE }, /* Input page */ { "input.voltage", 0, 0, "Uv", "%05.1f", VOLT, TRUE }, { "input.frequency", 0, 0, "Uf", "%05.2f", HERTZ, TRUE }, /* same as LOBOOSTXFER */ { "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "Ee ?", "%05.1f", VOLT, TRUE }, { "input.transfer.boost.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "Ee ?", "%05.1f", VOLT, TRUE }, { "input.transfer.boost.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "Eo ?", "%05.1f", VOLT, TRUE }, { "input.transfer.trim.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "Ea ?", "%05.1f", VOLT, TRUE }, /* same as HITRIMXFER */ { "input.transfer.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "Eu ?", "%05.1f", VOLT, TRUE }, { "input.transfer.trim.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "Eu ?", "%05.1f", VOLT, TRUE }, /* terminating element */ { NULL, 0, 0, "\0", "\0", NONE, FALSE } }; #endif /* NUT_MGE_UTALK_H_SEEN */ nut-2.8.4/drivers/victronups.c0000644000175000017500000003473615044656702013340 00000000000000/* victronups.c - Model specific routines for GE/IMV/Victron units * Match, Match Lite, NetUps * * Copyright (C) 1999 Russell Kroll * Copyright (C) 2000 Radek Benedikt * old style "victronups" * Copyright (C) 2001 Daniel.Prynych * porting to now style "newvictron" * Copyright (C) 2003 Gert Lynge * Porting to new serial functions. Now removes \n from data (was causing * periodic misreadings of temperature and voltage levels) * Copyright (C) 2004 Gert Lynge * Implemented some Instant Commands. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "serial.h" #define DRIVER_NAME "GE/IMV/Victron UPS driver" #define DRIVER_VERSION "0.25" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Russell Kroll \n" \ "Radek Benedikt \n" \ "Daniel Prynych \n" \ "Gert Lynge ", DRV_STABLE, { NULL } }; #define ENDCHAR '\r' #define IGNCHARS "\n" #define UPS_DELAY 150000 #define UPS_LONG_DELAY 450000 #define VICTRON_OVER 128 #define VICTRON_RB 1 #define VICTRON_OB 2 #define VICTRON_LB 4 #define VICTRON_NO_TEST 1 #define VICTRON_ABORT_TEST 2 #define VICTRON_SYSTEM_TEST 3 #define VICTRON_BATTERY_TEST 4 #define VICTRON_CALIBRATION 5 #define VICTRON_BYPASS_TEST 101 #define LENGTH_TEMP 256 static int sdwdelay = 0; /* shutdown after 0 second */ static char *model_name; static int start_is_datastale = 1; static int exist_ups_serial = 0; static int exist_ups_temperature = 0; static int exist_output_current = 0; static int exist_battery_charge = 0; static int exist_battery_current = 0; static int exist_battery_temperature = 0; static int exist_battery_runtime = 0; static int test_in_progress = VICTRON_NO_TEST; static int get_data (const char *out_string, char *in_string) { ssize_t ret_code; ser_send(upsfd, "%s%c", out_string, ENDCHAR); usleep (UPS_DELAY); ret_code = ser_get_line(upsfd, in_string, LENGTH_TEMP, ENDCHAR, IGNCHARS, 3, 0); if (ret_code < 1) { dstate_datastale(); return -1; } return 0; } static int instcmd(const char *cmdname, const char *extra) { char temp[ LENGTH_TEMP ]; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if(!strcasecmp(cmdname, "calibrate.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if(get_data("vTi5!",temp)) { upsdebugx(1, "instcmd: ser_send calibrate.start failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: calibrate.start returned: %s", temp); test_in_progress = VICTRON_CALIBRATION; return STAT_INSTCMD_HANDLED; } } else if(!strcasecmp(cmdname, "calibrate.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if(get_data("vTi2!",temp)) { upsdebugx(1, "instcmd: ser_send calibrate.stop failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: calibrate.stop returned: %s", temp); return STAT_INSTCMD_HANDLED; } } else if(!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if(get_data("vTi2!",temp)) { upsdebugx(1, "instcmd: ser_send test.battery.stop failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: test.battery.stop returned: %s", temp); return STAT_INSTCMD_HANDLED; } } else if(!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if(get_data("vTi4!",temp)) { upsdebugx(1, "instcmd: ser_send test.battery.start failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: test.battery.start returned: %s", temp); test_in_progress = VICTRON_BATTERY_TEST; return STAT_INSTCMD_HANDLED; } } else if(!strcasecmp(cmdname, "test.panel.stop")) { if(get_data("vTi2!",temp)) { upsdebugx(1, "instcmd: ser_send test.panel.stop failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: test.panel.stop returned: %s", temp); return STAT_INSTCMD_HANDLED; } } else if(!strcasecmp(cmdname, "test.panel.start")) { if(get_data("vTi3!",temp)) { upsdebugx(1, "instcmd: ser_send test.panel.start failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: test.panel.start returned: %s", temp); test_in_progress = VICTRON_SYSTEM_TEST; return STAT_INSTCMD_HANDLED; } } else if(!strcasecmp(cmdname, "bypass.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if(get_data("vTi2!",temp)) { upsdebugx(1, "instcmd: ser_send bypass.stop failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: bypass.stop returned: %s", temp); return STAT_INSTCMD_HANDLED; } } else if(!strcasecmp(cmdname, "bypass.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if(get_data("vTi101!",temp)) { upsdebugx(1, "instcmd: ser_send bypass.start failed"); return STAT_INSTCMD_UNKNOWN; /* Or Failed when it get defined */ } else { upsdebugx(1, "instcmd: bypass.start returned: %s", temp); test_in_progress = VICTRON_BYPASS_TEST; return STAT_INSTCMD_HANDLED; } } else { upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } } void upsdrv_initinfo(void) { if (model_name) dstate_setinfo("ups.model", "%s", model_name); upsh.instcmd = instcmd; dstate_addcmd("test.battery.start"); dstate_addcmd("test.battery.stop"); dstate_addcmd("calibrate.start"); dstate_addcmd("calibrate.stop"); dstate_addcmd("test.panel.start"); /* We need a GeneralSystemTest, but use this one instead */ dstate_addcmd("test.panel.stop"); /* We need a GeneralSystemTest, but use this one instead */ dstate_addcmd("bypass.start"); dstate_addcmd("bypass.stop"); } void upsdrv_updateinfo(void) { int flags; char temp[ LENGTH_TEMP ]; char test_result[ LENGTH_TEMP ]; long runtime_sec = -1; if (start_is_datastale) { if (get_data("vDS?",temp)) return; if (strcmp(temp+3,"NA")) exist_ups_serial=1; if (get_data("vBT?",temp)) return; if (strcmp(temp+3,"NA")) exist_ups_temperature =1; if (get_data("vO0I?",temp)) return; if (strcmp(temp+4,"NA")) exist_output_current =1; if (get_data("vBC?",temp)) return; if (strcmp(temp+3,"NA")) exist_battery_charge = 1; if (get_data("vBI?",temp)) return; if (strcmp(temp+3,"NA")) exist_battery_charge = 1; if (get_data("vBT?",temp)) return; if (strcmp(temp+3,"NA")) exist_battery_temperature = 1; if (get_data("vBt?",temp)) return; if (strcmp(temp+3,"NA")) exist_battery_runtime = 1; start_is_datastale = 0; } /* ups.status */ if (get_data("vAa?",temp)) return; flags = atoi (temp+3); status_init(); if (flags & VICTRON_OVER) status_set("OVER"); if (flags & VICTRON_RB) status_set("RB"); if (flags & VICTRON_LB) status_set("LB"); if (flags & VICTRON_OB) status_set("OB"); else status_set("OL"); /* Get UPS test results */ if (get_data("vTr?",temp)) return; if (get_data("vTd?",test_result)) return; switch(atoi(temp+3)) { case 1: upsdebugx(1, "upsdrv_updateinfo: test %i result = Done, Passed: %s",test_in_progress,test_result+3); test_in_progress = VICTRON_NO_TEST; break; case 2: upsdebugx(1, "upsdrv_updateinfo: test %i result = Done, Warning: %s",test_in_progress,test_result+3); test_in_progress = VICTRON_NO_TEST; break; case 3: upsdebugx(1, "upsdrv_updateinfo: test %i result = Done, Error: %s",test_in_progress,test_result+3); test_in_progress = VICTRON_NO_TEST; break; case 4: upsdebugx(1, "upsdrv_updateinfo: test %i result = Aborted: %s",test_in_progress,test_result+3); test_in_progress = VICTRON_NO_TEST; break; case 5: if(test_in_progress==VICTRON_CALIBRATION) status_set("CAL"); /* calibration in progress */ upsdebugx(1, "upsdrv_updateinfo: test %i result = In Progress: %s", test_in_progress,test_result+3); break; case 6: upsdebugx(1, "upsdrv_updateinfo: test result = No test initiated: %s", test_result+3); break; default: upsdebugx(1, "upsdrv_updateinfo: unknown test result: %s / %s",temp+3,test_result+3); break; } status_commit(); /* dstate_dataok(); */ upsdebugx(1, "upsdrv_updateinfo: ups.status = %s\n", dstate_getinfo("ups.status")); /************** ups.x ***************************/ /* ups model */ if (!model_name) { if (get_data("vDM?",temp)) return; dstate_setinfo("ups.model", "%s", temp+3); upsdebugx(1, "ups.model >%s<>%s<\n",temp,temp+3); } /* ups.mfr */ if (get_data("vDm?",temp)) return; dstate_setinfo("ups.mfr", "%s", temp+3); upsdebugx(1, "ups.mfr >%s<>%s<\n",temp,temp+3); /* ups.serial */ if (exist_ups_serial) { if (get_data("vDS?",temp)) return; dstate_setinfo("ups.serial", "%s", temp+3); } upsdebugx(1, "ups.serial >%s<>%s<\n",temp,temp+3); /* ups.firmware */ if (get_data("vDV?",temp)) return; dstate_setinfo("ups.firmware", "%s", temp+3); upsdebugx(1, "ups.firmware >%s<>%s<\n",temp,temp+3); /* ups.temperature */ if (exist_ups_temperature) { if (get_data("vBT?",temp)) return; dstate_setinfo("ups.temperature", "%s", temp+3); } upsdebugx(1, "ups.temperature >%s<>%s<\n",temp,temp+3); /* ups.load */ if (get_data("vO0L?",temp)) return; dstate_setinfo("ups.load", "%s", temp+4); upsdebugx(1, "ups.load >%s<>%s<\n",temp,temp+4); /* ups protocol */ /* if (get_data("vDC?",temp)) return; dstate_setinfo("ups.protocol", "%s", temp+3; upsdebugx(1, "ups.protocol >%s<>%s<\n",temp,temp+3; */ /************** input.x *****************/ /* input.voltage */ if (get_data("vI0U?",temp)) return; dstate_setinfo("input.voltage", "%s", temp+4); upsdebugx(1, "input.voltage >%s<>%s<\n",temp,temp+4); /* input.transfer.low */ if (get_data("vFi?",temp)) return; dstate_setinfo("input.transfer.low", "%s", temp+3); upsdebugx(1, "input.transfer.low >%s<>%s<\n",temp,temp+3); /* input.transfer.high */ if (get_data("vFj?",temp)) return; dstate_setinfo("input.transfer.high", "%s", temp+3); upsdebugx(1, "input.transfer.high >%s<>%s<\n",temp,temp+3); /* input.frequency */ if (get_data("vI0f?",temp)) return; dstate_setinfo("input.frequency", "%2.1f", atof(temp+4) / 10.0); upsdebugx(1, "input.frequency >%s<>%s<\n",temp,temp+4); /*************** output.x ********************************/ /* output.voltage */ if (get_data("vO0U?",temp)) return; dstate_setinfo("output.voltage", "%s", temp+4); upsdebugx(1, "output.voltage >%s<>%s<\n",temp,temp+4); /* output.frequency */ if (get_data("vOf?",temp)) return; dstate_setinfo("output.frequency", "%2.1f", atof(temp+3) / 10.0); upsdebugx(1, "output.frequency >%s<>%s<\n",temp,temp+3); /* output.current */ if (exist_output_current) { if (get_data("vO0I?",temp)) return; dstate_setinfo("output.current", "%2.1f", atof(temp+4) / 10.0); } upsdebugx(1, "output.current >%s<>%s<\n",temp,temp+4); /*************** battery.x *******************************/ /* battery charge */ if (exist_battery_charge) { if (get_data("vBC?",temp)) return; dstate_setinfo("battery.charge", "%s", temp+3); } upsdebugx(1, "battery.charge >%s<>%s<\n",temp,temp+3); /* battery.voltage */ if (get_data("vBU?",temp)) return; dstate_setinfo("battery.voltage", "%2.1f", atof(temp+3) / 10.0); upsdebugx(1, "battery.voltage >%s<>%s<\n",temp,temp+3); /* battery.current */ if (exist_battery_current) { if (get_data("vBI?",temp)) return; dstate_setinfo("battery.current", "%2.1f", atof(temp+3) / 10.0); } upsdebugx(1, "battery.current >%s<>%s<\n",temp,temp+3); /* battery.temperature */ if (exist_battery_temperature) { if (get_data("vBT?",temp)) return; dstate_setinfo("battery.temperature", "%s", temp+3); } upsdebugx(1, "battery.temperature >%s<>%s<\n",temp,temp+3); /* battery.runtime */ if (exist_battery_runtime) { if (get_data("vBt?",temp)) return; runtime_sec = strtol(temp+3, NULL, 10)*60; snprintf(temp, sizeof(temp), "%ld", runtime_sec); dstate_setinfo("battery.runtime", "%s", temp); } upsdebugx(1, "battery.runtime >%s<>%ld<\n",temp,runtime_sec); dstate_dataok(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ ser_send(upsfd, "vCc0!%c", ENDCHAR); usleep(UPS_DELAY); ser_send(upsfd, "vCb%i!%c", sdwdelay, ENDCHAR); } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { addvar(VAR_VALUE, "usd", "Seting delay before shutdown"); addvar(VAR_VALUE, "modelname", "Seting model name"); } void upsdrv_initups(void) { char temp[ LENGTH_TEMP ], *usd = NULL; /* = NULL je dulezite jen pro prekladac */ upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B1200); if ((usd = getval("usd"))) { sdwdelay=atoi(usd); upsdebugx(1, "(-x) Delay before shutdown %i",sdwdelay); } if ((model_name = getval("modelname"))) { /* kdyz modelname nebylo zadano je vraceno NULL*/ upsdebugx(1, "(-x) UPS Name %s",model_name); } /* inicializace a synchronizace UPS */ ser_send_char(upsfd, ENDCHAR); usleep (UPS_LONG_DELAY); ser_send(upsfd, "?%c", ENDCHAR); usleep (UPS_LONG_DELAY); ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, 3, 0); ser_send(upsfd, "?%c", ENDCHAR); usleep (UPS_LONG_DELAY); ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, 3, 0); ser_send(upsfd, "?%c", ENDCHAR); usleep (UPS_DELAY); ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, 3, 0); /* the upsh handlers can't be done here, as they get initialized * shortly after upsdrv_initups returns to main. */ } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/usb-common.c0000644000175000017500000003112415000736161013155 00000000000000/* usb-common.c - common useful USB functions Copyright (C) 2008 Arnaud Quette This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be first */ #include "common.h" #include "usb-common.h" int is_usb_device_supported(usb_device_id_t *usb_device_id_list, USBDevice_t *device) { int retval = NOT_SUPPORTED; usb_device_id_t *usbdev; for (usbdev = usb_device_id_list; (usbdev->vendorID != 0 || usbdev->productID != 0 || usbdev->fun != NULL); usbdev++ ) { if (usbdev->vendorID != device->VendorID) { continue; } /* flag as possibly supported if we see a known vendor */ retval = POSSIBLY_SUPPORTED; if (usbdev->productID != device->ProductID) { continue; } /* call the specific handler, if it exists */ if (usbdev->fun != NULL) { (*usbdev->fun)(device); } return SUPPORTED; } return retval; } /* ---------------------------------------------------------------------- */ /* matchers */ /* private callback function for exact matches */ static int match_function_exact(USBDevice_t *hd, void *privdata) { USBDevice_t *data = (USBDevice_t *)privdata; upsdebugx(3, "%s: matching a device...", __func__); if (hd->VendorID != data->VendorID) { upsdebugx(2, "%s: failed match of %s: %4x != %4x", __func__, "VendorID", hd->VendorID, data->VendorID); return 0; } if (hd->ProductID != data->ProductID) { upsdebugx(2, "%s: failed match of %s: %4x != %4x", __func__, "ProductID", hd->ProductID, data->ProductID); return 0; } if (strcmp_null(hd->Vendor, data->Vendor) != 0) { upsdebugx(2, "%s: failed match of %s: %s != %s", __func__, "Vendor", hd->Vendor, data->Vendor); return 0; } if (strcmp_null(hd->Product, data->Product) != 0) { upsdebugx(2, "%s: failed match of %s: %s != %s", __func__, "Product", hd->Product, data->Product); return 0; } if (strcmp_null(hd->Serial, data->Serial) != 0) { upsdebugx(2, "%s: failed match of %s: %s != %s", __func__, "Serial", hd->Serial, data->Serial); return 0; } #ifdef DEBUG_EXACT_MATCH_BUS if (strcmp_null(hd->Bus, data->Bus) != 0) { upsdebugx(2, "%s: failed match of %s: %s != %s", __func__, "Bus", hd->Bus, data->Bus); return 0; } #endif #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) # ifdef DEBUG_EXACT_MATCH_BUSPORT if (strcmp_null(hd->BusPort, data->BusPort) != 0) { upsdebugx(2, "%s: failed match of %s: %s != %s", __func__, "BusPort", hd->BusPort, data->BusPort); return 0; } # endif #endif #ifdef DEBUG_EXACT_MATCH_DEVICE if (strcmp_null(hd->Device, data->Device) != 0) { upsdebugx(2, "%s: failed match of %s: %s != %s", __func__, "Device", hd->Device, data->Device); return 0; } #endif return 1; } /* constructor: create an exact matcher that matches the device. * On success, return 0 and store the matcher in *matcher. On * error, return -1 with errno set */ int USBNewExactMatcher(USBDeviceMatcher_t **matcher, USBDevice_t *hd) { USBDeviceMatcher_t *m; USBDevice_t *data; m = malloc(sizeof(*m)); if (!m) { return -1; } data = calloc(1, sizeof(*data)); if (!data) { free(m); return -1; } m->match_function = &match_function_exact; m->privdata = (void *)data; m->next = NULL; data->VendorID = hd->VendorID; data->ProductID = hd->ProductID; data->Vendor = hd->Vendor ? strdup(hd->Vendor) : NULL; data->Product = hd->Product ? strdup(hd->Product) : NULL; data->Serial = hd->Serial ? strdup(hd->Serial) : NULL; #ifdef DEBUG_EXACT_MATCH_BUS data->Bus = hd->Bus ? strdup(hd->Bus) : NULL; #endif #ifdef DEBUG_EXACT_MATCH_DEVICE data->Device = hd->Device ? strdup(hd->Device) : NULL; #endif /* NOTE: Callers must pre-initialize to NULL! */ if (matcher && *matcher) { free(*matcher); *matcher = NULL; } *matcher = m; return 0; } /* destructor: free matcher previously created with USBNewExactMatcher */ void USBFreeExactMatcher(USBDeviceMatcher_t *matcher) { USBDevice_t *data; if (!matcher) { return; } data = (USBDevice_t *)matcher->privdata; free(data->Vendor); free(data->Product); free(data->Serial); #ifdef DEBUG_EXACT_MATCH_BUS free(data->Bus); #endif #ifdef DEBUG_EXACT_MATCH_DEVICE free(data->Device); #endif free(data); free(matcher); } /* private data type: hold a set of compiled regular expressions. */ typedef struct regex_matcher_data_s { regex_t *regex[USBMATCHER_REGEXP_ARRAY_LIMIT]; } regex_matcher_data_t; /* private callback function for regex matches */ static int match_function_regex(USBDevice_t *hd, void *privdata) { regex_matcher_data_t *data = (regex_matcher_data_t *)privdata; int r; upsdebugx(3, "%s: matching a device...", __func__); /* NOTE: Here and below the "detailed" logging is commented away * because data->regex[] elements are not strings anymore! */ r = match_regex_hex(data->regex[0], hd->VendorID); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %4x !~ %s", __func__, "VendorID", hd->VendorID, data->regex[0]); */ upsdebugx(2, "%s: failed match of %s: %4x", __func__, "VendorID", hd->VendorID); return r; } r = match_regex_hex(data->regex[1], hd->ProductID); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %4x !~ %s", __func__, "ProductID", hd->ProductID, data->regex[1]); */ upsdebugx(2, "%s: failed match of %s: %4x", __func__, "ProductID", hd->ProductID); return r; } r = match_regex(data->regex[2], hd->Vendor); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %s !~ %s", __func__, "Vendor", hd->Vendor, data->regex[2]); */ upsdebugx(2, "%s: failed match of %s: %s", __func__, "Vendor", hd->Vendor); return r; } r = match_regex(data->regex[3], hd->Product); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %s !~ %s", __func__, "Product", hd->Product, data->regex[3]); */ upsdebugx(2, "%s: failed match of %s: %s", __func__, "Product", hd->Product); return r; } r = match_regex(data->regex[4], hd->Serial); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %s !~ %s", __func__, "Serial", hd->Serial, data->regex[4]); */ upsdebugx(2, "%s: failed match of %s: %s", __func__, "Serial", hd->Serial); return r; } r = match_regex(data->regex[5], hd->Bus); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %s !~ %s", __func__, "Bus", hd->Bus, data->regex[5]); */ upsdebugx(2, "%s: failed match of %s: %s", __func__, "Bus", hd->Bus); return r; } r = match_regex(data->regex[6], hd->Device); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %s !~ %s", __func__, "Device", hd->Device, data->regex[6]); */ upsdebugx(2, "%s: failed match of %s: %s", __func__, "Device", hd->Device); return r; } #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) r = match_regex(data->regex[7], hd->BusPort); if (r != 1) { /* upsdebugx(2, "%s: failed match of %s: %s !~ %s", __func__, "Device", hd->Device, data->regex[6]); */ upsdebugx(2, "%s: failed match of %s: %s", __func__, "Bus Port", hd->BusPort); return r; } #endif return 1; } /* constructor: create a regular expression matcher. This matcher is * based on seven regular expression strings in regex_array[0..6], * corresponding to: vendorid, productid, vendor, product, serial, * bus, device. Any of these strings can be NULL, which matches * everything. Cflags are as in regcomp(3). Typical values for cflags * are REG_ICASE (case insensitive matching) and REG_EXTENDED (use * extended regular expressions). On success, return 0 and store the * matcher in *matcher. On error, return -1 with errno set, or return * i=1--7 to indicate that the regular expression regex_array[i-1] was * ill-formed (an error message can then be retrieved with * regerror(3)). */ int USBNewRegexMatcher(USBDeviceMatcher_t **matcher, char **regex, int cflags) { int r, i; USBDeviceMatcher_t *m; regex_matcher_data_t *data; m = malloc(sizeof(*m)); if (!m) { return -1; } data = calloc(1, sizeof(*data)); if (!data) { free(m); return -1; } m->match_function = &match_function_regex; m->privdata = (void *)data; m->next = NULL; for (i=0; i < USBMATCHER_REGEXP_ARRAY_LIMIT; i++) { r = compile_regex(&data->regex[i], regex[i], cflags); if (r == -2) { r = i+1; } if (r) { USBFreeRegexMatcher(m); return r; } } /* NOTE: Callers must pre-initialize to NULL! */ if (matcher && *matcher) { free(*matcher); *matcher = NULL; } *matcher = m; return 0; } void USBFreeRegexMatcher(USBDeviceMatcher_t *matcher) { int i; regex_matcher_data_t *data; if (!matcher) { return; } data = (regex_matcher_data_t *)matcher->privdata; for (i = 0; i < USBMATCHER_REGEXP_ARRAY_LIMIT; i++) { if (!data->regex[i]) { continue; } regfree(data->regex[i]); free(data->regex[i]); } free(data); free(matcher); } void warn_if_bad_usb_port_filename(const char *fn) { /* USB drivers ignore the 'port' setting - log a notice * if it is not "auto". Note: per se, ignoring the port * (or internally the device_path variable from main.c) * is currently not a bug and is actually documented at * docs/config-notes.txt; however it is not something * evident to users during troubleshooting a device. * Documentation and common practice recommend port=auto * so here we warn during driver start if it has some * other value and users might think it is honoured. */ if (!fn) { upslogx(LOG_WARNING, "WARNING: %s(): port argument was not " "specified to the driver", __func__); return; } if (!strcmp(fn, "auto")) return; upslogx(LOG_WARNING, "WARNING: %s(): port argument specified to\n" " the driver is \"%s\" but USB drivers do " "not use it and rely on\n" " libusb walking all devices and matching " "their identification metadata.\n" " NUT documentation recommends port=\"auto\" " "for USB devices to avoid confusion.", __func__, fn); return; } /* Retries were introduced for "Tripp Lite" devices, see * https://github.com/networkupstools/nut/issues/414 */ #define MAX_STRING_DESC_TRIES 3 /* API neutral, handles retries. * Note for future development: a variant of this code is adapted into * tools/nut-scanner/scan_usb.c - please keep in sync if changing here. */ static int nut_usb_get_string_descriptor( usb_dev_handle *udev, int StringIdx, int langid, char *buf, size_t buflen) { int ret = -1; int tries = MAX_STRING_DESC_TRIES; while (tries--) { ret = usb_get_string(udev, (usb_ctrl_strindex)StringIdx, langid, (usb_ctrl_charbuf)buf, buflen); if (ret >= 0) { break; } else if (tries) { upsdebugx(1, "%s: string descriptor %d request failed, retrying...", __func__, StringIdx); usleep(50000); /* 50 ms, might help in some cases */ } } return ret; } /* API neutral, assumes en_US if langid descriptor is broken. * Note for future development: a variant of this code is adapted into * tools/nut-scanner/scan_usb.c - please keep in sync if changing here. */ int nut_usb_get_string( usb_dev_handle *udev, int StringIdx, char *buf, size_t buflen) { int ret; char buffer[255]; int langid; int len; int i; if (!udev || StringIdx < 1 || StringIdx > 255) { return -1; } /* request langid descriptor */ ret = nut_usb_get_string_descriptor(udev, 0, 0, buffer, 4); if (ret < 0) return ret; if (ret == 4 && buffer[0] >= 4 && buffer[1] == USB_DT_STRING) { langid = buffer[2] | (buffer[3] << 8); } else { upsdebugx(1, "%s: Broken language identifier, assuming en_US", __func__); langid = 0x0409; } /* retrieve string in preferred language */ ret = nut_usb_get_string_descriptor(udev, StringIdx, langid, buffer, sizeof(buffer)); if (ret < 0) { #ifdef WIN32 /* only for libusb0 ? */ errno = -ret; #endif /* WIN32 */ return ret; } /* translate simple UTF-16LE to 8-bit */ len = ret < (int)buflen ? ret : (int)buflen; len = len / 2 - 1; /* 16-bit characters, without header */ len = len < (int)buflen - 1 ? len : (int)buflen - 1; /* reserve for null terminator */ for (i = 0; i < len; i++) { if (buffer[2 + i * 2 + 1] == 0) buf[i] = buffer[2 + i * 2]; else buf[i] = '?'; /* not decoded */ } buf[i] = '\0'; return len; } nut-2.8.4/drivers/nutdrv_qx_voltronic-axpert.h0000644000175000017500000000210315044656702016542 00000000000000/* nutdrv_qx_voltronic-axpert.h - Subdriver for Voltronic Power Axpert * * Copyright (C) * 2014 Daniele Pezzini * 2022 Graham Leggett * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_VOLTRONIC_AXPERT_H #define NUTDRV_QX_VOLTRONIC_AXPERT_H #include "nutdrv_qx.h" extern subdriver_t voltronic_axpert_subdriver; #endif /* NUTDRV_QX_VOLTRONIC_AXPERT_H */ nut-2.8.4/drivers/idowell-hid.c0000644000175000017500000001725614777753336013340 00000000000000/* idowell-hid.c - subdriver to monitor iDowell USB/HID devices with NUT * * Copyright (C) * 2003 - 2009 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * * Note: this subdriver was initially generated as a "stub" by the * gen-usbhid-subdriver script. It must be customized. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be first */ #include "usbhid-ups.h" #include "idowell-hid.h" #include "main.h" /* for getval() */ #include "usb-common.h" #define IDOWELL_HID_VERSION "iDowell HID 0.2" /* FIXME: experimental flag to be put in upsdrv_info */ /* iDowell */ #define IDOWELL_VENDORID 0x075d /* USB IDs device table */ static usb_device_id_t idowell_usb_device_table[] = { /* iDowell */ { USB_DEVICE(IDOWELL_VENDORID, 0x0300), NULL }, /* Terminating entry */ { 0, 0, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* IDOWELL usage table */ static usage_lkp_t idowell_usage_lkp[] = { { NULL, 0 } }; static usage_tables_t idowell_utab[] = { idowell_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t idowell_hid2nut[] = { #if WITH_UNMAPPED_DATA_POINTS || (defined DEBUG) { "unmapped.ups.flow.[4].flowid", 0, 0, "UPS.Flow.[4].FlowID", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powerconverter.output.outputid", 0, 0, "UPS.PowerConverter.Output.OutputID", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powerconverter.powerconverterid", 0, 0, "UPS.PowerConverter.PowerConverterID", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitygranularity1", 0, 0, "UPS.PowerSummary.CapacityGranularity1", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitymode", 0, 0, "UPS.PowerSummary.CapacityMode", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.flowid", 0, 0, "UPS.PowerSummary.FlowID", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.fullchargecapacity", 0, 0, "UPS.PowerSummary.FullChargeCapacity", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.imanufacturer", 0, 0, "UPS.PowerSummary.iManufacturer", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.iproduct", 0, 0, "UPS.PowerSummary.iProduct", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.iserialnumber", 0, 0, "UPS.PowerSummary.iSerialNumber", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.powersummaryid", 0, 0, "UPS.PowerSummary.PowerSummaryID", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.presentstatus.undefined", 0, 0, "UPS.PowerSummary.PresentStatus.Undefined", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS || DEBUG */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.CommunicationLost", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Good", NULL, NULL, 0, off_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.InternalFailure", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, /* battery page */ { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.charge.low", 0, 0, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_STATIC , NULL }, /* Read only */ { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, /* UPS page */ { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL}, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL}, { "ups.timer.start", 0, 0, "UPS.PowerSummary.DelayBeforeStartup", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.shutdown", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.load", 0, 0, "UPS.PowerSummary.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.power.nominal", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* input page */ { "input.transfer.high", 0, 0, "UPS.PowerConverter.Output.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.transfer.low", 0, 0, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* output page */ { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.1f", 0, NULL }, { "output.voltage.nominal", 0, 0, "UPS.Flow.[4].ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "output.frequency.nominal", 0, 0, "UPS.Flow.[4].ConfigFrequency", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* instant commands */ { "load.off.delay", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.PowerSummary.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "shutdown.stop", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *idowell_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *idowell_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "iDowell"; } static const char *idowell_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int idowell_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(idowell_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("iDowell", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t idowell_subdriver = { IDOWELL_HID_VERSION, idowell_claim, idowell_utab, idowell_hid2nut, idowell_format_model, idowell_format_mfr, idowell_format_serial, fix_report_desc, }; nut-2.8.4/drivers/nutdrv_qx_zinto.h0000644000175000017500000000174414670526611014376 00000000000000/* nutdrv_qx_zinto.h - Subdriver for Zinto protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_ZINTO_H #define NUTDRV_QX_ZINTO_H #include "nutdrv_qx.h" extern subdriver_t zinto_subdriver; #endif /* NUTDRV_QX_ZINTO_H */ nut-2.8.4/drivers/baytech-mib.c0000644000175000017500000001226015000601404013251 00000000000000/* baytech-mib.c - data to monitor BayTech PDUs * * Copyright (C) 2009 * Opengear * Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "baytech-mib.h" /* NOTE: last badly versioned release was "4032" but should be "X.Y[Z]"! */ #define BAYTECH_MIB_VERSION "0.4035" /* Baytech MIB */ #define BAYTECH_OID_MIB ".1.3.6.1.4.1.4779" #define BAYTECH_OID_MODEL_NAME ".1.3.6.1.4.1.4779.1.3.5.2.1.24.1" static info_lkp_t baytech_outlet_status_info[] = { info_lkp_default(-1, "error"), info_lkp_default(0, "off"), info_lkp_default(1, "on"), info_lkp_default(2, "cycling"), /* transitional status, "reboot" in MIB comments */ info_lkp_default(3, "lockon"), info_lkp_default(4, "lockoff"), info_lkp_default(5, "unlock"), info_lkp_default(6, "unknown"), info_lkp_sentinel }; /* Snmp2NUT lookup table for BayTech MIBs */ static snmp_info_t baytech_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "BayTech", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.2.1.24.1", "Generic SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.2.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.macaddr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.2.1.2.2.1.6.2", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* UPS page */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Baytech", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.2.1.24.1", "Generic SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.id", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.3.0", "unknown", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.2.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.1.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.temperature", 0, 0.1, ".1.3.6.1.4.1.4779.1.3.5.5.1.10.2.1", NULL, 0, NULL), /* Outlet page */ snmp_info_default("outlet.id", 0, 1, NULL, "0", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, NULL, "All outlets", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.count", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.2.1.15.1", "0", 0, NULL), snmp_info_default("outlet.current", 0, 0.1, ".1.3.6.1.4.1.4779.1.3.5.5.1.6.2.1", NULL, 0, NULL), snmp_info_default("outlet.voltage", 0, 0.1, ".1.3.6.1.4.1.4779.1.3.5.5.1.8.2.1", NULL, 0, NULL), /* outlet template definition */ snmp_info_default("outlet.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.3.1.3.1.%i", NULL, SU_OUTLET, &baytech_outlet_status_info[0]), snmp_info_default("outlet.%i.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.3.1.4.1.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.id", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.6.1.3.2.1.%i", "%i", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_OUTLET | SU_FLAG_OK, NULL), snmp_info_default("outlet.%i.switchable", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.3.1.1.1.%i", "yes", SU_FLAG_STATIC | SU_OUTLET, NULL), /* instant commands. */ snmp_info_default("outlet.%i.load.off", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.3.1.3.1.%i", "0", SU_TYPE_CMD | SU_OUTLET, NULL), snmp_info_default("outlet.%i.load.on", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.3.1.3.1.%i", "1", SU_TYPE_CMD | SU_OUTLET, NULL), /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t baytech = { "baytech", BAYTECH_MIB_VERSION, NULL, BAYTECH_OID_MODEL_NAME, baytech_mib, BAYTECH_OID_MIB, NULL }; nut-2.8.4/drivers/bcmxcp_ser.h0000644000175000017500000000117314777753336013260 00000000000000/* * bcmxcp_ser.h -- header for BCM/XCP RS-232 module */ #ifndef BCMXCP_SER__ #define BCMXCP_SER__ #include "serial.h" /* pulls termios.h to define speed_t */ /* This header is needed for this line, to avoid warnings about it not * being static in C file (can't hide, is also needed by nut-scanner) */ extern unsigned char BCMXCP_AUTHCMD[4]; typedef struct { speed_t rate; /* Value like B19200 defined in termios.h; note: NOT the bitrate numerically */ size_t name; /* Actual rate... WHY is this "name" - number to print interactively? */ } pw_baud_rate_t; extern pw_baud_rate_t pw_baud_rates[]; #endif /* BCMXCP_SER__ */ nut-2.8.4/drivers/nutdrv_atcl_usb.c0000644000175000017500000005110615044656702014310 00000000000000/* * nutdrv_atcl_usb.c - driver for generic-brand "ATCL FOR UPS" * * Copyright (C) 2013-2014 Charles Lepple * Copyright (C) 2016 Eaton * * Loosely based on richcomm_usb.c, * Copyright (C) 2007 Peter van Valderen * Dirk Teurlings * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "usb-common.h" /* driver version */ #define DRIVER_NAME "'ATCL FOR UPS' USB driver" #define DRIVER_VERSION "1.20" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Charles Lepple ", DRV_EXPERIMENTAL, { NULL } }; #define STATUS_ENDPOINT (USB_ENDPOINT_IN | 1) #define SHUTDOWN_ENDPOINT (USB_ENDPOINT_OUT | 2) #define STATUS_PACKETSIZE 8 #define SHUTDOWN_PACKETSIZE 8 /* Probably can reduce this, since the pcap file shows mostly 1050-ish ms response times */ #define ATCL_USB_TIMEOUT USB_TIMEOUT /* limit the amount of spew that goes in the syslog when we lose the UPS (from nut_usb.h) */ #define USB_ERR_LIMIT 10 /* start limiting after 10 in a row */ #define USB_ERR_RATE 10 /* then only print every 10th error */ #define USB_VENDOR_STRING "ATCL FOR UPS" static usb_device_id_t atcl_usb_id[] = { /* ATCL FOR UPS */ { USB_DEVICE(0x0001, 0x0000), NULL }, /* Terminating entry */ { 0, 0, NULL } }; static usb_dev_handle *udev = NULL; static USBDevice_t usbdevice; static unsigned int comm_failures = 0; /* Forward decls */ static int instcmd(const char *cmdname, const char *extra); static int device_match_func(USBDevice_t *device, void *privdata) { char *requested_vendor; NUT_UNUSED_VARIABLE(privdata); switch (is_usb_device_supported(atcl_usb_id, device)) { case SUPPORTED: if(!device->Vendor) { upsdebugx(1, "Couldn't retrieve USB string descriptor for vendor. Check permissions?"); requested_vendor = getval("vendor"); if(requested_vendor) { if(!strcmp("NULL", requested_vendor)) { upsdebugx(3, "Matched device with NULL vendor string."); return 1; } } upsdebugx(0, "To keep trying (in case your device does not have a vendor string), use vendor=NULL. " "Have you tried the nutdrv_qx driver?"); return 0; } if(!strcmp(device->Vendor, USB_VENDOR_STRING)) { upsdebugx(4, "Matched expected vendor='%s'.", USB_VENDOR_STRING); return 1; } /* Didn't match, but the user provided an alternate vendor ID: */ requested_vendor = getval("vendor"); if(requested_vendor) { if(!strcmp(device->Vendor, requested_vendor)) { upsdebugx(3, "Matched device with vendor='%s'.", requested_vendor); return 1; } else { upsdebugx(0, "idVendor=%04x and idProduct=%04x, " "but provided vendor '%s' does not match device: '%s'. " "Have you tried the nutdrv_qx driver?", device->VendorID, device->ProductID, requested_vendor, device->Vendor); return 0; } } /* TODO: automatic way of suggesting other drivers? */ upsdebugx(0, "idVendor=%04x and idProduct=%04x, " "but device vendor string '%s' does not match expected string '%s'. " "Have you tried the nutdrv_qx driver?", device->VendorID, device->ProductID, device->Vendor, USB_VENDOR_STRING); return 0; case POSSIBLY_SUPPORTED: case NOT_SUPPORTED: default: return 0; } } static USBDeviceMatcher_t device_matcher = { &device_match_func, NULL, NULL }; static int query_ups(char *reply) { int ret; ret = usb_interrupt_read(udev, STATUS_ENDPOINT, (usb_ctrl_charbuf)reply, STATUS_PACKETSIZE, ATCL_USB_TIMEOUT); if (ret <= 0) { upsdebugx(2, "status interrupt read: %s", ret ? nut_usb_strerror(ret) : "timeout"); return ret; } assert ((uintmax_t)ret < (uintmax_t)SIZE_MAX); upsdebug_hex(3, "read", reply, (size_t)ret); return ret; } static void usb_comm_fail(const char *fmt, ...) { int ret; char why[SMALLBUF]; va_list ap; /* this means we're probably here because select was interrupted */ if (exit_flag != 0) { return; /* ignored, since we're about to exit anyway */ } comm_failures++; if ((comm_failures == USB_ERR_LIMIT) || ((comm_failures % USB_ERR_RATE) == 0)) { upslogx(LOG_WARNING, "Warning: excessive comm failures, limiting error reporting"); } /* once it's past the limit, only log once every USB_ERR_LIMIT calls */ if ((comm_failures > USB_ERR_LIMIT) && ((comm_failures % USB_ERR_LIMIT) != 0)) { return; } /* generic message if the caller hasn't elaborated */ if (!fmt) { upslogx(LOG_WARNING, "Communications with UPS lost - check cabling"); return; } va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used locally with * fixed strings (and args) */ /* FIXME: Actually, only fixed strings, no formatting here. */ ret = vsnprintf(why, sizeof(why), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); if ((ret < 1) || (ret >= (int) sizeof(why))) { upslogx(LOG_WARNING, "usb_comm_fail: vsnprintf needed more than %d bytes", (int)sizeof(why)); } upslogx(LOG_WARNING, "Communications with UPS lost: %s", why); } static void usb_comm_good(void) { if (comm_failures == 0) { return; } upslogx(LOG_NOTICE, "Communications with UPS re-established"); comm_failures = 0; } /* * Callback that is called by usb_device_open() that handles USB device * settings prior to accepting the devide. At the very least claim the * device here. Detaching the kernel driver will be handled by the * caller, don't do this here. Return < 0 on error, 0 or higher on * success. */ static int driver_callback(usb_dev_handle *handle, USBDevice_t *device) { int ret; NUT_UNUSED_VARIABLE(device); if ((ret = usb_set_configuration(handle, 1)) < 0) { upslogx(LOG_WARNING, "Can't set USB configuration: %s", nut_usb_strerror(ret)); return -1; } if ((ret = usb_claim_interface(handle, 0)) < 0) { upslogx(LOG_WARNING, "Can't claim USB interface: %s", nut_usb_strerror(ret)); return -1; } /* TODO: HID SET_IDLE to 0 (not necessary?) */ return 1; } static int usb_device_close(usb_dev_handle *handle) { int ret = 0; if (!handle) { return 0; } /* usb_release_interface() sometimes blocks and goes * into uninterruptible sleep. So don't do it. */ /* usb_release_interface(handle, 0); */ #if WITH_LIBUSB_1_0 libusb_close(handle); libusb_exit(NULL); #else ret = usb_close(handle); #endif return ret; } static int usb_device_open(usb_dev_handle **handlep, USBDevice_t *device, USBDeviceMatcher_t *matcher, int (*callback)(usb_dev_handle *handle, USBDevice_t *device)) { int ret = 0; uint8_t iManufacturer = 0, iProduct = 0, iSerialNumber = 0; #if WITH_LIBUSB_1_0 libusb_device **devlist; ssize_t devcount = 0; libusb_device_handle *handle; struct libusb_device_descriptor dev_desc; uint8_t bus_num; /* TODO: consider device_addr */ int i; #else /* => WITH_LIBUSB_0_1 */ struct usb_bus *bus; #endif /* libusb base init */ #if WITH_LIBUSB_1_0 if (libusb_init(NULL) < 0) { libusb_exit(NULL); fatal_with_errno(EXIT_FAILURE, "Failed to init libusb 1.0"); } #else /* => WITH_LIBUSB_0_1 */ usb_init(); usb_find_busses(); usb_find_devices(); #endif /* WITH_LIBUSB_1_0 */ #ifndef __linux__ /* SUN_LIBUSB (confirmed to work on Solaris and FreeBSD) */ /* Causes a double free corruption in linux if device is detached! */ /* usb_device_close(*handlep); */ if (*handlep) usb_close(*handlep); #endif #if WITH_LIBUSB_1_0 devcount = libusb_get_device_list(NULL, &devlist); if (devcount <= 0) fatal_with_errno(EXIT_FAILURE, "No USB device found"); for (i = 0; i < devcount; i++) { USBDeviceMatcher_t *m; libusb_device *dev = devlist[i]; libusb_get_device_descriptor(dev, &dev_desc); ret = libusb_open(dev, &handle); *handlep = handle; #else /* => WITH_LIBUSB_0_1 */ for (bus = usb_busses; bus; bus = bus->next) { struct usb_device *dev; usb_dev_handle *handle; for (dev = bus->devices; dev; dev = dev->next) { int i; USBDeviceMatcher_t *m; upsdebugx(3, "Checking USB device [%04x:%04x] (%s/%s)", dev->descriptor.idVendor, dev->descriptor.idProduct, bus->dirname, dev->filename); /* supported vendors are now checked by the supplied matcher */ /* open the device */ *handlep = handle = usb_open(dev); #endif /* WITH_LIBUSB_1_0 */ if (!handle) { upsdebugx(4, "Failed to open USB device, skipping: %s", nut_usb_strerror(ret)); continue; } /* collect the identifying information of this device. Note that this is safe, because there's no need to claim an interface for this (and therefore we do not yet need to detach any kernel drivers). */ free(device->Vendor); free(device->Product); free(device->Serial); free(device->Bus); memset(device, 0, sizeof(*device)); #if WITH_LIBUSB_1_0 device->VendorID = dev_desc.idVendor; device->ProductID = dev_desc.idProduct; bus_num = libusb_get_bus_number(dev); device->Bus = (char *)malloc(4); if (device->Bus == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } sprintf(device->Bus, "%03d", bus_num); iManufacturer = dev_desc.iManufacturer; iProduct = dev_desc.iProduct; iSerialNumber = dev_desc.iSerialNumber; #else /* => WITH_LIBUSB_0_1 */ device->VendorID = dev->descriptor.idVendor; device->ProductID = dev->descriptor.idProduct; device->Bus = xstrdup(bus->dirname); iManufacturer = dev->descriptor.iManufacturer; iProduct = dev->descriptor.iProduct; iSerialNumber = dev->descriptor.iSerialNumber; #endif /* WITH_LIBUSB_1_0 */ if (iManufacturer) { char buf[SMALLBUF]; ret = usb_get_string_simple(handle, iManufacturer, (usb_ctrl_charbuf)buf, sizeof(buf)); if (ret > 0) { device->Vendor = strdup(buf); if (device->Vendor == NULL) { #if WITH_LIBUSB_1_0 libusb_free_device_list(devlist, 1); #endif /* WITH_LIBUSB_1_0 */ fatal_with_errno(EXIT_FAILURE, "Out of memory"); } } } if (iProduct) { char buf[SMALLBUF]; ret = usb_get_string_simple(handle, iProduct, (usb_ctrl_charbuf)buf, sizeof(buf)); if (ret > 0) { device->Product = strdup(buf); if (device->Product == NULL) { #if WITH_LIBUSB_1_0 libusb_free_device_list(devlist, 1); #endif /* WITH_LIBUSB_1_0 */ fatal_with_errno(EXIT_FAILURE, "Out of memory"); } } } if (iSerialNumber) { char buf[SMALLBUF]; ret = usb_get_string_simple(handle, iSerialNumber, (usb_ctrl_charbuf)buf, sizeof(buf)); if (ret > 0) { device->Serial = strdup(buf); if (device->Serial == NULL) { #if WITH_LIBUSB_1_0 libusb_free_device_list(devlist, 1); #endif /* WITH_LIBUSB_1_0 */ fatal_with_errno(EXIT_FAILURE, "Out of memory"); } } } upsdebugx(4, "- VendorID : %04x", device->VendorID); upsdebugx(4, "- ProductID : %04x", device->ProductID); upsdebugx(4, "- Manufacturer : %s", device->Vendor ? device->Vendor : "unknown"); upsdebugx(4, "- Product : %s", device->Product ? device->Product : "unknown"); upsdebugx(4, "- Serial Number: %s", device->Serial ? device->Serial : "unknown"); upsdebugx(4, "- Bus : %s", device->Bus ? device->Bus : "unknown"); for (m = matcher; m; m = m->next) { switch (m->match_function(device, m->privdata)) { case 0: upsdebugx(4, "Device does not match - skipping"); goto next_device; case -1: #if WITH_LIBUSB_1_0 libusb_free_device_list(devlist, 1); #endif /* WITH_LIBUSB_1_0 */ fatal_with_errno(EXIT_FAILURE, "matcher"); #ifndef HAVE___ATTRIBUTE__NORETURN # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunreachable-code" # endif goto next_device; # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic pop # endif #endif case -2: upsdebugx(4, "matcher: unspecified error"); goto next_device; default: break; } } #ifdef HAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVER /* First, try the auto-detach kernel driver method * This function is not available on FreeBSD 10.1-10.3 */ if ((ret = libusb_set_auto_detach_kernel_driver (udev, 1)) < 0) upsdebugx(2, "failed to auto detach kernel driver from USB device: %s", nut_usb_strerror((enum libusb_error)ret)); else upsdebugx(2, "auto detached kernel driver from USB device"); #endif /* HAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVER */ for (i = 0; i < 3; i++) { ret = callback(handle, device); if (ret >= 0) { upsdebugx(3, "USB device [%04x:%04x] opened", device->VendorID, device->ProductID); #if WITH_LIBUSB_1_0 libusb_free_device_list(devlist, 1); #endif /* WITH_LIBUSB_1_0 */ return ret; } #if WITH_LIBUSB_0_1 && (defined HAVE_USB_DETACH_KERNEL_DRIVER_NP) /* this method requires at least libusb 0.1.8: * it forces device claiming by unbinding * attached driver... From libhid */ if ((ret = usb_detach_kernel_driver_np(handle, 0)) < 0) { upsdebugx(1, "failed to detach kernel driver from USB device: %s", nut_usb_strerror(ret)); } else { upsdebugx(4, "detached kernel driver from USB device..."); } #else # ifdef HAVE_LIBUSB_DETACH_KERNEL_DRIVER if ((ret = libusb_detach_kernel_driver(udev, 0)) < 0) { upsdebugx(4, "failed to detach kernel driver from USB device: %s", nut_usb_strerror(ret)); } else { upsdebugx(4, "detached kernel driver from USB device..."); } # else # ifdef HAVE_LIBUSB_DETACH_KERNEL_DRIVER_NP if ((ret = libusb_detach_kernel_driver_np(udev, 0)) < 0) { upsdebugx(4, "failed to detach kernel driver from USB device: %s", nut_usb_strerror(ret)); } else { upsdebugx(4, "detached kernel driver from USB device..."); } # endif /* HAVE_LIBUSB_DETACH_KERNEL_DRIVER_NP */ # endif /* HAVE_LIBUSB_DETACH_KERNEL_DRIVER */ #endif /* HAVE_USB_DETACH_KERNEL_DRIVER_NP or HAVE_LIBUSB_DETACH_KERNEL_DRIVER or HAVE_LIBUSB_DETACH_KERNEL_DRIVER_NP */ } #if WITH_LIBUSB_1_0 libusb_free_device_list(devlist, 1); #endif /* WITH_LIBUSB_1_0 */ fatalx(EXIT_FAILURE, "USB device [%04x:%04x] matches, but driver callback failed: %s", device->VendorID, device->ProductID, nut_usb_strerror(ret)); next_device: usb_close(handle); #if (!WITH_LIBUSB_1_0) /* => WITH_LIBUSB_0_1 */ } #endif /* WITH_LIBUSB_1_0 */ } *handlep = NULL; #if WITH_LIBUSB_1_0 libusb_free_device_list(devlist, 1); #endif /* WITH_LIBUSB_1_0 */ upsdebugx(3, "No matching USB device found"); return -1; } /* * Initialise the UPS */ void upsdrv_initups(void) { int i; upsdebugx(1, "Searching for USB device..."); for (i = 0; usb_device_open(&udev, &usbdevice, &device_matcher, &driver_callback) < 0; i++) { if (i < 3) { #ifdef WIN32 sleep(5); #else /* !WIN32 */ if (sleep(5) == 0) { #endif /* !WIN32 */ usb_comm_fail("Can't open USB device, retrying ..."); continue; #ifndef WIN32 } #endif /* !WIN32 */ } fatalx(EXIT_FAILURE, "Unable to find ATCL FOR UPS\n\n" "Things to try:\n" " - Connect UPS device to USB bus\n" " - Run this driver as another user (upsdrvctl -u or 'user=...' in ups.conf).\n" " See upsdrvctl(8) and ups.conf(5).\n\n" "Fatal error: unusable configuration"); } } void upsdrv_cleanup(void) { usb_device_close(udev); free(usbdevice.Vendor); free(usbdevice.Product); free(usbdevice.Serial); free(usbdevice.Bus); } void upsdrv_initinfo(void) { dstate_setinfo("ups.mfr", "%s", usbdevice.Vendor ? usbdevice.Vendor : "unknown"); dstate_setinfo("ups.model", "%s", usbdevice.Product ? usbdevice.Product : "unknown"); if(usbdevice.Serial && usbdevice.Product && strcmp(usbdevice.Serial, usbdevice.Product)) { /* Only set "ups.serial" if it isn't the same as "ups.model": */ dstate_setinfo("ups.serial", "%s", usbdevice.Serial); } dstate_setinfo("ups.vendorid", "%04x", usbdevice.VendorID); dstate_setinfo("ups.productid", "%04x", usbdevice.ProductID); /* commands ----------------------------------------------- */ /* FIXME: Check with the device what our instcmd * (nee upsdrv_shutdown() contents) actually does! */ dstate_addcmd("shutdown.stayoff"); /* install handlers */ upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { char reply[STATUS_PACKETSIZE]; int ret; if (!udev) { ret = usb_device_open(&udev, &usbdevice, &device_matcher, &driver_callback); if (ret < 0) { return; } } ret = query_ups(reply); if (ret != STATUS_PACKETSIZE) { usb_comm_fail("Query to UPS failed"); dstate_datastale(); usb_device_close(udev); udev = NULL; return; } usb_comm_good(); dstate_dataok(); status_init(); switch(reply[0]) { case 3: upsdebugx(2, "reply[0] = 0x%02x -> OL", reply[0]); status_set("OL"); break; case 2: upsdebugx(2, "reply[0] = 0x%02x -> LB", reply[0]); status_set("LB"); goto fallthrough_LB_means_OB; /* Note: the comment below existed for years, so wondering * if this device CAN set independently LB and OB? */ /* fall through */ case 1: fallthrough_LB_means_OB: upsdebugx(2, "reply[0] = 0x%02x -> OB", reply[0]); status_set("OB"); break; default: upslogx(LOG_ERR, "Unknown status: 0x%02x", reply[0]); } if(strnlen(reply + 1, 7) != 0) { upslogx(LOG_NOTICE, "Status bytes 1-7 are not all zero"); } status_commit(); } /* handler for commands to be sent to UPS */ static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); /* FIXME: Which one is this - "load.off", * "shutdown.stayoff" or "shutdown.return"? */ /* Shutdown UPS */ if (!strcasecmp(cmdname, "shutdown.stayoff")) { /* If the UPS is on battery, it should shut down * about 30 seconds after receiving this packet. */ /* Not "const" because this mismatches arg type * of usb_interrupt_write() */ char shutdown_packet[SHUTDOWN_PACKETSIZE] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; int ret; upslogx(LOG_DEBUG, "%s: attempting to call usb_interrupt_write(01 00 00 00 00 00 00 00)", __func__); upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ret = usb_interrupt_write(udev, SHUTDOWN_ENDPOINT, (usb_ctrl_charbuf)shutdown_packet, SHUTDOWN_PACKETSIZE, ATCL_USB_TIMEOUT); if (ret <= 0) { upslogx(LOG_NOTICE, "%s: first usb_interrupt_write() failed: %s", __func__, ret ? nut_usb_strerror(ret) : "timeout"); } /* Totally guessing from the .pcap file here. * TODO: configurable delay? */ usleep(170*1000); ret = usb_interrupt_write(udev, SHUTDOWN_ENDPOINT, (usb_ctrl_charbuf)shutdown_packet, SHUTDOWN_PACKETSIZE, ATCL_USB_TIMEOUT); if (ret <= 0) { upslogx(LOG_ERR, "%s: second usb_interrupt_write() failed: %s", __func__, ret ? nut_usb_strerror(ret) : "timeout"); } return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* FIXME: Check with the device what our instcmd * (nee upsdrv_shutdown() contents) actually does! */ int ret = do_loop_shutdown_commands("shutdown.stayoff", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } void upsdrv_help(void) { } void upsdrv_makevartable(void) { /* NOTE: This driver uses a very custom device matching method, * so does not involve nut_usb_addvars() method like others do. * When fixing, see also tools/nut-scanner/scan_usb.c "exceptions". */ addvar(VAR_VALUE, "vendor", "USB vendor string (or NULL if none)"); } nut-2.8.4/drivers/apcupsd-ups.c0000644000175000017500000002241215044656702013354 00000000000000/* apcupsd-ups.c - client for apcupsd This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #ifndef WIN32 #include #include #include #include #else /* WIN32 */ #include "wincompat.h" #endif /* WIN32 */ #ifdef HAVE_POLL_H # include /* nfds_t */ #else typedef unsigned long int nfds_t; # ifndef POLLRDNORM # define POLLRDNORM 0x0100 # endif # ifndef POLLRDBAND # define POLLRDBAND 0x0200 # endif # ifndef POLLIN # define POLLIN (POLLRDNORM | POLLRDBAND) # endif # if ! HAVE_STRUCT_POLLFD typedef struct pollfd { SOCKET fd; short events; short revents; } pollfd_t; # define HAVE_STRUCT_POLLFD 1 # endif #endif /* !HAVE_POLL_H */ #include "main.h" #include "apcupsd-ups.h" #include "attribute.h" #include "nut_stdint.h" #define DRIVER_NAME "apcupsd network client UPS driver" #define DRIVER_VERSION "0.73" #define POLL_INTERVAL_MIN 10 /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Andreas Steinmetz ", DRV_STABLE, { NULL } }; static uint16_t port=3551; static struct sockaddr_in host; static void process(char *item,char *data) { int i; char *p1; char *p2; for(i=0;nut_data[i].info_type;i++)if(!(nut_data[i].apcupsd_item)) dstate_setinfo(nut_data[i].info_type,"%s", nut_data[i].default_value); else if(!strcmp(nut_data[i].apcupsd_item,item)) switch(nut_data[i].drv_flags&~DU_FLAG_INIT) { case DU_FLAG_STATUS: status_init(); if(!strcmp(data,"COMMLOST")||!strcmp(data,"NETWORK ERROR")|| !strcmp(data,"ERROR"))status_set("OFF"); else if(!strcmp(data,"SELFTEST"))status_set("OB"); else for(;(data=strtok(data," "));data=NULL) { if(!strcmp(data,"CAL"))status_set("CAL"); else if(!strcmp(data,"TRIM"))status_set("TRIM"); else if(!strcmp(data,"BOOST"))status_set("BOOST"); else if(!strcmp(data,"ONLINE"))status_set("OL"); else if(!strcmp(data,"ONBATT"))status_set("OB"); else if(!strcmp(data,"OVERLOAD"))status_set("OVER"); else if(!strcmp(data,"SHUTTING DOWN")|| !strcmp(data,"LOWBATT"))status_set("LB"); else if(!strcmp(data,"REPLACEBATT"))status_set("RB"); else if(!strcmp(data,"NOBATT"))status_set("BYPASS"); } status_commit(); break; case DU_FLAG_DATE: if((p1=strchr(data,' '))) { *p1=0; dstate_setinfo(nut_data[i].info_type,"%s",data); *p1=' '; } else dstate_setinfo(nut_data[i].info_type,"%s",data); break; case DU_FLAG_TIME: if((p1=strchr(data,' '))) { *p1=0; if((p2=strchr(p1+1,' '))) { *p2=0; dstate_setinfo(nut_data[i].info_type,"%s",p1+1); *p2=' '; } else dstate_setinfo(nut_data[i].info_type,"%s",p1+1); *p1=' '; } break; case DU_FLAG_FW1: if((p1=strchr(data,'/'))) { for(;p1!=data;p1--)if(p1[-1]!=' ')break; if(*p1==' ') { *p1=0; dstate_setinfo(nut_data[i].info_type,"%s",data); *p1=' '; } else dstate_setinfo(nut_data[i].info_type,"%s",data); } else dstate_setinfo(nut_data[i].info_type,"%s",data); break; case DU_FLAG_FW2: if((p1=strchr(data,'/'))) { for(;*p1;p1++)if(p1[1]!=' ')break; if(*p1&&p1[1])dstate_setinfo(nut_data[i].info_type,"%s", p1+1); } break; default:if(nut_data[i].info_flags&ST_FLAG_STRING) { if((int)strlen(data)>(int)nut_data[i].info_len) data[(int)nut_data[i].info_len]=0; dstate_setinfo(nut_data[i].info_type,"%s",data); } else { /* default_value acts as a format string in this case */ dstate_setinfo_dynamic(nut_data[i].info_type, nut_data[i].default_value, "%f", atof(data)*nut_data[i].info_len); } break; } } static int getdata(void) { ssize_t x; uint16_t n; char *item; char *data; struct pollfd p; char bfr[1024]; st_tree_timespec_t start; int ret = -1; #ifndef WIN32 int fd_flags; #else /* WIN32 */ /* Note: while the code below uses "pollfd" for simplicity as it is * available in mingw headers (although poll() method usually is not), * WIN32 builds use WaitForMultipleObjects(); see also similar code * in upsd.c for networking. */ HANDLE event = NULL; #endif /* WIN32 */ state_get_timestamp((st_tree_timespec_t *)&start); if (INVALID_FD_SOCK( (p.fd = socket(AF_INET, SOCK_STREAM, 0)) )) { upsdebugx(1,"socket error"); /* return -1; */ ret = -1; goto getdata_return; } if(connect(p.fd,(struct sockaddr *)&host,sizeof(host))) { upsdebugx(1,"can't connect to apcupsd"); /* close(p.fd); return -1; */ ret = -1; goto getdata_return; } #ifndef WIN32 /* WSAEventSelect automatically sets the socket to nonblocking mode */ fd_flags = fcntl(p.fd, F_GETFL); if (fd_flags == -1) { upsdebugx(1,"unexpected fcntl(fd, F_GETFL) failure"); /* close(p.fd); return -1; */ ret = -1; goto getdata_return; } fd_flags |= O_NONBLOCK; if(fcntl(p.fd, F_SETFL, fd_flags) == -1) { upsdebugx(1,"unexpected fcntl(fd, F_SETFL, fd_flags|O_NONBLOCK) failure"); /* close(p.fd); return -1; */ ret = -1; goto getdata_return; } #else /* WIN32 */ event = CreateEvent( NULL, /* Security */ FALSE, /* auto-reset */ FALSE, /* initial state */ NULL); /* no name */ /* Associate socket event to the socket via its Event object */ WSAEventSelect( p.fd, event, FD_CONNECT ); #endif /* WIN32 */ p.events=POLLIN; n=htons(6); x=write(p.fd,&n,2); x=write(p.fd,"status",6); /* TODO: double-check for poll() in configure script */ #ifndef WIN32 while(poll(&p,1,15000)==1) #else /* WIN32 */ while (WaitForMultipleObjects(1, &event, FALSE, 15000) == WAIT_TIMEOUT) #endif /* WIN32 */ { if(read(p.fd,&n,2)!=2) { upsdebugx(1,"apcupsd communication error"); ret = -1; goto getdata_return; } if(!(x=ntohs(n))) { ret = 0; goto getdata_return; } else if(x<0||x>=(int)sizeof(bfr)) /* Note: LGTM.com suggests "Comparison is always false because x >= 0" * for the line above, probably because ntohs() returns an uint type. * I am reluctant to fix this one, because googling for headers from * random OSes showed various types used as the return value (uint16_t, * unsigned_short, u_short, in_port_t...) */ { upsdebugx(1,"apcupsd communication error"); ret = -1; goto getdata_return; } #ifndef WIN32 if(poll(&p,1,15000)!=1)break; #else /* WIN32 */ if (WaitForMultipleObjects(1, &event, FALSE, 15000) != WAIT_OBJECT_0) break; #endif /* WIN32 */ if(read(p.fd,bfr,(size_t)x)!=x) { upsdebugx(1,"apcupsd communication error"); ret = -1; goto getdata_return; } bfr[x]=0; if(!(item=strtok(bfr," \t:\r\n"))) { upsdebugx(1,"apcupsd communication error"); ret = -1; goto getdata_return; } if(!(data=strtok(NULL,"\r\n"))) { upsdebugx(1,"apcupsd communication error"); ret = -1; goto getdata_return; } while(*data==' '||*data=='\t'||*data==':')data++; process(item,data); } upsdebugx(1,"unexpected connection close by apcupsd"); ret = -1; getdata_return: if (VALID_FD_SOCK(p.fd)) close(p.fd); #ifdef WIN32 if (event != NULL) CloseHandle(event); #endif /* WIN32 */ /* Remove any unprotected entries not refreshed in this run */ for(x=0;nut_data[x].info_type;x++) if(!(nut_data[x].drv_flags & DU_FLAG_INIT) && !(nut_data[x].drv_flags & DU_FLAG_PRESERVE)) dstate_delinfo_olderthan(nut_data[x].info_type, &start); return ret; } void upsdrv_initinfo(void) { if(!port)fatalx(EXIT_FAILURE,"invalid host or port specified!"); if(getdata())fatalx(EXIT_FAILURE,"can't communicate with apcupsd!"); else dstate_dataok(); poll_interval = (poll_interval < POLL_INTERVAL_MIN) ? POLL_INTERVAL_MIN : poll_interval; } void upsdrv_updateinfo(void) { if(getdata())upslogx(LOG_ERR,"can't communicate with apcupsd!"); else dstate_dataok(); poll_interval = (poll_interval < POLL_INTERVAL_MIN) ? POLL_INTERVAL_MIN : poll_interval; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_help(void) { } void upsdrv_makevartable(void) { } void upsdrv_initups(void) { char *p; struct hostent *h; #ifdef WIN32 WSADATA WSAdata; WSAStartup(2,&WSAdata); atexit((void(*)(void))WSACleanup); #endif /* WIN32 */ if(device_path&&*device_path) { /* TODO: fix parsing since bare IPv6 addresses contain colons */ if((p=strchr(device_path,':'))) { int i; *p++=0; i=atoi(p); if(i<1||i>65535)i=0; port = (uint16_t)i; } } else device_path="localhost"; if(!(h=gethostbyname(device_path)))port=0; else memcpy(&host.sin_addr,h->h_addr,4); /* TODO: add IPv6 support */ host.sin_family=AF_INET; host.sin_port=htons(port); } void upsdrv_cleanup(void) { } nut-2.8.4/drivers/libhid.h0000664000175000017500000001343215000733176012345 00000000000000/*! * @file libhid.h * @brief NUT HID Library - User API * * @author Copyright (C) 2003 - 2007 * Arnaud Quette && * Charles Lepple * Peter Selinger * Arjen de Korte * * This program is sponsored by MGE UPS SYSTEMS - opensource.mgeups.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * -------------------------------------------------------------------------- */ #ifndef NUT_LIBHID_H_SEEN #define NUT_LIBHID_H_SEEN 1 /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif #include #include "nut_stdint.h" #include "hidtypes.h" #include "timehead.h" #if (defined SHUT_MODE) && SHUT_MODE # include "libshut.h" typedef SHUTDevice_t HIDDevice_t; typedef char HIDDeviceMatcher_t; typedef usb_dev_handle hid_dev_handle_t; typedef shut_communication_subdriver_t communication_subdriver_t; # define HID_DEV_HANDLE_CLOSED (hid_dev_handle_t)(ERROR_FD_SER) #else /* !SHUT_MODE => USB */ # include "nut_libusb.h" /* includes usb-common.h */ typedef USBDevice_t HIDDevice_t; typedef USBDeviceMatcher_t HIDDeviceMatcher_t; typedef usb_dev_handle * hid_dev_handle_t; typedef usb_communication_subdriver_t communication_subdriver_t; # define HID_DEV_HANDLE_CLOSED (hid_dev_handle_t)(NULL) #endif /* SHUT_MODE / USB */ /* use explicit booleans */ #ifndef FALSE typedef enum ebool { FALSE, TRUE } bool_t; #else typedef int bool_t; #endif /* Device open modes */ #define MODE_OPEN 0 /* open a HID device for the first time */ #define MODE_REOPEN 1 /* reopen a HID device that was opened before */ #define MAX_TS 2 /* validity period of a gotten report (2 sec) */ /* ---------------------------------------------------------------------- */ /* structure to describe an item in a usage table */ typedef struct { const char *usage_name; const HIDNode_t usage_code; } usage_lkp_t; extern usage_lkp_t hid_usage_lkp[]; /* an object of type usage_tables_t is a NULL-terminated array of * pointers to individual usage tables. */ typedef usage_lkp_t *usage_tables_t; extern communication_subdriver_t *comm_driver; extern HIDDesc_t *pDesc; /* parsed Report Descriptor */ /* report buffer structure: holds data about most recent report for each given report id */ typedef struct reportbuf_s { time_t ts[256]; /* timestamp when report was retrieved */ size_t len[256]; /* size of report data */ unsigned char *data[256]; /* report data (allocated) */ } reportbuf_t; extern reportbuf_t *reportbuf; /* buffer for most recent reports */ extern size_t max_report_size; extern int interrupt_only; extern size_t interrupt_size; /* ---------------------------------------------------------------------- */ /* * HIDGetItemValue * -------------------------------------------------------------------------- */ int HIDGetItemValue(hid_dev_handle_t udev, const char *hidpath, double *Value, usage_tables_t *utab); /* * HIDGetItemString * -------------------------------------------------------------------------- */ char *HIDGetItemString(hid_dev_handle_t udev, const char *hidpath, char *buf, size_t buflen, usage_tables_t *utab); /* * HIDSetItemValue * -------------------------------------------------------------------------- */ bool_t HIDSetItemValue(hid_dev_handle_t udev, const char *hidpath, double value, usage_tables_t *utab); /* * GetItemData * -------------------------------------------------------------------------- */ HIDData_t *HIDGetItemData(const char *hidpath, usage_tables_t *utab); /* * GetDataItem * -------------------------------------------------------------------------- */ char *HIDGetDataItem(const HIDData_t *hiddata, usage_tables_t *utab); /* * HIDGetDataValue * -------------------------------------------------------------------------- */ int HIDGetDataValue(hid_dev_handle_t udev, HIDData_t *hiddata, double *Value, time_t age); /* * HIDSetDataValue * -------------------------------------------------------------------------- */ int HIDSetDataValue(hid_dev_handle_t udev, HIDData_t *hiddata, double Value); /* * HIDGetIndexString * -------------------------------------------------------------------------- */ char *HIDGetIndexString(hid_dev_handle_t udev, int Index, char *buf, size_t buflen); /* * HIDGetEvents * -------------------------------------------------------------------------- */ int HIDGetEvents(hid_dev_handle_t udev, HIDData_t **event, int eventlen); /* * Support functions * -------------------------------------------------------------------------- */ void HIDDumpTree(hid_dev_handle_t udev, HIDDevice_t *hd, usage_tables_t *utab); const char *HIDDataType(const HIDData_t *hiddata); void free_report_buffer(reportbuf_t *rbuf); reportbuf_t *new_report_buffer(HIDDesc_t *pDesc); #endif /* NUT_LIBHID_H_SEEN */ nut-2.8.4/drivers/common_voltronic-crc.h0000644000175000017500000001566015044656702015260 00000000000000/* common_voltronic-crc.h - Common CRC routines for Voltronic Power devices * * Copyright (C) * 2014 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef COMMON_VOLTRONIC_CRC_H #define COMMON_VOLTRONIC_CRC_H /* NOTE * ---- * The provided functions implement a simple 2-bytes non-reflected CRC (polynomial: 0x1021) as used in some Voltronic Power devices (LF, CR and '(' are 'escaped'). * * Apart from the basic functions (that require you to know the exact length, *len*, of what you feed them) to compute CRC and check whether a given byte array, *input*, is CRC-valid or not, some helper functions are provided, that automagically calculate the length of the part of a given *input* (of max size *inputlen*) to be used. * When using one of these functions (that, having been developed to work with Voltronic Power devices, expect a CR-terminated string), take into consideration that: * - *input* is considered first as a CR-terminated byte array that may contain inner '\0's and its length is calculated till the position of the expected CR; * - if a CR cannot be found, then, and only then, *input* is considered as a null-terminated byte string and its length calculated accordingly. * Therefore, the presence of one (or more) CR automatically: * - discards whatever stands after (the first CR); * - includes whatever stands before (the first CR). * So, as a CR takes precedence, if you know *input* is not (or may be not) CR-terminated, make sure the remaining bytes after the end of the string till *inputlen*-length are all 0'ed (or at least don't contain any CR), if you don't want to risk them being included. * Also, if you know *input* may contain inner CRs, you better use one of the functions that don't try to guess the part of *input* to be used and cook up instead your own routines using only the provided basic functions to compute and check CRC. * * Don't forget, too, that CRC may contain a '\0' and hence null-terminated strings will be fooled. */ #include /* Compute CRC of a given *input* till the length of *len* bytes. * Return: * - the CRC computed from *len* bytes of *input*. */ unsigned short common_voltronic_crc_compute(const char *input, const size_t len); /* Compute CRC (till the first CR, if any, or till the end of the string) of *input* (of max size *inputlen*). * Please note that *input* must be: * - at least 1 byte long (not counting the optional trailing CR and the terminating '\0' byte); * - either a valid null-terminated byte string or CR-terminated. * Return: * - -1, on failure (i.e: *input* not fulfilling the aforementioned conditions); * - the CRC computed from *input*, on success. */ unsigned short common_voltronic_crc_calc(const char *input, const size_t inputlen); /* Compute CRC (till the first CR, if any, or till the end of the string) of *input* (of max size *inputlen*), then write to *output* (of max size *outputlen*): * - *input* (minus the trailing CR, if any); * - the computed 2-bytes CRC; * - a trailing CR (if present in *input*). * Please note that: * - *input* must be at least 1 byte long (not counting the optional trailing CR and the terminating '\0' byte) and either be a valid null-terminated byte string or CR-terminated; * - *output* must have space, to accomodate the computed 2-bytes CRC, for at least 2 bytes more (not counting the trailing, reserved, byte for the terminating '\0') than the actually used size of *input*. * Return: * - -1, on failure (i.e: either *input* or *output* not fulfilling the aforementioned conditions); * - the number of bytes written to *output*, on success. */ int common_voltronic_crc_calc_and_add(const char *input, const size_t inputlen, char *output, const size_t outputlen); /* Compute CRC (till the first CR, if any, or till the end of the string) of *input* (of max size *inputlen*), then add to it the computed 2-bytes CRC (before the trailing CR, if present). * Please note that *input* must: * - be at least 1 byte long (not counting the optional trailing CR and the terminating '\0' byte); * - either be a valid null-terminated byte string or CR-terminated; * - have space, to accomodate the computed 2-bytes CRC, for at least 2 bytes more (not counting the trailing, reserved, byte for the terminating '\0') than the actually used size. * Return: * - -1, on failure (i.e: *input* not fulfilling the aforementioned conditions); * - the number of bytes that make up the modified *input*, on success. */ int common_voltronic_crc_calc_and_add_m(char *input, const size_t inputlen); /* Check *input* (of max size *inputlen*) CRC. * Please note that *input* must be: * - at least 3 bytes long (not counting the optional trailing CR and the terminating '\0' byte); * - either a valid null-terminated byte string or CR-terminated. * Return: * - -1, on failure (i.e: *input* not fulfilling the aforementioned conditions or not CRC-validated); * - 0, on success (i.e.: *input* successfully validated). */ int common_voltronic_crc_check(const char *input, const size_t inputlen); /* Check *input* (of max size *inputlen*) CRC and copy *input*, purged of the CRC, to *output* (of max size *outputlen*). * Please note that: * - *input* must be at least 3 bytes long (not counting the optional trailing CR and the terminating '\0' byte) and either be a valid null-terminated byte string or CR-terminated; * - *output* must have space for at least 2 bytes less (not counting the trailing, reserved, byte for the terminating '\0') than the actually used size of *input*. * Return: * - -1, on failure (i.e: either *input* or *output* not fulfilling the aforementioned conditions or *input* not CRC-validated); * - the number of bytes written to *output*, on success. */ int common_voltronic_crc_check_and_remove(const char *input, const size_t inputlen, char *output, const size_t outputlen); /* Check *input* (of max size *inputlen*) CRC and remove it from *input*. * Please note that *input* must be: * - at least 3 bytes long (not counting the optional trailing CR and the terminating '\0' byte); * - either a valid null-terminated byte string or CR-terminated. * Return: * - -1, on failure; * - the number of bytes that make up the modified *input*, on success. */ int common_voltronic_crc_check_and_remove_m(char *input, const size_t inputlen); #endif /* COMMON_VOLTRONIC_CRC_H */ nut-2.8.4/drivers/explore-hid.h0000644000175000017500000000174214670526611013337 00000000000000/* explore-hid.h - this is a "stub" subdriver used to collect data * about HID UPS systems that are not yet supported. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef EXPLORE_HID_H #define EXPLORE_HID_H #include "usbhid-ups.h" extern subdriver_t explore_subdriver; #endif /* EXPLORE_HID_H */ nut-2.8.4/drivers/eaton-pdu-marlin-mib.c0000644000175000017500000017054715044656702015046 00000000000000/* eaton-pdu-marlin-mib.c - data to monitor Eaton ePDUs branded as: * G2 Marlin SW / MI / MO / MA * G3 Shark SW / MI / MO / MA * * Copyright (C) 2008 - 2020 * Arnaud Quette * Arnaud Quette * Copyright (C) 2015 - 2017 * Jim Klimov * * Supported by Eaton * and previously MGE Office Protection Systems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "eaton-pdu-marlin-mib.h" #if WITH_SNMP_LKP_FUN #include "eaton-pdu-marlin-helpers.h" #endif /* Eaton PDU-MIB - Marlin MIB * ************************** */ #define EATON_MARLIN_MIB_VERSION "0.69" #define EATON_MARLIN_SYSOID ".1.3.6.1.4.1.534.6.6.7" #define EATON_MARLIN_OID_MODEL_NAME ".1.3.6.1.4.1.534.6.6.7.1.2.1.2.0" static info_lkp_t marlin_outlet_status_info[] = { info_lkp_default(0, "off"), info_lkp_default(1, "on"), info_lkp_default(2, "pendingOff"), /* transitional status */ info_lkp_default(3, "pendingOn"), /* transitional status */ info_lkp_sentinel }; static info_lkp_t marlin_outletgroups_status_info[] = { info_lkp_default(0, "off"), info_lkp_default(1, "on"), info_lkp_default(2, "rebooting"), /* transitional status */ info_lkp_default(3, "mixed"), /* transitional status, not sure what it means! */ info_lkp_sentinel }; /* Ugly hack for older G2 ePDU: * having the matching OID present means that the outlet/unit is * switchable. So, it should not require this value lookup */ static info_lkp_t g2_unit_outlet_switchability_info[] = { info_lkp_default(-1, "yes"), info_lkp_default(0, "yes"), info_lkp_sentinel }; static info_lkp_t marlin_outlet_switchability_info[] = { info_lkp_default(1, "yes"), /* switchable */ info_lkp_default(2, "no"), /* notSwitchable */ info_lkp_sentinel }; /* Overall outlets switchability info for the unit. * This is refined per-outlet, depending on user configuration, * possibly disabling switchability of some outlets */ static info_lkp_t marlin_unit_switchability_info[] = { info_lkp_default(0, "no"), /* unknown */ info_lkp_default(1, "yes"), /* switched */ info_lkp_default(2, "no"), /* advancedMonitored */ info_lkp_default(3, "yes"), /* managed */ info_lkp_default(4, "no"), /* monitored */ info_lkp_sentinel }; /* The physical type of outlet */ static info_lkp_t marlin_outlet_type_info[] = { info_lkp_default(0, "unknown"), info_lkp_default(1, "iecC13"), info_lkp_default(2, "iecC19"), info_lkp_default(10, "uk"), info_lkp_default(11, "french"), info_lkp_default(12, "schuko"), info_lkp_default(20, "nema515"), info_lkp_default(21, "nema51520"), info_lkp_default(22, "nema520"), info_lkp_default(23, "nemaL520"), info_lkp_default(24, "nemaL530"), info_lkp_default(25, "nema615"), info_lkp_default(26, "nema620"), info_lkp_default(27, "nemaL620"), info_lkp_default(28, "nemaL630"), info_lkp_default(29, "nemaL715"), info_lkp_default(30, "rf203p277"), info_lkp_sentinel }; static info_lkp_t marlin_ambient_presence_info[] = { info_lkp_default(-1, "unknown"), info_lkp_default(0, "no"), /* disconnected */ info_lkp_default(1, "yes"), /* connected */ info_lkp_sentinel }; static info_lkp_t marlin_emp002_ambient_presence_info[] = { info_lkp_default(0, "unknown"), info_lkp_default(2, "yes"), /* communicationOK */ info_lkp_default(3, "no"), /* communicationLost */ info_lkp_sentinel }; static info_lkp_t marlin_threshold_status_info[] = { info_lkp_default(0, "good"), /* No threshold triggered */ info_lkp_default(1, "warning-low"), /* Warning low threshold triggered */ info_lkp_default(2, "critical-low"), /* Critical low threshold triggered */ info_lkp_default(3, "warning-high"), /* Warning high threshold triggered */ info_lkp_default(4, "critical-high"), /* Critical high threshold triggered */ info_lkp_sentinel }; static info_lkp_t marlin_threshold_frequency_status_info[] = { info_lkp_default(0, "good"), /* No threshold triggered */ info_lkp_default(1, "out-of-range"), /* Frequency out of range triggered */ info_lkp_sentinel }; static info_lkp_t marlin_ambient_drycontacts_info[] = { info_lkp_default(-1, "unknown"), info_lkp_default(0, "opened"), info_lkp_default(1, "closed"), info_lkp_sentinel }; static info_lkp_t marlin_threshold_voltage_alarms_info[] = { info_lkp_default(0, ""), /* No threshold triggered */ info_lkp_default(1, "low voltage warning!"), /* Warning low threshold triggered */ info_lkp_default(2, "low voltage critical!"), /* Critical low threshold triggered */ info_lkp_default(3, "high voltage warning!"), /* Warning high threshold triggered */ info_lkp_default(4, "high voltage critical!"), /* Critical high threshold triggered */ info_lkp_sentinel }; static info_lkp_t marlin_threshold_current_alarms_info[] = { info_lkp_default(0, ""), /* No threshold triggered */ info_lkp_default(1, "low current warning!"), /* Warning low threshold triggered */ info_lkp_default(2, "low current critical!"), /* Critical low threshold triggered */ info_lkp_default(3, "high current warning!"), /* Warning high threshold triggered */ info_lkp_default(4, "high current critical!"), /* Critical high threshold triggered */ info_lkp_sentinel }; static info_lkp_t marlin_threshold_frequency_alarm_info[] = { info_lkp_default(0, ""), /* No threshold triggered */ info_lkp_default(1, "frequency out of range!"), /* Frequency out of range triggered */ info_lkp_sentinel }; static info_lkp_t marlin_threshold_temperature_alarms_info[] = { info_lkp_default(0, ""), /* No threshold triggered */ info_lkp_default(1, "low temperature warning!"), /* Warning low threshold triggered */ info_lkp_default(2, "low temperature critical!"), /* Critical low threshold triggered */ info_lkp_default(3, "high temperature warning!"), /* Warning high threshold triggered */ info_lkp_default(4, "high temperature critical!"), /* Critical high threshold triggered */ info_lkp_sentinel }; static info_lkp_t marlin_threshold_humidity_alarms_info[] = { info_lkp_default(0, ""), /* No threshold triggered */ info_lkp_default(1, "low humidity warning!"), /* Warning low threshold triggered */ info_lkp_default(2, "low humidity critical!"), /* Critical low threshold triggered */ info_lkp_default(3, "high humidity warning!"), /* Warning high threshold triggered */ info_lkp_default(4, "high humidity critical!"), /* Critical high threshold triggered */ info_lkp_sentinel }; static info_lkp_t marlin_outlet_group_type_info[] = { info_lkp_default(0, "unknown"), info_lkp_default(1, "breaker1pole"), info_lkp_default(2, "breaker2pole"), info_lkp_default(3, "breaker3pole"), info_lkp_default(4, "outlet-section"), info_lkp_default(5, "user-defined"), info_lkp_sentinel }; static info_lkp_t marlin_input_type_info[] = { info_lkp_default(1, "1"), /* singlePhase */ info_lkp_default(2, "2"), /* splitPhase */ info_lkp_default(3, "3"), /* threePhaseDelta */ info_lkp_default(4, "3"), /* threePhaseWye */ info_lkp_sentinel }; static info_lkp_t marlin_outlet_group_phase_info[] = { info_lkp_default(0, "unknown"), /* unknown */ info_lkp_default(1, "1"), /* singlePhase */ info_lkp_default(2, "1-N"), /* phase1toN */ info_lkp_default(3, "2-N"), /* phase2toN */ info_lkp_default(4, "3-N"), /* phase3toN */ info_lkp_default(5, "1-2"), /* phase1to2 */ info_lkp_default(6, "2-3"), /* phase2to3 */ info_lkp_default(7, "3-1"), /* phase3to1 */ info_lkp_sentinel }; #if WITH_SNMP_LKP_FUN /* Note: eaton_sensor_temperature_unit_fun() is defined in eaton-pdu-marlin-helpers.c * and su_temperature_read_fun() is in snmp-ups.c * Future work for DMF might provide same-named routines via LUA-C gateway. */ # if WITH_SNMP_LKP_FUN_DUMMY /* Temperature unit consideration */ const char *eaton_sensor_temperature_unit_fun(void *raw_snmp_value) { /* snmp_value here would be a (long*) */ NUT_UNUSED_VARIABLE(raw_snmp_value); return "unknown"; } /* FIXME: please DMF, though this should be in snmp-ups.c or equiv. */ const char *su_temperature_read_fun(void *raw_snmp_value) { /* snmp_value here would be a (long*) */ NUT_UNUSED_VARIABLE(raw_snmp_value); return "dummy"; } # endif /* WITH_SNMP_LKP_FUN_DUMMY */ static info_lkp_t eaton_sensor_temperature_unit_info[] = { info_lkp_fun_vp2s(0, "dummy", eaton_sensor_temperature_unit_fun), info_lkp_sentinel }; static info_lkp_t eaton_sensor_temperature_read_info[] = { info_lkp_fun_vp2s(0, "dummy", su_temperature_read_fun), info_lkp_sentinel }; #else /* if not WITH_SNMP_LKP_FUN: */ /* FIXME: For now, DMF codebase falls back to old implementation with static * lookup/mapping tables for this, which can easily go into the DMF XML file. */ static info_lkp_t eaton_sensor_temperature_unit_info[] = { info_lkp_default(0, "kelvin"), info_lkp_default(1, "celsius"), info_lkp_default(2, "fahrenheit"), info_lkp_sentinel }; #endif /* WITH_SNMP_LKP_FUN */ /* Extracted from powerware-mib.c ; try to commonalize */ static info_lkp_t marlin_ambient_drycontacts_polarity_info[] = { info_lkp_default(0, "normal-opened"), info_lkp_default(1, "normal-closed"), info_lkp_sentinel }; static info_lkp_t marlin_ambient_drycontacts_state_info[] = { info_lkp_default(0, "inactive"), info_lkp_default(1, "active"), info_lkp_sentinel }; #if WITH_SNMP_LKP_FUN /* Note: marlin_device_count_fun() is defined in eaton-pdu-marlin-helpers.c * Future work for DMF might provide a same-named routine via LUA-C gateway. */ # if WITH_SNMP_LKP_FUN_DUMMY long marlin_device_count_fun(const char *daisy_dev_list) { NUT_UNUSED_VARIABLE(daisy_dev_list); return 1; } # endif /* WITH_SNMP_LKP_FUN_DUMMY */ static info_lkp_t marlin_device_count_info[] = { /* TOTHINK: DMF branch used info_lkp_fun_s2l()? */ info_lkp_nuf_s2l(1, "dummy", marlin_device_count_fun), info_lkp_sentinel }; #else /* if not WITH_SNMP_LKP_FUN: */ /* FIXME: For now, DMF codebase falls back to old implementation with static * lookup/mapping tables for this, which can easily go into the DMF XML file. */ #endif /* WITH_SNMP_LKP_FUN */ /* Snmp2NUT lookup table for Eaton Marlin MIB */ static snmp_info_t eaton_marlin_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device collection */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "EATON", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.2.%i", "Eaton Powerware ePDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.4.%i", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.part", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.3.%i", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* For daisychain, there is only 1 physical interface! */ snmp_info_default("device.macaddr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.2.1.2.2.1.6.2", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* Daisychained devices support */ /* FIXME : Should this be a static value, or can we expect the amount of * daisy-chained devices to change without restart of the driver by user? * If this is a critical matter, should a detected change of amount of * daisy-chained devices, outlet counts, etc. cause restart/reinit of * this running driver instance? */ #if WITH_SNMP_LKP_FUN /* Number of daisychained units is processed according to present units * in the chain with new G3 firmware (02.00.0051, since autumn 2017): * Take string "unitsPresent" (ex: "0,3,4,5"), and count the amount * of "," separators+1 using an inline function */ /* FIXME: inline func */ snmp_info_default("device.count", 0, 1, ".1.3.6.1.4.1.534.6.6.7.1.1.0", "0", SU_FLAG_STATIC | SU_FLAG_UNIQUE, &marlin_device_count_info[0] /* devices_count */), #endif /* Notes: this older/fallback definition is used to: * - estimate the number of devices, based on the below OID iteration capabilities * - determine the base index of the SNMP OID (ie 0 or 1) */ #if WITH_SNMP_LKP_FUN snmp_info_default("device.count", 0, 1, ".1.3.6.1.4.1.534.6.6.7.1.2.1.2.%i", "1", SU_FLAG_STATIC, NULL /* devices_count */), #else snmp_info_default("device.count", 0, 1, ".1.3.6.1.4.1.534.6.6.7.1.2.1.2.%i", "1", SU_FLAG_STATIC | SU_FLAG_UNIQUE, NULL /* devices_count */), #endif /* UPS collection */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "EATON", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, "1.3.6.1.4.1.534.6.6.7.1.2.1.2.%i", "Eaton Powerware ePDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* FIXME: use unitName.0 (ePDU)? * snmp_info_default("ups.id", ST_FLAG_STRING, SU_INFOSIZE, AR_OID_DEVICE_NAME, "unknown", SU_FLAG_STATIC | SU_FLAG_OK, NULL), */ snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.4.%i", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* FIXME: this entry should be SU_FLAG_SEMI_STATIC */ snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.5.%i", "", SU_FLAG_OK, NULL), snmp_info_default("ups.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /* FIXME: needs a date reformatting callback * 2011-8-29,16:27:25.0,+1:0 * Hex-STRING: 07 DB 08 1D 10 0C 36 00 2B 01 00 00 * snmp_info_default("ups.date", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.8.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), * snmp_info_default("ups.time", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.8.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), */ /* Input collection */ /* Note: a larger ePDU can have several inputs. The "%i" iterators * in key names are currently available for daisychain devs, outlets, * and groups - but not for inputs. These would likely evolve later * to "input.%i.something" with default (non-%i) same as .1 instance. * At this time only a single-input (or first of several inputs) is * supported by this mapping. */ /* Historically, some of these data were previously published as * outlet.{realpower,...} * However, it's more suitable and logic to have these on input.{...} */ /* Note: the below gives the number of input, not the number of phase(s)! */ /* inputCount.0; Value (Integer): 1 snmp_info_default("input.count", 0, 1, ".1.3.6.1.4.1.534.6.6.7.1.2.1.20.0", NULL, SU_FLAG_STATIC, NULL), */ /* Note: for daisychain mode, we must handle phase(s) per device, * not as a whole. In case of daisychain, support of the UNIQUE * field is not yet implemented (FIXME) so the last resolved OID * value wins. If a more-preferable OID is not implemented by device, * this is ok - the previous available value remains in place. */ /* inputType.%i.1 = INTEGER: singlePhase (1) */ snmp_info_default("input.phases", 0, 1, ".1.3.6.1.4.1.534.6.6.7.3.1.1.2.%i.1", NULL, SU_FLAG_STATIC, &marlin_input_type_info[0]), /* Frequency is measured globally */ snmp_info_default("input.frequency", 0, 0.1, ".1.3.6.1.4.1.534.6.6.7.3.1.1.3.%i.1", NULL, 0, NULL), snmp_info_default("input.frequency.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.1.1.4.%i.1", NULL, SU_FLAG_OK, &marlin_threshold_frequency_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.1.1.4.%i.1", NULL, SU_FLAG_OK, &marlin_threshold_frequency_alarm_info[0]), /* inputCurrentPercentLoad (measured globally) * Current percent load, based on the rated current capacity */ /* FIXME: input.load is mapped on input.L1.load for both single and 3phase !!! */ snmp_info_default("input.load", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.3.1.11.%i.1.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L1.load", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.3.1.11.%i.1.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L2.load", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.3.1.11.%i.1.2", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L3.load", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.3.1.11.%i.1.3", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), /* FIXME: * - Voltage is only measured per phase, as mV! * so input.voltage == input.L1.voltage for both single and 3phase * - As per NUT namespace (https://www.networkupstools.org/docs/developer-guide.chunked/apas01.html#_valid_contexts) * Voltage has to be expressed either phase-phase or phase-neutral * This is depending on OID inputVoltageMeasType * INTEGER {singlePhase (1),phase1toN (2),phase2toN (3),phase3toN (4),phase1to2 (5),phase2to3 (6),phase3to1 (7) * => RFC input.Lx.voltage.context */ snmp_info_default("input.voltage", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.3.%i.1.1", NULL, 0, NULL), snmp_info_default("input.voltage.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_voltage_alarms_info[0]), snmp_info_default("input.voltage.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.5.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.voltage.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.6.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.voltage.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.7.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.voltage.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.8.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.voltage", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.3.%i.1.1", NULL, 0, NULL), snmp_info_default("input.L1.voltage.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("L1.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_voltage_alarms_info[0]), snmp_info_default("input.L1.voltage.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.5.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.voltage.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.6.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.voltage.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.7.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.voltage.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.8.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.voltage", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.3.%i.1.2", NULL, 0, NULL), snmp_info_default("input.L2.voltage.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.2", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("L2.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.2", NULL, SU_FLAG_OK, &marlin_threshold_voltage_alarms_info[0]), snmp_info_default("input.L2.voltage.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.5.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.voltage.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.6.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.voltage.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.7.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.voltage.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.8.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.voltage", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.3.%i.1.3", NULL, 0, NULL), snmp_info_default("input.L3.voltage.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.3", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("L3.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.2.1.4.%i.1.3", NULL, SU_FLAG_OK, &marlin_threshold_voltage_alarms_info[0]), snmp_info_default("input.L3.voltage.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.5.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.voltage.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.6.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.voltage.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.7.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.voltage.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.8.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), /* FIXME: * - input.current is mapped on input.L1.current for both single and 3phase !!! */ snmp_info_default("input.current", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.4.%i.1.1", NULL, 0, NULL), snmp_info_default("input.current.nominal", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.3.%i.1.1", NULL, 0, NULL), snmp_info_default("input.current.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_current_alarms_info[0]), snmp_info_default("input.current.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.6.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.current.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.7.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.current.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.8.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.current.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.9.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.current", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.4.0.1.1", NULL, 0, NULL), snmp_info_default("input.L1.current.nominal", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.3.%i.1.1", NULL, 0, NULL), snmp_info_default("input.L1.current.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("L1.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.1", NULL, SU_FLAG_OK, &marlin_threshold_current_alarms_info[0]), snmp_info_default("input.L1.current.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.6.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.current.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.7.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.current.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.8.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L1.current.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.9.%i.1.1", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.current", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.4.%i.1.2", NULL, 0, NULL), snmp_info_default("input.L2.current.nominal", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.3.%i.1.2", NULL, 0, NULL), snmp_info_default("input.L2.current.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.2", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("L2.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.2", NULL, SU_FLAG_OK, &marlin_threshold_current_alarms_info[0]), snmp_info_default("input.L2.current.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.6.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.current.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.7.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.current.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.8.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L2.current.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.9.%i.1.2", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.current", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.4.%i.1.3", NULL, 0, NULL), snmp_info_default("input.L3.current.nominal", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.3.%i.1.3", NULL, 0, NULL), snmp_info_default("input.L3.current.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.3", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("L3.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.3.1.5.%i.1.3", NULL, SU_FLAG_OK, &marlin_threshold_current_alarms_info[0]), snmp_info_default("input.L3.current.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.6.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.current.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.7.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.current.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.8.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("input.L3.current.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.3.1.9.%i.1.3", NULL, SU_FLAG_NEGINVALID, NULL), /* Sum of all phases realpower, valid for Shark 1ph/3ph only */ snmp_info_default("input.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.5.1.4.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_UNIQUE | SU_FLAG_OK, NULL), /* Fallback 1: Sum of all phases realpower, valid for Marlin 3ph only */ snmp_info_default("input.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.4.%i.1.4", NULL, SU_FLAG_NEGINVALID | SU_FLAG_UNIQUE | SU_FLAG_OK, NULL), /* Fallback 2: Sum of the phase realpower, valid for Marlin 1ph only */ snmp_info_default("input.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.4.%i.1.2", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L1.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.4.%i.1.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L2.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.4.%i.1.2", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L3.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.4.%i.1.3", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), /* Sum of all phases apparent power, valid for Shark 1ph/3ph only */ snmp_info_default("input.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.5.1.3.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_UNIQUE | SU_FLAG_OK, NULL), /* Fallback 1: Sum of all phases realpower, valid for Marlin 3ph only */ snmp_info_default("input.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.3.%i.1.4", NULL, SU_FLAG_NEGINVALID | SU_FLAG_UNIQUE | SU_FLAG_OK, NULL), /* Fallback 2: Sum of the phase realpower, valid for Marlin 1ph only */ snmp_info_default("input.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.3.%i.1.2", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L1.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.3.%i.1.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L2.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.3.%i.1.2", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("input.L3.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.3.%i.1.3", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), /* Input feed: a feed (A or B) is tied to an input, and this * sub-collection describes the properties of an actual cable. */ /* FIXME: RFC on key name is needed when backporting to NUT upstream ; check type (number? string?) and flags */ /* snmp_info_default("input.feed.%i.id", 0, 1, "???.%i.%i", NULL, SU_FLAG_NEGINVALID, NULL), */ /* Feed name(s) of the ePDU power input(s), can be set by user (FIXME: rename to .desc?) * inputFeedName.0.1 = Value (OctetString): Feed A */ /* FIXME: SU_FLAG_SEMI_STATIC or SU_FLAG_SETTING => refreshed from time to time or upon call to setvar */ /* snmp_info_default("input.%i.feed.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.1.1.10.%i.%i", NULL, SU_FLAG_SEMI_STATIC | SU_FLAG_OK | SU_TYPE_DAISY_1, NULL), */ snmp_info_default("input.feed.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.3.1.1.10.%i.1", NULL, SU_FLAG_SEMI_STATIC | SU_FLAG_OK | SU_TYPE_DAISY_1, NULL), /* Feed color (integer RGB) * inputFeedColor.0.1 = Gauge32: 0 (black) */ /* FIXME: RFC on key name is needed when backporting to NUT upstream */ /* snmp_info_default("input.%i.feed.color", 0, 1, ".1.3.6.1.4.1.534.6.6.7.3.1.1.9.%i.%i", NULL, SU_FLAG_STATIC | SU_FLAG_OK | SU_TYPE_DAISY_1, NULL), */ snmp_info_default("input.feed.color", 0, 1, ".1.3.6.1.4.1.534.6.6.7.3.1.1.9.%i.1", NULL, SU_FLAG_SEMI_STATIC | SU_FLAG_OK | SU_TYPE_DAISY_1, NULL), /* inputPowerCapacity.0.1 = INTEGER: 2300 */ /* FIXME: RFC on key name is needed when backporting to NUT upstream */ snmp_info_default("input.realpower.nominal", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.5.1.9.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), /* Ambient collection */ /* EMP001 (legacy) mapping */ /* Note: this is still published, beside from the new daisychained version! */ snmp_info_default("ambient.present", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.7.1.1.3.%i.1", NULL, SU_FLAG_OK, &marlin_ambient_presence_info[0]), snmp_info_default("ambient.temperature.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.7.1.1.5.%i.1", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.7.1.1.5.%i.1", NULL, SU_FLAG_OK, &marlin_threshold_temperature_alarms_info[0]), snmp_info_default("ambient.temperature", 0, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.1.1.4.%i.1", NULL, SU_FLAG_OK, NULL), /* Low and high threshold use the respective critical levels */ snmp_info_default("ambient.temperature.low", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.1.1.7.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.temperature.low.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.1.1.7.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.temperature.low.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.1.1.6.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.temperature.high", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.1.1.9.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.temperature.high.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.1.1.8.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.temperature.high.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.1.1.9.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.humidity.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.7.2.1.5.%i.1", NULL, SU_FLAG_OK, &marlin_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.7.2.1.5.%i.1", NULL, SU_FLAG_OK, &marlin_threshold_humidity_alarms_info[0]), snmp_info_default("ambient.humidity", 0, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.2.1.4.%i.1", NULL, SU_FLAG_OK, NULL), /* Low and high threshold use the respective critical levels */ snmp_info_default("ambient.humidity.low", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.2.1.7.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.humidity.low.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.2.1.6.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.humidity.low.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.2.1.7.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.humidity.high", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.2.1.9.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.humidity.high.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.2.1.8.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), snmp_info_default("ambient.humidity.high.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.6.7.7.2.1.9.%i.1", NULL, SU_FLAG_NEGINVALID | SU_FLAG_OK, NULL), /* Dry contacts on TH module */ snmp_info_default("ambient.contacts.1.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.7.3.1.4.%i.1", NULL, SU_FLAG_OK, &marlin_ambient_drycontacts_info[0]), snmp_info_default("ambient.contacts.2.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.7.3.1.4.%i.2", NULL, SU_FLAG_OK, &marlin_ambient_drycontacts_info[0]), /* EMP002 (EATON EMP MIB) mapping, including daisychain support */ /* Warning: indexes start at '1' not '0'! */ /* sensorCount.0 */ snmp_info_default("ambient.count", ST_FLAG_RW, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.1.0", "0", SU_TYPE_DAISY_MASTER_ONLY, NULL), /* CommunicationStatus.n */ snmp_info_default("ambient.%i.present", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.1.4.1.1.%i", NULL, SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_emp002_ambient_presence_info[0]), /* sensorName.n: OctetString EMPDT1H1C2 @1 */ snmp_info_default("ambient.%i.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.3.1.1.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* sensorManufacturer.n */ snmp_info_default("ambient.%i.mfr", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.6.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* sensorModel.n */ snmp_info_default("ambient.%i.model", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.7.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* sensorSerialNumber.n */ snmp_info_default("ambient.%i.serial", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.9.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* sensorUuid.n */ snmp_info_default("ambient.%i.id", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.2.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* sensorAddress.n */ snmp_info_default("ambient.%i.address", 0, 1, ".1.3.6.1.4.1.534.6.8.1.1.2.1.4.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* sensorMonitoredBy.n */ snmp_info_default("ambient.%i.parent.serial", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.5.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* sensorFirmwareVersion.n */ snmp_info_default("ambient.%i.firmware", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.10.%i", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* temperatureUnit.1 * MUST be before the temperature data reading! */ snmp_info_default("ambient.%i.temperature.unit", 0, 1.0, ".1.3.6.1.4.1.534.6.8.1.2.5.0", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &eaton_sensor_temperature_unit_info[0]), /* temperatureValue.n.1 */ #if WITH_SNMP_LKP_FUN snmp_info_default("ambient.%i.temperature", 0, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &eaton_sensor_temperature_read_info[0]), #else snmp_info_default("ambient.%i.temperature", 0, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), #endif snmp_info_default("ambient.%i.temperature.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.2.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.2.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_threshold_temperature_alarms_info[0]), /* FIXME: ambient.n.temperature.{minimum,maximum} */ /* temperatureThresholdLowCritical.n.1 */ snmp_info_default("ambient.%i.temperature.low.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.6.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* temperatureThresholdLowWarning.n.1 */ snmp_info_default("ambient.%i.temperature.low.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.5.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* temperatureThresholdHighWarning.n.1 */ snmp_info_default("ambient.%i.temperature.high.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.7.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* temperatureThresholdHighCritical.n.1 */ snmp_info_default("ambient.%i.temperature.high.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.8.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* humidityValue.n.1 */ snmp_info_default("ambient.%i.humidity", 0, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), snmp_info_default("ambient.%i.humidity.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.3.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.3.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_threshold_humidity_alarms_info[0]), /* FIXME: consider ambient.n.humidity.{minimum,maximum} */ /* humidityThresholdLowCritical.n.1 */ snmp_info_default("ambient.%i.humidity.low.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.6.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* humidityThresholdLowWarning.n.1 */ snmp_info_default("ambient.%i.humidity.low.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.5.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* humidityThresholdHighWarning.n.1 */ snmp_info_default("ambient.%i.humidity.high.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.7.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* humidityThresholdHighCritical.n.1 */ snmp_info_default("ambient.%i.humidity.high.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.8.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* digitalInputName.n.{1,2} */ snmp_info_default("ambient.%i.contacts.1.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.2.1.1.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), snmp_info_default("ambient.%i.contacts.2.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.2.1.1.%i.2", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, NULL), /* digitalInputPolarity.n */ snmp_info_default("ambient.%i.contacts.1.config", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.4.2.1.3.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_ambient_drycontacts_polarity_info[0]), snmp_info_default("ambient.%i.contacts.2.config", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.4.2.1.3.%i.2", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_ambient_drycontacts_polarity_info[0]), /* XUPS-MIB::xupsContactState.n */ snmp_info_default("ambient.%i.contacts.1.status", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_ambient_drycontacts_state_info[0]), snmp_info_default("ambient.%i.contacts.2.status", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.3.1.3.%i.2", "", SU_AMBIENT_TEMPLATE | SU_TYPE_DAISY_MASTER_ONLY, &marlin_ambient_drycontacts_state_info[0]), /* Outlet collection */ snmp_info_default("outlet.count", 0, 1, ".1.3.6.1.4.1.534.6.6.7.1.2.1.22.%i", "0", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("outlet.id", 0, 1, NULL, "0", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, NULL, "All outlets", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /* UnitType * used to depict the overall outlets switchability of the unit on G3 and newer ePDU*/ snmp_info_default("outlet.switchable", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.1.2.1.10.%i", "no", SU_FLAG_STATIC | SU_FLAG_UNIQUE, &marlin_unit_switchability_info[0]), /* Ugly hack for older G2 ePDU: check the first outlet to determine unit switchability */ snmp_info_default("outlet.switchable", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.6.1.3.%i.1", "no", SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_FLAG_OK | SU_TYPE_DAISY_1, &g2_unit_outlet_switchability_info[0]), /* The below ones are the same as the input.* equivalent */ /* FIXME: transition period, TO BE REMOVED, moved to input.* */ snmp_info_default("outlet.frequency", 0, 0.1, ".1.3.6.1.4.1.534.6.6.7.3.1.1.3.%i.1", NULL, 0, NULL), snmp_info_default("outlet.voltage", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.3.2.1.3.%i.1.1", NULL, 0, NULL), snmp_info_default("outlet.current", 0, 0.01, ".1.3.6.1.4.1.534.6.6.7.3.3.1.4.%i.1.1", NULL, 0, NULL), snmp_info_default("outlet.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.4.%i.1.4", NULL, 0, NULL), snmp_info_default("outlet.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.3.4.1.3.%i.1.4", NULL, 0, NULL), /* outlet template definition * Indexes start from 1, ie outlet.1 => .1 */ /* Note: the first definition is used to determine the base index (ie 0 or 1) */ /* Outlet friendly name, which can be modified by the user * outletName: = OctetString: "Outlet A16" */ /* FIXME: SU_FLAG_SEMI_STATIC or SU_FLAG_SETTING => * refreshed from time to time or upon call to setvar */ snmp_info_default("outlet.%i.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.1.1.3.%i.%i", NULL, SU_FLAG_SEMI_STATIC | SU_FLAG_OK | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.6.1.2.%i.%i", NULL, SU_FLAG_OK | SU_OUTLET | SU_TYPE_DAISY_1, &marlin_outlet_status_info[0]), /* Numeric identifier of the outlet, tied to the whole unit */ /* NOTE: For daisychain devices ATM the last listed value presented by * the SNMP device is kept by the driver - no SU_FLAG_UNIQUE here yet. * Verified that a non-implemented OID does not publish empty values. */ /* Fallback in firmwares issued before Sep 2017 is to use the * outletID: Outlet physical name, related to its number in the group * ex: first outlet of the second group (B) is B1, or can default to * the outlet number (represented as string) and is a read-only string * outletID.0.8 = Value (OctetString): "8" */ snmp_info_default("outlet.%i.id", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.7.%i.%i", NULL, SU_FLAG_STATIC | SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* The fallback in firmwares issued before Sep 2017 (outletID), see details above: */ snmp_info_default("outlet.%i.name", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.1.1.2.%i.%i", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_FLAG_OK | SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* Preferred: Outlet physical name OID in new G3 firmware (02.00.0051) * is named outletDesignator (other MIBs outletPhysicalName) * and is a read-only string provided by firmware * outletDesignator.0.1 = Value (OctetString): "A1" * outletPhysicalName.0.16 = Value (OctetString): "A16" */ snmp_info_default("outlet.%i.name", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.1.1.6.%i.%i", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_FLAG_OK | SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* FIXME: the last part of the OID gives the group number (i.e. %i.1 means "group 1") * Need to address that, without multiple declaration (%i.%i, SU_OUTLET | SU_OUTLET_GROUP)? */ snmp_info_default("outlet.%i.groupid", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.2.1.3.%i.%i.1", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.groupid", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.2.1.3.%i.%i.2", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.groupid", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.2.1.3.%i.%i.3", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.groupid", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.2.1.3.%i.%i.4", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.groupid", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.2.1.3.%i.%i.5", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.groupid", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.2.1.3.%i.%i.6", NULL, SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.current", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.4.1.3.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.current.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.4.1.4.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, &marlin_threshold_status_info[0]), snmp_info_default("outlet.%i.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.4.1.4.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, &marlin_threshold_current_alarms_info[0]), snmp_info_default("outlet.%i.current.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.4.1.5.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.current.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.4.1.6.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.current.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.4.1.7.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.current.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.4.1.8.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.6.5.1.3.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.voltage", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.3.1.2.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.voltage.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.3.1.3.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, &marlin_threshold_status_info[0]), snmp_info_default("outlet.%i.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.3.1.3.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, &marlin_threshold_voltage_alarms_info[0]), snmp_info_default("outlet.%i.voltage.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.3.1.4.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.voltage.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.3.1.5.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.voltage.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.3.1.6.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.voltage.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.6.3.1.7.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.6.5.1.2.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* outletControlSwitchable */ snmp_info_default("outlet.%i.switchable", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.6.1.9.%i.%i", "no", SU_OUTLET | SU_FLAG_UNIQUE | SU_TYPE_DAISY_1, &marlin_outlet_switchability_info[0]), /* FIXME: handle non switchable units (only measurements), which do not expose this OID */ snmp_info_default("outlet.%i.switchable", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.6.1.3.%i.%i", "no", SU_FLAG_STATIC | SU_FLAG_UNIQUE | SU_OUTLET | SU_FLAG_OK | SU_TYPE_DAISY_1, &g2_unit_outlet_switchability_info[0]), snmp_info_default("outlet.%i.type", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.6.1.1.5.%i.%i", "unknown", SU_FLAG_STATIC | SU_OUTLET | SU_TYPE_DAISY_1, &marlin_outlet_type_info[0]), /* TODO: handle statistics * outletWh.0.1 * outletWhTimer.0.1 */ /* Outlet groups collection */ snmp_info_default("outlet.group.count", 0, 1, ".1.3.6.1.4.1.534.6.6.7.1.2.1.21.%i", "0", SU_FLAG_STATIC | SU_TYPE_DAISY_1, NULL), /* outlet groups template definition * Indexes start from 1, ie outlet.group.1 => .1 */ /* Note: the first definition is used to determine the base index (ie 0 or 1) */ /* groupID.0.1 = OctetString: A */ snmp_info_default("outlet.group.%i.id", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.1.1.2.%i.%i", NULL, SU_FLAG_STATIC | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* User-friendly (writeable) description of the outlet group: * groupName.0.1 = OctetString: Factory Group 1 * groupName.0.2 = OctetString: Branch Circuit B */ /* FIXME: SU_FLAG_SEMI_STATIC or SU_FLAG_SETTING => * refreshed from time to time or upon call to setvar */ snmp_info_default("outlet.group.%i.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.1.1.3.%i.%i", NULL, SU_FLAG_SEMI_STATIC | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* Outlet-group physical name, a read-only string, * is named groupDesignator (other MIBs groupPhysicalName) * groupPhysicalName.0.1 = Value (OctetString): A * groupDesignator.0.2 = Value (OctetString): B */ snmp_info_default("outlet.group.%i.name", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.1.1.8.%i.%i", NULL, SU_FLAG_STATIC | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* Outlet-group color: groupColor (other MIBs groupBkgColor) * groupColor.0.1 = Value (Gauge32): 16051527 (0xF4ED47) */ /* FIXME: RFC on key name is needed when backporting to NUT upstream */ snmp_info_default("outlet.group.%i.color", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.1.1.7.%i.%i", NULL, SU_FLAG_STATIC | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupType.0.1 = Integer: outletSection (4) */ snmp_info_default("outlet.group.%i.type", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.1.1.4.%i.%i", NULL, SU_FLAG_STATIC | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, &marlin_outlet_group_type_info[0]), /* Phase to which an outlet-group is connected: * We use the following OID, which gives the voltage measurement type * groupVoltageMeasType.0.1; Value (Integer): singlePhase (1) */ /* FIXME: RFC on key name is needed when backporting to NUT upstream ; check type (number? string?) and flags (daisy?) */ snmp_info_default("outlet.group.%i.phase", 0, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.1.1.2.%i.%i", NULL, SU_FLAG_STATIC | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, &marlin_outlet_group_phase_info[0]), /* groupControlStatus.0.1 = Integer: on (1) */ snmp_info_default("outlet.group.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.6.1.2.%i.%i", NULL, SU_FLAG_OK | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, &marlin_outletgroups_status_info[0]), /* groupChildCount.0.1 = Integer: 12 */ snmp_info_default("outlet.group.%i.count", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.1.1.6.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupVoltage.0.1 = Integer: 243080 */ snmp_info_default("outlet.group.%i.voltage", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.3.1.3.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupVoltageThStatus.0.1 = Integer: good (0) */ snmp_info_default("outlet.group.%i.voltage.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.3.1.4.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, &marlin_threshold_status_info[0]), snmp_info_default("outlet.group.%i.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.3.1.4.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, &marlin_threshold_voltage_alarms_info[0]), snmp_info_default("outlet.group.%i.voltage.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.3.1.5.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.group.%i.voltage.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.3.1.6.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.group.%i.voltage.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.3.1.7.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.group.%i.voltage.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.3.1.8.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupCurrent.0.1 = Integer: 0 */ snmp_info_default("outlet.group.%i.current", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.4.1.3.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupCurrentCapacity.0.1 = Integer: 16000 */ snmp_info_default("outlet.group.%i.current.nominal", 0, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.4.1.2.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupCurrentThStatus.0.1 = Integer: good (0) */ snmp_info_default("outlet.group.%i.current.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.4.1.4.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, &marlin_threshold_status_info[0]), snmp_info_default("outlet.group.%i.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.6.7.5.4.1.4.%i.%i", NULL, SU_OUTLET_GROUP | SU_TYPE_DAISY_1, &marlin_threshold_current_alarms_info[0]), /* groupCurrentPercentLoad.0.1 = Integer: 0 */ snmp_info_default("outlet.group.%i.load", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.5.4.1.10.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupCurrentThLowerWarning.0.1 = Integer: 0 */ snmp_info_default("outlet.group.%i.current.low.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.4.1.5.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupCurrentThLowerCritical.0.1 = Integer: -1 */ snmp_info_default("outlet.group.%i.current.low.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.4.1.6.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupCurrentThUpperWarning.0.1 = Integer: 12800 */ snmp_info_default("outlet.group.%i.current.high.warning", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.4.1.7.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupCurrentThUpperCritical.0.1 = Integer: 16000 */ snmp_info_default("outlet.group.%i.current.high.critical", ST_FLAG_RW, 0.001, ".1.3.6.1.4.1.534.6.6.7.5.4.1.8.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupWatts.0.1 = Integer: 2670 */ snmp_info_default("outlet.group.%i.realpower", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.5.5.1.3.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupVA.0.1 = Integer: 3132 */ snmp_info_default("outlet.group.%i.power", 0, 1.0, ".1.3.6.1.4.1.534.6.6.7.5.5.1.2.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* Input to which an outlet-group is connected * groupInputIndex.0.1 = Integer: 1 */ /* FIXME: RFC on key name is needed when backporting to NUT upstream */ snmp_info_default("outlet.group.%i.input", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.1.1.9.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* instant commands. */ /* Notes: * - load.cycle might be replaced by / mapped on shutdown.reboot * - outletControl{Off,On,Reboot}Cmd values: * 0-n : Timer * -1 : Cancel * we currently use "0", so instant On | Off | Reboot... */ /* no counterpart found! snmp_info_default("outlet.load.off", 0, DO_OFF, AR_OID_OUTLET_STATUS ".0", NULL, SU_TYPE_CMD, NULL), snmp_info_default("outlet.load.on", 0, DO_ON, AR_OID_OUTLET_STATUS ".0", NULL, SU_TYPE_CMD, NULL), snmp_info_default("outlet.load.cycle", 0, DO_CYCLE, AR_OID_OUTLET_STATUS ".0", NULL, SU_TYPE_CMD, NULL), */ /* Delays handling: * 0-n :Time in seconds until the group command is issued * -1:Cancel a pending group-level Off/On/Reboot command */ snmp_info_default("outlet.%i.load.off", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.3.%i.%i", "0", SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.load.on", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.4.%i.%i", "0", SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.load.cycle", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.5.%i.%i", "0", SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* Per-outlet shutdown / startup delay (configuration point, not the timers) * outletControlShutoffDelay.0.3 = INTEGER: 120 * outletControlSequenceDelay.0.8 = INTEGER: 8 * (by default each output socket startup is delayed by its number in seconds) */ snmp_info_default("outlet.%i.delay.shutdown", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.10.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.delay.start", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.7.%i.%i", NULL, SU_FLAG_NEGINVALID | SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* Delayed version, parameter is mandatory (so dfl is NULL)! */ snmp_info_default("outlet.%i.load.off.delay", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.3.%i.%i", NULL, SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.load.on.delay", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.4.%i.%i", NULL, SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.load.cycle.delay", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.5.%i.%i", NULL, SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* Per-outlet shutdown / startup timers * outletControlOffCmd.0.1 = INTEGER: -1 * outletControlOnCmd.0.1 = INTEGER: -1 */ snmp_info_default("outlet.%i.timer.shutdown", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.3.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.timer.start", 0, 1, ".1.3.6.1.4.1.534.6.6.7.6.6.1.4.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* Delays handling: * 0-n :Time in seconds until the group command is issued * -1:Cancel a pending group-level Off/On/Reboot command */ /* groupControlOffCmd.0.1 = Integer: -1 */ snmp_info_default("outlet.group.%i.load.off", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.6.1.3.%i.%i", "0", SU_TYPE_CMD | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupControl0nCmd.0.1 = Integer: -1 */ snmp_info_default("outlet.group.%i.load.on", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.6.1.4.%i.%i", "0", SU_TYPE_CMD | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupControlRebootCmd.0.1 = Integer: -1 */ snmp_info_default("outlet.group.%i.load.cycle", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.6.1.5.%i.%i", "0", SU_TYPE_CMD | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* Delayed version, parameter is mandatory (so dfl is NULL)! */ snmp_info_default("outlet.group.%i.load.off.delay", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.6.1.3.%i.%i", NULL, SU_TYPE_CMD | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupControl0nCmd.0.1 = Integer: -1 */ snmp_info_default("outlet.group.%i.load.on.delay", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.6.1.4.%i.%i", NULL, SU_TYPE_CMD | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* groupControlRebootCmd.0.1 = Integer: -1 */ snmp_info_default("outlet.group.%i.load.cycle.delay", 0, 1, ".1.3.6.1.4.1.534.6.6.7.5.6.1.5.%i.%i", NULL, SU_TYPE_CMD | SU_OUTLET_GROUP | SU_TYPE_DAISY_1, NULL), /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t eaton_marlin = { "eaton_epdu", EATON_MARLIN_MIB_VERSION, NULL, EATON_MARLIN_OID_MODEL_NAME, eaton_marlin_mib, EATON_MARLIN_SYSOID, NULL }; nut-2.8.4/drivers/mge-xml.h0000644000175000017500000000345614670526611012471 00000000000000/* mge-xml.h Model specific data for MGE XML protocol UPSes Copyright (C) 2008 Arjen de Korte This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef MGE_XML_H #define MGE_XML_H #include "netxml-ups.h" extern subdriver_t mge_xml_subdriver; /** * \brief Convert NUT variable name to MGE XML * * \param name NUT variable name * * \return MGE XML variable name */ const char *vname_nut2mge_xml(const char *name); /** * \brief Convert MGE XML variable name to NUT * * \param name MGE XML variable name * * \return NUT variable name */ const char * vname_mge_xml2nut(const char *name); /** * \brief Convert MGE XML variable value to NUT value * * The function produces a newly created C-string that should * be destroyed using \c free. * * \param name NUT variable name * \param value MGE XML variable value * \param len MGE XML variable value length (in characters) * * \return NUT variable value */ char *vvalue_mge_xml2nut(const char *name, const char *value, size_t len); /** * \brief Register set of R/W variables */ void vname_register_rw(void); #endif /* MGE_XML_H */ nut-2.8.4/drivers/apc-epdu-mib.c0000644000175000017500000003747715000601404013351 00000000000000/* apc-epdu-mib.c - subdriver to monitor apc SNMP easy pdu with NUT * * Copyright (C) * 2011 - 2022 Eric Clappier * * Note: this subdriver was initially generated as a "stub" by the * gen-snmp-subdriver script. It must be customized! * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "apc-epdu-mib.h" #define APC_EPDU_MIB_VERSION "0.10" #define APC_EPDU_MIB_SYSOID ".1.3.6.1.4.1.318.1.3.4.9" static info_lkp_t apc_epdu_sw_outlet_status_info[] = { info_lkp_default(1, "off"), info_lkp_default(2, "on"), info_lkp_sentinel }; static info_lkp_t apc_epdu_sw_outlet_switchability_info[] = { info_lkp_default(1, "yes"), info_lkp_default(2, "yes"), info_lkp_sentinel }; /* POWERNET-MIB Snmp2NUT lookup table */ static snmp_info_t apc_epdu_mib[] = { /* Device page */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "APC", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /* ePDUDeviceStatusModelNumber.1 = STRING: "EPDU1016M" */ snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.318.1.1.30.2.1.1.4.1", "Easy ePDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_STALE | SU_FLAG_OK, NULL), snmp_info_default("device.description", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.2.1.1.5.0", NULL, SU_FLAG_STALE | SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_STALE | SU_FLAG_OK, NULL), /* FIXME: to be RFC'ed */ snmp_info_default("device.uptime", 0, 1, ".1.3.6.1.2.1.1.3.0", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID, NULL), /* ePDUDeviceStatusSerialNumber.1 = STRING: "506255604729" */ snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, " .1.3.6.1.4.1.318.1.1.30.2.1.1.5.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ePDUDeviceStatusModelNumber.1 = STRING: "EPDU1016M" */ snmp_info_default("device.part", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.318.1.1.30.2.1.1.4.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ePDUDeviceStatusVersion.1 = STRING: "Ver16.10" */ snmp_info_default("device.version", ST_FLAG_STRING, SU_INFOSIZE, " .1.3.6.1.4.1.318.1.1.30.2.1.1.3.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* Input */ /* ePDUPhaseTableSize = INTEGER: 1 */ snmp_info_default("input.phases", 0, 1, ".1.3.6.1.4.1.318.1.1.30.3.0", NULL, SU_FLAG_OK, NULL), /* ePDUDeviceStatusActivePower.1 = INTEGER: 785 */ snmp_info_default("input.realpower", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.7.1", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID, NULL), /* Take first phase for global if single phase */ /* ePDUPhaseStatusVoltage.1 = INTEGER: 2304 */ snmp_info_default("input.voltage", 0, 0.1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.4.1", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_1, NULL), /* Take first phase for global if single phase */ /* ePDUPhaseStatusCurrent.1 = INTEGER: 355 */ snmp_info_default("input.current", 0, 0.01, ".1.3.6.1.4.1.318.1.1.30.4.2.1.5.1", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_1, NULL), /* Only if tree-phase */ /* ePDUPhaseStatusVoltage.1 = INTEGER: 2304 */ snmp_info_default("input.L1-N.voltage", 0, 0.1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.4.1", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusVoltage.2 = INTEGER: 2304 */ snmp_info_default("input.L2-N.voltage", 0, 0.1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.4.2", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusVoltage.3 = INTEGER: 2304 */ snmp_info_default("input.L3-N.voltage", 0, 0.1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.4.3", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusCurrent.1 = INTEGER: 355 */ snmp_info_default("input.L1.current", 0, 0.01, ".1.3.6.1.4.1.318.1.1.30.4.2.1.5.1", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusCurrent.2 = INTEGER: 355 */ snmp_info_default("input.L2.current", 0, 0.01, ".1.3.6.1.4.1.318.1.1.30.4.2.1.5.2", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusCurrent.3 = INTEGER: 355 */ snmp_info_default("input.L3.current", 0, 0.01, ".1.3.6.1.4.1.318.1.1.30.4.2.1.5.3", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusActivePower.1 = INTEGER: 785 */ snmp_info_default("input.L1.realpower", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.6.1", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusActivePower.2 = INTEGER: 785 */ snmp_info_default("input.L2.realpower", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.6.2", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* ePDUPhaseStatusActivePower.3 = INTEGER: 785 */ snmp_info_default("input.L3.realpower", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.6.3", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_INPUT_3, NULL), /* Outlets */ /* ePDUOutletTableSize.0 = INTEGER: 1 */ snmp_info_default("outlet.count", 0, 1, ".1.3.6.1.4.1.318.1.1.30.5.0", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ePDUOutletStatusIndex.%i = INTEGER: 1 */ snmp_info_default("outlet.%i.id", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.1.1.1.%i", "%i", SU_FLAG_STATIC | SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_OUTLET, NULL), /* ePDUOutletStatusModule.%i= INTEGER: 1 */ snmp_info_default("outlet.%i.name", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.2.1.2.%i", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_OUTLET, NULL), /* ePDUOutletStatusNumber.%i = INTEGER: 1 */ snmp_info_default("outlet.%i.desc", 0, 1, NULL, "Outlet %i", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_OUTLET, NULL), /* ePDUOutletStatusState.%i = INTEGER: off(1) */ snmp_info_default("outlet.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.318.1.1.30.6.1.1.4.%i", NULL, SU_FLAG_OK | SU_FLAG_NEGINVALID | SU_OUTLET, &apc_epdu_sw_outlet_status_info[0]), /* Also use this OID to determine switchability ; its presence means "yes" */ /* ePDUOutletStatusState.%i = INTEGER: off(1) */ snmp_info_default("outlet.%i.switchable", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.318.1.1.30.6.1.1.4.%i", "yes", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK | SU_OUTLET, &apc_epdu_sw_outlet_switchability_info[0]), #if WITH_UNMAPPED_DATA_POINTS /* keep following scan for future development */ /* iso.3.6.1.4.1.318.1.1.30.1.0 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.1.0", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.2.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.3.1 = STRING: "Ver16.10" */ snmp_info_default("unmapped.iso", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.318.1.1.30.2.1.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.4.1 = STRING: "EPDU1016M" */ snmp_info_default("unmapped.iso", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.318.1.1.30.2.1.1.4.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.5.1 = STRING: "506255604717" */ snmp_info_default("unmapped.iso", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.318.1.1.30.2.1.1.5.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.6.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.6.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.7.1 = INTEGER: 785 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.7.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.8.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.8.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.9.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.9.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.10.1 = INTEGER: 965 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.10.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.11.1 = INTEGER: 9114157 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.11.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.1.1.12.1 = INTEGER: 49988 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.1.1.12.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.2.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.2.1.2.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.2.1.3.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.2.1.4.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.2.1.4.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.2.2.1.5.1 = INTEGER: 2 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.2.2.1.5.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.3.0 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.3.0", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.1.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.1.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.1.1.2.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.1.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.1.1.3.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.1.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.1.1.4.1 = INTEGER: 3000 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.1.1.4.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.1.1.5.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.1.1.5.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.1.1.6.1 = INTEGER: 3200 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.1.1.6.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.1.1.7.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.1.1.7.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.2.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.3.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.4.1 = INTEGER: 2304 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.4.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.5.1 = INTEGER: 353 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.5.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.6.1 = INTEGER: 785 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.6.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.7.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.7.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.8.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.8.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.9.1 = INTEGER: 965 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.9.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.4.2.1.10.1 = INTEGER: 9114157 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.4.2.1.10.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.5.0 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.5.0", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.1.1.1.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.1.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.1.1.2.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.1.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.1.1.3.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.1.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.1.1.4.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.1.1.4.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.2.1.1.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.2.1.2.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.2.1.3.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.6.2.1.4.1 = INTEGER: -1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.6.2.1.4.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.7.0 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.7.0", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.1.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.1.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.1.1.2.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.1.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.1.1.3.1 = INTEGER: 900 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.1.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.1.1.4.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.1.1.4.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.1.1.5.1 = INTEGER: 900 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.1.1.5.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.1.1.6.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.1.1.6.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.2.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.2.1.2.1 = INTEGER: 1 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.2.1.3.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* iso.3.6.1.4.1.318.1.1.30.8.2.1.4.1 = INTEGER: 0 */ snmp_info_default("unmapped.iso", 0, 1, ".1.3.6.1.4.1.318.1.1.30.8.2.1.4.1", NULL, SU_FLAG_OK, NULL), #endif /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t apc_pdu_epdu = { "apc", APC_EPDU_MIB_VERSION, NULL, NULL, apc_epdu_mib, APC_EPDU_MIB_SYSOID, NULL }; nut-2.8.4/drivers/nutdrv_qx_bestups.c0000644000175000017500000006034215044656702014713 00000000000000/* nutdrv_qx_bestups.c - Subdriver for Best Power/Sola Australia UPSes * * Copyright (C) * 2014 Daniele Pezzini * Based on: * bestups.c - Copyright (C) * 1999 Russell Kroll * Jason White * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nut_float.h" #include "nut_stdint.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_bestups.h" #define BESTUPS_VERSION "BestUPS 0.08" /* Support functions */ static int bestups_claim(void); static void bestups_initups(void); static void bestups_makevartable(void); /* Answer preprocess functions */ static int bestups_preprocess_id_answer(item_t *item, const int len); /* Preprocess functions */ static int bestups_process_setvar(item_t *item, char *value, const size_t valuelen); static int bestups_process_bbb_status_bit(item_t *item, char *value, const size_t valuelen); static int bestups_manufacturer(item_t *item, char *value, const size_t valuelen); static int bestups_model(item_t *item, char *value, const size_t valuelen); static int bestups_batt_runtime(item_t *item, char *value, const size_t valuelen); static int bestups_batt_packs(item_t *item, char *value, const size_t valuelen); static int bestups_get_pins_shutdown_mode(item_t *item, char *value, const size_t valuelen); static int bestups_voltage_settings(item_t *item, char *value, const size_t valuelen); /* ups.conf settings */ static int pins_shutdown_mode; /* General settings */ static int inverted_bbb_bit = 0; /* == Ranges/enums == */ /* Range for ups.delay.start */ static info_rw_t bestups_r_ondelay[] = { { "60", 0 }, { "599940", 0 }, { "", 0 } }; /* Range for ups.delay.shutdown */ static info_rw_t bestups_r_offdelay[] = { { "12", 0 }, { "5940", 0 }, { "", 0 } }; /* Range for number of battery packs */ static info_rw_t bestups_r_batt_packs[] = { { "0", 0 }, { "5", 0 }, { "", 0 } }; /* Range for pin shutdown mode */ static info_rw_t bestups_r_pins_shutdown_mode[] = { { "0", 0 }, { "6", 0 }, { "", 0 } }; /* == qx2nut lookup table == */ static item_t bestups_qx2nut[] = { /* Query UPS for status * > [Q1\r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000\r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ { "input.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.voltage.fault", 0, NULL, "Q1\r", "", 47, '(', "", 7, 11, "%.1f", 0, NULL, NULL, NULL }, { "output.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 13, 17, "%.1f", 0, NULL, NULL, NULL }, { "ups.load", 0, NULL, "Q1\r", "", 47, '(', "", 19, 21, "%.0f", 0, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "Q1\r", "", 47, '(', "", 23, 26, "%.1f", 0, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 28, 31, "%.2f", 0, NULL, NULL, qx_multiply_battvolt }, { "ups.temperature", 0, NULL, "Q1\r", "", 47, '(', "", 33, 36, "%.1f", 0, NULL, NULL, NULL }, /* Status bits */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 38, 38, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Utility Fail (Immediate) */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 39, 39, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Battery Low */ { "ups.alarm", 0, NULL, "Q1\r", "", 47, '(', "", 41, 41, NULL, 0, NULL, NULL, blazer_process_status_bits }, /* UPS Failed */ { "ups.type", 0, NULL, "Q1\r", "", 47, '(', "", 42, 42, "%s", QX_FLAG_STATIC, NULL, NULL, blazer_process_status_bits }, /* UPS Type */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 43, 43, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Test in Progress */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 44, 44, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Shutdown Active */ /* { "ups.beeper.status", 0, NULL, "Q1\r", "", 47, '(', "", 45, 45, "%s", 0, NULL, NULL, blazer_process_status_bits }, *//* Beeper status: not supported; always 0 */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 40, 40, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, bestups_process_bbb_status_bit }, /* Bypass/Boost or Buck Active - keep this one at the end as it needs the processed data from the previous items */ /* Query UPS for ratings and model infos * > [ID\r] * < [FOR,750,120,120,20.0,27.6\r] case #1: length = 26 * < [FOR,1500,120,120,20.0,27.6\r] case #2: length = 27 * < [FOR,3000,120,120,20.0,100.6\r] case #3: length = 28 * < [FOR, 750,120,120,20.0, 27.6\r] after being preprocessed: length = 28 * 0123456789012345678901234567 * 0 1 2 */ { "device.mfr", 0, NULL, "ID\r", "", 28, 0, "", 0, 2, "%s", QX_FLAG_STATIC, NULL, bestups_preprocess_id_answer, bestups_manufacturer }, { "device.model", 0, NULL, "ID\r", "", 28, 0, "", 0, 2, "%s", QX_FLAG_STATIC, NULL, bestups_preprocess_id_answer, bestups_model }, { "ups.power.nominal", 0, NULL, "ID\r", "", 28, 0, "", 4, 7, "%.0f", QX_FLAG_STATIC, NULL, bestups_preprocess_id_answer, NULL }, { "input.voltage.nominal", 0, NULL, "ID\r", "", 28, 0, "", 9, 11, "%.0f", QX_FLAG_STATIC, NULL, bestups_preprocess_id_answer, NULL }, { "output.voltage.nominal", 0, NULL, "ID\r", "", 28, 0, "", 13, 15, "%.0f", QX_FLAG_STATIC, NULL, bestups_preprocess_id_answer, NULL }, { "battery.voltage.low", 0, NULL, "ID\r", "", 28, 0, "", 17, 20, "%.1f", QX_FLAG_SEMI_STATIC, NULL, bestups_preprocess_id_answer, NULL }, { "battery.voltage.high", 0, NULL, "ID\r", "", 28, 0, "", 22, 26, "%.1f", QX_FLAG_SEMI_STATIC, NULL, bestups_preprocess_id_answer, NULL }, /* Query UPS for battery runtime (not available on the Patriot Pro/Sola 320 model series) * > [RT\r] * < [025\r] * 0123 * 0 */ { "battery.runtime", 0, NULL, "RT\r", "", 4, 0, "", 0, 2, "%.0f", QX_FLAG_SKIP, NULL, NULL, bestups_batt_runtime }, /* Query UPS for number of battery packs (available only on the Axxium/Sola 620 model series) * > [BP?\r] * < [02\r] * 012 * 0 */ { "battery.packs", ST_FLAG_RW, bestups_r_batt_packs, "BP?\r", "", 3, 0, "", 0, 1, "%d", QX_FLAG_SEMI_STATIC | QX_FLAG_RANGE | QX_FLAG_SKIP, NULL, NULL, bestups_batt_packs }, /* Set number of battery packs to n (integer, 0-5) (available only on the Axxium/Sola 620 model series) * > [BPn\r] * < [] */ { "battery.packs", 0, bestups_r_batt_packs, "BP%.0f\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_SETVAR | QX_FLAG_RANGE | QX_FLAG_SKIP, NULL, NULL, bestups_process_setvar }, /* Query UPS for shutdown mode functionality of Pin 1 and Pin 7 on the UPS DB9 communication port (Per Best Power's EPS-0059) * > [SS?\r] * < [0\r] * 01 * 0 */ { "pins_shutdown_mode", ST_FLAG_RW, bestups_r_pins_shutdown_mode, "SS?\r", "", 2, 0, "", 0, 0, "%.0f", QX_FLAG_SEMI_STATIC | QX_FLAG_RANGE | QX_FLAG_NONUT, NULL, NULL, bestups_get_pins_shutdown_mode }, /* Set shutdown mode functionality of Pin 1 and Pin 7 on the UPS DB9 communication port (Per Best Power's EPS-0059) to n (integer, 0-6) * > [SSn\r] * < [] */ { "pins_shutdown_mode", 0, bestups_r_pins_shutdown_mode, "SS%.0f\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_SETVAR | QX_FLAG_RANGE | QX_FLAG_NONUT | QX_FLAG_SKIP, NULL, NULL, bestups_process_setvar }, /* Query UPS for voltage settings * > [M\r] * < [0\r] * 01 * 0 */ { "input.transfer.low", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, { "input.transfer.boost.low", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, { "input.transfer.boost.high", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, { "input.voltage.nominal", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, { "output.voltage.nominal", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, { "input.transfer.trim.low", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, { "input.transfer.trim.high", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, { "input.transfer.high", 0, NULL, "M\r", "", 2, 0, "", 0, 0, "%d", 0, NULL, NULL, bestups_voltage_settings }, /* Instant commands */ { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, bestups_r_ondelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_ONDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, bestups_r_offdelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_OFFDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* == Testing table == */ #ifdef TESTING static testing_t bestups_testing[] = { { "Q1\r", "(215.0 195.0 230.0 014 49.0 22.7 30.0 00100000\r", -1 }, { "ID\r", "FOR,750,120,120,20.0,27.6\r", -1 }, { "RT\r", "015\r", -1 }, { "BP?\r", "02\r", -1 }, { "BP1\r", "", -1 }, { "SS?\r", "0\r", -1 }, { "SS2\r", "", -1 }, { "M\r", "0\r", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0001\r", "", -1 }, { "T04\r", "", -1 }, { "TL\r", "", -1 }, { "T\r", "", -1 }, { "CT\r", "", -1 }, { NULL } }; #endif /* TESTING */ /* == Support functions == */ /* This function allows the subdriver to "claim" a device: return 1 if the device is supported by this subdriver, else 0. */ static int bestups_claim(void) { /* We need at least Q1 and ID to run this subdriver */ item_t *item = find_nut_info("input.voltage", 0, 0); /* Don't know what happened */ if (!item) return 0; /* No reply/Unable to get value */ if (qx_process(item, NULL)) return 0; /* Unable to process value */ if (ups_infoval_set(item) != 1) return 0; /* UPS Model */ item = find_nut_info("device.model", 0, 0); /* Don't know what happened */ if (!item) { dstate_delinfo("input.voltage"); return 0; } /* No reply/Unable to get value */ if (qx_process(item, NULL)) { dstate_delinfo("input.voltage"); return 0; } /* Unable to process value */ if (ups_infoval_set(item) != 1) { dstate_delinfo("input.voltage"); return 0; } return 1; } /* Subdriver-specific initups */ static void bestups_initups(void) { blazer_initups_light(bestups_qx2nut); } /* Subdriver-specific flags/vars */ static void bestups_makevartable(void) { addvar(VAR_VALUE, "pins_shutdown_mode", "Set shutdown mode functionality of Pin 1 and Pin 7 on the UPS DB9 communication port (Per Best Power's EPS-0059) to n (integer, 0-6)"); blazer_makevartable_light(); } /* == Answer preprocess functions == */ /* Preprocess the answer we got back from the UPS when queried with 'ID\r': make data begin always at the same indexes */ static int bestups_preprocess_id_answer(item_t *item, const int len) { int i; char refined[SMALLBUF] = "", rawval[SMALLBUF] = "", *token, *saveptr = NULL; if (len <= 0) return len; if (len < 25 || len > 27) { upsdebugx(4, "%s: wrong length [%s: %d]", __func__, item->info_type, len); return -1; } /* e.g.: * 1. item->answer = "FOR,750,120,120,20.0,27.6\r"; len = 26 * 2. item->answer = "FOR,1500,120,120,20.0,27.6\r"; len = 27 * 3. item->answer = "FOR,3000,120,120,20.0,100.6\r"; len = 28 */ upsdebugx(4, "read: '%.*s'", (int)strcspn(item->answer, "\r"), item->answer); snprintf(rawval, sizeof(rawval), "%s", item->answer); for (i = 1, token = strtok_r(rawval, ",", &saveptr); token != NULL; i++, token = strtok_r(NULL, ",", &saveptr)) { switch (i) { case 1: snprintf(refined, sizeof(refined), "%s", token); continue; case 2: /* Output power */ snprintfcat(refined, sizeof(refined), ",%4s", token); continue; case 6: /* Battery voltage at full charge (+ trailing CR) */ snprintfcat(refined, sizeof(refined), ",%6s", token); continue; default: snprintfcat(refined, sizeof(refined), ",%s", token); } } if (i != 7 || strlen(refined) != 28) { upsdebugx(2, "noncompliant reply: '%.*s'", (int)strcspn(refined, "\r"), refined); return -1; } upsdebugx(4, "read: '%.*s'", (int)strcspn(refined, "\r"), refined); /* e.g.: item->answer = "FOR, 750,120,120,20.0, 27.6\r"; len = 28 */ return snprintf(item->answer, sizeof(item->answer), "%s", refined); } /* == Preprocess functions == */ /* *SETVAR(/NONUT)* Preprocess setvars */ static int bestups_process_setvar(item_t *item, char *value, const size_t valuelen) { double val; if (!strlen(value)) { upsdebugx(2, "%s: value not given for %s", __func__, item->info_type); return -1; } val = strtod(value, NULL); if (!strcasecmp(item->info_type, "pins_shutdown_mode")) { if (d_equal(val, pins_shutdown_mode)) { upslogx(LOG_INFO, "%s is already set to %.0f", item->info_type, val); return -1; } } snprintf_dynamic(value, valuelen, item->command, "%f", val); return 0; } /* Bypass/Boost or Buck status */ static int bestups_process_bbb_status_bit(item_t *item, char *value, const size_t valuelen) { /* Bypass/Boost/Buck bit is not reliable when a battery test, shutdown or on battery condition occurs: always ignore it in these cases */ if (!((unsigned int)(qx_status()) & STATUS(OL)) || ((unsigned int)(qx_status()) & (STATUS(CALIB) | STATUS(FSD)))) { if (item->value[0] == '1') item->value[0] = '0'; return blazer_process_status_bits(item, value, valuelen); } /* UPSes with inverted bypass/boost/buck bit */ if (inverted_bbb_bit) { if (item->value[0] == '1') item->value[0] = '0'; else if (item->value[0] == '0') item->value[0] = '1'; } return blazer_process_status_bits(item, value, valuelen); } /* Identify UPS manufacturer */ static int bestups_manufacturer(item_t *item, char *value, const size_t valuelen) { /* Best Power devices */ if ( !strcmp(item->value, "AX1") || !strcmp(item->value, "FOR") || !strcmp(item->value, "FTC") || !strcmp(item->value, "PR2") || !strcmp(item->value, "PRO") ) { snprintf_dynamic(value, valuelen, item->dfl, "%s", "Best Power"); return 0; } /* Sola Australia devices */ if ( !strcmp(item->value, "325") || !strcmp(item->value, "520") || !strcmp(item->value, "620") ) { snprintf_dynamic(value, valuelen, item->dfl, "%s", "Sola Australia"); return 0; } /* Unknown devices */ snprintf_dynamic(value, valuelen, item->dfl, "%s", "Unknown"); return 0; } /* Identify UPS model and unskip qx2nut table's items accordingly */ static int bestups_model(item_t *item, char *value, const size_t valuelen) { item_t *unskip; /* Best Power devices */ if (!strcmp(item->value, "AX1")) { snprintf_dynamic(value, valuelen, item->dfl, "%s", "Axxium Rackmount"); } else if (!strcmp(item->value, "FOR")) { snprintf_dynamic(value, valuelen, item->dfl, "%s", "Fortress"); } else if (!strcmp(item->value, "FTC")) { snprintf_dynamic(value, valuelen, item->dfl, "%s", "Fortress Telecom"); } else if (!strcmp(item->value, "PR2")) { snprintf_dynamic(value, valuelen, item->dfl, "%s", "Patriot Pro II"); inverted_bbb_bit = 1; } else if (!strcmp(item->value, "PRO")) { snprintf_dynamic(value, valuelen, item->dfl, "%s", "Patriot Pro"); inverted_bbb_bit = 1; /* Sola Australia devices */ } else if ( !strcmp(item->value, "320") || !strcmp(item->value, "325") || !strcmp(item->value, "520") || !strcmp(item->value, "525") || !strcmp(item->value, "620") ) { snprintf(value, valuelen, "Sola %s", item->value); /* Unknown devices */ } else { snprintf(value, valuelen, "Unknown (%s)", item->value); upslogx(LOG_INFO, "Unknown model detected - please report this ID: '%s'", item->value); } /* Unskip qx2nut table's items according to the UPS model */ /* battery.runtime var is not available on the Patriot Pro/Sola 320 model series: leave it skipped in these cases, otherwise unskip it */ if (strcmp(item->value, "PRO") && strcmp(item->value, "320")) { unskip = find_nut_info("battery.runtime", 0, 0); /* Don't know what happened */ if (!unskip) return -1; unskip->qxflags &= ~QX_FLAG_SKIP; } /* battery.packs var is available only on the Axxium/Sola 620 model series: unskip it in these cases */ if (!strcmp(item->value, "AX1") || !strcmp(item->value, "620")) { unskip = find_nut_info("battery.packs", 0, QX_FLAG_SETVAR); /* Don't know what happened */ if (!unskip) return -1; unskip->qxflags &= ~QX_FLAG_SKIP; } return 0; } /* Battery runtime */ static int bestups_batt_runtime(item_t *item, char *value, const size_t valuelen) { double runtime; if (strspn(item->value, "0123456789 .") != strlen(item->value)) { upsdebugx(2, "%s: non numerical value [%s: %s]", __func__, item->info_type, item->value); return -1; } /* Battery runtime is reported by the UPS in minutes, NUT expects seconds */ runtime = strtod(item->value, NULL) * 60; snprintf_dynamic(value, valuelen, item->dfl, "%f", runtime); return 0; } /* Battery packs */ static int bestups_batt_packs(item_t *item, char *value, const size_t valuelen) { item_t *unskip; long l; if (strspn(item->value, "0123456789 ") != strlen(item->value)) { upsdebugx(2, "%s: non numerical value [%s: %s]", __func__, item->info_type, item->value); return -1; } l = strtol(item->value, NULL, 10); if (l < 0 || l > INT_MAX) { upsdebugx(2, "%s: value out of range [%s: %s]", __func__, item->info_type, item->value); return -1; } snprintf_dynamic(value, valuelen, item->dfl, "%d", (int)l); /* Unskip battery.packs setvar */ unskip = find_nut_info("battery.packs", QX_FLAG_SETVAR, 0); /* Don't know what happened */ if (!unskip) return -1; unskip->qxflags &= ~QX_FLAG_SKIP; return 0; } /* *NONUT* Get shutdown mode functionality of Pin 1 and Pin 7 on the UPS DB9 communication port (Per Best Power's EPS-0059) as set in the UPS */ static int bestups_get_pins_shutdown_mode(item_t *item, char *value, const size_t valuelen) { item_t *unskip; long l; if (strspn(item->value, "0123456789") != strlen(item->value)) { upsdebugx(2, "%s: non numerical value [%s: %s]", __func__, item->info_type, item->value); return -1; } l = strtol(item->value, NULL, 10); if (l > INT_MAX) { upsdebugx(2, "%s: pins_shutdown_mode out of range [%s: %s]", __func__, item->info_type, item->value); return -1; } pins_shutdown_mode = (int)l; /* NOTE: Mapping table has "%.0f" for R/W of this concept's value, * meaning zero digits after the decimal point (could as well be * an int right away?) * TODO: Someone with the device should check replacement by "%d". */ snprintf_dynamic(value, valuelen, item->dfl, "%.0f", (double)pins_shutdown_mode); /* We were not asked by the user to change the value */ if ((item->qxflags & QX_FLAG_NONUT) && !getval(item->info_type)) return 0; /* Unskip setvar */ unskip = find_nut_info(item->info_type, QX_FLAG_SETVAR, 0); /* Don't know what happened */ if (!unskip) return -1; unskip->qxflags &= ~QX_FLAG_SKIP; return 0; } /* Voltage settings */ static int bestups_voltage_settings(item_t *item, char *value, const size_t valuelen) { long index; int val; const char *nominal_voltage; const struct { const int low; /* Low voltage -> input.transfer.low / input.transfer.boost.low */ const int boost; /* Boost voltage -> input.transfer.boost.high */ const int nominal; /* Nominal voltage -> input.voltage.nominal / output.voltage.nominal */ const int buck; /* Buck voltage -> input.transfer.trim.low */ const int high; /* High voltage -> input.transfer.high / input.transfer.trim.high */ } voltage_settings[] = { /* U models voltage limits, for: * - Fortress (750U, 1050U, 1425U, 1800U and 2250U) * - Fortress Rackmount (750, 1050, 1425, 1800, and 2250 VA) * - Patriot Pro II (400U, 750U, and 1000U) */ /* M low boost nominal buck high */ /* 0 */ { 96, 109, 120, 130, 146 }, /* LEDs lit: 2,3,4 (Default) */ /* 1 */ { 96, 109, 120, 138, 156 }, /* LEDs lit: 1,3,4 */ /* 2 */ { 90, 104, 120, 130, 146 }, /* LEDs lit: 2,3,5 */ /* 3 */ { 90, 104, 120, 138, 156 }, /* LEDs lit: 1,3,5 */ /* 4 */ { 90, 104, 110, 120, 130 }, /* LEDs lit: 3,4,5 */ /* 5 */ { 90, 104, 110, 130, 146 }, /* LEDs lit: 2,4,5 */ /* 6 */ { 90, 96, 110, 120, 130 }, /* LEDs lit: 3,4,6 */ /* 7 */ { 90, 96, 110, 130, 146 }, /* LEDs lit: 2,4,6 */ /* 8 */ { 96, 109, 128, 146, 156 }, /* LEDs lit: 1,2,4 */ /* 9 */ { 90, 104, 128, 146, 156 }, /* LEDs lit: 1,2,5 */ /* E models voltage limits, for: * - Fortress (750E, 1050E, 1425E, and 2250E) * - Fortress Rackmount (750, 1050, 1425, and 2250 VA) * - Patriot Pro II (400E, 750E, and 1000E) */ /* M low boost nominal buck high */ /* 0 */ { 200, 222, 240, 250, 284 }, /* LEDs lit: 2,3,4 */ /* 1 */ { 200, 222, 240, 264, 290 }, /* LEDs lit: 1,3,4 */ /* 2 */ { 188, 210, 240, 250, 284 }, /* LEDs lit: 2,3,5 */ /* 3 */ { 188, 210, 240, 264, 290 }, /* LEDs lit: 1,3,5 */ /* 4 */ { 188, 210, 230, 244, 270 }, /* LEDs lit: 3,4,5 (Default) */ /* 5 */ { 188, 210, 230, 250, 284 }, /* LEDs lit: 2,4,5 */ /* 6 */ { 180, 200, 230, 244, 270 }, /* LEDs lit: 3,4,6 */ /* 7 */ { 180, 200, 230, 250, 284 }, /* LEDs lit: 2,4,6 */ /* 8 */ { 165, 188, 208, 222, 244 }, /* LEDs lit: 4,5,6 */ /* 9 */ { 165, 188, 208, 244, 270 } /* LEDs lit: 3,5,6 */ }; if (strspn(item->value, "0123456789") != strlen(item->value)) { upsdebugx(2, "%s: non numerical value [%s: %s]", __func__, item->info_type, item->value); return -1; } index = strtol(item->value, NULL, 10); if (index < 0 || index > 9) { upsdebugx(2, "%s: value '%ld' out of range [0..9]", __func__, index); return -1; } nominal_voltage = dstate_getinfo("input.voltage.nominal"); if (!nominal_voltage) nominal_voltage = dstate_getinfo("output.voltage.nominal"); if (!nominal_voltage) { upsdebugx(2, "%s: unable to get nominal voltage", __func__); return -1; } /* E models */ if (strtol(nominal_voltage, NULL, 10) > 160) index += 10; if (!strcasecmp(item->info_type, "input.transfer.low") || !strcasecmp(item->info_type, "input.transfer.boost.low")) { val = voltage_settings[index].low; } else if (!strcasecmp(item->info_type, "input.transfer.boost.high")) { val = voltage_settings[index].boost; } else if (!strcasecmp(item->info_type, "input.voltage.nominal") || !strcasecmp(item->info_type, "output.voltage.nominal")) { val = voltage_settings[index].nominal; } else if (!strcasecmp(item->info_type, "input.transfer.trim.low")) { val = voltage_settings[index].buck; } else if (!strcasecmp(item->info_type, "input.transfer.trim.high") || !strcasecmp(item->info_type, "input.transfer.high")) { val = voltage_settings[index].high; } else { /* Don't know what happened */ return -1; } snprintf_dynamic(value, valuelen, item->dfl, "%d", val); return 0; } /* == Subdriver interface == */ subdriver_t bestups_subdriver = { BESTUPS_VERSION, bestups_claim, bestups_qx2nut, bestups_initups, NULL, bestups_makevartable, NULL, NULL, #ifdef TESTING bestups_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/nutdrv_qx_ablerex.c0000644000175000017500000003677515044656702014665 00000000000000/* nutdrv_qx_ablerex.c - Subdriver for Ablerex Qx protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * 2021 Ablerex Software * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_ablerex.h" #define ABLEREX_VERSION "Ablerex 0.02" static int Q5_Vbc = -1; static int ablerexQ5Vb = -1; static int ablerex_Q5(item_t *item, char *value, const size_t valuelen) { int Q5_Fout, Q5_Vb, Q5_O_Cur, Q5_Err; #ifdef ABLEREX_WITH_Q5_InvW int Q5_InvW; #endif #ifdef ABLEREX_WITH_RawValue int RawValue = ((int)(unsigned char)item->value[0]) * 256 + (unsigned char)item->value[1]; #endif /* // real code below, this is for dev-testing ablerexQ5Vb = ((int)(unsigned char)buf[7]) * 256 + (unsigned char)buf[8]; Q5_Vbc = ((int)(unsigned char)buf[9]) * 256 + (unsigned char)buf[10]; */ upsdebugx(2, "Q51: %d %d %d %d %d %d", item->answer[0], item->answer[1], item->answer[2], item->answer[3], item->answer[4], item->answer[5]); upsdebugx(2, "Q52: %d %d %d %d %d %d", item->answer[6], item->answer[7], item->answer[8], item->answer[9], item->answer[10], item->answer[11]); upsdebugx(2, "Q53: %d %d %d %d", item->answer[12], item->answer[13], item->answer[14], item->answer[15]); Q5_Fout = (unsigned char)item->answer[1] * 256 + (unsigned char)item->answer[2]; Q5_Vb = (unsigned char)item->answer[7] * 256 + (unsigned char)item->answer[8]; Q5_Vbc = (unsigned char)item->answer[9] * 256 + (unsigned char)item->answer[10]; #ifdef ABLEREX_WITH_Q5_InvW Q5_InvW = (unsigned char)item->answer[11] * 256 + (unsigned char)item->answer[12]; #endif Q5_Err = (unsigned char)item->answer[13] * 256 + (unsigned char)item->answer[14]; Q5_O_Cur = (unsigned char)item->answer[15] * 256 + (unsigned char)item->answer[16]; ablerexQ5Vb = Q5_Vb; upsdebugx(2, "Q5: %.1f %d %.1f", 0.1 * Q5_Fout, Q5_Err, 0.1 * Q5_O_Cur); upsdebugx(2, "Q5Vb: %d Vbc %d", Q5_Vb, Q5_Vbc); #ifdef ABLEREX_WITH_Q5_InvW upsdebugx(2, "Q5_InvW: %d", Q5_InvW); #endif dstate_setinfo("output.frequency", "%.1f", 0.1 * Q5_Fout); /* alarm init and commit happens in main driver */ snprintf(value, valuelen, "%d", Q5_Err); alarm_set(value); dstate_setinfo("output.current", "%.1f", 0.1 * Q5_O_Cur); snprintf(value, valuelen, "%.1f", Q5_Fout * 0.1); #ifdef ABLEREX_WITH_RawValue switch (item->from) { case 1: snprintf(value, valuelen, "%.1f", RawValue * 0.1); upsdebugx(2, "Q51: %.1f", 0.1*RawValue); break; case 13: snprintf(value, valuelen, "%.0f", RawValue); upsdebugx(2, "Q52: %.0f", 0.1*RawValue); break; case 15: snprintf(value, valuelen, "%.1f", RawValue * 0.1); upsdebugx(2, "Q53: %.1f", 0.1*RawValue); break; default: /* Don't know what happened */ return -1; } #endif return 0; } static int ablerex_battery(item_t *item, char *value, const size_t valuelen) { double BattV = 0.0; double nomBattV = 0.0; double battvoltact = 0.0; BattV = strtod(item->value, NULL); upsdebugx(2, "battvoltact2: %.2f", BattV); if (!dstate_getinfo("battery.voltage.nominal")) { snprintf(value, valuelen, "%.2f", BattV); return 0; } nomBattV = strtod(dstate_getinfo("battery.voltage.nominal"), NULL); upsdebugx(2, "battvoltact1: %.2f", nomBattV); /* * //return 0; */ if (ablerexQ5Vb > 0) { battvoltact = ablerexQ5Vb * nomBattV / 1200; } else { if (BattV > 3.0) { battvoltact = BattV; } else { battvoltact = BattV * 6 * nomBattV / 12; } } snprintf(value, valuelen, "%.2f", battvoltact); upsdebugx(2, "battvoltact: %.2f / %.2f", battvoltact, BattV); return 0; } static int ablerex_battery_charge(double BattIn) { const double onlineP[] = { 2.22, 2.21, 2.20, 2.19, 2.18, 2.17, 2.16, 2.15, 2.14, 2.13, 2.12, 2.11, 2.10, 2.09, 2.08, 2.07, 2.06, 2.05, 2.04, 2.03, 2.02, 2.01, 2.00, 1.99, 1.98, 1.97, 1.96, 1.95, 1.94, 1.93, 1.92, 1.91, 1.90, 1.89, 1.88, 1.87, 1.86, 1.85, 1.84, 1.83, 1.82, 1.81, 1.80, 1.79, 1.78, 1.77, 1.76, 1.75, 1.74, 1.73, 1.72, 1.71, 1.70, 1.69, 1.68, 1.67 }; const int onlineC[] = { 100, 90, 88, 87, 85, 83, 82, 80, 78, 77, 75, 73, 72, 70, 68, 65, 65, 62, 62, 58, 58, 55, 55, 53, 52, 50, 48, 47, 45, 43, 42, 40, 38, 37, 35, 33, 32, 30, 28, 27, 25, 23, 22, 20, 18, 17, 15, 13, 12, 10, 8, 7, 5, 3, 2, 0, -1 }; const double offlineP[] = { 13.5, 13.3, 13.2, 13.1, 13, 12.9, 12.8, 12.7, 12.6, 12.5, 12.4, 12.3, 12.2, 12.1, 12, 11.9, 11.8, 11.7, 11.6, 11.5, 11.4, 11.3, 11.2, 11.1, 11, 10.9, 10.8, 10.7, 10.6, 10.5, 10.4, 10.3, 10.2, 10.1, 10 }; const int offlineC[] = { 100, 90, 88, 86, 83, 80, 77, 74, 72, 69, 66, 63, 61, 58, 55, 52, 49, 47, 44, 41, 38, 36, 33, 30, 27, 24, 22, 19, 16, 13, 11, 8, 5, 2, 0, -1 }; int charge = 0; int i; if (BattIn < 3.0) { for (i = 0; onlineC[i] > 0; i++) { if (BattIn >= onlineP[i]) { charge = onlineC[i]; break; } } } else { /* * //double nomBattV = strtod(dstate_getinfo("battery.voltage.nominal"), NULL); * //double battV = BattIn / (nomBattV / 12); */ for (i = 0; offlineC[i] > 0; i++) { if (BattIn >= offlineP[i]) { charge = offlineC[i]; break; } } } return charge; } static int ablerex_batterycharge(item_t *item, char *value, const size_t valuelen) { double BattV = 0.0; double nomBattV = 0.0; int BattP; BattV = strtod(item->value, NULL); upsdebugx(2, "battvoltc2: %.2f", BattV); if (!dstate_getinfo("battery.voltage.nominal")) { snprintf(value, valuelen, "%d", 100); return 0; } nomBattV = strtod(dstate_getinfo("battery.voltage.nominal"), NULL); upsdebugx(2, "battvv1: %.2f", nomBattV); /* * //return 0; */ if (BattV > 3.0) { BattV = BattV / (nomBattV / 12); } BattP = ablerex_battery_charge(BattV); /* * //dstate_setinfo("battery.charge", "%.0f", BattP); */ snprintf(value, valuelen, "%d", BattP); upsdebugx(2, "battcharge: %d", BattP); return 0; } static int ablerex_initbattery(item_t *item, char *value, const size_t valuelen) { double nomBattV = strtod(dstate_getinfo("battery.voltage.nominal"), NULL); double batthigh = 0.0; double battlow = 0.0; if (Q5_Vbc > 0) { battlow = Q5_Vbc * nomBattV / 1200; } else { battlow = 960 * nomBattV / 1200; } batthigh = 1365 * nomBattV / 1200; switch (item->from) { case 1: snprintf(value, valuelen, "%.2f", battlow); upsdebugx(2, "BattLow: %.2f", battlow); break; case 2: snprintf(value, valuelen, "%.2f", batthigh); upsdebugx(2, "BattHigh: %.2f", batthigh); break; default: /* Don't know what happened */ return -1; } return 0; } static int ablerex_At(item_t *item, char *value, const size_t valuelen) { int RawValue = 0; RawValue = (unsigned char)item->answer[1] * 65536 * 256 + (unsigned char)item->answer[2] * 65536 + (unsigned char)item->answer[3] * 256 + (unsigned char)item->answer[4]; snprintf(value, valuelen, "%d", RawValue); upsdebugx(2, "At: %d", RawValue); return 0; } static int ablerex_TR(item_t *item, char *value, const size_t valuelen) { char TR[8]; TR[0] = item->answer[1]; TR[1] = item->answer[2]; TR[2] = item->answer[3]; TR[3] = item->answer[4]; TR[4] = 0; snprintf(value, valuelen, "%s", TR); upsdebugx(2, "At: %s", TR); return 0; } static int ablerex_process_status_bits(item_t *item, char *value, const size_t valuelen) { char *val = ""; switch (item->from) { case 40: /* Bypass/Boost or Buck Active */ if (item->value[0] == '1') { double vi, vo; vi = strtod(dstate_getinfo("input.voltage"), NULL); vo = strtod(dstate_getinfo("output.voltage"), NULL); if (item->value[2] == '1') {/* UPS Type is Standby (0 is On_line) */ if (vo < 0.5 * vi) { upsdebugx(2, "%s: output voltage too low", __func__); return -1; } else if (vo < 0.95 * vi) { status_set("TRIM"); } else if (vo < 1.05 * vi) { status_set("BYPASS"); } else if (vo < 1.5 * vi) { status_set("BOOST"); } else { upsdebugx(2, "%s: output voltage too high", __func__); return -1; } } else { status_set("BYPASS"); } } break; case 41: /* UPS Failed - ups.alarm */ if (item->value[0] == '1') { /* Battery abnormal */ status_set("RB"); } { /* scope */ double vout = strtod(dstate_getinfo("output.voltage"), NULL); if (vout < 50.0) { status_set("OFF"); } } break; default: /* Don't know what happened */ return -1; } snprintf(value, valuelen, "%s", val); return 0; } /* qx2nut lookup table */ static item_t ablerex_qx2nut[] = { /* * > [Q1\r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000\r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ { "input.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.voltage.fault", 0, NULL, "Q1\r", "", 47, '(', "", 7, 11, "%.1f", 0, NULL, NULL, NULL }, { "output.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 13, 17, "%.1f", 0, NULL, NULL, NULL }, { "ups.load", 0, NULL, "Q1\r", "", 47, '(', "", 19, 21, "%.0f", 0, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "Q1\r", "", 47, '(', "", 23, 26, "%.1f", 0, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 28, 31, "%.2f", 0, NULL, NULL, ablerex_battery }, { "battery.charge", 0, NULL, "Q1\r", "", 47, '(', "", 28, 31, "%.2f", 0, NULL, NULL, ablerex_batterycharge }, { "ups.temperature", 0, NULL, "Q1\r", "", 47, '(', "", 33, 36, "%.1f", 0, NULL, NULL, NULL }, /* Status bits */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 38, 38, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Utility Fail (Immediate) */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 39, 39, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Battery Low */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 40, 42, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, ablerex_process_status_bits }, /* Ablerex Bypass/Boost or Buck Active */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 41, 41, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, ablerex_process_status_bits }, /* Ablerex UPS Failed */ { "ups.alarm", 0, NULL, "Q1\r", "", 47, '(', "", 41, 41, NULL, 0, NULL, NULL, blazer_process_status_bits }, /* UPS Failed */ { "ups.type", 0, NULL, "Q1\r", "", 47, '(', "", 42, 42, "%s", QX_FLAG_STATIC, NULL, NULL, blazer_process_status_bits }, /* UPS Type */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 43, 43, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Test in Progress */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 44, 44, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Shutdown Active */ { "ups.beeper.status", 0, NULL, "Q1\r", "", 47, '(', "", 45, 45, "%s", 0, NULL, NULL, blazer_process_status_bits }, /* Beeper status */ /* * > [F\r] * < [#220.0 000 024.0 50.0\r] * 0123456789012345678901 * 0 1 2 */ { "output.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 1, 5, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "output.current.nominal", 0, NULL, "F\r", "", 22, '#', "", 7, 9, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "battery.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 11, 15, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "output.frequency.nominal", 0, NULL, "F\r", "", 22, '#', "", 17, 20, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "battery.voltage.low", 0, NULL, "F\r", "", 22, '#', "", 1, 2, "%.2f", QX_FLAG_QUICK_POLL, NULL, NULL, ablerex_initbattery }, { "battery.voltage.high", 0, NULL, "F\r", "", 22, '#', "", 2, 3, "%.2f", QX_FLAG_QUICK_POLL, NULL, NULL, ablerex_initbattery }, /* Ablerex */ { "output.frequency", 0, NULL, "Q5\r", "", 22, '(', "", 1, 18, "%.1f", 0, NULL, NULL, ablerex_Q5 }, { "battery.runtime", 0, NULL, "At\r", "", 0, '(', "", 0, 0, "%d", 0, NULL, NULL, ablerex_At }, /* * //{ "ups.alarm", 0, NULL, "Q5\r", "", 22, '(', "", 1, 14, "%.0f", 0, QX_FLAG_QUICK_POLL, NULL, ablerex_Q5 }, */ { "ups.test.result", 0, NULL, "TR\r", "", 0, '#', "", 0, 0, "%s", 0, NULL, NULL, ablerex_TR }, /* * //{ "output.current", 0, NULL, "Q5\r", "", 22, '(', "", 1, 16, "%.1f", 0, QX_FLAG_QUICK_POLL, NULL, ablerex_Q5 }, */ /* * > [I\r] * < [#------------- ------ VT12046Q \r] * 012345678901234567890123456789012345678 * 0 1 2 3 */ { "device.mfr", 0, NULL, "I\r", "", 39, '#', "", 1, 15, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "device.model", 0, NULL, "I\r", "", 39, '#', "", 17, 26, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "ups.firmware", 0, NULL, "I\r", "", 39, '#', "", 28, 37, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* Instant commands */ { "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.off", 0, NULL, "S.2\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%sR0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, blazer_r_ondelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_ONDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, blazer_r_offdelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_OFFDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* Testing table */ #ifdef TESTING static testing_t ablerex_testing[] = { { "Q1\r", "(215.0 195.0 230.0 014 49.0 22.7 30.0 00000000\r", -1 }, { "F\r", "#230.0 000 024.0 50.0\r", -1 }, { "I\r", "#NOT_A_LIVE_UPS TESTING TESTING \r", -1 }, { "Q\r", "", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0000\r", "", -1 }, { "T04\r", "", -1 }, { "TL\r", "", -1 }, { "T\r", "", -1 }, { "CT\r", "", -1 }, { NULL } }; #endif /* TESTING */ /* Subdriver-specific initups */ static void ablerex_initups(void) { blazer_initups(ablerex_qx2nut); } /* Subdriver interface */ subdriver_t ablerex_subdriver = { ABLEREX_VERSION, blazer_claim, ablerex_qx2nut, ablerex_initups, NULL, blazer_makevartable, "ACK", NULL, #ifdef TESTING ablerex_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/apc-ats-mib.h0000644000175000017500000000176714670526611013223 00000000000000/* apcats-mib.h - subdriver to monitor apcats SNMP devices with NUT * * Copyright (C) * 2011 - 2012 Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef APCATS_MIB_H #define APCATS_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t apc_ats; #endif /* APCATS_MIB_H */ nut-2.8.4/drivers/eaton-pdu-genesis2-mib.h0000644000175000017500000000233714670526611015276 00000000000000/* eaton-pdu-genesis2-mib.h - subdriver to monitor Eaton ePDU SNMP devices with NUT * * Copyright (C) * 2010 Arjen de Korte * 2011 - 2012 Arnaud Quette * 2017 Arnaud Quette * 2017 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef EATON_EPDU_GENESIS_MIB_H #define EATON_EPDU_GENESIS_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t aphel_genesisII; #endif /* EATON_EPDU_GENESIS_MIB_H */ nut-2.8.4/drivers/eaton-pdu-marlin-mib.h0000644000175000017500000000232714670526611015040 00000000000000/* eaton-pdu-marlin-mib.h - subdriver to monitor Eaton ePDU SNMP devices with NUT * * Copyright (C) * 2010 Arjen de Korte * 2011 - 2012 Arnaud Quette * 2017 Arnaud Quette * 2017 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef EATON_EPDU_MARLIN_MIB_H #define EATON_EPDU_MARLIN_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t eaton_marlin; #endif /* EATON_EPDU_MARLIN_MIB_H */ nut-2.8.4/drivers/ietf-mib.c0000644000175000017500000005261315044656702012612 00000000000000/* ietf-mib.c - data to monitor SNMP UPS (RFC 1628 compliant) with NUT * * Copyright (C) 2002-2006 * 2002-2012 Arnaud Quette * 2002-2006 Niels Baggesen * 2002-2006 Arjen de Korte * * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "ietf-mib.h" #define IETF_MIB_VERSION "1.55" /* SNMP OIDs set */ #define IETF_OID_UPS_MIB "1.3.6.1.2.1.33.1." #define IETF_SYSOID ".1.3.6.1.2.1.33" /* NOTE: Currently the Tripplite UPSes await user-validation of their * real SNMP OID tree, so temporarily the IETF tree is used as "tripplite" * for the mapping purposes; the devices ave their entry point OID though. * For more details see: * https://github.com/networkupstools/nut/issues/309 * https://github.com/networkupstools/nut/issues/171 * Also related to: * https://github.com/networkupstools/nut/issues/270 */ #define TRIPPLITE_SYSOID ".1.3.6.1.4.1.850.1" /* #define DEBUG */ static info_lkp_t ietf_battery_info[] = { info_lkp_default(1, ""), /* unknown */ info_lkp_default(2, ""), /* batteryNormal */ info_lkp_default(3, "LB"), /* batteryLow */ info_lkp_default(4, "LB"), /* batteryDepleted */ info_lkp_sentinel }; static info_lkp_t ietf_power_source_info[] = { info_lkp_default(1, ""), /* other */ info_lkp_default(2, "OFF"), /* none */ info_lkp_default(3, "OL"), /* normal */ info_lkp_default(4, "OL BYPASS"), /* bypass */ info_lkp_default(5, "OB"), /* battery */ info_lkp_default(6, "OL BOOST"), /* booster */ info_lkp_default(7, "OL TRIM"), /* reducer */ info_lkp_sentinel }; static info_lkp_t ietf_overload_info[] = { info_lkp_default(1, "OVER"), /* output overload */ info_lkp_sentinel }; static info_lkp_t ietf_test_active_info[] = { info_lkp_default(1, ""), /* upsTestNoTestsInitiated */ info_lkp_default(2, ""), /* upsTestAbortTestInProgress */ info_lkp_default(3, "TEST"), /* upsTestGeneralSystemsTest */ info_lkp_default(4, "TEST"), /* upsTestQuickBatteryTest */ info_lkp_default(5, "CAL"), /* upsTestDeepBatteryCalibration */ info_lkp_sentinel }; static info_lkp_t ietf_test_result_info[] = { info_lkp_default(1, "done and passed"), info_lkp_default(2, "done and warning"), info_lkp_default(3, "done and error"), info_lkp_default(4, "aborted"), info_lkp_default(5, "in progress"), info_lkp_default(6, "no test initiated"), info_lkp_sentinel }; #ifdef DEBUG static info_lkp_t ietf_shutdown_type_info[] = { info_lkp_default(1, "output"), info_lkp_default(2, "system"), info_lkp_sentinel }; #endif static info_lkp_t ietf_yes_no_info[] = { info_lkp_default(1, "yes"), info_lkp_default(2, "no"), info_lkp_sentinel }; static info_lkp_t ietf_beeper_status_info[] = { info_lkp_default(1, "disabled"), info_lkp_default(2, "enabled"), info_lkp_default(3, "muted"), info_lkp_sentinel }; /* Snmp2NUT lookup table info_type, info_flags, info_len, OID, dfl, flags, oid2info, setvar */ static snmp_info_t ietf_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* The Device Identification group */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "1.1.0", "Generic", SU_FLAG_STATIC, NULL), /* upsIdentManufacturer */ snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "1.2.0", "Generic SNMP UPS", SU_FLAG_STATIC, NULL), /* upsIdentModel */ snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "1.3.0", "", SU_FLAG_STATIC, NULL), /* upsIdentUPSSoftwareVersion */ snmp_info_default("ups.firmware.aux", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "1.4.0", "", SU_FLAG_STATIC, NULL), /* upsIdentAgentSoftwareVersion */ #ifdef DEBUG snmp_info_default("debug.upsIdentName", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "1.5.0", "", 0, NULL), /* upsIdentName */ snmp_info_default("debug.upsIdentAttachedDevices", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "1.6.0", "", 0, NULL), /* upsIdentAttachedDevices */ #endif /* Battery Group */ snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "2.1.0", "", SU_STATUS_BATT, ietf_battery_info), /* upsBatteryStatus */ #ifdef DEBUG snmp_info_default("debug.upsSecondsOnBattery", 0, 1.0, IETF_OID_UPS_MIB "2.2.0", "", 0, NULL), /* upsSecondsOnBattery */ #endif snmp_info_default("battery.runtime", 0, 60.0, IETF_OID_UPS_MIB "2.3.0", "", 0, NULL), /* upsEstimatedMinutesRemaining */ snmp_info_default("battery.charge", 0, 1, IETF_OID_UPS_MIB "2.4.0", "", 0, NULL), /* upsEstimatedChargeRemaining */ snmp_info_default("battery.voltage", 0, 0.1, IETF_OID_UPS_MIB "2.5.0", "", 0, NULL), /* upsBatteryVoltage */ snmp_info_default("battery.current", 0, 0.1, IETF_OID_UPS_MIB "2.6.0", "", SU_FLAG_NEGINVALID, NULL), /* upsBatteryCurrent */ snmp_info_default("battery.temperature", 0, 1.0, IETF_OID_UPS_MIB "2.7.0", "", 0, NULL), /* upsBatteryTemperature */ /* Input Group */ #ifdef DEBUG snmp_info_default("debug.upsInputLineBads", 0, 1.0, IETF_OID_UPS_MIB "3.1.0", "", 0, NULL), /* upsInputLineBads */ #endif snmp_info_default("input.phases", 0, 1.0, IETF_OID_UPS_MIB "3.2.0", "", 0, NULL), /* upsInputNumLines */ #ifdef DEBUG snmp_info_default("debug.upsInputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.1.1", "", SU_INPUT_1, NULL), /* upsInputLineIndex */ snmp_info_default("debug.[1].upsInputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.1.1", "", SU_INPUT_3, NULL), snmp_info_default("debug.[2].upsInputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.1.2", "", SU_INPUT_3, NULL), snmp_info_default("debug.[3].upsInputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.1.3", "", SU_INPUT_3, NULL), #endif snmp_info_default("input.frequency", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.2.1", "", SU_INPUT_1, NULL), /* upsInputFrequency */ snmp_info_default("input.L1.frequency", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.2.1", "", SU_INPUT_3, NULL), snmp_info_default("input.L2.frequency", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.2.2", "", SU_INPUT_3, NULL), snmp_info_default("input.L3.frequency", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.2.3", "", SU_INPUT_3, NULL), snmp_info_default("input.voltage", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.3.1", "", SU_INPUT_1, NULL), /* upsInputVoltage */ snmp_info_default("input.L1-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.3.1", "", SU_INPUT_3, NULL), snmp_info_default("input.L2-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.3.2", "", SU_INPUT_3, NULL), snmp_info_default("input.L3-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.3.3", "", SU_INPUT_3, NULL), snmp_info_default("input.current", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.4.1", "", SU_INPUT_1 |SU_FLAG_NEGINVALID, NULL), /* upsInputCurrent */ snmp_info_default("input.L1.current", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.4.1", "", SU_INPUT_3, NULL), snmp_info_default("input.L2.current", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.4.2", "", SU_INPUT_3, NULL), snmp_info_default("input.L3.current", 0, 0.1, IETF_OID_UPS_MIB "3.3.1.4.3", "", SU_INPUT_3, NULL), snmp_info_default("input.realpower", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.5.1", "", SU_INPUT_1 | SU_FLAG_NEGINVALID, NULL), /* upsInputTruePower */ snmp_info_default("input.L1.realpower", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.5.1", "", SU_INPUT_3, NULL), snmp_info_default("input.L2.realpower", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.5.2", "", SU_INPUT_3, NULL), snmp_info_default("input.L3.realpower", 0, 1.0, IETF_OID_UPS_MIB "3.3.1.5.3", "", SU_INPUT_3, NULL), /* Output Group */ snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "4.1.0", "", SU_STATUS_PWR, ietf_power_source_info), /* upsOutputSource */ snmp_info_default("output.frequency", 0, 0.1, IETF_OID_UPS_MIB "4.2.0", "", 0, NULL), /* upsOutputFrequency */ snmp_info_default("output.phases", 0, 1.0, IETF_OID_UPS_MIB "4.3.0", "", 0, NULL), /* upsOutputNumLines */ #ifdef DEBUG snmp_info_default("debug.upsOutputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.1.1", "", SU_OUTPUT_1, NULL), /* upsOutputLineIndex */ snmp_info_default("debug.[1].upsOutputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.1.1", "", SU_OUTPUT_3, NULL), snmp_info_default("debug.[2].upsOutputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.1.2", "", SU_OUTPUT_3, NULL), snmp_info_default("debug.[3].upsOutputLineIndex", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.1.3", "", SU_OUTPUT_3, NULL), #endif snmp_info_default("output.voltage", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.2.1", "", SU_OUTPUT_1, NULL), /* upsOutputVoltage */ snmp_info_default("output.L1-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.2.1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.2.2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.2.3", "", SU_OUTPUT_3, NULL), snmp_info_default("output.current", 0, 0.1, IETF_OID_UPS_MIB "4.4.1.3.1", "", SU_OUTPUT_1 | SU_FLAG_NEGINVALID, NULL), /* upsOutputCurrent */ snmp_info_default("output.L1.current", 0, 0.1, IETF_OID_UPS_MIB "4.4.1.3.1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2.current", 0, 0.1, IETF_OID_UPS_MIB "4.4.1.3.2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3.current", 0, 0.1, IETF_OID_UPS_MIB "4.4.1.3.3", "", SU_OUTPUT_3, NULL), snmp_info_default("output.realpower", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.4.1", "", SU_OUTPUT_1 | SU_FLAG_NEGINVALID, NULL), /* upsOutputPower */ snmp_info_default("output.L1.realpower", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.4.1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2.realpower", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.4.2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3.realpower", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.4.3", "", SU_OUTPUT_3, NULL), snmp_info_default("ups.load", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.5.1", "", SU_OUTPUT_1, NULL), /* upsOutputPercentLoad */ snmp_info_default("output.L1.power.percent", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.5.1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2.power.percent", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.5.2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3.power.percent", 0, 1.0, IETF_OID_UPS_MIB "4.4.1.5.3", "", SU_OUTPUT_3, NULL), /* Bypass Group */ snmp_info_default("input.bypass.phases", 0, 1.0, IETF_OID_UPS_MIB "5.2.0", "", SU_FLAG_NEGINVALID, NULL), /* upsBypassNumLines */ snmp_info_default("input.bypass.frequency", 0, 0.1, IETF_OID_UPS_MIB "5.1.0", "", SU_BYPASS_1 | SU_BYPASS_3 | SU_FLAG_NEGINVALID, NULL), /* upsBypassFrequency */ #ifdef DEBUG snmp_info_default("debug.upsBypassLineIndex", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.1.1", "", SU_BYPASS_1, NULL), /* upsBypassLineIndex */ snmp_info_default("debug.[1].upsBypassLineIndex", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.1.1", "", SU_BYPASS_3, NULL), snmp_info_default("debug.[2].upsBypassLineIndex", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.1.2", "", SU_BYPASS_3, NULL), snmp_info_default("debug.[3].upsBypassLineIndex", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.1.3", "", SU_BYPASS_3, NULL), #endif snmp_info_default("input.bypass.voltage", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.2.1", "", SU_BYPASS_1, NULL), /* upsBypassVoltage */ snmp_info_default("input.bypass.L1-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.2.1", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L2-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.2.2", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L3-N.voltage", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.2.3", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.current", 0, 0.1, IETF_OID_UPS_MIB "5.3.1.3.1", "", SU_BYPASS_1, NULL), /* upsBypassCurrent */ snmp_info_default("input.bypass.L1.current", 0, 0.1, IETF_OID_UPS_MIB "5.3.1.3.1", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L2.current", 0, 0.1, IETF_OID_UPS_MIB "5.3.1.3.2", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L3.current", 0, 0.1, IETF_OID_UPS_MIB "5.3.1.3.3", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.realpower", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.4.1", "", SU_BYPASS_1, NULL), /* upsBypassPower */ snmp_info_default("input.bypass.L1.realpower", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.4.1", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L2.realpower", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.4.2", "", SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L3.realpower", 0, 1.0, IETF_OID_UPS_MIB "5.3.1.4.3", "", SU_BYPASS_3, NULL), /* Alarm Group */ #ifdef DEBUG snmp_info_default("debug.upsAlarmsPresent", 0, 1.0, IETF_OID_UPS_MIB "6.1.0", "", 0, NULL), /* upsAlarmsPresent */ snmp_info_default("debug.upsAlarmBatteryBad", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.1", "", 0, NULL), /* upsAlarmBatteryBad */ snmp_info_default("debug.upsAlarmOnBattery", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.2", "", 0, NULL), /* upsAlarmOnBattery */ snmp_info_default("debug.upsAlarmLowBattery", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.3", "", 0, NULL), /* upsAlarmLowBattery */ snmp_info_default("debug.upsAlarmDepletedBattery", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.4", "", 0, NULL), /* upsAlarmDepletedBattery */ snmp_info_default("debug.upsAlarmTempBad", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.5", "", 0, NULL), /* upsAlarmTempBad */ snmp_info_default("debug.upsAlarmInputBad", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.6", "", 0, NULL), /* upsAlarmInputBad */ snmp_info_default("debug.upsAlarmOutputBad", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.7", "", 0, NULL), /* upsAlarmOutputBad */ #endif snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.8", "", 0, ietf_overload_info), /* upsAlarmOutputOverload */ #ifdef DEBUG snmp_info_default("debug.upsAlarmOnBypass", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.9", "", 0, NULL), /* upsAlarmOnBypass */ snmp_info_default("debug.upsAlarmBypassBad", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.10", "", 0, NULL), /* upsAlarmBypassBad */ snmp_info_default("debug.upsAlarmOutputOffAsRequested", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.11", "", 0, NULL), /* upsAlarmOutputOffAsRequested */ snmp_info_default("debug.upsAlarmUpsOffAsRequested", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.12", "", 0, NULL), /* upsAlarmUpsOffAsRequested */ snmp_info_default("debug.upsAlarmChargerFailed", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.13", "", 0, NULL), /* upsAlarmChargerFailed */ snmp_info_default("debug.upsAlarmUpsOutputOff", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.14", "", 0, NULL), /* upsAlarmUpsOutputOff */ snmp_info_default("debug.upsAlarmUpsSystemOff", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.15", "", 0, NULL), /* upsAlarmUpsSystemOff */ snmp_info_default("debug.upsAlarmFanFailure", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.16", "", 0, NULL), /* upsAlarmFanFailure */ snmp_info_default("debug.upsAlarmFuseFailure", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.17", "", 0, NULL), /* upsAlarmFuseFailure */ snmp_info_default("debug.upsAlarmGeneralFault", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.18", "", 0, NULL), /* upsAlarmGeneralFault */ snmp_info_default("debug.upsAlarmDiagnosticTestFailed", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.19", "", 0, NULL), /* upsAlarmDiagnosticTestFailed */ snmp_info_default("debug.upsAlarmCommunicationsLost", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.20", "", 0, NULL), /* upsAlarmCommunicationsLost */ snmp_info_default("debug.upsAlarmAwaitingPower", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.21", "", 0, NULL), /* upsAlarmAwaitingPower */ snmp_info_default("debug.upsAlarmShutdownPending", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.22", "", 0, NULL), /* upsAlarmShutdownPending */ snmp_info_default("debug.upsAlarmShutdownImminent", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.23", "", 0, NULL), /* upsAlarmShutdownImminent */ snmp_info_default("debug.upsAlarmTestInProgress", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "6.3.24", "", 0, NULL), /* upsAlarmTestInProgress */ #endif /* Test Group */ snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "7.1.0", "", 0, ietf_test_active_info), /* upsTestId */ snmp_info_default("test.battery.stop", 0, 1, IETF_OID_UPS_MIB "7.1.0", "0", SU_TYPE_CMD, NULL), /* upsTestAbortTestInProgress */ snmp_info_default("test.battery.start", 0, 1, IETF_OID_UPS_MIB "7.1.0", "0", SU_TYPE_CMD, NULL), /* upsTestGeneralSystemsTest */ snmp_info_default("test.battery.start.quick", 0, 1, IETF_OID_UPS_MIB "7.1.0", "0", SU_TYPE_CMD, NULL), /* upsTestQuickBatteryTest */ snmp_info_default("test.battery.start.deep", 0, 1, IETF_OID_UPS_MIB "7.1.0", "0", SU_TYPE_CMD, NULL), /* upsTestDeepBatteryCalibration */ #ifdef DEBUG snmp_info_default("debug.upsTestSpinLock", 0, 1.0, IETF_OID_UPS_MIB "7.2.0", "", 0, NULL), /* upsTestSpinLock */ #endif snmp_info_default("ups.test.result", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "7.3.0", "", 0, ietf_test_result_info), /* upsTestResultsSummary */ #ifdef DEBUG snmp_info_default("debug.upsTestResultsDetail", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "7.4.0", "", 0, NULL), /* upsTestResultsDetail */ snmp_info_default("debug.upsTestStartTime", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "7.5.0", "", 0, NULL), /* upsTestStartTime */ snmp_info_default("debug.upsTestElapsedTime", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "7.6.0", "", 0, NULL), /* upsTestElapsedTime */ #endif /* Control Group */ #ifdef DEBUG snmp_info_default("debug.upsShutdownType", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "8.1.0", "", 0, ietf_shutdown_type_info), /* upsShutdownType */ #endif snmp_info_default("ups.timer.shutdown", ST_FLAG_STRING | ST_FLAG_RW, 8, IETF_OID_UPS_MIB "8.2.0", "", 0, NULL), /* upsShutdownAfterDelay*/ snmp_info_default("load.off", 0, 1, IETF_OID_UPS_MIB "8.2.0", "0", SU_TYPE_CMD, NULL), snmp_info_default("ups.timer.start", ST_FLAG_STRING | ST_FLAG_RW, 8, IETF_OID_UPS_MIB "8.3.0", "", 0, NULL), /* upsStartupAfterDelay */ snmp_info_default("load.on", 0, 1, IETF_OID_UPS_MIB "8.3.0", "0", SU_TYPE_CMD, NULL), snmp_info_default("ups.timer.reboot", ST_FLAG_STRING | ST_FLAG_RW, 8, IETF_OID_UPS_MIB "8.4.0", "", 0, NULL), /* upsRebootWithDuration */ snmp_info_default("ups.start.auto", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "8.5.0", "", 0, ietf_yes_no_info), /* upsAutoRestart */ /* Configuration Group */ snmp_info_default("input.voltage.nominal", 0, 1.0, IETF_OID_UPS_MIB "9.1.0", "", SU_FLAG_NEGINVALID, NULL), /* upsConfigInputVoltage */ snmp_info_default("input.frequency.nominal", 0, 0.1, IETF_OID_UPS_MIB "9.2.0", "", SU_FLAG_NEGINVALID, NULL), /* upsConfigInputFreq */ snmp_info_default("output.voltage.nominal", 0, 1.0, IETF_OID_UPS_MIB "9.3.0", "", 0, NULL), /* upsConfigOutputVoltage */ snmp_info_default("output.frequency.nominal", 0, 0.1, IETF_OID_UPS_MIB "9.4.0", "", 0, NULL), /* upsConfigOutputFreq */ snmp_info_default("output.power.nominal", 0, 1.0, IETF_OID_UPS_MIB "9.5.0", "", SU_FLAG_NEGINVALID, NULL), /* upsConfigOutputVA */ snmp_info_default("output.realpower.nominal", 0, 1.0, IETF_OID_UPS_MIB "9.6.0", "", SU_FLAG_NEGINVALID, NULL), /* upsConfigOutputPower */ snmp_info_default("battery.runtime.low", 0, 60.0, IETF_OID_UPS_MIB "9.7.0", "", 0, NULL), /* upsConfigLowBattTime */ snmp_info_default("ups.beeper.status", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_UPS_MIB "9.8.0", "", 0, ietf_beeper_status_info), /* upsConfigAudibleStatus */ snmp_info_default("beeper.disable", 0, 1, IETF_OID_UPS_MIB "9.8.0", "1", SU_TYPE_CMD, NULL), snmp_info_default("beeper.enable", 0, 1, IETF_OID_UPS_MIB "9.8.0", "2", SU_TYPE_CMD, NULL), snmp_info_default("beeper.mute", 0, 1, IETF_OID_UPS_MIB "9.8.0", "3", SU_TYPE_CMD, NULL), snmp_info_default("input.transfer.low", 0, 1.0, IETF_OID_UPS_MIB "9.9.0", "", 0, NULL), /* upsConfigLowVoltageTransferPoint */ snmp_info_default("input.transfer.high", 0, 1.0, IETF_OID_UPS_MIB "9.10.0", "", 0, NULL), /* upsConfigHighVoltageTransferPoint */ /* end of structure. */ snmp_info_sentinel }; /* FIXME: Rename the structure here (or even relocate to new file) * and in snmp-ups.c when the real TrippLite mappings get defined. */ /* FIXME: Duplicate the line below to fix an issue with the code generator (nut-snmpinfo.py -> line is discarding) */ /*mib2nut_info_t tripplite_ietf = { "tripplite", IETF_MIB_VERSION, NULL, NULL, ietf_mib, TRIPPLITE_SYSOID, NULL };*/ mib2nut_info_t tripplite_ietf = { "tripplite", IETF_MIB_VERSION, NULL, NULL, ietf_mib, TRIPPLITE_SYSOID, NULL }; /* FIXME: Duplicate the line below to fix an issue with the code generator (nut-snmpinfo.py -> line is discarding) */ /*mib2nut_info_t ietf = { "ietf", IETF_MIB_VERSION, IETF_OID_UPS_MIB "4.1.0", IETF_OID_UPS_MIB "1.1.0", ietf_mib, IETF_SYSOID, NULL };*/ mib2nut_info_t ietf = { "ietf", IETF_MIB_VERSION, IETF_OID_UPS_MIB "4.1.0", IETF_OID_UPS_MIB "1.1.0", ietf_mib, IETF_SYSOID, NULL }; nut-2.8.4/drivers/powervar-hid.h0000644000175000017500000000217615044656702013531 00000000000000/* powervar-hid.h - subdriver to monitor Powervar USB/HID devices with NUT * * Copyright (C) * 2003 - 2009 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef POWERVAR_HID_H #define POWERVAR_HID_H #include "usbhid-ups.h" extern subdriver_t powervar_subdriver; #endif /* POWERVAR_HID_H */ nut-2.8.4/drivers/hwmon_ina219.c0000644000175000017500000002554215044656702013332 00000000000000/* hwmon.c Driver for INA219 hwmon-based power monitors. Copyright (C) 2024 Jan Viktorin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "nut_float.h" #include "nut_stdint.h" #include #include #include #include #ifndef STRFY0 # define STRFY0(x) #x #endif #ifndef STRFY # define STRFY(x) STRFY0(x) #endif #define SYSFS_HWMON_DIR "/sys/class/hwmon" #define BATTERY_CHARGE_LOW 15 #define DRIVER_NAME "hwmon-INA219 UPS driver" #define DRIVER_VERSION "0.03" upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Jan Viktorin ", DRV_EXPERIMENTAL, { NULL }, }; /** * @brief Path usually pointing to /sys/class/hwmon/hwmonX. */ static char ina219_base_path[NUT_PATH_MAX + 1]; /** * @brief Threshold for detection of LB status. */ static unsigned int battery_charge_low = BATTERY_CHARGE_LOW; /** * @brief Battery voltage (mV) when it is considered depleted. */ static unsigned int battery_voltage_min; /** * @brief Battery voltage (mV) when it is considered fully charged. */ static unsigned int battery_voltage_max; /** * @brief Voltage value as recently read from in1_input (mV). * @see https://docs.kernel.org/hwmon/ina2xx.html */ static int voltage = 0; /** * @brief Current value as recently read from curr1_input (mA). * @see https://docs.kernel.org/hwmon/ina2xx.html */ static int current = 0; static int file_contains(const char *path, const char *text) { FILE *f; char buf[128]; size_t len; if ((f = fopen(path, "r")) == NULL) { upslog_with_errno(LOG_ERR, "unable to open %s", path); return 0; } len = fread(buf, 1, sizeof(buf), f); fclose(f); upsdebugx(4, "read %" PRIuSIZE " bytes", len); if (strlen(text) != len) return 0; if (memcmp(buf, text, len)) return 0; return 1; } static int file_read_number(const char *path, int *value) { char buf[128]; ssize_t ret; int fd; if ((fd = open(path, O_RDONLY)) < 0) return -errno; if ((ret = pread(fd, buf, sizeof(buf), 0)) < 0) { const int _e = -errno; close(fd); return _e; } else { close(fd); buf[ret] = '\0'; *value = atoi(buf); return 0; } } static int detect_ina219(const char *ina219_dir) { char namepath[NUT_PATH_MAX + 1]; upsdebugx(3, "checking %s", ina219_dir); snprintf(namepath, sizeof(namepath), "%s/name", ina219_dir); if (!file_contains(namepath, "ina219\n")) return -ENODEV; upsdebugx(3, "detected ina219 at %s", ina219_dir); return 0; } static int scan_hwmon_ina219(const char *sysfs_hwmon_dir) { DIR *sysfs; struct dirent *entry; int ret; if (strcmp(device_path, "auto")) { if ((ret = detect_ina219(device_path)) < 0) { fatal_with_errno(EXIT_FAILURE, "'port' does not specify a valid hwmon ina219 dir: '%s'", device_path); } snprintf(ina219_base_path, sizeof(ina219_base_path), "%s", device_path); return 0; } upslogx(LOG_NOTICE, "scanning %s for ina219", sysfs_hwmon_dir); if ((sysfs = opendir(sysfs_hwmon_dir)) == NULL) { const int _e = -errno; upslog_with_errno(LOG_ERR, "unable to open %s", sysfs_hwmon_dir); return _e; } while ((entry = readdir(sysfs)) != NULL) { char hwmon_dir[NUT_PATH_MAX + 1]; if (entry->d_type != DT_DIR && entry->d_type != DT_LNK) { upsdebugx(3, "path %s/%s is not directory/symlink", sysfs_hwmon_dir, entry->d_name); continue; } if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) { upsdebugx(3, "skipping path %s/%s", sysfs_hwmon_dir, entry->d_name); continue; } snprintf(hwmon_dir, sizeof(hwmon_dir), "%s/%s", sysfs_hwmon_dir, entry->d_name); if (detect_ina219(hwmon_dir) < 0) { /* Log this one only if really troubleshooting, * this is quite an anticipated and noisy situation, * to disregard most of the directories in sysfs :) */ upsdebugx(6, "skipping path %s: not the expected subsystem", hwmon_dir); continue; } snprintf(ina219_base_path, sizeof(ina219_base_path), "%s", hwmon_dir); closedir(sysfs); return 0; } closedir(sysfs); return -ENODEV; } static int update_intvar( const char *base_path, const char *name, int *value) { char path[NUT_PATH_MAX + 1]; int ret; if (snprintf(path, sizeof(path), "%s/%s", base_path, name) >= NUT_PATH_MAX) { errno = ENAMETOOLONG; upslog_with_errno(LOG_ERR, "snprintf(%s/%s) has failed", base_path, name); return -ENAMETOOLONG; } if ((ret = file_read_number(path, value)) < 0) { errno = -ret; upslog_with_errno(LOG_ERR, "file_read_number(%s) has failed", path); return ret; } return 0; } static int update_voltage(void) { return update_intvar(ina219_base_path, "in1_input", &voltage); } static int update_current(void) { return update_intvar(ina219_base_path, "curr1_input", ¤t); } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "sysfs_dir", "Path to sysfs dir of hwmon if port=auto (" SYSFS_HWMON_DIR ")"); } static int parse_voltage(const char *s, double *v) { errno = 0; *v = strtod(s, NULL); if (errno) return -errno; if (!isnormal(*v) || !isfinite(*v)) return -EDOM; return 0; } static void battery_voltage_params_init(void) { /* Note: with this device, we do not really expect these values * to be reported by hardware or change over time, so this is * only parsed (from built-in or user-provided defaults) into * C variables once. */ const char *d_min = dstate_getinfo("battery.voltage.low"); const char *d_max = dstate_getinfo("battery.voltage.high"); double volt_nominal; int ret; if (!d_min || !d_max) { const char *d_nom; d_nom = dstate_getinfo("battery.voltage.nominal"); upsdebugx(4, "battery.voltage.nominal = '%s'\n", d_nom); if (d_nom == NULL) { volt_nominal = 3.6; } else { if ((ret = parse_voltage(d_nom, &volt_nominal)) < 0) { errno = -ret; fatal_with_errno(EXIT_FAILURE, "battery.voltage.nominal is invalid: '%s'\n", d_nom); } } upslogx(LOG_NOTICE, "guess battery params from battery.voltage.nominal = %.1lf V\n", volt_nominal); if (d_equal(volt_nominal, 3.6)) { battery_voltage_min = 3000; battery_voltage_max = 4250; } else if (d_equal(volt_nominal, 3.7)) { battery_voltage_min = 3000; battery_voltage_max = 4250; } else if (d_equal(volt_nominal, 3.8)) { battery_voltage_min = 3000; battery_voltage_max = 4350; } else if (d_equal(volt_nominal, 3.85)) { battery_voltage_min = 3000; battery_voltage_max = 4400; } else { fatalx(EXIT_FAILURE, "unsupported battery.voltage.nominal: %lf\n", volt_nominal); } } else { double tmp; if ((ret = parse_voltage(d_min, &tmp)) < 0) { errno = -ret; fatal_with_errno(EXIT_FAILURE, "invalid battery.voltage.low: '%s'\n", d_min); } else { battery_voltage_min = (unsigned int) (tmp * 1000.0); } if ((ret = parse_voltage(d_max, &tmp)) < 0) { errno = -ret; fatal_with_errno(EXIT_FAILURE, "invalid battery.voltage.high: '%s'\n", d_max); } else { battery_voltage_max = (unsigned int) (tmp * 1000.0); } } upslogx(LOG_NOTICE, "battery.voltage.low = %u mV\n", battery_voltage_min); upslogx(LOG_NOTICE, "battery.voltage.high = %u mV\n", battery_voltage_max); } static int parse_charge(const char *s, unsigned int *v) { long tmp; errno = 0; tmp = strtol(s, NULL, 0); if (errno) return -errno; if (tmp < 1 || tmp > 100) return -ERANGE; *v = (int) tmp; return 0; } static void battery_charge_params_init(void) { const char *v_lb = dstate_getinfo("battery.charge.low"); int ret; if (v_lb) { if ((ret = parse_charge(v_lb, &battery_charge_low)) < 0) { errno = -ret; fatal_with_errno(EXIT_FAILURE, "battery.charge.low is invalid: '%s'", v_lb); } } upslogx(LOG_NOTICE, "battery.charge.low = %u\n", battery_charge_low); } void upsdrv_initups(void) { const char *hwmon_dir = SYSFS_HWMON_DIR; int ret; if (getval("sysfs_dir")) hwmon_dir = getval("sysfs_dir"); if ((ret = scan_hwmon_ina219(hwmon_dir)) < 0) { errno = -ret; fatal_with_errno(EXIT_FAILURE, "scan_hwmon_ina219(%s) has failed", hwmon_dir); } battery_voltage_params_init(); battery_charge_params_init(); } void upsdrv_initinfo(void) { dstate_setinfo("ups.mfr", "%s", "Texas Instruments"); dstate_setinfo("ups.model", "%s", "INA219"); dstate_setinfo("ups.type", "%s", "ups"); dstate_setinfo("device.mfr", "%s", "Texas Instruments"); dstate_setinfo("device.model", "%s", "INA219"); dstate_setinfo("device.type", "%s", "ups"); dstate_setinfo("device.description", "%s", "Bidirectional Current/Power Monitor With I2C Interface"); dstate_setinfo("battery.charge.low", "%u", battery_charge_low); } static unsigned int battery_charge_compute(void) { const double divisor = (battery_voltage_max - battery_voltage_min) / 100.0; double charge; if (voltage < 0) return 0; if (((unsigned int) voltage) > battery_voltage_min) charge = voltage - battery_voltage_min; else charge = 0; charge /= divisor; charge = charge > 100 ? 100 : charge; return (unsigned int) charge; } void upsdrv_updateinfo(void) { unsigned int charge = 0; int stale = 0; if (update_voltage() < 0) stale = 1; upsdebugx(3, "Battery voltage: %.3fV", voltage / 1000.0); if (update_current() < 0) stale = 1; upsdebugx(3, "Battery current: %.3fA", current / 1000.0); if (stale) { dstate_datastale(); return; } status_init(); charge = battery_charge_compute(); status_set(current <= 0 ? "OL" : "OB"); if (current < 0) status_set("CHRG"); else if (current > 0) status_set("DISCHRG"); if (charge <= battery_charge_low) status_set("LB"); dstate_setinfo("battery.voltage", "%.3f", voltage / 1000.0); dstate_setinfo("battery.current", "%.3f", current / 1000.0); dstate_setinfo("battery.charge", "%u", charge); if (charge <= battery_charge_low && current > 0) dstate_setinfo("battery.runtime", "%d", 60); /* 1 minute */ status_commit(); dstate_dataok(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_help(void) { /* No special options in this driver (vars/flags are auto-documented) */ } void upsdrv_cleanup(void) { } nut-2.8.4/drivers/tripplite_usb.c0000644000175000017500000014506715044656702014011 00000000000000/*!@file tripplite_usb.c * @brief Driver for Tripp Lite non-PDC/HID USB models. */ /* tripplite_usb.c was derived from tripplite.c by Charles Lepple tripplite.c was derived from Russell Kroll's bestups.c by Rik Faith. Copyright (C) 1999 Russell Kroll Copyright (C) 2001 Rickard E. (Rik) Faith Copyright (C) 2004 Nicholas J. Kain Copyright (C) 2005-2008, 2014 Charles Lepple Copyright (C) 2016 Eaton Copyright (C) 2023 Eliran Sapir This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % * * Protocol 1001 * * OMNIVS Commands: (capital letters are literals, lower-case are variables) * :B -> Bxxxxyy (xxxx/55.0: Hz in, yy/16: battery voltage) * :F -> F1143_A (where _ = \0) Firmware version? * :L -> LvvvvXX (vvvv/2.0: VAC out) * :P -> P01000X (1000VA unit) * :S -> Sbb_XXX (bb = 10: on-line, 11: on battery) * :V -> V102XXX (firmware/protocol version?) * :Wt -> Wt (watchdog; t = time in seconds (binary, not hex), * 0 = disable; if UPS is not pinged in this interval, it * will power off the load, and then power it back on after * a delay.) * * % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % * * The outgoing commands are sent with HID Set_Report commands over EP0 * (control message), and incoming commands are received on EP1IN (interrupt * endpoint). The UPS completely ignores the conventions of Set_Idle (where * you NAK the interrupt read if you have no new data), so you constantly have * to poll EP1IN. * * The descriptors say that bInterval is 10 ms. You generally need to wait at * least 80-90 ms to get some characters back from the device. If it takes * more than 250 ms, you probably need to resend the command. * * All outgoing commands are followed by a checksum, which is 255 - (sum of * characters after ':'), and then by '\r'. All responses should start with * the command letter that was sent (no colon), and should be followed by * '\r'. If the command is not supported (or apparently if there is a serial * timeout internally), the previous response will be echoed back. * * % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % * * SMARTPRO commands (3003): * * :A -> ? (start self-test) * :D -> D7187 (? - doesn't match tripplite.c) * :F -> F1019 A firmware rev * :H__ -> H (delay before action?) * :I_ -> I (set flags for conditions that cause a reset?) * :J__ -> J (set 16-bit unit ID) * :K#0 -> (turn outlet off: # in 0..2; 0 is main relay) * :K#1 -> (turn outlet on: # in 0..2) * :L -> L290D_X * :M -> M007F (min/max voltage seen) * :N__ -> N * :P -> P01500X (max power) * :Q -> (while online: reboot) * :R -> R<01> (query flags for conditions that cause a reset?) * :S -> S100_Z0 (status?) * :T -> T7D2581 (temperature, frequency) * :U -> U (unit ID, 1-65535) * :V -> V1062XX (outlets in groups of 2-2-4, with the groups of 2 * individually switchable.) * :W_ -> W_ (watchdog) * :Z -> Z (reset for max/min; takes a moment to complete) * * % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % * * The SMARTPRO unit seems to be slightly saner with regard to message * polling. It specifies an interrupt in interval of 100 ms, but I just * started at a 2 second timeout to obtain the above table. * * % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % * * Commands from serial tripplite.c: * * :N%02X -- delay the UPS for provided time (hex seconds) * :H%06X -- reboot the UPS. UPS will restart after provided time (hex s) * :A -- begins a self-test * :C -- fetches result of a self-test * :K1 -- turns on power receptacles * :K0 -- turns off power receptacles * :G -- unconfirmed: shuts down UPS until power returns * :Q1 -- enable "Remote Reboot" * :Q0 -- disable "Remote Reboot" * :W -- returns 'W' data * :L -- returns 'L' data * :V -- returns 'V' data (firmware revision) * :X -- returns 'X' data (firmware revision) * :D -- returns general status data * :B -- returns battery voltage (hexadecimal decivolts) * :I -- returns minimum input voltage (hexadecimal hertz) [sic] * :M -- returns maximum input voltage (hexadecimal hertz) [sic] * :P -- returns power rating * :Z -- unknown * :U -- unknown * :O -- unknown * :E -- unknown * :Y -- returns mains frequency (':D' is preferred) * :T -- returns ups temperature (':D' is preferred) * :R -- returns input voltage (':D' is preferred) * :F -- returns load percentage (':D' is preferred) * :S -- enables remote reboot/remote power on */ /* Watchdog for 3005 is 15 - 255 seconds. */ #include "main.h" #include "nut_libusb.h" #include "nut_float.h" #include #include "usb-common.h" #define DRIVER_NAME "Tripp Lite OMNIVS / SMARTPRO driver" #define DRIVER_VERSION "0.40" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Charles Lepple \n" \ "Russell Kroll \n" \ "Rickard E. (Rik) Faith \n" \ "Nicholas J. Kain \n" \ "Eliran Sapir ", DRV_EXPERIMENTAL, { NULL } }; /* TrippLite */ #define TRIPPLITE_VENDORID 0x09ae /* USB IDs device table */ static usb_device_id_t tripplite_usb_device_table[] = { /* e.g. OMNIVS1000, SMART550USB, ... */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x0001), NULL }, /* Terminating entry */ { 0, 0, NULL } }; static int subdriver_match_func(USBDevice_t *arghd, void *privdata) { NUT_UNUSED_VARIABLE(privdata); /* FIXME? Should we save "arghd" into global "hd" variable? * This was previously shadowed by function argument named "hd"... */ /* hd = arghd; */ switch (is_usb_device_supported(tripplite_usb_device_table, arghd)) { case SUPPORTED: return 1; case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } return 0; case NOT_SUPPORTED: default: return 0; } } static USBDeviceMatcher_t subdriver_matcher = { &subdriver_match_func, NULL, NULL }; static enum tl_model_t { TRIPP_LITE_UNKNOWN = 0, TRIPP_LITE_OMNIVS, TRIPP_LITE_OMNIVS_2001, TRIPP_LITE_SMARTPRO, TRIPP_LITE_SMART_0004, TRIPP_LITE_SMART_3005 } tl_model = TRIPP_LITE_UNKNOWN; /*! Are the values encoded in ASCII or binary? * TODO: Add 3004? */ static int is_binary_protocol(void) { switch(tl_model) { case TRIPP_LITE_SMART_3005: return 1; case TRIPP_LITE_SMARTPRO: case TRIPP_LITE_SMART_0004: case TRIPP_LITE_OMNIVS: case TRIPP_LITE_OMNIVS_2001: case TRIPP_LITE_UNKNOWN: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic pop #endif return 0; } } /*! Is this the "SMART" family of protocols? * TODO: Add 3004? */ static int is_smart_protocol(void) { switch(tl_model) { case TRIPP_LITE_SMARTPRO: case TRIPP_LITE_SMART_0004: case TRIPP_LITE_SMART_3005: return 1; case TRIPP_LITE_OMNIVS: case TRIPP_LITE_OMNIVS_2001: case TRIPP_LITE_UNKNOWN: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic pop #endif return 0; } } /*!@brief If a character is not printable, return a dot. */ #define toprint(x) (isalnum((int)x) ? (char)(x) : (char)'.') #define ENDCHAR 13 #define MAX_SEND_TRIES 10 #define SEND_WAIT_SEC 0 #define SEND_WAIT_NSEC (1000*1000*100) #define MAX_RECV_TRIES 10 #define RECV_WAIT_MSEC 1000 /*!< was 100 for OMNIVS; SMARTPRO units need longer */ #define MAX_RECONNECT_TRIES 10 #define DEFAULT_OFFDELAY 64 /*!< seconds (max 0xFF) */ #define DEFAULT_STARTDELAY 60 /*!< seconds (max 0xFFFFFF) */ #define DEFAULT_BOOTDELAY 64 /*!< seconds (max 0xFF) */ #define MAX_VOLT 13.4 /*!< Max battery voltage (100%) */ #define MIN_VOLT 11.0 /*!< Min battery voltage (10%) */ #define DEFAULT_UPSID 65535 static USBDevice_t *hd = NULL; static USBDevice_t curDevice; static USBDeviceMatcher_t *reopen_matcher = NULL; static USBDeviceMatcher_t *regex_matcher = NULL; static usb_dev_handle *udev; static usb_communication_subdriver_t *comm_driver = &usb_subdriver; /* We calculate battery charge (q) as a function of voltage (V). * It seems that this function probably varies by firmware revision or * UPS model - the Windows monitoring software gives different q for a * given V than the old open source Tripp Lite monitoring software. * * The discharge curve should be the same for any given battery chemistry, * so it should only be necessary to specify the minimum and maximum * voltages likely to be seen in operation. */ /* Interval notation for Q% = 10% <= [minV, maxV] <= 100% */ static double V_interval[2] = {MIN_VOLT, MAX_VOLT}; static long battery_voltage_nominal = 12, input_voltage_nominal = 120, input_voltage_scaled = 120, /* input_voltage_maximum = -1, input_voltage_minimum = -1, */ switchable_load_banks = 0, unit_id = -1; /*!< range: 1-65535, most likely */ /*! Time in seconds to delay before shutting down. */ static unsigned int offdelay = DEFAULT_OFFDELAY; /* static unsigned int bootdelay = DEFAULT_BOOTDELAY; */ /* Function declaration for send_cmd */ static int send_cmd(const unsigned char *msg, size_t msg_len, unsigned char *reply, size_t reply_len); /* Driver matching by ups.id since serial number isn't exposed on some Tripplite models. Ups.id is the same as Unit Id, and it is a user configurable value between 1-65535. Default Unit Id is 65535. May be set with upsrw, and it persists after powerloss as well. To match by ups id, (upsid='your ups id') must be defined inside the ups.conf */ int match_by_unitid(usb_dev_handle *argudev, USBDevice_t *arghd, usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen); int match_by_unitid(usb_dev_handle *argudev, USBDevice_t *arghd, usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen) { char *value = getval("upsid"); long config_unit_id = 0; ssize_t ret; unsigned char u_msg[] = "U"; unsigned char u_value[9]; NUT_UNUSED_VARIABLE(argudev); NUT_UNUSED_VARIABLE(arghd); NUT_UNUSED_VARIABLE(rdbuf); NUT_UNUSED_VARIABLE(rdlen); /* If upsid is not defined in the config, return 1 (null behavior - match any device), * otherwise read it from the device and match against what was asked in ups.conf */ if (value == NULL) { return 1; } else { config_unit_id = atol(value); } /* Read ups id from the device */ if (tl_model != TRIPP_LITE_OMNIVS && tl_model != TRIPP_LITE_SMART_0004) { /* Unit ID might not be supported by all models: */ ret = send_cmd(u_msg, sizeof(u_msg), u_value, sizeof(u_value) - 1); if (ret <= 0) { upslogx(LOG_INFO, "Unit ID not retrieved (not available on all models)"); } else { /* Translating from two bytes (unsigned chars), so via uint16_t */ unit_id = (uint16_t)((uint16_t)(u_value[1]) << 8) | (uint16_t)(u_value[2]); upsdebugx(1, "Retrieved Unit ID: %ld", unit_id); } } /* Check if the ups ids match */ if (config_unit_id == unit_id) { upsdebugx(1, "Retrieved Unit ID (%ld) matches the configured one (%ld)", unit_id, config_unit_id); return 1; } else { upsdebugx(1, "Retrieved Unit ID (%ld) does not match the configured one (%ld). " "Do you have several compatible UPSes? Otherwise, please check if the ID " "was set in the previous life of your device (can use upsrw to set another" "value).", unit_id, config_unit_id); return 0; } } /*!@brief Try to reconnect once. * @return 1 if reconnection was successful. */ static int reconnect_ups(void) { int ret; if (hd != NULL) { return 1; } dstate_setinfo("driver.state", "reconnect.trying"); upsdebugx(2, "=================================================="); upsdebugx(2, "= device has been disconnected, try to reconnect ="); upsdebugx(2, "=================================================="); ret = comm_driver->open_dev(&udev, &curDevice, reopen_matcher, match_by_unitid); if (ret < 1) { upslogx(LOG_INFO, "Reconnecting to UPS failed; will retry later..."); dstate_datastale(); return 0; } hd = &curDevice; dstate_setinfo("driver.state", "quiet"); return ret; } /*!@brief Convert a string to printable characters (in-place) * * @param[in,out] str String to convert * @param[in] len Maximum number of characters to convert, or == 0 to * convert all. * * Uses toprint() macro defined above. */ static void toprint_str(char *str, size_t len) { size_t i; if (len == 0) len = strlen(str); /* FIXME? Should we check for '\0' along the way? */ for (i = 0; i < len; i++) str[i] = toprint(str[i]); } /*!@brief Convert N characters from hex to decimal * * @param start Beginning of string to convert * @param len Maximum number of characters to consider (max 32) * * @a len characters of @a start are copied to a temporary buffer, then passed * to strtol() to be converted to decimal. * * @return See strtol(3) */ static long hex2d(const unsigned char *start, unsigned int len) { unsigned char buf[32]; buf[31] = '\0'; strncpy((char *)buf, (const char *)start, (len < (sizeof buf) ? len : (sizeof buf - 1))); if(len < sizeof(buf)) buf[len] = '\0'; return strtol((char *)buf, NULL, 16); } /*!@brief Convert N characters from big-endian binary to decimal * * @param start Beginning of string to convert * @param len Maximum number of characters to consider (max 32) * * @a len characters of @a start are shifted into an accumulator. * * We assume len < sizeof(int), and that value > 0. * * @return the value */ static unsigned int bin2d(const unsigned char *start, unsigned int len) { unsigned int value = 0, index = 0; for(index = 0; index < len; index++) { value <<= 8; value |= start[index]; } return value; } static long hex_or_bin2d(const unsigned char *start, unsigned int len) { if(is_binary_protocol()) { return bin2d(start, len); } return hex2d(start, len); } /*!@brief Dump message in both hex and ASCII * * @param[in] msg Buffer to dump * @param[in] len Number of bytes to dump * * @return Pointer to static buffer with decoded message */ static const char *hexascdump(unsigned char *msg, size_t len) { size_t i; static unsigned char buf[256]; unsigned char *bufp, *end; bufp = buf; end = bufp + sizeof(buf); buf[0] = 0; /* Dump each byte in hex: */ for(i=0; i=3; i++) { bufp += sprintf((char *)bufp, "%02x ", msg[i]); } /* Dump single-quoted string with printable version of each byte: */ if (end-bufp > 0) *bufp++ = '\''; for(i=0; i0; i++) { *bufp++ = (unsigned char)toprint(msg[i]); } if (end-bufp > 0) *bufp++ = '\''; if (end-bufp > 0) *bufp = '\0'; else *--end='\0'; return (char *)buf; } static enum tl_model_t decode_protocol(unsigned int proto) { switch (proto) { case 0x0004: upslogx(LOG_INFO, "Using older SMART protocol (%04x)", proto); return TRIPP_LITE_SMART_0004; case 0x1001: upslogx(LOG_INFO, "Using OMNIVS protocol (%x)", proto); return TRIPP_LITE_OMNIVS; case 0x2001: upslogx(LOG_INFO, "Using OMNIVS 2001 protocol (%x)", proto); return TRIPP_LITE_OMNIVS_2001; case 0x3003: upslogx(LOG_INFO, "Using SMARTPRO protocol (%x)", proto); return TRIPP_LITE_SMARTPRO; case 0x3005: upslogx(LOG_INFO, "Using binary SMART protocol (%x)", proto); return TRIPP_LITE_SMART_3005; default: upslogx(LOG_INFO, "Unknown protocol (%04x)", proto); break; } return TRIPP_LITE_UNKNOWN; } static void decode_v(const unsigned char *value) { unsigned char ivn, lb; long bv; if(is_binary_protocol()) { /* 0x00 0x0c -> 12V ? */ battery_voltage_nominal = (value[2] << 8) | value[3]; } else { bv = hex2d(value+2, 2); battery_voltage_nominal = bv * 6; } ivn = value[1]; lb = value[4]; switch(ivn) { case '0': input_voltage_nominal = input_voltage_scaled = 100; break; case 2: /* protocol 3005 */ case '1': input_voltage_nominal = input_voltage_scaled = 120; break; case '2': input_voltage_nominal = input_voltage_scaled = 230; break; case '3': input_voltage_nominal = 208; input_voltage_scaled = 230; break; case 6: input_voltage_nominal = input_voltage_scaled = 230; break; default: upslogx(LOG_WARNING, "Unknown input voltage range: 0x%02x", (unsigned int)ivn); break; } if( (lb >= '0') && (lb <= '9') ) { switchable_load_banks = lb - '0'; } else { if(is_binary_protocol()) { switchable_load_banks = lb; } else { if( lb != 'X' ) { upslogx(LOG_WARNING, "Unknown number of switchable load banks: 0x%02x", (unsigned int)lb); } } } upsdebugx(2, "Switchable load banks: %ld", switchable_load_banks); } void upsdrv_initinfo(void); /*!@brief Report a USB comm failure, and reconnect if necessary * * @param[in] res Result code from libusb/libhid call * @param[in] msg Error message to display */ static void usb_comm_fail(int res, const char *msg) { static int try = 0; switch(res) { case LIBUSB_ERROR_BUSY: upslogx(LOG_WARNING, "%s: Device claimed by another process", msg); fatalx(EXIT_FAILURE, "Terminating: EBUSY"); #ifndef HAVE___ATTRIBUTE__NORETURN break; #endif default: dstate_setinfo("driver.state", "reconnect.trying"); upslogx(LOG_WARNING, "%s: Device detached? (error %d: %s)", msg, res, nut_usb_strerror(res)); upslogx(LOG_NOTICE, "Reconnect attempt #%d", ++try); hd = NULL; reconnect_ups(); if(hd) { upslogx(LOG_NOTICE, "Successfully reconnected"); try = 0; dstate_setinfo("driver.state", "reconnect.updateinfo"); upsdrv_initinfo(); dstate_setinfo("driver.state", "quiet"); } else { if(try > MAX_RECONNECT_TRIES) { fatalx(EXIT_FAILURE, "Too many unsuccessful reconnection attempts"); } } break; } } /*!@brief Send a command to the UPS, and wait for a reply. * * All of the UPS commands are challenge-response. If a command does not have * anything to return, it simply returns the command character. * * @param[in] msg Command string, minus the ':' or CR * @param[in] msg_len Be sure to use sizeof(msg) instead of strlen(msg), * since some commands have embedded NUL characters * @param[out] reply Reply (but check return code for validity) * @param[out] reply_len (currently unused) * * @return number of chars in reply, excluding terminating NUL * @return 0 if command was not accepted */ static int send_cmd(const unsigned char *msg, size_t msg_len, unsigned char *reply, size_t reply_len) { unsigned char buffer_out[8]; unsigned char csum = 0; int ret = 0, send_try, recv_try=0, done = 0; size_t i = 0; NUT_UNUSED_VARIABLE(reply_len); upsdebugx(3, "send_cmd(msg_len=%u, type='%c')", (unsigned)msg_len, msg[0]); if(msg_len > 5) { fatalx(EXIT_FAILURE, "send_cmd(): Trying to pass too many characters to UPS (%u)", (unsigned)msg_len); } buffer_out[0] = ':'; for(i=1; i<8; i++) buffer_out[i] = '\0'; for(i=0; iset_report(udev, 0, (usb_ctrl_charbuf)buffer_out, (usb_ctrl_charbufsize)sizeof(buffer_out)); if(ret != sizeof(buffer_out)) { upsdebugx(3, "libusb_set_report() returned %d instead of %" PRIuSIZE, ret, sizeof(buffer_out)); return ret; } #if ! defined(__FreeBSD__) usleep(1000*100); /* TODO: nanosleep */ #endif for(recv_try=0; !done && recv_try < MAX_RECV_TRIES; recv_try++) { upsdebugx(7, "send_cmd recv_try %d", recv_try+1); ret = comm_driver->get_interrupt(udev, (usb_ctrl_charbuf)reply, (usb_ctrl_charbufsize)sizeof(buffer_out), RECV_WAIT_MSEC); if(ret != sizeof(buffer_out)) { upsdebugx(3, "libusb_get_interrupt() returned %d instead of %u while sending %s", ret, (unsigned)(sizeof(buffer_out)), hexascdump(buffer_out, sizeof(buffer_out))); } done = (ret == sizeof(buffer_out)) && (buffer_out[1] == reply[0]); } } if(ret == sizeof(buffer_out)) { upsdebugx(5, "send_cmd: received %s (%s)", hexascdump(reply, sizeof(buffer_out)), done ? "OK" : "bad"); } upsdebugx(((send_try > 2) || (recv_try > 2)) ? 3 : 6, "send_cmd: send_try = %d, recv_try = %d\n", send_try, recv_try); return done ? sizeof(buffer_out) : 0; } /*!@brief Send an unknown command to the UPS, and store response in a variable * * @param msg Command string (usually a character and a null) * @param len Length of command plus null * * The variables are of the form "ups.debug.X" where "X" is the command * character. */ static void debug_message(const char *msg, size_t len) { int ret; unsigned char tmp_value[9]; char var_name[20], err_msg[80]; snprintf(var_name, sizeof(var_name), "ups.debug.%c", *msg); ret = send_cmd((const unsigned char *)msg, len, tmp_value, sizeof(tmp_value)); if(ret <= 0) { sprintf(err_msg, "Error reading '%c' value", *msg); usb_comm_fail(ret, err_msg); return; } dstate_setinfo(var_name, "%s", hexascdump(tmp_value+1, 7)); } #if 0 /* using the watchdog to reboot won't work while polling */ static void do_reboot_wait(unsigned dly) { int ret; char buf[256], cmd_W[]="Wx"; cmd_W[1] = dly; upsdebugx(3, "do_reboot_wait(wait=%d): N", dly); ret = send_cmd(cmd_W, sizeof(cmd_W), buf, sizeof(buf)); } static int do_reboot_now(void) { do_reboot_wait(1); return 0; } static void do_reboot(void) { do_reboot_wait(bootdelay); } #endif /*! Called by 'tripplite_usb -k' */ static int soft_shutdown(void) { int ret; unsigned char buf[256], cmd_N[]="N\0x", cmd_G[] = "G"; /* Already binary: */ /* FIXME: Assumes memory layout / endianness? */ cmd_N[2] = (unsigned char)(offdelay & 0x00FF); cmd_N[1] = (unsigned char)(offdelay >> 8); upsdebugx(3, "soft_shutdown(offdelay=%u): N", offdelay); ret = send_cmd(cmd_N, sizeof(cmd_N), buf, sizeof(buf)); if(ret != 8) { upslogx(LOG_ERR, "Could not set offdelay to %u", offdelay); return ret; } sleep(2); /*! The unit must be on battery for this to work. * * @todo check for on-battery condition, and print error if not. * @todo Find an equivalent command for non-OMNIVS models. */ ret = send_cmd(cmd_G, sizeof(cmd_G), buf, sizeof(buf)); if(ret != 8) { upslogx(LOG_ERR, "Could not turn off UPS (is it still on battery?)"); return 0; } return 1; } #if 0 static int hard_shutdown(void) { int ret; unsigned char buf[256], cmd_N[]="N\0x", cmd_K[] = "K\0"; /* FIXME: Assumes memory layout / endianness? */ cmd_N[2] = (unsigned char)(offdelay & 0x00FF); cmd_N[1] = (unsigned char)(offdelay >> 8); upsdebugx(3, "hard_shutdown(offdelay=%d): N", offdelay); ret = send_cmd(cmd_N, sizeof(cmd_N), buf, sizeof(buf)); if(ret != 8) return ret; sleep(2); ret = send_cmd(cmd_K, sizeof(cmd_K), buf, sizeof(buf)); return (ret == 8); } #endif /*!@brief Turn an outlet on or off. * * @return 1 if the command worked, 0 if not. */ static int control_outlet(int outlet_id, int state) { char k_cmd[10], buf[10]; int ret; switch(tl_model) { case TRIPP_LITE_SMARTPRO: /* tested */ case TRIPP_LITE_SMART_0004: /* untested */ snprintf(k_cmd, sizeof(k_cmd)-1, "N%02X", (unsigned int)5); ret = send_cmd((unsigned char *)k_cmd, strlen(k_cmd) + 1, (unsigned char *)buf, sizeof buf); snprintf(k_cmd, sizeof(k_cmd)-1, "K%d%d", outlet_id, state & 1); ret = send_cmd((unsigned char *)k_cmd, strlen(k_cmd) + 1, (unsigned char *)buf, sizeof buf); if(ret != 8) { upslogx(LOG_ERR, "Could not set outlet %d to state %d, ret = %d", outlet_id, state, ret); return 0; } else { return 1; } #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_BREAK #pragma GCC diagnostic ignored "-Wunreachable-code-break" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif break; #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic pop #endif case TRIPP_LITE_SMART_3005: snprintf(k_cmd, sizeof(k_cmd)-1, "N%c", 5); ret = send_cmd((unsigned char *)k_cmd, strlen(k_cmd) + 1, (unsigned char *)buf, sizeof buf); snprintf(k_cmd, sizeof(k_cmd)-1, "K%c%c", outlet_id, state & 1); ret = send_cmd((unsigned char *)k_cmd, strlen(k_cmd) + 1, (unsigned char *)buf, sizeof buf); if(ret != 8) { upslogx(LOG_ERR, "Could not set outlet %d to state %d, ret = %d", outlet_id, state, ret); return 0; } else { return 1; } #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE_BREAK #pragma GCC diagnostic ignored "-Wunreachable-code-break" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif break; #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic pop #endif case TRIPP_LITE_OMNIVS: case TRIPP_LITE_OMNIVS_2001: case TRIPP_LITE_UNKNOWN: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic pop #endif upslogx(LOG_ERR, "control_outlet unimplemented for protocol %04x", tl_model); } return 0; } /*!@brief Handler for "instant commands" */ static int instcmd(const char *cmdname, const char *extra) { unsigned char buf[10]; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (is_smart_protocol()) { if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); send_cmd((const unsigned char *)"A", 2, buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "reset.input.minmax")) { return (send_cmd((const unsigned char *)"Z", 2, buf, sizeof buf) == 2) ? STAT_INSTCMD_HANDLED : STAT_INSTCMD_UNKNOWN; } } if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); return control_outlet(0, 0) ? STAT_INSTCMD_HANDLED : STAT_INSTCMD_UNKNOWN; } if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); return control_outlet(0, 1) ? STAT_INSTCMD_HANDLED : STAT_INSTCMD_UNKNOWN; } /* code for individual outlets is in setvar() */ #if 0 if (!strcasecmp(cmdname, "shutdown.reboot")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); do_reboot_now(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.reboot.graceful")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); do_reboot(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); hard_shutdown(); return STAT_INSTCMD_HANDLED; } #endif if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); soft_shutdown(); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } static int setvar(const char *varname, const char *val) { upsdebug_SET_STARTING(varname, val); if (!strcasecmp(varname, "ups.delay.shutdown")) { int ival = atoi(val); if (ival >= 0) { offdelay = (unsigned int)ival; dstate_setinfo("ups.delay.shutdown", "%u", offdelay); return STAT_SET_HANDLED; } else { upslogx(LOG_SET_UNKNOWN, "FAILED to set '%s' to %d", varname, ival); return STAT_SET_UNKNOWN; } } if (unit_id >= 0 && !strcasecmp(varname, "ups.id")) { int new_unit_id, ret; unsigned char J_msg[] = "J__", buf[9]; new_unit_id = atoi(val); /* FIXME: Assumes memory layout / endianness? */ J_msg[1] = (unsigned char)(new_unit_id >> 8); J_msg[2] = (unsigned char)(new_unit_id & 0xff); ret = send_cmd(J_msg, sizeof(J_msg), buf, sizeof(buf)); if(ret <= 0) { upslogx(LOG_SET_UNKNOWN, "Could not set Unit ID (return code: %d).", ret); return STAT_SET_UNKNOWN; } dstate_setinfo("ups.id", "%s", val); return STAT_SET_HANDLED; } if(!strncmp(varname, "outlet.", strlen("outlet."))) { char outlet_name[80]; char index_str[10], *first_dot, *next_dot; long index_chars; int index, state, ret; first_dot = strstr(varname, "."); next_dot = strstr(first_dot + 1, "."); if (!next_dot) { upslogx(LOG_SET_UNKNOWN, "FAILED to get outlet index from '%s' (no second dot)", varname); return STAT_SET_UNKNOWN; } index_chars = next_dot - (first_dot + 1); if (index_chars > 9 || index_chars < 0) return STAT_SET_UNKNOWN; if (strcmp(next_dot, ".switch")) return STAT_SET_UNKNOWN; strncpy(index_str, first_dot + 1, (size_t)index_chars); index_str[index_chars] = 0; index = atoi(index_str); upslogx(LOG_DEBUG, "outlet.%d.switch = %s", index, val); if(!strcasecmp(val, "on") || !strcmp(val, "1")) { state = 1; } else { state = 0; } upslogx(LOG_DEBUG, "outlet.%d.switch = %s -> %d", index, val, state); snprintf(outlet_name, sizeof(outlet_name)-1, "outlet.%d.switch", index); ret = control_outlet(index, state); if(ret) { dstate_setinfo(outlet_name, "%d", state); return STAT_SET_HANDLED; } else { return STAT_SET_UNKNOWN; } } #if 0 if (!strcasecmp(varname, "ups.delay.start")) { startdelay = atoi(val); dstate_setinfo("ups.delay.start", val); return STAT_SET_HANDLED; } if (!strcasecmp(varname, "ups.delay.reboot")) { bootdelay = atoi(val); dstate_setinfo("ups.delay.reboot", val); return STAT_SET_HANDLED; } #endif upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } void upsdrv_initinfo(void) { const unsigned char proto_msg[] = "\0", f_msg[] = "F", p_msg[] = "P", s_msg[] = "S", u_msg[] = "U", v_msg[] = "V", w_msg[] = "W\0"; char *model, *model_end; unsigned char proto_value[9], f_value[9], p_value[9], s_value[9], u_value[9], v_value[9], w_value[9]; long va; ssize_t ret; unsigned int proto_number = 0; /* Read protocol: */ ret = send_cmd(proto_msg, sizeof(proto_msg), proto_value, sizeof(proto_value)-1); if(ret <= 0) { fatalx(EXIT_FAILURE, "Error reading protocol"); } proto_number = ((unsigned)(proto_value[1]) << 8) | (unsigned)(proto_value[2]); tl_model = decode_protocol(proto_number); if(tl_model == TRIPP_LITE_UNKNOWN) dstate_setinfo("ups.debug.0", "%s", hexascdump(proto_value+1, 7)); dstate_setinfo("ups.firmware.aux", "protocol %04x", proto_number); /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ /* Reset watchdog: */ /* Watchdog not supported on TRIPP_LITE_SMARTPRO models */ if(tl_model != TRIPP_LITE_SMARTPRO ) { ret = send_cmd(w_msg, sizeof(w_msg), w_value, sizeof(w_value)-1); if(ret <= 0) { if(ret == LIBUSB_ERROR_PIPE) { fatalx(EXIT_FAILURE, "Could not reset watchdog. Please check and" "see if usbhid-ups(8) works with this UPS."); } else { upslogx(LOG_ERR, "Could not reset watchdog. Please send model " "information to nut-upsdev mailing list"); } } } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ ret = send_cmd(s_msg, sizeof(s_msg), s_value, sizeof(s_value)-1); if(ret <= 0) { fatalx(EXIT_FAILURE, "Could not retrieve status ... is this an OMNIVS model?"); } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ dstate_setinfo("ups.mfr", "%s", "Tripp Lite"); /* Get nominal power: */ ret = send_cmd(p_msg, sizeof(p_msg), p_value, sizeof(p_value)-1); va = strtol((char *)(p_value+1), NULL, 10); if(tl_model == TRIPP_LITE_SMART_0004) { dstate_setinfo("ups.debug.P","%s", hexascdump(p_value+1, 7)); va *= 10; /* TODO: confirm? */ } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ /* trim "TRIPP LITE" from beginning of model */ model = strdup(hd->Product); if(strstr(model, hd->Vendor) == model) { model += strlen(hd->Vendor); } /* trim leading spaces: */ for(; *model == ' '; model++); /* Trim trailing spaces */ for(model_end = model + strlen(model) - 1; model_end > model && *model_end == ' '; model_end--) { *model_end = '\0'; } dstate_setinfo("ups.model", "%s", model); dstate_setinfo("ups.power.nominal", "%ld", va); /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ /* Fetch firmware version: */ ret = send_cmd(f_msg, sizeof(f_msg), f_value, sizeof(f_value)-1); toprint_str((char *)(f_value+1), 6); f_value[7] = 0; dstate_setinfo("ups.firmware", "F%s", f_value+1); /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ /* Get configuration: */ ret = send_cmd(v_msg, sizeof(v_msg), v_value, sizeof(v_value)-1); decode_v(v_value); /* FIXME: redundant, but since it's static, we don't need to poll * every time. */ debug_message("V", 2); if(switchable_load_banks > 0) { int i; char outlet_name[80]; for(i = 1; i <= switchable_load_banks + 1; i++) { snprintf(outlet_name, sizeof(outlet_name), "outlet.%d.id", i); dstate_setinfo(outlet_name, "%d", i); snprintf(outlet_name, sizeof(outlet_name), "outlet.%d.desc", i); dstate_setinfo(outlet_name, "Load %d", i); snprintf(outlet_name, sizeof(outlet_name), "outlet.%d.switchable", i); if( i <= switchable_load_banks ) { dstate_setinfo(outlet_name, "1"); snprintf(outlet_name, sizeof(outlet_name)-1, "outlet.%d.switch", i); dstate_setinfo(outlet_name, "1"); dstate_setflags(outlet_name, ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux(outlet_name, 3); } else { /* Last bank is not switchable: */ dstate_setinfo(outlet_name, "0"); } } /* For the main relay: */ dstate_addcmd("load.on"); dstate_addcmd("load.off"); } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ if(tl_model != TRIPP_LITE_OMNIVS && tl_model != TRIPP_LITE_SMART_0004) { /* Unit ID might not be supported by all models: */ ret = send_cmd(u_msg, sizeof(u_msg), u_value, sizeof(u_value)-1); if(ret <= 0) { upslogx(LOG_INFO, "Unit ID not retrieved (not available on all models)"); } else { unit_id = (long)((unsigned)(u_value[1]) << 8) | (unsigned)(u_value[2]); } if(tl_model == TRIPP_LITE_SMART_0004) { debug_message("U", 2); } } if(unit_id >= 0) { dstate_setinfo("ups.id", "%ld", unit_id); dstate_setflags("ups.id", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.id", 5); upslogx(LOG_DEBUG,"Unit ID: %ld", unit_id); } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ dstate_setinfo("input.voltage.nominal", "%ld", input_voltage_nominal); dstate_setinfo("battery.voltage.nominal", "%ld", battery_voltage_nominal); dstate_setinfo("ups.debug.load_banks", "%ld", switchable_load_banks); dstate_setinfo("ups.delay.shutdown", "%u", offdelay); dstate_setflags("ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.shutdown", 3); #if 0 dstate_setinfo("ups.delay.start", "%u", startdelay); dstate_setflags("ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.start", 8); dstate_setinfo("ups.delay.reboot", "%u", bootdelay); dstate_setflags("ups.delay.reboot", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.reboot", 3); #endif if(is_smart_protocol()) { dstate_addcmd("test.battery.start"); dstate_addcmd("reset.input.minmax"); } dstate_addcmd("shutdown.return"); #if 0 dstate_addcmd("shutdown.stayoff"); dstate_addcmd("test.battery.start"); /* Turns off automatically */ dstate_addcmd("load.off"); dstate_addcmd("load.on"); dstate_addcmd("shutdown.reboot"); dstate_addcmd("shutdown.reboot.graceful"); #endif upsh.instcmd = instcmd; upsh.setvar = setvar; printf("Attached to %s %s\n", dstate_getinfo("ups.mfr"), dstate_getinfo("ups.model")); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = do_loop_shutdown_commands("shutdown.return", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } void upsdrv_updateinfo(void) { unsigned char b_msg[] = "B", d_msg[] = "D", l_msg[] = "L", s_msg[] = "S", m_msg[] = "M", t_msg[] = "T"; unsigned char b_value[9], d_value[9], l_value[9], s_value[9], m_value[9], t_value[9]; int bp; long freq; double bv_12V = 0.0; /*!< battery voltage, relative to a 12V battery */ double battery_voltage; /*!< the total battery voltage */ unsigned int s_value_1; int ret; status_init(); /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ /* General status (e.g. "S10") */ ret = send_cmd(s_msg, sizeof(s_msg), s_value, sizeof(s_value)); if(ret <= 0) { dstate_datastale(); usb_comm_fail(ret, "Error reading S value"); return; } if(tl_model != TRIPP_LITE_OMNIVS && tl_model != TRIPP_LITE_OMNIVS_2001) { dstate_setinfo("ups.debug.S","%s", hexascdump(s_value+1, 7)); } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ if(tl_model == TRIPP_LITE_OMNIVS) { switch(s_value[2]) { case '0': status_set("OL"); break; case '1': status_set("OB"); break; case '2': /* "charge-only" mode, no AC in or out... the PC * shouldn't see this, because there is no power in * that case (OMNIVS), but it's here for testing. * * Entered by holding down the power button. */ status_set("BYPASS"); break; case '3': /* I have seen this once when switching from off+LB to charging */ upslogx(LOG_WARNING, "Unknown value for s[2]: 0x%02x", s_value[2]); break; default: upslogx(LOG_ERR, "Unknown value for s[2]: 0x%02x", s_value[2]); dstate_datastale(); break; } } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ if(is_smart_protocol() || tl_model == TRIPP_LITE_OMNIVS_2001) { unsigned int s_value_2 = s_value[2]; if(is_binary_protocol()) { s_value_2 += '0'; } switch(s_value_2) { case '0': dstate_setinfo("battery.test.status", "Battery OK"); break; case '1': dstate_setinfo("battery.test.status", "Battery bad - replace"); break; case '2': status_set("CAL"); break; case '3': status_set("OVER"); dstate_setinfo("battery.test.status", "Overcurrent?"); break; case '4': /* The following message is confusing, and may not be accurate: */ /* dstate_setinfo("battery.test.status", "Battery state unknown"); */ break; case '5': status_set("OVER"); dstate_setinfo("battery.test.status", "Battery fail - overcurrent?"); break; default: upslogx(LOG_ERR, "Unknown value for s[2]: 0x%02x", s_value[2]); dstate_datastale(); break; } if(s_value[4] & 4) { status_set("OFF"); } else { /* Online/on battery: */ if(s_value[4] & 1) { status_set("OB"); } else { status_set("OL"); } } #if 0 /* Apparently, this value changes more frequently when the * battery is discharged, but it does not track the actual * state-of-charge. See battery.charge calculation below. */ if(tl_model == TRIPP_LITE_SMARTPRO) { unsigned battery_charge; battery_charge = (unsigned)(s_value[5]); dstate_setinfo("battery.charge", "%u", battery_charge); } #endif } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ s_value_1 = s_value[1]; if(is_binary_protocol()) { s_value_1 += '0'; } switch(s_value_1) { case '0': status_set("LB"); break; case '1': /* Depends on s_value[2] */ break; case '2': if( tl_model == TRIPP_LITE_SMARTPRO ) { status_set("RB"); break; } /* else fall through: */ goto fallthrough_case_default; default: fallthrough_case_default: upslogx(LOG_ERR, "Unknown value for s[1]: 0x%02x", s_value[1]); dstate_datastale(); break; } status_commit(); /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ if( tl_model == TRIPP_LITE_OMNIVS || tl_model == TRIPP_LITE_OMNIVS_2001 ) { ret = send_cmd(b_msg, sizeof(b_msg), b_value, sizeof(b_value)); if(ret <= 0) { dstate_datastale(); usb_comm_fail(ret, "Error reading B value"); return; } dstate_setinfo("input.voltage", "%.2f", hex2d(b_value+1, 4)/3600.0*input_voltage_scaled); bv_12V = hex2d(b_value+5, 2)/16.0; /* TODO: use battery_voltage_nominal, even though it is most likely 12V */ dstate_setinfo("battery.voltage", "%.2f", bv_12V); } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ if( is_smart_protocol() ) { ret = send_cmd(d_msg, sizeof(d_msg), d_value, sizeof(d_value)); if(ret <= 0) { dstate_datastale(); usb_comm_fail(ret, "Error reading D value"); return; } dstate_setinfo("input.voltage", "%ld", hex_or_bin2d(d_value+1, 2) * input_voltage_scaled / 120); /* TODO: factor out the two constants */ bv_12V = hex_or_bin2d(d_value+3, 2) / 10.0 ; battery_voltage = bv_12V * battery_voltage_nominal / 12.0; dstate_setinfo("battery.voltage", "%.2f", battery_voltage); /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ ret = send_cmd(m_msg, sizeof(m_msg), m_value, sizeof(m_value)); if(m_value[5] != 0x0d) { /* we only expect 4 hex/binary digits */ dstate_setinfo("ups.debug.M", "%s", hexascdump(m_value+1, 7)); } if(ret <= 0) { dstate_datastale(); usb_comm_fail(ret, "Error reading M (min/max input voltage)"); return; } dstate_setinfo("input.voltage.minimum", "%3ld", hex_or_bin2d(m_value+1, 2) * input_voltage_scaled / 120); dstate_setinfo("input.voltage.maximum", "%3ld", hex_or_bin2d(m_value+3, 2) * input_voltage_scaled / 120); /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ ret = send_cmd(t_msg, sizeof(t_msg), t_value, sizeof(t_value)); dstate_setinfo("ups.debug.T", "%s", hexascdump(t_value+1, 7)); if(ret <= 0) { dstate_datastale(); usb_comm_fail(ret, "Error reading T value"); return; } if( tl_model == TRIPP_LITE_SMARTPRO ) { freq = hex2d(t_value + 3, 3); dstate_setinfo("input.frequency", "%.1f", freq / 10.0); switch(t_value[6]) { case '1': dstate_setinfo("input.frequency.nominal", "%d", 60); break; case '0': dstate_setinfo("input.frequency.nominal", "%d", 50); break; default: break; } } if( tl_model == TRIPP_LITE_SMART_0004 ) { freq = hex2d(t_value + 3, 4); dstate_setinfo("input.frequency", "%.1f", freq / 10.0); } if( tl_model == TRIPP_LITE_SMART_3005 ) { dstate_setinfo("ups.temperature", "%u", (unsigned)(hex2d(t_value+1, 1))); } else { /* I'm guessing this is a calibration constant of some sort. */ dstate_setinfo("ups.temperature", "%.1f", (unsigned)(hex2d(t_value+1, 2)) * 0.3636 - 21); } } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ if( tl_model == TRIPP_LITE_OMNIVS || tl_model == TRIPP_LITE_OMNIVS_2001 || tl_model == TRIPP_LITE_SMARTPRO || tl_model == TRIPP_LITE_SMART_0004 || tl_model == TRIPP_LITE_SMART_3005) { /* dq ~= sqrt(dV) is a reasonable approximation * Results fit well against the discrete function used in the Tripp Lite * source, but give a continuous result. */ if (bv_12V >= V_interval[1]) bp = 100; else if (bv_12V <= V_interval[0]) bp = 10; else bp = (int)(100*sqrt((bv_12V - V_interval[0]) / (V_interval[1] - V_interval[0]))); dstate_setinfo("battery.charge", "%3d", bp); } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ ret = send_cmd(l_msg, sizeof(l_msg), l_value, sizeof(l_value)); if(ret <= 0) { dstate_datastale(); usb_comm_fail(ret, "Error reading L value"); return; } switch(tl_model) { case TRIPP_LITE_OMNIVS: case TRIPP_LITE_OMNIVS_2001: dstate_setinfo("output.voltage", "%.1f", hex2d(l_value+1, 4)/240.0*input_voltage_scaled); break; case TRIPP_LITE_SMARTPRO: dstate_setinfo("ups.load", "%ld", hex2d(l_value+1, 2)); break; case TRIPP_LITE_SMART_3005: dstate_setinfo("ups.load", "%ld", hex_or_bin2d(l_value+1, 1)); break; case TRIPP_LITE_SMART_0004: dstate_setinfo("ups.load", "%ld", hex2d(l_value+1, 2)); dstate_setinfo("ups.debug.L","%s", hexascdump(l_value+1, 7)); break; case TRIPP_LITE_UNKNOWN: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic pop #endif dstate_setinfo("ups.debug.L","%s", hexascdump(l_value+1, 7)); break; } /* - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ if(tl_model != TRIPP_LITE_OMNIVS && tl_model != TRIPP_LITE_OMNIVS_2001) { debug_message("D", 2); /* We already grabbed these above: */ if(tl_model != TRIPP_LITE_SMARTPRO) { debug_message("V", 2); /* Probably not necessary - seems to be static */ debug_message("M", 2); debug_message("T", 2); debug_message("P", 2); } /* debug_message("U", 2); */ } dstate_dataok(); } void upsdrv_help(void) { } void upsdrv_makevartable(void) { char msg[256]; snprintf(msg, sizeof msg, "Set shutdown delay, in seconds (default=%d)", DEFAULT_OFFDELAY); addvar(VAR_VALUE, "offdelay", msg); /* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */ nut_usb_addvars(); snprintf(msg, sizeof msg, "Minimum battery voltage, corresponding to 10%% charge (default=%.1f)", MIN_VOLT); addvar(VAR_VALUE, "battery_min", msg); snprintf(msg, sizeof msg, "Maximum battery voltage, corresponding to 100%% charge (default=%.1f)", MAX_VOLT); addvar(VAR_VALUE, "battery_max", msg); /* allow -x upsid=X */ snprintf(msg, sizeof msg, "UPS ID (Unit ID) (default=%d)", DEFAULT_UPSID); addvar(VAR_VALUE, "upsid", msg); #if 0 snprintf(msg, sizeof msg, "Set start delay, in seconds (default=%d).", DEFAULT_STARTDELAY); addvar(VAR_VALUE, "startdelay", msg); snprintf(msg, sizeof msg, "Set reboot delay, in seconds (default=%d).", DEFAULT_BOOTDELAY); addvar(VAR_VALUE, "rebootdelay", msg); #endif } /*!@brief Initialize UPS and variables from ups.conf * * @todo Allow binding based on firmware version (which seems to vary wildly * from unit to unit) */ void upsdrv_initups(void) { char *regex_array[USBMATCHER_REGEXP_ARRAY_LIMIT]; char *value; int r; warn_if_bad_usb_port_filename(device_path); /* process the UPS selection options */ regex_array[0] = NULL; /* handled by USB IDs device table */ regex_array[1] = getval("productid"); regex_array[2] = getval("vendor"); /* vendor string */ regex_array[3] = getval("product"); /* product string */ regex_array[4] = getval("serial"); /* probably won't see this */ regex_array[5] = getval("bus"); regex_array[6] = getval("device"); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) regex_array[7] = getval("busport"); #endif r = USBNewRegexMatcher(®ex_matcher, regex_array, REG_ICASE | REG_EXTENDED); if (r==-1) { fatal_with_errno(EXIT_FAILURE, "USBNewRegexMatcher"); } else if (r) { fatalx(EXIT_FAILURE, "invalid regular expression: %s", regex_array[r]); } /* link the matchers */ regex_matcher->next = &subdriver_matcher; /* Search for the first supported UPS matching the regular * expression */ r = comm_driver->open_dev(&udev, &curDevice, regex_matcher, match_by_unitid); if (r < 1) { fatalx(EXIT_FAILURE, "No matching USB/HID UPS found"); } hd = &curDevice; upslogx(LOG_INFO, "Detected a UPS: %s/%s", hd->Vendor ? hd->Vendor : "unknown", hd->Product ? hd->Product : "unknown"); dstate_setinfo("ups.vendorid", "%04x", hd->VendorID); dstate_setinfo("ups.productid", "%04x", hd->ProductID); /* create a new matcher for later reopening */ r = USBNewExactMatcher(&reopen_matcher, hd); if (r) { fatal_with_errno(EXIT_FAILURE, "USBNewExactMatcher"); } /* link the two matchers */ reopen_matcher->next = regex_matcher; value = getval("offdelay"); if (value) { int ival = atoi(value); if (ival >= 0) { offdelay = (unsigned int)ival; upsdebugx(2, "Setting 'offdelay' to %u", offdelay); } else { upsdebugx(2, "FAILED to set 'offdelay' to %d", ival); } } value = getval("battery_min"); if (value) { V_interval[0] = atof(value); upsdebugx(2, "Setting 'battery_min' to %.g", V_interval[0]); } value = getval("battery_max"); if (value) { V_interval[1] = atof(value); upsdebugx(2, "Setting 'battery_max' to %.g", V_interval[1]); } #if 0 if (getval("startdelay")) startdelay = atoi(getval("startdelay")); if (getval("rebootdelay")) bootdelay = atoi(getval("rebootdelay")); #endif } void upsdrv_cleanup(void) { comm_driver->close_dev(udev); USBFreeExactMatcher(reopen_matcher); USBFreeRegexMatcher(regex_matcher); free(curDevice.Vendor); free(curDevice.Product); free(curDevice.Serial); free(curDevice.Bus); free(curDevice.Device); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) free(curDevice.BusPort); #endif } nut-2.8.4/drivers/nutdrv_qx_blazer-common.c0000644000175000017500000002671515044656702016001 00000000000000/* nutdrv_qx_blazer-common.c - Common functions/settings for nutdrv_qx_{innovart31,innovart33,mecer,megatec,megatec-old,mustek,q1,q2,q6,voltronic-qs,zinto}.{c,h} * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" /* == Ranges == */ /* Range for ups.delay.start */ info_rw_t blazer_r_ondelay[] = { { "0", 0 }, { "599940", 0 }, { "", 0 } }; /* Range for ups.delay.shutdown */ info_rw_t blazer_r_offdelay[] = { { "12", 0 }, { "600", 0 }, { "", 0 } }; /* == Support functions == */ /* This function allows the subdriver to "claim" a device: return 1 if the device is supported by this subdriver, else 0. */ int blazer_claim(void) { /* To tell whether the UPS is supported or not, we'll check both status (Q1/QS/D) and vendor (I/FW?) - provided that we were not told not to do it with the ups.conf flag 'novendor'. */ item_t *item = find_nut_info("input.voltage", 0, 0); /* Don't know what happened */ if (!item) return 0; /* No reply/Unable to get value */ if (qx_process(item, NULL)) return 0; /* Unable to process value */ if (ups_infoval_set(item) != 1) return 0; if (testvar("novendor")) return 1; /* Vendor */ item = find_nut_info("ups.firmware", 0, 0); /* Don't know what happened */ if (!item) { dstate_delinfo("input.voltage"); return 0; } /* No reply/Unable to get value */ if (qx_process(item, NULL)) { dstate_delinfo("input.voltage"); return 0; } /* Unable to process value */ if (ups_infoval_set(item) != 1) { dstate_delinfo("input.voltage"); return 0; } return 1; } /* This function allows the subdriver to "claim" a device: return 1 if the device is supported by this subdriver, else 0. * NOTE: this 'light' version only checks for status (Q1/QS/D/..) */ int blazer_claim_light(void) { /* To tell whether the UPS is supported or not, we'll check just status (Q1/QS/D/..). */ item_t *item = find_nut_info("input.voltage", 0, 0); /* Don't know what happened */ if (!item) return 0; /* No reply/Unable to get value */ if (qx_process(item, NULL)) return 0; /* Unable to process value */ if (ups_infoval_set(item) != 1) return 0; return 1; } /* Subdriver-specific flags/vars */ void blazer_makevartable(void) { addvar(VAR_FLAG, "norating", "Skip reading rating information from UPS"); addvar(VAR_FLAG, "novendor", "Skip reading vendor information from UPS"); blazer_makevartable_light(); } /* Subdriver-specific flags/vars * NOTE: this 'light' version only handles vars/flags related to UPS status query (Q1/QS/D/...) */ void blazer_makevartable_light(void) { addvar(VAR_FLAG, "ignoresab", "Ignore 'Shutdown Active' bit in UPS status"); } /* Subdriver-specific initups */ void blazer_initups(item_t *qx2nut) { int nr, nv, isb; item_t *item; nr = testvar("norating"); nv = testvar("novendor"); isb = testvar("ignoresab"); if (!nr && !nv && !isb) return; for (item = qx2nut; item->info_type != NULL; item++) { if (!item->command) continue; /* norating */ if (nr && !strcasecmp(item->command, "F\r")) { upsdebugx(2, "%s: skipping %s", __func__, item->info_type); item->qxflags |= QX_FLAG_SKIP; } /* novendor */ if (nv && (!strcasecmp(item->command, "I\r") || !strcasecmp(item->command, "FW?\r"))) { upsdebugx(2, "%s: skipping %s", __func__, item->info_type); item->qxflags |= QX_FLAG_SKIP; } /* ignoresab */ if (isb && !strcasecmp(item->info_type, "ups.status") && item->from == 44 && item->to == 44) { upsdebugx(2, "%s: skipping %s ('Shutdown Active' bit)", __func__, item->info_type); item->qxflags |= QX_FLAG_SKIP; } } } /* Subdriver-specific initups * NOTE: this 'light' version only checks for status (Q1/QS/D/..) related items */ void blazer_initups_light(item_t *qx2nut) { item_t *item; if (!testvar("ignoresab")) return; for (item = qx2nut; item->info_type != NULL; item++) { if (strcasecmp(item->info_type, "ups.status") || item->from != 44 || item->to != 44) continue; upsdebugx(2, "%s: skipping %s ('Shutdown Active' bit)", __func__, item->info_type); item->qxflags |= QX_FLAG_SKIP; break; } } /* == Preprocess functions == */ /* Preprocess setvars */ int blazer_process_setvar(item_t *item, char *value, const size_t valuelen) { /* upsdebug_SET_STARTING(item->info_type, value); */ if (!strlen(value)) { upsdebugx(2, "%s: value not given for %s", __func__, item->info_type); return -1; } if (!strcasecmp(item->info_type, "ups.delay.start")) { long ondelay = strtol(value, NULL, 10); if (ondelay < 0) { upslogx(LOG_ERR, "%s: ondelay '%ld' should not be negative", item->info_type, ondelay); return -1; } /* Truncate to minute */ ondelay -= (ondelay % 60); snprintf(value, valuelen, "%ld", ondelay); } else if (!strcasecmp(item->info_type, "ups.delay.shutdown")) { long offdelay = strtol(value, NULL, 10); if (offdelay < 0) { upslogx(LOG_ERR, "%s: offdelay '%ld' should not be negative", item->info_type, offdelay); return -1; } /* Truncate to nearest settable value */ if (offdelay < 60) { offdelay -= (offdelay % 6); } else { offdelay -= (offdelay % 60); } snprintf(value, valuelen, "%ld", offdelay); } else { /* Don't know what happened: unknown entry for pre-processing? */ /* upslog_SET_UNKNOWN(item->info_type, value); */ return -1; } return 0; } /* Preprocess instant commands */ int blazer_process_command(item_t *item, char *value, const size_t valuelen) { /* upsdebug_INSTCMD_STARTING(item->info_type, value); */ if (!strcasecmp(item->info_type, "shutdown.return")) { /* Sn: Shutdown after n minutes and then turn on when mains is back * SnRm: Shutdown after n minutes and then turn on after m minutes * Accepted values for n: .2 -> .9 , 01 -> 10 * Accepted values for m: 0001 -> 9999 * Note: "S01R0001" and "S01R0002" may not work on early (GE) firmware versions. * The failure mode is that the UPS turns off and never returns. * The fix is to push the return value up by 2, i.e. S01R0003, and it will return online properly. * (thus the default of ondelay=3 mins) */ long offdelay = strtol(dstate_getinfo("ups.delay.shutdown"), NULL, 10), ondelay = strtol(dstate_getinfo("ups.delay.start"), NULL, 10) / 60; char buf[SMALLBUF] = ""; if (ondelay <= 0) { if (offdelay < 0) { upslogx(LOG_ERR, "%s: offdelay '%ld' should not be negative", item->info_type, offdelay); return -1; } if (offdelay < 60) { snprintf(buf, sizeof(buf), ".%ld", offdelay / 6); } else { snprintf(buf, sizeof(buf), "%02ld", offdelay / 60); } } else if (offdelay < 60) { if (offdelay < 0) { upslogx(LOG_ERR, "%s: offdelay '%ld' should not be negative", item->info_type, offdelay); return -1; } snprintf(buf, sizeof(buf), ".%ldR%04ld", offdelay / 6, ondelay); } else { if (offdelay < 0) { upslogx(LOG_ERR, "%s: offdelay '%ld' should not be negative", item->info_type, offdelay); return -1; } snprintf(buf, sizeof(buf), "%02ldR%04ld", offdelay / 60, ondelay); } snprintf_dynamic(value, valuelen, item->command, "%s", buf); } else if (!strcasecmp(item->info_type, "shutdown.stayoff")) { /* SnR0000 * Shutdown after n minutes and stay off * Accepted values for n: .2 -> .9 , 01 -> 10 */ long offdelay = strtol(dstate_getinfo("ups.delay.shutdown"), NULL, 10); char buf[SMALLBUF] = ""; if (offdelay < 0) { upslogx(LOG_ERR, "%s: offdelay '%ld' should not be negative", item->info_type, offdelay); return -1; } if (offdelay < 60) { snprintf(buf, sizeof(buf), ".%ld", offdelay / 6); } else { snprintf(buf, sizeof(buf), "%02ld", offdelay / 60); } snprintf_dynamic(value, valuelen, item->command, "%s", buf); } else if (!strcasecmp(item->info_type, "test.battery.start")) { long delay = strlen(value) > 0 ? strtol(value, NULL, 10) : 600; if ((delay < 60) || (delay > 5940)) { upslogx(LOG_ERR, "%s: battery test time '%ld' out of range [60..5940] seconds", item->info_type, delay); return -1; } delay = delay / 60; /* In various mapping tables, "%02d" is prevalent; actual * value is range-checked above to fit into a typical int */ if (validate_formatting_string(item->command, "%d", NUT_DYNAMICFORMATTING_DEBUG_LEVEL_SILENT) >= 0) { /* The most likely case, should not cause much overhead */ snprintf_dynamic(value, valuelen, item->command, "%d", (int)delay); } else { if (validate_formatting_string(item->command, "", NUT_DYNAMICFORMATTING_DEBUG_LEVEL_SILENT) >= 0) { /* A few mappings seem to just request the test * without parameters, so the second check is * for that eventuality */ snprintf(value, valuelen, "%s", item->command); } else { /* Finally try the actual long int (complaining * with default verbosity==1 if a bad fit) */ snprintf_dynamic(value, valuelen, item->command, "%ld", delay); } } } else { /* Don't know what happened: unknown entry for pre-processing? */ /* upslog_INSTCMD_UNKNOWN(item->info_type, value); */ return -1; } return 0; } /* Process status bits */ int blazer_process_status_bits(item_t *item, char *value, const size_t valuelen) { char *val = ""; if (strspn(item->value, "01") != 1) { upsdebugx(3, "%s: unexpected value %s@%d->%s", __func__, item->value, item->from, item->value); return -1; } switch (item->from) { case 38: /* Utility Fail (Immediate) */ if (item->value[0] == '1') val = "!OL"; else val = "OL"; break; case 39: /* Battery Low */ if (item->value[0] == '1') val = "LB"; else val = "!LB"; break; case 40: /* Bypass/Boost or Buck Active */ if (item->value[0] == '1') { double vi, vo; vi = strtod(dstate_getinfo("input.voltage"), NULL); vo = strtod(dstate_getinfo("output.voltage"), NULL); if (vo < 0.5 * vi) { upsdebugx(2, "%s: output voltage too low", __func__); return -1; } else if (vo < 0.95 * vi) { val = "TRIM"; } else if (vo < 1.05 * vi) { val = "BYPASS"; } else if (vo < 1.5 * vi) { val = "BOOST"; } else { upsdebugx(2, "%s: output voltage too high", __func__); return -1; } } break; case 41: /* UPS Failed - ups.alarm */ if (item->value[0] == '1') val = "UPS selftest failed!"; break; case 42: /* UPS Type - ups.type */ if (item->value[0] == '1') val = "offline / line interactive"; else val = "online"; break; case 43: /* Test in Progress */ if (item->value[0] == '1') val = "CAL"; else val = "!CAL"; break; case 44: /* Shutdown Active */ if (item->value[0] == '1') val = "FSD"; else val = "!FSD"; break; case 45: /* Beeper status - ups.beeper.status */ if (item->value[0] == '1') val = "enabled"; else val = "disabled"; break; default: /* Don't know what happened */ return -1; } snprintf(value, valuelen, "%s", val); return 0; } nut-2.8.4/drivers/main.h0000644000175000017500000001741415000736161012035 00000000000000#ifndef NUT_MAIN_H_SEEN #define NUT_MAIN_H_SEEN 1 #include "common.h" #include "upsconf.h" #include "upshandler.h" #include "dstate.h" #include "extstate.h" #ifdef WIN32 #include "wincompat.h" #endif /* WIN32 */ /* public functions & variables from main.c, documented in detail there */ extern const char *progname, *upsname, *device_name; extern char *device_path, *device_sdcommands; extern int broken_driver, experimental_driver, do_lock_port, exit_flag, handling_upsdrv_shutdown; extern TYPE_FD upsfd, extrafd; extern time_t poll_interval; /* functions & variables required in each driver */ void upsdrv_initups(void); /* open connection to UPS, fail if not found */ void upsdrv_initinfo(void); /* prep data, settings for UPS monitoring */ void upsdrv_updateinfo(void); /* update state data if possible */ void upsdrv_shutdown(void); /* make the UPS power off the load */ void upsdrv_help(void); /* tack on anything useful for the -h text */ void upsdrv_banner(void); /* print your version information */ void upsdrv_cleanup(void); /* free any resources before shutdown */ void set_exit_flag(int sig); /* --- details for the variable/value sharing --- */ /* Try each instant command in the comma-separated list of * sdcmds, until the first one that reports it was handled. * Returns STAT_INSTCMD_HANDLED if one of those was accepted * by the device, or STAT_INSTCMD_INVALID if none succeeded. * If cmdused is not NULL, it is populated by the command * string which succeeded (or NULL if none), and the caller * should free() it eventually. */ int do_loop_shutdown_commands(const char *sdcmds, char **cmdused); #define MAX_SDCOMMANDS_DEPTH 15 /* Use driver-provided sdcmds_default, unless a custom driver parameter value * "sdcommands" is set - then use it instead. Call do_loop_shutdown_commands() * for actual work; return STAT_INSTCMD_HANDLED or STAT_INSTCMD_HANDLED as * applicable; if caller-provided cmdused is not NULL, populate it with the * command that was used successfully (if any). */ int loop_shutdown_commands(const char *sdcmds_default, char **cmdused); /* * Effectively call loop_shutdown_commands("shutdown.default") (which in turn * probably calls some other INSTCMD, but may be using a more custom logic), * and report how that went. * Depending on run-time circumstances, probably set_exit_flag() too. */ int upsdrv_shutdown_sdcommands_or_default(const char *sdcmds_default, char **cmdused); /* handle instant commands common for all drivers * (returns STAT_INSTCMD_* state values per enum in upshandler.h) */ int main_instcmd(const char *cmdname, const char *extra, conn_t *conn); /* handle setting variables common for all drivers * (returns STAT_SET_* state values per enum in upshandler.h) */ int main_setvar(const char *varname, const char *val, conn_t *conn); /* main calls this driver function - it needs to call addvar */ void upsdrv_makevartable(void); /* retrieve the value of variable if possible */ char *getval(const char *var); /* see if has been defined, even if no value has been given to it */ int testvar(const char *var); /* extended variable table - used for -x defines/flags */ typedef struct vartab_s { int vartype; /* VAR_* value, below */ char *var; /* left side of =, or whole word if none */ char *val; /* right side of = */ char *desc; /* 40 character description for -h text */ int found; /* set once encountered, for testvar() */ int reloadable; /* driver reload may redefine this value */ struct vartab_s *next; } vartab_t; /* flags to define types in the vartab */ #define VAR_FLAG 0x0001 /* argument is a flag (no value needed) */ #define VAR_VALUE 0x0002 /* argument requires a value setting */ #define VAR_SENSITIVE 0x0004 /* do not publish in driver.parameter */ /* callback from driver - create the table for future -x entries */ void addvar(int vartype, const char *name, const char *desc); void addvar_reloadable(int vartype, const char *name, const char *desc); /* Several helpers for driver configuration reloading follow: * * testval_reloadable() checks if we are currently reloading (or initially * loading) the configuration, and if strings oldval==newval or not, * e.g. for values saved straight into driver source code variables; * * testinfo_reloadable() checks this for a name saved as dstate_setinfo(); * * testvar_reloadable() checks in vartab_t list as maintained by addvar(). * * All these methods check if value can be (re-)loaded now: * * either it is reloadable by argument or vartab_t definition, * * or no value has been saved into it yet (e.g. is NULL), * * or we are handling initial loading and keep legacy behavior of trusting * the inputs (e.g. some values may be defined as defaults in global section * and tuned in a driver section). * * Return values: * * -1 -- if nothing needs to be done and that is not a failure * (e.g. value not modified so we do not care if we may change it or not); * * 0 -- if can not modify this value (but it did change in config); * * 1 -- if we can and should apply a new (maybe initial) value. */ int testvar_reloadable(const char *var, const char *val, int vartype); int testval_reloadable(const char *var, const char *oldval, const char *newval, int reloadable); int testinfo_reloadable(const char *var, const char *infoname, const char *newval, int reloadable); /* subdriver description structure */ typedef struct upsdrv_info_s { const char *name; /* driver full name, for banner printing, ... */ const char *version; /* driver version */ const char *authors; /* authors name */ const int status; /* driver development status */ struct upsdrv_info_s *subdrv_info[2]; /* sub driver information */ } upsdrv_info_t; /* flags to define the driver development status */ #define DRV_BROKEN 0x0001 /* dito... */ #define DRV_EXPERIMENTAL 0x0002 /* dito... */ #define DRV_BETA 0x0004 /* more stable and complete, but still * not suitable for production systems */ #define DRV_STABLE 0x0008 /* suitable for production systems, but * not 100 % feature complete */ #define DRV_COMPLETE 0x0010 /* gold level: implies 100 % of the * protocol implemented and the full QA * pass */ /* FIXME: complete with mfr support, and other interesting info */ /* public driver information from the driver file */ extern upsdrv_info_t upsdrv_info; /* functions and data possibly used via libdummy_mockdrv.la for unit-tests */ #ifdef DRIVERS_MAIN_WITHOUT_MAIN extern vartab_t *vartab_h; void dparam_setinfo(const char *var, const char *val); void storeval(const char *var, char *val); void vartab_free(void); void setup_signals(void); #endif /* DRIVERS_MAIN_WITHOUT_MAIN */ #ifndef WIN32 # define SIGCMD_RELOAD SIGHUP /* not a signal, so negative; relies on socket protocol */ # define SIGCMD_EXIT -SIGTERM # define SIGCMD_RELOAD_OR_ERROR -SIGCMD_RELOAD # define SIGCMD_RELOAD_OR_EXIT SIGUSR1 /* // FIXME: Implement this self-recycling in drivers (keeping the PID): # define SIGCMD_RELOAD_OR_RESTART SIGUSR2 */ /* This is commonly defined on systems we know; file bugs/PRs for * relevant systems where it is not present (SIGWINCH might be an * option there, though terminal resizes might cause braindumps). * Their packaging may want to add a patch for this bit (and docs). */ # if (defined SIGURG) # define SIGCMD_DATA_DUMP SIGURG # else # if (defined SIGWINCH) # define SIGCMD_DATA_DUMP SIGWINCH # else # pragma warn "This OS lacks SIGURG and SIGWINCH, will not handle SIGCMD_DATA_DUMP" # endif # endif #else /* WIN32 */ /* FIXME NUT_WIN32_INCOMPLETE : handle WIN32 builds for other signals too */ # define SIGCMD_EXIT "driver.exit" # define SIGCMD_RELOAD_OR_ERROR "driver.reload-or-error" /* NUT_WIN32_INCOMPLETE */ #endif /* WIN32 */ #endif /* NUT_MAIN_H_SEEN */ nut-2.8.4/drivers/apc_modbus.h0000664000175000017500000001135115000733176013224 00000000000000/* apc_modbus.h - Driver for APC Modbus UPS * Copyright © 2023 Axel Gembe * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef APC_MODBUS_H #define APC_MODBUS_H #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_PENDING (1 << 0) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_INPROGRESS (1 << 1) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_PASSED (1 << 2) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_FAILED (1 << 3) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_REFUSED (1 << 4) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_ABORTED (1 << 5) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_SOURCE_PROTOCOL (1 << 6) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_SOURCE_LOCALUI (1 << 7) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_SOURCE_INTERNAL (1 << 8) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_MOD_INVALIDSTATE (1 << 9) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_MOD_INTERNALFAULT (1 << 10) #define APC_MODBUS_REPLACEBATTERYTESTSTATUS_BF_MOD_STATEOFCHARGENOTACCEPTABLE (1 << 11) #define APC_MODBUS_SOGRELAYCONFIGSETTING_BF_REG 590 #define APC_MODBUS_SOGRELAYCONFIGSETTING_BF_MOG_PRESENT (1 << 0) #define APC_MODBUS_SOGRELAYCONFIGSETTING_BF_SOG_0_PRESENT (1 << 1) #define APC_MODBUS_SOGRELAYCONFIGSETTING_BF_SOG_1_PRESENT (1 << 2) #define APC_MODBUS_SOGRELAYCONFIGSETTING_BF_SOG_2_PRESENT (1 << 3) #define APC_MODBUS_SOGRELAYCONFIGSETTING_BF_SOG_3_PRESENT (1 << 4) #define APC_MODBUS_UPSCOMMAND_BF_REG 1536 /* 0 - 2 are reserved */ #define APC_MODBUS_UPSCOMMAND_BF_RESTORE_FACTORY_SETTINGS (1 << 3) #define APC_MODBUS_UPSCOMMAND_BF_OUTPUT_INTO_BYPASS (1 << 4) #define APC_MODBUS_UPSCOMMAND_BF_OUTPUT_OUT_OF_BYPASS (1 << 5) /* 6 - 8 are reserved */ #define APC_MODBUS_UPSCOMMAND_BF_CLEAR_FAULTS (1 << 9) /* 10 - 12 are reserved */ #define APC_MODBUS_UPSCOMMAND_BF_RESET_STRINGS (1 << 13) #define APC_MODBUS_UPSCOMMAND_BF_RESET_LOGS (1 << 14) #define APC_MODBUS_OUTLETCOMMAND_BF_REG 1538 #define APC_MODBUS_OUTLETCOMMAND_BF_CMD_CANCEL (1 << 0) #define APC_MODBUS_OUTLETCOMMAND_BF_CMD_OUTPUT_ON (1 << 1) #define APC_MODBUS_OUTLETCOMMAND_BF_CMD_OUTPUT_OFF (1 << 2) #define APC_MODBUS_OUTLETCOMMAND_BF_CMD_OUTPUT_SHUTDOWN (1 << 3) #define APC_MODBUS_OUTLETCOMMAND_BF_CMD_OUTPUT_REBOOT (1 << 4) #define APC_MODBUS_OUTLETCOMMAND_BF_MOD_COLD_BOOT_ALLOWED (1 << 5) #define APC_MODBUS_OUTLETCOMMAND_BF_MOD_USE_ON_DELAY (1 << 6) #define APC_MODBUS_OUTLETCOMMAND_BF_MOD_USE_OFF_DELAY (1 << 7) #define APC_MODBUS_OUTLETCOMMAND_BF_TARGET_MAIN_OUTLET_GROUP (1 << 8) #define APC_MODBUS_OUTLETCOMMAND_BF_TARGET_SWITCHED_OUTLET_GROUP_0 (1 << 9) #define APC_MODBUS_OUTLETCOMMAND_BF_TARGET_SWITCHED_OUTLET_GROUP_1 (1 << 10) #define APC_MODBUS_OUTLETCOMMAND_BF_TARGET_SWITCHED_OUTLET_GROUP_2 (1 << 11) #define APC_MODBUS_OUTLETCOMMAND_BF_SOURCE_USB_PORT (1 << 12) #define APC_MODBUS_OUTLETCOMMAND_BF_SOURCE_LOCAL_USER (1 << 13) #define APC_MODBUS_OUTLETCOMMAND_BF_SOURCE_RJ45_PORT (1 << 14) #define APC_MODBUS_OUTLETCOMMAND_BF_SOURCE_SMART_SLOT_1 (1 << 15) #define APC_MODBUS_OUTLETCOMMAND_BF_SOURCE_SMART_SLOT_2 (1 << 16) #define APC_MODBUS_OUTLETCOMMAND_BF_SOURCE_INTERNAL_NETWORK_1 (1 << 17) #define APC_MODBUS_OUTLETCOMMAND_BF_SOURCE_INTERNAL_NETWORK_2 (1 << 18) #define APC_MODBUS_REPLACEBATTERYTESTCOMMAND_BF_REG 1541 #define APC_MODBUS_REPLACEBATTERYTESTCOMMAND_BF_START (1 << 0) #define APC_MODBUS_REPLACEBATTERYTESTCOMMAND_BF_ABORT (1 << 1) #define APC_MODBUS_RUNTIMECALIBRATIONCOMMAND_BF_REG 1542 #define APC_MODBUS_RUNTIMECALIBRATIONCOMMAND_BF_START (1 << 0) #define APC_MODBUS_RUNTIMECALIBRATIONCOMMAND_BF_ABORT (1 << 1) #define APC_MODBUS_USERINTERFACECOMMAND_BF_REG 1543 #define APC_MODBUS_USERINTERFACECOMMAND_BF_SHORT_TEST (1 << 0) #define APC_MODBUS_USERINTERFACECOMMAND_BF_CONTINUOUS_TEST (1 << 1) #define APC_MODBUS_USERINTERFACECOMMAND_BF_MUTE_ALL_ACTIVE_AUDIBLE_ALARMS (1 << 2) #define APC_MODBUS_USERINTERFACECOMMAND_BF_CANCEL_MUTE (1 << 3) /* 4 is reserved */ #define APC_MODBUS_USERINTERFACECOMMAND_BF_ACKNOWLEDGE_BATTERY_ALARMS (1 << 5) #define APC_MODBUS_USERINTERFACECOMMAND_BF_ACKNOWLEDGE_SITE_WIRING_ALARM (1 << 6) #endif /* APC_MODBUS_H */ nut-2.8.4/drivers/nutdrv_qx_blazer-common.h0000644000175000017500000000320015044656702015766 00000000000000/* nutdrv_qx_blazer-common.h - Common functions/settings for nutdrv_qx_{innovart31,innovart33,mecer,megatec,megatec-old,mustek,q1,q2,q6,voltronic-qs,zinto}.{c,h} * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_BLAZER_COMMON_H #define NUTDRV_QX_BLAZER_COMMON_H #include "nutdrv_qx.h" /* Support functions */ void blazer_makevartable(void); void blazer_makevartable_light(void); void blazer_initups(item_t *qx2nut); void blazer_initups_light(item_t *qx2nut); int blazer_claim(void); int blazer_claim_light(void); /* Preprocess functions */ int blazer_process_command(item_t *item, char *value, const size_t valuelen); int blazer_process_setvar(item_t *item, char *value, const size_t valuelen); int blazer_process_status_bits(item_t *item, char *value, const size_t valuelen); /* Ranges */ extern info_rw_t blazer_r_ondelay[]; extern info_rw_t blazer_r_offdelay[]; #endif /* NUTDRV_QX_BLAZER_COMMON_H */ nut-2.8.4/drivers/ve-direct.c0000644000175000017500000001532415044656702012776 00000000000000/* ve-direct.c - Model specific routines for Victron Energy Direct units * * Copyright (C) 2017 Petr Kubanek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "serial.h" #define DRIVER_NAME "Victron Energy Direct UPS and solar controller driver" #define DRIVER_VERSION "0.22" #define VE_GET 7 #define VE_SET 8 /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Petr Kubanek ", DRV_EXPERIMENTAL, { NULL } }; /* FIXME: Does the protocol dictate a certain size here? * Or can SMALLBUF etc. suffice? */ static char line[500]; static size_t r_start = 0; static void ve_copy(const char *endl) { size_t left = (line + r_start) - endl; if (left > 0) memmove(line, endl, left); r_start = left; } static int ve_process_text_buffer(void) { char vn[50], ch; char *v_name, *v_value, *checksum; upsdebugx (3, "%s: buf '%s'", __func__, line); /* find checksum, verify checksum */ checksum = strstr(line, "Checksum\t"); if (checksum == NULL || checksum + 9 >= line + r_start) return -1; /* calculate checksum */ ch = 0; for (v_name = line; v_name <= checksum + 8; v_name++) ch += *v_name; ch = ~ch + 1; if (ch != checksum[9]) { upsdebugx(1, "invalid checksum: %d %d", ch, checksum[9]); ve_copy(checksum + 10); return 0; } checksum[9] = '\0'; /* parse what is in buffer */ v_name = line; while (v_name < checksum) { char *end; if (v_name[0] != '\r' || v_name[1] != '\n') break; v_name += 2; v_value = v_name; while (*v_value != '\t' && *v_value != '\0') v_value++; if (v_value >= checksum) break; *v_value = '\0'; v_value++; end = v_value; while (*end != '\r' && *end != '\0') end++; if (*end != '\r') break; *end = '\0'; snprintf(vn, sizeof(vn), "experimental.ve-direct.%s", v_name); upsdebugx(1, "name %s value %s", vn, v_value); dstate_setinfo(vn, "%s", v_value); v_name = end; *v_name = '\r'; } ve_copy(checksum + 10); return 0; } /* calculates checksum for VE.Direct HEX command/reply */ static unsigned char ve_checksum(const char ve_cmd, const char *ve_extra) { unsigned char ch = ve_cmd - '0'; if (ve_extra != NULL) { const char *ve; for (ve = ve_extra; *ve != '\0'; ve++) { if (ve[1] != '\0') { unsigned int a; sscanf (ve, "%02X", &a); ch += (unsigned char) a; ve++; } } } ch = 0x55 - ch; return ch; } static int ve_command(const char ve_cmd, const char *ve_extra, char *ve_return, size_t ret_length) { int ret; char *reply = NULL; char *endl = NULL; if (ve_extra != NULL) ser_send(upsfd, ":%c%s%02X\n", ve_cmd, ve_extra, ve_checksum(ve_cmd, ve_extra)); else ser_send(upsfd, ":%c%02X\n", ve_cmd, ve_checksum(ve_cmd, ve_extra)); while (endl == NULL) { ret = ser_get_buf(upsfd, line + r_start, sizeof(line) - r_start, 2, 0); if (ret < 0) return STAT_INSTCMD_FAILED; r_start += ret; /* check if we read full line with the reply... */ reply = strchr(line, ':'); endl = NULL; if (reply != NULL) endl = strchr(reply, '\n'); /* already seen start of command reply */ if (reply != NULL && endl != NULL) break; ve_process_text_buffer(); } /* process what's left */ while (line[0] != ':') { if (ve_process_text_buffer() < 0) break; } endl = NULL; endl = strchr(line, '\n'); if (endl != NULL) { int checksum = -1; *endl = '\0'; upsdebugx(2, "reply to command: %s", line); sscanf(endl - 2, "%02X", (unsigned int *)&checksum); endl[-2] = '\0'; if (checksum == ve_checksum(line[1], line + 2)) { upsdebugx(3, "correct checksum on reply to command %c", line[1]); } else { upslogx(LOG_INSTCMD_FAILED, "invalid checksum on reply to command %c", line[1]); return STAT_INSTCMD_FAILED; } if (ve_return != NULL) { size_t r_len; memset(ve_return, 9, ret_length); r_len = endl - line - 4; if (r_len > 0) { strncpy(ve_return, line + 2, r_len > ret_length ? ret_length : r_len); } } ve_copy (endl + 1); } return STAT_INSTCMD_HANDLED; } static int instcmd(const char *cmdname, const char *extra) { upsdebug_INSTCMD_STARTING(cmdname, extra); /* experimental: many of the names below are not among * standard docs/nut-names.txt */ if (!strcasecmp(cmdname, "experimental.ve-direct.ping")) return ve_command('1', NULL, NULL, 0); if (!strcasecmp(cmdname, "experimental.ve-direct.get")) return ve_command(VE_GET, extra, NULL, 0); if (!strcasecmp(cmdname, "experimental.ve-direct.set")) return ve_command(VE_SET, extra, NULL, 0); if (!strcasecmp(cmdname, "beeper.disable")) return ve_command(VE_SET, "FCEE0000", NULL, 0); if (!strcasecmp(cmdname, "beeper.enable")) return ve_command(VE_SET, "FCEE0001", NULL, 0); upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_initinfo(void) { /* experimental: the names below are not among * standard docs/nut-names.txt */ dstate_addcmd("experimental.ve-direct.ping"); dstate_addcmd("experimental.ve-direct.set"); dstate_addcmd("experimental.ve-direct.get"); dstate_addcmd("beeper.disable"); dstate_addcmd("beeper.enable"); upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { /* ups.status */ status_init(); status_set("OL"); status_commit(); upsdebugx(1, "upsdrv_updateinfo: ups.status = %s", dstate_getinfo("ups.status")); /************** ups.x ***************************/ while (1) { int nred; if (r_start >= sizeof(line)) r_start = 0; memset(line + r_start, 0, sizeof(line) - r_start); nred = ser_get_buf(upsfd, line + r_start, sizeof(line) - r_start, 0, 200); if (nred < 0) break; if (nred == 0) continue; r_start += nred; while (ve_process_text_buffer() >= 0) { } break; } dstate_dataok(); } void upsdrv_shutdown(void) { } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { } void upsdrv_initups(void) { #ifndef TESTING poll_interval = 1; upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B19200); #endif } void upsdrv_cleanup(void) { #ifndef TESTING ser_close(upsfd, device_path); #endif } nut-2.8.4/drivers/optiups.c0000644000175000017500000004741615044656702012626 00000000000000/* optiups.c - OptiSafe UPS (very loosely based on the nut 0.45.5 driver) Copyright (C) 1999 Russell Kroll Copyright (C) 2006 Scott Heavner [Use my alioth acct: sheavner] Support for Zinto D from ONLINE USV (only minor differences to OptiSafe UPS) added by Matthias Goebl This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ================================================================================== */ #include "main.h" #include "serial.h" #include "nut_stdint.h" #define DRIVER_NAME "Opti-UPS driver" #define DRIVER_VERSION "1.08" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Russell Kroll \n" \ "Scott Heavner \n" \ "Matthias Goebl ", DRV_STABLE, { NULL } }; #define HELP "\n" \ "**********************************************************" "\n" \ "This driver has been tested only with the OPTI SAFE 420E using" "\n" \ "the custom cable described in the NUT Opti-UPS protocol page." "\n" \ "Seriously, it does _NOT_ work with the [windows] cable provided with" "\n" \ "the UPS or a standard serial cable. (I don't know if OPTI makes other" "\n" \ "UPS models that will work with another cable?) Standard linux serial" "\n" \ "port drivers do not support the required DTR handshaking." "\n" \ "" "\n" \ " UPS 6 -> PC 3 This 3 wire cable pinout maps DTR to CTS." "\n" \ " UPS 9 -> PC 2" "\n" \ " UPS 4 -> PC 5" "\n" \ "" "\n" \ "This driver has also been tested with a Zinto D from Online-USV AG," "\n" \ "using their special cable:" "\n" \ " UPS 6 -> PC 3" "\n" \ " UPS 9 -> PC 2" "\n" \ " UPS 7 -> PC 5" "\n" \ "It works even with a pl2303 usb-serial converter." "\n" \ "**********************************************************" "\n" /* See https://www.networkupstools.org/protocols/optiups.html and the end of this * file for more information on the cable and the OPTI-UPS serial protocol used on * at least the older OPTI UPS models (420E, 820ES). */ #define ENDCHAR '\n' #define IGNCHARS "\r" /* Our custom options available with -x */ #define OPTI_MINPOLL "status_only" #define OPTI_FAKELOW "fake_lowbatt" #define OPTI_NOWARN_NOIMP "nowarn_noimp" #define OPTI_POWERUP "powerup" /* All serial commands put their response in the same buffer space */ static char opti_buf[256]; /* Model */ static int optimodel = 0; enum { OPTIMODEL_DEFAULT = 0, OPTIMODEL_ZINTO = 1, OPTIMODEL_PS = 2 }; /* Status bits returned by the "AG" command */ enum { OPTISBIT_NOOUTPUT = 2L, OPTISBIT_OVERLOAD = 8L, OPTISBIT_REPLACE_BATTERY = 16L, OPTISBIT_ON_BATTERY_POWER = 32L, OPTISBIT_LOW_BATTERY = 64L }; /* Helper struct for the optifill() function */ typedef struct ezfill_s { const char *cmd; const char *var; const float scale; /* if 0, no conversion is done and the string is passed to dstate as is, otherwise a float conversion with single decimal is applied */ } ezfill_t; /* These can be polled right into a string usable by NUT. * Others such as "AG" and "BV" require some transformation of the return value */ static ezfill_t opti_pollv[] = { { "NV", "input.voltage", 0 }, { "OL", "ups.load", 1.0 }, { "OV", "output.voltage", 0 }, { "FF", "input.frequency", 0.1 }, { "BT", "ups.temperature", 0 }, }; static ezfill_t opti_pollv_zinto[] = { { "NV", "input.voltage", 2.0 }, { "OL", "ups.load", 1.0 }, { "OV", "output.voltage", 2.0 }, { "OF", "output.frequency", 0.1 }, { "NF", "input.frequency", 0.1 }, { "BT", "ups.temperature", 0 }, }; /* When on a 220-2400V mains supply, the NV and OV commands return 115V values. FV * returns a value that matches the DIP switch settings for 120/240V models, so * it can be used to scale the valus from NV and OV. * * I suspect this will be the case for other Opti-UPS models, but as I can only * test with a PS-1440RM at 230V the change is only applied to PowerSeries models. */ static ezfill_t opti_pollv_ps[] = { { "OL", "ups.load", 1.0 }, { "FF", "input.frequency", 0.1 }, { "BT", "ups.temperature", 0 }, }; /* model "IO" is parsed differently in upsdrv_initinfo() */ static ezfill_t opti_initv[] = { { "IM", "ups.mfr", 0 }, { "IZ", "ups.serial", 0 }, { "IS", "ups.firmware", 0 }, }; /* All serial reads of the OPTI-UPS go through here. We always expect a CR/LF terminated * response. Unknown/Unimplemented commands return ^U (0x15). Actions that complete * successfully return ^F (0x06). */ static inline ssize_t optireadline(void) { ssize_t r; usleep(150000); r = ser_get_line(upsfd, opti_buf, sizeof(opti_buf), ENDCHAR, IGNCHARS, 0, 500000 ); opti_buf[sizeof(opti_buf)-1] = 0; if ( r > 0 ) { if ( r < (int)sizeof(opti_buf) ) opti_buf[r] = 0; if ( opti_buf[0] == 0x15 ) { r=-2; upsdebugx(1, "READ: "); } if ( opti_buf[0] == 0x06 ) { upsdebugx(2, "READ: "); } else { upsdebugx(2, "READ: \"%s\"", opti_buf ); } } else upsdebugx(1, "READ ERROR: %" PRIiSIZE, r); return r; } /* Send a command and read the response. Command response is in global opti_buf. * Return * > 0 implies success. * -1 serial timeout * -2 unknown/unimplemented command */ static inline ssize_t optiquery( const char *cmd ) { upsdebugx(2, "SEND: \"%s\"", cmd ); ser_send( upsfd, "%s", cmd ); if ( optimodel == OPTIMODEL_ZINTO ) ser_send( upsfd, "\r\n" ); return optireadline(); } /* Uses the ezfill_t structure to map UPS commands to the NUT variable destinations */ static void optifill( ezfill_t *a, size_t len ) { size_t i; ssize_t r; /* Some things are easy to poll and store */ for ( i=0; i 1e-20 ) { float f = strtol( opti_buf, NULL, 10 ) * a[i].scale; dstate_setinfo( a[i].var, "%.1f", f ); } else { dstate_setinfo( a[i].var, "%s", opti_buf); } } } /* Handle custom (but standardized) NUT commands */ static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "test.failure.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); optiquery( "Ts" ); return STAT_INSTCMD_HANDLED; } else if (!strcasecmp(cmdname, "load.off")) { /* You do realize this will kill power to ourself. * Would probably only be useful for killing power for * a computer with upsmon in "secondary" mode */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if ( optimodel == OPTIMODEL_ZINTO ) { optiquery( "Ct1" ); optiquery( "Cs0000000" ); sleep(2); return STAT_INSTCMD_HANDLED; } optiquery( "Ct0" ); optiquery( "Cs00000000" ); return STAT_INSTCMD_HANDLED; } else if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if ( optimodel == OPTIMODEL_ZINTO ) { optiquery( "Ct1" ); optiquery( "Cu0000000" ); sleep(2); return STAT_INSTCMD_HANDLED; } optiquery( "Ct0" ); optiquery( "Cu00000000" ); return STAT_INSTCMD_HANDLED; } else if (!strcasecmp(cmdname, "shutdown.return")) { /* This shuts down the UPS. When the power returns to the UPS, * it will power back up in its default state. */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if ( optimodel == OPTIMODEL_ZINTO ) { optiquery( "Ct1" ); optiquery( "Cu0000010" ); optiquery( "Cs0000001" ); return STAT_INSTCMD_HANDLED; } optiquery( "Ct1" ); optiquery( "Cs00000010" ); return STAT_INSTCMD_HANDLED; } else if (!strcasecmp(cmdname, "shutdown.stayoff")) { /* This actually stays off as long as the batteries hold, * if the line power comes back before the batteries die, * the UPS will never powerup its output stage!!! */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if ( optimodel == OPTIMODEL_ZINTO ) { optiquery( "Ct1" ); optiquery( "Cs0000001" ); return STAT_INSTCMD_HANDLED; } optiquery( "Ct0" ); optiquery( "Cs00000010" ); return STAT_INSTCMD_HANDLED; } else if (!strcasecmp(cmdname, "shutdown.stop")) { /* Aborts a shutdown that is counting down via the Cs command */ upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); optiquery( "Cs-0000001" ); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } /* Handle variable setting */ static int setvar(const char *varname, const char *val) { int status; upsdebug_SET_STARTING(varname, val); if (sscanf(val, "%d", &status) != 1) { return STAT_SET_UNKNOWN; } if (strcasecmp(varname, "outlet.1.switch") == 0) { status = status==1 ? 1 : 0; dstate_setinfo( "outlet.1.switch", "%d", status); optiquery(status ? "Oi11" : "Oi10"); dstate_dataok(); return STAT_SET_HANDLED; } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } void upsdrv_initinfo(void) { ssize_t r; /* If an Zinto Online-USV is off, switch it on first. */ /* It sends only "2" when off, without "\r\n", and doesn't */ /* answer other commands. Therefore without power we'll be */ /* unable to identify the ups. */ if ( testvar(OPTI_POWERUP) && optiquery( "AG" ) < 1 ) { ser_send( upsfd, "AG\r\n" ); r = ser_get_char(upsfd, &opti_buf[0], 1, 0); if ( r == 1 && opti_buf[0] == '2' ) { upslogx( LOG_WARNING, "ups was off, switching it on" ); optiquery( "Ct1" ); optiquery( "Cu0000000" ); /* wait for power up */ sleep(15); } } /* Autodetect an Online-USV (only Zinto D is known to work) */ r = optiquery( "IM" ); if ( r > 0 && !strcasecmp(opti_buf, "ONLINE") ) { optimodel = OPTIMODEL_ZINTO; optiquery( "Om11" ); optiquery( "Om21" ); optiquery( "ON" ); } /* Autodetect an Opti-UPS PS series */ r = optiquery( "IO" ); if ( r > 0 && !strncasecmp(opti_buf, "PS-", 3) ) { optimodel = OPTIMODEL_PS; } optifill( opti_initv, SIZEOF_ARRAY(opti_initv) ); /* Parse out model into longer string -- is this really USEFUL??? */ r = optiquery( "IO" ); if ( r < 1 ) fatal_with_errno(EXIT_FAILURE, "can't retrieve model" ); else { switch ( opti_buf[r-1] ) { case 'E': case 'P': case 'V': dstate_setinfo("ups.model", "Power%cS %s", opti_buf[r-1], opti_buf ); break; default: dstate_setinfo("ups.model", "%s", opti_buf ); break; } } /* Parse out model into longer string */ r = optiquery( "IM" ); if ( r > 0 && !strcasecmp(opti_buf, "ONLINE") ) { dstate_setinfo("ups.mfr", "ONLINE USV-Systeme AG"); r = optiquery( "IO" ); if ( r < 1 ) fatal_with_errno(EXIT_FAILURE, "can't retrieve model" ); switch ( opti_buf[0] ) { case 'D': dstate_setinfo("ups.model", "Zinto %s", opti_buf ); break; default: dstate_setinfo("ups.model", "%s", opti_buf ); break; } } dstate_addcmd("test.failure.start"); dstate_addcmd("load.off"); dstate_addcmd("load.on"); if( optimodel != OPTIMODEL_ZINTO ) dstate_addcmd("shutdown.stop"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); upsh.instcmd = instcmd; if ( optimodel == OPTIMODEL_ZINTO ) { dstate_setinfo("outlet.desc", "%s", "Main Outlet 1+2"); dstate_setinfo("outlet.1.desc", "%s", "Switchable Outlet 3+4"); dstate_setinfo("outlet.id", "%d", 1); dstate_setinfo("outlet.1.id", "%d", 2); dstate_setinfo("outlet.switchable", "%d", 0); dstate_setinfo("outlet.1.switchable", "%d", 1); dstate_setinfo("outlet.1.switch", "%d", 1); dstate_setflags("outlet.1.switch", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("outlet.1.switch", 1); upsh.setvar = setvar; } } void upsdrv_updateinfo(void) { ssize_t r = optiquery( "AG" ); /* Online-UPS send only "2" when off, without "\r\n" */ if ( r < 1 && optimodel == OPTIMODEL_ZINTO ) { ser_send( upsfd, "AG\r\n" ); r = ser_get_char(upsfd, &opti_buf[0], 1, 0); if ( r == 1 && opti_buf[0] == '2' ) { status_init(); status_set("OFF"); status_commit(); return; } } if ( r < 1 ) { upslogx(LOG_ERR, "can't retrieve ups status" ); dstate_datastale(); } else { long s = strtol( opti_buf, NULL, 16 ); status_init(); if ( s & OPTISBIT_OVERLOAD ) status_set("OVER"); if ( s & OPTISBIT_REPLACE_BATTERY ) status_set("RB"); if ( s & OPTISBIT_ON_BATTERY_POWER ) status_set("OB"); else status_set("OL"); if ( s & OPTISBIT_NOOUTPUT ) status_set("OFF"); if ( s & OPTISBIT_LOW_BATTERY ) status_set("LB"); if ( testvar(OPTI_FAKELOW) ) /* FOR TESTING */ status_set("LB"); status_commit(); dstate_dataok(); } /* Get out of here now if minimum polling is desired */ if ( testvar(OPTI_MINPOLL) ) return; /* read some easy settings */ if ( optimodel == OPTIMODEL_ZINTO ) optifill( opti_pollv_zinto, SIZEOF_ARRAY(opti_pollv_zinto) ); else if ( optimodel == OPTIMODEL_PS ) { short inV, outV, fV; optifill( opti_pollv_ps, SIZEOF_ARRAY(opti_pollv_ps) ); r = optiquery( "NV" ); str_to_short ( opti_buf, &inV, 10 ); r = optiquery( "OV" ); str_to_short ( opti_buf, &outV, 10 ); r = optiquery( "FV" ); if ( r >= 1 ) { str_to_short ( opti_buf, &fV, 10 ); if ( fV > 180 ) { inV = inV * 2; outV = outV * 2; } } dstate_setinfo( "input.voltage", "%d", inV ); dstate_setinfo( "output.voltage", "%d", outV ); } else optifill( opti_pollv, SIZEOF_ARRAY(opti_pollv) ); /* Battery voltage is harder */ r = optiquery( "BV" ); if ( r < 1 ) upslogx( LOG_WARNING, "cannot retrieve battery voltage" ); else { float p, v = strtol( opti_buf, NULL, 10 ) / 10.0; dstate_setinfo("battery.voltage", "%.1f", v ); if (v > 20) { /* battery voltage range: 20.8 - 26.0 VDC */ p = ((v - 20.8) / 5.2) * 100.0; } else { /* battery voltage range: 10.4 - 13.0 VDC */ p = ((v - 10.4) / 2.6) * 100.0; } if ( p > 100.0 ) p = 100.0; dstate_setinfo("battery.charge", "%.1f", p ); } } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* OL: this must power cycle the load if possible */ /* OB: the load must remain off until the power returns */ /* If get no response, assume on battery & battery low */ long s = OPTISBIT_ON_BATTERY_POWER | OPTISBIT_LOW_BATTERY; ssize_t r = optiquery( "AG" ); if ( r < 1 ) { upslogx(LOG_ERR, "can't retrieve ups status during shutdown" ); } else { s = strtol( opti_buf, NULL, 16 ); } /* Turn output stage back on if power returns - but really means * turn off ups if on battery */ optiquery( "Ct1" ); /* What happens, if the power comes back *after* reading the ups status and * before the shutdown command? For "Online-UPS Zinto D" *always* asking for * "shutdown shortly and power-up later" works perfectly, because it forces * a power cycle, even for the named race condition. * For Opti-UPS I have no information, so I wouldn't dare to change it. * BTW, Zinto expects only 7 digits after Cu/Cs. * (Matthias Goebl) */ if ( optimodel == OPTIMODEL_ZINTO ) { /* On line power: Power up in 60 seconds (30 seconds after the following shutdown) */ /* On battery: Power up when the line power returns */ optiquery( "Cu0000060" ); /* Shutdown in 30 seconds */ optiquery( "Cs0000030" ); return; } /* Just cycling power, schedule output stage to come back on in 60 seconds */ if ( !(s & OPTISBIT_ON_BATTERY_POWER) ) optiquery( "Cu00000600" ); /* Shutdown in 8 seconds */ optiquery( "Cs00000080" ); } void upsdrv_help(void) { printf(HELP); } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { addvar(VAR_FLAG, OPTI_MINPOLL, "Only poll for critical status variables"); addvar(VAR_FLAG, OPTI_FAKELOW, "Fake a low battery status" ); addvar(VAR_FLAG, OPTI_NOWARN_NOIMP, "Suppress warnings of unsupported commands"); addvar(VAR_FLAG, OPTI_POWERUP, "(Zinto D) Power-up UPS at start (cannot identify a powered-down Zinto D)"); } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); /* NO PARSED COMMAND LINE VARIABLES */ } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } /******************************************* * COMMANDS THAT QUERY THE UPS ******************************************* * IM - manufacturer * IO - model * IS - firmware version * IZ - serial number <> (unsupported on 420E, returns ^U) * * BS - ??? returns <2> * BV - battery voltage (in deciVolts) <0140> * BT - battery temperature (deg C) <0033> (returns ^U on OptiUPS 420E) * * NF - input line frequency <600> * NV - input line voltage <116> * * OS - ?? return <3> * OF - output stage frequency (in 0.1 Hz) <600> * OV - output stage voltage <118> * OL - output stage load <027> * * FV - Input voltage <120> * FF - Input Frequency (0.1Hz) <600> * FO - Output volts <120> * FR - Output Frequency (0.1Hz) <600> * FA - Output VA <420> * FP - Ouptu power <252> * FU - ?? returns <2> * FB - ?? * FH - High Transfer Point <144> * FL - Low Transfer Point <093> * FT - Transfer point? <121> * * AG - UPS status (bitmapped ASCII hex value) <00> * bit 2: 1 = * bit 3: 1 = overload * bit 4: 1 = replace battery * bit 5: 1 = on battery, 0 = on line * bit 6: 1 = low battery * TR - Test results <00> * 00 = Unknown * 01 = Passed * 02 = Warning * 03 = Error * 04 = Aborted * 05 = In Progress * 06 = No test init * ******************************************* * ACTIONS ******************************************* * * Ts - Start test * Ct0 - set power down mode (when running on battery) * Ct0 = power down only ouput stage * Ct1 = complete power down * Cs00000000 - power down after delay (count in 0.1s) * Cs00000100 = power down in 10s * Cs-0000001 = cancel power down request * Cu00000000 - power down after delay (count in 0.1s) * Cu00000050 = power up in 5s * Cu00000000 = power up now * * CT - returns last setting passed to Ct command <0> * ******************************************* * UNKNOWN COMMANDS (on 420e anyways) ******************************************* * Fu * Fv * Ff * Fo * Fr * Fb * Fl * Fh */ nut-2.8.4/drivers/adelsystem_cbi.c0000644000175000017500000012203515044656702014101 00000000000000/* adelsystem_cbi.c - driver for ADELSYSTEM CB/CBI DC-UPS * * Copyright (C) * 2022 Dimitris Economou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * code indentation with tabstop=4 */ #include "main.h" #include "adelsystem_cbi.h" #include #include #if !(defined NUT_MODBUS_LINKTYPE_STR) # define NUT_MODBUS_LINKTYPE_STR "unknown" #endif #define DRIVER_NAME "NUT ADELSYSTEM DC-UPS CB/CBI driver (libmodbus link type: " NUT_MODBUS_LINKTYPE_STR ")" #define DRIVER_VERSION "0.05" /* variables */ static modbus_t *mbctx = NULL; /* modbus memory context */ static devstate_t *dstate = NULL; /* device state context */ static int errcnt = 0; /* modbus access error counter */ static char *device_mfr = DEVICE_MFR; /* device manufacturer */ static char *device_model = DEVICE_MODEL; /* device model */ static char *device_type = DEVICE_TYPE_STRING; /* device type (e.g. UPS, PDU...) */ static int ser_baud_rate = BAUD_RATE; /* serial port baud rate */ static char ser_parity = PARITY; /* serial port parity */ static int ser_data_bit = DATA_BIT; /* serial port data bit */ static int ser_stop_bit = STOP_BIT; /* serial port stop bit */ static int dev_slave_id = MODBUS_SLAVE_ID; /* set device ID to default value */ static uint32_t mod_resp_to_s = MODRESP_TIMEOUT_s; /* set the modbus response time out (s) */ static uint32_t mod_resp_to_us = MODRESP_TIMEOUT_us; /* set the modbus response time out (us) */ static uint32_t mod_byte_to_s = MODBYTE_TIMEOUT_s; /* set the modbus byte time out (us) */ static uint32_t mod_byte_to_us = MODBYTE_TIMEOUT_us; /* set the modbus byte time out (us) */ /* initialize alarm structs */ void alrminit(void); /* initialize register start address and hex address from register number */ void reginit(void); /* read registers' memory region */ int read_all_regs(modbus_t *mb, uint16_t *data); /* get config vars set by -x or defined in ups.conf driver section */ void get_config_vars(void); /* get device state */ int get_dev_state(devreg_t regindx, devstate_t **dvstat); /* create a new modbus context based on connection type (serial or TCP) */ modbus_t *modbus_new(const char *port); /* reconnect upon communication error */ void modbus_reconnect(void); /* modbus register read function */ int register_read(modbus_t *mb, int addr, regtype_t type, void *data); /* modbus register write function */ int register_write(modbus_t *mb, int addr, regtype_t type, void *data); /* instant command triggered by upsd */ int upscmd(const char *cmdname, const char *extra); /* count the time elapsed since start */ long time_elapsed(struct timeval *start); /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Dimitris Economou \n", DRV_BETA, {NULL} }; /* * driver functions */ /* read configuration variables from ups.conf and connect to ups device */ void upsdrv_initups(void) { int rval; upsdebugx(2, "upsdrv_initups"); dstate = (devstate_t *)xmalloc(sizeof(devstate_t)); alrminit(); reginit(); get_config_vars(); /* open communication port */ mbctx = modbus_new(device_path); if (mbctx == NULL) { fatalx(EXIT_FAILURE, "modbus_new_rtu: Unable to open communication port context"); } /* set slave ID */ rval = modbus_set_slave(mbctx, dev_slave_id); if (rval < 0) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_set_slave: Invalid modbus slave ID %d", dev_slave_id); } /* connect to modbus device */ if (modbus_connect(mbctx) == -1) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_connect: unable to connect: error(%s)", modbus_strerror(errno)); } /* set modbus response timeout */ #if (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32) || (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32_cast_timeval_fields) rval = modbus_set_response_timeout(mbctx, mod_resp_to_s, mod_resp_to_us); if (rval < 0) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_set_response_timeout: error(%s)", modbus_strerror(errno)); } #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval_numeric_fields) { /* Older libmodbus API (with timeval), and we have * checked at configure time that we can put uint32_t * into its fields. They are probably "long" on many * systems as respectively time_t and suseconds_t - * but that is not guaranteed; for more details see * https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_time.h.html */ struct timeval to; memset(&to, 0, sizeof(struct timeval)); to.tv_sec = mod_resp_to_s; to.tv_usec = mod_resp_to_us; /* void */ modbus_set_response_timeout(mbctx, &to); } /* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */ #else # error "Can not use libmodbus API for timeouts" #endif /* NUT_MODBUS_TIMEOUT_ARG_* */ /* set modbus byte time out */ #if (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32) || (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32_cast_timeval_fields) rval = modbus_set_byte_timeout(mbctx, mod_byte_to_s, mod_byte_to_us); if (rval < 0) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_set_byte_timeout: error(%s)", modbus_strerror(errno)); } #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval_numeric_fields) { /* see comments above */ struct timeval to; memset(&to, 0, sizeof(struct timeval)); to.tv_sec = mod_byte_to_s; to.tv_usec = mod_byte_to_us; /* void */ modbus_set_byte_timeout(mbctx, &to); } /* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */ #endif /* NUT_MODBUS_TIMEOUT_ARG_* */ } /* initialize ups driver information */ void upsdrv_initinfo(void) { devstate_t *ds = dstate; /* device state context */ upsdebugx(2, "upsdrv_initinfo"); /* set device information */ dstate_setinfo("device.mfr", "%s", device_mfr); dstate_setinfo("device.model", "%s", device_model); dstate_setinfo("device.type", "%s", device_type); /* read ups model */ get_dev_state(PRDN, &ds); dstate_setinfo("ups.model", "%s", ds->product.name); upslogx(LOG_INFO, "ups.model = %s", ds->product.name); /* register instant commands */ dstate_addcmd("load.off"); /* FIXME: Check with the device what this instcmd * (nee upsdrv_shutdown() contents) actually does! */ dstate_addcmd("shutdown.stayoff"); /* set callback for instant commands */ upsh.instcmd = upscmd; } /* update UPS signal state */ void upsdrv_updateinfo(void) { int rval; /* return value */ int i; /* local index */ devstate_t *ds = dstate; /* device state */ upsdebugx(2, "upsdrv_updateinfo"); errcnt = 0; /* initialize error counter to zero */ status_init(); /* initialize ups.status update */ alarm_init(); /* initialize ups.alarm update */ #if READALL_REGS == 1 rval = read_all_regs(mbctx, regs_data); if (rval == -1) { errcnt++; } else { #endif /* * update UPS status regarding MAINS and SHUTDOWN request * - OL: On line (mains is present) * - OB: On battery (mains is not present) */ rval = get_dev_state(MAIN, &ds); if (rval == -1) { errcnt++; } else { if (ds->alrm->alrm[MAINS_AVAIL_I].actv) { status_set("OB"); alarm_set(mains->alrm[MAINS_AVAIL_I].descr); upslogx(LOG_INFO, "ups.status = OB"); } else { status_set("OL"); upslogx(LOG_INFO, "ups.status = OL"); } if (ds->alrm->alrm[SHUTD_REQST_I].actv) { status_set("FSD"); alarm_set(mains->alrm[SHUTD_REQST_I].descr); upslogx(LOG_INFO, "ups.status = FSD"); } } /* * update UPS status regarding battery voltage */ rval = get_dev_state(BVAL, &ds); if (rval == -1) { errcnt++; } else { if (ds->alrm->alrm[BVAL_LOALRM_I].actv) { status_set("LB"); alarm_set(bval->alrm[BVAL_LOALRM_I].descr); upslogx(LOG_INFO, "ups.status = LB"); } if (ds->alrm->alrm[BVAL_HIALRM_I].actv) { status_set("HB"); alarm_set(bval->alrm[BVAL_HIALRM_I].descr); upslogx(LOG_INFO, "ups.status = HB"); } if (ds->alrm->alrm[BVAL_BSTSFL_I].actv) { alarm_set(bval->alrm[BVAL_BSTSFL_I].descr); upslogx(LOG_INFO, "battery start with battery flat"); } } /* get "battery.voltage" */ rval = get_dev_state(BATV, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("battery.voltage", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "battery.voltage = %s", ds->reg.strval); } /* * update UPS status regarding battery charger status */ /* get "battery.charger.status" */ rval = get_dev_state(CHRG, &ds); if (rval == -1) { errcnt++; } else { if (ds->charge.state == CHRG_BULK || ds->charge.state == CHRG_ABSR) { status_set("CHRG"); upslogx(LOG_INFO, "ups.status = CHRG"); } dstate_setinfo("battery.charger.status", "%s", ds->charge.info); upslogx(LOG_DEBUG, "battery.charger.status = %s", ds->charge.info); } rval = get_dev_state(PMNG, &ds); if (rval == -1) { errcnt++; } else { if (ds->power.state == PMNG_BCKUP) { status_set("DISCHRG"); dstate_setinfo("battery.charger.status", "discharging"); upslogx(LOG_INFO, "ups.status = DISCHRG"); } if (ds->power.state == PMNG_BOOST) { status_set("BOOST"); upslogx(LOG_INFO, "ups.status = BOOST"); } } /* * update UPS battery state of charge */ rval = get_dev_state(BSOC, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("battery.charge", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "battery.charge = %s", ds->reg.strval); } /* * update UPS AC input state */ rval = get_dev_state(VACA, &ds); if (rval == -1) { errcnt++; } else { for (i = 0; i < ds->alrm->alrm_c; i++) { if (ds->alrm->alrm[i].actv) { alarm_set(ds->alrm->alrm[i].descr); upsdebugx(3, "%s is active", ds->alrm->alrm[i].descr); } } } rval = get_dev_state(VAC, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("input.voltage", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "input.voltage = %s", ds->reg.strval); } /* * update UPS onboard temperature state */ rval = get_dev_state(OBTA, &ds); if (rval == -1) { errcnt++; } else { for (i = 0; i < ds->alrm->alrm_c; i++) { if (ds->alrm->alrm[i].actv) { alarm_set(ds->alrm->alrm[i].descr); upsdebugx(3, "%s is active", ds->alrm->alrm[i].descr); } } } rval = get_dev_state(OTMP, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("ups.temperature", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "ups.temperature = %s", ds->reg.strval); } /* * update UPS battery temperature state */ rval = get_dev_state(BSTA, &ds); if (rval == -1) { errcnt++; } else { for (i = 0; i < ds->alrm->alrm_c; i++) { if (ds->alrm->alrm[i].actv) { alarm_set(ds->alrm->alrm[i].descr); upsdebugx(3, "%s alarm is active", ds->alrm->alrm[i].descr); } } } rval = get_dev_state(BTMP, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("battery.temperature", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "battery.temperature = %s", ds->reg.strval); } rval = get_dev_state(TBUF, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("battery.runtime", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "battery.runtime = %s", ds->reg.strval); } /* * update UPS device failure state */ rval = get_dev_state(DEVF, &ds); if (rval == -1) { errcnt++; } else { for (i = 0; i < ds->alrm->alrm_c; i++) { if (ds->alrm->alrm[i].actv) { alarm_set(ds->alrm->alrm[i].descr); upsdebugx(3, "%s alarm is active", ds->alrm->alrm[i].descr); } } } /* * update UPS SoH and SoC states */ rval = get_dev_state(SCSH, &ds); if (rval == -1) { errcnt++; } else { for (i = 0; i < ds->alrm->alrm_c; i++) { if (ds->alrm->alrm[i].actv) { alarm_set(ds->alrm->alrm[i].descr); upsdebugx(3, "%s alarm is active", ds->alrm->alrm[i].descr); } } } /* * update UPS battery state */ rval = get_dev_state(BSTA, &ds); if (rval == -1) { errcnt++; } else { for (i = 0; i < ds->alrm->alrm_c; i++) { if (ds->alrm->alrm[i].actv) { alarm_set(ds->alrm->alrm[i].descr); upsdebugx(3, "%s alarm is active", ds->alrm->alrm[i].descr); } } } /* * update UPS load status */ rval = get_dev_state(LVDC, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("output.voltage", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "output.voltage = %s", ds->reg.strval); } rval = get_dev_state(LCUR, &ds); if (rval == -1) { errcnt++; } else { dstate_setinfo("output.current", "%s", ds->reg.strval); upslogx(LOG_DEBUG, "output.current = %s", ds->reg.strval); } #if READALL_REGS == 1 } #endif /* check for communication errors */ if (errcnt == 0) { alarm_commit(); status_commit(); dstate_dataok(); } else { upsdebugx(2, "Communication errors: %d", errcnt); dstate_datastale(); } } /* shutdown UPS */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* * WARNING: When using RTU TCP, this driver will probably * never support shutdowns properly, except on some systems: * In order to be of any use, the driver should be called * near the end of the system halt script (or a service * management framework's equivalent, if any). By that * time we, in all likelyhood, won't have basic network * capabilities anymore, so we could never send this * command to the UPS. This is not an error, but rather * a limitation (on some platforms) of the interface/media * used for these devices. */ int ret = do_loop_shutdown_commands("shutdown.stayoff", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } /* print driver usage info */ void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { addvar(VAR_VALUE, "ser_baud_rate", "serial port baud rate"); addvar(VAR_VALUE, "ser_parity", "serial port parity"); addvar(VAR_VALUE, "ser_data_bit", "serial port data bit"); addvar(VAR_VALUE, "ser_stop_bit", "serial port stop bit"); addvar(VAR_VALUE, "dev_slave_id", "device modbus slave ID"); addvar(VAR_VALUE, "mod_resp_to_s", "modbus response timeout (s)"); addvar(VAR_VALUE, "mod_resp_to_us", "modbus response timeout (us)"); addvar(VAR_VALUE, "mod_byte_to_s", "modbus byte timeout (s)"); addvar(VAR_VALUE, "mod_byte_to_us", "modbus byte timeout (us)"); } /* close modbus connection and free modbus context allocated memory */ void upsdrv_cleanup(void) { if (mbctx != NULL) { modbus_close(mbctx); modbus_free(mbctx); } if (dstate != NULL) { free(dstate); } } /* * driver support functions */ /* initialize alarm structs */ void alrminit(void) { mains = alloc_alrm_ar(mains_c, sizeof(mains_ar)); alrm_ar_init(mains, mains_ar, mains_c); vaca = alloc_alrm_ar(vaca_c, sizeof(vaca_ar)); alrm_ar_init(vaca, vaca_ar, vaca_c); devf = alloc_alrm_ar(devf_c, sizeof(devf_ar)); alrm_ar_init(devf, devf_ar, devf_c); btsf = alloc_alrm_ar(btsf_c, sizeof(btsf_ar)); alrm_ar_init(btsf, btsf_ar, btsf_c); bval = alloc_alrm_ar(bval_c, sizeof(bval_ar)); alrm_ar_init(bval, bval_ar, bval_c); shsc = alloc_alrm_ar(shsc_c, sizeof(shsc_ar)); alrm_ar_init(shsc, shsc_ar, shsc_c); bsta = alloc_alrm_ar(bsta_c, sizeof(bsta_ar)); alrm_ar_init(bsta, bsta_ar, bsta_c); obta = alloc_alrm_ar(obta_c, sizeof(obta_ar)); alrm_ar_init(obta, obta_ar, obta_c); } /* initialize register start address and hex address from register number */ void reginit(void) { int i; /* local index */ for (i = 0; i < MODBUS_NUMOF_REGS; i++) { int rnum = regs[i].num; switch (regs[i].type) { case COIL: regs[i].saddr = rnum - 1; regs[i].xaddr = 0x0 + regs[i].num - 1; break; case INPUT_B: rnum -= 10000; regs[i].saddr = rnum - 1; regs[i].xaddr = 0x10000 + rnum - 1; break; case INPUT_R: rnum -= 30000; regs[i].saddr = rnum - 1; regs[i].xaddr = 0x30000 + rnum - 1; break; case HOLDING: rnum -= 40000; regs[i].saddr = rnum - 1; regs[i].xaddr = 0x40000 + rnum - 1; break; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: upslogx(LOG_ERR, "Invalid register type %u for register %d", regs[i].type, regs[i].num ); upsdebugx(3, "Invalid register type %u for register %d", regs[i].type, regs[i].num ); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } upsdebugx(3, "reginit: num:%d, type: %u saddr: %d, xaddr: 0x%x", regs[i].num, regs[i].type, regs[i].saddr, (unsigned int)(regs[i].xaddr) ); } } /* read registers' memory region */ int read_all_regs(modbus_t *mb, uint16_t *data) { int rval; /* read all HOLDING registers */ rval = modbus_read_registers(mb, regs[H_REG_STARTIDX].xaddr, MAX_H_REGS, data); if (rval == -1) { upslogx(LOG_ERR, "ERROR:(%s) modbus_read: addr:0x%x, length:%8d, path:%s", modbus_strerror(errno), (unsigned int)(regs[H_REG_STARTIDX].xaddr), MAX_H_REGS, device_path ); /* on BROKEN PIPE, INVALID CRC and INVALID DATA error try to reconnect */ if (errno == EPIPE || errno == EMBBADDATA || errno == EMBBADCRC) { upsdebugx(1, "register_read: error(%s)", modbus_strerror(errno)); modbus_reconnect(); } } /* no COIL, INPUT_B or INPUT_R register regions to read */ return rval; } /* Read a modbus register */ int register_read(modbus_t *mb, int addr, regtype_t type, void *data) { int rval = -1; /* register bit masks */ uint16_t mask8 = 0x00FF; uint16_t mask16 = 0xFFFF; switch (type) { case COIL: rval = modbus_read_bits(mb, addr, 1, (uint8_t *)data); *(uint16_t *)data = *(uint16_t *)data & mask8; break; case INPUT_B: rval = modbus_read_input_bits(mb, addr, 1, (uint8_t *)data); *(uint16_t *)data = *(uint16_t *)data & mask8; break; case INPUT_R: rval = modbus_read_input_registers(mb, addr, 1, (uint16_t *)data); *(uint16_t *)data = *(uint16_t *)data & mask16; break; case HOLDING: rval = modbus_read_registers(mb, addr, 1, (uint16_t *)data); *(uint16_t *)data = *(uint16_t *)data & mask16; break; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: upsdebugx(2, "ERROR: register_read: invalid register type %u", type); break; #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } if (rval == -1) { upslogx(LOG_ERR, "ERROR:(%s) modbus_read: addr:0x%x, type:%8s, path:%s", modbus_strerror(errno), (unsigned int)addr, (type == COIL) ? "COIL" : (type == INPUT_B) ? "INPUT_B" : (type == INPUT_R) ? "INPUT_R" : "HOLDING", device_path ); /* on BROKEN PIPE, INVALID CRC and INVALID DATA error try to reconnect */ if (errno == EPIPE || errno == EMBBADDATA || errno == EMBBADCRC) { upsdebugx(1, "register_read: error(%s)", modbus_strerror(errno)); modbus_reconnect(); } } upsdebugx(3, "register addr: 0x%x, register type: %u read: %u", (unsigned int)addr, type, *(unsigned int *)data); return rval; } /* write a modbus register */ int register_write(modbus_t *mb, int addr, regtype_t type, void *data) { int rval = -1; /* register bit masks */ uint16_t mask8 = 0x00FF; uint16_t mask16 = 0xFFFF; switch (type) { case COIL: *(uint16_t *)data = *(uint16_t *)data & mask8; rval = modbus_write_bit(mb, addr, *(uint8_t *)data); break; case HOLDING: *(uint16_t *)data = *(uint16_t *)data & mask16; rval = modbus_write_register(mb, addr, *(uint16_t *)data); break; case INPUT_B: case INPUT_R: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic pop #endif upsdebugx(2, "ERROR: register_write: invalid register type %u", type); break; } if (rval == -1) { upslogx(LOG_ERR, "ERROR:(%s) modbus_write: addr:0x%x, type:%8s, path:%s", modbus_strerror(errno), (unsigned int)addr, (type == COIL) ? "COIL" : (type == INPUT_B) ? "INPUT_B" : (type == INPUT_R) ? "INPUT_R" : "HOLDING", device_path ); /* on BROKEN PIPE error try to reconnect */ if (errno == EPIPE) { upsdebugx(1, "register_write: error(%s)", modbus_strerror(errno)); modbus_reconnect(); } } upsdebugx(3, "register addr: 0x%x, register type: %u read: %u", (unsigned int)addr, type, *(unsigned int *)data); return rval; } /* returns the time elapsed since start in milliseconds */ long time_elapsed(struct timeval *start) { long rval; struct timeval end; rval = gettimeofday(&end, NULL); if (rval < 0) { upslog_with_errno(LOG_ERR, "time_elapsed"); } if (start->tv_usec < end.tv_usec) { suseconds_t nsec = (end.tv_usec - start->tv_usec) / 1000000 + 1; end.tv_usec -= 1000000 * nsec; end.tv_sec += nsec; } if (start->tv_usec - end.tv_usec > 1000000) { suseconds_t nsec = (start->tv_usec - end.tv_usec) / 1000000; end.tv_usec += 1000000 * nsec; end.tv_sec -= nsec; } rval = (end.tv_sec - start->tv_sec) * 1000 + (end.tv_usec - start->tv_usec) / 1000; return rval; } /* instant command triggered by upsd */ int upscmd(const char *cmdname, const char *extra) { int rval; int data; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "load.off")) { data = 1; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); rval = register_write(mbctx, regs[FSD].xaddr, regs[FSD].type, &data); if (rval == -1) { upsdebugx(2, "ERROR:(%s) modbus_write_register: addr:0x%08x, regtype: %u, path:%s", modbus_strerror(errno), (unsigned int)(regs[FSD].xaddr), regs[FSD].type, device_path ); upslogx(LOG_INSTCMD_FAILED, "load.off: failed (communication error) [%s] [%s]", NUT_STRARG(cmdname), NUT_STRARG(extra)); rval = STAT_INSTCMD_FAILED; } else { upsdebugx(2, "load.off: addr: 0x%x, data: %d", (unsigned int)(regs[FSD].xaddr), data); rval = STAT_INSTCMD_HANDLED; } } else if (!strcasecmp(cmdname, "shutdown.stayoff")) { /* FIXME: Which one is this actually - * "shutdown.stayoff" or "shutdown.return"? */ int cnt = FSD_REPEAT_CNT; /* shutdown repeat counter */ struct timeval start; long etime; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* retry sending shutdown command on error */ while ((rval = upscmd("load.off", NULL)) != STAT_INSTCMD_HANDLED && cnt > 0) { rval = gettimeofday(&start, NULL); if (rval < 0) { upslog_with_errno(LOG_ERR, "upscmd: gettimeofday"); } /* wait for an increasing time interval before sending shutdown command */ while ((etime = time_elapsed(&start)) < ( FSD_REPEAT_INTRV / cnt)); upsdebugx(2, "ERROR: load.off failed, wait for %lims, retries left: %d", etime, cnt - 1); cnt--; } switch (rval) { case STAT_INSTCMD_FAILED: case STAT_INSTCMD_INVALID: upslog_with_errno(LOG_INSTCMD_FAILED, "instcmd: %s failed", cmdname); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); break; case STAT_INSTCMD_UNKNOWN: upslog_with_errno(LOG_INSTCMD_UNKNOWN, "instcmd: %s not supported", cmdname); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); break; default: upslogx(LOG_INFO, "shutdown command executed"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); break; } } else { upslog_INSTCMD_UNKNOWN(cmdname, extra); rval = STAT_INSTCMD_UNKNOWN; } return rval; } /* read device state, returns 0 on success or -1 on communication error it formats state depending on register semantics */ int get_dev_state(devreg_t regindx, devstate_t **dvstat) { int i; /* local index */ int n; int rval; /* return value */ static char *ptr = NULL; /* temporary pointer */ unsigned int reg_val; /* register value */ #if READALL_REGS == 0 unsigned int num; /* register number */ regtype_t rtype; /* register type */ int addr; /* register address */ #endif devstate_t *state; /* device state */ state = *dvstat; #if READALL_REGS == 1 reg_val = regs_data[regindx]; rval = 0; #elif READALL_REGS == 0 num = regs[regindx].num; addr = regs[regindx].xaddr; rtype = regs[regindx].type; rval = register_read(mbctx, addr, rtype, ®_val); if (rval == -1) { return rval; } upsdebugx(3, "get_dev_state: num: %d, addr: 0x%x, regtype: %d, data: %d", num, addr, rtype, reg_val ); #endif /* process register data */ switch (regindx) { case CHRG: /* "ups.charge" */ if (reg_val == CHRG_NONE) { state->charge.state = CHRG_NONE; state->charge.info = chrgs_i[CHRG_NONE]; } else if (reg_val == CHRG_RECV) { state->charge.state = CHRG_RECV; state->charge.info = chrgs_i[CHRG_RECV]; } else if (reg_val == CHRG_BULK) { state->charge.state = CHRG_BULK; state->charge.info = chrgs_i[CHRG_BULK]; } else if (reg_val == CHRG_ABSR) { state->charge.state = CHRG_ABSR; state->charge.info = chrgs_i[CHRG_ABSR]; } else if (reg_val == CHRG_FLOAT) { state->charge.state = CHRG_FLOAT; state->charge.info = chrgs_i[CHRG_FLOAT]; } upsdebugx(3, "get_dev_state: charge.state: %s", state->charge.info); break; case BATV: /* "battery.voltage" */ case LVDC: /* "output.voltage" */ case LCUR: /* "output.current" */ if (reg_val != 0) { char *fval_s; double fval; state->reg.val.ui16 = reg_val; fval = reg_val / 1000.00; /* convert mV to V, mA to A */ n = snprintf(NULL, 0, "%.2f", fval); if (ptr != NULL) { free(ptr); } fval_s = (char *)xmalloc(sizeof(char) * (n + 1)); ptr = fval_s; sprintf(fval_s, "%.2f", fval); state->reg.strval = fval_s; } else { state->reg.val.ui16 = 0; state->reg.strval = "0.00"; } upsdebugx(3, "get_dev_state: variable: %s", state->reg.strval); break; case TBUF: case BSOH: case BCEF: case VAC: /* "input.voltage" */ if (reg_val != 0) { char *reg_val_s; state->reg.val.ui16 = reg_val; n = snprintf(NULL, 0, "%u", reg_val); if (ptr != NULL) { free(ptr); } reg_val_s = (char *)xmalloc(sizeof(char) * (n + 1)); ptr = reg_val_s; sprintf(reg_val_s, "%u", reg_val); state->reg.strval = reg_val_s; } else { state->reg.val.ui16 = 0; state->reg.strval = "0"; } upsdebugx(3, "get_dev_state: variable: %s", state->reg.strval); break; case BSOC: /* "battery.charge" */ if (reg_val != 0) { double fval; char *fval_s; state->reg.val.ui16 = reg_val; fval = (double )reg_val * regs[BSOC].scale; n = snprintf(NULL, 0, "%.2f", fval); if (ptr != NULL) { free(ptr); } fval_s = (char *)xmalloc(sizeof(char) * (n + 1)); ptr = fval_s; sprintf(fval_s, "%.2f", fval); state->reg.strval = fval_s; } else { state->reg.val.ui16 = 0; state->reg.strval = "0.00"; } upsdebugx(3, "get_dev_state: variable: %s", state->reg.strval); break; case BTMP: /* "battery.temperature" */ case OTMP: /* "ups.temperature" */ { /* scoping */ double fval; char *fval_s; state->reg.val.ui16 = reg_val; fval = reg_val - 273.15; n = snprintf(NULL, 0, "%.2f", fval); fval_s = (char *)xmalloc(sizeof(char) * (n + 1)); if (ptr != NULL) { free(ptr); } ptr = fval_s; sprintf(fval_s, "%.2f", fval); state->reg.strval = fval_s; } upsdebugx(3, "get_dev_state: variable: %s", state->reg.strval); break; case PMNG: /* "ups.status" & "battery.charge" */ if (reg_val == PMNG_BCKUP) { state->power.state = PMNG_BCKUP; state->power.info = pwrmng_i[PMNG_BCKUP]; } else if (reg_val == PMNG_CHRGN) { state->power.state = PMNG_CHRGN; state->power.info = pwrmng_i[PMNG_CHRGN]; } else if (reg_val == PMNG_BOOST) { state->power.state = PMNG_BOOST; state->power.info = pwrmng_i[PMNG_BOOST]; } else if (reg_val == PMNG_NCHRG) { state->power.state = PMNG_NCHRG; state->power.info = pwrmng_i[PMNG_NCHRG]; } upsdebugx(3, "get_dev_state: power.state: %s", state->reg.strval); break; case PRDN: /* "ups.model" */ for (i = 0; i < DEV_NUMOF_MODELS; i++) { if (prdnm_i[i].val == reg_val) { break; } } state->product.val = reg_val; state->product.name = prdnm_i[i].name; upsdebugx(3, "get_dev_state: product.name: %s", state->product.name); break; case BSTA: if (reg_val & BSTA_REVPOL_M) { bsta->alrm[BSTA_REVPOL_I].actv = 1; } else { bsta->alrm[BSTA_REVPOL_I].actv = 0; } if (reg_val & BSTA_NOCNND_M) { bsta->alrm[BSTA_NOCNND_I].actv = 1; } else { bsta->alrm[BSTA_NOCNND_I].actv = 0; } if (reg_val & BSTA_CLSHCR_M) { bsta->alrm[BSTA_CLSHCR_I].actv = 1; } else { bsta->alrm[BSTA_CLSHCR_I].actv = 0; } if (reg_val & BSTA_SULPHD_M) { bsta->alrm[BSTA_SULPHD_I].actv = 1; } else { bsta->alrm[BSTA_SULPHD_I].actv = 0; } if (reg_val & BSTA_CHEMNS_M) { bsta->alrm[BSTA_CHEMNS_I].actv = 1; } else { bsta->alrm[BSTA_CHEMNS_I].actv = 0; } if (reg_val & BSTA_CNNFLT_M) { bsta->alrm[BSTA_CNNFLT_I].actv = 1; } else { bsta->alrm[BSTA_CNNFLT_I].actv = 0; } state->alrm = bsta; break; case SCSH: if (reg_val & SHSC_HIRESI_M) { shsc->alrm[SHSC_HIRESI_I].actv = 1; } else { shsc->alrm[SHSC_HIRESI_I].actv = 0; } if (reg_val & SHSC_LOCHEF_M) { shsc->alrm[SHSC_LOCHEF_I].actv = 1; } else { shsc->alrm[SHSC_LOCHEF_I].actv = 0; } if (reg_val & SHSC_LOEFCP_M) { shsc->alrm[SHSC_LOEFCP_I].actv = 1; } else { shsc->alrm[SHSC_LOEFCP_I].actv = 0; } if (reg_val & SHSC_LOWSOC_M) { shsc->alrm[SHSC_LOWSOC_I].actv = 1; } else { shsc->alrm[SHSC_LOWSOC_I].actv = 0; } state->alrm = shsc; break; case BVAL: if (reg_val & BVAL_HIALRM_M) { bval->alrm[BVAL_HIALRM_I].actv = 1; } else { bval->alrm[BVAL_HIALRM_I].actv = 0; } if (reg_val & BVAL_LOALRM_M) { bval->alrm[BVAL_LOALRM_I].actv = 1; } else { bval->alrm[BVAL_LOALRM_I].actv = 0; } if (reg_val & BVAL_BSTSFL_M) { bval->alrm[BVAL_BSTSFL_I].actv = 1; } else { bval->alrm[BVAL_BSTSFL_I].actv = 0; } state->alrm = bval; break; case BTSF: if (reg_val & BTSF_FCND_M) { btsf->alrm[BTSF_FCND_I].actv = 1; } else { btsf->alrm[BTSF_FCND_I].actv = 0; } if (reg_val & BTSF_NCND_M) { btsf->alrm[BTSF_NCND_I].actv = 1; } else { btsf->alrm[BTSF_NCND_I].actv = 0; } state->alrm = btsf; break; case DEVF: if (reg_val & DEVF_RCALRM_M) { devf->alrm[DEVF_RCALRM_I].actv = 1; } else { devf->alrm[DEVF_RCALRM_I].actv = 0; } if (reg_val & DEVF_INALRM_M) { devf->alrm[DEVF_INALRM_I].actv = 1; } else { devf->alrm[DEVF_INALRM_I].actv = 0; } if (reg_val & DEVF_LFNAVL_M) { devf->alrm[DEVF_LFNAVL_I].actv = 1; } else { devf->alrm[DEVF_LFNAVL_I].actv = 0; } state->alrm = devf; break; case VACA: if (reg_val & VACA_HIALRM_M) { vaca->alrm[VACA_HIALRM_I].actv = 1; } else { vaca->alrm[VACA_HIALRM_I].actv = 0; } if (reg_val == VACA_LOALRM_M) { vaca->alrm[VACA_LOALRM_I].actv = 1; } else { vaca->alrm[VACA_LOALRM_I].actv = 0; } state->alrm = vaca; break; case MAIN: if (reg_val & MAINS_AVAIL_M) { mains->alrm[MAINS_AVAIL_I].actv = 1; } else { mains->alrm[MAINS_AVAIL_I].actv = 0; } if (reg_val == SHUTD_REQST_M) { mains->alrm[SHUTD_REQST_I].actv = 1; } else { mains->alrm[SHUTD_REQST_I].actv = 0; } state->alrm = mains; break; case OBTA: if (reg_val == OBTA_HIALRM_V) { obta->alrm[OBTA_HIALRM_I].actv = 1; } state->alrm = obta; break; case BINH: case FSD: break; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: { /* scoping */ char *reg_val_s; state->reg.val.ui16 = reg_val; n = snprintf(NULL, 0, "%u", reg_val); if (ptr != NULL) { free(ptr); } reg_val_s = (char *)xmalloc(sizeof(char) * (n + 1)); ptr = reg_val_s; sprintf(reg_val_s, "%u", reg_val); state->reg.strval = reg_val_s; } break; #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } return rval; } /* get driver configuration parameters */ void get_config_vars(void) { /* check if serial baud rate is set and get the value */ if (testvar("ser_baud_rate")) { ser_baud_rate = (int)strtol(getval("ser_baud_rate"), NULL, 10); } upsdebugx(2, "ser_baud_rate %d", ser_baud_rate); /* check if serial parity is set and get the value */ if (testvar("ser_parity")) { /* Dereference the char* we get */ char *sp = getval("ser_parity"); if (sp) { /* TODO? Sanity-check the char we get? */ ser_parity = *sp; } else { upsdebugx(2, "Could not determine ser_parity, will keep default"); } } upsdebugx(2, "ser_parity %c", ser_parity); /* check if serial data bit is set and get the value */ if (testvar("ser_data_bit")) { ser_data_bit = (int)strtol(getval("ser_data_bit"), NULL, 10); } upsdebugx(2, "ser_data_bit %d", ser_data_bit); /* check if serial stop bit is set and get the value */ if (testvar("ser_stop_bit")) { ser_stop_bit = (int)strtol(getval("ser_stop_bit"), NULL, 10); } upsdebugx(2, "ser_stop_bit %d", ser_stop_bit); /* check if device ID is set and get the value */ if (testvar("dev_slave_id")) { dev_slave_id = (int)strtol(getval("dev_slave_id"), NULL, 10); } upsdebugx(2, "dev_slave_id %d", dev_slave_id); /* check if response time out (s) is set and get the value */ if (testvar("mod_resp_to_s")) { mod_resp_to_s = (uint32_t)strtol(getval("mod_resp_to_s"), NULL, 10); } upsdebugx(2, "mod_resp_to_s %u", mod_resp_to_s); /* check if response time out (us) is set and get the value */ if (testvar("mod_resp_to_us")) { mod_resp_to_us = (uint32_t) strtol(getval("mod_resp_to_us"), NULL, 10); if (mod_resp_to_us > 999999) { fatalx(EXIT_FAILURE, "get_config_vars: Invalid mod_resp_to_us %u", mod_resp_to_us); } } upsdebugx(2, "mod_resp_to_us %u", mod_resp_to_us); /* check if byte time out (s) is set and get the value */ if (testvar("mod_byte_to_s")) { mod_byte_to_s = (uint32_t)strtol(getval("mod_byte_to_s"), NULL, 10); } upsdebugx(2, "mod_byte_to_s %u", mod_byte_to_s); /* check if byte time out (us) is set and get the value */ if (testvar("mod_byte_to_us")) { mod_byte_to_us = (uint32_t) strtol(getval("mod_byte_to_us"), NULL, 10); if (mod_byte_to_us > 999999) { fatalx(EXIT_FAILURE, "get_config_vars: Invalid mod_byte_to_us %u", mod_byte_to_us); } } upsdebugx(2, "mod_byte_to_us %u", mod_byte_to_us); } /* create a new modbus context based on connection type (serial or TCP) */ modbus_t *modbus_new(const char *port) { modbus_t *mb; char *sp; if (strstr(port, "/dev/tty") != NULL) { mb = modbus_new_rtu(port, ser_baud_rate, ser_parity, ser_data_bit, ser_stop_bit); if (mb == NULL) { upslogx(LOG_ERR, "modbus_new_rtu: Unable to open serial port context"); } } else if ((sp = strchr(port, ':')) != NULL) { char *tcp_port = xmalloc(sizeof(sp)); strcpy(tcp_port, sp + 1); *sp = '\0'; mb = modbus_new_tcp(port, (int)strtoul(tcp_port, NULL, 10)); if (mb == NULL) { upslogx(LOG_ERR, "modbus_new_tcp: Unable to connect to %s", port); } free(tcp_port); } else { mb = modbus_new_tcp(port, 502); if (mb == NULL) { upslogx(LOG_ERR, "modbus_new_tcp: Unable to connect to %s", port); } } return mb; } /* reconnect to modbus server upon connection error */ void modbus_reconnect(void) { int rval; upsdebugx(1, "modbus_reconnect, trying to reconnect to modbus server"); dstate_setinfo("driver.state", "reconnect.trying"); /* clear current modbus context */ modbus_close(mbctx); modbus_free(mbctx); /* open communication port */ mbctx = modbus_new(device_path); if (mbctx == NULL) { fatalx(EXIT_FAILURE, "modbus_new_rtu: Unable to open communication port context"); } /* set slave ID */ rval = modbus_set_slave(mbctx, dev_slave_id); if (rval < 0) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_set_slave: Invalid modbus slave ID %d", dev_slave_id); } /* connect to modbus device */ if (modbus_connect(mbctx) == -1) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_connect: unable to connect: %s", modbus_strerror(errno)); } /* set modbus response timeout */ #if (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32) || (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32_cast_timeval_fields) rval = modbus_set_response_timeout(mbctx, mod_resp_to_s, mod_resp_to_us); if (rval < 0) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_set_response_timeout: error(%s)", modbus_strerror(errno)); } #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval_numeric_fields) { /* see comments above */ struct timeval to; memset(&to, 0, sizeof(struct timeval)); to.tv_sec = mod_resp_to_s; to.tv_usec = mod_resp_to_us; /* void */ modbus_set_response_timeout(mbctx, &to); } /* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */ #endif /* NUT_MODBUS_TIMEOUT_ARG_* */ /* set modbus byte timeout */ #if (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32) || (defined NUT_MODBUS_TIMEOUT_ARG_sec_usec_uint32_cast_timeval_fields) rval = modbus_set_byte_timeout(mbctx, mod_byte_to_s, mod_byte_to_us); if (rval < 0) { modbus_free(mbctx); fatalx(EXIT_FAILURE, "modbus_set_byte_timeout: error(%s)", modbus_strerror(errno)); } #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval_numeric_fields) { /* see comments above */ struct timeval to; memset(&to, 0, sizeof(struct timeval)); to.tv_sec = mod_byte_to_s; to.tv_usec = mod_byte_to_us; /* void */ modbus_set_byte_timeout(mbctx, &to); } /* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */ #endif /* NUT_MODBUS_TIMEOUT_ARG_* */ dstate_setinfo("driver.state", "quiet"); } nut-2.8.4/drivers/snmp-ups.c0000644000175000017500000040773615044656702012712 00000000000000/* snmp-ups.c - NUT Generic SNMP driver core (supports different MIBs) * * Based on NetSNMP API (Simple Network Management Protocol v1-2c-3) * * Copyright (C) * 2002 - 2014 Arnaud Quette * 2015 - 2022 Eaton (author: Arnaud Quette ) * 2016 - 2022 Eaton (author: Jim Klimov ) * 2022 - 2025 Jim Klimov * 2002 - 2006 Dmitry Frolov * J.W. Hoogervorst * Niels Baggesen * 2009 - 2010 Arjen de Korte * * Sponsored by Eaton * and originally by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* NUT SNMP common functions */ #include "main.h" /* includes "config.h" which must be the first header */ #include "nut_float.h" #include "nut_stdint.h" #include "snmp-ups.h" #include "parseconf.h" #include /* for isprint() */ /* include all known mib2nut lookup tables */ #include "apc-mib.h" #include "mge-mib.h" #include "netvision-mib.h" #include "eaton-pdu-genesis2-mib.h" #include "eaton-pdu-marlin-mib.h" #include "eaton-pdu-nlogic-mib.h" #include "eaton-pdu-pulizzi-mib.h" #include "eaton-pdu-revelation-mib.h" #include "eaton-ups-pwnm2-mib.h" #include "eaton-ups-pxg-mib.h" #include "raritan-pdu-mib.h" #include "raritan-px2-mib.h" #include "baytech-mib.h" #include "baytech-rpc3nc-mib.h" #include "compaq-mib.h" #include "bestpower-mib.h" #include "cyberpower-mib.h" #include "delta_ups-mib.h" #include "huawei-mib.h" #include "ietf-mib.h" #include "xppc-mib.h" #include "eaton-ats16-nmc-mib.h" #include "eaton-ats16-nm2-mib.h" #include "apc-ats-mib.h" #include "apc-pdu-mib.h" #include "apc-epdu-mib.h" #include "eaton-ats30-mib.h" #include "emerson-avocent-pdu-mib.h" #include "hpe-pdu-mib.h" #include "hpe-pdu3-cis-mib.h" /* Address API change */ #if ( ! NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol ) && ( ! defined usmAESPrivProtocol ) #define usmAESPrivProtocol usmAES128PrivProtocol #endif #ifdef USM_PRIV_PROTO_AES_LEN # define NUT_securityPrivProtoLen USM_PRIV_PROTO_AES_LEN #else # ifdef USM_PRIV_PROTO_AES128_LEN # define NUT_securityPrivProtoLen USM_PRIV_PROTO_AES128_LEN # else /* FIXME: Find another way to get the size of array(?) to avoid: * error: division 'sizeof (oid * {aka long unsigned int *}) / sizeof (oid {aka long unsigned int})' does not compute the number of array elements [-Werror=sizeof-pointer-div] * See also https://bugs.php.net/bug.php?id=37564 for context * which is due to most values in /usr/include/net-snmp/librarytransform_oids.h * being defined as "oid[10]" or similar arrays, and "backwards compatibility" * usmAESPrivProtocol name is an "oid *" pointer. */ # define NUT_securityPrivProtoLen (sizeof(usmAESPrivProtocol)/sizeof(oid)) # endif #endif static mib2nut_info_t *mib2nut[] = { &apc_ats, /* This struct comes from : apc-ats-mib.c */ &apc_pdu_rpdu, /* This struct comes from : apc-pdu-mib.c */ &apc_pdu_rpdu2, /* This struct comes from : apc-pdu-mib.c */ &apc_pdu_msp, /* This struct comes from : apc-pdu-mib.c */ &apc_pdu_epdu, /* This struct comes from : apc-epdu-mib.c */ &apc, /* This struct comes from : apc-mib.c */ &baytech, /* This struct comes from : baytech-mib.c */ &baytech_rpc3nc, /* This struct comes from : baytech-rpc3nc-mib.c */ &bestpower, /* This struct comes from : bestpower-mib.c */ &compaq, /* This struct comes from : compaq-mib.c */ &cyberpower, /* This struct comes from : cyberpower-mib.c */ &cyberpower2, /* This struct comes from : cyberpower-mib.c */ &delta_ups, /* This struct comes from : delta_ups-mib.c */ &eaton_ats16_nmc, /* This struct comes from : eaton-ats16-nmc-mib.c */ &eaton_ats16_nm2, /* This struct comes from : eaton-ats16-nm2-mib.c */ &eaton_ats30, /* This struct comes from : eaton-ats30-mib.c */ &eaton_marlin, /* This struct comes from : eaton-mib.c */ &eaton_pdu_nlogic, /* This struct comes from : eaton-pdu-nlogic-mib.c */ &eaton_pxg_ups, /* This struct comes from : eaton-ups-pxg-mib.c */ &eaton_pw_nm2, /* This struct comes from : eaton-ups-pwnm2-mib.c */ &emerson_avocent_pdu, /* This struct comes from : emerson-avocent-pdu-mib.c */ &aphel_revelation, /* This struct comes from : eaton-mib.c */ &aphel_genesisII, /* This struct comes from : eaton-mib.c */ &pulizzi_switched1, /* This struct comes from : eaton-mib.c */ &pulizzi_switched2, /* This struct comes from : eaton-mib.c */ &hpe_pdu, /* This struct comes from : hpe-pdu-mib.c */ &hpe_pdu3_cis, /* This struct comes from : hpe-pdu3-cis-mib.c */ &huawei, /* This struct comes from : huawei-mib.c */ &mge, /* This struct comes from : mge-mib.c */ &netvision, /* This struct comes from : netvision-mib.c */ &raritan, /* This struct comes from : raritan-pdu-mib.c */ &raritan_px2, /* This struct comes from : raritan-px2-mib.c */ &xppc, /* This struct comes from : xppc-mib.c */ /* * Prepend vendor specific MIB mappings before IETF, so that * if a device supports both IETF and vendor specific MIB, * the vendor specific one takes precedence (when mibs=auto) */ &tripplite_ietf, /* This struct comes from : ietf-mib.c */ &ietf, /* This struct comes from : ietf-mib.c */ /* end of structure. */ NULL }; struct snmp_session g_snmp_sess, *g_snmp_sess_p; const char *OID_pwr_status; int g_pwr_battery; int pollfreq; /* polling frequency */ int semistaticfreq; /* semistatic entry update frequency */ static int semistatic_countdown = 0; static int quirk_symmetra_threephase = 0; /* Number of device(s): standard is "1", but talking * to a daisychain (master device) means more than 1 * (a directly addressable member of a daisy chain * would be seen as a single-device chain though) */ static long devices_count = 1; /* global var to handle daisychain iterations - * changed by loops in snmp_ups_walk() and su_addcmd(); * may be 0 for addressing certain values/commands * across all chain devices via master (1); * also may be 0 for non-daisychained devices */ static int current_device_number = 0; /* global var to handle daisychain iterations - * made TRUE if we resolved a "device.count" value */ static bool_t daisychain_enabled = FALSE; static daisychain_info_t **daisychain_info = NULL; /* pointer to the Snmp2Nut lookup table */ mib2nut_info_t *mib2nut_info; /* FIXME: to be trashed */ snmp_info_t *snmp_info; alarms_info_t *alarms_info; static const char *mibname; static const char *mibvers; #define DRIVER_NAME "Generic SNMP UPS driver" #define DRIVER_VERSION "1.37" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Arnaud Quette \n" \ "Arnaud Quette \n" \ "Dmitry Frolov \n" \ "J.W. Hoogervorst \n" \ "Niels Baggesen \n" \ "Jim Klimov \n" \ "Arjen de Korte ", DRV_STABLE, { NULL } }; /* FIXME: integrate MIBs info? do the same as for usbhid-ups! */ static time_t lastpoll = 0; /* Communication status handling */ #define COMM_UNKNOWN 0 #define COMM_OK 1 #define COMM_LOST 2 static int comm_status = COMM_UNKNOWN; /* template OIDs index start with 0 or 1 (estimated stable for a MIB), * automatically guessed at the first pass */ static int template_index_base = -1; /* Not that stable in the end... */ static int device_template_index_base = -1; /* OID index of the 1rst daisychained device */ static int outlet_template_index_base = -1; static int outletgroup_template_index_base = -1; static int ambient_template_index_base = -1; static int device_template_offset = -1; /* sysOID location */ #define SYSOID_OID ".1.3.6.1.2.1.1.2.0" /* Forward functions declarations */ static void disable_transfer_oids(void); bool_t get_and_process_data(int mode, snmp_info_t *su_info_p); int extract_template_number(snmp_info_flags_t template_type, const char* varname); snmp_info_flags_t get_template_type(const char* varname); /* --------------------------------------------- * driver functions implementations * --------------------------------------------- */ void upsdrv_initinfo(void) { snmp_info_t *su_info_p; upsdebugx(1, "SNMP UPS driver: entering %s()", __func__); dstate_setinfo("driver.version.data", "%s MIB %s", mibname, mibvers); if (snmp_info == NULL) { fatalx(EXIT_FAILURE, "%s: snmp_info is not initialized", __func__); } if (snmp_info[0].info_type == NULL) { upsdebugx(1, "%s: WARNING: snmp_info is empty", __func__); } /* add instant commands to the info database. * outlet (and groups) commands are processed later, during initial walk */ for (su_info_p = &snmp_info[0]; (su_info_p != NULL && su_info_p->info_type != NULL) ; su_info_p++) { if (su_info_p->flags == 0UL) { upsdebugx(4, "SNMP UPS driver: %s: MIB2NUT mapping '%s' (OID '%s') did not define flags bits. " "Entry would be treated as SU_FLAG_OK if available in returned data.", __func__, (su_info_p->info_type ? su_info_p->info_type : ""), (su_info_p->OID ? su_info_p->OID : "") ); /* Treat as OK if avail, otherwise discarded */ } su_info_p->flags |= SU_FLAG_OK; if ((SU_TYPE(su_info_p) == SU_TYPE_CMD) && !(su_info_p->flags & SU_OUTLET) && !(su_info_p->flags & SU_OUTLET_GROUP)) { /* first check that this OID actually exists */ /* FIXME: daisychain commands support! */ su_addcmd(su_info_p); /* if (nut_snmp_get(su_info_p->OID) != NULL) { dstate_addcmd(su_info_p->info_type); upsdebugx(1, "upsdrv_initinfo(): adding command '%s'", su_info_p->info_type); } */ } } if (testvar("notransferoids")) disable_transfer_oids(); if (testvar("symmetrathreephase")) quirk_symmetra_threephase = 1; else quirk_symmetra_threephase = 0; /* initialize all other INFO_ fields from list */ if (snmp_ups_walk(SU_WALKMODE_INIT) == TRUE) { dstate_dataok(); comm_status = COMM_OK; } else { dstate_datastale(); comm_status = COMM_LOST; } /* setup handlers for instcmd and setvar functions */ upsh.setvar = su_setvar; upsh.instcmd = su_instcmd; } void upsdrv_updateinfo(void) { upsdebugx(1,"SNMP UPS driver: entering %s()", __func__); /* only update every pollfreq */ /* FIXME: only update status (SU_STATUS_*), à la usbhid-ups, in between */ if (time(NULL) > (lastpoll + pollfreq)) { alarm_init(); status_init(); /* update all dynamic info fields */ if (snmp_ups_walk(SU_WALKMODE_UPDATE)) { upsdebugx(1, "%s: pollfreq: Data OK", __func__); dstate_dataok(); comm_status = COMM_OK; } else { upsdebugx(1, "%s: pollfreq: Data STALE", __func__); dstate_datastale(); comm_status = COMM_LOST; } /* Commit status first, otherwise in daisychain mode, "device.0" may * clear the alarm count since it has an empty alarm buffer and if there * is only one device that has alarms! */ if (daisychain_enabled == FALSE) alarm_commit(); status_commit(); if (daisychain_enabled == TRUE) alarm_commit(); /* store timestamp */ lastpoll = time(NULL); } else { /* Just tell the same status to upsd */ if (comm_status == COMM_OK) dstate_dataok(); else dstate_datastale(); } } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* * WARNING: * This driver will probably never support this properly: * In order to be of any use, the driver should be called * near the end of the system halt script (or a service * management framework's equivalent, if any). By that * time we, in all likelyhood, won't have basic network * capabilities anymore, so we could never send this * command to the UPS. This is not an error, but rather * a limitation (on some platforms) of the interface/media * used for these devices. */ char *cmd_used = NULL; upsdebugx(1, "%s...", __func__); /* set shutdown and autostart delay */ set_delays(); /* By default: * - Try to shutdown with delay * - If the above doesn't work, try shutdown.reboot * - If the above doesn't work, try load.off.delay * - Finally, try shutdown.stayoff */ if (do_loop_shutdown_commands("shutdown.return,shutdown.reboot,load.off.delay,shutdown.stayoff", &cmd_used) == STAT_INSTCMD_HANDLED) { upslogx(LOG_INFO, "Shutdown successful with '%s'", NUT_STRARG(cmd_used)); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); return; } upslogx(LOG_ERR, "Shutdown failed!"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_help(void) { upsdebugx(1, "entering %s", __func__); } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { upsdebugx(1, "entering %s()", __func__); addvar(VAR_VALUE, SU_VAR_MIBS, "NOTE: You can run the driver binary with '-x mibs=--list' for an up to date listing)\n" "Set MIB compliance (default=ietf, allowed: mge,apcc,netvision,pw,cpqpower,...)"); addvar(VAR_VALUE | VAR_SENSITIVE, SU_VAR_COMMUNITY, "Set community name (default=public)"); addvar(VAR_VALUE, SU_VAR_VERSION, "Set SNMP version (default=v1, allowed: v2c,v3)"); addvar(VAR_VALUE, SU_VAR_POLLFREQ, "Set polling frequency in seconds, to reduce network flow (default=30)"); addvar(VAR_VALUE, SU_VAR_SEMISTATICFREQ, "Set semistatic value update frequency in update cycles, to reduce network flow (default=10)"); addvar(VAR_VALUE, SU_VAR_RETRIES, "Specifies the number of Net-SNMP retries to be used in the requests (default=5)"); addvar(VAR_VALUE, SU_VAR_TIMEOUT, "Specifies the Net-SNMP timeout in seconds between retries (default=1)"); addvar(VAR_FLAG, "notransferoids", "Disable transfer OIDs (use on APCC Symmetras)"); addvar(VAR_FLAG, "symmetrathreephase", "Enable APCC three phase Symmetra quirks (use on APCC three phase Symmetras)"); addvar(VAR_VALUE, SU_VAR_SECLEVEL, "Set the securityLevel used for SNMPv3 messages (default=noAuthNoPriv, allowed: authNoPriv,authPriv)"); addvar(VAR_VALUE | VAR_SENSITIVE, SU_VAR_SECNAME, "Set the securityName used for authenticated SNMPv3 messages (no default)"); addvar(VAR_VALUE | VAR_SENSITIVE, SU_VAR_AUTHPASSWD, "Set the authentication pass phrase used for authenticated SNMPv3 messages (no default)"); addvar(VAR_VALUE | VAR_SENSITIVE, SU_VAR_PRIVPASSWD, "Set the privacy pass phrase used for encrypted SNMPv3 messages (no default)"); /* Construct addvar() for SU_VAR_AUTHPROT: */ { int comma = 0; char tmp_buf[SU_LARGEBUF]; char *p = tmp_buf; char *pn; /* proto name to add */ size_t remain = sizeof(tmp_buf) - 1; int ret; NUT_UNUSED_VARIABLE(comma); /* potentially, if no protocols are available */ tmp_buf[0] = '\0'; ret = snprintf(p, remain, "%s", "Set the authentication protocol ("); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar()"); } p += ret; remain -= (size_t)ret; #if NUT_HAVE_LIBNETSNMP_usmHMACMD5AuthProtocol pn = "MD5"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; #endif #if NUT_HAVE_LIBNETSNMP_usmHMACSHA1AuthProtocol pn = "SHA"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; #endif #if NUT_HAVE_LIBNETSNMP_usmHMAC192SHA256AuthProtocol pn = "SHA256"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; #endif #if NUT_HAVE_LIBNETSNMP_usmHMAC256SHA384AuthProtocol pn = "SHA384"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; #endif #if NUT_HAVE_LIBNETSNMP_usmHMAC384SHA512AuthProtocol pn = "SHA512"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; #endif pn = "none supported"; ret = snprintf(p, remain, "%s", (comma++ ? "" : pn) ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; ret = snprintf(p, remain, "%s", ") used for authenticated SNMPv3 messages (default=MD5 if available)"); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar()"); } p += ret; remain -= (size_t)ret; addvar(VAR_VALUE, SU_VAR_AUTHPROT, tmp_buf); } /* Construct addvar() for AUTHPROTO */ /* Construct addvar() for SU_VAR_PRIVPROT: */ { int comma = 0; char tmp_buf[SU_LARGEBUF]; char *p = tmp_buf; char *pn; /* proto name to add */ size_t remain = sizeof(tmp_buf) - 1; int ret; NUT_UNUSED_VARIABLE(comma); /* potentially, if no protocols are available */ tmp_buf[0] = '\0'; ret = snprintf(p, remain, "%s", "Set the privacy protocol ("); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar()"); } p += ret; remain -= (size_t)ret; #if NUT_HAVE_LIBNETSNMP_usmDESPrivProtocol pn = "DES"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; #endif #if NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol || NUT_HAVE_LIBNETSNMP_usmAES128PrivProtocol pn = "AES"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; #endif #if NUT_HAVE_LIBNETSNMP_DRAFT_BLUMENTHAL_AES_04 # if NUT_HAVE_LIBNETSNMP_usmAES192PrivProtocol pn = "AES192"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; # endif # if NUT_HAVE_LIBNETSNMP_usmAES256PrivProtocol pn = "AES256"; ret = snprintf(p, remain, "%s%s", (comma++ ? ", " : ""), pn ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; # endif #endif /* NUT_HAVE_LIBNETSNMP_DRAFT_BLUMENTHAL_AES_04 */ pn = "none supported"; ret = snprintf(p, remain, "%s", (comma++ ? "" : pn) ); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar(%s)", pn); } p += ret; remain -= (size_t)ret; ret = snprintf(p, remain, "%s", ") used for encrypted SNMPv3 messages (default=DES if available)"); if (ret < 0 || (uintmax_t)ret > (uintmax_t)remain || (uintmax_t)ret > SIZE_MAX) { fatalx(EXIT_FAILURE, "Could not addvar()"); } p += ret; remain -= (size_t)ret; addvar(VAR_VALUE, SU_VAR_PRIVPROT, tmp_buf); } /* Construct addvar() for PRIVPROTO */ addvar(VAR_VALUE, SU_VAR_ONDELAY, "Set start delay time after shutdown"); addvar(VAR_VALUE, SU_VAR_OFFDELAY, "Set delay time before shutdown "); } void upsdrv_initups(void) { snmp_info_t *su_info_p, *cur_info_p; char model[SU_INFOSIZE]; bool_t status= FALSE; const char *mibs; int curdev = 0; upsdebugx(1, "SNMP UPS driver: entering %s()", __func__); /* Retrieve user's parameters */ mibs = testvar(SU_VAR_MIBS) ? getval(SU_VAR_MIBS) : "auto"; if (!strcmp(mibs, "--list")) { int i; printf("The 'mibs' argument is '%s', so just listing the mappings this driver knows,\n" "and for 'mibs=auto' these mappings will be tried in the following order until\n" "the first one matches your device\n\n", mibs); printf("%7s\t%-23s\t%-7s\t%-31s\t%-s\n", "NUMBER", "MAPPING NAME", "VERSION", "ENTRY POINT OID", "AUTO CHECK OID"); for (i=0; mib2nut[i] != NULL; i++) { printf(" %4d \t%-23s\t%7s\t%-31s\t%-s\n", (i+1), mib2nut[i]->mib_name ? mib2nut[i]->mib_name : "" , mib2nut[i]->mib_version ? mib2nut[i]->mib_version : "" , mib2nut[i]->sysOID ? mib2nut[i]->sysOID : "" , mib2nut[i]->oid_auto_check ? mib2nut[i]->oid_auto_check : "" ); } printf("\nOverall this driver has loaded %d MIB-to-NUT mapping tables\n", i); exit(EXIT_SUCCESS); /* fatalx(EXIT_FAILURE, "Marking the exit code as failure since the driver is not started now"); */ } /* init SNMP library, etc... */ nut_snmp_init(progname, device_path); /* FIXME: first test if the device is reachable to avoid timeouts! */ /* FIXME: with the argument called "mibs" (plural) it could make * sense to actually support a list of MIBs to try to get info * from, in order of preference, e.g. both a vendor MIB and the * IETF MIB for missing data points. Or even several vendor MIBs * for devices from companies with a long heritage. */ /* Load the SNMP to NUT translation data */ load_mib2nut(mibs); /* init polling frequency */ if (getval(SU_VAR_POLLFREQ)) pollfreq = atoi(getval(SU_VAR_POLLFREQ)); else pollfreq = DEFAULT_POLLFREQ; /* init semistatic update frequency */ if (getval(SU_VAR_SEMISTATICFREQ)) semistaticfreq = atoi(getval(SU_VAR_SEMISTATICFREQ)); else semistaticfreq = DEFAULT_SEMISTATICFREQ; if (semistaticfreq < 1) { upsdebugx(1, "Bad %s value provided, setting to default", SU_VAR_SEMISTATICFREQ); semistaticfreq = DEFAULT_SEMISTATICFREQ; } semistatic_countdown = semistaticfreq; /* Get UPS Model node to see if there's a MIB */ /* FIXME: extend and use match_model_OID(char *model) */ su_info_p = su_find_info("ups.model"); /* Try to get device.model if ups.model is not available */ if (su_info_p == NULL) su_info_p = su_find_info("device.model"); if (su_info_p != NULL) { /* Daisychain specific: we may have a template (including formatting * string) that needs to be adapted! */ if (strchr(su_info_p->OID, '%') != NULL) { upsdebugx(2, "Found template, need to be adapted"); cur_info_p = (snmp_info_t *)malloc(sizeof(snmp_info_t)); cur_info_p->info_type = (char *)xmalloc(SU_INFOSIZE); cur_info_p->OID = (char *)xmalloc(SU_INFOSIZE); snprintf((char*)cur_info_p->info_type, SU_INFOSIZE, "%s", su_info_p->info_type); /* Use the daisychain master (0) / 1rst device index */ snprintf_dynamic((char*)cur_info_p->OID, SU_INFOSIZE, su_info_p->OID, "%i", 0); } else { upsdebugx(2, "Found entry, not a template %s", su_info_p->OID); /* Otherwise, just point at what we found */ cur_info_p = su_info_p; } /* Actually get the data */ status = nut_snmp_get_str(cur_info_p->OID, model, sizeof(model), NULL); /* Free our malloc, if it was dynamic */ if (strchr(su_info_p->OID, '%') != NULL) { if (cur_info_p->info_type != NULL) free((char*)cur_info_p->info_type); if (cur_info_p->OID != NULL) free((char*)cur_info_p->OID); if (cur_info_p != NULL) free((char*)cur_info_p); } } if (status == TRUE) upslogx(LOG_INFO, "Detected %s on host %s (mib: %s %s)", model, device_path, mibname, mibvers); else fatalx(EXIT_FAILURE, "%s MIB wasn't found on %s", mibs, g_snmp_sess.peername); /* FIXME: "No supported device detected" */ /* Init daisychain and check if support is required */ daisychain_init(); /* Allocate / init the daisychain info structure (for phases only for now) * daisychain_info[0] is the whole chain! (added +1) */ daisychain_info = (daisychain_info_t**)malloc( sizeof(daisychain_info_t) * (size_t)(devices_count + 1) ); for (curdev = 0 ; curdev <= devices_count ; curdev++) { daisychain_info[curdev] = (daisychain_info_t*)malloc(sizeof(daisychain_info_t)); daisychain_info[curdev]->input_phases = (long)-1; daisychain_info[curdev]->output_phases = (long)-1; daisychain_info[curdev]->bypass_phases = (long)-1; } /* FIXME: also need daisychain awareness (so init)! * i.e load.off.delay+load.off + device.1.load.off.delay+device.1.load.off + ... */ /* FIXME: daisychain commands support! */ if (su_find_info("load.off.delay")) { /* Adds default with a delay value of '0' (= immediate) */ dstate_addcmd("load.off"); } if (su_find_info("load.on.delay")) { /* Adds default with a delay value of '0' (= immediate) */ dstate_addcmd("load.on"); } if (su_find_info("load.off.delay") && su_find_info("load.on.delay")) { /* Add composite instcmds (require setting multiple OID values) */ dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); } /* Publish sysDescr, sysContact and sysLocation (from IETF standard paths) * for all subdrivers that do not have one defined in their mapping * tables (note: for lack of better knowledge, defined as read-only * entries here, and also read-once - not updated during driver uptime) */ if (NULL == dstate_getinfo("device.description") && NULL == dstate_getinfo("device.1.description") ) { /* sysDescr.0 */ if (nut_snmp_get_str(".1.3.6.1.2.1.1.1.0", model, sizeof(model), NULL) == TRUE) { upsdebugx(2, "Using IETF-MIB default to get and publish sysDescr for device.description (once)"); dstate_setinfo("device.description", "%s", model); } else { upsdebugx(2, "Can't get and publish sysDescr for device.description"); } } if (NULL == dstate_getinfo("device.contact") && NULL == dstate_getinfo("device.1.contact") ) { /* sysContact.0 */ if (nut_snmp_get_str(".1.3.6.1.2.1.1.4.0", model, sizeof(model), NULL) == TRUE) { upsdebugx(2, "Using IETF-MIB default to get and publish sysContact for device.contact (once)"); dstate_setinfo("device.contact", "%s", model); } else { upsdebugx(2, "Can't get and publish sysContact for device.contact"); } } if (NULL == dstate_getinfo("device.location") && NULL == dstate_getinfo("device.1.location") ) { /* sysLocation.0 */ if (nut_snmp_get_str(".1.3.6.1.2.1.1.6.0", model, sizeof(model), NULL) == TRUE) { upsdebugx(2, "Using IETF-MIB default to get and publish sysLocation for device.location (once)"); dstate_setinfo("device.location", "%s", model); } else { upsdebugx(2, "Can't get and publish sysLocation for device.location"); } } /* set shutdown and autostart delay */ set_delays(); } void upsdrv_cleanup(void) { /* General cleanup */ if (daisychain_info) free(daisychain_info); /* Net-SNMP specific cleanup */ nut_snmp_cleanup(); } /* ----------------------------------------------------------- * SNMP functions. * ----------------------------------------------------------- */ void nut_snmp_init(const char *type, const char *hostname) { char *ns_options = NULL; const char *community, *version; const char *secLevel = NULL, *authPassword, *privPassword; const char *authProtocol, *privProtocol; int snmp_retries = DEFAULT_NETSNMP_RETRIES; long snmp_timeout = DEFAULT_NETSNMP_TIMEOUT; upsdebugx(2, "SNMP UPS driver: entering %s(%s)", __func__, type); /* Force numeric OIDs resolution (ie, do not resolve to textual names) * This is mostly for the convenience of debug output */ ns_options = snmp_out_toggle_options("n"); if (ns_options != NULL) { upsdebugx(2, "Failed to enable numeric OIDs resolution"); } /* Initialize the SNMP library */ init_snmp(type); /* Initialize session */ snmp_sess_init(&g_snmp_sess); g_snmp_sess.peername = xstrdup(hostname); /* Net-SNMP timeout and retries */ if (testvar(SU_VAR_RETRIES)) { snmp_retries = atoi(getval(SU_VAR_RETRIES)); } g_snmp_sess.retries = snmp_retries; upsdebugx(2, "Setting SNMP retries to %i", snmp_retries); if (testvar(SU_VAR_TIMEOUT)) { snmp_timeout = atol(getval(SU_VAR_TIMEOUT)); } /* We have to convert from seconds to microseconds */ g_snmp_sess.timeout = snmp_timeout * ONE_SEC; upsdebugx(2, "Setting SNMP timeout to %ld second(s)", snmp_timeout); /* Retrieve user parameters */ version = testvar(SU_VAR_VERSION) ? getval(SU_VAR_VERSION) : "v1"; /* Older CLANG (e.g. clang-3.4) sees short strings in str{n}cmp() * arguments as arrays and claims out-of-bounds accesses */ #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ARRAY_BOUNDS) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Warray-bounds" #endif #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Warray-bounds" #endif if ((strcmp(version, "v1") == 0) || (strcmp(version, "v2c") == 0)) { g_snmp_sess.version = (strcmp(version, "v1") == 0) ? SNMP_VERSION_1 : SNMP_VERSION_2c; community = testvar(SU_VAR_COMMUNITY) ? getval(SU_VAR_COMMUNITY) : "public"; g_snmp_sess.community = (unsigned char *)xstrdup(community); g_snmp_sess.community_len = strlen(community); } else if (strcmp(version, "v3") == 0) { #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_ARRAY_BOUNDS) # pragma GCC diagnostic pop #endif /* SNMP v3 related init */ g_snmp_sess.version = SNMP_VERSION_3; /* Security level */ if (testvar(SU_VAR_SECLEVEL)) { secLevel = getval(SU_VAR_SECLEVEL); if (strcmp(secLevel, "noAuthNoPriv") == 0) g_snmp_sess.securityLevel = SNMP_SEC_LEVEL_NOAUTH; else if (strcmp(secLevel, "authNoPriv") == 0) g_snmp_sess.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV; else if (strcmp(secLevel, "authPriv") == 0) g_snmp_sess.securityLevel = SNMP_SEC_LEVEL_AUTHPRIV; else fatalx(EXIT_FAILURE, "Bad SNMPv3 securityLevel: %s", secLevel); } else g_snmp_sess.securityLevel = SNMP_SEC_LEVEL_NOAUTH; /* Security name */ if (testvar(SU_VAR_SECNAME)) { g_snmp_sess.securityName = xstrdup(getval(SU_VAR_SECNAME)); g_snmp_sess.securityNameLen = strlen(g_snmp_sess.securityName); } else fatalx(EXIT_FAILURE, "securityName is required for SNMPv3"); /* Process mandatory fields, based on the security level */ authPassword = testvar(SU_VAR_AUTHPASSWD) ? getval(SU_VAR_AUTHPASSWD) : NULL; privPassword = testvar(SU_VAR_PRIVPASSWD) ? getval(SU_VAR_PRIVPASSWD) : NULL; switch (g_snmp_sess.securityLevel) { case SNMP_SEC_LEVEL_AUTHNOPRIV: if (authPassword == NULL) fatalx(EXIT_FAILURE, "authPassword is required for SNMPv3 in %s mode", secLevel); break; case SNMP_SEC_LEVEL_AUTHPRIV: if ((authPassword == NULL) || (privPassword == NULL)) fatalx(EXIT_FAILURE, "authPassword and privPassword are required for SNMPv3 in %s mode", secLevel); break; default: case SNMP_SEC_LEVEL_NOAUTH: /* nothing else needed */ break; } /* Process authentication protocol and key */ g_snmp_sess.securityAuthKeyLen = USM_AUTH_KU_LEN; authProtocol = testvar(SU_VAR_AUTHPROT) ? getval(SU_VAR_AUTHPROT) : "MD5"; #if NUT_HAVE_LIBNETSNMP_usmHMACMD5AuthProtocol if (strcmp(authProtocol, "MD5") == 0) { g_snmp_sess.securityAuthProto = usmHMACMD5AuthProtocol; g_snmp_sess.securityAuthProtoLen = sizeof(usmHMACMD5AuthProtocol)/sizeof(oid); } else #endif #if NUT_HAVE_LIBNETSNMP_usmHMACSHA1AuthProtocol if (strcmp(authProtocol, "SHA") == 0) { g_snmp_sess.securityAuthProto = usmHMACSHA1AuthProtocol; g_snmp_sess.securityAuthProtoLen = sizeof(usmHMACSHA1AuthProtocol)/sizeof(oid); } else #endif #if NUT_HAVE_LIBNETSNMP_usmHMAC192SHA256AuthProtocol if (strcmp(authProtocol, "SHA256") == 0) { g_snmp_sess.securityAuthProto = usmHMAC192SHA256AuthProtocol; g_snmp_sess.securityAuthProtoLen = sizeof(usmHMAC192SHA256AuthProtocol)/sizeof(oid); } else #endif #if NUT_HAVE_LIBNETSNMP_usmHMAC256SHA384AuthProtocol if (strcmp(authProtocol, "SHA384") == 0) { g_snmp_sess.securityAuthProto = usmHMAC256SHA384AuthProtocol; g_snmp_sess.securityAuthProtoLen = sizeof(usmHMAC256SHA384AuthProtocol)/sizeof(oid); } else #endif #if NUT_HAVE_LIBNETSNMP_usmHMAC384SHA512AuthProtocol if (strcmp(authProtocol, "SHA512") == 0) { g_snmp_sess.securityAuthProto = usmHMAC384SHA512AuthProtocol; g_snmp_sess.securityAuthProtoLen = sizeof(usmHMAC384SHA512AuthProtocol)/sizeof(oid); } else #endif fatalx(EXIT_FAILURE, "Bad SNMPv3 authProtocol: %s", authProtocol); /* set the authentication key to a MD5/SHA1 hashed version of our * passphrase (must be at least 8 characters long) */ if (g_snmp_sess.securityLevel != SNMP_SEC_LEVEL_NOAUTH) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif /* NOTE: Net-SNMP headers just are weird like that, in the same release: net-snmp/types.h: size_t securityAuthProtoLen; net-snmp/library/keytools.h: int generate_Ku(const oid * hashtype, u_int hashtype_len, ... * Should we match in configure like for "getnameinfo()" arg types? * Currently we cast one to another, below (detecting target type could help). */ if ((uintmax_t)g_snmp_sess.securityAuthProtoLen > UINT_MAX) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif fatalx(EXIT_FAILURE, "Bad SNMPv3 securityAuthProtoLen: %" PRIuSIZE, g_snmp_sess.securityAuthProtoLen); } if (generate_Ku(g_snmp_sess.securityAuthProto, (u_int)g_snmp_sess.securityAuthProtoLen, (const unsigned char *) authPassword, strlen(authPassword), g_snmp_sess.securityAuthKey, &g_snmp_sess.securityAuthKeyLen) != SNMPERR_SUCCESS) { fatalx(EXIT_FAILURE, "Error generating Ku from authentication pass phrase"); } } privProtocol = testvar(SU_VAR_PRIVPROT) ? getval(SU_VAR_PRIVPROT) : "DES"; #if NUT_HAVE_LIBNETSNMP_usmDESPrivProtocol if (strcmp(privProtocol, "DES") == 0) { g_snmp_sess.securityPrivProto = usmDESPrivProtocol; g_snmp_sess.securityPrivProtoLen = sizeof(usmDESPrivProtocol)/sizeof(oid); } else #endif #if NUT_HAVE_LIBNETSNMP_usmAESPrivProtocol || NUT_HAVE_LIBNETSNMP_usmAES128PrivProtocol if (strcmp(privProtocol, "AES") == 0) { g_snmp_sess.securityPrivProto = usmAESPrivProtocol; g_snmp_sess.securityPrivProtoLen = NUT_securityPrivProtoLen; } else #endif #if NUT_HAVE_LIBNETSNMP_DRAFT_BLUMENTHAL_AES_04 # if NUT_HAVE_LIBNETSNMP_usmAES192PrivProtocol if (strcmp(privProtocol, "AES192") == 0) { g_snmp_sess.securityPrivProto = usmAES192PrivProtocol; g_snmp_sess.securityPrivProtoLen = (sizeof(usmAES192PrivProtocol)/sizeof(oid)); } else # endif # if NUT_HAVE_LIBNETSNMP_usmAES256PrivProtocol if (strcmp(privProtocol, "AES256") == 0) { g_snmp_sess.securityPrivProto = usmAES256PrivProtocol; g_snmp_sess.securityPrivProtoLen = (sizeof(usmAES256PrivProtocol)/sizeof(oid)); } else # endif #endif /* NUT_HAVE_LIBNETSNMP_DRAFT_BLUMENTHAL_AES_04 */ fatalx(EXIT_FAILURE, "Bad SNMPv3 privProtocol: %s", privProtocol); /* set the privacy key to a MD5/SHA1 hashed version of our * passphrase (must be at least 8 characters long) */ if (g_snmp_sess.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) { g_snmp_sess.securityPrivKeyLen = USM_PRIV_KU_LEN; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif /* See comment on generate_Ku() a few dozen lines above */ if ((uintmax_t)g_snmp_sess.securityAuthProtoLen > UINT_MAX) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif fatalx(EXIT_FAILURE, "Bad SNMPv3 securityAuthProtoLen: %" PRIuSIZE, g_snmp_sess.securityAuthProtoLen); } if (generate_Ku(g_snmp_sess.securityAuthProto, (u_int)g_snmp_sess.securityAuthProtoLen, (const unsigned char *) privPassword, strlen(privPassword), g_snmp_sess.securityPrivKey, &g_snmp_sess.securityPrivKeyLen) != SNMPERR_SUCCESS) { fatalx(EXIT_FAILURE, "Error generating Ku from privacy pass phrase"); } } } else fatalx(EXIT_FAILURE, "Bad SNMP version: %s", version); /* Open the session */ SOCK_STARTUP; /* MS Windows wrapper, not really needed on Unix! */ g_snmp_sess_p = snmp_open(&g_snmp_sess); /* establish the session */ if (g_snmp_sess_p == NULL) { nut_snmp_perror(&g_snmp_sess, 0, NULL, "nut_snmp_init: snmp_open"); fatalx(EXIT_FAILURE, "Unable to establish communication"); } } void nut_snmp_cleanup(void) { /* close snmp session. */ if (g_snmp_sess_p) { snmp_close(g_snmp_sess_p); g_snmp_sess_p = NULL; } SOCK_CLEANUP; /* wrapper not needed on Unix! */ } /* Free a struct snmp_pdu * returned by nut_snmp_walk */ static void nut_snmp_free(struct snmp_pdu ** array_to_free) { struct snmp_pdu ** current_element; if (array_to_free != NULL) { current_element = array_to_free; while (*current_element != NULL) { snmp_free_pdu(*current_element); current_element++; } free( array_to_free ); } } /* Return a NULL terminated array of snmp_pdu * */ static struct snmp_pdu **nut_snmp_walk(const char *OID, int max_iteration) { int status; struct snmp_pdu *pdu, *response = NULL; oid name[MAX_OID_LEN]; size_t name_len = MAX_OID_LEN; oid * current_name; size_t current_name_len; static unsigned int numerr = 0; int nb_iteration = 0; struct snmp_pdu ** ret_array = NULL; int type = SNMP_MSG_GET; upsdebugx(3, "%s(%s)", __func__, OID); upsdebugx(4, "%s: max. iteration = %i", __func__, max_iteration); /* create and send request. */ if (!snmp_parse_oid(OID, name, &name_len)) { upsdebugx(2, "[%s] %s: %s: %s", upsname?upsname:device_name, __func__, OID, snmp_api_errstring(snmp_errno)); return NULL; } current_name = name; current_name_len = name_len; while( nb_iteration < max_iteration ) { struct snmp_pdu **new_ret_array; /* Going to a shorter OID means we are outside our sub-tree */ if( current_name_len < name_len ) { break; } pdu = snmp_pdu_create(type); if (pdu == NULL) { fatalx(EXIT_FAILURE, "Not enough memory"); } snmp_add_null_var(pdu, current_name, current_name_len); status = snmp_synch_response(g_snmp_sess_p, pdu, &response); if (!response) { break; } if (!((status == STAT_SUCCESS) && (response->errstat == SNMP_ERR_NOERROR))) { if (mibname == NULL) { /* We are probing for proper mib - ignore errors */ snmp_free_pdu(response); nut_snmp_free(ret_array); return NULL; } if (response->errstat == SNMP_ERR_NOSUCHNAME) { upsdebugx(4, "%s: OID does not exist, skipping", __func__); snmp_free_pdu(response); nut_snmp_free(ret_array); return NULL; } upsdebugx(3, "status = %i, response->errstat = %li", status, response->errstat); /* Error throttling otherwise */ numerr++; upsdebugx(4, "%s: numerr++ (total=%u)", __func__, numerr); if ((numerr == SU_ERR_LIMIT) || ((numerr % SU_ERR_RATE) == 0)) { upslogx(LOG_WARNING, "[%s] Warning: excessive poll " "failures, limiting error reporting (OID = %s)", upsname?upsname:device_name, OID); } if ((numerr < SU_ERR_LIMIT) || ((numerr % SU_ERR_RATE) == 0)) { if (type == SNMP_MSG_GETNEXT) { upsdebugx(2, "=> No more OID, walk complete"); } else { nut_snmp_perror(g_snmp_sess_p, status, response, "%s: %s", __func__, OID); } } snmp_free_pdu(response); break; } else { /* Checked the "type" field of the returned varbind if * it is a type error exception (only applicable with * SNMPv2 or SNMPv3 protocol, would not happen with * SNMPv1). This allows to proceed interpreting large * responses when one entry in the middle is rejectable. */ if (response->variables->type == SNMP_NOSUCHOBJECT || response->variables->type == SNMP_NOSUCHINSTANCE || response->variables->type == SNMP_ENDOFMIBVIEW) { upslogx(LOG_WARNING, "[%s] Warning: type error exception (OID = %s)", upsname?upsname:device_name, OID); snmp_free_pdu(response); break; } else { /* no error */ numerr = 0; } } nb_iteration++; /* +1 is for the terminating NULL */ new_ret_array = realloc( ret_array, sizeof(struct snmp_pdu*) * ((size_t)nb_iteration+1) ); if (new_ret_array == NULL) { upsdebugx(1, "%s: Failed to realloc thread", __func__); break; } else { ret_array = new_ret_array; } ret_array[nb_iteration-1] = response; ret_array[nb_iteration]=NULL; current_name = response->variables->name; current_name_len = response->variables->name_length; type = SNMP_MSG_GETNEXT; } return ret_array; } struct snmp_pdu *nut_snmp_get(const char *OID) { struct snmp_pdu ** pdu_array; struct snmp_pdu * ret_pdu; if (OID == NULL) return NULL; upsdebugx(3, "%s(%s)", __func__, OID); pdu_array = nut_snmp_walk(OID,1); if(pdu_array == NULL) { return NULL; } ret_pdu = snmp_clone_pdu(*pdu_array); nut_snmp_free(pdu_array); return ret_pdu; } static bool_t decode_str(struct snmp_pdu *pdu, char *buf, size_t buf_len, info_lkp_t *oid2info) { size_t len = 0; char tmp_buf[SU_LARGEBUF]; /* zero out buffer. */ memset(buf, 0, buf_len); switch (pdu->variables->type) { case ASN_OCTET_STR: case ASN_OPAQUE: { /* scoping */ /* Test for hexadecimal values */ int hex = 0, x; unsigned char *cp; len = pdu->variables->val_len > buf_len - 1 ? buf_len - 1 : pdu->variables->val_len; for(cp = pdu->variables->val.string, x = 0; x < (int)pdu->variables->val_len; x++, cp++) { if (!(isprint((size_t)*cp) || isspace((size_t)*cp))) { hex = 1; } } if (hex) snprint_hexstring(buf, buf_len, pdu->variables->val.string, pdu->variables->val_len); else { memcpy(buf, pdu->variables->val.string, len); buf[len] = '\0'; } } break; case ASN_INTEGER: case ASN_COUNTER: case ASN_GAUGE: if(oid2info) { const char *str; /* See union netsnmp_vardata in net-snmp/types.h: "integer" is a "long*" */ assert(sizeof(pdu->variables->val.integer) == sizeof(long*)); /* If in future net-snmp headers val becomes not-a-pointer, * compiler should complain about (void*) arg casting here */ if((str = su_find_infoval(oid2info, pdu->variables->val.integer))) { strncpy(buf, str, buf_len-1); } /* when oid2info returns NULL, don't publish the variable! */ else { /* strncpy(buf, "UNKNOWN", buf_len-1); */ return FALSE; } buf[buf_len-1]='\0'; } else { int ret = snprintf(buf, buf_len, "%ld", *pdu->variables->val.integer); if (ret < 0) upsdebugx(3, "Failed to retrieve ASN_GAUGE"); else len = (size_t)ret; } break; case ASN_TIMETICKS: /* convert timeticks to seconds */ { int ret = snprintf(buf, buf_len, "%ld", *pdu->variables->val.integer / 100); if (ret < 0) upsdebugx(3, "Failed to retrieve ASN_TIMETICKS"); else len = (size_t)ret; } break; case ASN_OBJECT_ID: snprint_objid (tmp_buf, sizeof(tmp_buf), pdu->variables->val.objid, pdu->variables->val_len / sizeof(oid)); upsdebugx(2, "Received an OID value: %s", tmp_buf); /* Try to get the value of the pointed OID */ if (nut_snmp_get_str(tmp_buf, buf, buf_len, oid2info) == FALSE) { char *oid_leaf; upsdebugx(3, "Failed to retrieve OID value, using fallback"); /* Otherwise return the last part of the returned OID (ex: 1.2.3 => 3) */ oid_leaf = strrchr(tmp_buf, '.'); snprintf(buf, buf_len, "%s", oid_leaf+1); upsdebugx(3, "Fallback value: %s", buf); } break; default: return FALSE; } return TRUE; } bool_t nut_snmp_get_str(const char *OID, char *buf, size_t buf_len, info_lkp_t *oid2info) { struct snmp_pdu *pdu; bool_t ret; upsdebugx(3, "Entering %s()", __func__); pdu = nut_snmp_get(OID); if (pdu == NULL) return FALSE; ret = decode_str(pdu,buf,buf_len,oid2info); if(ret == FALSE) { upsdebugx(2, "[%s] unhandled ASN 0x%x received from %s", upsname?upsname:device_name, pdu->variables->type, OID); } snmp_free_pdu(pdu); return ret; } static bool_t decode_oid(struct snmp_pdu *pdu, char *buf, size_t buf_len) { /* zero out buffer. */ memset(buf, 0, buf_len); switch (pdu->variables->type) { case ASN_OBJECT_ID: snprint_objid (buf, buf_len, pdu->variables->val.objid, pdu->variables->val_len / sizeof(oid)); upsdebugx(2, "OID value: %s", buf); break; default: return FALSE; } return TRUE; } /* Return the value stored in OID, which is an OID (sysOID for example) * and don't try to get the value pointed by this OID (no follow). * To achieve the latter behavior, use standard nut_snmp_get_{str,int}() */ bool_t nut_snmp_get_oid(const char *OID, char *buf, size_t buf_len) { struct snmp_pdu *pdu; bool_t ret = FALSE; /* zero out buffer. */ memset(buf, 0, buf_len); upsdebugx(3, "Entering %s()", __func__); pdu = nut_snmp_get(OID); if (pdu == NULL) return FALSE; ret = decode_oid(pdu, buf, buf_len); if(ret == FALSE) { upsdebugx(2, "[%s] unhandled ASN 0x%x received from %s", upsname?upsname:device_name, pdu->variables->type, OID); } snmp_free_pdu(pdu); return ret; } bool_t nut_snmp_get_int(const char *OID, long *pval) { char tmp_buf[SU_LARGEBUF]; struct snmp_pdu *pdu; long value; char *buf; upsdebugx(3, "Entering %s()", __func__); pdu = nut_snmp_get(OID); if (pdu == NULL) return FALSE; switch (pdu->variables->type) { case ASN_OCTET_STR: case ASN_OPAQUE: buf = xmalloc(pdu->variables->val_len + 1); memcpy(buf, pdu->variables->val.string, pdu->variables->val_len); buf[pdu->variables->val_len] = '\0'; value = strtol(buf, NULL, 0); free(buf); break; case ASN_INTEGER: case ASN_COUNTER: case ASN_GAUGE: value = *pdu->variables->val.integer; break; case ASN_TIMETICKS: /* convert timeticks to seconds */ value = *pdu->variables->val.integer / 100; break; case ASN_OBJECT_ID: snprint_objid (tmp_buf, sizeof(tmp_buf), pdu->variables->val.objid, pdu->variables->val_len / sizeof(oid)); upsdebugx(2, "Received an OID value: %s", tmp_buf); /* Try to get the value of the pointed OID */ if (nut_snmp_get_int(tmp_buf, &value) == FALSE) { char *oid_leaf; upsdebugx(3, "Failed to retrieve OID value, using fallback"); /* Otherwise return the last part of the returned OID (ex: 1.2.3 => 3) */ oid_leaf = strrchr(tmp_buf, '.'); value = strtol(oid_leaf+1, NULL, 0); upsdebugx(3, "Fallback value: %ld", value); } break; default: upslogx(LOG_ERR, "[%s] unhandled ASN 0x%x received from %s", upsname?upsname:device_name, pdu->variables->type, OID); return FALSE; } snmp_free_pdu(pdu); if (pval != NULL) *pval = value; return TRUE; } bool_t nut_snmp_set(const char *OID, char type, const char *value) { int status; bool_t ret = FALSE; struct snmp_pdu *pdu, *response = NULL; oid name[MAX_OID_LEN]; size_t name_len = MAX_OID_LEN; upsdebugx(1, "entering %s(%s, %c, %s)", __func__, OID, type, value); if (!snmp_parse_oid(OID, name, &name_len)) { upslogx(LOG_ERR, "[%s] %s: %s: %s", upsname?upsname:device_name, __func__, OID, snmp_api_errstring(snmp_errno)); return FALSE; } pdu = snmp_pdu_create(SNMP_MSG_SET); if (pdu == NULL) fatalx(EXIT_FAILURE, "Not enough memory"); if (snmp_add_var(pdu, name, name_len, type, value)) { upslogx(LOG_ERR, "[%s] %s: %s: %s", upsname?upsname:device_name, __func__, OID, snmp_api_errstring(snmp_errno)); return FALSE; } status = snmp_synch_response(g_snmp_sess_p, pdu, &response); if ((status == STAT_SUCCESS) && (response->errstat == SNMP_ERR_NOERROR)) ret = TRUE; else nut_snmp_perror(g_snmp_sess_p, status, response, "%s: can't set %s", __func__, OID); snmp_free_pdu(response); return ret; } bool_t nut_snmp_set_str(const char *OID, const char *value) { return nut_snmp_set(OID, 's', value); } bool_t nut_snmp_set_int(const char *OID, long value) { char buf[SU_BUFSIZE]; snprintf(buf, sizeof(buf), "%ld", value); return nut_snmp_set(OID, 'i', buf); } bool_t nut_snmp_set_time(const char *OID, long value) { char buf[SU_BUFSIZE]; snprintf(buf, SU_BUFSIZE, "%ld", value * 100); return nut_snmp_set(OID, 't', buf); } /* log descriptive SNMP error message. */ void nut_snmp_perror(struct snmp_session *sess, int status, struct snmp_pdu *response, const char *fmt, ...) { va_list va; int cliberr, snmperr; char *snmperrstr; char buf[SU_LARGEBUF]; va_start(va, fmt); vsnprintf(buf, sizeof(buf), fmt, va); va_end(va); if (response == NULL) { snmp_error(sess, &cliberr, &snmperr, &snmperrstr); upslogx(LOG_ERR, "[%s] %s: %s", upsname?upsname:device_name, buf, snmperrstr); free(snmperrstr); } else if (status == STAT_SUCCESS) { /* Net-SNMP headers provide and consume errstat with different types: net-snmp/output_api.h: const char *snmp_errstring(int snmp_errorno); net-snmp/types.h: long errstat; * Should we match in configure like for "getnameinfo()" arg types? * Currently we cast one to another, below (detecting target type could help). */ switch (response->errstat) { case SNMP_ERR_NOERROR: break; case SNMP_ERR_NOSUCHNAME: /* harmless */ upsdebugx(2, "[%s] %s: %s", upsname?upsname:device_name, buf, (response->errstat > INT_MAX ? "(Net-SNMP errstat value is out of range)" : snmp_errstring((int)response->errstat) )); break; default: upslogx(LOG_ERR, "[%s] %s: Error in packet: %s", upsname?upsname:device_name, buf, (response->errstat > INT_MAX ? "(Net-SNMP errstat value is out of range)" : snmp_errstring((int)response->errstat) )); break; } } else if (status == STAT_TIMEOUT) { upslogx(LOG_ERR, "[%s] %s: Timeout: no response from %s", upsname?upsname:device_name, buf, sess->peername); } else { snmp_sess_error(sess, &cliberr, &snmperr, &snmperrstr); upslogx(LOG_ERR, "[%s] %s: %s", upsname?upsname:device_name, buf, snmperrstr); free(snmperrstr); } } /* ----------------------------------------------------------- * utility functions. * ----------------------------------------------------------- */ /* deal with APCC weirdness on Symmetras */ static void disable_transfer_oids(void) { snmp_info_t *su_info_p; upslogx(LOG_INFO, "Disabling transfer OIDs"); if (snmp_info == NULL) { fatalx(EXIT_FAILURE, "%s: snmp_info is not initialized", __func__); } if (snmp_info[0].info_type == NULL) { upsdebugx(1, "%s: WARNING: snmp_info is empty", __func__); } for (su_info_p = &snmp_info[0]; (su_info_p != NULL && su_info_p->info_type != NULL) ; su_info_p++) { if (!strcasecmp(su_info_p->info_type, "input.transfer.low")) { su_info_p->flags &= ~SU_FLAG_OK; continue; } if (!strcasecmp(su_info_p->info_type, "input.transfer.high")) { su_info_p->flags &= ~SU_FLAG_OK; continue; } } } /* Universal function to add or update info element. * If value is NULL, use the default one (su_info_p->dfl) if provided */ void su_setinfo(snmp_info_t *su_info_p, const char *value) { info_lkp_t *info_lkp; char info_type[128]; /* We tweak incoming "su_info_p->info_type" value in some cases */ /* FIXME: Replace hardcoded 128 with a macro above (use {SU_}LARGEBUF?), * and same macro or sizeof(info_type) below (also more 128 cases below)? */ upsdebugx(1, "entering %s(%s, %s)", __func__, su_info_p->info_type, (value)?value:""); /* FIXME: This 20 seems very wrong (should be "128", macro or sizeof? see above) */ memset(info_type, 0, 20); /* pre-fill with the device name for checking */ snprintf(info_type, 128, "device.%i", current_device_number); /* Daisy-chain template magic should only apply to defaulted * entries (oid==null) or templated entries (contains .%i); * however at this point we see exact OIDs handed down from * su_ups_get() which instantiates a template (if needed - * and knows it was a template) and calls su_setinfo(). * NOTE: For setting the values (or commands) from clients * like `upsrw`, see su_setOID() method. Here we change our * device state records based on readings from a device. */ if ((daisychain_enabled == TRUE) && (devices_count > 1)) { if (su_info_p->OID != NULL && strstr(su_info_p->OID, ".%i") != NULL ) { /* Only inform, do not react so far, * need more understanding if and when * such situation might happen at all: */ upsdebugx(5, "%s: in a daisy-chained device, " "got a templated OID %s for type %s", __func__, su_info_p->OID, su_info_p->info_type); } /* Only append "device.X" for master and slaves, if not already done! */ if ((current_device_number > 0) && (strstr(su_info_p->info_type, info_type) == NULL)) { /* Special case: we remove "device" from the device collection not to * get "device.X.device.", but "device.X." */ if (!strncmp(su_info_p->info_type, "device.", 7)) { upsdebugx(6, "%s: in a daisy-chained device, " "OID %s: TRIM 'device.' from type %s (value %s)", __func__, su_info_p->OID, su_info_p->info_type, (value)?value:""); snprintf(info_type, 128, "device.%i.%s", current_device_number, su_info_p->info_type + 7); } else { upsdebugx(6, "%s: in a daisy-chained device, " "OID %s is templated: for type %s (value %s)", __func__, su_info_p->OID, su_info_p->info_type, (value)?value:""); snprintf(info_type, 128, "device.%i.%s", current_device_number, su_info_p->info_type); } } else { upsdebugx(6, "%s: in a daisy-chained device, " "OID %s: for type %s (value %s) " "device %d is not positive or type already " "contains the prepared expectation: %s", __func__, su_info_p->OID, su_info_p->info_type, (value)?value:"", current_device_number, info_type ); snprintf(info_type, 128, "%s", su_info_p->info_type); } } else { upsdebugx(6, "%s: NOT in a daisy-chained device", __func__); snprintf(info_type, 128, "%s", su_info_p->info_type); } upsdebugx(1, "%s: using info_type '%s'", __func__, info_type); if (SU_TYPE(su_info_p) == SU_TYPE_CMD) return; /* ups.status and {ups, Lx, outlet, outlet.group}.alarm have special * handling, not here! */ if ((strcasecmp(su_info_p->info_type, "ups.status")) && (strcasecmp(strrchr(su_info_p->info_type, '.'), ".alarm"))) { if (value != NULL) dstate_setinfo(info_type, "%s", value); else if (su_info_p->dfl != NULL) dstate_setinfo(info_type, "%s", su_info_p->dfl); else { upsdebugx(3, "%s: no value nor default provided, aborting...", __func__); return; } dstate_setflags(info_type, su_info_p->info_flags); dstate_setaux(info_type, su_info_p->info_len); /* Set enumerated values, only if the data has ST_FLAG_RW and there * are lookup values */ /* FIXME: daisychain settings support: check if applicable */ if ((su_info_p->info_flags & ST_FLAG_RW) && su_info_p->oid2info) { upsdebugx(3, "%s: adding enumerated values", __func__); /* Loop on all existing values */ for (info_lkp = su_info_p->oid2info; info_lkp != NULL && info_lkp->info_value != NULL; info_lkp++) { dstate_addenum(info_type, "%s", info_lkp->info_value); } } /* Commit the current value, to avoid staleness with huge * data collections on slow devices */ dstate_dataok(); } } void su_status_set(snmp_info_t *su_info_p, long value) { const char *info_value = NULL; upsdebugx(2, "SNMP UPS driver: entering %s()", __func__); if ((info_value = su_find_infoval(su_info_p->oid2info, &value)) != NULL) { if (info_value[0] != '\0') { status_set(info_value); } } /* TODO: else */ } void su_alarm_set(snmp_info_t *su_info_p, long value) { const char *info_value = NULL; const char *info_type = NULL; char alarm_info_value[SU_LARGEBUF]; /* number of the outlet or phase */ int item_number = -1; upsdebugx(2, "SNMP UPS driver: entering %s(%s)", __func__, su_info_p->info_type); /* daisychain handling * extract the template part to get the relevant 'info_type' part * ex: device.6.L1.alarm => L1.alarm * ex: device.6.outlet.1.alarm => outlet.1.alarm */ if (!strncmp(su_info_p->info_type, "device.", 7)) { info_type = strchr(su_info_p->info_type + 7, '.') + 1; } else info_type = su_info_p->info_type; upsdebugx(2, "%s: using definition %s", __func__, info_type); if ((info_value = su_find_infoval(su_info_p->oid2info, &value)) != NULL && info_value[0] != 0) { char alarm_info_value_more[SU_LARGEBUF + 32]; /* can sprintf() SU_LARGEBUF plus markup into here */ /* Special handling for outlet & outlet groups alarms */ if ((su_info_p->flags & SU_OUTLET) || (su_info_p->flags & SU_OUTLET_GROUP)) { /* Extract template number */ item_number = extract_template_number(su_info_p->flags, info_type); upsdebugx(2, "%s: appending %s %i", __func__, (su_info_p->flags & SU_OUTLET_GROUP) ? "outlet group" : "outlet", item_number); /* Inject in the alarm string */ snprintf(alarm_info_value, sizeof(alarm_info_value), "outlet%s %i %s", (su_info_p->flags & SU_OUTLET_GROUP) ? " group" : "", item_number, info_value); info_value = &alarm_info_value[0]; } /* Special handling for phase alarms * Note that SU_*PHASE flags are cleared, so match the 'Lx' * start of path */ if (info_type[0] == 'L') { /* Extract phase number */ item_number = atoi(info_type+1); upsdebugx(2, "%s: appending phase L%i", __func__, item_number); /* Inject in the alarm string */ snprintf(alarm_info_value_more, sizeof(alarm_info_value_more), "phase L%i %s", item_number, info_value); info_value = &alarm_info_value_more[0]; } /* Set the alarm value */ alarm_set(info_value); } /* TODO: else */ } /* find info element definition in my info array. */ snmp_info_t *su_find_info(const char *type) { snmp_info_t *su_info_p; if (snmp_info == NULL) { fatalx(EXIT_FAILURE, "%s: snmp_info is not initialized", __func__); } if (snmp_info[0].info_type == NULL) { upsdebugx(1, "%s: WARNING: snmp_info is empty", __func__); } for (su_info_p = &snmp_info[0]; (su_info_p != NULL && su_info_p->info_type != NULL) ; su_info_p++) if (!strcasecmp(su_info_p->info_type, type)) { upsdebugx(3, "%s: \"%s\" found", __func__, type); return su_info_p; } upsdebugx(3, "%s: unknown info type (%s)", __func__, type); return NULL; } /* Counter match the sysOID using {device,ups}.model OID * Return TRUE if this OID can be retrieved, FALSE otherwise */ static bool_t match_model_OID(void) { bool_t retCode = FALSE; snmp_info_t *su_info_p, *cur_info_p; char testOID_buf[LARGEBUF]; /* Try to get device.model first */ su_info_p = su_find_info("device.model"); /* Otherwise, try to get ups.model */ if (su_info_p == NULL) su_info_p = su_find_info("ups.model"); if (su_info_p != NULL) { /* Daisychain specific: we may have a template (including formatting * string) that needs to be adapted! */ if (strchr(su_info_p->OID, '%') != NULL) { upsdebugx(2, "Found template, need to be adapted"); cur_info_p = (snmp_info_t *)malloc(sizeof(snmp_info_t)); cur_info_p->info_type = (char *)xmalloc(SU_INFOSIZE); cur_info_p->OID = (char *)xmalloc(SU_INFOSIZE); snprintf((char*)cur_info_p->info_type, SU_INFOSIZE, "%s", su_info_p->info_type); /* Use the daisychain master (0) / 1rst device index */ snprintf_dynamic((char*)cur_info_p->OID, SU_INFOSIZE, su_info_p->OID, "%i", 0); } else { upsdebugx(2, "Found entry, not a template %s", su_info_p->OID); /* Otherwise, just point at what we found */ cur_info_p = su_info_p; } upsdebugx(2, "Testing %s using OID %s", cur_info_p->info_type, cur_info_p->OID); retCode = nut_snmp_get_str(cur_info_p->OID, testOID_buf, LARGEBUF, NULL); /* Free our malloc, if it was dynamic */ if (strchr(su_info_p->OID, '%') != NULL) { if (cur_info_p->info_type != NULL) free((char*)cur_info_p->info_type); if (cur_info_p->OID != NULL) free((char*)cur_info_p->OID); if (cur_info_p != NULL) free((char*)cur_info_p); } } return retCode; } /* Try to find the MIB using sysOID matching. * Return a pointer to a mib2nut definition if found, NULL otherwise */ static mib2nut_info_t *match_sysoid(void) { char sysOID_buf[LARGEBUF]; oid device_sysOID[MAX_OID_LEN]; size_t device_sysOID_len = MAX_OID_LEN; oid mib2nut_sysOID[MAX_OID_LEN]; size_t mib2nut_sysOID_len = MAX_OID_LEN; int i; /* Retrieve sysOID value of this device */ if (nut_snmp_get_oid(SYSOID_OID, sysOID_buf, sizeof(sysOID_buf)) != TRUE) { upsdebugx(2, "Can't get sysOID value (using nut_snmp_get_oid())"); /* Fallback for non-compliant device, that returns a string and not an OID */ if (nut_snmp_get_str(SYSOID_OID, sysOID_buf, sizeof(sysOID_buf), NULL) != TRUE) { upsdebugx(2, "Can't get sysOID value (using nut_snmp_get_str())"); return NULL; } } upsdebugx(1, "%s: device sysOID value = %s", __func__, sysOID_buf); /* Build OIDs for comparison */ if (!read_objid(sysOID_buf, device_sysOID, &device_sysOID_len)) { upsdebugx(2, "%s: can't build device_sysOID %s: %s", __func__, sysOID_buf, snmp_api_errstring(snmp_errno)); return NULL; } /* Now, iterate on mib2nut definitions */ for (i = 0; mib2nut[i] != NULL; i++) { upsdebugx(1, "%s: checking MIB %s", __func__, mib2nut[i]->mib_name); if (mib2nut[i]->sysOID == NULL) continue; /* Clear variables */ memset(mib2nut_sysOID, 0, sizeof(mib2nut_sysOID)); mib2nut_sysOID_len = MAX_OID_LEN; if (!read_objid(mib2nut[i]->sysOID, mib2nut_sysOID, &mib2nut_sysOID_len)) { upsdebugx(2, "%s: can't build OID %s: %s", __func__, sysOID_buf, snmp_api_errstring(snmp_errno)); /* Try to continue anyway! */ continue; } /* Now compare these */ upsdebugx(1, "%s: comparing %s with %s", __func__, sysOID_buf, mib2nut[i]->sysOID); if (!netsnmp_oid_equals(device_sysOID, device_sysOID_len, mib2nut_sysOID, mib2nut_sysOID_len)) { upsdebugx(2, "%s: sysOID matches MIB '%s'!", __func__, mib2nut[i]->mib_name); /* Counter verify, using {ups,device}.model */ snmp_info = mib2nut[i]->snmp_info; if (snmp_info == NULL) { upsdebugx(0, "%s: WARNING: snmp_info is not initialized " "for mapping table entry #%d \"%s\"", __func__, i, mib2nut[i]->mib_name ); continue; } else if (snmp_info[0].info_type == NULL) { upsdebugx(1, "%s: WARNING: snmp_info is empty " "for mapping table entry #%d \"%s\"", __func__, i, mib2nut[i]->mib_name); } if (match_model_OID() != TRUE) { upsdebugx(2, "%s: testOID provided and doesn't match MIB '%s'!", __func__, mib2nut[i]->mib_name); snmp_info = NULL; continue; } else upsdebugx(2, "%s: testOID provided and matches MIB '%s'!", __func__, mib2nut[i]->mib_name); return mib2nut[i]; } } /* Yell all to call for user report */ upslogx(LOG_ERR, "No matching MIB found for sysOID '%s'!\n" \ "Please report it to NUT developers, with an 'upsc' output for your device.\n" \ "Going back to the classic MIB detection method.", sysOID_buf); return NULL; } /* Load the right snmp_info_t structure matching mib parameter */ bool_t load_mib2nut(const char *mib) { int i; mib2nut_info_t *m2n = NULL; /* Below we have many checks for "auto"; avoid redundant string walks: */ bool_t mibIsAuto = (0 == strcmp(mib, "auto")); bool_t mibSeen = FALSE; /* Did we see the MIB name while walking mib2nut[]? */ upsdebugx(1, "SNMP UPS driver: entering %s(%s) to detect " "proper MIB for device [%s] (host %s)", __func__, mib, upsname ? upsname : device_name, device_path /* the "port" from config section is hostname/IP for networked drivers */ ); /* First, try to match against sysOID, if no MIB was provided. * This should speed up init stage * (Note: sysOID points the device main MIB entry point) */ if (mibIsAuto) { upsdebugx(2, "%s: trying the new match_sysoid() method with %s", __func__, mib); /* Retry at most 3 times, to maximise chances */ for (i = 0; i < 3 ; i++) { upsdebugx(3, "%s: trying the new match_sysoid() method: attempt #%d", __func__, (i+1)); if ((m2n = match_sysoid()) != NULL) break; if (m2n == NULL) upsdebugx(3, "%s: failed with new match_sysoid() method", __func__); else upsdebugx(3, "%s: found something with new match_sysoid() method", __func__); } } /* Otherwise, revert to the classic method */ if (m2n == NULL) { for (i = 0; mib2nut[i] != NULL; i++) { /* Is there already a MIB name provided? */ upsdebugx(4, "%s: checking against mapping table entry #%d \"%s\"", __func__, i, mib2nut[i]->mib_name); if (!mibIsAuto && strcmp(mib, mib2nut[i]->mib_name)) { /* "mib" is neither "auto" nor the name in mapping table */ upsdebugx(2, "%s: skip the \"%s\" entry from " "the mapping table which is not \"%s\" " "(and which in turn is not \"auto\")", __func__, mib2nut[i]->mib_name, mib); continue; } upsdebugx(2, "%s: trying classic sysOID matching method with '%s' mib", __func__, mib2nut[i]->mib_name); /* Classic method: test an OID specific to this MIB */ snmp_info = mib2nut[i]->snmp_info; if (snmp_info == NULL) { upsdebugx(0, "%s: WARNING: snmp_info is not initialized " "for mapping table entry #%d \"%s\"", __func__, i, mib2nut[i]->mib_name ); continue; } else if (snmp_info[0].info_type == NULL) { upsdebugx(1, "%s: WARNING: snmp_info is empty " "for mapping table entry #%d \"%s\"", __func__, i, mib2nut[i]->mib_name); } /* Device might not support this MIB, but we want to * track that the name string is valid for diags below */ if (!mibIsAuto) { mibSeen = TRUE; } if (match_model_OID() != TRUE) { upsdebugx(3, "%s: testOID provided and doesn't match MIB '%s'!", __func__, mib2nut[i]->mib_name); snmp_info = NULL; continue; } else upsdebugx(3, "%s: testOID provided and matches MIB '%s'!", __func__, mib2nut[i]->mib_name); /* MIB found */ m2n = mib2nut[i]; break; } } /* Store the result, if any */ if (m2n != NULL) { snmp_info = m2n->snmp_info; OID_pwr_status = m2n->oid_pwr_status; mibname = m2n->mib_name; mibvers = m2n->mib_version; alarms_info = m2n->alarms_info; upsdebugx(1, "%s: using %s MIB for device [%s] (host %s)", __func__, mibname, upsname ? upsname : device_name, device_path); return TRUE; } /* Did we find something or is it really an unknown mib */ if (!mibIsAuto) { if (mibSeen) { fatalx(EXIT_FAILURE, "Requested 'mibs' value '%s' " "did not match this device [%s] (host %s)", mib, upsname ? upsname : device_name, device_path); } else { /* String not seen during mib2nut[] walk - * and if we had no hits, we walked it all */ fatalx(EXIT_FAILURE, "Unknown 'mibs' value " "which is neither \"auto\" nor a valid " "name in the mapping table: %s", mib); } } else { fatalx(EXIT_FAILURE, "No supported device detected at [%s] (host %s)", upsname ? upsname : device_name, device_path); } /* Should not get here thanks to fatalx() above, but need to silence a warning */ return FALSE; } /* find the OID value matching that INFO_* value * Return -1 and errno==EINVAL for unsupported inputs. */ long su_find_valinfo(info_lkp_t *oid2info, const char* value) { info_lkp_t *info_lkp; for (info_lkp = oid2info; (info_lkp != NULL) && (strcmp(info_lkp->info_value, "NULL")); info_lkp++) { if (!(strcmp(info_lkp->info_value, value))) { upsdebugx(1, "%s: found %s (value: %s)", __func__, info_lkp->info_value, value); errno = 0; return info_lkp->oid_value; } } upsdebugx(1, "%s: no matching INFO_* value for this OID value (%s)", __func__, value); errno = EINVAL; return -1; } /* String reformatting function. * Return NULL and errno==EINVAL for unsupported inputs. */ const char *su_find_strval(info_lkp_t *oid2info, void *value) { #if WITH_SNMP_LKP_FUN /* First test if we have a generic lookup function */ if ( (oid2info != NULL) && (oid2info->fun_vp2s != NULL) ) { const char *retvalue; upsdebugx(2, "%s: using generic lookup function (string reformatting)", __func__); errno = 0; retvalue = oid2info->fun_vp2s(value); upsdebugx(2, "%s: got value '%s'%s", __func__, retvalue, (errno == EINVAL ? ", invalid input" : "") ); return retvalue; } upsdebugx(1, "%s: no result value for this OID string value (%s)", __func__, (char*)value); #else NUT_UNUSED_VARIABLE(oid2info); upsdebugx(1, "%s: no mapping function for this OID string value (%s)", __func__, (char*)value); #endif /* WITH_SNMP_LKP_FUN */ errno = EINVAL; return NULL; } /* Find the INFO_* value matching that OID numeric (long) value. * Return NULL and errno==EINVAL for unsupported inputs. */ const char *su_find_infoval(info_lkp_t *oid2info, void *raw_value) { info_lkp_t *info_lkp; long value = *((long *)raw_value); #if WITH_SNMP_LKP_FUN /* First test if we have a generic lookup function */ if ( (oid2info != NULL) && (oid2info->fun_vp2s != NULL) ) { const char *retvalue; upsdebugx(2, "%s: using generic lookup function", __func__); errno = 0; retvalue = oid2info->fun_vp2s(raw_value); upsdebugx(2, "%s: got value '%s'%s", __func__, retvalue, (errno == EINVAL ? ", invalid input" : "") ); return retvalue; } #endif /* WITH_SNMP_LKP_FUN */ /* Otherwise, use the simple values mapping */ for (info_lkp = oid2info; (info_lkp != NULL) && (info_lkp->info_value != NULL) && (strcmp(info_lkp->info_value, "NULL")); info_lkp++) { if (info_lkp->oid_value == value) { upsdebugx(1, "%s: found %s (value: %ld)", __func__, info_lkp->info_value, value); errno = 0; return info_lkp->info_value; } } upsdebugx(1, "%s: no matching INFO_* value for this OID value (%ld)", __func__, value); errno = EINVAL; return NULL; } /* FIXME: doesn't work with templates! */ static void disable_competition(snmp_info_t *entry) { snmp_info_t *p; if (snmp_info == NULL) { fatalx(EXIT_FAILURE, "%s: snmp_info is not initialized", __func__); } if (snmp_info[0].info_type == NULL) { upsdebugx(1, "%s: WARNING: snmp_info is empty", __func__); } for(p = snmp_info; (p != NULL && p->info_type != NULL) ; p++) { if(p!=entry && !strcmp(p->info_type, entry->info_type)) { upsdebugx(2, "%s: disabling %s %s", __func__, p->info_type, p->OID); p->flags &= ~SU_FLAG_OK; } } } /* set shutdown and/or start delays */ void set_delays(void) { int ondelay, offdelay; char su_scratch_buf[255]; if (getval(SU_VAR_ONDELAY)) ondelay = atoi(getval(SU_VAR_ONDELAY)); else ondelay = -1; if (getval(SU_VAR_OFFDELAY)) offdelay = atoi(getval(SU_VAR_OFFDELAY)); else offdelay = -1; if (ondelay >= 0) { sprintf(su_scratch_buf, "%d", ondelay); su_setvar("ups.delay.start", su_scratch_buf); } if (offdelay >= 0) { sprintf(su_scratch_buf, "%d", offdelay); su_setvar("ups.delay.shutdown", su_scratch_buf); } } /*********************************************************************** * Template handling functions **********************************************************************/ /* Test if the template is a multiple one, i.e. with a formatting string that * contains multiple "%i". * Return TRUE if yes (multiple "%i" found), FALSE otherwise */ static bool_t is_multiple_template(const char *OID_template) { bool_t retCode = FALSE; char *format_char = NULL; if (OID_template) { format_char = strchr(OID_template, '%'); upsdebugx(4, "%s(%s)", __func__, OID_template); } else upsdebugx(4, "%s(NULL)", __func__); if (format_char != NULL) { if (strchr(format_char + 1, '%') != NULL) { retCode = TRUE; } } upsdebugx(4, "%s: has %smultiple template definition", __func__, (retCode == FALSE)?"not ":""); return retCode; } /* Instantiate an snmp_info_t from a template. * Useful for device, outlet, outlet.group and ambient templates. * Note: remember to adapt info_type, OID and optionaly dfl */ static snmp_info_t *instantiate_info(snmp_info_t *info_template, snmp_info_t *new_instance) { upsdebugx(1, "%s(%s)", __func__, info_template ? info_template->info_type : "n/a"); /* sanity check */ if (info_template == NULL) return NULL; if (new_instance == NULL) new_instance = (snmp_info_t *)xmalloc(sizeof(snmp_info_t)); /* TOTHINK: Should there be an "else" to free() * the fields which we (re-)allocate below? */ new_instance->info_type = (char *)xmalloc(SU_INFOSIZE); if (new_instance->info_type) memset((char *)new_instance->info_type, 0, SU_INFOSIZE); if (info_template->OID != NULL) { new_instance->OID = (char *)xmalloc(SU_INFOSIZE); if (new_instance->OID) memset((char *)new_instance->OID, 0, SU_INFOSIZE); } else { new_instance->OID = NULL; } new_instance->info_flags = info_template->info_flags; new_instance->info_len = info_template->info_len; /* FIXME: check if we need to adapt this one... */ new_instance->dfl = info_template->dfl; new_instance->flags = info_template->flags; new_instance->oid2info = info_template->oid2info; upsdebugx(2, "instantiate_info: template instantiated"); return new_instance; } /* Free a dynamically allocated snmp_info_t. * Useful for outlet and outlet.group templates */ static void free_info(snmp_info_t *su_info_p) { /* sanity check */ if (su_info_p == NULL) return; if (su_info_p->info_type != NULL) free ((char *)su_info_p->info_type); if (su_info_p->OID != NULL) free ((char *)su_info_p->OID); free (su_info_p); } /* return the base SNMP index (0 or 1) to start template iteration on * the MIB, based on a test using a template OID */ static int base_snmp_template_index(const snmp_info_t *su_info_p) { int base_index = -1; char test_OID[SU_INFOSIZE]; snmp_info_flags_t template_type; if (!su_info_p) return -1; template_type = get_template_type(su_info_p->info_type); upsdebugx(3, "%s: OID template = %s", __func__, (su_info_p->OID ? su_info_p->OID : "") ); /* Try to differentiate between template types which may have * different indexes ; and store it to not redo it again */ switch (template_type) { case SU_OUTLET: template_index_base = outlet_template_index_base; break; case SU_OUTLET_GROUP: template_index_base = outletgroup_template_index_base; break; case SU_DAISY: template_index_base = device_template_index_base; break; case SU_AMBIENT_TEMPLATE: template_index_base = ambient_template_index_base; break; default: /* we should never fall here! */ upsdebugx(3, "%s: unknown template type '%" PRI_SU_FLAGS "' for %s", __func__, template_type, su_info_p->info_type); } base_index = template_index_base; /* If no OID defined, now we can return the good index computed */ if (!su_info_p->OID) return base_index; if (template_index_base == -1) { /* not initialised yet */ for (base_index = 0 ; base_index < 2 ; base_index++) { /* Test if this template also includes daisychain, in which case * we just use the current device index */ if (is_multiple_template(su_info_p->OID) == TRUE) { if (su_info_p->flags & SU_TYPE_DAISY_1) { snprintf_dynamic(test_OID, sizeof(test_OID), su_info_p->OID, "%i%i", current_device_number + device_template_offset, base_index); } else { snprintf_dynamic(test_OID, sizeof(test_OID), su_info_p->OID, "%i%i", base_index, current_device_number + device_template_offset); } } else { snprintf_dynamic(test_OID, sizeof(test_OID), su_info_p->OID, "%i", base_index); } if (nut_snmp_get(test_OID) != NULL) { if (su_info_p->flags & SU_FLAG_ZEROINVALID) { long value; if ((nut_snmp_get_int(test_OID, &value)) && (value!=0)) { break; } } else if (su_info_p->flags & SU_FLAG_NAINVALID) { char value[SU_BUFSIZE]; if ((nut_snmp_get_str(test_OID, value, SU_BUFSIZE, NULL)) && (strncmp(value, "N/A", 3))) { break; } } else { break; } } } /* Only store if it's a template for outlets or outlets groups, * not for daisychain (which has different index) */ if (su_info_p->flags & SU_OUTLET) outlet_template_index_base = base_index; else if (su_info_p->flags & SU_OUTLET_GROUP) outletgroup_template_index_base = base_index; else if (su_info_p->flags & SU_AMBIENT_TEMPLATE) ambient_template_index_base = base_index; else device_template_index_base = base_index; } upsdebugx(3, "%s: template_index_base = %i", __func__, base_index); return base_index; } /* Try to determine the number of items (outlets, outlet groups, ...), * using a template definition. Walk through the template until we can't * get anymore values. I.e., if we can iterate up to 8 item, return 8 */ static int guesstimate_template_count(snmp_info_t *su_info_p) { int base_index = 0; char test_OID[SU_INFOSIZE]; int base_count; const char *OID_template = su_info_p->OID; upsdebugx(1, "%s(%s)", __func__, OID_template); /* Test if OID is indexed: safeguard for infinite loop */ if (strchr(OID_template, '%') == NULL) { upsdebugx(3, "Warning: non-indexed object, discarding (OID = %s)", OID_template); return 0; } /* Determine if OID index starts from 0 or 1? */ snprintf_dynamic(test_OID, sizeof(test_OID), OID_template, "%i", base_index); if (nut_snmp_get(test_OID) == NULL) { base_index++; } else { if (su_info_p->flags & SU_FLAG_ZEROINVALID) { long value; if ((nut_snmp_get_int(test_OID, &value)) && (value==0)) { base_index++; } } } /* Now, actually iterate */ for (base_count = 0 ; ; base_count++) { snprintf_dynamic(test_OID, sizeof(test_OID), OID_template, "%i", base_index + base_count); if (nut_snmp_get(test_OID) == NULL) break; } upsdebugx(3, "%s: %i", __func__, base_count); return base_count; } /* Process template definition, instantiate and get data or register * command * type: outlet, outlet.group, device */ static bool_t process_template(int mode, const char* type, snmp_info_t *su_info_p) { /* Default to TRUE, and leave to get_and_process_data() to set * to FALSE when actually getting data from devices, to avoid false * negative with server side data */ bool_t status = TRUE; int cur_template_number = 1; int cur_nut_index = 0; int template_count = 0; int base_snmp_index = 0; snmp_info_t cur_info_p; char template_count_var[SU_BUFSIZE * 2]; /* Needed *2 to fit a max size_t in snprintf() below, * even if that should never happen */ char tmp_buf[SU_INFOSIZE]; upsdebugx(1, "%s template definition found (%s)...", type, su_info_p->info_type); if ((strncmp(type, "device", 6)) && (devices_count > 1) && (current_device_number > 0)) { snprintf(template_count_var, sizeof(template_count_var), "device.%i.%s.count", current_device_number, type); } else { snprintf(template_count_var, sizeof(template_count_var), "%s.count", type); } if(dstate_getinfo(template_count_var) == NULL) { /* FIXME: should we disable it? * su_info_p->flags &= ~SU_FLAG_OK; * or rely on guesstimation? */ template_count = guesstimate_template_count(su_info_p); /* Publish the count estimation */ if (template_count > 0) { dstate_setinfo(template_count_var, "%i", template_count); } } else { template_count = atoi(dstate_getinfo(template_count_var)); } upsdebugx(1, "%i instances found...", template_count); /* Only instantiate templates if needed! */ if (template_count > 0) { /* general init of data using the template */ instantiate_info(su_info_p, &cur_info_p); base_snmp_index = base_snmp_template_index(su_info_p); for (cur_template_number = base_snmp_index ; cur_template_number < (template_count + base_snmp_index) ; cur_template_number++) { upsdebugx(1, "Processing instance %i/%i...", cur_template_number, template_count); /* Special processing for daisychain: * append 'device.x' to the NUT variable name, except for the * whole daisychain ("device.0") */ if (!strncmp(type, "device", 6)) { /* Device(s) 1-N (master + slave(s)) need to append 'device.x' */ if (current_device_number > 0) { char *ptr = NULL; /* Another special processing for daisychain * device collection needs special appending */ if (!strncmp(su_info_p->info_type, "device.", 7)) ptr = (char*)&su_info_p->info_type[7]; else ptr = (char*)su_info_p->info_type; snprintf((char*)cur_info_p.info_type, SU_INFOSIZE, "device.%i.%s", current_device_number, ptr); } else { /* Device 1 ("device.0", whole daisychain) needs no * special processing */ cur_nut_index = cur_template_number; snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, su_info_p->info_type, "%i", cur_nut_index); } } else if (!strncmp(type, "outlet", 6)) /* Outlet and outlet groups templates */ { /* Get the index of the current template instance */ cur_nut_index = cur_template_number; /* Special processing for daisychain */ if (daisychain_enabled == TRUE) { /* Device(s) 1-N (master + slave(s)) need to append 'device.x' */ if ((devices_count > 1) && (current_device_number > 0)) { memset(&tmp_buf[0], 0, SU_INFOSIZE); strcat(&tmp_buf[0], "device.%i."); strcat(&tmp_buf[0], su_info_p->info_type); upsdebugx(4, "FORMATTING STRING = %s", &tmp_buf[0]); snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, &tmp_buf[0], "%i%i", current_device_number, cur_nut_index); } else { /* FIXME: daisychain-whole, what to do? */ snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, su_info_p->info_type, "%i", cur_nut_index); } } else { snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, su_info_p->info_type, "%i", cur_nut_index); } } else if (!strncmp(type, "ambient", 7)) { /* FIXME: can be grouped with outlet* above */ /* Get the index of the current template instance */ cur_nut_index = cur_template_number; /* Special processing for daisychain */ if (daisychain_enabled == TRUE) { /* Only publish on the daisychain host */ if ( (su_info_p->flags & SU_TYPE_DAISY_MASTER_ONLY) && (current_device_number != 1) ) { upsdebugx(2, "discarding variable due to daisychain master flag"); continue; } /* Device(s) 1-N (master + slave(s)) need to append 'device.x' */ if ((devices_count > 1) && (current_device_number > 0)) { memset(&tmp_buf[0], 0, SU_INFOSIZE); strcat(&tmp_buf[0], "device.%i."); strcat(&tmp_buf[0], su_info_p->info_type); upsdebugx(4, "FORMATTING STRING = %s", &tmp_buf[0]); snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, &tmp_buf[0], "%i%i", current_device_number, cur_nut_index); } else { /* FIXME: daisychain-whole, what to do? */ snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, su_info_p->info_type, "%i", cur_nut_index); } } else { snprintf_dynamic((char*)cur_info_p.info_type, SU_INFOSIZE, su_info_p->info_type, "%i", cur_nut_index); } } else upsdebugx(4, "Error: unknown template type '%s", type); /* check if default value is also a template */ if ((cur_info_p.dfl != NULL) && (strstr(su_info_p->dfl, "%i") != NULL)) { cur_info_p.dfl = (char *)xmalloc(SU_INFOSIZE); snprintf_dynamic((char *)cur_info_p.dfl, SU_INFOSIZE, su_info_p->dfl, "%i", cur_nut_index); } if (cur_info_p.OID != NULL) { /* Special processing for daisychain */ if (!strncmp(type, "device", 6)) { if (current_device_number > 0) { snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, "%i", current_device_number + device_template_offset); } /*else * FIXME: daisychain-whole, what to do? */ } else { /* Special processing for daisychain: * these outlet | outlet groups also include formatting info, * so we have to check if the daisychain is enabled, and if * the formatting info for it are in 1rst or 2nd position */ if (daisychain_enabled == TRUE) { if (su_info_p->flags & SU_TYPE_DAISY_1) { snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, "%i%i", current_device_number + device_template_offset, cur_template_number); } else if (su_info_p->flags & SU_TYPE_DAISY_2) { snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, "%i%i", cur_template_number + device_template_offset, current_device_number - device_template_offset); } else { /* Note: no device daisychain templating (SU_TYPE_DAISY_MASTER_ONLY)! */ snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, "%i", cur_template_number); } } else { snprintf_dynamic((char *)cur_info_p.OID, SU_INFOSIZE, su_info_p->OID, "%i", cur_template_number); } } /* add instant commands to the info database. */ if (SU_TYPE(su_info_p) == SU_TYPE_CMD) { upsdebugx(1, "Adding template command %s", cur_info_p.info_type); /* FIXME: only add if "su_ups_get(cur_info_p) == TRUE" */ if (mode == SU_WALKMODE_INIT) dstate_addcmd(cur_info_p.info_type); } else /* get and process this data */ status = get_and_process_data(mode, &cur_info_p); } else { /* server side (ABSENT) data */ su_setinfo(&cur_info_p, NULL); } /* set back the flag */ su_info_p->flags = cur_info_p.flags; } free((char*)cur_info_p.info_type); if (cur_info_p.OID != NULL) free((char*)cur_info_p.OID); if ((cur_info_p.dfl != NULL) && (strstr(su_info_p->dfl, "%i") != NULL)) free((char*)cur_info_p.dfl); } else { upsdebugx(1, "No %s present, discarding template definition...", type); } return status; } /* Return the type of template, according to a variable name. * Return: SU_OUTLET_GROUP, SU_OUTLET or 0 if not a template */ snmp_info_flags_t get_template_type(const char* varname) { if (!strncmp(varname, "outlet.group", 12)) { upsdebugx(4, "outlet.group template"); return SU_OUTLET_GROUP; } else if (!strncmp(varname, "outlet", 6)) { upsdebugx(4, "outlet template"); return SU_OUTLET; } else if (!strncmp(varname, "device", 6)) { upsdebugx(4, "device template"); return SU_DAISY; } else if (!strncmp(varname, "ambient", 7)) { upsdebugx(4, "ambient template"); return SU_AMBIENT_TEMPLATE; } else { upsdebugx(2, "Unknown template type: %s", varname); return 0; } } /* Extract the id number of an instantiated template. * Example: return '1' for type = 'outlet.1.desc', -1 if unknown */ int extract_template_number(snmp_info_flags_t template_type, const char* varname) { const char* item_number_ptr = NULL; int item_number = -1; if (template_type & SU_OUTLET_GROUP) item_number_ptr = &varname[12]; else if (template_type & SU_OUTLET) item_number_ptr = &varname[6]; else if (template_type & SU_DAISY) item_number_ptr = &varname[6]; else if (template_type & SU_AMBIENT_TEMPLATE) item_number_ptr = &varname[7]; else return -1; item_number = atoi(++item_number_ptr); upsdebugx(3, "%s: item %i", __func__, item_number); return item_number; } /* Extract the id number of a template from a variable name. * Example: return '1' for type = 'outlet.1.desc' */ static int extract_template_number_from_snmp_info_t(const char* varname) { return extract_template_number(get_template_type(varname), varname); } /* end of template functions */ /* process a single data from a walk */ bool_t get_and_process_data(int mode, snmp_info_t *su_info_p) { bool_t status = FALSE; upsdebugx(1, "%s: %s (%s)", __func__, su_info_p->info_type, su_info_p->OID); /* ok, update this element. */ status = su_ups_get(su_info_p); upsdebugx(4, "%s: su_ups_get returned %d", __func__, status); /* set stale flag if data is stale, clear if not. */ if (status == TRUE) { if (su_info_p->flags & SU_FLAG_STALE) { upslogx(LOG_INFO, "[%s] %s: data resumed for %s", upsname?upsname:device_name, __func__, su_info_p->info_type); su_info_p->flags &= ~SU_FLAG_STALE; } if(su_info_p->flags & SU_FLAG_UNIQUE) { /* We should be the only provider of this */ upsdebugx(4, "%s: unique flag", __func__); disable_competition(su_info_p); su_info_p->flags &= ~SU_FLAG_UNIQUE; } dstate_dataok(); } else { if (mode == SU_WALKMODE_INIT) { /* handle unsupported vars */ upsdebugx(4, "%s: Disabling var '%s'", __func__, su_info_p->info_type); su_info_p->flags &= ~SU_FLAG_OK; } else { if (!(su_info_p->flags & SU_FLAG_STALE)) { upslogx(LOG_INFO, "[%s] snmp_ups_walk: data stale for %s", upsname?upsname:device_name, su_info_p->info_type); su_info_p->flags |= SU_FLAG_STALE; } dstate_datastale(); } } return status; } /*********************************************************************** * Daisychain handling functions **********************************************************************/ /*! * Daisychained devices support init: * Determine the number of device(s) and if daisychain support has to be enabled * Set the values of devices_count (internal) and "device.count" (public) * Return TRUE if daisychain support is enabled, FALSE otherwise */ bool_t daisychain_init(void) { snmp_info_t *su_info_p = NULL; upsdebugx(1, "Checking if daisychain support has to be enabled"); su_info_p = su_find_info("device.count"); if (su_info_p != NULL) { upsdebugx(1, "Found device.count entry..."); /* Enable daisychain if there is a device.count entry. * This means that will have templates for entries */ daisychain_enabled = TRUE; /* Try to get the OID value, if it's not a template */ upsdebugx(3, "OID for device.count is %s", su_info_p->OID ? su_info_p->OID : ""); if ((su_info_p->OID != NULL) && (strstr(su_info_p->OID, "%i") == NULL)) { #if WITH_SNMP_LKP_FUN devices_count = -1; errno = 0; /* First test if we have a generic lookup function * FIXME: Check if the field type is a string? */ /* TODO: backport the 2x2 mapping function support * and this would be "fun_s2l" in resulting codebase */ if ( (su_info_p->oid2info != NULL) && (su_info_p->oid2info->nuf_s2l != NULL) ) { char buf[1024]; upsdebugx(2, "%s: using generic string-to-long lookup function", __func__); if (TRUE == nut_snmp_get_str(su_info_p->OID, buf, sizeof(buf), su_info_p->oid2info)) { devices_count = su_info_p->oid2info->nuf_s2l(buf); upsdebugx(2, "%s: got value '%ld'%s", __func__, devices_count, (errno == EINVAL ? ", invalid input" : "") ); } } if (devices_count == -1 || errno == EINVAL) { #endif /* WITH_SNMP_LKP_FUN */ if (nut_snmp_get_int(su_info_p->OID, &devices_count) == TRUE) { upsdebugx(1, "There are %ld device(s) present", devices_count); } else { upsdebugx(1, "Error: can't get the number of device(s) present!"); upsdebugx(1, "Falling back to 1 device!"); devices_count = 1; } #if WITH_SNMP_LKP_FUN } #endif /* WITH_SNMP_LKP_FUN */ } /* Otherwise (template), use the guesstimation function to get * the number of devices present */ else { devices_count = guesstimate_template_count(su_info_p); upsdebugx(1, "Guesstimation: there are %ld device(s) present", devices_count); } /* Sanity check before data publication */ if (devices_count < 1) { devices_count = 1; daisychain_enabled = FALSE; upsdebugx(1, "Devices count is less than 1!"); upsdebugx(1, "Falling back to 1 device and disabling daisychain support!"); } else { /* Publish the device(s) count - even if just one * device was recognized at this moment */ dstate_setinfo("device.count", "%ld", devices_count); /* Also publish the default value for mfr and a forged model * for device.0 (whole daisychain) */ su_info_p = su_find_info("device.mfr"); if (su_info_p != NULL) { su_info_p = su_find_info("ups.mfr"); if (su_info_p != NULL) { su_setinfo(su_info_p, NULL); } } /* Forge model using device.type and number */ su_info_p = su_find_info("device.type"); if ((su_info_p != NULL) && (su_info_p->dfl != NULL)) { dstate_setinfo("device.model", "daisychain %s (1+%ld)", su_info_p->dfl, devices_count - 1); dstate_setinfo("device.type", "%s", su_info_p->dfl); } else { dstate_setinfo("device.model", "daisychain (1+%ld)", devices_count - 1); } } } else { daisychain_enabled = FALSE; upsdebugx(1, "No device.count entry found, daisychain support not needed"); } /* Finally, compute and store the base OID index and NUT offset */ su_info_p = su_find_info("device.model"); if (su_info_p != NULL) { device_template_index_base = base_snmp_template_index(su_info_p); upsdebugx(1, "%s: device_template_index_base = %i", __func__, device_template_index_base); device_template_offset = device_template_index_base - 1; upsdebugx(1, "%s: device_template_offset = %i", __func__, device_template_offset); } else { upsdebugx(1, "%s: No device.model entry found.", __func__); } upsdebugx(1, "%s: daisychain support is %s", __func__, (daisychain_enabled==TRUE)?"enabled":"disabled"); return daisychain_enabled; } /*********************************************************************** * SNMP handling functions **********************************************************************/ /* Process a data with regard to SU_OUTPHASES, SU_INPHASES and SU_BYPPHASES. * 3phases related data are disabled if the unit is 1ph, and conversely. * If the related phases data (input, output, bypass) is not yet valued, * retrieve it first. * * type: input, output, bypass * su_info_p: variable to process flags on * Return 0 if OK, 1 if the caller needs to "continue" the walk loop (i.e. * skip the present data) */ static int process_phase_data(const char* type, long *nb_phases, snmp_info_t *su_info_p) { snmp_info_t *tmp_info_p; char tmpOID[SU_INFOSIZE]; char tmpInfo[SU_INFOSIZE]; long tmpValue; snmp_info_flags_t phases_flag = 0, single_phase_flag = 0, three_phase_flag = 0; /* Phase specific data */ if (!strncmp(type, "input", 5)) { phases_flag = SU_INPHASES; single_phase_flag = SU_INPUT_1; three_phase_flag = SU_INPUT_3; } else if (!strncmp(type, "output", 6)) { phases_flag = SU_OUTPHASES; single_phase_flag = SU_OUTPUT_1; three_phase_flag = SU_OUTPUT_3; } else if (!strncmp(type, "input.bypass", 12)) { phases_flag = SU_BYPPHASES; single_phase_flag = SU_BYPASS_1; three_phase_flag = SU_BYPASS_3; } else { upsdebugx(2, "%s: unknown type '%s'", __func__, type); return 1; } /* Init the phase(s) info for this device, if not already done */ if (*nb_phases == -1) { upsdebugx(2, "%s phases information not initialized for device %i", type, current_device_number); memset(tmpInfo, 0, SU_INFOSIZE); /* daisychain specifics... */ if ( (daisychain_enabled == TRUE) && (current_device_number > 0) ) { /* Device(s) 2-N (slave(s)) need to append 'device.x' */ snprintf(tmpInfo, SU_INFOSIZE, "device.%i.%s.phases", current_device_number, type); } else { snprintf(tmpInfo, SU_INFOSIZE, "%s.phases", type); } if (dstate_getinfo(tmpInfo) == NULL) { /* {input,output,bypass}.phases is not yet published, * try to get the template for it */ snprintf(tmpInfo, SU_INFOSIZE, "%s.phases", type); tmp_info_p = su_find_info(tmpInfo); if (tmp_info_p != NULL) { memset(tmpOID, 0, SU_INFOSIZE); /* Daisychain specific: we may have a template (including * formatting string) that needs to be adapted! */ if (strchr(tmp_info_p->OID, '%') != NULL) { upsdebugx(2, "Found template, need to be adapted"); snprintf_dynamic((char*)tmpOID, SU_INFOSIZE, tmp_info_p->OID, "%i", current_device_number + device_template_offset); } else { /* Otherwise, just point at what we found */ upsdebugx(2, "Found entry, not a template %s", tmp_info_p->OID); snprintf((char*)tmpOID, SU_INFOSIZE, "%s", tmp_info_p->OID); } /* Actually get the data */ if (nut_snmp_get_int(tmpOID, &tmpValue) == TRUE) { *nb_phases = tmpValue; } else { upsdebugx(2, "Can't get %s value. Defaulting to 1 %s.phase", tmpInfo, type); *nb_phases = 1; /* FIXME: return something or process using default?! */ } } else { upsdebugx(2, "No %s entry. Defaulting to 1 %s.phase", tmpInfo, type); *nb_phases = 1; /* FIXME: return something or process using default?! */ } } else { *nb_phases = atoi(dstate_getinfo(tmpInfo)); } /* Publish the number of phase(s) */ dstate_setinfo(tmpInfo, "%ld", *nb_phases); upsdebugx(2, "device %i has %ld %s.phases", current_device_number, *nb_phases, type); } /* FIXME: what to do here? else if (*nb_phases == 0) { return 1; } */ /* Actual processing of phases related data */ /* FIXME: don't clear SU_INPHASES in daisychain mode!!! ??? */ if (su_info_p->flags & single_phase_flag) { if (*nb_phases == 1) { upsdebugx(1, "%s_phases is 1", type); su_info_p->flags &= ~phases_flag; } else { upsdebugx(1, "%s_phases is not 1", type); su_info_p->flags &= ~SU_FLAG_OK; return 1; } } else if (su_info_p->flags & three_phase_flag) { if (*nb_phases == 3) { upsdebugx(1, "%s_phases is 3", type); su_info_p->flags &= ~phases_flag; } else { upsdebugx(1, "%s_phases is not 3", type); su_info_p->flags &= ~SU_FLAG_OK; return 1; } } else { upsdebugx(1, "%s_phases is %ld", type, *nb_phases); } return 0; /* FIXME: remap EXIT_SUCCESS to RETURN_SUCCESS */ } /* walk ups variables and set elements of the info array. */ bool_t snmp_ups_walk(int mode) { long *walked_input_phases, *walked_output_phases, *walked_bypass_phases; #ifdef COUNT_ITERATIONS /* Experimental workaround for stale info */ static unsigned long iterations = 0; #endif snmp_info_t *su_info_p; bool_t status = FALSE; if (mode == SU_WALKMODE_UPDATE) { semistatic_countdown--; if (semistatic_countdown < 0) semistatic_countdown = semistaticfreq; } /* Loop through all device(s) */ /* Note: considering "unitary" and "daisy-chained" devices, we have * several variables (and their values) that can come into play: * devices_count == 1 (default) AND daisychain_enabled == FALSE => unitary * devices_count > 1 (AND/OR?) daisychain_enabled == TRUE => a daisy-chain * The current_device_number == 0 in context of daisy-chain means the * "whole device" with composite or summary values that refer to the * chain as a virtual power device (e.g. might be a sum of outlet counts). * If daisychain_enabled == TRUE and current_device_number == 1 then we * are looking at the "master" device (one that we have direct/networked * connectivity to; the current_device_number > 1 is a slave (chained by * some proprietary link not visible from the outside) and represented * through the master - the slaves are not addressable directly. If the * master dies/reboots, connection to the whole chain is interrupted. * The dstate string names for daisychained sub-devices have the prefix * "device." and number embedded (e.g. "device.3.input.phases") except * for the whole (#0) virtual device, so it *seems* similar to unitary. */ for (current_device_number = (daisychain_enabled == FALSE && devices_count == 1 ? 1 : 0) ; current_device_number <= devices_count; current_device_number++) { upsdebugx(1, "%s: walking device %d", __func__, current_device_number); /* reinit the alarm buffer, before */ if (devices_count > 1) device_alarm_init(); /* better safe than sorry, check sanity on every loop cycle */ if (snmp_info == NULL) { fatalx(EXIT_FAILURE, "%s: snmp_info is not initialized", __func__); } if (snmp_info[0].info_type == NULL) { upsdebugx(1, "%s: WARNING: snmp_info is empty", __func__); } /* Loop through all mapping entries for the current_device_number */ for (su_info_p = &snmp_info[0]; (su_info_p != NULL && su_info_p->info_type != NULL) ; su_info_p++) { /* NOTE: Effectively below we do this: * switch(current_device_number) { * case 0: devtype = "daisychain whole" * case 1: devtype = "daisychain master" * default: devtype = "daisychain slave" * } * with a consideration for directly-addressable * slave devices (can be seen in chain via master, * but also queryable alone with an IP connection) * NOTE: until proven otherwise, "single" may mean * both (either) a daisy-chain enabled master device * without further connected "slave" devices, and * a directly addressable (IP-connected) "slave". * Possibly also an ePDU etc. that serves a MIB * which resolves "device.count" with the selected * subdriver. */ if (daisychain_enabled == TRUE) { upsdebugx(1, "%s: processing daisy-chain device %i (%s)", __func__, current_device_number, (current_device_number == 1) ? (devices_count > 1 ? "master" : "single") : (current_device_number > 1 ? "slave" : "whole") ); } else { upsdebugx(1, "%s: processing unitary device (%i)", __func__, current_device_number); } /* Check if we are asked to stop (reactivity++) */ if (exit_flag != 0) { upsdebugx(1, "%s: aborting because exit_flag was set", __func__); return TRUE; } /* Skip daisychain data count */ if (mode == SU_WALKMODE_INIT && (!strncmp(su_info_p->info_type, "device.count", 12))) { su_info_p->flags &= ~SU_FLAG_OK; continue; } /* FIXME: daisychain-whole, what to do? */ /* Note that when addressing the FIXME above, * if (current_device_number == 0 && daisychain_enabled == FALSE) * then we'd skip it still (unitary device is at current_device_number == 1)... */ /* skip the whole-daisychain for now */ if (current_device_number == 0 && daisychain_enabled == TRUE) { upsdebugx(1, "Skipping daisychain device.0 for now..."); continue; } /* skip instcmd, not linked to outlets */ if ((SU_TYPE(su_info_p) == SU_TYPE_CMD) && !(su_info_p->flags & SU_OUTLET) && !(su_info_p->flags & SU_OUTLET_GROUP)) { upsdebugx(1, "SU_CMD_MASK => %s", su_info_p->OID); continue; } /* skip elements we shouldn't show in update mode */ if ((mode == SU_WALKMODE_UPDATE) && !(su_info_p->flags & SU_FLAG_OK)) continue; /* skip semi-static elements in update mode: only parse when countdown reaches 0 */ if ((mode == SU_WALKMODE_UPDATE) && (su_info_p->flags & SU_FLAG_SEMI_STATIC)) { if (semistatic_countdown != 0) continue; upsdebugx(1, "Refreshing semi-static entry %s", su_info_p->OID); } /* skip static elements in update mode */ if ((mode == SU_WALKMODE_UPDATE) && (su_info_p->flags & SU_FLAG_STATIC)) { upsdebugx(1, "Skipping static entry %s", su_info_p->OID); continue; } /* Set default value if we cannot fetch it */ /* and set static flag on this element. * Not applicable to outlets (need SU_FLAG_STATIC tagging) */ if ( (su_info_p->flags & SU_FLAG_ABSENT) && !(su_info_p->flags & SU_OUTLET) && !(su_info_p->flags & SU_OUTLET_GROUP) && !(su_info_p->flags & SU_AMBIENT_TEMPLATE)) { if (mode == SU_WALKMODE_INIT) { if (su_info_p->dfl) { if ((daisychain_enabled == TRUE) && (devices_count > 1)) { if (current_device_number == 0) { su_setinfo(su_info_p, NULL); /* FIXME: daisychain-whole, what to do? */ } else { status = process_template(mode, "device", su_info_p); } } else { /* Set default value if we cannot fetch it from ups. */ su_setinfo(su_info_p, NULL); } upsdebugx(1, "Defaulting absent entry and setting to static: %s", su_info_p->OID); } else { upsdebugx(1, "Setting absent entry to static (no defautl provided): %s", su_info_p->OID); } su_info_p->flags |= SU_FLAG_STATIC; } continue; } #ifdef COUNT_ITERATIONS /* check stale elements only on each PN_STALE_RETRY iteration. */ if ((su_info_p->flags & SU_FLAG_STALE) && (iterations % SU_STALE_RETRY) != 0) continue; #endif /* Filter 1-phase Vs 3-phase according to {input,output,bypass}.phase. * Non matching items are disabled, and flags are cleared at init * time */ /* Process input phases information */ walked_input_phases = &daisychain_info[current_device_number]->input_phases; if (su_info_p->flags & SU_INPHASES) { upsdebugx(1, "Check input_phases (%ld)", *walked_input_phases); if (process_phase_data("input", walked_input_phases, su_info_p) == 1) continue; } /* Process output phases information */ walked_output_phases = &daisychain_info[current_device_number]->output_phases; if (su_info_p->flags & SU_OUTPHASES) { upsdebugx(1, "Check output_phases (%ld)", *walked_output_phases); if (process_phase_data("output", walked_output_phases, su_info_p) == 1) continue; } /* Process bypass phases information */ walked_bypass_phases = &daisychain_info[current_device_number]->bypass_phases; if (su_info_p->flags & SU_BYPPHASES) { upsdebugx(1, "Check bypass_phases (%ld)", *walked_bypass_phases); if (process_phase_data("input.bypass", walked_bypass_phases, su_info_p) == 1) continue; } /* process template (outlet, outlet group, inc. daisychain) definition */ if (su_info_p->flags & SU_OUTLET) { /* Skip commands after init */ if ((SU_TYPE(su_info_p) == SU_TYPE_CMD) && (mode == SU_WALKMODE_UPDATE)) continue; else status = process_template(mode, "outlet", su_info_p); } else if (su_info_p->flags & SU_OUTLET_GROUP) { /* Skip commands after init */ if ((SU_TYPE(su_info_p) == SU_TYPE_CMD) && (mode == SU_WALKMODE_UPDATE)) continue; else status = process_template(mode, "outlet.group", su_info_p); } else if (su_info_p->flags & SU_AMBIENT_TEMPLATE) { /* Skip commands after init */ if ((SU_TYPE(su_info_p) == SU_TYPE_CMD) && (mode == SU_WALKMODE_UPDATE)) continue; else status = process_template(mode, "ambient", su_info_p); } else { /* if (daisychain_enabled == TRUE) { status = process_template(mode, "device", su_info_p); } else { */ /* get and process this data, including daisychain adaptation */ status = get_and_process_data(mode, su_info_p); /* } */ } } /* for (su_info_p... */ if (devices_count > 1) { /* commit the device alarm buffer */ device_alarm_commit(current_device_number); /* reinit the alarm buffer, after, not to pollute "device.0" */ device_alarm_init(); } } #ifdef COUNT_ITERATIONS iterations++; #endif return status; } bool_t su_ups_get(snmp_info_t *su_info_p) { static char buf[SU_INFOSIZE]; bool_t status; long value; double dvalue; const char *strValue = NULL; struct snmp_pdu ** pdu_array; struct snmp_pdu * current_pdu; alarms_info_t * alarms; int index = 0; char *format_char = NULL; int saved_current_device_number = -1; snmp_info_t *tmp_info_p = NULL; upsdebugx(2, "%s: %s %s", __func__, su_info_p->info_type, su_info_p->OID); /* Check if this is a daisychain template */ if (su_info_p->OID != NULL && (format_char = strchr(su_info_p->OID, '%')) != NULL ) { upsdebugx(3, "%s: calling instantiate_info() for " "daisy-chain template", __func__); tmp_info_p = instantiate_info(su_info_p, tmp_info_p); if (tmp_info_p != NULL) { upsdebugx(3, "%s: instantiate_info() returned " "non-null OID: %s", __func__, tmp_info_p->OID); /* adapt the OID */ if (su_info_p->OID != NULL) { snprintf_dynamic((char *)tmp_info_p->OID, SU_INFOSIZE, su_info_p->OID, "%i", current_device_number + device_template_offset); upsdebugx(3, "%s: OID %s adapted into %s", __func__, su_info_p->OID, tmp_info_p->OID); } else { free_info(tmp_info_p); return FALSE; } /* adapt info_type */ if (su_info_p->info_type != NULL) { snprintf((char *)tmp_info_p->info_type, SU_INFOSIZE, "%s", su_info_p->info_type); } else { free_info(tmp_info_p); return FALSE; } su_info_p = tmp_info_p; } else { upsdebugx(2, "%s: can't instantiate template", __func__); return FALSE; } } else { /* Non-templated OID, still may be aimed at a * daisy-chained device (master of the chain * makes sense for IETF device.contact etc.). * BUT: It could be a direct request for earlier * resolved OID. So check for "device.N." too. */ if (daisychain_enabled == TRUE && devices_count > 1 && current_device_number > 0 ) { /* So we had a literal OID string, originally * Check for "device.N." in the string: */ char * varname = su_info_p->info_type; if (!strncmp(varname, "device.", 7) && (varname[7] >= '0' && varname[7] <= '9') ) { upsdebugx(2, "%s: keeping original " "current device == %d for " "non-templated daisy value", __func__, current_device_number); } else { upsdebugx(2, "%s: would fake " "current device == 1 for " "non-templated daisy value " "instead of %d", __func__, current_device_number); saved_current_device_number = current_device_number; } /* At this point we applied no hacks yet, * just stashed a non-negative value into * saved_current_device_number */ } } if (!strcasecmp(su_info_p->info_type, "ups.status")) { /* FIXME: daisychain status support! */ upsdebugx(2, "%s: requesting nut_snmp_get_int() for " "ups.status, with%s daisy template originally", __func__, (format_char!=NULL ? "" : "out")); status = nut_snmp_get_int(su_info_p->OID, &value); if (status == TRUE) { su_status_set(su_info_p, value); upsdebugx(2, "=> value: %ld", value); } else upsdebugx(2, "=> Failed"); free_info(tmp_info_p); return status; } /* Handle 'ups.alarm', 'outlet.n.alarm' and 3phase 'Lx.alarm', * nothing else! */ if (!strcmp(strrchr(su_info_p->info_type, '.'), ".alarm")) { upsdebugx(2, "Processing alarm: %s", su_info_p->info_type); /* FIXME: daisychain alarms support! */ upsdebugx(2, "%s: requesting nut_snmp_get_int() for " "some alarm, with%s daisy template originally", __func__, (format_char!=NULL ? "" : "out")); status = nut_snmp_get_int(su_info_p->OID, &value); if (status == TRUE) { su_alarm_set(su_info_p, value); upsdebugx(2, "=> value: %ld", value); } else upsdebugx(2, "=> Failed"); free_info(tmp_info_p); return status; } /* Walk a subtree (array) of alarms, composed of OID references. * The object referenced should not be accessible, but rather when * present, this means that the alarm condition is TRUE. * Only present in powerware-mib.c for now */ if (!strcasecmp(su_info_p->info_type, "ups.alarms")) { upsdebugx(2, "%s: requesting nut_snmp_get_int() for " "ups.alarms, with%s daisy template originally", __func__, (format_char!=NULL ? "" : "out")); status = nut_snmp_get_int(su_info_p->OID, &value); if (status == TRUE) { upsdebugx(2, "=> %ld alarms present", value); if (value > 0) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if (value > INT_MAX) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif upsdebugx(2, "=> truncating alarms present to INT_MAX"); value = INT_MAX; } pdu_array = nut_snmp_walk(su_info_p->OID, (int)value); if(pdu_array == NULL) { upsdebugx(2, "=> Walk failed"); return FALSE; } current_pdu = pdu_array[index]; while(current_pdu) { /* Retrieve the OID name, for comparison */ if (decode_oid(current_pdu, buf, sizeof(buf)) == TRUE) { alarms = alarms_info; while( alarms->OID ) { if(!strcmp(buf, alarms->OID)) { upsdebugx(3, "Alarm OID found => %s", alarms->OID); /* Check for ups.status value */ if (alarms->status_value) { upsdebugx(3, "Alarm value (status) found => %s", alarms->status_value); status_set(alarms->status_value); } /* Check for ups.alarm value */ if (alarms->alarm_value) { upsdebugx(3, "Alarm value (alarm) found => %s", alarms->alarm_value); alarm_set(alarms->alarm_value); } break; } alarms++; } } index++; current_pdu = pdu_array[index]; } nut_snmp_free(pdu_array); } } else { upsdebugx(2, "=> Failed"); } free_info(tmp_info_p); return status; } /* another special case */ if (!strcasecmp(su_info_p->info_type, "ambient.temperature")) { float temp=0; upsdebugx(2, "%s: requesting nut_snmp_get_int() for " "ambient.temperature, with%s daisy template originally", __func__, (format_char!=NULL ? "" : "out")); status = nut_snmp_get_int(su_info_p->OID, &value); if(status != TRUE) { free_info(tmp_info_p); return status; } /* only do this if using the IEM sensor */ if (!strcmp(su_info_p->OID, APCC_OID_IEM_TEMP)) { int su; long units; su = nut_snmp_get_int(APCC_OID_IEM_TEMP_UNIT, &units); /* no response, or units == F */ if ((su == FALSE) || (units == APCC_IEM_FAHRENHEIT)) temp = (value - 32) / 1.8; else temp = value; } else { temp = value * su_info_p->info_len; } snprintf(buf, sizeof(buf), "%.1f", temp); su_setinfo(su_info_p, buf); free_info(tmp_info_p); return TRUE; } /* special treatment for element without oid but with default value */ if (su_info_p->OID == NULL && su_info_p->dfl != NULL) { status = TRUE; /* FIXME: strlcpy() would fit here safer; not used in NUT yet */ strncpy(buf, su_info_p->dfl, sizeof(buf) - 1); buf[sizeof(buf) - 1] = '\0'; } else if (su_info_p->info_flags & ST_FLAG_STRING) { upsdebugx(2, "%s: requesting nut_snmp_get_str(), " "with%s daisy template originally", __func__, (format_char!=NULL ? "" : "out")); status = nut_snmp_get_str(su_info_p->OID, buf, sizeof(buf), su_info_p->oid2info); if (status == TRUE) { const char *fmt_buf; if (quirk_symmetra_threephase) { if (!strcasecmp(su_info_p->info_type, "input.transfer.low") || !strcasecmp(su_info_p->info_type, "input.transfer.high")) { /* Convert from three phase line-to-line voltage to line-to-neutral voltage */ double tmp_dvalue = atof(buf); tmp_dvalue = tmp_dvalue * 0.707; snprintf(buf, sizeof(buf), "%.2f", tmp_dvalue); } } /* Check if there is a string reformatting function */ fmt_buf = NULL; if ((fmt_buf = su_find_strval(su_info_p->oid2info, buf)) != NULL) { snprintf(buf, sizeof(buf), "%s", fmt_buf); } } } else { upsdebugx(2, "%s: requesting nut_snmp_get_int(), " "with%s daisy template originally", __func__, (format_char!=NULL ? "" : "out")); status = nut_snmp_get_int(su_info_p->OID, &value); if (status == TRUE) { if ((su_info_p->flags&SU_FLAG_NEGINVALID && value<0) || (su_info_p->flags&SU_FLAG_ZEROINVALID && value==0)) { su_info_p->flags &= ~SU_FLAG_OK; if(su_info_p->flags&SU_FLAG_UNIQUE) { disable_competition(su_info_p); su_info_p->flags &= ~SU_FLAG_UNIQUE; } free_info(tmp_info_p); return FALSE; } /* Check if there is a value to be looked up */ if ((strValue = su_find_infoval(su_info_p->oid2info, &value)) != NULL) snprintf(buf, sizeof(buf), "%s", strValue); else { /* Check if there is a need to publish decimal too, * i.e. if switching to integer does not cause a * loss of precision. * FIXME: Use remainder? is (dvalue%1.0)>0 cleaner? */ dvalue = value * su_info_p->info_len; if (f_equal((int)dvalue, dvalue)) snprintf(buf, sizeof(buf), "%i", (int)dvalue); else snprintf(buf, sizeof(buf), "%.2f", (float)dvalue); } } } if (status == TRUE) { if (saved_current_device_number >= 0) { current_device_number = 1; } su_setinfo(su_info_p, buf); if (saved_current_device_number >= 0) { current_device_number = saved_current_device_number; } upsdebugx(2, "=> value: %s", buf); } else { upsdebugx(2, "=> Failed"); } free_info(tmp_info_p); return status; } /* Common function for setting OIDs, from a NUT variable name, * used by su_setvar() and su_instcmd() * Params: * @mode: SU_MODE_INSTCMD for instant commands, SU_MODE_SETVAR for settings * @varname: name of variable or command to set the OID from * @val: value for settings, NULL for commands * Returns respectively (for instcmd or setvar activity): * STAT_INSTCMD_HANDLED or STAT_SET_HANDLED if OK, * STAT_*_CONVERSION_FAILED if the value was invalid * (not a number when expected one, * not a key in mapping table when used) * STAT_*_INVALID or STAT_*_UNKNOWN if the command / setting is not supported * STAT_*_FAILED otherwise */ static int su_setOID(int mode, const char *varname, const char *val) { snmp_info_t *su_info_p = NULL; bool_t status; int retval = STAT_SET_FAILED; int cmd_offset = 0; /* FIXME: Does not seem to be actually used! */ long value = -1; /* normal (default), outlet, or outlet group variable */ snmp_info_flags_t vartype = 0; int daisychain_device_number = -1; /* variable without the potential "device.X" prefix, to find the template */ char *tmp_varname = NULL; const char *val_practical = NULL; char setOID[SU_INFOSIZE]; /* Used for potentially appending "device.X." to {outlet,outlet.group}.count */ char template_count_var[SU_BUFSIZE]; upsdebugx(2, "entering %s(%s, %s, %s)", __func__, (mode==SU_MODE_INSTCMD)?"instcmd":"setvar", NUT_STRARG(varname), NUT_STRARG(val)); memset(setOID, 0, SU_INFOSIZE); memset(template_count_var, 0, SU_BUFSIZE); /* Check if it's a daisychain setting (device.x.varname), * or a non-daisy setting/value/cmd for the "master" unit * (as un-numbered device.varname), or something else? */ if (!strncmp(varname, "device", 6)) { if (varname[7] >= '0' && varname[7] <= '9') { /* Extract the (single-digit) device number * TODO: use strtol() or similar to support multi-digit * chains and offset tmp_varname inside varname properly */ daisychain_device_number = atoi(&varname[7]); /* Point at the command, without the "device.x" prefix */ tmp_varname = strdup(&varname[9]); snprintf(template_count_var, 10, "%s", varname); upsdebugx(2, "%s: got a daisychain %s (%s) for device %i", __func__, (mode==SU_MODE_INSTCMD)?"command":"setting", tmp_varname, daisychain_device_number); if (daisychain_device_number > devices_count) upsdebugx(2, "%s: item is out of bound (%i / %ld)", __func__, daisychain_device_number, devices_count); } else { /* Note: below we check if "OID" contains ".%i" template text * like we do in su_setinfo(); eventually we might get vendor * MIBs that do expose device.contact/location/description * for each link in the chain... */ if (daisychain_enabled == TRUE) { /* Is the original "device.varname" backed by a templated * OID string, so we can commonly set e.g. device.contact * for everything in the chain? */ su_info_p = su_find_info(varname); if (su_info_p && (su_info_p->OID == NULL || strstr(su_info_p->OID, ".%i") != NULL) ) { /* is templated or defaulted */ daisychain_device_number = 0; } else { daisychain_device_number = 1; } upsdebugx(2, "%s: got an un-numbered daisychain %s (%s), " "directing it to %s", __func__, (mode==SU_MODE_INSTCMD)?"command":"setting", varname, (daisychain_device_number==1)?"'master' device":"all devices" ); } else { /* No daisy, no poppy */ daisychain_device_number = 0; } tmp_varname = strdup(varname); } } else { daisychain_device_number = 0; tmp_varname = strdup(varname); } /* skip the whole-daisychain for now: * will send the settings to all devices in the daisychain */ if ((daisychain_enabled == TRUE) && (devices_count > 1) && (daisychain_device_number == 0)) { upsdebugx(2, "daisychain %s for device.0 are not yet supported!", (mode==SU_MODE_INSTCMD)?"command":"setting"); free(tmp_varname); return (mode==SU_MODE_INSTCMD ? (int)STAT_INSTCMD_INVALID : (int)STAT_SET_INVALID); } /* Check if it is outlet / outlet.group, or standard variable */ if (strncmp(tmp_varname, "outlet", 6)) { su_info_p = su_find_info(tmp_varname); /* what if e.g. "device.x.contact" is not found as a "contact"? */ if (!su_info_p && strcmp(tmp_varname, varname)) { upsdebugx(2, "%s: did not find info for daisychained entry %s, " "retrying with original varname %s", __func__, tmp_varname, varname); su_info_p = su_find_info(varname); /* Still nothing? Try to revert from "device.1." * as a daisychain master? */ if (!su_info_p && daisychain_enabled == TRUE && devices_count > 1 && daisychain_device_number == 1 && !strncmp(varname, "device.1.", 9) ) { char tmp_buf[SU_INFOSIZE]; snprintf(tmp_buf, sizeof(tmp_buf), "device.%s", (varname + 9)); su_info_p = su_find_info(tmp_buf); if (su_info_p) { upsdebugx(2, "%s: finally found " "as daisy master revert %s", __func__, tmp_buf); free(tmp_varname); tmp_varname = strdup(tmp_buf); } } } } else { /* is indeed an outlet.* or device.x.outlet.* */ snmp_info_t *tmp_info_p; /* Point the outlet or outlet group number in the string */ const char *item_number_ptr = NULL; char *item_varname; /* Store the target outlet or group number */ int item_number = extract_template_number_from_snmp_info_t(tmp_varname); /* Store the total number of outlets or outlet groups */ int total_items = -1; /* Check if it is outlet / outlet.group */ vartype = get_template_type(tmp_varname); if (vartype == SU_OUTLET_GROUP) { snprintfcat(template_count_var, SU_BUFSIZE, "outlet.group.count"); total_items = atoi(dstate_getinfo(template_count_var)); item_number_ptr = &tmp_varname[12]; } else { snprintfcat(template_count_var, SU_BUFSIZE, "outlet.count"); total_items = atoi(dstate_getinfo(template_count_var)); item_number_ptr = &tmp_varname[6]; } upsdebugx(3, "Using count variable '%s'", template_count_var); item_number = atoi(++item_number_ptr); upsdebugx(3, "%s: item %i / %i", __func__, item_number, total_items); /* ensure the item number is supported (filtered upstream though)! */ if (item_number > total_items) { /* out of bound item number */ upsdebugx(2, "%s: item is out of bound (%i / %i)", __func__, item_number, total_items); return (mode==SU_MODE_INSTCMD ? (int)STAT_INSTCMD_INVALID : (int)STAT_SET_INVALID); } /* find back the item template */ item_varname = (char *)xmalloc(SU_INFOSIZE); snprintf(item_varname, SU_INFOSIZE, "%s.%s%s", (vartype == SU_OUTLET)?"outlet":"outlet.group", "%i", strchr(item_number_ptr++, '.')); upsdebugx(3, "%s: searching for template\"%s\"", __func__, item_varname); tmp_info_p = su_find_info(item_varname); free(item_varname); /* for an snmp_info_t instance */ su_info_p = instantiate_info(tmp_info_p, su_info_p); /* check if default value is also a template */ if ((su_info_p->dfl != NULL) && (strstr(tmp_info_p->dfl, "%i") != NULL)) { su_info_p->dfl = (char *)xmalloc(SU_INFOSIZE); snprintf_dynamic((char *)su_info_p->dfl, SU_INFOSIZE, tmp_info_p->dfl, "%i", item_number); } /* adapt the OID */ if (su_info_p->OID != NULL) { if (mode==SU_MODE_INSTCMD) { /* Workaround buggy Eaton Pulizzi implementation * which have different offsets index for data & commands! */ if (su_info_p->flags & SU_CMD_OFFSET) { cmd_offset++; upsdebugx(3, "Adding command offset, now: %i", cmd_offset); } } /* Special processing for daisychain: * these outlet | outlet groups also include formatting info, * so we have to check if the daisychain is enabled, and if * the formatting info for it are in 1rst or 2nd position */ if (daisychain_enabled == TRUE) { /* Note: daisychain_enabled == TRUE means that we have * daisychain template. However: * * when there are multiple devices, offset "-1" applies * since device.0 is a fake and actual devices start at * index 1 * * when there is only 1 device, offset doesn't apply since * the device index is "0" */ int daisychain_offset = 0; if (devices_count > 1) daisychain_offset = 1; if (su_info_p->flags & SU_TYPE_DAISY_1) { snprintf_dynamic((char *)su_info_p->OID, SU_INFOSIZE, tmp_info_p->OID, "%i%i", daisychain_device_number - daisychain_offset, item_number); } else { snprintf_dynamic((char *)su_info_p->OID, SU_INFOSIZE, tmp_info_p->OID, "%i%i", item_number, daisychain_device_number - daisychain_offset); } } else { snprintf_dynamic((char *)su_info_p->OID, SU_INFOSIZE, tmp_info_p->OID, "%i", item_number); } } /* else, don't return STAT_SET_INVALID for mode==SU_MODE_SETVAR * since we can be setting a server side variable - but * note this consideration does not apply to instcmd's! */ else { if (mode==SU_MODE_INSTCMD) { free_info(su_info_p); return STAT_INSTCMD_UNKNOWN; } else { /* adapt info_type */ if (su_info_p->info_type != NULL) snprintf((char *)su_info_p->info_type, SU_INFOSIZE, "%s", tmp_varname); } } } /* Sanity check */ if (!su_info_p || !su_info_p->info_type || !(su_info_p->flags & SU_FLAG_OK)) { upsdebugx(2, "%s: info element unavailable %s", __func__, varname); /* Free template (outlet and outlet.group) */ free_info(su_info_p); if (tmp_varname != NULL) free(tmp_varname); return (mode==SU_MODE_INSTCMD ? (int)STAT_INSTCMD_UNKNOWN : (int)STAT_SET_UNKNOWN); } /* set value into the device, using the provided one, or the default one otherwise */ if (mode==SU_MODE_INSTCMD) { /* Sanity check: commands should either have a value or a default */ if ( (val == NULL) && (su_info_p->dfl == NULL) ) { upsdebugx(1, "%s: cannot execute command '%s': a provided or default value is needed!", __func__, varname); return STAT_INSTCMD_INVALID; } upslog_INSTCMD_POWERSTATE_CHECKED(varname, val); } val_practical = val ? val : su_info_p->dfl; if (su_info_p->info_flags & ST_FLAG_STRING) { status = nut_snmp_set_str(su_info_p->OID, val_practical); } else { if (mode==SU_MODE_INSTCMD) { if ( !str_to_long(val_practical, &value, 10) ) { upsdebugx(1, "%s: cannot execute command '%s': value is not a number!", __func__, varname); return STAT_INSTCMD_CONVERSION_FAILED; } } else { /* non string data may imply a value lookup */ if (su_info_p->oid2info) { value = su_find_valinfo(su_info_p->oid2info, val_practical); if (value == -1 && errno == EINVAL) { upsdebugx(1, "%s: cannot set '%s': value %s is not supported by lookup mapping!", __func__, varname, NUT_STRARG(val_practical)); return STAT_SET_CONVERSION_FAILED; } } else { /* Convert value and apply multiplier */ if ( !str_to_long(val, &value, 10) ) { upsdebugx(1, "%s: cannot set '%s': value is not a number!", __func__, varname); return STAT_SET_CONVERSION_FAILED; } value = (long)((double)value / su_info_p->info_len); } } /* Actually apply the new value */ if (SU_TYPE(su_info_p) == SU_TYPE_TIME) { status = nut_snmp_set_time(su_info_p->OID, value); } else { status = nut_snmp_set_int(su_info_p->OID, value); } } /* Process result */ if (status == FALSE) { if (mode==SU_MODE_INSTCMD) { upsdebugx(1, "%s: cannot execute command '%s'", __func__, varname); retval = STAT_INSTCMD_FAILED; } else { upsdebugx(1, "%s: cannot set value %s on OID %s", __func__, val, su_info_p->OID); retval = STAT_SET_FAILED; } } else { if (mode==SU_MODE_INSTCMD) { upsdebugx(1, "%s: successfully sent command %s", __func__, varname); retval = STAT_INSTCMD_HANDLED; } else { upsdebugx(1, "%s: successfully set %s to \"%s\"", __func__, varname, val); /* update info array: call dstate_setinfo, since flags and aux are * already published, and this saves us some processing */ dstate_setinfo(varname, "%s", val); retval = STAT_SET_HANDLED; } } /* Free template (outlet and outlet.group) */ if (!strncmp(tmp_varname, "outlet", 6)) free_info(su_info_p); free(tmp_varname); return retval; } /* set r/w INFO_ element to a value. * FIXME: make a common function with su_instcmd! */ int su_setvar(const char *varname, const char *val) { int ret; upsdebug_SET_STARTING(varname, val); ret = su_setOID(SU_MODE_SETVAR, varname, val); upslog_SET_RESULT(ret, varname, val); return ret; } /* Daisychain-aware function to add instant commands: * Every command that is valid for a device has to be added for device.0 * This then allows to composite commands, called on device.0 and executed * on all devices of the daisychain */ int su_addcmd(snmp_info_t *su_info_p) { upsdebugx(2, "entering %s(%s)", __func__, su_info_p->info_type); if (daisychain_enabled == TRUE) { /* FIXME?: daisychain */ for (current_device_number = 1 ; current_device_number <= devices_count ; current_device_number++) { process_template(SU_WALKMODE_INIT, "device", su_info_p); } } else { if (nut_snmp_get(su_info_p->OID) != NULL) { dstate_addcmd(su_info_p->info_type); upsdebugx(1, "%s: adding command '%s'", __func__, su_info_p->info_type); } } return 0; } /* process instant command and take action. */ int su_instcmd(const char *cmdname, const char *extradata) { int ret; upsdebug_INSTCMD_STARTING(cmdname, extradata); ret = su_setOID(SU_MODE_INSTCMD, cmdname, extradata); upslog_INSTCMD_RESULT(ret, cmdname, extradata); return ret; } /* FIXME: the below functions can be removed since these were for loading * the mib2nut information from a file instead of the .h definitions... */ /* return 1 if usable, 0 if not */ static int parse_mibconf_args(size_t numargs, char **arg) { bool_t ret; /* everything below here uses up through arg[1] */ if (numargs < 6) return 0; /* */ /* special case for setting some OIDs value at driver startup */ if (!strcmp(arg[0], "init")) { /* set value. */ if (!strcmp(arg[1], "str")) { ret = nut_snmp_set_str(arg[3], arg[4]); } else { ret = nut_snmp_set_int(arg[3], strtol(arg[4], NULL, 0)); } if (ret == FALSE) upslogx(LOG_ERR, "%s: cannot set value %s for %s", __func__, arg[4], arg[3]); else upsdebugx(1, "%s: successfully set %s to \"%s\"", __func__, arg[0], arg[4]); return 1; } /* TODO: create the lookup table */ upsdebugx(2, "%s, %s, %s, %s, %s, %s", arg[0], arg[1], arg[2], arg[3], arg[4], arg[5]); return 1; } /* called for fatal errors in parseconf like malloc failures */ static void mibconf_err(const char *errmsg) { upslogx(LOG_ERR, "Fatal error in parseconf (*mib.conf): %s", errmsg); } /* load *mib.conf into an snmp_info_t structure */ void read_mibconf(char *mib) { char fn[NUT_PATH_MAX + 1]; PCONF_CTX_t ctx; int numerrors = 0; upsdebugx(2, "SNMP UPS driver: entering %s(%s)", __func__, mib); snprintf(fn, sizeof(fn), "%s/snmp/%s.conf", CONFPATH, mib); pconf_init(&ctx, mibconf_err); if (!pconf_file_begin(&ctx, fn)) fatalx(EXIT_FAILURE, "%s", ctx.errmsg); while (pconf_file_next(&ctx)) { if (pconf_parse_error(&ctx)) { upslogx(LOG_ERR, "Parse error: %s:%d: %s", fn, ctx.linenum, ctx.errmsg); numerrors++; continue; } if (ctx.numargs < 1) continue; if (!parse_mibconf_args(ctx.numargs, ctx.arglist)) { unsigned int i; char errmsg[SMALLBUF]; snprintf(errmsg, sizeof(errmsg), "mib.conf: invalid directive"); for (i = 0; i < ctx.numargs; i++) snprintfcat(errmsg, sizeof(errmsg), " %s", ctx.arglist[i]); numerrors++; upslogx(LOG_WARNING, "%s", errmsg); } } /* FIXME: Per legacy behavior, we silently went on. * Maybe should abort on unusable configs? */ if (numerrors) { upslogx(LOG_ERR, "Encountered %d MIB config errors, those entries were ignored", numerrors); } pconf_finish(&ctx); } nut-2.8.4/drivers/generic_gpio_libgpiod.h0000644000175000017500000000310515000736161015404 00000000000000/* generic_gpio_libgpiod.h - gpiod based NUT driver definitions for GPIO attached UPS devices * * Copyright (C) * 2023 - 2025 Modris Berzonis * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef GENERIC_GPIO_LIBGPIOD_H_SEEN #define GENERIC_GPIO_LIBGPIOD_H_SEEN 1 #include #include typedef struct libgpiod_data_t { struct gpiod_chip *gpioChipHandle; /* libgpiod chip handle when opened */ #if WITH_LIBGPIO_VERSION < 0x00020000 struct gpiod_line_bulk gpioLines; /* libgpiod lines to monitor */ struct gpiod_line_bulk gpioEventLines; /* libgpiod lines for event monitoring */ #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ struct gpiod_line_config *lineConfig; struct gpiod_request_config *config; struct gpiod_line_request *request; enum gpiod_line_value *values; #endif /* WITH_LIBGPIO_VERSION */ } libgpiod_data; #endif /* GENERIC_GPIO_LIBGPIOD_H_SEEN */ nut-2.8.4/drivers/baytech-rpc3nc-mib.c0000644000175000017500000001270515000736161014454 00000000000000/* baytech-rpc3nc-mib.c - data to monitor BayTech RPC3-NC PDUs * * Copied and modified from baytech-mib.c. The Snmp2NUT lookup table is * the same, excluding changing the OID for ups.model and device.model. * * Copyright (C) 2009 from baytech-mib.c * Opengear * Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "baytech-rpc3nc-mib.h" /* NOTE: last badly versioned release was "4032" but should be "X.Y[Z]"! */ #define BAYTECH_RPC3NC_MIB_VERSION "0.4035" /* Baytech RPC3NC MIB */ #define BAYTECH_RPC3NC_OID_MIB ".1.3.6.1.4.1.4779" #define BAYTECH_RPC3NC_OID_MODEL_NAME ".1.3.6.1.4.1.4779.1.3.5.5.1.3.2.1" static info_lkp_t baytech_outlet_status_info[] = { info_lkp_default(-1, "error"), info_lkp_default(0, "off"), info_lkp_default(1, "on"), info_lkp_default(2, "cycling"), /* transitional status, "reboot" in MIB comments */ info_lkp_default(3, "lockon"), info_lkp_default(4, "lockoff"), info_lkp_default(5, "unlock"), info_lkp_default(6, "unknown"), info_lkp_sentinel }; /* Snmp2NUT lookup table for BayTech RPC3NC MIBs */ static snmp_info_t baytech_rpc3nc_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "BayTech", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.5.1.3.2.1", "Generic SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.2.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.macaddr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.2.1.2.2.1.6.2", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* UPS page */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Baytech", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.5.1.3.2.1", "Generic SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.id", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.3.0", "unknown", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.2.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.1.1.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.temperature", 0, 0.1, ".1.3.6.1.4.1.4779.1.3.5.5.1.10.2.1", NULL, 0, NULL), /* Outlet page */ snmp_info_default("outlet.id", 0, 1, NULL, "0", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, NULL, "All outlets", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.count", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.2.1.15.1", "0", 0, NULL), snmp_info_default("outlet.current", 0, 0.1, ".1.3.6.1.4.1.4779.1.3.5.5.1.6.2.1", NULL, 0, NULL), snmp_info_default("outlet.voltage", 0, 0.1, ".1.3.6.1.4.1.4779.1.3.5.5.1.8.2.1", NULL, 0, NULL), /* outlet template definition */ snmp_info_default("outlet.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.3.1.3.1.%i", NULL, SU_OUTLET, &baytech_outlet_status_info[0]), snmp_info_default("outlet.%i.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4779.1.3.5.3.1.4.1.%i", NULL, SU_OUTLET, NULL), snmp_info_default("outlet.%i.id", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.6.1.3.2.1.%i", "%i", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_OUTLET | SU_FLAG_OK, NULL), snmp_info_default("outlet.%i.switchable", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.3.1.1.1.%i", "yes", SU_FLAG_STATIC | SU_OUTLET, NULL), /* instant commands. */ snmp_info_default("outlet.%i.load.off", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.3.1.3.1.%i", "0", SU_TYPE_CMD | SU_OUTLET, NULL), snmp_info_default("outlet.%i.load.on", 0, 1, ".1.3.6.1.4.1.4779.1.3.5.3.1.3.1.%i", "1", SU_TYPE_CMD | SU_OUTLET, NULL), /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t baytech_rpc3nc = { "baytech_rpc3nc", BAYTECH_RPC3NC_MIB_VERSION, NULL, BAYTECH_RPC3NC_OID_MODEL_NAME, baytech_rpc3nc_mib, BAYTECH_RPC3NC_OID_MIB, NULL }; nut-2.8.4/drivers/bcmxcp_usb.c0000644000175000017500000004211315000736161013223 00000000000000#include "main.h" #include "bcmxcp.h" #include "bcmxcp_io.h" #include "common.h" #include "usb-common.h" #include "timehead.h" #include "nut_stdint.h" /* for uint16_t */ #include #include #include #include #define SUBDRIVER_NAME "USB communication subdriver" #define SUBDRIVER_VERSION "0.27" /* communication driver description structure */ upsdrv_info_t comm_upsdrv_info = { SUBDRIVER_NAME, SUBDRIVER_VERSION, NULL, 0, { NULL } }; #define MAX_TRY 4 #define MAX_TRY_OPENUSB 32 /* Powerware */ #define POWERWARE 0x0592 /* Phoenixtec Power Co., Ltd */ #define PHOENIXTEC 0x06da /* Hewlett Packard */ #define HP_VENDORID 0x03f0 static USBDevice_t curDevice; /* USB functions */ usb_dev_handle *nutusb_open(const char *port); int nutusb_close(usb_dev_handle *dev_h, const char *port); /* unified failure reporting: call these often */ void nutusb_comm_fail(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2))); void nutusb_comm_good(void); /* function pointer, set depending on which device is used */ /* FIXME? Use usb_ctrl_* typedefs*/ static int (*usb_set_descriptor)(usb_dev_handle *udev, unsigned char type, unsigned char index, void *buf, size_t size); /* usb_set_descriptor() for Powerware devices */ /* FIXME? Use usb_ctrl_* typedefs*/ static int usb_set_powerware(usb_dev_handle *udev, unsigned char type, unsigned char index, void *buf, size_t size) { assert (size < INT_MAX); return usb_control_msg(udev, USB_ENDPOINT_OUT, USB_REQ_SET_DESCRIPTOR, (type << 8) + index, 0, buf, (int)size, 1000); } static void *powerware_ups(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); usb_set_descriptor = &usb_set_powerware; return NULL; } /* usb_set_descriptor() for Phoenixtec devices */ /* FIXME? Use usb_ctrl_* typedefs*/ static int usb_set_phoenixtec(usb_dev_handle *udev, unsigned char type, unsigned char index, void *buf, size_t size) { NUT_UNUSED_VARIABLE(index); NUT_UNUSED_VARIABLE(type); assert (size < INT_MAX); return usb_control_msg(udev, 0x42, 0x0d, (0x00 << 8) + 0x0, 0, buf, (int)size, 1000); } static void *phoenixtec_ups(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); usb_set_descriptor = &usb_set_phoenixtec; return NULL; } /* USB IDs device table */ static usb_device_id_t pw_usb_device_table[] = { /* various models */ { USB_DEVICE(POWERWARE, 0x0002), &powerware_ups }, /* various models */ { USB_DEVICE(PHOENIXTEC, 0x0002), &phoenixtec_ups }, /* T500 */ { USB_DEVICE(HP_VENDORID, 0x1f01), &phoenixtec_ups }, /* T750 */ { USB_DEVICE(HP_VENDORID, 0x1f02), &phoenixtec_ups }, /* Terminating entry */ { 0, 0, NULL } }; /* limit the amount of spew that goes in the syslog when we lose the UPS */ #define USB_ERR_LIMIT 10 /* start limiting after 10 in a row */ #define USB_ERR_RATE 10 /* then only print every 10th error */ #define XCP_USB_TIMEOUT 5000 /* in msec */ /* global variables */ static usb_dev_handle *upsdev = NULL; extern int exit_flag; static unsigned int comm_failures = 0; /* Functions implementations */ void send_read_command(unsigned char command) { unsigned char buf[4]; if (upsdev) { buf[0] = PW_COMMAND_START_BYTE; buf[1] = 0x01; /* data length */ buf[2] = command; /* command to send */ buf[3] = calc_checksum(buf); /* checksum */ upsdebug_hex (3, "send_read_command", buf, 4); usb_set_descriptor(upsdev, USB_DT_STRING, 4, buf, 4); /* FIXME: Ignore error */ } } void send_write_command(unsigned char *command, size_t command_length) { unsigned char sbuf[128]; if (upsdev) { /* Prepare the send buffer */ sbuf[0] = PW_COMMAND_START_BYTE; sbuf[1] = (unsigned char)(command_length); memcpy(sbuf+2, command, command_length); command_length += 2; /* Add checksum */ sbuf[command_length] = calc_checksum(sbuf); command_length += 1; upsdebug_hex (3, "send_write_command", sbuf, command_length); usb_set_descriptor(upsdev, USB_DT_STRING, 4, sbuf, command_length); /* FIXME: Ignore error */ } } #define PW_HEADER_SIZE (PW_HEADER_LENGTH + 1) #define PW_CMD_BUFSIZE 256 /* get the answer of a command from the ups. And check that the answer is for this command */ ssize_t get_answer(unsigned char *data, unsigned char command) { unsigned char buf[PW_CMD_BUFSIZE], *my_buf = buf; ssize_t res; int endblock, need_data; long elapsed_time; /* milliseconds */ ssize_t tail; size_t bytes_read, end_length, length; unsigned char block_number, sequence, seq_num; struct timeval start_time, now; if (upsdev == NULL) return -1; need_data = PW_HEADER_SIZE; /* 4 - cmd response header length, 1 for csum */ end_length = 0; /* total length of sequence(s), not counting header(s) */ endblock = 0; /* signal the last sequence in the block */ bytes_read = 0; /* total length of data read, including XCP header */ res = 0; elapsed_time = 0; seq_num = 1; /* current theoric sequence */ upsdebugx(1, "entering get_answer(%x)", command); /* Store current time */ gettimeofday(&start_time, NULL); memset(&buf, 0x0, PW_CMD_BUFSIZE); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #endif /* Stay ahead of possible redefinitions... */ assert (XCP_USB_TIMEOUT < INT_MAX); #ifdef __clang__ #pragma clang diagnostic pop #endif #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic pop #endif while ( (!endblock) && ((XCP_USB_TIMEOUT - elapsed_time) > 0) ) { /* Get (more) data if needed */ if (need_data > 0) { res = usb_interrupt_read(upsdev, 0x81, (usb_ctrl_charbuf) buf + bytes_read, 128, (int)(XCP_USB_TIMEOUT - elapsed_time)); /* Update time */ gettimeofday(&now, NULL); elapsed_time = (now.tv_sec - start_time.tv_sec)*1000 + (now.tv_usec - start_time.tv_usec)/1000; /* Check libusb return value */ if (res < 0) { /* Clear any possible endpoint stalls */ usb_clear_halt(upsdev, 0x81); /* continue; */ /* FIXME: seems a break would be better! */ break; } /* this seems to occur on XSlot USB card */ if (res == 0) { /* FIXME: */ continue; } /* Else, we got some input bytes */ bytes_read += (size_t)res; need_data -= res; upsdebug_hex(1, "get_answer", buf, bytes_read); } if (need_data > 0) /* We need more data */ continue; /* Now validate XCP frame */ /* Check header */ if ( my_buf[0] != PW_COMMAND_START_BYTE ) { upsdebugx(2, "get_answer: wrong header 0xab vs. %02x", my_buf[0]); /* Sometime we read something wrong. bad cables? bad ports? */ my_buf = memchr(my_buf, PW_COMMAND_START_BYTE, bytes_read); if (!my_buf) return -1; } /* Read block number byte */ block_number = my_buf[1]; upsdebugx(1, "get_answer: block_number = %x", block_number); /* Check data length byte (remove the header length) */ length = my_buf[2]; upsdebugx(3, "get_answer: data length = %" PRIuSIZE, length); if (bytes_read < (length + PW_HEADER_SIZE)) { if (need_data < 0) --need_data; /* count zerro byte too */ need_data += length + 1; /* packet lenght + checksum */ upsdebugx(2, "get_answer: need to read %d more data", need_data); continue; } /* Check if Length conforms to XCP (121 for normal, 140 for Test mode) */ /* Use the more generous length for testing */ if (length > 140) { upsdebugx(2, "get_answer: bad length"); return -1; } if (bytes_read >= SSIZE_MAX) { upsdebugx(2, "get_answer: bad length (incredibly large read)"); return -1; } /* Test the Sequence # */ sequence = my_buf[3]; if ((sequence & PW_SEQ_MASK) != seq_num) { nutusb_comm_fail("get_answer: not the right sequence received %x!!!\n", (unsigned int)(sequence & PW_SEQ_MASK)); return -1; } else { upsdebugx(2, "get_answer: sequence number (%x) is ok", (unsigned int)(sequence & PW_SEQ_MASK)); } /* Validate checksum */ if (!checksum_test(my_buf)) { nutusb_comm_fail("get_answer: checksum error! "); return -1; } else { upsdebugx(2, "get_answer: checksum is ok"); } /* Check if it's the last sequence */ if (sequence & PW_LAST_SEQ) { /* we're done receiving data */ upsdebugx(2, "get_answer: all data received"); endblock = 1; } else { seq_num++; upsdebugx(2, "get_answer: next sequence is %d", seq_num); } /* copy the current valid XCP frame back */ memcpy(data+end_length, my_buf + 4, length); /* increment pointers to process the next sequence */ end_length += length; /* Work around signedness of comparison result, SSIZE_MAX checked above: */ tail = (ssize_t)bytes_read; tail -= (ssize_t)(length + PW_HEADER_SIZE); if (tail > 0) my_buf = memmove(&buf[0], my_buf + length + PW_HEADER_SIZE, (size_t)tail); else if (tail == 0) my_buf = &buf[0]; else { /* if (tail < 0) */ upsdebugx(1, "get_answer(): did not expect to get negative tail size: %" PRIiSIZE, tail); return -1; } bytes_read = (size_t)tail; } upsdebug_hex (5, "get_answer", data, end_length); assert (end_length < SSIZE_MAX); return (ssize_t)end_length; } /* Sends a single command (length=1). and get the answer */ ssize_t command_read_sequence(unsigned char command, unsigned char *data) { ssize_t bytes_read = 0; size_t retry = 0; while ((bytes_read < 1) && (retry < 5)) { send_read_command(command); bytes_read = get_answer(data, command); retry++; } if (bytes_read < 1) { nutusb_comm_fail("Error executing command"); dstate_datastale(); return -1; } return bytes_read; } /* Sends a setup command (length > 1) */ ssize_t command_write_sequence(unsigned char *command, size_t command_length, unsigned char *answer) { ssize_t bytes_read = 0; size_t retry = 0; while ((bytes_read < 1) && (retry < 5)) { send_write_command(command, command_length); sleep(PW_SLEEP); bytes_read = get_answer(answer, command[0]); retry ++; } if (bytes_read < 1) { nutusb_comm_fail("Error executing command"); dstate_datastale(); return -1; } return bytes_read; } void upsdrv_comm_good(void) { nutusb_comm_good(); } void upsdrv_initups(void) { upsdev = nutusb_open("USB"); } void upsdrv_cleanup(void) { upslogx(LOG_ERR, "CLOSING\n"); nutusb_close(upsdev, "USB"); free(curDevice.Vendor); free(curDevice.Product); free(curDevice.Serial); free(curDevice.Bus); free(curDevice.Device); } void upsdrv_reconnect(void) { dstate_setinfo("driver.state", "reconnect.trying"); upsdebugx(4, "=================================================="); upsdebugx(4, "= device has been disconnected, try to reconnect ="); upsdebugx(4, "=================================================="); nutusb_close(upsdev, "USB"); upsdev = NULL; upsdrv_initups(); dstate_setinfo("driver.state", "quiet"); } /* USB functions */ static void nutusb_open_error(const char *port) __attribute__((noreturn)); static void nutusb_open_error(const char *port) { printf("Unable to find POWERWARE UPS device on USB bus (%s)\n\n", port); printf("Things to try:\n\n"); printf(" - Connect UPS device to USB bus\n\n"); printf(" - Run this driver as another user (upsdrvctl -u or 'user=...' in ups.conf).\n"); printf(" See upsdrvctl(8) and ups.conf(5).\n\n"); fatalx(EXIT_FAILURE, "Fatal error: unusable configuration"); } /* FIXME: this part of the opening can go into common... */ static usb_dev_handle *open_powerware_usb(void) { #if WITH_LIBUSB_1_0 libusb_device **devlist; ssize_t devcount = 0; libusb_device_handle *udev; struct libusb_device_descriptor dev_desc; uint8_t bus_num; /* TODO: consider device_addr */ int i; devcount = libusb_get_device_list(NULL, &devlist); if (devcount <= 0) fatal_with_errno(EXIT_FAILURE, "No USB device found"); for (i = 0; i < devcount; i++) { libusb_device *device = devlist[i]; libusb_get_device_descriptor(device, &dev_desc); if (dev_desc.bDeviceClass != LIBUSB_CLASS_PER_INTERFACE) { continue; } curDevice.VendorID = dev_desc.idVendor; curDevice.ProductID = dev_desc.idProduct; bus_num = libusb_get_bus_number(device); curDevice.Bus = (char *)malloc(4); if (curDevice.Bus == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } sprintf(curDevice.Bus, "%03d", bus_num); /* FIXME: we should also retrieve * dev->descriptor.iManufacturer * dev->descriptor.iProduct * dev->descriptor.iSerialNumber * as in libusb.c->libusb_open() * This is part of the things to put in common... */ if (is_usb_device_supported(pw_usb_device_table, &curDevice) == SUPPORTED) { libusb_open(device, &udev); libusb_free_device_list(devlist, 1); return udev; } } libusb_free_device_list(devlist, 1); #else /* not WITH_LIBUSB_1_0 */ struct usb_bus *busses = usb_get_busses(); struct usb_bus *bus; for (bus = busses; bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.bDeviceClass != USB_CLASS_PER_INTERFACE) { continue; } curDevice.VendorID = dev->descriptor.idVendor; curDevice.ProductID = dev->descriptor.idProduct; curDevice.Bus = xstrdup(bus->dirname); /* FIXME: we should also retrieve * dev->descriptor.iManufacturer * dev->descriptor.iProduct * dev->descriptor.iSerialNumber * as in libusb.c->libusb_open() * This is part of the things to put in common... */ if (is_usb_device_supported(pw_usb_device_table, &curDevice) == SUPPORTED) { return usb_open(dev); } } } #endif /* WITH_LIBUSB_1_0 */ return 0; } usb_dev_handle *nutusb_open(const char *port) { int dev_claimed = 0; usb_dev_handle *dev_h = NULL; int retry, errout = 0; int ret = 0; upsdebugx(1, "entering nutusb_open()"); warn_if_bad_usb_port_filename(device_path); /* Initialize Libusb */ #if WITH_LIBUSB_1_0 if (libusb_init(NULL) < 0) { libusb_exit(NULL); fatal_with_errno(EXIT_FAILURE, "Failed to init libusb 1.0"); } #else /* not WITH_LIBUSB_1_0 */ usb_init(); usb_find_busses(); usb_find_devices(); #endif /* WITH_LIBUSB_1_0 */ /* for (retry = 0; dev_h == NULL && retry < MAX_TRY_OPENUSB; retry++) */ for (retry = 0; retry < MAX_TRY ; retry++) { dev_h = open_powerware_usb(); if (!dev_h) { upsdebugx(1, "Can't open POWERWARE USB device"); errout = 1; } else { upsdebugx(1, "device %s opened successfully", curDevice.Bus); errout = 0; #ifdef WIN32 if ((ret = usb_set_configuration(dev_h, 1)) < 0) { upsdebugx(1, "Can't set POWERWARE USB configuration: %s", nut_usb_strerror(ret)); errout = 1; } #endif /* WIN32 */ if ((ret = usb_claim_interface(dev_h, 0)) < 0) { upsdebugx(1, "Can't claim POWERWARE USB interface: %s", nut_usb_strerror(ret)); errout = 1; } else { dev_claimed = 1; errout = 0; } /* FIXME: the above part of the opening can go into common... up to here at least */ if ((ret = usb_clear_halt(dev_h, 0x81)) < 0) { upsdebugx(1, "Can't reset POWERWARE USB endpoint: %s", nut_usb_strerror(ret)); if (dev_claimed) usb_release_interface(dev_h, 0); usb_reset(dev_h); sleep(5); /* Wait reconnect */ errout = 1; } else errout = 0; } /* Test if we succeeded */ if ( (dev_h != NULL) && dev_claimed && (errout == 0) ) break; else { /* Clear errors, and try again */ errout = 0; } } if (!dev_h && !dev_claimed && retry == MAX_TRY) errout = 1; else return dev_h; if (dev_h && dev_claimed) usb_release_interface(dev_h, 0); nutusb_close(dev_h, port); if (errout == 1) nutusb_open_error(port); return NULL; } /* FIXME: this part can go into common... */ int nutusb_close(usb_dev_handle *dev_h, const char *port) { int ret = 0; NUT_UNUSED_VARIABLE(port); if (dev_h) { usb_release_interface(dev_h, 0); #if WITH_LIBUSB_1_0 libusb_close(dev_h); libusb_exit(NULL); #else ret = usb_close(dev_h); #endif } return ret; } void nutusb_comm_fail(const char *fmt, ...) { int ret; char why[SMALLBUF]; va_list ap; /* this means we're probably here because select was interrupted */ if (exit_flag != 0) return; /* ignored, since we're about to exit anyway */ comm_failures++; if ((comm_failures == USB_ERR_LIMIT) || ((comm_failures % USB_ERR_RATE) == 0)) { upslogx(LOG_WARNING, "Warning: excessive comm failures, " "limiting error reporting"); } /* once it's past the limit, only log once every USB_ERR_LIMIT calls */ if ((comm_failures > USB_ERR_LIMIT) && ((comm_failures % USB_ERR_LIMIT) != 0)) { /* Try reconnection */ upsdebugx(1, "Got to reconnect!\n"); upsdrv_reconnect(); return; } /* generic message if the caller hasn't elaborated */ if (!fmt) { upslogx(LOG_WARNING, "Communications with UPS lost - check cabling"); return; } va_start(ap, fmt); ret = vsnprintf(why, sizeof(why), fmt, ap); va_end(ap); if ((ret < 1) || (ret >= (int) sizeof(why))) upslogx(LOG_WARNING, "usb_comm_fail: vsnprintf needed " "more than %d bytes", (int)sizeof(why)); upslogx(LOG_WARNING, "Communications with UPS lost: %s", why); } void nutusb_comm_good(void) { if (comm_failures == 0) return; upslogx(LOG_NOTICE, "Communications with UPS re-established"); comm_failures = 0; } nut-2.8.4/drivers/microsol-apc.h0000644000175000017500000002051314777753337013523 00000000000000/* microsol-apc.h - APC Back-UPS BR series UPS driver Copyright (C) 2004 Silvino B. Magalhaes 2019 Roberto Panerai Velloso 2021 Ygor A. S. Regados This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2021/03/19 - Version 0.70 - Initial release, based on solis driver */ #ifndef INCLUDED_MICROSOL_APC_H #define INCLUDED_MICROSOL_APC_H #define MODEL_COUNT 3 /* Supported UPS models */ static const unsigned int MODELS[MODEL_COUNT] = { 183 /* APC Back-UPS BZ2200I-BR */ , 190 /* APC Back-UPS BZ1500-BR */ , 191 /* APC Back-UPS BZ2200BI-BR */ }; /* Note: int type here is aligned with the "nominal_power" * variable in microsol-common.h and many related drivers. */ static const int NOMINAL_POWER[MODEL_COUNT] = { 2200 /* Model 183 */ , 1500 /* Model 190 */ , 2200 /* Model 191 */ }; /* Curves for output voltage (depends on relay state and battery state) * Second index: On-line (0) or On-battery (1) * Third index: Electric relay state */ /* For on-line UPS */ static const float OUTPUT_VOLTAGE_MULTIPLIER_A[MODEL_COUNT][2][8] = { { { 1.831, 1.831, 1.831, 1.831, 1.831, 1.831, 1.831, 1.831}, { 0.1566, 0.1566, 0.1566, 0.1566, 0.1566, 0.1566, 0.1566, 0.1566} } /* Model 183 */ , { { 0.9266, 0.9266, 0.9266, 0.9266, 0.9266, 0.9266, 0.9266, 0.9266}, { 5.59, 9.47, 13.7, 0.0, 0.0, 0.0, 0.0, 0.0} } /* Model 190 */ , { { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00}, { 1.26, 1.26, 1.26, 1.26, 1.26, 1.26, 1.26, 1.26} } /* Model 191 */ }; static const float OUTPUT_VOLTAGE_MULTIPLIER_B[MODEL_COUNT][2][8] = { { { -2.1374, -2.1374, -2.1374, -2.1374, -2.1374, -2.1374, -2.1374, -2.1374}, { 204.93, 204.93, 204.93, 204.93, 204.93, 204.93, 204.93, 204.93} } /* Model 183 */ , { { 5.0694, 5.0694, 5.0694, 5.0694, 5.0694, 5.0694, 5.0694, 5.0694}, { 5.4, 6.5, 17.6, 0.0, 0.0, 0.0, 0.0, 0.0} } /* Model 190 */ , { { 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0}, { -5.91, -5.91, -5.91, -5.91, -5.91, -5.91, -5.91, -5.91} } /* Model 191 */ }; /* Curves for output current * Second index: On-line (0) or On-battery (1) */ static const float OUTPUT_CURRENT_MULTIPLIER_A[MODEL_COUNT][2] = { { 0.0892999991774559, 0.09070000052452087 } /* Model 183 */ , { 0.1264, 0.1303 } /* Model 190 */ , { 0.13819999992847443, 0.08959999680519104 } /* Model 191 */ , }; static const float OUTPUT_CURRENT_MULTIPLIER_B[MODEL_COUNT][2] = { { 0.09350000321865082, 0.14550000429153442 } /* Model 183 */ , { 0.522, 0.468 } /* Model 190 */ , { 0.12999999523162842, 0.1881999969482422 } /* Model 191 */ }; /* Curves for input voltage (depends on nominal output voltage) * Second index: Nominal output voltage = 220V (1) or 115V (0). */ static const float INPUT_VOLTAGE_MULTIPLIER_A[MODEL_COUNT][2] = { { 1.7937, 1.7937 } /* Model 183 */ , { 1.8, 1.8 } /* Model 190 */ , { 1.4825, 1.4952 } /* Model 191 */ }; static const float INPUT_VOLTAGE_MULTIPLIER_B[MODEL_COUNT][2] = { { 1.854, 1.854 } /* Model 183 */ , { 2.224, 2.224 } /* Model 190 */ , { 0.0853, -2.4241 } /* Model 191 */ }; /* Curves for battery voltage */ static const float BATTERY_VOLTAGE_MULTIPLIER_A[MODEL_COUNT] = { 0.1551 /* Model 183 */ , 0.1513 /* Model 190 */ , 0.1543 /* Model 191 */ }; static const float BATTERY_VOLTAGE_MULTIPLIER_B[MODEL_COUNT] = { 0.0654 /* Model 183 */ , 0.7153 /* Model 190 */ , 0.1414 /* Model 191 */ }; /* Real power estimation curves (depends on relay state) */ /* * Remarks: * - Model 190 use a direct real power determination (no need for curve selectors) */ static const float REAL_POWER_CURVE_SELECTOR_A1[MODEL_COUNT][8] = { { 0.24, 0.26, 0.0, 0.0, 0.24, 0.26, 0.0, 0.28 } /* Model 183 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* Model 190 */ , { 0.24, 0.26, 0.0, 0.0, 0.24, 0.26, 0.0, 0.28 } /* Model 191 */ }; static const float REAL_POWER_CURVE_SELECTOR_B1[MODEL_COUNT][8] = { { 83.15, 81.23, 0.0, 0.0, 83.49, 79.05, 0.0, 85.67 } /* Model 183 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* Model 190 */ , { 83.15, 81.23, 0.0, 0.0, 83.49, 79.05, 0.0, 85.67 } /* Model 191 */ }; static const float REAL_POWER_CURVE_SELECTOR_A2[MODEL_COUNT][8] = { { 0.0763, 0.081, 0.0919, 0.0, 0.0741, 0.0828, 0.0, 0.0938 } /* Model 183 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* Model 190 */ , { 0.0763, 0.081, 0.0919, 0.0, 0.0741, 0.0828, 0.0, 0.0938 } /* Model 191 */ }; static const float REAL_POWER_CURVE_SELECTOR_B2[MODEL_COUNT][8] = { { 81.732, 94.459, 86.686, 0.0, 84.657, 84.999, 0.0, 78.097 } /* Model 183 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* Model 190 */ , { 81.732, 94.459, 86.686, 0.0, 84.657, 84.999, 0.0, 78.097 } /* Model 191 */ }; static const float REAL_POWER_CURVE_SELECTOR_A3[MODEL_COUNT][8] = { { 0.0744, 0.0808, 0.0885, 0.0, 0.0732, 0.084, 0.0, 0.0955 } /* Model 183 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* Model 190 */ , { 0.0744, 0.0808, 0.0885, 0.0, 0.0732, 0.084, 0.0, 0.0955 } /* Model 191 */ }; static const float REAL_POWER_CURVE_SELECTOR_B3[MODEL_COUNT][8] = { { 122.06, 122.9, 125.75, 0.0, 120.39, 108.52, 0.0, 92.239 } /* Model 183 */ , { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } /* Model 190 */ , { 122.06, 122.9, 125.75, 0.0, 120.39, 108.52, 0.0, 92.239 } /* Model 191 */ }; static const float REAL_POWER_MULTIPLIER_A1[MODEL_COUNT][8] = { { 0.08040007075206226, 0.0894, 0.0999, 0.0, 0.0813, 0.0905, 0.0, 0.1005 } /* Model 183 */ , { 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127 } /* Model 190 */ , { 0.08040007075206226, 0.0894, 0.0999, 0.0, 0.0813, 0.0905, 0.0, 0.1005 } /* Model 191 */ }; static const float REAL_POWER_MULTIPLIER_B1[MODEL_COUNT][8] = { { 45.292, 41.928, 41.727, 0.0, 40.269, 41.81, 0.0, 43.458 } /* Model 183 */ , { 50.031, 50.031, 50.031, 50.031, 50.031, 50.031, 50.031, 50.031 } /* Model 190 */ , { 45.292, 41.928, 41.727, 0.0, 40.269, 41.81, 0.0, 43.458 } /* Model 191 */ }; static const float REAL_POWER_MULTIPLIER_A2[MODEL_COUNT][8] = { { 0.08630063689870031, 0.0946, 0.1068, 0.0, 0.086, 0.0967, 0.0, 0.1088 } /* Model 183 */ , { 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127 } /* Model 190 */ , { 0.08630063689870031, 0.0946, 0.1068, 0.0, 0.086, 0.0967, 0.0, 0.1088 } /* Model 191 */ }; static const float REAL_POWER_MULTIPLIER_B2[MODEL_COUNT][8] = { { 8.3927, 9.2393, 8.2852, 0.0, 8.301, 6.7636, 0.0, 8.2842 } /* Model 183 */ , { 50.031, 50.031, 50.031, 50.031, 50.031, 50.031, 50.031, 50.031 } /* Model 190 */ , { 8.3927, 9.2393, 8.2852, 0.0, 8.301, 6.7636, 0.0, 8.2842 } /* Model 191 */ }; static const float REAL_POWER_MULTIPLIER_A3[MODEL_COUNT][8] = { { 0.0896001146881468, 0.0991, 0.1116, 0.0, 0.0967, 0.1068, 0.0, 0.1169 } /* Model 183 */ , { 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127, 0.1127 } /* Model 190 */ , { 0.0896001146881468, 0.0991, 0.1116, 0.0, 0.0967, 0.1068, 0.0, 0.1169 } /* Model 191 */ }; static const float REAL_POWER_MULTIPLIER_B3[MODEL_COUNT][8] = { { -31.115, -33.777, -33.826, 0.0, -59.513, -57.729, 0.0, -41.333 } /* Model 183 */ , { 50.031, 50.031, 50.031, 50.031, 50.031, 50.031, 50.031, 50.031 } /* Model 190 */ , { -31.115, -33.777, -33.826, 0.0, -59.513, -57.729, 0.0, -41.333 } /* Model 191 */ }; /** * Maximum battery voltage, used to estimate battery charge * Second index: Recharging battery flag: charging (1) or charged/discharging (0) */ static const float MAX_BATTERY_VOLTAGE[MODEL_COUNT][2] = { { 27.0, 29.5 } /* Model 183 */ , { 27.0, 29.5 } /* Model 190 */ , { 27.0, 29.5 } /* Model 191 */ }; /** Minimum battery voltage, used to estimate battery charge */ static const float MIN_BATTERY_VOLTAGE[MODEL_COUNT] = { 20 /* Model 183 */ , 20 /* Model 190 */ , 20 /* Model 191 */ }; #endif /* INCLUDED_MICROSOL_APC_H */ nut-2.8.4/drivers/liebert-hid.h0000644000175000017500000000207114670526611013303 00000000000000/* liebert-hid.h - subdriver to monitor Liebert USB/HID devices with NUT * * Copyright (C) * 2003 - 2005 Arnaud Quette * 2005 - 2006 Peter Selinger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef LIEBERT_HID_H #define LIEBERT_HID_H #include "usbhid-ups.h" extern subdriver_t liebert_subdriver; #endif /* LIEBERT_HID_H */ nut-2.8.4/drivers/nutdrv_qx.c0000644000175000017500000036072415044667045013157 00000000000000/* nutdrv_qx.c - Driver for USB and serial UPS units with Q* protocols * * Copyright (C) * 2013 Daniele Pezzini * 2016 Eaton * Based on: * usbhid-ups.c - Copyright (C) * 2003-2012 Arnaud Quette * 2005 John Stamp * 2005-2006 Peter Selinger * 2007-2009 Arjen de Korte * blazer.c - Copyright (C) * 2008-2009 Arjen de Korte * 2012 Arnaud Quette * blazer_ser.c - Copyright (C) * 2008 Arjen de Korte * blazer_usb.c - Copyright (C) * 2003-2009 Arjen de Korte * 2011-2012 Arnaud Quette * Masterguard additions * 2020-2021 Edgar Fuß, Mathematisches Institut der Universität Bonn * Armac (Richcomm-variant) additions * 2021 Tomasz Fortuna * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "config.h" #include #include "main.h" #include "attribute.h" #include "nut_float.h" #include "nut_stdint.h" /* note: QX_USB/QX_SERIAL set through Makefile */ #ifdef QX_USB # include "nut_libusb.h" /* also includes "usb-common.h" */ # ifdef QX_SERIAL # define DRIVER_NAME "Generic Q* USB/Serial driver" # else # define DRIVER_NAME "Generic Q* USB driver" # endif /* QX_SERIAL */ #else # define DRIVER_NAME "Generic Q* Serial driver" #endif /* QX_USB */ #define DRIVER_VERSION "0.45" #ifdef QX_SERIAL # include "serial.h" # define SER_WAIT_SEC 1 /* 3 seconds for Best UPS */ #endif /* QX_SERIAL */ #include "nutdrv_qx.h" /* == Subdrivers == */ /* Include all known subdrivers */ #include "nutdrv_qx_bestups.h" #include "nutdrv_qx_hunnox.h" #include "nutdrv_qx_innovart31.h" #include "nutdrv_qx_innovart33.h" #include "nutdrv_qx_mecer.h" #include "nutdrv_qx_megatec.h" #include "nutdrv_qx_megatec-old.h" #include "nutdrv_qx_mustek.h" #include "nutdrv_qx_q1.h" #include "nutdrv_qx_q2.h" #include "nutdrv_qx_q6.h" #include "nutdrv_qx_voltronic.h" #include "nutdrv_qx_voltronic-qs.h" #include "nutdrv_qx_voltronic-qs-hex.h" #include "nutdrv_qx_voltronic-axpert.h" #include "nutdrv_qx_zinto.h" #include "nutdrv_qx_masterguard.h" #include "nutdrv_qx_ablerex.h" #include "nutdrv_qx_gtec.h" /* Reference list of available non-USB subdrivers */ static subdriver_t *subdriver_list[] = { &voltronic_subdriver, &voltronic_axpert_subdriver, &voltronic_qs_subdriver, &voltronic_qs_hex_subdriver, &mustek_subdriver, &megatec_old_subdriver, &bestups_subdriver, &mecer_subdriver, &megatec_subdriver, &zinto_subdriver, &masterguard_subdriver, &hunnox_subdriver, &ablerex_subdriver, &innovart31_subdriver, &innovart33_subdriver, &q2_subdriver, &q6_subdriver, >ec_subdriver, /* Fallback Q1 subdriver */ &q1_subdriver, NULL }; /* == Driver description structure == */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Daniele Pezzini " \ "Arnaud Quette " \ "John Stamp " \ "Peter Selinger " \ "Arjen de Korte " \ "Edgar Fuß ", DRV_BETA, #ifdef QX_USB { &comm_upsdrv_info, NULL } #else { NULL } #endif /* QX_USB */ }; /* == Data walk modes == */ typedef enum { QX_WALKMODE_INIT = 0, QX_WALKMODE_QUICK_UPDATE, QX_WALKMODE_FULL_UPDATE } walkmode_t; /* == Global vars == */ /* Pointer to the active subdriver object (changed in subdriver_matcher() function) */ static subdriver_t *subdriver = NULL; static long pollfreq = DEFAULT_POLLFREQ; static unsigned int ups_status = 0; static bool_t data_has_changed = FALSE; /* for SEMI_STATIC data polling */ static time_t lastpoll; /* Timestamp the last polling */ #if defined(QX_USB) && !defined(TESTING) static int hunnox_step = 0; #endif /* QX_USB && !TESTING */ #if defined(QX_USB) && defined(QX_SERIAL) static int is_usb = 0; /* Whether the device is connected through USB (1) or serial (0) */ #endif /* QX_USB && QX_SERIAL */ static struct { char command[SMALLBUF]; /* Command sent to the UPS to get answer/to execute an instant command */ char answer[SMALLBUF]; /* Answer from the UPS, filled at runtime */ } previous_item = { "", "" }; /* Hold the values of the item processed just before the actual one */ /* == Support functions == */ static int subdriver_matcher(void); static ssize_t qx_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen); static int qx_process_answer(item_t *item, const size_t len); /* returns just 0 or -1 */ static bool_t qx_ups_walk(walkmode_t mode); static void ups_status_set(void); static void ups_alarm_set(void); static void qx_set_var(item_t *item); /* == Struct & data for status processing == */ typedef struct { const char *status_str; /* UPS status string */ const unsigned int status_mask; /* UPS status mask */ } status_lkp_t; static status_lkp_t status_info[] = { /* Map status strings to bit masks */ { "OL", STATUS(OL) }, { "LB", STATUS(LB) }, { "RB", STATUS(RB) }, { "CHRG", STATUS(CHRG) }, { "DISCHRG", STATUS(DISCHRG) }, { "BYPASS", STATUS(BYPASS) }, { "CAL", STATUS(CALIB) }, { "OFF", STATUS(OFF) }, { "OVER", STATUS(OVER) }, { "TRIM", STATUS(TRIM) }, { "BOOST", STATUS(BOOST) }, { "FSD", STATUS(FSD) }, { NULL, 0 }, }; /* == battery.{charge,runtime} guesstimation == */ /* Support functions */ static int qx_battery(void); static int qx_load(void); static void qx_initbattery(void); /* Battery data */ static struct { double packs; /* Battery voltage multiplier */ struct { double act; /* Actual runtime on battery */ double nom; /* Nominal runtime on battery (full load) */ double est; /* Estimated runtime remaining (full load) */ double exp; /* Load exponent */ } runt; struct { double act; /* Actual battery voltage */ double high; /* Battery float voltage */ double nom; /* Nominal battery voltage */ double low; /* Battery low voltage */ } volt; struct { double act; /* Actual battery charge */ long time; /* Recharge time from empty to full */ } chrg; } batt = { 1, { -1, -1, 0, 0 }, { -1, -1, -1, -1 }, { -1, 43200 } }; /* Load data */ static struct { double act; /* Actual load (reported by the UPS) */ double low; /* Idle load */ double eff; /* Effective load */ } load = { 0, 0.1, 1 }; static time_t battery_lastpoll = 0; static int battery_voltage_reports_one_pack = 0, battery_voltage_reports_one_pack_considered = 0; /* Optionally multiply device-provided "battery.voltage" reading by * the "battery.packs" (reading or common override setting) to end up * with the dstate value representing the voltage of battery assembly, * not that of a single cell/pack (different devices report different * physically meaningful values for that reading). * This shared method can be referenced from subdriver mapping tables. */ int qx_multiply_battvolt(item_t *item, char *value, const size_t valuelen) { float s = 0; /* Adjusted here or not, this method was called at all * and other code should not multiply again! */ battery_voltage_reports_one_pack_considered = 1; if (!battery_voltage_reports_one_pack || batt.packs < 2) { /* (We assume by default that) this device already reports * the sum-total voltage for the battery assembly - so just * pass it on unmodified. * Or we can't reasonably use a "batt.packs" anyway. */ snprintf(value, valuelen, "%s", item->value); return 0; } if (sscanf(item->value, "%f", &s) != 1) { upsdebugx(2, "unparsable ss.ss %s", item->value); return -1; } snprintf(value, valuelen, "%.2f", s * batt.packs); return 0; } /* Convert kilo-values to their full representation */ int qx_multiply_x1000(item_t *item, char *value, const size_t valuelen) { float s = 0; if (sscanf(item->value, "%f", &s) != 1) { upsdebugx(2, "unparsable ss.ss %s", item->value); return -1; } snprintf(value, valuelen, "%.2f", s * 1000.0); return 0; } /* Convert minutes to seconds */ int qx_multiply_m2s(item_t *item, char *value, const size_t valuelen) { float s = 0; if (sscanf(item->value, "%f", &s) != 1) { upsdebugx(2, "unparsable ss.ss %s", item->value); return -1; } snprintf(value, valuelen, "%.0f", s * 60.0); return 0; } /* Fill batt.volt.act and guesstimate the battery charge * if it isn't already available. */ static int qx_battery(void) { const char *val = dstate_getinfo("battery.voltage"); if (!val) { upsdebugx(2, "%s: unable to get battery.voltage", __func__); return -1; } batt.volt.act = strtod(val, NULL); if (!battery_voltage_reports_one_pack_considered) { batt.volt.act *= batt.packs; } if (d_equal(batt.chrg.act, -1) && batt.volt.low > 0 && batt.volt.high > batt.volt.low) { batt.chrg.act = 100 * (batt.volt.act - batt.volt.low) / (batt.volt.high - batt.volt.low); if (batt.chrg.act < 0) { batt.chrg.act = 0; } if (batt.chrg.act > 100) { batt.chrg.act = 100; } dstate_setinfo("battery.charge", "%.0f", batt.chrg.act); } return 0; } /* Load for battery.{charge,runtime} from runtimecal */ static int qx_load(void) { const char *val = dstate_getinfo("ups.load"); if (!val) { upsdebugx(2, "%s: unable to get ups.load", __func__); return -1; } load.act = strtod(val, NULL); load.eff = pow(load.act / 100, batt.runt.exp); if (load.eff < load.low) { load.eff = load.low; } return 0; } /* Init known (readings, configs) and guessed (if needed) battery related values */ static void qx_initbattery(void) { const char *val; int batt_packs_known = 0; val = dstate_getinfo("battery.voltage.high"); if (val) { batt.volt.high = strtod(val, NULL); } val = dstate_getinfo("battery.voltage.low"); if (val) { batt.volt.low = strtod(val, NULL); } val = dstate_getinfo("battery.voltage.nominal"); if (val) { batt.volt.nom = strtod(val, NULL); } /* If no values are available for both battery.voltage.{low,high} * either from the UPS or provided by the user in ups.conf, * but nominal battery.voltage.nom is known, * try to guesstimate them, but announce it! */ if ( (!d_equal(batt.volt.nom, -1)) && (d_equal(batt.volt.low, -1) || d_equal(batt.volt.high, -1))) { upslogx(LOG_INFO, "No values for battery high/low voltages"); /* Basic formula, which should cover most cases */ batt.volt.low = 104 * batt.volt.nom / 120; /* Per https://www.csb-battery.com.tw/english/01_product/02_detail.php?fid=17&pid=113 * a nominally 12V battery can have "float charging voltage" * at 13.5-13.8V and an "equalization charging voltage" (e.g. * to desulphurize) at 14-15V. Note that per nut-names.txt, * the "battery.voltage.high" is the practical 100% charge * value (so equal or a bit less than actual battery.voltage * reported by the device, when the situation is healthy); * it is not the voltage that the battery CAN reach on the * brink of boiling out: */ batt.volt.high = 130 * batt.volt.nom / 120; /* Publish these data too */ dstate_setinfo("battery.voltage.low", "%.2f", batt.volt.low); dstate_setinfo("battery.voltage.high", "%.2f", batt.volt.high); upslogx(LOG_INFO, "Using 'guesstimation' (low: %f, high: %f)!", batt.volt.low, batt.volt.high); } val = dstate_getinfo("battery.packs"); if (val && (strspn(val, "0123456789 .") == strlen(val))) { batt.packs = strtod(val, NULL); batt_packs_known = 1; } if (testvar("battery_voltage_reports_one_pack")) { battery_voltage_reports_one_pack = 1; /* If we already have a battery.voltage reading from the device, * it is not yet "adjusted" to consider the multiplication for * packs (if known; if not - the guesswork and call below for * qx_battery() should take care of it). Note that it is only * a few lines above that we might have learned the user-set * amount of battery packs and that they know the device only * reports a single pack voltage in the protocol. * Even if the qx_multiply_battvolt() method was called before * and set the battery_voltage_reports_one_pack_considered flag, * it is not too relevant until now *for maths*. However it is * important to know that the mapping table for this subdriver * does reference the adjustment method at all (which it would * encounter and set the flag while querying battery.voltage * from device and having a non-NULL reading now). */ if (battery_voltage_reports_one_pack_considered) { val = dstate_getinfo("battery.voltage"); if (val && batt_packs_known && batt.packs > 1) { batt.volt.act = strtod(val, NULL) * batt.packs; dstate_setinfo("battery.voltage", "%.2f", batt.volt.act); } } } /* Guesstimation: init values if not provided by device/overrides */ if (!dstate_getinfo("battery.charge") || !dstate_getinfo("battery.runtime")) { if (!batt_packs_known) { /* qx_battery -> batt.volt.act */ if (!qx_battery() && (!d_equal(batt.volt.nom, -1))) { const double packs[] = { 120, 100, 80, 60, 48, 36, 30, 24, 18, 12, 8, 6, 4, 3, 2, 1, 0.5, -1 }; int i; /* The battery voltage will quickly return to * at least the nominal value after discharging them. * For overlapping battery.voltage.low/high ranges * therefore choose the one with the highest multiplier. */ for (i = 0; packs[i] > 0; i++) { if (packs[i] * batt.volt.act > 1.25 * batt.volt.nom) { continue; } if (packs[i] * batt.volt.act < 0.8 * batt.volt.nom) { upslogx(LOG_INFO, "Can't autodetect number of battery packs [%.0f/%.2f]", batt.volt.nom, batt.volt.act); break; } batt.packs = packs[i]; upslogx(LOG_INFO, "Autodetected %.0f as number of battery packs [%.0f/%.2f]", batt.packs, batt.volt.nom, batt.volt.act); break; } } else { upslogx(LOG_INFO, "Can't autodetect number of battery packs [%.0f/%.2f]", batt.volt.nom, batt.volt.act); } } /* Update batt.{chrg,volt}.act */ qx_battery(); val = getval("runtimecal"); if (val) { double rh, lh, rl, ll; time(&battery_lastpoll); if (sscanf(val, "%lf,%lf,%lf,%lf", &rh, &lh, &rl, &ll) < 4) { fatalx(EXIT_FAILURE, "Insufficient parameters for runtimecal"); } if ((rl < rh) || (rh <= 0)) { fatalx(EXIT_FAILURE, "Parameter out of range (runtime)"); } if ((lh > 100) || (ll > lh) || (ll <= 0)) { fatalx(EXIT_FAILURE, "Parameter out of range (load)"); } batt.runt.exp = log(rl / rh) / log(lh / ll); upsdebugx(2, "%s: battery runtime exponent: %.3f", __func__, batt.runt.exp); batt.runt.nom = rh * pow(lh / 100, batt.runt.exp); upsdebugx(2, "%s: battery runtime nominal: %.1f", __func__, batt.runt.nom); } else { upslogx(LOG_INFO, "Battery runtime will not be calculated " "(runtimecal not set)"); return; } val = dstate_getinfo("battery.charge"); if (!val && (!d_equal(batt.volt.nom, -1))) { batt.volt.low = batt.volt.nom; batt.volt.high = 1.15 * batt.volt.nom; if (qx_battery()) fatalx(EXIT_FAILURE, "Initial battery charge undetermined"); val = dstate_getinfo("battery.charge"); } if (val) { batt.runt.est = batt.runt.nom * strtod(val, NULL) / 100; upsdebugx(2, "%s: battery runtime estimate: %.1f", __func__, batt.runt.est); } else { fatalx(EXIT_FAILURE, "Initial battery charge undetermined"); } val = getval("chargetime"); if (val) { batt.chrg.time = strtol(val, NULL, 10); if (batt.chrg.time <= 0) { fatalx(EXIT_FAILURE, "Charge time out of range [1..s]"); } upsdebugx(2, "%s: battery charge time: %ld", __func__, batt.chrg.time); } else { upslogx(LOG_INFO, "No charge time specified, " "using built in default [%ld seconds]", batt.chrg.time); } val = getval("idleload"); if (val) { load.low = strtod(val, NULL) / 100; if ((load.low <= 0) || (load.low > 1)) { fatalx(EXIT_FAILURE, "Idle load out of range [0..100]"); } upsdebugx(2, "%s: minimum load used (idle): %.3f", __func__, load.low); } else { upslogx(LOG_INFO, "No idle load specified, using built in default [%.1f %%]", 100 * load.low); } } } /* == USB communication subdrivers == */ #if defined(QX_USB) && !defined(TESTING) static usb_communication_subdriver_t *usb = &usb_subdriver; static usb_dev_handle *udev = NULL; static USBDevice_t usbdevice; static USBDeviceMatcher_t *reopen_matcher = NULL; static USBDeviceMatcher_t *regex_matcher = NULL; static int langid_fix = -1; static int (*subdriver_command)(const char *cmd, size_t cmdlen, char *buf, size_t buflen) = NULL; /* Cypress communication subdriver */ static int cypress_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { char tmp[SMALLBUF]; size_t tmplen; int ret = 0; size_t i; if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } /* Send command */ memset(tmp, 0, sizeof(tmp)); tmplen = cmdlen > sizeof(tmp) ? sizeof(tmp) : cmdlen; memcpy(tmp, cmd, tmplen); for (i = 0; i < tmplen; i += (size_t)ret) { /* Write data in 8-byte chunks */ /* ret = usb->set_report(udev, 0, (unsigned char *)&tmp[i], 8); */ ret = usb_control_msg(udev, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x09, 0x200, 0, (usb_ctrl_charbuf)&tmp[i], 8, 5000); if (ret <= 0) { upsdebugx(3, "send: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } } upsdebugx(3, "send: %.*s", (int)strcspn(tmp, "\r"), tmp); /* Read reply */ memset(buf, 0, buflen); for (i = 0; (i <= buflen-8) && (memchr(buf, '\r', buflen) == NULL); i += (size_t)ret) { /* Read data in 8-byte chunks */ /* ret = usb->get_interrupt(udev, (unsigned char *)&buf[i], 8, 1000); */ ret = usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)&buf[i], 8, 1000); /* Any errors here mean that we are unable to read a reply * (which will happen after successfully writing a command * to the UPS) */ if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } snprintf(tmp, sizeof(tmp), "read [% 3d]", (int)i); upsdebug_hex(5, tmp, &buf[i], (size_t)ret); } upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); if (i > INT_MAX) { upsdebugx(3, "%s: read too much (%" PRIuSIZE ")", __func__, i); return -1; } return (int)i; } /* SGS communication subdriver */ static int sgs_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { char tmp[SMALLBUF]; int ret = 0; size_t i; if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } /* Send command */ for (i = 0; i < cmdlen; i += (size_t)ret) { memset(tmp, 0, sizeof(tmp)); /* i and cmdlen are size_t nominally, but diff is not large */ ret = (int)((cmdlen - i) < 7 ? (cmdlen - i) : 7); /* ret is between 0 and 7 */ tmp[0] = (char)ret; memcpy(&tmp[1], &cmd[i], (unsigned char)ret); /* Write data in 8-byte chunks */ ret = usb_control_msg(udev, USB_ENDPOINT_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0x09, 0x200, 0, (usb_ctrl_charbuf)tmp, 8, 5000); if (ret <= 0) { upsdebugx(3, "send: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } ret--; } upsdebugx(3, "send: %.*s", (int)strcspn(cmd, "\r"), cmd); /* Read reply */ memset(buf, 0, buflen); for (i = 0; i <= buflen - 8; i += (size_t)ret) { memset(tmp, 0, sizeof(tmp)); /* Read data in 8-byte chunks */ ret = usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)tmp, 8, 1000); /* No error!!! */ /* if (ret == -110) */ if (ret == LIBUSB_ERROR_TIMEOUT) break; /* Any errors here mean that we are unable to read a reply * (which will happen after successfully writing a command * to the UPS) */ if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } /* Every call to read returns 8 bytes * -> actually returned bytes: */ ret = tmp[0] <= 7 ? tmp[0] : 7; if (ret > 0) memcpy(&buf[i], &tmp[1], (unsigned char)ret); snprintf(tmp, sizeof(tmp), "read [% 3d]", (int)i); upsdebug_hex(5, tmp, &buf[i], (size_t)ret); } /* If the reply lacks the expected terminating CR, add it (if there's enough space) */ if (i && memchr(buf, '\r', i) == NULL) { upsdebugx(4, "%s: the reply lacks the expected terminating CR.", __func__); if (i < buflen - 1) { upsdebugx(4, "%s: adding missing terminating CR.", __func__); buf[i++] = '\r'; buf[i] = 0; } } upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); if (i > INT_MAX) { upsdebugx(3, "%s: read too much (%" PRIuSIZE ")", __func__, i); return -1; } return (int)i; } /* Phoenix communication subdriver */ static int phoenix_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { char tmp[SMALLBUF]; size_t tmplen; int ret; size_t i; if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } for (i = 0; i < 8; i++) { /* Read data in 8-byte chunks */ /* ret = usb->get_interrupt(udev, (unsigned char *)tmp, 8, 1000); */ ret = usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)tmp, 8, 1000); /* This USB to serial implementation is crappy. * In order to read correct replies we need to flush the * output buffers of the converter until we get no more * data (e.g. it times out). */ switch (ret) { case LIBUSB_ERROR_PIPE: /* Broken pipe */ usb_clear_halt(udev, 0x81); break; case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */ break; default: break; } if (ret < 0) { upsdebugx(3, "flush: %s (%d)", nut_usb_strerror(ret), ret); break; } upsdebug_hex(4, "dump", tmp, (size_t)ret); } /* Send command */ memset(tmp, 0, sizeof(tmp)); tmplen = cmdlen > sizeof(tmp) ? sizeof(tmp) : cmdlen; memcpy(tmp, cmd, tmplen); for (i = 0; i < tmplen; i += (size_t)ret) { /* Write data in 8-byte chunks */ /* ret = usb->set_report(udev, 0, (unsigned char *)&tmp[i], 8); */ ret = usb_control_msg(udev, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x09, 0x200, 0, (usb_ctrl_charbuf)&tmp[i], 8, 1000); if (ret <= 0) { upsdebugx(3, "send: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } } upsdebugx(3, "send: %.*s", (int)strcspn(tmp, "\r"), tmp); /* Read reply */ memset(buf, 0, buflen); for (i = 0; (i <= buflen-8) && (memchr(buf, '\r', buflen) == NULL); i += (size_t)ret) { /* Read data in 8-byte chunks */ /* ret = usb->get_interrupt(udev, (unsigned char *)&buf[i], 8, 1000); */ ret = usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)&buf[i], 8, 1000); /* Any errors here mean that we are unable to read a reply * (which will happen after successfully writing a command * to the UPS) */ if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } snprintf(tmp, sizeof(tmp), "read [% 3d]", (int)i); upsdebug_hex(5, tmp, &buf[i], (size_t)ret); } upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); if (i > INT_MAX) { upsdebugx(3, "%s: read too much (%" PRIuSIZE ")", __func__, i); return -1; } return (int)i; } /* Ippon communication subdriver */ static int ippon_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { char tmp[64]; size_t tmplen; int ret; size_t i, len; if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } /* Send command */ memset(tmp, 0, sizeof(tmp)); tmplen = cmdlen > sizeof(tmp) ? sizeof(tmp) : cmdlen; memcpy(tmp, cmd, tmplen); for (i = 0; i < tmplen; i += (size_t)ret) { /* Write data in 8-byte chunks */ ret = usb_control_msg(udev, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x09, 0x2, 0, (usb_ctrl_charbuf)&tmp[i], 8, 1000); if (ret <= 0) { upsdebugx(3, "send: %s (%d)", (ret != LIBUSB_ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out", ret); return ret; } } upsdebugx(3, "send: %.*s", (int)strcspn(tmp, "\r"), tmp); /* Read all 64 bytes of the reply in one large chunk */ ret = usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)tmp, sizeof(tmp), 1000); /* Any errors here mean that we are unable to read a reply * (which will happen after successfully writing a command * to the UPS) */ if (ret <= 0) { upsdebugx(3, "read: %s (%d)", (ret != LIBUSB_ERROR_TIMEOUT) ? nut_usb_strerror(ret) : "Connection timed out", ret); return ret; } /* As Ippon will always return 64 bytes in response, * we have to calculate and return length of actual * response data here. * Empty response will look like 0x00 0x0D, otherwise * it will be data string terminated by 0x0D. */ for (i = 0, len = 0; i < (size_t)ret; i++) { if (tmp[i] != '\r') continue; len = ++i; break; } /* Just in case there wasn't any '\r', fallback to string length, if any */ if (!len) len = strlen(tmp); upsdebug_hex(5, "read", tmp, (size_t)len); upsdebugx(3, "read: %.*s", (int)strcspn(tmp, "\r"), tmp); len = len < buflen ? len : buflen - 1; memset(buf, 0, buflen); memcpy(buf, tmp, len); /* If the reply lacks the expected terminating CR, add it (if there's enough space) */ if (len && memchr(buf, '\r', len) == NULL) { upsdebugx(4, "%s: the reply lacks the expected terminating CR.", __func__); if (len < buflen - 1) { upsdebugx(4, "%s: adding missing terminating CR.", __func__); buf[len++] = '\r'; buf[len] = 0; } } if (len > INT_MAX) { upsdebugx(3, "%s: read too much (%" PRIuSIZE ")", __func__, len); return -1; } return (int)len; } static int hunnox_protocol(int asking_for) { char buf[1030]; int langid_fix_local = 0x0409; if (langid_fix != -1) { langid_fix_local = langid_fix; } switch (hunnox_step) { case 0: upsdebugx(3, "asking for: %02X", (unsigned int)0x00); usb_get_string(udev, 0x00, langid_fix_local, (usb_ctrl_charbuf)buf, 1026); usb_get_string(udev, 0x00, langid_fix_local, (usb_ctrl_charbuf)buf, 1026); usb_get_string(udev, 0x01, langid_fix_local, (usb_ctrl_charbuf)buf, 1026); usleep(10000); break; case 1: if (asking_for != 0x0d) { upsdebugx(3, "asking for: %02X", (unsigned int)0x0d); usb_get_string(udev, 0x0d, langid_fix_local, (usb_ctrl_charbuf)buf, 102); } break; case 2: if (asking_for != 0x03) { upsdebugx(3, "asking for: %02X", (unsigned int)0x03); usb_get_string(udev, 0x03, langid_fix_local, (usb_ctrl_charbuf)buf, 102); } break; case 3: if (asking_for != 0x0c && !testvar("novendor")) { upsdebugx(3, "asking for: %02X", (unsigned int)0x0c); usb_get_string(udev, 0x0c, langid_fix_local, (usb_ctrl_charbuf)buf, 102); } break; default: hunnox_step = 0; } hunnox_step++; if (hunnox_step > 3) { hunnox_step = 1; } return 0; } /* Krauler communication subdriver */ static int krauler_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { /* Still not implemented: * 0x6 T (don't know how to pass the parameter) * 0x68 and 0x69 both cause shutdown after an undefined interval */ const struct { const char *str; /* Megatec command */ const int index; /* Krauler string index for this command */ const char prefix; /* Character to replace the first byte in reply */ } command[] = { { "Q1\r", 0x03, '(' }, { "F\r", 0x0d, '#' }, { "I\r", 0x0c, '#' }, { "T\r", 0x04, '\r' }, { "TL\r", 0x05, '\r' }, { "Q\r", 0x07, '\r' }, { "C\r", 0x0b, '\r' }, { "CT\r", 0x0b, '\r' }, { NULL, 0, '\0' } }; int i; upsdebugx(3, "send: %.*s", (int)strcspn(cmd, "\r"), cmd); if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } for (i = 0; command[i].str; i++) { int retry; if (strncmp(cmd, command[i].str, cmdlen)) { continue; } for (retry = 0; retry < 10; retry++) { int ret; if (langid_fix != -1) { /* Apply langid_fix value */ ret = usb_get_string(udev, command[i].index, langid_fix, (usb_ctrl_charbuf)buf, buflen); } else { ret = usb_get_string_simple(udev, command[i].index, (usb_ctrl_charbuf)buf, buflen); } if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } /* This may serve in the future */ upsdebugx(1, "received %d (%d)", ret, buf[0]); if (langid_fix != -1) { unsigned int di, si, size; /* Limit this check, at least for now */ /* Invalid receive size - message corrupted */ if (ret != buf[0]) { upsdebugx(1, "size mismatch: %d / %d", ret, buf[0]); continue; } /* Simple unicode -> ASCII inplace conversion * FIXME: this code is at least shared with mge-shut/libshut * Create a common function? */ size = (unsigned int)buf[0]; for (di = 0, si = 2; si < size; si += 2) { if (di >= (buflen - 1)) break; if (buf[si + 1]) /* high byte */ buf[di++] = '?'; else buf[di++] = buf[si]; } /* Note: effective range of di should be unsigned char */ buf[di] = 0; ret = (int)di; } /* If the reply lacks the expected terminating CR, add it (if there's enough space) */ if (ret && memchr(buf, '\r', ret) == NULL) { upsdebugx(4, "%s: the reply lacks the expected terminating CR.", __func__); if ((size_t)ret < buflen - 1) { upsdebugx(4, "%s: adding missing terminating CR.", __func__); buf[ret++] = '\r'; buf[ret] = 0; } } /* "UPS No Ack" has a special meaning */ if ( strcspn(buf, "\r") == 10 && !strncasecmp(buf, "UPS No Ack", 10) ) { upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); continue; } /* Replace the first byte of what we received with the correct one */ buf[0] = command[i].prefix; upsdebug_hex(5, "read", buf, (size_t)ret); upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); return ret; } return 0; } /* Echo the unknown command back */ upsdebugx(3, "read: %.*s", (int)strcspn(cmd, "\r"), cmd); return snprintf(buf, buflen, "%s", cmd); } /* Fabula communication subdriver */ static int fabula_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { const struct { const char *str; /* Megatec command */ const int index; /* Fabula string index for this command */ } commands[] = { { "Q1\r", 0x03, }, /* Status */ { "F\r", 0x0d, }, /* Ratings */ { "I\r", 0x0c, }, /* Vendor infos */ { "Q\r", 0x07, }, /* Beeper toggle */ { "C\r", 0x0a, }, /* Cancel shutdown/Load on [0x(0..F)A]*/ { NULL, 0 } }; int i, ret, index = 0; upsdebugx(3, "send: %.*s", (int)strcspn(cmd, "\r"), cmd); if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } for (i = 0; commands[i].str; i++) { if (strncmp(cmd, commands[i].str, cmdlen)) continue; index = commands[i].index; break; } if (!index) { int val2 = -1; double val1 = -1; /* Shutdowns */ if ( sscanf(cmd, "S%lfR%d\r", &val1, &val2) == 2 || sscanf(cmd, "S%lf\r", &val1) == 1 ) { double delay; /* 0x(1+)0 -> shutdown.stayoff (SnR0000) * 0x(1+)8 -> shutdown.return (Sn[Rm], m != 0) * [delay before restart is always 10 seconds] * +0x10 (16dec) = next megatec delay * (min .5 = hex 0x1*; max 10 = hex 0xF*) -> n < 1 ? -> n += .1; n >= 1 ? -> n += 1 */ /* delay: [.5..10] (-> seconds: [30..600]) */ delay = val1 < .5 ? .5 : val1 > 10 ? 10 : val1; if (delay < 1) index = 16 + round((delay - .5) * 10) * 16; else index = 96 + (delay - 1) * 16; /* shutdown.return (Sn[Rm], m != 0) */ if (val2) index += 8; /* Unknown commands */ } else { /* Echo the unknown command back */ upsdebugx(3, "read: %.*s", (int)strcspn(cmd, "\r"), cmd); return snprintf(buf, buflen, "%s", cmd); } } upsdebugx(4, "command index: 0x%02x", (unsigned int)index); /* Send command/Read reply */ ret = usb_get_string_simple(udev, index, (usb_ctrl_charbuf)buf, buflen); if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } /* If the reply lacks the expected terminating CR, add it (if there's enough space) */ if (memchr(buf, '\r', ret) == NULL) { upsdebugx(4, "%s: the reply lacks the expected terminating CR.", __func__); if ((size_t)ret < buflen - 1) { upsdebugx(4, "%s: adding missing terminating CR.", __func__); buf[ret++] = '\r'; buf[ret] = 0; } } upsdebug_hex(5, "read", buf, (size_t)ret); upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); /* The UPS always replies "UPS No Ack" when a supported command * is issued (either if it fails or if it succeeds).. */ if ( strcspn(buf, "\r") == 10 && !strncasecmp(buf, "UPS No Ack", 10) ) { /* ..because of that, always return 0 (with buf empty, * as if it was a timeout): queries will see it as a failure, * instant commands ('megatec' protocol) as a success */ memset(buf, 0, buflen); return 0; } return ret; } /* Hunnox communication subdriver, based on Fabula code above so repeats * much of it currently. Possible future optimization is to refactor shared * code into new routines to be called from both (or more) methods.*/ static int hunnox_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { /* The hunnox_patch was an argument in initial implementation of PR #638 * which added "hunnox" support; keeping it fixed here helps to visibly * track the modifications compared to original fabula_command() e.g. to * facilitate refactoring commented above, in the future. */ /* char hunnox_patch = 1; */ const struct { const char *str; /* Megatec command */ const int index; /* Fabula string index for this command */ } commands[] = { { "Q1\r", 0x03, }, /* Status */ { "F\r", 0x0d, }, /* Ratings */ { "I\r", 0x0c, }, /* Vendor infos */ { "Q\r", 0x07, }, /* Beeper toggle */ { "C\r", 0x0a, }, /* Cancel shutdown/Load on [0x(0..F)A]*/ { NULL, 0 } }; int i, ret, index = 0; upsdebugx(3, "send: %.*s", (int)strcspn(cmd, "\r"), cmd); if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } for (i = 0; commands[i].str; i++) { if (strncmp(cmd, commands[i].str, cmdlen)) continue; index = commands[i].index; break; } if (!index) { int val2 = -1; double val1 = -1; /* Shutdowns */ if ( sscanf(cmd, "S%lfR%d\r", &val1, &val2) == 2 || sscanf(cmd, "S%lf\r", &val1) == 1 ) { double delay; /* 0x(1+)0 -> shutdown.stayoff (SnR0000) * 0x(1+)8 -> shutdown.return (Sn[Rm], m != 0) * [delay before restart is always 10 seconds] * +0x10 (16dec) = next megatec delay * (min .5 = hex 0x1*; max 10 = hex 0xF*) -> n < 1 ? -> n += .1; n >= 1 ? -> n += 1 */ /* delay: [.5..10] (-> seconds: [30..600]) */ delay = val1 < .5 ? .5 : val1 > 10 ? 10 : val1; if (delay < 1) index = 16 + round((delay - .5) * 10) * 16; else index = 96 + (delay - 1) * 16; /* shutdown.return (Sn[Rm], m != 0) */ if (val2) index += 8; /* Unknown commands */ } else { /* Echo the unknown command back */ upsdebugx(3, "read: %.*s", (int)strcspn(cmd, "\r"), cmd); return snprintf(buf, buflen, "%s", cmd); } } upsdebugx(4, "command index: 0x%02x", (unsigned int)index); /* if (hunnox_patch) { */ /* Enable lock-step protocol for Hunnox */ if (hunnox_protocol(index) != 0) { return 0; } /* Seems that if we inform a large buffer, the USB locks. * This value was captured from the Windows "official" client. * Note this should not be a problem programmatically: it just * means that the caller reserved a longer buffer that we need * in practice to write a response into. */ if (buflen > 102) { buflen = 102; } /* } */ /* Send command/Read reply */ if (langid_fix != -1) { ret = usb_get_string(udev, index, langid_fix, (usb_ctrl_charbuf)buf, buflen); } else { ret = usb_get_string_simple(udev, index, (usb_ctrl_charbuf)buf, buflen); } if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } /* if (hunnox_patch) { */ if (langid_fix != -1) { unsigned int di, si, size; /* Limit this check, at least for now */ /* Invalid receive size - message corrupted */ if (ret != buf[0]) { upsdebugx(1, "size mismatch: %d / %d", ret, buf[0]); return 0; } /* Simple unicode -> ASCII inplace conversion * FIXME: this code is at least shared with mge-shut/libshut * Create a common function? */ size = (unsigned int)buf[0]; for (di = 0, si = 2; si < size; si += 2) { if (di >= (buflen - 1)) break; if (buf[si + 1]) /* high byte */ buf[di++] = '?'; else buf[di++] = buf[si]; } /* Note: effective range of di should be unsigned char */ buf[di] = 0; ret = (int)di; } /* } */ upsdebug_hex(5, "read", buf, (size_t)ret); upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); /* The UPS always replies "UPS No Ack" when a supported command * is issued (either if it fails or if it succeeds).. */ if ( strcspn(buf, "\r") == 10 && !strncasecmp(buf, "UPS No Ack", 10) ) { /* ..because of that, always return 0 (with buf empty, * as if it was a timeout): queries will see it as a failure, * instant commands ('megatec' protocol) as a success */ memset(buf, 0, buflen); return 0; } return ret; } /* Fuji communication subdriver */ static int fuji_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { unsigned char tmp[8]; char command[SMALLBUF] = "", read[SMALLBUF] = ""; int ret, val2; unsigned char answer_len; double val1; size_t i; const struct { const char *command; /* Megatec command */ const unsigned char answer_len; /* Expected length of the answer * to the ongoing query */ } query[] = { { "Q1", 47 }, { "F", 22 }, { "I", 39 }, { NULL, 0 } }; if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } /* * Queries (b1..b8) sent (as a 8-bytes interrupt) to the UPS * adopt the following scheme: * * b1: 0x80 * b2: 0x06 * b3: * b4: 0x03 * b5..bn: * bn+1..b7: [] * b8: * * Where: * Length (in Hex) of the command (without the trailing CR) + 1 * Command/query (without the trailing CR) * [] 0x00 padding to the 7th byte * Expected length (in Hex) of the answer to the ongoing * query (0 when no reply is expected, i.e. commands) * * Replies to queries (commands are followed by action without * any reply) are sent from the UPS (in 8-byte chunks) with * 0x00 padding after the trailing CR to full 8 bytes. * */ /* Send command */ /* Remove the CR */ snprintf(command, sizeof(command), "%.*s", (int)strcspn(cmd, "\r"), cmd); /* Length of the command that will be sent to the UPS can be * at most: 8 - 5 (0x80, 0x06, , 0x03, ) = 3. * As a consequence also 'SnRm' commands (shutdown.{return,stayoff} * and load.off) are not supported. * So, map all the 'SnRm' shutdown.returns (m != 0) as the * corresponding 'Sn' commands, meanwhile ignoring ups.delay.start * and making the UPS turn on the load as soon as power is back. */ if (sscanf(cmd, "S%lfR%d\r", &val1, &val2) == 2 && val2) { upsdebugx(4, "%s: trimming '%s' to '%.*s'", __func__, command, 3, command); command[3] = 0; } /* Too long command */ if (strlen(command) > 3) { /* Be 'megatec-y': echo the unsupported command back */ upsdebugx(3, "%s: unsupported command %s", __func__, command); return snprintf(buf, buflen, "%.*s", (int)cmdlen, cmd); } /* Expected length of the answer to the ongoing query * (0 when no reply is expected, i.e. commands) */ answer_len = 0; for (i = 0; query[i].command; i++) { if (strcmp(command, query[i].command)) continue; answer_len = query[i].answer_len; break; } memset(tmp, 0, sizeof(tmp)); /* 0x80 */ tmp[0] = 0x80; /* 0x06 */ tmp[1] = 0x06; /* ; per above under 3 */ tmp[2] = (unsigned char)strlen(command) + 1; /* 0x03 */ tmp[3] = 0x03; /* */ memcpy(&tmp[4], command, strlen(command)); /* */ tmp[7] = answer_len; upsdebug_hex(4, "command", (char *)tmp, 8); /* Write data */ ret = usb_interrupt_write(udev, USB_ENDPOINT_OUT | 2, (const usb_ctrl_charbuf)tmp, 8, USB_TIMEOUT); if (ret <= 0) { upsdebugx(3, "send: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } upsdebugx(3, "send: %s", command); /* Read reply */ memset(buf, 0, buflen); for (i = 0; (i <= buflen - 8) && (memchr(buf, '\r', buflen) == NULL); i += (size_t)ret) { /* Read data in 8-byte chunks */ ret = usb_interrupt_read(udev, USB_ENDPOINT_IN | 1, (usb_ctrl_charbuf)&buf[i], 8, 1000); /* Any errors here mean that we are unable to read a reply * (which will happen after successfully writing a command * to the UPS) */ if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } snprintf(read, sizeof(read), "read [%3d]", (int)i); upsdebug_hex(5, read, &buf[i], (size_t)ret); } upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); /* As Fuji units return the reply in 8-byte chunks always padded to the 8th byte with 0x00, we need to calculate and return the length of the actual response here. */ return (int)strlen(buf); } /* Phoenixtec (Masterguard) communication subdriver */ static int phoenixtec_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { int ret; char *p, *e = NULL; char *l[] = { "T", "TL", "S", "C", "CT", "M", "N", "O", "SRC", "FCLR", "SS", "TUD", "SSN", NULL }; /* commands that don't return an answer */ char **lp; if (cmdlen > INT_MAX) { upsdebugx(3, "%s: requested command is too long (%" PRIuSIZE ")", __func__, cmdlen); return 0; } if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } if ((ret = usb_control_msg(udev, USB_ENDPOINT_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x0d, 0, 0, (usb_ctrl_charbuf)cmd, (int)cmdlen, 1000)) <= 0 ) { upsdebugx(3, "send: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); *buf = '\0'; return ret; } for (lp = l; *lp != NULL; lp++) { const char *q; int b; p = *lp; q = cmd; b = 1; while (*p != '\0') { if (*p++ != *q++) { b = 0; break; } } if (b && *q >= 'A' && *q <= 'Z') b = 0; /* "M" not to match "MSO" */ if (b) { upsdebugx(4, "command %s returns no answer", *lp); *buf = '\0'; return 0; } } for (p = buf; p < buf + buflen; p += ret) { /* buflen constrained to INT_MAX above, so we can cast: */ if ((ret = usb_interrupt_read(udev, USB_ENDPOINT_IN | 1, (usb_ctrl_charbuf)p, (int)(buf + buflen - p), 1000)) <= 0 ) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); *buf = '\0'; return ret; } if ((e = memchr(p, '\r', (size_t)ret)) != NULL) break; } if (e != NULL && ++e < buf + buflen) { *e = '\0'; /* buflen constrained to INT_MAX above, so we can cast: */ return (int)(e - buf); } else { upsdebugx(3, "read: buflen %" PRIuSIZE " too small", buflen); *buf = '\0'; return 0; } } /* SNR communication subdriver */ static int snr_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { /*ATTENTION: This subdriver uses short buffer with length 102 byte*/ const struct { const char *str; /* Megatec command */ const int index; /* String index for this command */ const char prefix; /* Character to replace the first byte in reply */ } command[] = { { "Q1\r", 0x03, '(' }, { "F\r", 0x0d, '#' }, { "I\r", 0x0c, '#' }, { NULL, 0, '\0' } }; int i; upsdebugx(3, "send: %.*s", (int)strcspn(cmd, "\r"), cmd); if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } if (buflen < 102) { upsdebugx(4, "size of buf less than 102 byte!"); return 0; } /* Prepare SNR-UPS for communication. * Without the interrupt UPS returns zeros for some time, * and afterwards NUT returns a communications error. */ usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)buf, 102, 1000); for (i = 0; command[i].str; i++) { int retry; if (strncmp(cmd, command[i].str, cmdlen)) { continue; } for (retry = 0; retry < 10; retry++) { unsigned int di, si, size; int ret; ret = usb_get_string(udev, command[i].index, langid_fix, (usb_ctrl_charbuf)buf, 102); if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } /* This may serve in the future */ upsdebugx(1, "received %d (%d)", ret, buf[0]); if (ret != buf[0]) { upsdebugx(1, "size mismatch: %d / %d", ret, buf[0]); continue; } /* Simple unicode -> ASCII inplace conversion * FIXME: this code is at least shared with mge-shut/libshut * Create a common function? */ size = (unsigned int)buf[0]; for (di = 0, si = 2; si < size; si += 2) { if (di >= (buflen - 1)) break; if (buf[si + 1]) /* high byte */ buf[di++] = '?'; else buf[di++] = buf[si]; } /* Note: effective range of di should be unsigned char */ buf[di] = 0; ret = (int)di; /* "UPS No Ack" has a special meaning */ if ( strcspn(buf, "\r") == 10 && !strncasecmp(buf, "UPS No Ack", 10) ) { upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); continue; } /* Replace the first byte of what we received with the correct one */ buf[0] = command[i].prefix; upsdebug_hex(5, "read", buf, (size_t)ret); upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); return ret; } return 0; } /* Echo the unknown command back */ upsdebugx(3, "read: %.*s", (int)strcspn(cmd, "\r"), cmd); return snprintf(buf, buflen, "%s", cmd); } static int ablerex_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { size_t iii, len, idx, retry; char tmp[64]; char tmpryy[64]; upsdebugx(3, "send: %.*s", (int)strcspn(cmd, "\r"), cmd); if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } for (retry = 0; retry < 3; retry++) { int ret; memset(buf, 0, buflen); tmp[0] = 0x05; tmp[1] = 0; tmp[2] = 1 + (char)strcspn(cmd, "\r"); for (iii = 0 ; iii < (unsigned char)tmp[2] && iii < cmdlen && (iii + 3) < sizeof(tmp) ; iii++) { tmp[3+iii] = cmd[iii]; } ret = usb_control_msg(udev, 0x21, 0x09, 0x305, 0, (usb_ctrl_charbuf)tmp, 47, 1000); upsdebugx(3, "R11 read: %s", ret ? nut_usb_strerror(ret) : "timeout"); usleep(500000); tmpryy[0] = 0x05; ret = usb_control_msg(udev, 0xA1, 0x01, 0x305, 0, (usb_ctrl_charbuf)tmpryy, 47, 1000); upsdebugx(3, "R2 read%d: %.*s", ret, ret, tmpryy); len = 0; for (idx = 0 ; idx < 47 ; idx++) { buf[idx] = tmpryy[idx]; if (tmpryy[idx] == '\r') { len = idx; break; } } upsdebugx(3, "R3 read%" PRIuSIZE ": %.*s", len, (int)len, tmpryy); if (len > 0) { len ++; } if (ret <= 0) { upsdebugx(3, "read: %s", ret ? nut_usb_strerror(ret) : "timeout"); return ret; } upsdebugx(1, "received %d (%d)", ret, buf[0]); if ((!strcasecmp(cmd, "Q1\r")) && len != 47) continue; if ((!strcasecmp(cmd, "I\r")) && len != 39) continue; if ((!strcasecmp(cmd, "F\r")) && len != 22) continue; if ((!strcasecmp(cmd, "Q5\r")) && len != 22) { buf[0] = '('; for (idx = 1 ; idx < 47 ; idx++) { buf[idx] = 0; } upsdebugx(3, "read Q5 Fail..."); return 22; } upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); return len; } return 0; } static void *ablerex_subdriver_fun(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &ablerex_command; return NULL; } /* Gtec communication subdriver (based on Cypress) */ static int gtec_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { char tmp[SMALLBUF]; int ret = 0; size_t i, tmpstrlen; size_t tmplen = cmdlen > sizeof(tmp) ? sizeof(tmp) : cmdlen; if (buflen > INT_MAX) { upsdebugx(3, "%s: requested to read too much (%" PRIuSIZE "), " "reducing buflen to (INT_MAX-1)", __func__, buflen); buflen = (INT_MAX - 1); } /* Send command */ memset(tmp, 0, sizeof(tmp)); memcpy(tmp, cmd, tmplen); tmp[sizeof(tmp) - 1] = '\0'; tmpstrlen = strlen(tmp); for (i = 0; i < tmpstrlen; i += (size_t)ret) { /* Write data in 8-byte chunks */ /* ret = usb->set_report(udev, 0, (unsigned char *)&tmp[i], 8); */ ret = usb_control_msg(udev, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x09, 0x02, 0, (usb_ctrl_charbuf)&tmp[i], 8, 5000); if (ret <= 0) { upsdebugx(3, "send: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } } upsdebugx(3, "send: %.*s", (int)strcspn(tmp, "\r"), tmp); /* Read reply */ memset(buf, 0, buflen); for (i = 0; (i <= buflen-128) && (memchr(buf, '\r', buflen) == NULL); i += (size_t)ret) { /* Read data in 8-byte chunks */ /* ret = usb->get_interrupt(udev, (unsigned char *)&buf[i], 8, 1000); */ ret = usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)&buf[i], 128, 1000); /* Any errors here mean that we are unable to read a reply * (which will happen after successfully writing a command * to the UPS) */ if (ret <= 0) { upsdebugx(3, "read: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } snprintf(tmp, sizeof(tmp), "read [% 3d]", (int)i); upsdebug_hex(5, tmp, &buf[i], (size_t)ret); } upsdebugx(3, "read: %.*s", (int)strcspn(buf, "\r"), buf); if (i > INT_MAX) { upsdebugx(3, "%s: read too much (%" PRIuSIZE ")", __func__, i); return -1; } return (int)i; } static struct { bool_t initialized; bool_t ok; uint8_t in_endpoint_address; uint8_t in_bmAttributes; uint16_t in_wMaxPacketSize; uint8_t out_endpoint_address; uint8_t out_bmAttributes; uint16_t out_wMaxPacketSize; } armac_endpoint_cache = { .initialized = FALSE, .ok = FALSE }; static void load_armac_endpoint_cache(void) { #if WITH_LIBUSB_1_0 int ret; struct libusb_device *dev; struct libusb_config_descriptor *config_descriptor; bool_t found_in = FALSE; bool_t found_out = FALSE; #endif /* WITH_LIBUSB_1_0 */ if (armac_endpoint_cache.initialized) { return; } armac_endpoint_cache.initialized = TRUE; armac_endpoint_cache.ok = FALSE; #if WITH_LIBUSB_1_0 dev = libusb_get_device(udev); if (!dev) { upsdebugx(4, "load_armac_endpoint_cache: unable to libusb_get_device"); return; } ret = libusb_get_active_config_descriptor(dev, &config_descriptor); if (ret) { upsdebugx(4, "load_armac_endpoint_cache: libusb_get_active_config_descriptor error=%d", ret); libusb_free_config_descriptor(config_descriptor); return; } if (config_descriptor->bNumInterfaces != 1) { upsdebugx(4, "load_armac_endpoint_cache: unexpected config_descriptor->bNumInterfaces=%d", config_descriptor->bNumInterfaces); libusb_free_config_descriptor(config_descriptor); return; } else { /* Here and below, the "else" is for C99-satisfying new variable scoping */ const struct libusb_interface *interface = &config_descriptor->interface[0]; if (interface->num_altsetting != 1) { upsdebugx(4, "load_armac_endpoint_cache: unexpected interface->num_altsetting=%d", interface->num_altsetting); libusb_free_config_descriptor(config_descriptor); return; } else { uint8_t i; const struct libusb_interface_descriptor *interface_descriptor = &interface->altsetting[0]; if (interface_descriptor->bNumEndpoints != 2) { upsdebugx(4, "load_armac_endpoint_cache: unexpected interface_descriptor->bNumEndpoints=%d", interface_descriptor->bNumEndpoints); libusb_free_config_descriptor(config_descriptor); return; } for (i = 0; i < interface_descriptor->bNumEndpoints; i++) { const struct libusb_endpoint_descriptor *endpoint = &interface_descriptor->endpoint[i]; if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) { found_in = TRUE; armac_endpoint_cache.in_endpoint_address = endpoint->bEndpointAddress; armac_endpoint_cache.in_bmAttributes = endpoint->bmAttributes; armac_endpoint_cache.in_wMaxPacketSize = endpoint->wMaxPacketSize; } else { found_out = TRUE; armac_endpoint_cache.out_endpoint_address = endpoint->bEndpointAddress; armac_endpoint_cache.out_bmAttributes = endpoint->bmAttributes; armac_endpoint_cache.out_wMaxPacketSize = endpoint->wMaxPacketSize; } } } } if (found_in || found_out) { armac_endpoint_cache.ok = TRUE; upsdebugx(4, "%s: in_endpoint_address=%02x, in_bmAttributes=%02d, out_endpoint_address=%02d, out_bmAttributes=%02d", __func__, armac_endpoint_cache.in_endpoint_address, armac_endpoint_cache.in_bmAttributes, armac_endpoint_cache.out_endpoint_address, armac_endpoint_cache.out_bmAttributes); } libusb_free_config_descriptor(config_descriptor); #else /* WITH_LIBUSB_1_0 */ upsdebugx(4, "%s: SKIP: not implemented for libusb-0.1 or serial connections", __func__); #endif /* !WITH_LIBUSB_1_0 */ } /* Armac communication subdriver * * This reproduces a communication protocol used by an old PowerManagerII * software, which doesn't seem to be Armac specific. The banner is: "2004 * Richcomm Technologies, Inc. Dec 27 2005 ver 1.1." Maybe other Richcomm UPSes * would work with this - better than with the richcomm_usb driver. */ #define ARMAC_READ_SIZE_FOR_CONTROL 6 #define ARMAC_READ_SIZE_FOR_INTERRUPT 64 static int armac_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { char tmpbuf[ARMAC_READ_SIZE_FOR_INTERRUPT]; int ret = 0; size_t i, bufpos; const size_t cmdstrlen = strnlen(cmd, cmdlen); /* Length of cmd string (excluding terminating '\0'), or cmdlen if the string is too long */ const size_t cmddatalen = cmdstrlen >= cmdlen ? cmdlen : cmdstrlen + 1; /* Amount of useful/valid data bytes in cmd string (max=cmdlen, or length of cmd+'\0' if the string is short enough) */ const size_t tmplen = cmddatalen > sizeof(tmpbuf) ? sizeof(tmpbuf) : cmddatalen; /* How much of cmd[] we can copy into tmp[] so it fits (and remains useful), including the terminating '\0' */ bool_t use_interrupt = FALSE; int read_size = ARMAC_READ_SIZE_FOR_CONTROL; /* UPS ignores (doesn't echo back) unsupported commands which makes * the initialization long. List commands tested to be unsupported: */ const char *unsupported[] = { "QGS\r", "QS\r", "QPI\r", "M\r", "D\r", NULL }; if (cmdstrlen >= cmdlen || cmd[cmdstrlen - 1] != '\0') { upsdebugx(2, "%s: strlen(cmd) > cmdlen (provided by caller), would effectively truncate!", __func__); /* TOTHINK: // cmd[cmdlen] = '\0'; */ } if (cmdstrlen + 1 > sizeof(tmpbuf)) { upsdebugx(2, "%s: strlen(cmd) or cmdlen (provided by caller) are longer than tmp buffer, would effectively truncate!", __func__); /* TOTHINK: // cmd[sizeof(tmpbuf)] = '\0'; */ } if (!armac_endpoint_cache.initialized) { load_armac_endpoint_cache(); } for (i = 0; unsupported[i] != NULL; i++) { if (strcmp(cmd, unsupported[i]) == 0) { upsdebugx(2, "armac: unsupported cmd: %.*s", (int)strcspn(cmd, "\r"), cmd); return snprintf(buf, buflen, "%s", cmd); } } upsdebugx(4, "armac command %.*s", (int)strcspn(cmd, "\r"), cmd); #if WITH_LIBUSB_1_0 /* Be conservative and do not break old Armac UPSes */ use_interrupt = armac_endpoint_cache.ok && armac_endpoint_cache.in_endpoint_address == 0x82 && armac_endpoint_cache.in_bmAttributes & LIBUSB_TRANSFER_TYPE_INTERRUPT && armac_endpoint_cache.out_endpoint_address == 0x02 && armac_endpoint_cache.out_bmAttributes & LIBUSB_TRANSFER_TYPE_INTERRUPT && armac_endpoint_cache.in_wMaxPacketSize == 64; #endif /* WITH_LIBUSB_1_0 */ if (use_interrupt && cmddatalen < armac_endpoint_cache.in_wMaxPacketSize) { /* We deal with strings here, always leave last byte as '\0' * and the first byte tmpbuf[0] is used for the string length. * So tmpdatalen is how much of cmd we can copy into tmp so it * fits and makes sense (just the whole string if short enough). */ size_t tmpdatalen = tmplen < sizeof(tmpbuf) - 1 ? tmplen : sizeof(tmpbuf) - 2; memset(tmpbuf, 0, sizeof(tmpbuf)); tmpbuf[0] = 0xa0 + tmpdatalen; memcpy(tmpbuf + 1, cmd, tmpdatalen); /* Include terminating '\0' in the transfer */ ret = usb_interrupt_write(udev, armac_endpoint_cache.out_endpoint_address, (usb_ctrl_charbuf)tmpbuf, tmpdatalen + 1, 5000); read_size = ARMAC_READ_SIZE_FOR_INTERRUPT; } else { /* Cleanup buffer before sending a new command */ for (i = 0; i < 10; i++) { ret = usb_interrupt_read(udev, 0x81, (usb_ctrl_charbuf)tmpbuf, ARMAC_READ_SIZE_FOR_CONTROL, 100); if (ret != ARMAC_READ_SIZE_FOR_CONTROL) { /* Timeout - buffer is clean. */ break; } upsdebugx(4, "armac cleanup ret i=%" PRIuSIZE " ret=%d ctrl=%02hhx", i, ret, tmpbuf[0]); } /* Send command to the UPS in 3-byte chunks. Most fit 1 chunk, except for eg. * parameterized tests. */ for (i = 0; i < cmddatalen;) { const size_t bytes_to_send = (cmddatalen <= (i + 3)) ? (cmddatalen - i) : 3; memset(tmpbuf, 0, sizeof(tmpbuf)); tmpbuf[0] = 0xa0 + bytes_to_send; memcpy(tmpbuf + 1, cmd + i, bytes_to_send); ret = usb_control_msg(udev, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x09, 0x200, 0, (usb_ctrl_charbuf)tmpbuf, 4, 5000); i += bytes_to_send; } } if (ret <= 0) { upsdebugx(1, "send control: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret; } /* Wait for response to buffer */ usleep(2000); memset(buf, 0, buflen); bufpos = 0; while (bufpos + read_size + 1 < buflen) { size_t bytes_available; /* Read data in 6-byte chunks */ ret = usb_interrupt_read(udev, use_interrupt ? armac_endpoint_cache.in_endpoint_address : 0x81, (usb_ctrl_charbuf)tmpbuf, read_size, 1000); /* Any errors here mean that we are unable to read a reply * (which will happen after successfully writing a command * to the UPS) */ if (ret != read_size) { /* NOTE: If end condition is invalid for particular UPS we might make one * request more and get this error. If bufpos > (say) 10 this could be ignored * and the reply correctly read. */ upsdebugx(1, "interrupt read error: %s (%d)", ret ? nut_usb_strerror(ret) : "timeout", ret); return ret < 0 ? ret : (int)bufpos; } upsdebugx(4, "read: ret %d buf %02hhx: %02hhx %02hhx %02hhx %02hhx %02hhx >%c%c%c%c%c<", ret, tmpbuf[0], tmpbuf[1], tmpbuf[2], tmpbuf[3], tmpbuf[4], tmpbuf[5], tmpbuf[1], tmpbuf[2], tmpbuf[3], tmpbuf[4], tmpbuf[5]); /* * On most tested devices (including R/2000I/PSW) this was equal to the number of * bytes returned in the buffer, but on some newer UPS (R/3000I/PF1) it was 1 more * (1 control + 5 bytes transferred and bytes_available equal to 6 instead of 5). * * Current assumption is that this is number of bytes available on the UPS side * with up to 5 (ret - 1) transferred. */ bytes_available = (unsigned char)tmpbuf[0] & 0x3f; if (bytes_available == 0) { /* End of transfer */ break; } if (bytes_available > (unsigned)read_size - 1) { /* Single interrupt transfer has 1 control + 5 data bytes */ bytes_available = read_size - 1; } /* Copy bytes into the final buffer while detecting end of line - \r */ for (i = 0; i < bytes_available; i++) { if (tmpbuf[i + 1] == 0x00 && bufpos == 0) { /* Happens when a manually turned off UPS is connected to the USB */ upsdebugx(3, "null byte read - is UPS off?"); return 0; } /* Vultech V2000 seems to use 0x00 within status bits. This might mean "unsupported". * or something else completely. */ if (tmpbuf[i + 1] == 0x00) { if (bufpos >= 38) { upsdebugx(3, "found null byte in status bits at %" PRIuSIZE " byte, assuming 0.", bufpos); buf[bufpos++] = '0'; continue; } else { upsdebugx(3, "found null byte in data stream - interrupting read."); /* Break through two loops */ goto end_of_message; } } buf[bufpos++] = tmpbuf[i + 1]; if (tmpbuf[i + 1] == 0x0d) { if (i + 1 != bytes_available) { upsdebugx(3, "trailing bytes in serial transmission found: %" PRIuSIZE " copied out of %" PRIuSIZE, i + 1, bytes_available ); } /* Break through two loops */ goto end_of_message; } } if (bytes_available <= 2) { /* Slow down, let the UPS buffer more bytes */ usleep(10000); } } end_of_message: if (bufpos + read_size >= buflen) { upsdebugx(2, "Protocol error, too much data read."); return -1; } upsdebugx(3, "armac command %.*s response read: '%.*s'", (int)strcspn(cmd, "\r"), cmd, (int)strcspn(buf, "\r"), buf ); return (int)bufpos; } static void *cypress_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &cypress_command; return NULL; } static void *sgs_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &sgs_command; return NULL; } static void *ippon_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &ippon_command; return NULL; } static void *krauler_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &krauler_command; return NULL; } static void *phoenix_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &phoenix_command; return NULL; } static void *fabula_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &fabula_command; return NULL; } static void *phoenixtec_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &phoenixtec_command; return NULL; } /* Note: the "hunnox_subdriver" name is taken by the subdriver_t structure */ static void *fabula_hunnox_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &hunnox_command; return NULL; } static void *fuji_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &fuji_command; return NULL; } static void *snr_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &snr_command; return NULL; } static void *armac_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &armac_command; return NULL; } /* USB device match structure */ typedef struct { const int vendorID; /* USB device's VendorID */ const int productID; /* USB device's ProductID */ const char *vendor; /* USB device's iManufacturer string */ const char *product; /* USB device's iProduct string */ void *(*fun)(USBDevice_t *); /* Handler for specific processing */ } qx_usb_device_id_t; /* USB VendorID/ProductID/iManufacturer/iProduct match - note: rightmost comment is used for naming rules by tools/nut-usbinfo.pl */ static qx_usb_device_id_t qx_usb_id[] = { { USB_DEVICE(0x05b8, 0x0000), NULL, NULL, &cypress_subdriver }, /* Agiler UPS */ { USB_DEVICE(0xffff, 0x0000), NULL, NULL, &ablerex_subdriver_fun }, /* Ablerex 625L USB (Note: earlier best-fit was "krauler_subdriver" before PR #1135) */ { USB_DEVICE(0x1cb0, 0x0035), NULL, NULL, &krauler_subdriver }, /* Legrand Daker DK / DK Plus */ { USB_DEVICE(0x0665, 0x5161), NULL, NULL, &cypress_subdriver }, /* Belkin F6C1200-UNV/Voltronic Power UPSes */ { USB_DEVICE(0x06da, 0x0002), "Phoenixtec Power","USB Cable (V2.00)", &phoenixtec_subdriver },/* Masterguard A Series */ { USB_DEVICE(0x06da, 0x0002), NULL, NULL, &cypress_subdriver }, /* Online Yunto YQ450 */ { USB_DEVICE(0x06da, 0x0003), NULL, NULL, &ippon_subdriver }, /* Mustek Powermust */ { USB_DEVICE(0x06da, 0x0004), NULL, NULL, &cypress_subdriver }, /* Phoenixtec Innova 3/1 T */ { USB_DEVICE(0x06da, 0x0005), NULL, NULL, &cypress_subdriver }, /* Phoenixtec Innova RT */ { USB_DEVICE(0x06da, 0x0201), NULL, NULL, &cypress_subdriver }, /* Phoenixtec Innova T */ { USB_DEVICE(0x06da, 0x0601), NULL, NULL, &phoenix_subdriver }, /* Online Zinto A */ { USB_DEVICE(0x0f03, 0x0001), NULL, NULL, &cypress_subdriver }, /* Unitek Alpha 1200Sx */ { USB_DEVICE(0x14f0, 0x00c9), NULL, NULL, &phoenix_subdriver }, /* GE EP series */ { USB_DEVICE(0x0483, 0x0035), NULL, NULL, &sgs_subdriver }, /* TS Shara UPSes; vendor ID 0x0483 is from ST Microelectronics - with product IDs delegated to different OEMs */ { USB_DEVICE(0x0001, 0x0000), "MEC", "MEC0003", &fabula_subdriver }, /* Fideltronik/MEC LUPUS 500 USB */ { USB_DEVICE(0x0001, 0x0000), NULL, "MEC0003", &fabula_hunnox_subdriver }, /* Hunnox HNX 850, reported to also help support Powercool and some other devices; closely related to fabula with tweaks */ { USB_DEVICE(0x0001, 0x0000), "ATCL FOR UPS", "ATCL FOR UPS", &fuji_subdriver }, /* Fuji UPSes */ { USB_DEVICE(0x0001, 0x0000), NULL, NULL, &krauler_subdriver }, /* Krauler UP-M500VA */ { USB_DEVICE(0x0001, 0x0000), NULL, "MEC0003", &snr_subdriver }, /* SNR-UPS-LID-XXXX UPSes */ { USB_DEVICE(0x0925, 0x1234), NULL, NULL, &armac_subdriver }, /* Armac UPS and maybe other richcomm-like or using old PowerManagerII software */ /* End of list */ { -1, -1, NULL, NULL, NULL } }; static int qx_is_usb_device_supported(qx_usb_device_id_t *usb_device_id_list, USBDevice_t *device) { int retval = NOT_SUPPORTED; qx_usb_device_id_t *usbdev; for (usbdev = usb_device_id_list; usbdev->vendorID != -1; usbdev++) { if (usbdev->vendorID != device->VendorID) continue; /* Flag as possibly supported if we see a known vendor */ retval = POSSIBLY_SUPPORTED; if (usbdev->productID != device->ProductID) continue; if (usbdev->vendor && (!device->Vendor || strcasecmp(usbdev->vendor, device->Vendor)) ) { continue; } if (usbdev->product && (!device->Product || strcasecmp(usbdev->product, device->Product)) ) { continue; } /* Call the specific handler, if it exists */ if (usbdev->fun != NULL) (*usbdev->fun)(device); return SUPPORTED; } return retval; } static int device_match_func(USBDevice_t *hd, void *privdata) { NUT_UNUSED_VARIABLE(privdata); if (subdriver_command) { return 1; } switch (qx_is_usb_device_supported(qx_usb_id, hd)) { case SUPPORTED: return 1; case POSSIBLY_SUPPORTED: case NOT_SUPPORTED: default: return 0; } } static USBDeviceMatcher_t device_matcher = { &device_match_func, NULL, NULL }; #endif /* QX_USB && !TESTING */ /* == Driver functions implementations == */ /* See header file for details. */ int instcmd(const char *cmdname, const char *extradata) { item_t *item; char value[SMALLBUF]; if (!strcasecmp(cmdname, "beeper.off")) { /* Compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.off' command has been renamed to 'beeper.disable'"); return instcmd("beeper.disable", NULL); } if (!strcasecmp(cmdname, "beeper.on")) { /* Compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.on' command has been renamed to 'beeper.enable'"); return instcmd("beeper.enable", NULL); } upsdebug_INSTCMD_STARTING(cmdname, extradata); /* Historically we did user-visible LOG_INFO in this driver * with this markup, so we still do */ upslogx(LOG_INFO, "%s(%s, %s)", __func__, NUT_STRARG(cmdname), extradata ? extradata : "[NULL]"); /* Retrieve item by command name */ item = find_nut_info(cmdname, QX_FLAG_CMD, QX_FLAG_SKIP); /* Check for fallback if not found */ if (item == NULL) { /* Process aliases/fallbacks */ if (!strcasecmp(cmdname, "load.on")) { return instcmd("load.on.delay", "0"); } if (!strcasecmp(cmdname, "load.off")) { return instcmd("load.off.delay", "0"); } if (!strcasecmp(cmdname, "shutdown.return")) { int ret; /* Ensure "ups.start.auto" is set to "yes", if supported */ if (dstate_getinfo("ups.start.auto")) { if (setvar("ups.start.auto", "yes") != STAT_SET_HANDLED) { upslogx(LOG_INSTCMD_FAILED, "%s: FAILED", __func__); return STAT_INSTCMD_FAILED; } } ret = instcmd("load.on.delay", dstate_getinfo("ups.delay.start")); if (ret != STAT_INSTCMD_HANDLED) { return ret; } return instcmd("load.off.delay", dstate_getinfo("ups.delay.shutdown")); } if (!strcasecmp(cmdname, "shutdown.stayoff")) { int ret; /* Ensure "ups.start.auto" is set to "no", if supported */ if (dstate_getinfo("ups.start.auto")) { if (setvar("ups.start.auto", "no") != STAT_SET_HANDLED) { upslogx(LOG_INSTCMD_FAILED, "%s: FAILED", __func__); return STAT_INSTCMD_FAILED; } } ret = instcmd("load.on.delay", "-1"); if (ret != STAT_INSTCMD_HANDLED) { return ret; } return instcmd("load.off.delay", dstate_getinfo("ups.delay.shutdown")); } upsdebugx(2, "%s: command %s unavailable", __func__, cmdname); return STAT_INSTCMD_INVALID; } /* If extradata is empty, use the default value * from the QX to NUT table, if any */ extradata = extradata ? extradata : item->dfl; snprintf(value, sizeof(value), "%s", extradata ? extradata : ""); errno = 0; /* Preprocess command */ if (item->preprocess != NULL && item->preprocess(item, value, sizeof(value)) ) { /* Something went wrong */ upslogx(LOG_INSTCMD_FAILED, "%s: FAILED", __func__); return (errno == EINVAL ? STAT_INSTCMD_CONVERSION_FAILED : STAT_INSTCMD_FAILED); } /* No preprocess function -> nothing to do with extradata */ if (item->preprocess == NULL) snprintf(value, sizeof(value), "%s", ""); /* Send the command, get the reply */ upslog_INSTCMD_POWERSTATE_CHECKED(cmdname, extradata); errno = 0; if (qx_process(item, strlen(value) > 0 ? value : NULL)) { /* Something went wrong */ upslogx(LOG_INSTCMD_FAILED, "%s: FAILED", __func__); return (errno == EINVAL ? STAT_INSTCMD_CONVERSION_FAILED : STAT_INSTCMD_FAILED); } /* We got a reply from the UPS: * either subdriver->accepted (-> command handled) * or the command itself echoed back (-> command failed) */ if (strlen(item->value) > 0) { if (subdriver->accepted != NULL && !strcasecmp(item->value, subdriver->accepted) ) { upslogx(LOG_INFO, "%s: SUCCEED", __func__); /* Set the status so that SEMI_STATIC vars are polled */ data_has_changed = TRUE; return STAT_INSTCMD_HANDLED; } upslogx(LOG_INSTCMD_FAILED, "%s: FAILED", __func__); return STAT_INSTCMD_FAILED; } /* No reply from the UPS -> command handled */ upslogx(LOG_INFO, "%s: SUCCEED", __func__); /* Set the status so that SEMI_STATIC vars are polled */ data_has_changed = TRUE; return STAT_INSTCMD_HANDLED; } /* See header file for details. */ int setvar(const char *varname, const char *val) { item_t *item; char value[SMALLBUF]; st_tree_t *root = (st_tree_t *)dstate_getroot(); int ok = 0; upsdebug_SET_STARTING(varname, val); /* Retrieve variable */ item = find_nut_info(varname, QX_FLAG_SETVAR, QX_FLAG_SKIP); if (item == NULL) { upsdebugx(2, "%s: element %s unavailable", __func__, varname); return STAT_SET_UNKNOWN; } /* No NUT variable is available for this item, so we're handling * a one-time setvar from ups.conf */ if (item->qxflags & QX_FLAG_NONUT) { const char *userval; /* Nothing to do */ if (!testvar(item->info_type)) { upsdebugx(2, "%s: nothing to do... [%s]", __func__, item->info_type); return STAT_SET_HANDLED; } userval = getval(item->info_type); upslogx(LOG_INFO, "%s(%s, %s)", __func__, varname, userval ? userval : "[NULL]"); snprintf(value, sizeof(value), "%s", userval ? userval : ""); /* This item is available in NUT */ } else { upslogx(LOG_INFO, "%s(%s, %s)", __func__, varname, strlen(val) ? val : "[NULL]"); if (!strlen(val)) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: value not given for %s", __func__, item->info_type); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } snprintf(value, sizeof(value), "%s", val); /* Nothing to do */ if (!strcasecmp(dstate_getinfo(item->info_type), value)) { upslogx(LOG_INFO, "%s: nothing to do... [%s]", __func__, item->info_type); return STAT_SET_HANDLED; } } /* Check if given value is in the range of accepted values (range) */ if (item->qxflags & QX_FLAG_RANGE) { long valuetoset, min, max; if (strspn(value, "0123456789 .") != strlen(value)) { /* FIXME: ..._CONVERSION_FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: non numerical value [%s: %s]", __func__, item->info_type, value); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } valuetoset = strtol(value, NULL, 10); /* No NUT var is available for this item, so * take its range from qx2nut table */ if (item->qxflags & QX_FLAG_NONUT) { info_rw_t *rvalue; if (!strlen(value)) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: value not given for %s", __func__, item->info_type); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } min = max = -1; /* Loop on all existing values */ for (rvalue = item->info_rw; rvalue != NULL && strlen(rvalue->value) > 0; rvalue++) { if (rvalue->preprocess && rvalue->preprocess(rvalue->value, sizeof(rvalue->value)) ) { continue; } if (min < 0) { min = strtol(rvalue->value, NULL, 10); continue; } max = strtol(rvalue->value, NULL, 10); /* valuetoset is in the range */ if (min <= valuetoset && valuetoset <= max) { ok = 1; break; } min = -1; max = -1; } /* We have a NUT var for this item, so check given value * against the already set range */ } else { const range_t *range = state_getrangelist(root, item->info_type); /* Unable to find tree node for var */ if (!range) { upsdebugx(2, "%s: unable to find tree node for %s", __func__, item->info_type); return STAT_SET_UNKNOWN; } while (range) { min = range->min; max = range->max; /* valuetoset is in the range */ if (min <= valuetoset && valuetoset <= max) { ok = 1; break; } range = range->next; } } if (!ok) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: value out of range [%s: %s]", __func__, item->info_type, value); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } /* Check if given value is in the range of accepted values (enum) */ } else if (item->qxflags & QX_FLAG_ENUM) { /* No NUT var is available for this item, so * take its range from qx2nut table */ if (item->qxflags & QX_FLAG_NONUT) { info_rw_t *envalue; if (!strlen(value)) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: value not given for %s", __func__, item->info_type); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } /* Loop on all existing values */ for (envalue = item->info_rw; envalue != NULL && strlen(envalue->value) > 0; envalue++) { if (envalue->preprocess && envalue->preprocess(envalue->value, sizeof(envalue->value)) ) { continue; } if (strcasecmp(envalue->value, value)) continue; /* value found */ ok = 1; break; } /* We have a NUT var for this item, so check given value * against the already set range */ } else { const enum_t *enumlist = state_getenumlist(root, item->info_type); /* Unable to find tree node for var */ if (!enumlist) { upsdebugx(2, "%s: unable to find tree node for %s", __func__, item->info_type); return STAT_SET_UNKNOWN; } while (enumlist) { /* If this is not the right value, go on to the next */ if (strcasecmp(enumlist->val, value)) { enumlist = enumlist->next; continue; } /* value found in enumlist */ ok = 1; break; } } if (!ok) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: value out of range [%s: %s]", __func__, item->info_type, value); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } /* Check if given value is not too long (string) */ } else if (item->info_flags & ST_FLAG_STRING) { const long aux = state_getaux(root, item->info_type); /* Unable to find tree node for var */ if (aux < 0) { upsdebugx(2, "%s: unable to find tree node for %s", __func__, item->info_type); return STAT_SET_UNKNOWN; } /* FIXME? Should this cast to "long"? * An int-size string is quite a lot already, * even on architectures with a moderate INTMAX */ if (aux < (int)strlen(value)) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: value is too long [%s: %s]", __func__, item->info_type, value); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } } /* Preprocess value: from NUT-compliant to UPS-compliant */ errno = 0; if (item->preprocess != NULL && item->preprocess(item, value, sizeof(value)) ) { /* Something went wrong */ /* FIXME: Actually ..._FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: FAILED", __func__); /* TODO: HANDLED but FAILED, not UNKNOWN! */ return (errno == EINVAL ? STAT_SET_CONVERSION_FAILED : STAT_SET_UNKNOWN); } /* Handle server side variable */ if (item->qxflags & QX_FLAG_ABSENT) { upsdebugx(2, "%s: setting server side variable %s", __func__, item->info_type); dstate_setinfo(item->info_type, "%s", value); upslogx(LOG_INFO, "%s: SUCCEED", __func__); return STAT_SET_HANDLED; } /* No preprocess function -> nothing to do with val */ if (item->preprocess == NULL) snprintf(value, sizeof(value), "%s", ""); /* Actual variable setting */ errno = 0; if (qx_process(item, strlen(value) > 0 ? value : NULL)) { /* Something went wrong */ /* FIXME: Actually ..._FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: FAILED", __func__); /* TODO: HANDLED but FAILED, not UNKNOWN! */ return (errno == EINVAL ? STAT_SET_CONVERSION_FAILED : STAT_SET_UNKNOWN); } /* We got a reply from the UPS: * either subdriver->accepted (-> command handled) * or the command itself echoed back (-> command failed) */ if (strlen(item->value) > 0) { if (subdriver->accepted != NULL && !strcasecmp(item->value, subdriver->accepted) ) { upslogx(LOG_INFO, "%s: SUCCEED", __func__); /* Set the status so that SEMI_STATIC vars are polled */ data_has_changed = TRUE; return STAT_SET_HANDLED; } /* FIXME: Actually ..._FAILED? */ upslogx(LOG_SET_UNKNOWN, "%s: FAILED", __func__); return STAT_SET_UNKNOWN; /* TODO: HANDLED but FAILED, not UNKNOWN! */ } /* No reply from the UPS -> command handled */ upslogx(LOG_INFO, "%s: SUCCEED", __func__); /* Set the status so that SEMI_STATIC vars are polled */ data_has_changed = TRUE; return STAT_SET_HANDLED; } /* Try to shutdown the UPS */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int retry; item_t *item; const char *val; upsdebugx(1, "%s...", __func__); /* FIXME: Use common "sdcommands" feature to * replace tunables used below ("stayoff" etc). */ /* Get user-defined delays */ /* Start delay */ item = find_nut_info("ups.delay.start", 0, QX_FLAG_SKIP); /* Don't know what happened */ if (!item) { upslogx(LOG_ERR, "Unable to set start delay"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); return; } /* Set the default value */ dstate_setinfo(item->info_type, "%s", item->dfl); /* Set var flags/range/enum */ qx_set_var(item); /* Retrieve user defined delay settings */ val = getval(QX_VAR_ONDELAY); if (val && setvar(item->info_type, val) != STAT_SET_HANDLED) { upslogx(LOG_ERR, "Start delay '%s' out of range", val); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); return; } /* Shutdown delay */ item = find_nut_info("ups.delay.shutdown", 0, QX_FLAG_SKIP); /* Don't know what happened */ if (!item) { upslogx(LOG_ERR, "Unable to set shutdown delay"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); return; } /* Set the default value */ dstate_setinfo(item->info_type, "%s", item->dfl); /* Set var flags/range/enum */ qx_set_var(item); /* Retrieve user defined delay settings */ val = getval(QX_VAR_OFFDELAY); if (val && setvar(item->info_type, val) != STAT_SET_HANDLED) { upslogx(LOG_ERR, "Shutdown delay '%s' out of range", val); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); return; } /* Stop pending shutdowns */ if (find_nut_info("shutdown.stop", QX_FLAG_CMD, QX_FLAG_SKIP)) { for (retry = 1; retry <= MAXTRIES; retry++) { if (instcmd("shutdown.stop", NULL) != STAT_INSTCMD_HANDLED) { continue; } break; } if (retry > MAXTRIES) { upslogx(LOG_NOTICE, "No shutdown pending"); } } /* Shutdown */ for (retry = 1; retry <= MAXTRIES; retry++) { if (testvar("stayoff")) { if (instcmd("shutdown.stayoff", NULL) != STAT_INSTCMD_HANDLED) { continue; } } else { if (instcmd("shutdown.return", NULL) != STAT_INSTCMD_HANDLED) { continue; } } upslogx(LOG_ERR, "Shutting down in %s seconds", dstate_getinfo("ups.delay.shutdown")); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); return; } upslogx(LOG_ERR, "Shutdown failed!"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } #ifdef QX_USB # ifndef TESTING static const struct { const char *name; int (*command)(const char *cmd, size_t cmdlen, char *buf, size_t buflen); } usbsubdriver[] = { { "cypress", &cypress_command }, { "phoenixtec", &phoenixtec_command }, { "phoenix", &phoenix_command }, { "ippon", &ippon_command }, { "krauler", &krauler_command }, { "fabula", &fabula_command }, { "hunnox", &hunnox_command }, { "fuji", &fuji_command }, { "sgs", &sgs_command }, { "snr", &snr_command }, { "ablerex", &ablerex_command }, { "armac", &armac_command }, { "gtec", >ec_command }, { NULL, NULL } }; # endif #endif void upsdrv_help(void) { #ifndef TESTING size_t i; # ifdef QX_USB /* Subdrivers have special SOMETHING_command() handling and * are listed in usbsubdriver[] array (just above in this * source file). */ printf("\nAcceptable values for USB 'subdriver' via -x or ups.conf in this driver: "); for (i = 0; usbsubdriver[i].name != NULL; i++) { if (i>0) printf(", "); printf("%s", usbsubdriver[i].name); } printf("\n"); # endif /* QX_USB*/ /* Protocols are the first token from "name" field in * subdriver_t instances in files like nutdrv_qx_mecer.c */ printf("\nAcceptable values for 'protocol' via -x or ups.conf in this driver: "); for (i = 0; subdriver_list[i] != NULL; i++) { char subdrv_name[SMALLBUF], *p; /* Get rid of subdriver version */ snprintf(subdrv_name, sizeof(subdrv_name), "%.*s", (int)strcspn(subdriver_list[i]->name, " "), subdriver_list[i]->name); /* lowercase the (ASCII) string */ for (p = subdrv_name; *p; ++p) *p = tolower((unsigned char)(*p)); if (i>0) printf(", "); printf("%s", subdrv_name); } printf("\n"); #endif /* TESTING */ } /* Adding flags/vars */ void upsdrv_makevartable(void) { char temp[SMALLBUF]; int i; upsdebugx(1, "%s...", __func__); snprintf(temp, sizeof(temp), "Set shutdown delay, in seconds (default=%s)", DEFAULT_OFFDELAY); addvar(VAR_VALUE, QX_VAR_OFFDELAY, temp); snprintf(temp, sizeof(temp), "Set startup delay, in seconds (default=%s)", DEFAULT_ONDELAY); addvar(VAR_VALUE, QX_VAR_ONDELAY, temp); addvar(VAR_FLAG, "stayoff", "If invoked the UPS won't return after a shutdown when FSD arises"); snprintf(temp, sizeof(temp), "Set polling frequency, in seconds, to reduce data flow (default=%d)", DEFAULT_POLLFREQ); addvar(VAR_VALUE, QX_VAR_POLLFREQ, temp); addvar(VAR_VALUE, "protocol", "Preselect communication protocol (skip autodetection)"); /* battery.{charge,runtime} guesstimation */ addvar(VAR_VALUE, "runtimecal", "Parameters used for runtime calculation"); addvar(VAR_VALUE, "chargetime", "Nominal charge time for UPS battery"); addvar(VAR_VALUE, "idleload", "Minimum load to be used for runtime calculation"); addvar(VAR_FLAG, "battery_voltage_reports_one_pack", "If your device natively reports battery.voltage of a single cell/pack, " "multiply that into voltage of the whole battery assembly. " "You may need an override.battery.packs=N setting also."); #ifdef QX_USB addvar(VAR_VALUE, "subdriver", "Serial-over-USB subdriver selection"); /* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */ nut_usb_addvars(); addvar(VAR_VALUE, "langid_fix", "Apply the language ID workaround to the krauler subdriver " "(0x409 or 0x4095)"); addvar(VAR_FLAG, "noscanlangid", "Don't autoscan valid range for langid"); #endif /* QX_USB */ #ifdef QX_SERIAL addvar(VAR_VALUE, "cablepower", "Set cable power for serial interface"); #endif /* QX_SERIAL */ /* Subdrivers flags/vars */ for (i = 0; subdriver_list[i] != NULL; i++) { if (subdriver_list[i]->makevartable != NULL) subdriver_list[i]->makevartable(); } } /* Update UPS status/infos */ void upsdrv_updateinfo(void) { time_t now; static int retry = 0; upsdebugx(1, "%s...", __func__); time(&now); /* Clear status buffer before beginning */ status_init(); buzzmode_init(); /* Do a full update (polling) every pollfreq or upon data change * (i.e. setvar/instcmd) */ if ((now > (lastpoll + pollfreq)) || (data_has_changed == TRUE)) { upsdebugx(1, "Full update..."); /* Clear ups_status */ ups_status = 0; alarm_init(); if (qx_ups_walk(QX_WALKMODE_FULL_UPDATE) == FALSE) { if (retry < MAXTRIES || retry == MAXTRIES) { upsdebugx(1, "Communications with the UPS lost: status read failed!"); retry++; } else { dstate_datastale(); } return; } lastpoll = now; data_has_changed = FALSE; ups_alarm_set(); alarm_commit(); } else { upsdebugx(1, "Quick update..."); /* Quick poll data only to see if the UPS is still connected */ if (qx_ups_walk(QX_WALKMODE_QUICK_UPDATE) == FALSE) { if (retry < MAXTRIES || retry == MAXTRIES) { upsdebugx(1, "Communications with the UPS lost: status read failed!"); retry++; } else { dstate_datastale(); } return; } } ups_status_set(); buzzmode_commit(); status_commit(); if (retry > MAXTRIES) { upslogx(LOG_NOTICE, "Communications with the UPS re-established"); } retry = 0; dstate_dataok(); } /* Initialise data from UPS */ void upsdrv_initinfo(void) { char *val; upsdebugx(1, "%s...", __func__); dstate_setinfo("driver.version.data", "%s", subdriver->name); /* Initialise data */ if (qx_ups_walk(QX_WALKMODE_INIT) == FALSE) { fatalx(EXIT_FAILURE, "Can't initialise data from the UPS"); } /* Init battery guesstimation */ qx_initbattery(); if (dstate_getinfo("ups.delay.start")) { /* Retrieve user defined delay settings */ val = getval(QX_VAR_ONDELAY); if (val && setvar("ups.delay.start", val) != STAT_SET_HANDLED) { fatalx(EXIT_FAILURE, "Start delay '%s' out of range", val); } } if (dstate_getinfo("ups.delay.shutdown")) { /* Retrieve user defined delay settings */ val = getval(QX_VAR_OFFDELAY); if (val && setvar("ups.delay.shutdown", val) != STAT_SET_HANDLED) { fatalx(EXIT_FAILURE, "Shutdown delay '%s' out of range", val); } } if (!find_nut_info("load.off", QX_FLAG_CMD, QX_FLAG_SKIP) && find_nut_info("load.off.delay", QX_FLAG_CMD, QX_FLAG_SKIP) ) { /* Adds default with a delay value of '0' (= immediate) */ dstate_addcmd("load.off"); } if (!find_nut_info("load.on", QX_FLAG_CMD, QX_FLAG_SKIP) && find_nut_info("load.on.delay", QX_FLAG_CMD, QX_FLAG_SKIP) ) { /* Adds default with a delay value of '0' (= immediate) */ dstate_addcmd("load.on"); } /* Init polling frequency */ val = getval(QX_VAR_POLLFREQ); if (val) pollfreq = strtol(val, NULL, 10); dstate_setinfo("driver.parameter.pollfreq", "%ld", pollfreq); time(&lastpoll); /* Install handlers */ upsh.setvar = setvar; upsh.instcmd = instcmd; /* Subdriver initinfo */ if (subdriver->initinfo != NULL) subdriver->initinfo(); } /* Open the port and the like and choose the subdriver */ void upsdrv_initups(void) { #ifdef QX_USB # ifndef TESTING int ret, langid; char tbuf[255]; /* Some devices choke on size > 255 */ char *regex_array[USBMATCHER_REGEXP_ARRAY_LIMIT]; char *subdrv; # endif #endif upsdebugx(1, "%s...", __func__); #if defined(QX_SERIAL) && defined(QX_USB) /* Whether the device is connected through USB or serial */ if ( !strcasecmp(device_path, "auto") || getval("subdriver") || getval("vendorid") || getval("productid") || getval("vendor") || getval("product") || getval("serial") || getval("bus") || getval("langid_fix") # if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) || getval("busport") # endif ) { /* USB */ is_usb = 1; /* FIXME: Revise when/if we add support for port devfs paths */ /* NOTE: We also get a more detailed message below with * the warn_if_bad_usb_port_filename() method */ if (strcasecmp(device_path, "auto")) { upslogx(LOG_WARNING, "WARNING: port='%s' would be ignored, since other options indicate USB mode", device_path); } } else { /* Serial */ is_usb = 0; } #endif /* QX_SERIAL && QX_USB */ /* Serial */ #ifdef QX_SERIAL # ifdef QX_USB if (!is_usb) { # else { /* scoping */ # endif /* QX_USB */ # ifndef TESTING const struct { const char *val; const int dtr; const int rts; } cablepower[] = { { "normal", 1, 0 }, /* Default */ { "reverse", 0, 1 }, { "both", 1, 1 }, { "none", 0, 0 }, { NULL, 0, 0 } }; int i; const char *val; struct termios tio; /* Open and lock the serial port and set the speed to 2400 baud. */ upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); if (tcgetattr(upsfd, &tio)) { fatal_with_errno(EXIT_FAILURE, "tcgetattr"); } /* Use canonical mode input processing (to read reply line) */ tio.c_lflag |= ICANON; /* Canonical input (erase and kill processing) */ tio.c_cc[VEOF] = _POSIX_VDISABLE; tio.c_cc[VEOL] = '\r'; tio.c_cc[VERASE] = _POSIX_VDISABLE; tio.c_cc[VINTR] = _POSIX_VDISABLE; tio.c_cc[VKILL] = _POSIX_VDISABLE; tio.c_cc[VQUIT] = _POSIX_VDISABLE; tio.c_cc[VSUSP] = _POSIX_VDISABLE; tio.c_cc[VSTART] = _POSIX_VDISABLE; tio.c_cc[VSTOP] = _POSIX_VDISABLE; if (tcsetattr(upsfd, TCSANOW, &tio)) { fatal_with_errno(EXIT_FAILURE, "tcsetattr"); } val = getval("cablepower"); for (i = 0; val && cablepower[i].val; i++) { if (!strcasecmp(val, cablepower[i].val)) { break; } } if (!cablepower[i].val) { fatalx(EXIT_FAILURE, "Value '%s' not valid for 'cablepower'", val); } ser_set_dtr(upsfd, cablepower[i].dtr); ser_set_rts(upsfd, cablepower[i].rts); /* Allow some time to settle for the cablepower */ usleep(100000); # endif /* TESTING */ # ifdef QX_USB } else { /* is_usb */ # else } /* end of scoping */ # endif /* QX_USB */ #endif /* QX_SERIAL */ /* USB */ #ifdef QX_USB warn_if_bad_usb_port_filename(device_path); # ifndef TESTING subdrv = getval("subdriver"); regex_array[0] = getval("vendorid"); regex_array[1] = getval("productid"); regex_array[2] = getval("vendor"); regex_array[3] = getval("product"); regex_array[4] = getval("serial"); regex_array[5] = getval("bus"); regex_array[6] = getval("device"); # if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) regex_array[7] = getval("busport"); # else if (getval("busport")) { upslogx(LOG_WARNING, "\"busport\" is configured for the device, but is not actually handled by current build combination of NUT and libusb (ignored)"); } # endif /* Check for language ID workaround (#1) */ if (getval("langid_fix")) { /* Skip "0x" prefix and set back to hexadecimal */ unsigned int u_langid_fix; if ( (sscanf(getval("langid_fix") + 2, "%x", &u_langid_fix) != 1) || (u_langid_fix > INT_MAX) ) { upslogx(LOG_NOTICE, "Error enabling language ID workaround"); } else { langid_fix = (int)u_langid_fix; upsdebugx(2, "Language ID workaround enabled (using '0x%x')", (unsigned int)langid_fix); } } /* Pick up the subdriver name if set explicitly */ if (subdrv) { int i; if (!regex_array[0] || !regex_array[1]) { fatalx(EXIT_FAILURE, "When specifying a USB 'subdriver', " "'vendorid' and 'productid' are mandatory."); } for (i = 0; usbsubdriver[i].name; i++) { if (strcasecmp(subdrv, usbsubdriver[i].name)) { continue; } subdriver_command = usbsubdriver[i].command; break; } if (!subdriver_command) { fatalx(EXIT_FAILURE, "Subdriver '%s' not found!", subdrv); } } ret = USBNewRegexMatcher(®ex_matcher, regex_array, REG_ICASE | REG_EXTENDED); switch (ret) { case -1: fatal_with_errno(EXIT_FAILURE, "USBNewRegexMatcher"); case 0: break; /* All is well */ default: fatalx(EXIT_FAILURE, "Invalid regular expression: %s", regex_array[ret]); } /* Link the matchers */ regex_matcher->next = &device_matcher; ret = usb->open_dev(&udev, &usbdevice, regex_matcher, NULL); if (ret < 0) { fatalx(EXIT_FAILURE, "No supported devices found. " "Please check your device availability with 'lsusb'\n" "and make sure you have an up-to-date version of NUT. " "If this does not help,\n" "try running the driver with at least 'subdriver', " "'vendorid' and 'productid'\n" "options specified. Please refer to the man page " "for details about these options\n" "(man 8 nutdrv_qx).\n"); } if (!subdriver_command) { fatalx(EXIT_FAILURE, "No subdriver selected"); } /* Create a new matcher for later reopening */ ret = USBNewExactMatcher(&reopen_matcher, &usbdevice); if (ret) { fatal_with_errno(EXIT_FAILURE, "USBNewExactMatcher"); } /* Link the matchers */ reopen_matcher->next = regex_matcher; dstate_setinfo("ups.vendorid", "%04x", usbdevice.VendorID); dstate_setinfo("ups.productid", "%04x", usbdevice.ProductID); /* Check for language ID workaround (#2) */ if ((langid_fix != -1) && (!getval("noscanlangid"))) { /* Future improvement: * Asking for the zero'th index is special - it returns * a string descriptor that contains all the language * IDs supported by the device. * Typically there aren't many - often only one. * The language IDs are 16 bit numbers, and they start at * the third byte in the descriptor. * See USB 2.0 specification, section 9.6.7, for more * information on this. * This should allow automatic application of the workaround */ ret = usb_get_string(udev, 0, 0, (usb_ctrl_charbuf)tbuf, sizeof(tbuf)); if (ret >= 4) { langid = ((uint8_t)tbuf[2]) | (((uint8_t)tbuf[3]) << 8); upsdebugx(1, "First supported language ID: 0x%x " "(please report to the NUT maintainer!)", (unsigned int)langid); } } # endif /* TESTING */ # ifdef QX_SERIAL } /* is_usb */ # endif /* QX_SERIAL */ #endif /* QX_USB */ /* Choose subdriver */ if (!subdriver_matcher()) fatalx(EXIT_FAILURE, "Device not supported!"); /* Subdriver initups */ if (subdriver->initups != NULL) subdriver->initups(); } /* Close the ports and the like */ void upsdrv_cleanup(void) { upsdebugx(1, "%s...", __func__); #ifndef TESTING # ifdef QX_SERIAL # ifdef QX_USB if (!is_usb) { # endif /* QX_USB */ ser_set_dtr(upsfd, 0); ser_close(upsfd, device_path); # ifdef QX_USB } else { /* is_usb */ # endif /* QX_USB */ # endif /* QX_SERIAL */ # ifdef QX_USB usb->close_dev(udev); USBFreeExactMatcher(reopen_matcher); USBFreeRegexMatcher(regex_matcher); free(usbdevice.Vendor); free(usbdevice.Product); free(usbdevice.Serial); free(usbdevice.Bus); free(usbdevice.Device); # if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) free(usbdevice.BusPort); # endif # ifdef QX_SERIAL } /* is_usb */ # endif /* QX_SERIAL */ # endif /* QX_USB */ #endif /* TESTING */ } /* == Support functions == */ /* Generic command processing function: send a command and read a reply. * Returns < 0 on error, 0 on timeout and the number of bytes read on success. */ static ssize_t qx_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen) { #ifndef TESTING ssize_t ret = -1; #endif /* NOTE: Could not find in which ifdef-ed codepath, but clang complained * about unused parameters here. Reference them just in case... */ NUT_UNUSED_VARIABLE(cmd); NUT_UNUSED_VARIABLE(buf); NUT_UNUSED_VARIABLE(buflen); #ifndef TESTING # ifdef QX_USB # ifdef QX_SERIAL /* Communication: USB */ if (is_usb) { # endif /* QX_SERIAL (&& QX_USB)*/ if (udev == NULL) { dstate_setinfo("driver.state", "reconnect.trying"); ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, NULL); if (ret < 1) { return ret; } dstate_setinfo("driver.state", "reconnect.updateinfo"); } ret = (*subdriver_command)(cmd, cmdlen, buf, buflen); if (ret >= 0) { return ret; } switch (ret) { case LIBUSB_ERROR_BUSY: /* Device or resource busy */ fatal_with_errno(EXIT_FAILURE, "Got disconnected by another driver"); #ifndef HAVE___ATTRIBUTE__NORETURN # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunreachable-code" # endif exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic pop # endif #endif # if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */ case -EPERM: /* Operation not permitted */ fatal_with_errno(EXIT_FAILURE, "Permissions problem"); #ifndef HAVE___ATTRIBUTE__NORETURN # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunreachable-code" # endif exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic pop # endif #endif # endif /* WITH_LIBUSB_0_1 */ case LIBUSB_ERROR_PIPE: /* Broken pipe */ if (usb_clear_halt(udev, 0x81) == 0) { upsdebugx(1, "Stall condition cleared"); break; } #if (defined ETIME) && ETIME && WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */ goto fallthrough_case_ETIME; case -ETIME: /* Timer expired */ fallthrough_case_ETIME: #endif /* ETIME && WITH_LIBUSB_0_1 */ if (usb_reset(udev) == 0) { upsdebugx(1, "Device reset handled"); } goto fallthrough_case_reconnect; case LIBUSB_ERROR_NO_DEVICE: /* No such device */ case LIBUSB_ERROR_ACCESS: /* Permission denied */ case LIBUSB_ERROR_IO: /* I/O error */ #if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */ case -ENXIO: /* No such device or address */ #endif /* WITH_LIBUSB_0_1 */ case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */ fallthrough_case_reconnect: /* Uh oh, got to reconnect! */ dstate_setinfo("driver.state", "reconnect.trying"); usb->close_dev(udev); udev = NULL; break; case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */ case LIBUSB_ERROR_OVERFLOW: /* Value too large for defined data type */ #if EPROTO && WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */ case -EPROTO: /* Protocol error */ #endif default: break; } # ifdef QX_SERIAL /* Communication: serial */ } else { /* !is_usb */ # endif /* QX_SERIAL (&& QX_USB) */ # endif /* QX_USB (&& TESTING) */ # ifdef QX_SERIAL ser_flush_io(upsfd); ret = ser_send_buf(upsfd, cmd, cmdlen); if (ret <= 0) { upsdebugx(3, "send: %s (%" PRIiSIZE ")", ret ? strerror(errno) : "timeout", ret); return ret; } upsdebugx(3, "send: '%.*s'", (int)strcspn(cmd, "\r"), cmd); ret = ser_get_buf(upsfd, buf, buflen, SER_WAIT_SEC, 0); if (ret <= 0) { upsdebugx(3, "read: %s (%" PRIiSIZE ")", ret ? strerror(errno) : "timeout", ret); return ret; } upsdebug_hex(5, "read", buf, (size_t)ret); upsdebugx(3, "read: '%.*s'", (int)strcspn(buf, "\r"), buf); # ifdef QX_USB } /* !is_usb */ # endif /* QX_USB (&& QX_SERIAL) */ # endif /* QX_SERIAL (&& TESTING) */ return ret; #else /* TESTING */ testing_t *testing = subdriver->testing; int i; memset(buf, 0, buflen); upsdebugx(3, "send: '%.*s'", (int)strcspn(cmd, "\r"), cmd); for (i = 0; cmd && testing[i].cmd; i++) { if (strcasecmp(cmd, testing[i].cmd)) { continue; } upsdebugx(3, "read: '%.*s'", (int)strcspn(testing[i].answer, "\r"), testing[i].answer); /* If requested to do so and this is the case, try to preserve inner '\0's (treat answer as a sequence of bytes) */ if (testing[i].answer_len > 0 && strlen(testing[i].answer) < (size_t)testing[i].answer_len) { size_t len; len = buflen <= (size_t)testing[i].answer_len ? buflen - 1 : (size_t)testing[i].answer_len; len = len <= sizeof(testing[i].answer) ? len : sizeof(testing[i].answer); memcpy(buf, testing[i].answer, len); upsdebug_hex(4, "read", buf, (int)len); return len; } return snprintf(buf, buflen, "%s", testing[i].answer); } /* If the driver expects some kind of reply in case of error.. */ if (subdriver->rejected != NULL) { /* ..fulfill its expectations.. */ upsdebugx(3, "read: '%.*s'", (int)strcspn(subdriver->rejected, "\r"), subdriver->rejected); return snprintf(buf, buflen, "%s", subdriver->rejected); /* ..otherwise.. */ } else { /* ..echo back the command */ upsdebugx(3, "read: '%.*s'", (int)strcspn(cmd, "\r"), cmd); return snprintf(buf, buflen, "%s", cmd); } #endif /* TESTING */ } /* See header file for details. * Interpretation is done in ups_status_set(). */ void update_status(const char *value) { status_lkp_t *status_item; int clear = 0; upsdebugx(5, "%s: %s", __func__, value); if (*value == '!') { value++; clear = 1; } for (status_item = status_info; status_item->status_str != NULL ; status_item++) { if (strcasecmp(status_item->status_str, value)) continue; if (clear) { ups_status &= ~status_item->status_mask; } else { ups_status |= status_item->status_mask; } return; } upsdebugx(5, "%s: Warning! %s not in list of known values", __func__, value); } /* Choose subdriver */ static int subdriver_matcher(void) { const char *protocol = getval("protocol"); int i; /* Select the subdriver for this device */ for (i = 0; subdriver_list[i] != NULL; i++) { int j; /* If protocol is set in ups.conf, use it */ if (protocol) { char subdrv_name[SMALLBUF]; /* Get rid of subdriver version */ snprintf(subdrv_name, sizeof(subdrv_name), "%.*s", (int)strcspn(subdriver_list[i]->name, " "), subdriver_list[i]->name); if (strcasecmp(subdrv_name, protocol)) { upsdebugx(2, "Skipping protocol %s", subdriver_list[i]->name); continue; } } /* Give every subdriver some tries */ for (j = 0; j < MAXTRIES; j++) { subdriver = subdriver_list[i]; if (subdriver->claim()) { break; } subdriver = NULL; } if (subdriver != NULL) break; } if (!subdriver) { upslogx(LOG_ERR, "Device not supported!"); return 0; } upslogx(LOG_INFO, "Using protocol: %s", subdriver->name); return 1; } /* Set vars boundaries */ static void qx_set_var(item_t *item) { if (!(item->qxflags & QX_FLAG_NONUT)) dstate_setflags(item->info_type, item->info_flags); /* Set max length for strings, if needed */ if (item->info_flags & ST_FLAG_STRING && !(item->qxflags & QX_FLAG_NONUT)) dstate_setaux(item->info_type, strtol(item->info_rw[0].value, NULL, 10)); /* Set enum list */ if (item->qxflags & QX_FLAG_ENUM) { info_rw_t *envalue; char buf[LARGEBUF] = ""; /* Loop on all existing values */ for (envalue = item->info_rw; envalue != NULL && strlen(envalue->value) > 0; envalue++) { if (envalue->preprocess && envalue->preprocess(envalue->value, sizeof(envalue->value)) ) { continue; } /* This item is not available yet in NUT, so publish these data in the logs */ if (item->qxflags & QX_FLAG_NONUT) { snprintfcat(buf, sizeof(buf), " %s", envalue->value); /* This item is available in NUT, add its enum to the variable */ } else { dstate_addenum(item->info_type, "%s", envalue->value); } } if (item->qxflags & QX_FLAG_NONUT) upslogx(LOG_INFO, "%s, settable values:%s", item->info_type, strlen(buf) > 0 ? buf : " none"); } /* Set range */ if (item->qxflags & QX_FLAG_RANGE) { info_rw_t *rvalue, *from = NULL, *to = NULL; int ok = 0; /* Loop on all existing values */ for (rvalue = item->info_rw; rvalue != NULL && strlen(rvalue->value) > 0; rvalue++) { if (rvalue->preprocess && rvalue->preprocess(rvalue->value, sizeof(rvalue->value)) ) { continue; } if (!from) { from = rvalue; continue; } to = rvalue; /* This item is not available yet in NUT, so * publish these data in the logs */ if (item->qxflags & QX_FLAG_NONUT) { upslogx(LOG_INFO, "%s, settable range: %s..%s", item->info_type, from->value, to->value); ok++; /* This item is available in NUT, add its range to the variable */ } else { long lFrom = strtol(from->value, NULL, 10), lTo = strtol(to->value, NULL, 10); if (lFrom > INT_MAX || lTo > INT_MAX) { upslogx(LOG_INFO, "%s, settable range exceeds INT_MAX: %ld..%ld", item->info_type, lFrom, lTo); } else { dstate_addrange(item->info_type, (int)lFrom, (int)lTo); } } from = NULL; to = NULL; } /* This item is not available yet in NUT and we weren't able to * get its range; let people know it */ if ((item->qxflags & QX_FLAG_NONUT) && !ok) upslogx(LOG_INFO, "%s, settable range: none", item->info_type); } } /* Walk UPS variables and set elements of the qx2nut array. */ static bool_t qx_ups_walk(walkmode_t mode) { item_t *item; int retcode; /* Clear batt.{chrg,runt}.act for guesstimation */ if (mode == QX_WALKMODE_FULL_UPDATE) { batt.runt.act = -1; batt.chrg.act = -1; battery_voltage_reports_one_pack_considered = 0; } /* Clear data from previous_item */ memset(previous_item.command, 0, sizeof(previous_item.command)); memset(previous_item.answer, 0, sizeof(previous_item.answer)); /* 3 modes: QX_WALKMODE_INIT, QX_WALKMODE_QUICK_UPDATE * and QX_WALKMODE_FULL_UPDATE */ /* Device data walk */ for (item = subdriver->qx2nut; item->info_type != NULL; item++) { /* Skip this item */ if (item->qxflags & QX_FLAG_SKIP) continue; upsdebugx(10, "%s: processing: %s", __func__, item->info_type); /* Filter data according to mode */ switch (mode) { /* Device capabilities enumeration */ case QX_WALKMODE_INIT: /* Special case for handling server side variables */ if (item->qxflags & QX_FLAG_ABSENT) { /* Already set */ if (dstate_getinfo(item->info_type)) continue; dstate_setinfo(item->info_type, "%s", item->dfl); /* Set var flags/range/enum */ qx_set_var(item); continue; } /* Allow duplicates for these NUT variables */ if (!strncmp(item->info_type, "ups.alarm", 9) || !strncmp(item->info_type, "ups.status", 10) ) { break; } /* This one doesn't exist yet */ if (dstate_getinfo(item->info_type) == NULL) break; continue; case QX_WALKMODE_QUICK_UPDATE: /* Quick update only deals with status and alarms! */ if (!(item->qxflags & QX_FLAG_QUICK_POLL)) continue; break; case QX_WALKMODE_FULL_UPDATE: /* These don't need polling after initinfo() */ if (item->qxflags & (QX_FLAG_ABSENT | QX_FLAG_CMD | QX_FLAG_SETVAR | QX_FLAG_STATIC)) continue; /* These need to be polled after user changes (setvar / instcmd) */ if ((item->qxflags & QX_FLAG_SEMI_STATIC) && (data_has_changed == FALSE) ) { continue; } break; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: fatalx(EXIT_FAILURE, "%s: unknown update mode!", __func__); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } /* Instant commands */ if (item->qxflags & QX_FLAG_CMD) { dstate_addcmd(item->info_type); continue; } /* Setvars */ if (item->qxflags & QX_FLAG_SETVAR) { if (item->qxflags & QX_FLAG_NONUT) { setvar(item->info_type, NULL); item->qxflags |= QX_FLAG_SKIP; } continue; } /* Check whether the previous item uses the same command * and then use its answer, if available.. */ if (strlen(previous_item.command) > 0 && strlen(previous_item.answer) > 0 && !strcasecmp(previous_item.command, item->command) ) { snprintf(item->answer, sizeof(item->answer), "%s", previous_item.answer); /* Process the answer */ retcode = qx_process_answer(item, strlen(item->answer)); /* ..otherwise: execute command to get answer from the UPS */ } else { retcode = qx_process(item, NULL); } /* Record item as previous_item */ snprintf(previous_item.command, sizeof(previous_item.command), "%s", item->command); snprintf(previous_item.answer, sizeof(previous_item.answer), "%s", item->answer); if (retcode) { /* Clear data from the item */ memset(item->answer, 0, sizeof(item->answer)); memset(item->value, 0, sizeof(item->value)); if (item->qxflags & QX_FLAG_QUICK_POLL) return FALSE; if (mode == QX_WALKMODE_INIT) /* Skip this item from now on */ item->qxflags |= QX_FLAG_SKIP; /* Don't know what happened, try again later... */ continue; } /* Process the value we got back (set status bits * and set the value of other parameters) */ retcode = ups_infoval_set(item); /* Clear data from the item */ memset(item->answer, 0, sizeof(item->answer)); memset(item->value, 0, sizeof(item->value)); /* Uh-oh! Some error! */ if (retcode == -1) { if (item->qxflags & QX_FLAG_QUICK_POLL) return FALSE; continue; } /* Set var flags/range/enum (not for ups.{alarm.status}, * hence the retcode check) */ if (retcode && mode == QX_WALKMODE_INIT) { qx_set_var(item); } } /* Update battery guesstimation */ if (mode == QX_WALKMODE_FULL_UPDATE && (d_equal(batt.runt.act, -1) || d_equal(batt.chrg.act, -1)) ) { if (getval("runtimecal")) { const char *val; time_t battery_now; time(&battery_now); /* OL */ if (ups_status & STATUS(OL)) { batt.runt.est += batt.runt.nom * difftime(battery_now, battery_lastpoll) / batt.chrg.time; if (batt.runt.est > batt.runt.nom) { batt.runt.est = batt.runt.nom; } /* OB */ } else { batt.runt.est -= load.eff * difftime(battery_now, battery_lastpoll); if (batt.runt.est < 0) { batt.runt.est = 0; } } val = dstate_getinfo("battery.voltage"); if (!val) { upsdebugx(2, "%s: unable to get battery.voltage", __func__); } else { /* For age-corrected estimates below, * see theory and experimental graphs at * https://github.com/networkupstools/nut/pull/1027 */ batt.volt.act = strtod(val, NULL); if (!battery_voltage_reports_one_pack_considered) { batt.volt.act *= batt.packs; } if (batt.volt.act > 0 && batt.volt.low > 0 && batt.volt.high > batt.volt.low) { double voltage_battery_charge = (batt.volt.act - batt.volt.low) / (batt.volt.high - batt.volt.low); if (voltage_battery_charge < 0) { voltage_battery_charge = 0; } if (voltage_battery_charge > 1) { voltage_battery_charge = 1; } /* Correct estimated runtime remaining for old batteries: * this value replacement only happens if the actual * voltage_battery_charge is smaller than expected by * previous (load-based) estimation, thus adapting to a * battery too old and otherwise behaving non-linearly */ if (voltage_battery_charge < (batt.runt.est / batt.runt.nom)) { double estPrev = batt.runt.est; batt.runt.est = voltage_battery_charge * batt.runt.nom; upsdebugx(3, "%s: updating batt.runt.est from '%g' to '%g'", __func__, estPrev, batt.runt.est); } } } if (d_equal(batt.chrg.act, -1)) dstate_setinfo("battery.charge", "%.0f", 100 * batt.runt.est / batt.runt.nom); if (d_equal(batt.runt.act, -1) && !qx_load()) dstate_setinfo("battery.runtime", "%.0f", batt.runt.est / load.eff); battery_lastpoll = battery_now; } else { qx_battery(); } } return TRUE; } /* Convert the local status information to NUT format and set NUT alarms. */ static void ups_alarm_set(void) { if (ups_status & STATUS(RB)) { alarm_set("Replace battery!"); } if (ups_status & STATUS(FSD)) { alarm_set("Shutdown imminent!"); } } /* Convert the local status information to NUT format and set NUT status. */ static void ups_status_set(void) { if (ups_status & STATUS(OL)) { status_set("OL"); /* On line */ } else { status_set("OB"); /* On battery */ } if (ups_status & STATUS(DISCHRG)) { status_set("DISCHRG"); /* Discharging */ } if (ups_status & STATUS(CHRG)) { status_set("CHRG"); /* Charging */ } if (ups_status & STATUS(LB)) { status_set("LB"); /* Low battery */ } if (ups_status & STATUS(OVER)) { status_set("OVER"); /* Overload */ } if (ups_status & STATUS(RB)) { status_set("RB"); /* Replace battery */ } if (ups_status & STATUS(TRIM)) { status_set("TRIM"); /* SmartTrim */ } if (ups_status & STATUS(BOOST)) { status_set("BOOST"); /* SmartBoost */ } if (ups_status & STATUS(BYPASS)) { status_set("BYPASS"); /* On bypass */ } if (ups_status & STATUS(OFF)) { status_set("OFF"); /* UPS is off */ } if (ups_status & STATUS(CALIB)) { status_set("CAL"); /* Calibration */ } if (ups_status & STATUS(FSD)) { status_set("FSD"); /* Forced shutdown */ } } /* See header file for details. */ item_t *find_nut_info(const char *varname, const unsigned long flag, const unsigned long noflag) { item_t *item; for (item = subdriver->qx2nut; item->info_type != NULL; item++) { if (strcasecmp(item->info_type, varname)) continue; if (flag && ((item->qxflags & flag) != flag)) continue; if (noflag && (item->qxflags & noflag)) continue; return item; } upsdebugx(2, "%s: info type %s not found", __func__, varname); return NULL; } /* Process the answer we got back from the UPS * Return -1 on errors, 0 on success * Can set errno, note that EINVAL means unsupported * parameter value here! */ static int qx_process_answer(item_t *item, const size_t len) { errno = 0; /* Query rejected by the UPS */ if (subdriver->rejected && !strcasecmp(item->answer, subdriver->rejected)) { upsdebugx(2, "%s: query rejected by the UPS (%s)", __func__, item->info_type); errno = EINVAL; return -1; } /* Short reply */ if (item->answer_len && len < item->answer_len) { upsdebugx(2, "%s: short reply (%s) %" PRIuSIZE "<%" PRIuSIZE, __func__, item->info_type, len, item->answer_len); errno = EINVAL; return -1; } /* Wrong leading character */ if (item->leading && item->answer[0] != item->leading) { upsdebugx(2, "%s: %s - invalid start character [%02x], expected [%02x]", __func__, item->info_type, item->answer[0], item->leading); return -1; } /* Check boundaries */ if (item->to && item->to < item->from) { upsdebugx(1, "%s: in %s, starting char's position (%d) " "follows ending char's one (%d)", __func__, item->info_type, item->from, item->to); return -1; } /* Get value */ if (strlen(item->answer)) { snprintf(item->value, sizeof(item->value), "%.*s", item->to ? 1 + item->to - item->from : (int)strcspn(item->answer, "\r") - item->from, item->answer + item->from); } else { snprintf(item->value, sizeof(item->value), "%s", ""); } errno = 0; return 0; } /* See header file for details. */ int qx_process(item_t *item, const char *command) { char buf[sizeof(item->answer) - 1] = "", *cmd; ssize_t len; size_t cmdlen = command ? (strlen(command) >= SMALLBUF ? strlen(command) + 1 : SMALLBUF) : (item->command && strlen(item->command) >= SMALLBUF ? strlen(item->command) + 1 : SMALLBUF); size_t cmdsz = (sizeof(char) * cmdlen); /* in bytes, to be pedantic */ int cmd_len; if ( !(cmd = xmalloc(cmdsz)) ) { upslogx(LOG_ERR, "qx_process() failed to allocate buffer"); return -1; } /* Prepare the command to be used */ memset(cmd, 0, cmdsz); cmd_len = snprintf(cmd, cmdsz, "%s", command ? command : item->command); /* Whether the sub-driver code sets errno or not, so be it; * note that EINVAL means unsupported parameter value here! */ /* Preprocess the command */ if ( item->preprocess_command != NULL && (cmd_len = item->preprocess_command(item, cmd, cmdsz)) == -1 ) { upsdebugx(4, "%s: failed to preprocess command [%s]", __func__, item->info_type); free (cmd); return -1; } /* Send the command */ len = qx_command(cmd, cmd_len, buf, sizeof(buf)); memset(item->answer, 0, sizeof(item->answer)); if (len < 0 || len > INT_MAX) { upsdebugx(4, "%s: failed to preprocess answer [%s]", __func__, item->info_type); free (cmd); return -1; } memcpy(item->answer, buf, sizeof(buf)); /* Preprocess the answer */ if (item->preprocess_answer != NULL) { len = item->preprocess_answer(item, (int)len); if (len < 0 || len > INT_MAX) { upsdebugx(4, "%s: failed to preprocess answer [%s]", __func__, item->info_type); /* Clear the failed answer, preventing it from * being reused by next items with same command */ memset(item->answer, 0, sizeof(item->answer)); free (cmd); return -1; } } free (cmd); /* Process the answer to get the value */ return qx_process_answer(item, (size_t)len); } /* See header file for details. */ int ups_infoval_set(item_t *item) { char value[SMALLBUF] = ""; /* Item need to be preprocessed? */ if (item->preprocess != NULL){ /* Process the value returned by the UPS to NUT standards */ if (item->preprocess(item, value, sizeof(value))) { upsdebugx(4, "%s: failed to preprocess value [%s: %s]", __func__, item->info_type, item->value); return -1; } /* Deal with status items */ if (!strncmp(item->info_type, "ups.status", 10)) { if (strlen(value) > 0) update_status(value); return 0; } /* Deal with alarm items */ if (!strncmp(item->info_type, "ups.alarm", 9)) { if (strlen(value) > 0) alarm_set(value); return 0; } } else { snprintf(value, sizeof(value), "%s", item->value); /* Cover most of the cases: either left/right filled with hashes, * spaces or a mix of both */ if (item->qxflags & QX_FLAG_TRIM) str_trim_m(value, "# "); if (strcasecmp(item->dfl, "%s")) { if (strspn(value, "0123456789 .") != strlen(value)) { upsdebugx(2, "%s: non numerical value [%s: %s]", __func__, item->info_type, value); return -1; } snprintf_dynamic(value, sizeof(value), item->dfl, "%f", strtod(value, NULL)); } } if (item->qxflags & QX_FLAG_NONUT) { upslogx(LOG_INFO, "%s: %s", item->info_type, value); return 1; } if (!strlen(value)) { upsdebugx(1, "%s: non significant value [%s]", __func__, item->info_type); return -1; } dstate_setinfo(item->info_type, "%s", value); /* Fill batt.{chrg,runt}.act for guesstimation */ if (!strcasecmp(item->info_type, "battery.charge")) batt.chrg.act = strtol(value, NULL, 10); else if (!strcasecmp(item->info_type, "battery.runtime")) batt.runt.act = strtol(value, NULL, 10); return 1; } /* See header file for details. */ unsigned int qx_status(void) { return ups_status; } nut-2.8.4/drivers/adelsystem_cbi.h0000664000175000017500000004143215000733203014071 00000000000000/* adelsystem_cbi.h - Driver for ADELSYSTEM CB/CBI DC-UPS * * Copyright (C) * 2022 Dimitris Economou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* * code indentation with tabstop=4 */ #ifndef ADELSYSTEM_CBI_H #define ADELSYSTEM_CBI_H #include "nut_stdint.h" /* UPS device details */ #define DEVICE_MFR "ADELSYSTEM" #define DEVICE_TYPE_STRING "DC-UPS" #define DEVICE_MODEL "CBI2801224A" /* serial access parameters */ #define BAUD_RATE 9600 #define PARITY 'N' #define DATA_BIT 8 #define STOP_BIT 1 /* * modbus response and byte timeouts * us: 1 - 999999 */ #define MODRESP_TIMEOUT_s 0 #define MODRESP_TIMEOUT_us 200000 #define MODBYTE_TIMEOUT_s 0 #define MODBYTE_TIMEOUT_us 50000 /* modbus access parameters */ #define MODBUS_SLAVE_ID 5 /* number of modbus registers */ #define MODBUS_NUMOF_REGS 98 /* max HOLDING registers */ #define MAX_H_REGS 120 /* start HOLDING register index */ #define H_REG_STARTIDX 0 /* read all regs preprocessor flag */ #ifndef READALL_REGS #define READALL_REGS 1 #endif /* number of device models */ #define DEV_NUMOF_MODELS 10 /* shutdown repeat on error */ #define FSD_REPEAT_CNT 3 /* shutdown repeat interval in ms */ #define FSD_REPEAT_INTRV 1500 /* definition of register type */ enum regtype { COIL = 0, INPUT_B, INPUT_R, HOLDING }; typedef enum regtype regtype_t; /* product name info, "device.model" */ struct prodname { uint16_t val; char *name; }; typedef struct prodname prodname_t; static prodname_t prdnm_i[] = { {1, "CBI1235A"}, {2, "CBI2420A"}, {3, "CBI4810A"}, {4, "CBI2801224"}, {7, "CBI480W"}, {8, "CB122410A"}, {9, "CB480W"}, {11, "CB12245AJ"}, {12, "CB1235A"}, {13, "CB2420A"}, {14, "CB4810A"} }; /* charging status info, "battery.charger.status" */ static char *chrgs_i[] = { "none", "resting", /* recovering */ "charging", /* bulk */ "charging", /* absorb */ "floating" /* float */ }; struct chrgs { int state; char *info; }; typedef struct chrgs chrgs_t; /* power management info, "ups.status", "battery.charger.status" */ static char *pwrmng_i[] = { "backup", /* "OB", "discharging" */ "charging", /* "OL" */ "boost", "not charging" }; struct pwrmng { int state; char *info; }; typedef struct pwrmng pwrmng_t; /* general modbus register value */ struct reg { union val { uint16_t ui16; uint8_t ui8; } val; char *strval; }; typedef struct reg reg_t; /* general alarm struct */ struct alrm { int actv; /* active flag */ char *descr; /* description field */ }; typedef struct alrm alrm_t; /* general alarm array */ struct alrm_ar { int alrm_c; /* alarm count */ alrm_t *alrm; /* alarm array */ }; typedef struct alrm_ar alrm_ar_t; /* * BIT MASKS and VALUES */ /* Charging status */ #define CHRG_NONE 0 #define CHRG_RECV 1 #define CHRG_BULK 2 #define CHRG_ABSR 3 #define CHRG_FLOAT 4 /* power management */ #define PMNG_BCKUP 0 #define PMNG_CHRGN 1 #define PMNG_BOOST 2 #define PMNG_NCHRG 3 /* product name */ #define PRDN_MAX 14 /* Mains alarm masks */ #define MAINS_AVAIL_M 0x0001 /* 0: available (OL) 1: not available (OB) */ #define SHUTD_REQST_M 0x0002 /* shutdown requested */ /* Mains alarm indices */ #define MAINS_AVAIL_I 0 /* 0: available (OL) 1: not available (OB) */ #define SHUTD_REQST_I 1 /* shutdown requested */ /* AC input voltage alarm masks */ #define VACA_HIALRM_M 0x0001 /* high alarm */ #define VACA_LOALRM_M 0x0002 /* low alarm */ /* AC input voltage alarm indices */ #define VACA_HIALRM_I 0 /* high alarm */ #define VACA_LOALRM_I 1 /* low alarm */ /* Onboard temperature alarm value */ #define OBTA_HIALRM_V 1 /* high alarm */ /* Onboard temperature alarm index */ #define OBTA_HIALRM_I 0 /* high alarm */ /* Device failure alarm masks */ #define DEVF_RCALRM_M 0x0001 /* rectifier failure */ #define DEVF_INALRM_M 0x0006 /* internal failure */ #define DEVF_LFNAVL_M 0x0008 /* lifetest not available */ /* Device failure alarm indices */ #define DEVF_RCALRM_I 0 /* rectifier failure */ #define DEVF_INALRM_I 1 /* internal failure */ #define DEVF_LFNAVL_I 2 /* lifetest not available */ /* Battery temp sensor failure alarm masks */ #define BTSF_FCND_M 0x0001 /* connection fault */ #define BTSF_NCND_M 0x0002 /* not connected */ /* Battery temp sensor failure alarm indices */ #define BTSF_FCND_I 0 /* connection fault */ #define BTSF_NCND_I 1 /* not connected */ /* Battery voltage alarm masks */ #define BVAL_HIALRM_M 0x0001 /* high voltage */ #define BVAL_LOALRM_M 0x0002 /* low voltage */ #define BVAL_BSTSFL_M 0x0004 /* battery start with battery flat */ /* Battery voltage alarm indices */ #define BVAL_HIALRM_I 0 /* high voltage */ #define BVAL_LOALRM_I 1 /* low voltage */ #define BVAL_BSTSFL_I 2 /* battery start with battery flat */ /* SoH and SoC alarm masks */ #define SHSC_HIRESI_M 0x0001 /* high internal resistance */ #define SHSC_LOCHEF_M 0x0002 /* low charge efficiency */ #define SHSC_LOEFCP_M 0x0004 /* low effective capacity */ #define SHSC_LOWSOC_M 0x0040 /* low state of charge */ /* SoH and SoC alarm indices */ #define SHSC_HIRESI_I 0 /* high internal resistance */ #define SHSC_LOCHEF_I 1 /* low charge efficiency */ #define SHSC_LOEFCP_I 2 /* low effective capacity */ #define SHSC_LOWSOC_I 3 /* low state of charge */ /* Battery status alarm masks */ #define BSTA_REVPOL_M 0x0001 /* reversed polarity */ #define BSTA_NOCNND_M 0x0002 /* not connected */ #define BSTA_CLSHCR_M 0x0004 /* cell short circuit */ #define BSTA_SULPHD_M 0x0008 /* sulphated */ #define BSTA_CHEMNS_M 0x0010 /* chemistry not supported */ #define BSTA_CNNFLT_M 0x0020 /* connection fault */ /* Battery status alarm indices */ #define BSTA_REVPOL_I 0 /* reversed polarity */ #define BSTA_NOCNND_I 1 /* not connected */ #define BSTA_CLSHCR_I 2 /* cell short circuit */ #define BSTA_SULPHD_I 3 /* sulphated */ #define BSTA_CHEMNS_I 4 /* chemistry not supported */ #define BSTA_CNNFLT_I 5 /* connection fault */ /* Allocate alarm arrays */ static inline alrm_ar_t *alloc_alrm_ar(int as, size_t extra) { alrm_ar_t *ret = xcalloc(1, sizeof(alrm_t) + extra); if (ret) { memcpy(ret, &(alrm_ar_t const) { .alrm_c = as }, sizeof(alrm_ar_t) ); } return ret; } /* Initialize alarm arrays */ static inline void alrm_ar_init(alrm_ar_t *ar_ptr, alrm_t *a_ptr, int as) { ar_ptr->alrm_c = as; ar_ptr->alrm = a_ptr; } /* input mains and shutdown alarms */ static alrm_t mains_ar[] = { {0, "input voltage not available"}, {0, "ups shutdown requested"} }; static int mains_c = 2; static alrm_ar_t *mains; /* AC input voltage alarms */ static alrm_t vaca_ar[] = { {0, "input voltage high alarm"}, {0, "input voltage low alarm"} }; static int vaca_c = 2; static alrm_ar_t *vaca; /* device failure alarms */ static alrm_t devf_ar[] = { {0, "UPS rectifier failure"}, {0, "UPS internal failure"}, {0, "UPS lifetest not available"} }; static int devf_c = 3; static alrm_ar_t *devf; /* battery sensor failure alarms */ static alrm_t btsf_ar[] = { {0, "battery temp sensor connection fault"}, {0, "battery temp sensor not connected"} }; static int btsf_c = 2; static alrm_ar_t *btsf; /* battery voltage alarms */ static alrm_t bval_ar[] = { {0, "battery high voltage"}, {0, "battery low voltage"}, {0, "battery start with battery flat"} }; static int bval_c = 3; static alrm_ar_t *bval; /* battery SoH and SoC alarms */ static alrm_t shsc_ar[] = { {0, "battery high internal resistance"}, {0, "battery low charge efficiency"}, {0, "battery low effective capacity"}, {0, "battery low state of charge"} }; static int shsc_c = 4; static alrm_ar_t *shsc; /* battery status alarm */ static alrm_t bsta_ar[] = { {0, "battery reversed polarity"}, {0, "battery not connected"}, {0, "battery cell short circuit"}, {0, "battery sulphated"}, {0, "battery chemistry not supported"}, {0, "battery connection fault"} }; static int bsta_c = 4; static alrm_ar_t *bsta; /* onboard temperature alarm */ static alrm_t obta_ar[] = { {0, "onboard temperature high"} }; static int obta_c = 4; static alrm_ar_t *obta; /* UPS device reg enum */ enum devreg { CHRG = 4, /* Charging status, "battery.charger.status" */ BATV = 7, /* Battery voltage, "battery.voltage" */ BCEF = 18, /* Battery charge efficiency factor (CEF) */ BSOH = 20, /* Battery state-of-health */ BSOC = 22, /* Battery state-of-charge, "battery.charge" */ BTMP = 25, /* Battery temperature in Kelvin units, "battery.temperature" */ PMNG = 5, /* Power management, "ups.status" */ OTMP = 28, /* Onboard temperature, "ups.temperature" */ PRDN = 67, /* Product name, "ups.model" */ VAC = 29, /* AC voltage, "input.voltage" */ LVDC = 10, /* Load voltage, "output.voltage" */ LCUR = 19, /* Load current, "output.current" */ BINH = 87, /* Backup inhibit */ FSD = 40, /* Force shutdown */ TBUF = 103, /* Time buffering, "battery.runtime" */ BSTA = 31, /* Battery status alarms */ SCSH, /* SoH and SoC alarms */ BVAL = 34, /* Battery voltage alarm */ BTSF = 43, /* Battery temp sensor failure */ DEVF = 42, /* Device failure */ OBTA = 46, /* On board temp alarm */ VACA = 44, /* VAC alarms */ MAIN /* Mains status */ }; typedef enum devreg devreg_t; /* UPS register attributes */ struct regattr { int num; int saddr; /* register start address */ int xaddr; /* register hex address */ float scale; /* scale */ regtype_t type; /* register type */ }; typedef struct regattr regattr_t; /* UPS device state info union */ union devstate { prodname_t product; /* ups model name */ chrgs_t charge; /* charging status */ pwrmng_t power; /* ups status */ reg_t reg; /* state register*/ alrm_ar_t *alrm; /* alarm statuses */ }; typedef union devstate devstate_t; /* device register memory image */ static uint16_t regs_data[MAX_H_REGS]; /* ADELSYSTEM CBI registers */ static regattr_t regs[] = { {40001, 0, 0, 1, HOLDING}, /* Address of slave unit */ {40002, 0, 0, 1, HOLDING}, /* Baud rate for serial communication */ {40003, 0, 0, 1, HOLDING}, /* Parity bit for serial communication */ {40004, 0, 0, 1, HOLDING}, {40005, 0, 0, 1, HOLDING}, /* Charging status */ {40006, 0, 0, 1, HOLDING}, /* Power management * 0:Backup 1:Charging 2:boost 3:Not charging */ {40007, 0, 0, 1, HOLDING}, /* Nominal output voltage */ {40008, 0, 0, 1, HOLDING}, /* Battery voltage */ {40009, 0, 0, 1, HOLDING}, /* Parameter map version ID */ {40010, 0, 0, 1, HOLDING}, /* Software ID */ {40011, 0, 0, 1, HOLDING}, /* Output load voltage */ {40012, 0, 0, 1, HOLDING}, {40013, 0, 0, 1, HOLDING}, {40014, 0, 0, 1, HOLDING}, /* Battery charge current */ {40015, 0, 0, 1, HOLDING}, {40016, 0, 0, .1, HOLDING}, /* Battery capacity consumed */ {40017, 0, 0, 1, HOLDING}, /* Battery discharge current */ {40018, 0, 0, .1, HOLDING}, /* Effective battery capacity */ {40019, 0, 0, 1, HOLDING}, /* Battery charge efficiency factor (CEF) */ {40020, 0, 0, 1, HOLDING}, /* Output load current */ {40021, 0, 0, 1, HOLDING}, /* Battery state-of-health */ {40022, 0, 0, 1, HOLDING}, /* Time remaining to 100% discharge */ {40023, 0, 0, .1, HOLDING}, /* Battery state-of-charge */ {40024, 0, 0, 1, HOLDING}, /* Battery type currently selected */ {40025, 0, 0, 1, HOLDING}, {40026, 0, 0, 1, HOLDING}, /* Battery temperature in Kelvin units */ {40027, 0, 0, 1, HOLDING}, /* Configuration mode */ {40028, 0, 0, .1, HOLDING}, /* Battery net internal resistance */ {40029, 0, 0, 1, HOLDING}, /* On-board temperature */ {40030, 0, 0, 1, HOLDING}, /* AC input voltage */ {40031, 0, 0, 1, HOLDING}, {40032, 0, 0, 1, HOLDING}, /* Battery status alarm */ {40033, 0, 0, 1, HOLDING}, /* Battery State of Charge and State of Health */ {40034, 0, 0, 1, HOLDING}, /* Load output off duration after PC shutdown */ {40035, 0, 0, 1, HOLDING}, /* Battery voltage alarm */ {40036, 0, 0, 1, HOLDING}, /* Low AC input voltage alarm threshold */ {40037, 0, 0, 1, HOLDING}, /* High AC input voltage alarm threshold */ {40038, 0, 0, 1, HOLDING}, /* Load alarm */ {40039, 0, 0, 1, HOLDING}, /* Device variant */ {40040, 0, 0, 1, HOLDING}, {40041, 0, 0, 1, HOLDING}, /* Force shutdown */ {40042, 0, 0, 1, HOLDING}, {40043, 0, 0, 1, HOLDING}, /* Device failure */ {40044, 0, 0, 1, HOLDING}, /* Battery temperature sensor failure */ {40045, 0, 0, 1, HOLDING}, /* AC input voltage alarm */ {40046, 0, 0, 1, HOLDING}, /* Mains status */ {40047, 0, 0, 1, HOLDING}, /* On board temperature alarm */ {40048, 0, 0, 1, HOLDING}, /* Number of charge cycles completed */ {40049, 0, 0, 1, HOLDING}, /* Charge cycles not completed */ {40050, 0, 0, .1, HOLDING}, /* Ah charged */ {40051, 0, 0, 1, HOLDING}, /* Total run time */ {40052, 0, 0, 1, HOLDING}, /* Number of low battery voltage events */ {40053, 0, 0, 1, HOLDING}, /* Number of high battery voltage events */ {40054, 0, 0, 1, HOLDING}, /* Number of low VAC events at mains input */ {40055, 0, 0, 1, HOLDING}, /* Number of High VAC events at mains input */ {40056, 0, 0, 1, HOLDING}, /* Number of over temperature inside events */ {40057, 0, 0, 1, HOLDING}, /* Number of mains-backup transitions */ {40058, 0, 0, 1, HOLDING}, /* Number power boost events */ {40059, 0, 0, 1, HOLDING}, /* Highest battery voltage */ {40060, 0, 0, 1, HOLDING}, /* Highest output load voltage */ {40061, 0, 0, .1, HOLDING}, /* Maximum depth of discharge */ {40062, 0, 0, 1, HOLDING}, /* Lowest battery voltage */ {40063, 0, 0, 1, HOLDING}, /* Lowest output load voltage */ {40064, 0, 0, .1, HOLDING}, /* Average depth of discharge */ {40065, 0, 0, 1, HOLDING}, /* History clear all */ {40066, 0, 0, 1, HOLDING}, /* Factory settings */ {40067, 0, 0, 1, HOLDING}, /* Product name */ {40068, 0, 0, 1, HOLDING}, {40069, 0, 0, 1, HOLDING}, /* Reset internal battery model */ {40070, 0, 0, 1, HOLDING}, {40071, 0, 0, 1, HOLDING}, /* Deep discharge battery prevention */ {40072, 0, 0, 1, HOLDING}, /* Maximum charge current */ {40073, 0, 0, 1, HOLDING}, /* Bulk voltage */ {40074, 0, 0, 1, HOLDING}, /* Max bulk timer */ {40075, 0, 0, 1, HOLDING}, /* Min bulk timer */ {40076, 0, 0, 1, HOLDING}, {40077, 0, 0, 1, HOLDING}, /* Absorption voltage */ {40078, 0, 0, 1, HOLDING}, /* Max absorption timer */ {40079, 0, 0, 1, HOLDING}, /* Min absorption timer */ {40080, 0, 0, 1, HOLDING}, /* Return Amperes to float */ {40081, 0, 0, 1, HOLDING}, /* Return amps timer */ {40082, 0, 0, 1, HOLDING}, /* Float voltage */ {40083, 0, 0, 1, HOLDING}, /* Force boost charge */ {40084, 0, 0, 1, HOLDING}, /* Return to bulk voltage from float */ {40085, 0, 0, 1, HOLDING}, /* Return to bulk delay */ {40086, 0, 0, 1, HOLDING}, {40087, 0, 0, 1, HOLDING}, /* Switchoff voltage without mains */ {40088, 0, 0, 1, HOLDING}, /* Backup Inhibit 0 = Backup allowed * 1 = Backup not allowed */ {40089, 0, 0, 1, HOLDING}, /* Number of battery cells */ {40090, 0, 0, 1, HOLDING}, /* Temperature compensation coefficient */ {40091, 0, 0, 1, HOLDING}, {40092, 0, 0, 1, HOLDING}, /* Lifetest enable */ {40093, 0, 0, 1, HOLDING}, /* Max alarm temp */ {40094, 0, 0, 1, HOLDING}, /* Min alarm temp */ {40095, 0, 0, 1, HOLDING}, {40096, 0, 0, 1, HOLDING}, {40097, 0, 0, 1, HOLDING}, /* Low battery threshold */ {40098, 0, 0, 1, HOLDING}, /* SoC/SoH test period */ {40099, 0, 0, 1, HOLDING}, /* Manual SoC/SoH test request */ {40100, 0, 0, 1, HOLDING}, /* SoC/SoH test possible */ {40101, 0, 0, .1, HOLDING}, /* Nominal battery internal resistance */ {40102, 0, 0, .1, HOLDING}, /* Nominal battery cables resistance */ {40103, 0, 0, 1, HOLDING}, /* Firmware ID */ {40104, 0, 0, 1, HOLDING}, /* Time buffering */ {40105, 0, 0, .1, HOLDING}, /* Battery capacity C20 */ {40106, 0, 0, .1, HOLDING}, /* Battery Capacity C10 */ {40107, 0, 0, 1, HOLDING}, /* Device switchoff delay */ {40108, 0, 0, .1, HOLDING}, /* Battery Capacity C5 */ {40109, 0, 0, .1, HOLDING}, /* Battery Capacity C2 */ {40110, 0, 0, 1, HOLDING}, {40111, 0, 0, 1, HOLDING}, /* PC power supply removal delay */ {40112, 0, 0, .1, HOLDING}, /* Battery Capacity C1 */ {40113, 0, 0, .1, HOLDING}, /* Low state-of-charge */ {40114, 0, 0, 1, HOLDING}, {40115, 0, 0, 1, HOLDING}, {40116, 0, 0, 1, HOLDING}, {40117, 0, 0, 1, HOLDING}, {40118, 0, 0, 1, HOLDING}, {40119, 0, 0, 1, HOLDING}, {40120, 0, 0, 1, HOLDING} /* Zero-SoC reference */ }; #endif /* ADELSYSTEM_CBI_H */ nut-2.8.4/drivers/netvision-mib.h0000644000175000017500000000023114670526611013672 00000000000000#ifndef NETVISION_MIB_H #define NETVISION_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t netvision; #endif /* NETVISION_MIB_H */ nut-2.8.4/drivers/skel.c0000644000175000017500000001160115044656702012044 00000000000000/* anything commented is optional anything else is mandatory for more information, refer to: * docs/developers.txt * docs/new-drivers.txt * docs/nut-names.txt and possibly also to: * docs/hid-subdrivers.txt for USB/HID devices * or docs/snmp-subdrivers.txt for SNMP devices */ #include "config.h" #include "main.h" #include "attribute.h" /* #include "serial.h" */ /* #define ENDCHAR '\r' */ /* #define IGNCHARS "" */ #define DRIVER_NAME "Skeleton UPS driver" #define DRIVER_VERSION "0.07" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "John Doe ", DRV_STABLE, { NULL } }; /* Forward decls */ /*static int instcmd(const char *cmdname, const char *extra);*/ void upsdrv_initinfo(void) { /* try to detect the UPS here - call fatal_with_errno(EXIT_FAILURE, ...) * or fatalx(EXIT_FAILURE, ...) if it fails */ /* dstate_setinfo("ups.mfr", "skel manufacturer"); */ /* dstate_setinfo("ups.model", "longrun 15000"); */ /* note: for a transition period, these data are redundant! */ /* dstate_setinfo("device.mfr", "skel manufacturer"); */ /* dstate_setinfo("device.model", "longrun 15000"); */ /* commands ----------------------------------------------- */ /*dstate_addcmd("shutdown.return");*/ /*dstate_addcmd("test.battery.stop);*/ /* upsh.instcmd = instcmd; */ } void upsdrv_updateinfo(void) { /* int flags; */ /* char temp[256]; */ /* ser_sendchar(upsfd, 'A'); */ /* ser_send(upsfd, "foo%d", 1234); */ /* ser_send_buf(upsfd, bincmd, 12); */ /* * ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS); * * if (ret < STATUS_LEN) { * upslogx(LOG_ERR, "Short read from UPS"); * dstate_datastale(); * return; * } */ /* dstate_setinfo("var.name", ""); */ /* if (ioctl(upsfd, TIOCMGET, &flags)) { * upslog_with_errno(LOG_ERR, "TIOCMGET"); * dstate_datastale(); * return; * } */ /* status_init(); * * if (ol) * status_set("OL"); * else * status_set("OB"); * ... * * status_commit(); * * dstate_dataok(); */ /* * poll_interval = 2; */ } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ /* maybe try to detect the UPS here, but try a shutdown even if it doesn't respond at first if possible */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); /* you may have to check the line status since the commands for toggling power are frequently different for OL vs. OB */ /* OL: this must power cycle the load if possible */ /* OB: the load must remain off until the power returns */ } /* static int instcmd(const char *cmdname, const char *extra) { / * May be used in logging below, but not as a command argument * / NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ser_send_buf(upsfd, ...); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ser_send_buf(upsfd, ...); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } */ /* static int setvar(const char *varname, const char *val) { upsdebug_SET_STARTING(varname, val); if (!strcasecmp(varname, "ups.test.interval")) { ser_send_buf(upsfd, ...); return STAT_SET_HANDLED; } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } */ void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { /* allow '-x xyzzy' */ /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */ /* allow '-x foo=' */ /* addvar(VAR_VALUE, "foo", "Override foo setting"); */ } void upsdrv_initups(void) { /* upsfd = ser_open(device_path); */ /* ser_set_speed(upsfd, device_path, B1200); */ /* probe ups type */ /* to get variables and flags from the command line, use this: * * first populate with upsdrv_makevartable() above, then... * * set flag foo : /bin/driver -x foo * set variable 'cable' to '1234' : /bin/driver -x cable=1234 * * to test flag foo in your code: * * if (testvar("foo")) * do_something(); * * to show the value of cable: * * if ((cable = getval("cable"))) * printf("cable is set to %s\n", cable); * else * printf("cable is not set!\n"); * * don't use NULL pointers - test the return result first! */ /* the upsh handlers can't be done here, as they get initialized * shortly after upsdrv_initups returns to main. */ /* don't try to detect the UPS here */ } void upsdrv_cleanup(void) { /* free(dynamic_mem); */ /* ser_close(upsfd, device_path); */ } nut-2.8.4/drivers/liebert-hid.c0000644000175000017500000002205114777753337013315 00000000000000/* liebert-hid.c - subdriver to monitor Liebert USB/HID devices with NUT * * Copyright (C) * 2003 - 2008 Arnaud Quette * 2005 - 2006 Peter Selinger * 2007 Charles Lepple * 2018 Markus "Links2004" * 2023 Blaž Zakrajšek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" /* for getval() */ #include "usbhid-ups.h" #include "liebert-hid.h" #include "usb-common.h" #define LIEBERT_HID_VERSION "Phoenixtec/Liebert HID 0.41" /* FIXME: experimental flag to be put in upsdrv_info */ /* Phoenixtec Power Co., Ltd */ #define LIEBERT_VENDORID 0x06da /*! USB IDs device table. * * Note that this subdriver was named before the USB VendorID was determined to * actually belong to Phoenixtec. The belkin-hid.c file covers the other * Liebert units which share some of the same incorrect exponents as the * Belkin HID firmware. */ static usb_device_id_t liebert_usb_device_table[] = { /* various models */ { USB_DEVICE(LIEBERT_VENDORID, 0xffff), NULL }, /* Terminating entry */ { 0, 0, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* LIEBERT usage table */ static usage_lkp_t liebert_usage_lkp[] = { { NULL, 0 } }; static usage_tables_t liebert_utab[] = { liebert_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t liebert_hid2nut[] = { #if WITH_UNMAPPED_DATA_POINTS { "unmapped.ups.powersummary.flowid", 0, 0, "UPS.PowerSummary.FlowID", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.powersummaryid", 0, 0, "UPS.PowerSummary.PowerSummaryID", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitygranularity1", 0, 0, "UPS.PowerSummary.CapacityGranularity1", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitymode", 0, 0, "UPS.PowerSummary.CapacityMode", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.rechargeable", 0, 0, "UPS.PowerSummary.Rechargeable", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.iproduct", 0, 0, "UPS.PowerSummary.iProduct", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.product", 0, 0, "UPS.PowerSummary.iProduct", NULL, "%s", 0, stringid_conversion }, { "unmapped.ups.powersummary.imanufacturer", 0, 0, "UPS.PowerSummary.iManufacturer", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.manufacturer", 0, 0, "UPS.PowerSummary.iManufacturer", NULL, "%s", 0, stringid_conversion }, { "unmapped.ups.powersummary.iserialnumber", 0, 0, "UPS.PowerSummary.iSerialNumber", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.serialnumber", 0, 0, "UPS.PowerSummary.iSerialNumber", NULL, "%s", 0, stringid_conversion }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* Battery page */ { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.2f", 0, NULL }, { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "experimental.battery.capacity", 0, 0, "UPS.PowerSummary.FullChargeCapacity", NULL, "%.0f", 0, NULL }, { "experimental.battery.capacity.nominal", 0, 0, "UPS.PowerSummary.DesignCapacity", NULL, "%.0f", 0, NULL }, { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", 0, stringid_conversion }, /* UPS page */ { "ups.load", 0, 0, "UPS.PowerSummary.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.power.nominal", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "ups.test.result", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "%s", 0, test_read_info }, { "ups.beeper.status", 0 ,0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "%s", HU_FLAG_SEMI_STATIC, beeper_info }, /* Output page */ { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.1f", 0, NULL }, { "output.voltage.nominal", 0, 0, "UPS.Flow.[4].ConfigVoltage", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%.2f", 0, NULL }, { "output.frequency.nominal", 0, 0, "UPS.Flow.[4].ConfigFrequency", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "output.transfer.high", 0, 0, "UPS.PowerConverter.Output.HighVoltageTransfer", NULL, "%.1f", HU_FLAG_SEMI_STATIC, NULL }, { "output.transfer.low", 0, 0, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.1f", HU_FLAG_SEMI_STATIC, NULL }, /* Input page */ { "input.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Voltage", NULL, "%.1f", 0, NULL }, { "input.frequency", 0, 0, "UPS.PowerConverter.Input.[1].Frequency", NULL, "%.2f", 0, NULL }, { "input.transfer.low", 0, 0, "UPS.PowerConverter.Output.ffff0057", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.high", 0, 0, "UPS.PowerConverter.Output.ffff0058", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL}, { "input.frequency.transfer.low", 0, 0, "UPS.PowerConverter.Output.ffff00f9", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.frequency.transfer.high", 0, 0, "UPS.PowerConverter.Output.ffff00f8", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL}, /* Status page */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, "%.0f", HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, "%.0f", HU_FLAG_QUICK_POLL, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, "%.0f", HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, "%.0f", HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, "%.0f", HU_FLAG_QUICK_POLL, overload_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Good", NULL, NULL, HU_FLAG_QUICK_POLL, off_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.InternalFailure", NULL, NULL, HU_FLAG_QUICK_POLL, commfault_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, "%.0f", HU_FLAG_QUICK_POLL, shutdownimm_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.Buck", NULL, NULL, 0, trim_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.Boost", NULL, NULL, 0, boost_info }, /* Variables */ { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL}, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL}, /* Instant commands */ { "test.battery.start", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "load.off.delay", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.PowerSummary.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "shutdown.stop", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, { "beeper.toggle", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *liebert_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *liebert_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "Liebert"; } static const char *liebert_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int liebert_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(liebert_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("Liebert", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t liebert_subdriver = { LIEBERT_HID_VERSION, liebert_claim, liebert_utab, liebert_hid2nut, liebert_format_model, liebert_format_mfr, liebert_format_serial, fix_report_desc, }; nut-2.8.4/drivers/nutdrv_qx.h0000644000175000017500000003200415044656702013145 00000000000000/* nutdrv_qx.h - Driver for USB and serial UPS units with Q* protocols * * Copyright (C) * 2013 Daniele Pezzini * Based on usbhid-ups.h - Copyright (C) * 2003-2009 Arnaud Quette * 2005-2006 Peter Selinger * 2007-2009 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_H #define NUTDRV_QX_H /* "config.h" is generated by autotools and lacks a header guard, so * we use an unambiguously named macro we know we must have, as one. * It must be the first header: be sure to know all about system config. */ #ifndef NUT_NETVERSION # include "config.h" #endif #include #include #include #include /* For testing purposes */ /*#define TESTING*/ /* Driver's parameters */ #define QX_VAR_ONDELAY "ondelay" #define QX_VAR_OFFDELAY "offdelay" #define QX_VAR_POLLFREQ "pollfreq" /* Parameters default values */ #define DEFAULT_ONDELAY "180" /* Delay between return of utility power and powering up of load, in seconds */ #define DEFAULT_OFFDELAY "30" /* Delay before power off, in seconds */ #define DEFAULT_POLLFREQ 30 /* Polling interval between full updates, in seconds; the driver will do quick polls in the meantime */ #ifndef TRUE typedef enum { FALSE, TRUE } bool_t; #else typedef int bool_t; #endif /* Structure for rw vars */ typedef struct { char value[SMALLBUF]; /* Value for enum/range, or length for ST_FLAG_STRING */ int (*preprocess)(char *value, const size_t len); /* Optional function to preprocess range/enum value. * This function will be given value and its size_t and must return either 0 if value is supported or -1 if not supported. */ } info_rw_t; /* Structure containing information about how to get/set data from/to the UPS and convert these to/from NUT standard */ typedef struct item_t { const char *info_type; /* NUT variable name * If QX_FLAG_NONUT is set, name to print to the logs * If both QX_FLAG_NONUT and QX_FLAG_SETVAR are set, name of the var to retrieve from ups.conf */ const int info_flags; /* NUT flags (ST_FLAG_* values to set in dstate_addinfo) */ info_rw_t *info_rw; /* An array of info_rw_t to handle r/w variables: * If ST_FLAG_STRING is set: length of the string (dstate_setaux) * If QX_FLAG_ENUM is set: enumerated values (dstate_addenum) * If QX_FLAG_RANGE is set: range boundaries (dstate_addrange) * If QX_FLAG_SETVAR is set the value given by the user will be checked against these infos. */ const char *command; /* Command sent to the UPS to get answer/to execute an instant command/to set a variable */ char answer[SMALLBUF]; /* Answer from the UPS, filled at runtime. * If you expect a nonvalid C string (e.g.: inner '\0's) or need to perform actions before the answer is used (and treated as a null-terminated string), you should set a preprocess_answer() function */ const size_t answer_len; /* Expected min length of the answer. Set it to 0 if there's no minimum length to look after. */ const char leading; /* Expected leading character of the answer (optional) */ char value[SMALLBUF]; /* Value from the answer, filled at runtime (i.e. answer between from and to) */ const int from; /* Position of the starting character of the info (i.e. 'value') we're after in the answer */ const int to; /* Position of the ending character of the info (i.e. 'value') we're after in the answer: use 0 if all the remaining of the line is needed */ const char *dfl; /* Format to store value from the UPS in NUT variables. Not used by the driver for QX_FLAG_{CMD,SETVAR} items. * If there's no preprocess function, set it either to %s for strings or to a floating point specifier (e.g. %.1f) for numbers. * Otherwise: * If QX_FLAG_ABSENT: default value * If QX_FLAG_CMD: default command value */ unsigned long qxflags; /* Driver's own flags */ int (*preprocess_command)(struct item_t *item, char *command, const size_t commandlen); /* Last chance to preprocess the command to be sent to the UPS (e.g. to add CRC, ...). * This function is given the currently processed item (item), the command to be sent to the UPS (command) and its size_t (commandlen). * Return -1 in case of errors, else 0 if a NUL terminated string, else the length of the command in bytes. * command must be filled with the actual command to be sent to the UPS. */ int (*preprocess_answer)(struct item_t *item, const int len); /* Function to preprocess the answer we got from the UPS before we do anything else (e.g. for CRC, decoding, ...). * This function is given the currently processed item (item) with the answer we got from the UPS unmolested and already stored in item->answer and the length of that answer (len). * Return -1 in case of errors, else the length of the newly allocated item->answer (from now on, treated as a null-terminated string). */ int (*preprocess)(struct item_t *item, char *value, const size_t valuelen); /* Function to preprocess the data from/to the UPS * This function is given the currently processed item (item), a char array (value) and its size_t (valuelen). * Return -1 in case of errors, else 0. * If QX_FLAG_SETVAR/QX_FLAG_CMD -> process command before it is sent: value must be filled with the command to be sent to the UPS. * Otherwise -> process value we got from answer before it gets stored in a NUT variable: value must be filled with the processed value already compliant to NUT standards. */ } item_t; /* Driver's own flags */ #define QX_FLAG_STATIC 2UL /* Retrieve info only once. */ #define QX_FLAG_SEMI_STATIC 4UL /* Retrieve info smartly, i.e. only when a command/setvar is executed and we expect that data could have been changed. */ #define QX_FLAG_ABSENT 8UL /* Data is absent in the device, use default value. */ #define QX_FLAG_QUICK_POLL 16UL /* Mandatory vars, polled also in QX_WALKMODE_QUICK_UPDATE. * If there's a problem with a var not flagged as QX_FLAG_QUICK_POLL in QX_WALKMODE_INIT, the driver will automagically set QX_FLAG_SKIP on it and then it'll skip that item in QX_WALKMODE_{QUICK,FULL}_UPDATE. * Otherwise, if the item has the flag QX_FLAG_QUICK_POLL set, in case of errors in QX_WALKMODE_INIT the driver will set datastale. */ #define QX_FLAG_CMD 32UL /* Instant command. */ #define QX_FLAG_SETVAR 64UL /* The var is settable and the actual item stores info on how to set it. */ #define QX_FLAG_TRIM 128UL /* This var's value need to be trimmed of leading/trailing spaces/hashes. */ #define QX_FLAG_ENUM 256UL /* Enum values exist and are stored in info_rw. */ #define QX_FLAG_RANGE 512UL /* Ranges for this var available and are stored in info_rw. */ #define QX_FLAG_NONUT 1024UL /* This var doesn't have a corresponding var in NUT. */ #define QX_FLAG_SKIP 2048UL /* Skip this var: this item won't be processed. */ #define MAXTRIES 3 /* Max number of retries */ #ifdef TESTING /* Testing struct */ typedef struct { const char *cmd; /* Command to match */ const char answer[SMALLBUF]; /* Answer for that command. * Note: if 'answer' contains inner '\0's, in order to preserve them, 'answer_len' as well as an item_t->preprocess_answer() function must be set */ const int answer_len; /* Answer length: * - if set to -1 -> auto calculate answer length (treat 'answer' as a null-terminated string) * - otherwise -> use the provided length (if reasonable) and preserve inner '\0's (treat 'answer' as a sequence of bytes till the item_t->preprocess_answer() function gets called) */ } testing_t; #endif /* TESTING */ /* Subdriver interface */ typedef struct { const char *name; /* Name of this subdriver, i.e. name (must be equal to the protocol name) + space + version */ int (*claim)(void); /* Function that allows the subdriver to "claim" a device: return 1 if device is covered by this subdriver, else 0 */ item_t *qx2nut; /* Main table of vars and instcmds */ void (*initups)(void); /* Subdriver specific upsdrv_initups. Called at the end of nutdrv_qx's own upsdrv_initups */ void (*initinfo)(void); /* Subdriver specific upsdrv_initinfo. Called at the end of nutdrv_qx's own upsdrv_initinfo */ void (*makevartable)(void); /* Subdriver specific ups.conf flags/vars */ const char *accepted; /* String to match if the driver is expecting a reply from the UPS on instcmd/setvar. * This comparison is done after the answer we got back from the UPS has been processed to get the value we are searching: * - you don't have to include the trailing carriage return (\r) * - you can decide at which index of the answer the value should start or end setting the appropriate from and to in the item_t */ const char *rejected; /* String to match if the driver is expecting a reply from the UPS in case of error. * This comparison is done on the answer we got back from the UPS before it has been processed: * - include also the trailing carriage return (\r) and whatever character is expected */ #ifdef TESTING testing_t *testing; /* Testing table: commands and the replies used for testing the subdriver */ #endif /* TESTING */ } subdriver_t; /* The following functions are exported for the benefit of subdrivers */ /* Execute an instant command. In detail: * - look up the given 'cmdname' in the qx2nut data structure (if not found, try to fallback to commonly known commands); * - if 'cmdname' is found, call its preprocess function, passing to it 'extradata', if any, otherwise its dfl value, if any; * - send the command to the device and check the reply. * Return STAT_INSTCMD_INVALID if the command is invalid, STAT_INSTCMD_FAILED if it failed, STAT_INSTCMD_HANDLED on success. */ int instcmd(const char *cmdname, const char *extradata); /* Set r/w variable to a value after it has been checked against its info_rw structure. Return STAT_SET_HANDLED on success, otherwise STAT_SET_UNKNOWN. */ int setvar(const char *varname, const char *val); /* Find an item of item_t type in qx2nut data structure by its info_type, optionally filtered by its qxflags, and return it if found, otherwise return NULL. * - 'flag': flags that have to be set in the item, i.e. if one of the flags is absent in the item it won't be returned * - 'noflag': flags that have to be absent in the item, i.e. if at least one of the flags is set in the item it won't be returned */ item_t *find_nut_info(const char *varname, const unsigned long flag, const unsigned long noflag); /* Send 'command' (a null-terminated byte string) or, if it is NULL, send the command stored in the item to the UPS and process the reply, saving it in item->answer. Return -1 on errors, 0 on success. */ int qx_process(item_t *item, const char *command); /* Process the value we got back from the UPS (set status bits and set the value of other parameters), calling the item-specific preprocess function, if any, otherwise executing the standard preprocessing (including trimming if QX_FLAG_TRIM is set). * Return -1 on failure, 0 for a status update and 1 in all other cases. */ int ups_infoval_set(item_t *item); /* Return the currently processed status so that it can be checked with one of the status_bit_t passed to the STATUS() macro. */ unsigned int qx_status(void); /* Edit the current status: it takes one of the NUT status (all but OB are supported, simply set it as not OL), eventually preceded with an exclamation mark to clear it from the status (e.g. !OL). */ void update_status(const char *nutvalue); /* Let subdrivers reference this: for devices that report "battery.voltage" of a single cell/pack, optionally multiply that into representing the whole assembly */ int qx_multiply_battvolt(item_t *item, char *value, const size_t valuelen); /* Convert kilo-values to their full representation */ int qx_multiply_x1000(item_t *item, char *value, const size_t valuelen); /* Convert minutes to seconds */ int qx_multiply_m2s(item_t *item, char *value, const size_t valuelen); /* Data for processing status values */ #define STATUS(x) ((unsigned int)1U< * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_VOLTRONIC_QS_H #define NUTDRV_QX_VOLTRONIC_QS_H #include "nutdrv_qx.h" extern subdriver_t voltronic_qs_subdriver; #endif /* NUTDRV_QX_VOLTRONIC_QS_H */ nut-2.8.4/drivers/eaton-ats30-mib.c0000644000175000017500000006146315000601404013701 00000000000000/* eaton-ats30-mib.c - subdriver to monitor eaton_ats30 SNMP devices with NUT * * Copyright (C) 2017 Eaton * Author: Tomas Halman * 2011-2012 Arnaud Quette * * Note: this subdriver was initially generated as a "stub" by the * gen-snmp-subdriver script. It must be customized! * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "eaton-ats30-mib.h" #define EATON_ATS30_MIB_VERSION "0.03" #define EATON_ATS30_SYSOID ".1.3.6.1.4.1.534.10.1" #define EATON_ATS30_MODEL ".1.3.6.1.4.1.534.10.1.2.1.0" static info_lkp_t eaton_ats30_source_info[] = { info_lkp_default(1, "init"), info_lkp_default(2, "diagnosis"), info_lkp_default(3, "off"), info_lkp_default(4, "1"), info_lkp_default(5, "2"), info_lkp_default(6, "safe"), info_lkp_default(7, "fault"), info_lkp_sentinel }; static info_lkp_t eaton_ats30_input_sensitivity[] = { info_lkp_default(1, "high"), info_lkp_default(2, "low"), info_lkp_sentinel }; /* * bitmap values of atsStatus.atsFailureIndicator * * 1 atsFailureSwitchFault N/A * 2 atsFailureNoOutput OFF * 3 atsFailureOutputOC OVER * 4 atsFailureOverTemperature N/A */ static info_lkp_t eaton_ats30_status_info[] = { info_lkp_default(0, "OL"), info_lkp_default(1, "OL"), /* SwitchFault */ info_lkp_default(2, "OFF"), /* NoOutput */ info_lkp_default(3, "OFF"), /* SwitchFault + NoOutput */ info_lkp_default(4, "OL OVER"), /* OutputOC */ info_lkp_default(5, "OL OVER"), /* OutputOC + SwitchFault */ info_lkp_default(6, "OFF OVER"), /* OutputOC + NoOutput */ info_lkp_default(7, "OFF OVER"), /* OutputOC + SwitchFault + NoOutput */ info_lkp_default(8, "OL"), /* OverTemperature */ info_lkp_default(9, "OL"), /* OverTemperature + SwitchFault */ info_lkp_default(10, "OFF"), /* OverTemperature + NoOutput */ info_lkp_default(11, "OFF"), /* OverTemperature + SwitchFault + NoOutput */ info_lkp_default(12, "OL OVER"), /* OverTemperature + OutputOC */ info_lkp_default(13, "OL OVER"), /* OverTemperature + OutputOC + SwitchFault */ info_lkp_default(14, "OFF OVER"), /* OverTemperature + OutputOC + NoOutput */ info_lkp_default(15, "OFF OVER"), /* OverTemperature + OutputOC + SwitchFault + NoOutput */ info_lkp_sentinel }; /* EATON_ATS30 Snmp2NUT lookup table */ static snmp_info_t eaton_ats30_mib[] = { /* device type: ats */ snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "ats", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.1.1.0 = STRING: "Eaton" */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.1.1.0", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* enterprises.534.10.1.1.2.0 = STRING: "01.12.13b" -- SNMP agent version */ /* snmp_info_default("device.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.1.2.0", NULL, SU_FLAG_OK, NULL), */ /* enterprises.534.10.1.1.3.1.0 = INTEGER: 1 */ /* snmp_info_default("unmapped.enterprise", 0, 1, ".1.3.6.1.4.1.534.10.1.1.3.1.0", NULL, SU_FLAG_OK, NULL), */ /* enterprises.534.10.1.2.1.0 = STRING: "STS30002SR10019 " */ snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.2.1.0", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* enterprises.534.10.1.2.2.0 = STRING: "1A0003AR00.00.00" -- Firmware */ snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.2.2.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.2.3.0 = STRING: "2014-09-17 " -- Release date */ /* snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.2.3.0", NULL, SU_FLAG_OK, NULL), */ /* enterprises.534.10.1.2.4.0 = STRING: "JA00E52021 " */ snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.2.4.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.2.5.0 = STRING: " " -- Device ID codes */ /* snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.2.5.0", NULL, SU_FLAG_OK, NULL), */ /* ats measure */ /* =========== */ /* enterprises.534.10.1.3.1.1.1.1 = INTEGER: 1 */ snmp_info_default("input.1.id", 0, 1, ".1.3.6.1.4.1.534.10.1.3.1.1.1.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.1.1.1.2 = INTEGER: 2 */ snmp_info_default("input.2.id", 0, 1, ".1.3.6.1.4.1.534.10.1.3.1.1.1.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.1.1.2.1 = INTEGER: 2379 */ snmp_info_default("input.1.voltage", 0, 0.1, ".1.3.6.1.4.1.534.10.1.3.1.1.2.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.1.1.2.2 = INTEGER: 0 */ snmp_info_default("input.2.voltage", 0, 0.1, ".1.3.6.1.4.1.534.10.1.3.1.1.2.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.1.1.3.1 = INTEGER: 500 */ snmp_info_default("input.1.frequency", 0, 0.1, ".1.3.6.1.4.1.534.10.1.3.1.1.3.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.1.1.3.2 = INTEGER: 0 */ snmp_info_default("input.2.frequency", 0, 0.1, ".1.3.6.1.4.1.534.10.1.3.1.1.3.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.2.1.0 = INTEGER: 2375 */ snmp_info_default("output.voltage", 0, 0.1, ".1.3.6.1.4.1.534.10.1.3.2.1.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.2.2.0 = INTEGER: 0 */ snmp_info_default("output.current", 0, 0.1, ".1.3.6.1.4.1.534.10.1.3.2.2.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.3.0 = INTEGER: 25 -- internal temperature in celsius */ snmp_info_default("ups.temperature", 0, 1, ".1.3.6.1.4.1.534.10.1.3.3.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.4.0 = INTEGER: 77 -- internal temperature in fahrenheit */ /* snmp_info_default("ups.temperatureF", 0, 1, ".1.3.6.1.4.1.534.10.1.3.4.0", NULL, SU_FLAG_OK, NULL), */ /* enterprises.534.10.1.3.5.0 = INTEGER: 37937541 */ snmp_info_default("device.uptime", 0, 1, ".1.3.6.1.4.1.534.10.1.3.5.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.3.6.0 = INTEGER: 284 */ /* snmp_info_default("unmapped.atsMessureTransferedTimes", 0, 1, ".1.3.6.1.4.1.534.10.1.3.6.0", NULL, SU_FLAG_OK, NULL), */ /* enterprises.534.10.1.3.7.0 = INTEGER: 4 */ snmp_info_default("input.source", 0, 1, ".1.3.6.1.4.1.534.10.1.3.7.0", NULL, SU_FLAG_OK, eaton_ats30_source_info), /* atsStatus */ /* ========= */ #if WITH_UNMAPPED_DATA_POINTS /* NOTE: Unused OIDs are left as comments for potential future improvements */ /* enterprises.534.10.1.4.1.0 = INTEGER: 7 */ snmp_info_default("unmapped.atsInputFlowIndicator", 0, 1, ".1.3.6.1.4.1.534.10.1.4.1.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.1.1 = INTEGER: 1 -- atsInputFlowTable start */ snmp_info_default("unmapped.atsInputFlowIndex.1", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.1.2 = INTEGER: 2 */ snmp_info_default("unmapped.atsInputFlowIndex.2", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.1.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.2.1 = INTEGER: 1 */ snmp_info_default("unmapped.atsInputFlowRelay.1", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.2.2 = INTEGER: 2 */ snmp_info_default("unmapped.atsInputFlowRelay.2", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.2.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.3.1 = INTEGER: 1 */ snmp_info_default("unmapped.atsInputFlowSCR.1", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.3.2 = INTEGER: 2 */ snmp_info_default("unmapped.atsInputFlowSCR.2", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.3.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.4.1 = INTEGER: 1 */ snmp_info_default("unmapped.atsInputFlowParallelRelay.1", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.4.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.2.1.4.2 = INTEGER: 2 */ snmp_info_default("unmapped.atsInputFlowParallelRelay.2", 0, 1, ".1.3.6.1.4.1.534.10.1.4.2.1.4.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.3.0 = INTEGER: 58720256 */ snmp_info_default("unmapped.atsInputFailureIndicator", 0, 1, ".1.3.6.1.4.1.534.10.1.4.3.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.1.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.1.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.1.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.2.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.2.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.2.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.2.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.3.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.3.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.3.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.3.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.4.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.4.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.4.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.4.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.5.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.5.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.5.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.5.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.6.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.6.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.6.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.6.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.7.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.7.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.7.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.7.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.8.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.8.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.8.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.8.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.9.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.9.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.9.2 = INTEGER: 1 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.9.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.10.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.10.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.10.2 = INTEGER: 1 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.10.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.11.1 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.11.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.4.1.11.2 = INTEGER: 1 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.4.1.11.2", NULL, SU_FLAG_OK, NULL), #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* enterprises.atsFailureIndicator = INTEGER: 0 */ snmp_info_default("ups.status", 0, 1, ".1.3.6.1.4.1.534.10.1.4.5.0", NULL, SU_FLAG_OK, eaton_ats30_status_info), #if WITH_UNMAPPED_DATA_POINTS /* enterprises.534.10.1.4.6.1.0 = INTEGER: 2 -- atsFailure start */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.6.1.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.6.2.0 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.6.2.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.6.3.0 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.6.3.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.4.6.4.0 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.4.6.4.0", NULL, SU_FLAG_OK, NULL), #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* atsLog */ /* ====== */ #if WITH_UNMAPPED_DATA_POINTS /* We are not interested in log */ /* enterprises.534.10.1.5.1.0 = INTEGER: 272 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.1.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.3 = INTEGER: 3 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.3", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.4 = INTEGER: 4 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.4", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.5 = INTEGER: 5 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.5", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.6 = INTEGER: 6 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.6", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.7 = INTEGER: 7 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.7", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.8 = INTEGER: 8 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.8", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.9 = INTEGER: 9 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.9", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.1.10 = INTEGER: 10 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.1.10", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.1 = INTEGER: 1482323677 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.2 = INTEGER: 1480076955 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.3 = INTEGER: 1480069128 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.3", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.4 = INTEGER: 1480069093 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.4", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.5 = INTEGER: 1478693745 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.5", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.6 = INTEGER: 1478693741 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.6", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.7 = INTEGER: 1466604406 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.7", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.8 = INTEGER: 1466604386 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.8", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.9 = INTEGER: 1466604386 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.9", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.2.10 = INTEGER: 1463038288 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.2.10", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.1 = INTEGER: 41 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.2 = INTEGER: 41 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.3 = INTEGER: 44 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.3", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.4 = INTEGER: 44 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.4", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.5 = INTEGER: 44 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.5", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.6 = INTEGER: 41 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.6", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.7 = INTEGER: 41 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.7", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.8 = INTEGER: 46 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.8", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.9 = INTEGER: 45 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.9", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.3.10 = INTEGER: 41 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.5.2.1.3.10", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.1 = STRING: "12:34:37 12/21/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.2 = STRING: "12:29:15 11/25/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.3 = STRING: "10:18:48 11/25/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.3", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.4 = STRING: "10:18:13 11/25/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.4", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.5 = STRING: "12:15:45 11/09/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.5", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.6 = STRING: "12:15:41 11/09/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.6", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.7 = STRING: "14:06:46 06/22/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.7", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.8 = STRING: "14:06:26 06/22/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.8", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.9 = STRING: "14:06:26 06/22/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.9", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.5.2.1.4.10 = STRING: "07:31:28 05/12/2016" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.5.2.1.4.10", NULL, SU_FLAG_OK, NULL), #endif /* WITH_UNMAPPED_DATA_POINTS */ /* atsConfig */ /* ========= */ #if WITH_UNMAPPED_DATA_POINTS /* enterprises.534.10.1.6.1.1.0 = INTEGER: 538562409 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.1.1.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.1.2.0 = STRING: "01/24/2017" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.6.1.2.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.1.3.0 = STRING: "08:40:09" */ snmp_info_default("unmapped.enterprises", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.1.6.1.3.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.1.1 = INTEGER: 1 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.1.2 = INTEGER: 2 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.1.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.2.1 = INTEGER: 1700 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.2.2 = INTEGER: 1700 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.2.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.3.1 = INTEGER: 1800 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.3.2 = INTEGER: 1800 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.3.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.4.1 = INTEGER: 2640 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.4.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.4.2 = INTEGER: 2640 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.4.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.5.1 = INTEGER: 3000 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.5.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.5.2 = INTEGER: 3000 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.5.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.6.1 = INTEGER: 50 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.6.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.6.2 = INTEGER: 50 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.6.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.7.1 = INTEGER: 40 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.7.1", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.2.1.7.2 = INTEGER: 40 */ snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.6.2.1.7.2", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.3.0 = INTEGER: 2640 */ snmp_info_default("unmapped.atsConfigInputVoltageRating", 0, 1, ".1.3.6.1.4.1.534.10.1.6.3.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.4.0 = INTEGER: 26 */ snmp_info_default("unmapped.atsConfigRandomTime", 0, 1, ".1.3.6.1.4.1.534.10.1.6.4.0", NULL, SU_FLAG_OK, NULL), #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* enterprises.534.10.1.6.5.0 = INTEGER: 1 */ snmp_info_default("input.source.preferred", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.1.6.5.0", NULL, SU_FLAG_OK, NULL), /* enterprises.534.10.1.6.6.0 = INTEGER: 2 */ snmp_info_default("input.sensitivity", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.1.6.6.0", NULL, SU_FLAG_OK, eaton_ats30_input_sensitivity), /* enterprises.534.10.1.6.7.0 = INTEGER: 2 */ /* snmp_info_default("unmapped.atsConfigTest", 0, 1, ".1.3.6.1.4.1.534.10.1.6.7.0", NULL, SU_FLAG_OK, NULL), */ /* atsUpgrade */ /* ========== */ #if WITH_UNMAPPED_DATA_POINTS /* We are not interested in atsUpgrade */ /* enterprises.534.10.1.7.1.0 = INTEGER: 1 */ /* snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.7.1.0", NULL, SU_FLAG_OK, NULL), */ /* enterprises.534.10.1.7.2.0 = INTEGER: 1 */ /* snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.7.2.0", NULL, SU_FLAG_OK, NULL), */ /* enterprises.534.10.1.7.3.0 = INTEGER: 0 */ /* snmp_info_default("unmapped.enterprises", 0, 1, ".1.3.6.1.4.1.534.10.1.7.3.0", NULL, SU_FLAG_OK, NULL), */ #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t eaton_ats30 = { "eaton_ats30", EATON_ATS30_MIB_VERSION, NULL, EATON_ATS30_MODEL, eaton_ats30_mib, EATON_ATS30_SYSOID, NULL }; nut-2.8.4/drivers/nutdrv_qx_q6.c0000644000175000017500000003032615000736161013541 00000000000000/* nutdrv_qx_q6.c - Subdriver for Q6 Megatec protocol variant * * Copyright (C) * 2024 Viktor Drobot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_q6.h" #define Q6_VERSION "Q6 0.01" /* Support functions */ static int q6_process_topology_bits(item_t *item, char *value, const size_t valuelen); static int q6_claim(void); static void q6_initups(void); static void q6_initinfo(void); static void q6_makevartable(void); /* qx2nut lookup table */ static item_t q6_qx2nut[] = { /* * > [Q6\r] * < [(MMM.M MMM.M MMM.M NN.N PPP.P PPP.P PPP.P RR.R QQQ QQQ QQQ SSS.S VVV.V TT.T ttttt CCC KB ffffffff wwwwwwww YO\r] * 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 * 0 1 2 3 4 5 6 7 8 9 10 */ /* Common parameters */ { "input.L1-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.L2-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 7, 11, "%.1f", 0, NULL, NULL, NULL }, { "input.L3-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 13, 17, "%.1f", 0, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "Q6\r", "", 110, '(', "", 19, 22, "%.1f", 0, NULL, NULL, NULL }, { "output.L1-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 24, 28, "%.1f", 0, NULL, NULL, NULL }, { "output.L2-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 30, 34, "%.1f", 0, NULL, NULL, NULL }, { "output.L3-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 36, 40, "%.1f", 0, NULL, NULL, NULL }, { "output.frequency", 0, NULL, "Q6\r", "", 110, '(', "", 42, 45, "%.1f", 0, NULL, NULL, NULL }, { "output.L1.load", 0, NULL, "Q6\r", "", 110, '(', "", 47, 49, "%.0f", 0, NULL, NULL, NULL }, { "output.L2.load", 0, NULL, "Q6\r", "", 110, '(', "", 51, 53, "%.0f", 0, NULL, NULL, NULL }, { "output.L3.load", 0, NULL, "Q6\r", "", 110, '(', "", 55, 57, "%.0f", 0, NULL, NULL, NULL }, { "ups.temperature", 0, NULL, "Q6\r", "", 110, '(', "", 71, 74, "%.1f", 0, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 59, 63, "%.1f", 0, NULL, NULL, qx_multiply_battvolt }, { "battery.runtime", 0, NULL, "Q6\r", "", 110, '(', "", 76, 80, "%.0f", 0, NULL, NULL, NULL }, { "battery.charge", 0, NULL, "Q6\r", "", 110, '(', "", 82, 84, "%.0f", 0, NULL, NULL, NULL }, { "experimental.battery.voltage.negative", 0, NULL, "Q6\r", "", 110, '(', "", 65, 69, "%.1f", 0, NULL, NULL, qx_multiply_battvolt }, /* Negative battery voltage */ { "experimental.input.topology", 0, NULL, "Q6\r", "", 110, '(', "", 107, 107, "%s", QX_FLAG_STATIC, NULL, NULL, q6_process_topology_bits }, /* Input transformer topology */ { "experimental.output.topology", 0, NULL, "Q6\r", "", 110, '(', "", 108, 108, "%s", QX_FLAG_STATIC, NULL, NULL, q6_process_topology_bits }, /* Output transformer topology */ /* TODO handle KB (86-87) properly: mb use "experimental." vars for that */ /* * > [WA\r] * < [(WWW.W WWW.W WWW.W VVV.V VVV.V VVV.V TTT.T SSS.S AAA.A AAA.A AAA.A QQQ b7b6b5b4b3b2b1b0\r] * 012345678901234567890123456789012345678901234567890123456789012345678901 2 3 4 5 6 7 8 9 * 0 1 2 3 4 5 6 7 */ /* Output consumption parameters */ { "output.L1.realpower", 0, NULL, "WA\r", "", 80, '(', "", 1, 5, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "output.L2.realpower", 0, NULL, "WA\r", "", 80, '(', "", 7, 11, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "output.L3.realpower", 0, NULL, "WA\r", "", 80, '(', "", 13, 17, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "output.L1.power", 0, NULL, "WA\r", "", 80, '(', "", 19, 23, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "output.L2.power", 0, NULL, "WA\r", "", 80, '(', "", 25, 29, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "output.L3.power", 0, NULL, "WA\r", "", 80, '(', "", 31, 35, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "output.L1.current", 0, NULL, "WA\r", "", 80, '(', "", 49, 53, "%.1f", 0, NULL, NULL, NULL }, { "output.L2.current", 0, NULL, "WA\r", "", 80, '(', "", 55, 59, "%.1f", 0, NULL, NULL, NULL }, { "output.L3.current", 0, NULL, "WA\r", "", 80, '(', "", 61, 65, "%.1f", 0, NULL, NULL, NULL }, { "ups.realpower", 0, NULL, "WA\r", "", 80, '(', "", 37, 41, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "ups.power", 0, NULL, "WA\r", "", 80, '(', "", 43, 47, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "ups.load", 0, NULL, "WA\r", "", 80, '(', "", 67, 69, "%.0f", 0, NULL, NULL, NULL }, /* * > [Q1\r] * < [(MMM.M NNN.N PPP.P QQQ RR.R S.SS TT.T b7b6b5b4b3b2b1b0\r] * 012345678901234567890123456789012345678 9 0 1 2 3 4 5 6 * 0 1 2 3 4 */ /* Status bits */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 38, 38, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Utility Fail (Immediate) */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 39, 39, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Battery Low */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 40, 40, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Bypass/Boost or Buck Active */ { "ups.alarm", 0, NULL, "Q1\r", "", 47, '(', "", 41, 41, NULL, 0, NULL, NULL, blazer_process_status_bits }, /* UPS Failed */ { "ups.type", 0, NULL, "Q1\r", "", 47, '(', "", 42, 42, "%s", QX_FLAG_STATIC, NULL, NULL, blazer_process_status_bits }, /* UPS Type */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 43, 43, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Test in Progress */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 44, 44, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Shutdown Active */ { "ups.beeper.status", 0, NULL, "Q1\r", "", 47, '(', "", 45, 45, "%s", 0, NULL, NULL, blazer_process_status_bits }, /* Beeper status */ /* Instant commands */ { "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%sR0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, blazer_r_ondelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_ONDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, blazer_r_offdelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_OFFDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* Testing table */ #ifdef TESTING static testing_t q6_testing[] = { { "Q6\r", "(227.0 225.6 230.0 50.0 229.9 000.0 000.0 49.9 007 000 000 327.8 000.0 23.0 06932 100 32 00000000 00000000 11\r", -1 }, { "WA\r", "(001.4 000.0 000.0 001.4 000.0 000.0 001.4 001.4 006.5 000.0 000.0 007 00000000\r", -1 }, { "Q1\r", "(215.0 195.0 230.0 014 49.0 22.7 30.0 00000000\r", -1 }, { "Q\r", "", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0000\r", "", -1 }, { "T04\r", "", -1 }, { "TL\r", "", -1 }, { "T\r", "", -1 }, { "CT\r", "", -1 }, { NULL } }; #endif /* TESTING */ /* == Support functions == */ /* This function allows to process input/output transformers topology bits */ static int q6_process_topology_bits(item_t *item, char *value, const size_t valuelen) { char *val = ""; if (strspn(item->value, "01") != 1) { upsdebugx(3, "%s: unexpected value %s@%d->%s", __func__, item->value, item->from, item->value); return -1; } switch (item->from) { case 107: /* Input topology - experimental.input.topology */ if (item->value[0] == '1') val = "star"; else if (item->value[0] == '0') val = "delta"; else val = "unknown"; break; case 108: /* Output topology - experimental.output.topology */ if (item->value[0] == '1') val = "star"; else if (item->value[0] == '0') val = "delta"; else val = "unknown"; break; default: /* Don't know what happened */ return -1; } snprintf(value, valuelen, "%s", val); return 0; } /* This function allows the subdriver to "claim" a device: * return 1 if the device is supported by this subdriver, else 0 */ static int q6_claim(void) { /* We need Q6, Q1, and WA to use this subdriver (WA only if user hasn't requested 'nooutstats' flag) */ /* TODO think whether we should check for BPS (and bypass-related variables) too */ struct { char *var; char *cmd; } mandatory[] = { { "input.L1-N.voltage", "Q6" }, { "ups.type", "Q1" }, { "output.L1.current", "WA"}, { NULL, NULL } }; int vari; char *sp, *cmd; item_t *item; for (vari = 0; mandatory[vari].var; vari++) { sp = mandatory[vari].var; cmd = mandatory[vari].cmd; /* Ignore checks for 'WA' command support if explicitly asked */ if (testvar("nooutstats") && (strcasecmp(cmd, "WA") == 0)) continue; item = find_nut_info(sp, 0, 0); /* Don't know what happened */ if (!item) return 0; /* No reply/Unable to get value */ if (qx_process(item, NULL)) return 0; /* Unable to process value */ if (ups_infoval_set(item) != 1) return 0; } return 1; } /* Subdriver-specific initups */ static void q6_initups(void) { int nr, nos, isb; item_t *item; nr = testvar("norating"); nos = testvar("nooutstats"); isb = testvar("ignoresab"); if (!nr && !nos && !isb) return; for (item = q6_qx2nut; item->info_type != NULL; item++) { if (!item->command) continue; /* norating */ if (nr && (strcasecmp(item->command, "F\r") == 0)) { upsdebugx(2, "%s: skipping %s", __func__, item->info_type); item->qxflags |= QX_FLAG_SKIP; } /* nooutstats */ if (nos && (strcasecmp(item->command, "WA\r") == 0)) { upsdebugx(2, "%s: skipping %s", __func__, item->info_type); item->qxflags |= QX_FLAG_SKIP; } /* ignoresab */ if (isb && (strcasecmp(item->info_type, "ups.status") == 0) && item->from == 44 && item->to == 44) { upsdebugx(2, "%s: skipping %s ('Shutdown Active' bit)", __func__, item->info_type); item->qxflags |= QX_FLAG_SKIP; } } } /* Subdriver-specific initinfo */ static void q6_initinfo(void) { dstate_setinfo("input.phases", "%d", 3); dstate_setinfo("output.phases", "%d", 3); } /* Subdriver-specific flags/vars */ static void q6_makevartable(void) { addvar(VAR_FLAG, "norating", "Skip reading rating information from UPS"); addvar(VAR_FLAG, "nooutstats", "Skip reading output load stats information from UPS"); blazer_makevartable_light(); } /* Subdriver interface */ subdriver_t q6_subdriver = { Q6_VERSION, q6_claim, q6_qx2nut, q6_initups, q6_initinfo, q6_makevartable, "ACK", NULL, #ifdef TESTING q6_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/delta_ups-hid.h0000644000175000017500000000227014670526611013636 00000000000000/* delta_ups-hid.h - data mapping subdriver to monitor Delta UPS USB/HID devices with NUT * * Copyright (C) * 2003 - 2009 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * 2021 Jungeon Kim * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DELTA_UPS_HID_H #define DELTA_UPS_HID_H #include "usbhid-ups.h" extern subdriver_t delta_ups_subdriver; #endif /* DELTA_UPS_HID_H */ nut-2.8.4/drivers/compaq-mib.h0000644000175000017500000000021514670526611013136 00000000000000#ifndef COMPAQ_MIB_H #define COMPAQ_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t compaq; #endif /* COMPAQ_MIB_H */ nut-2.8.4/drivers/riello_usb.c0000644000175000017500000011657015044656702013260 00000000000000/* * riello_usb.c: support for Riello USB protocol based UPSes * * A document describing the protocol implemented by this driver can be * found online at: * * https://www.networkupstools.org/protocols/riello/PSGPSER-0104.pdf * * Copyright (C) 2012 - Elio Parisi * Copyright (C) 2016 Eaton * Copyright (C) 2022-2024 "amikot" * Copyright (C) 2022-2024 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Reference of the derivative work: blazer driver */ #include "config.h" /* must be the first header */ #include "main.h" #include "nut_libusb.h" #include "usb-common.h" #include "riello.h" #define DRIVER_NAME "Riello USB driver" #define DRIVER_VERSION "0.15" #define DEFAULT_OFFDELAY 5 /*!< seconds (max 0xFF) */ #define DEFAULT_BOOTDELAY 5 /*!< seconds (max 0xFF) */ /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Elio Parisi ", DRV_EXPERIMENTAL, { NULL } }; static uint8_t bufOut[BUFFER_SIZE]; static uint8_t bufIn[BUFFER_SIZE]; static uint8_t gpser_error_control; static uint8_t input_monophase; static uint8_t output_monophase; /*! Time in seconds to delay before shutting down. */ static unsigned int offdelay = DEFAULT_OFFDELAY; static unsigned int bootdelay = DEFAULT_BOOTDELAY; static TRielloData DevData; static usb_communication_subdriver_t *usb = &usb_subdriver; static usb_dev_handle *udev = NULL; static USBDevice_t usbdevice; static USBDeviceMatcher_t *reopen_matcher = NULL; static USBDeviceMatcher_t *regex_matcher = NULL; /* Flag for estimation of battery.runtime and battery.charge */ static int localcalculation = 0; static int localcalculation_logged = 0; /* NOTE: Do not change these default, they refer to battery.voltage.nominal=12.0 * and used in related maths later */ static double batt_volt_nom = 12.0; static double batt_volt_low = 10.4; static double batt_volt_high = 13.0; static int (*subdriver_command)(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t buflen) = NULL; static void ussleep(useconds_t usec) { if (usec == 1) usec = 400; else usec *= 1000; usleep(usec); } static int cypress_setfeatures(void) { int ret; bufOut[0] = 0xB0; bufOut[1] = 0x4; bufOut[2] = 0x0; bufOut[3] = 0x0; bufOut[4] = 0x3; /* Write features report */ ret = usb_control_msg(udev, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, 0x09, /* HID_REPORT_SET = 0x09 */ 0 + (0x03 << 8), /* HID_REPORT_TYPE_FEATURE */ 0, (usb_ctrl_charbuf) bufOut, 0x5, 1000); if (ret <= 0) { upsdebugx(3, "send: %s", ret ? nut_usb_strerror(ret) : "error"); return ret; } upsdebugx(3, "send: features report ok"); return ret; } static int Send_USB_Packet(uint8_t *send_str, uint16_t numbytes) { uint8_t USB_buff_pom[10]; int i, err, size; /*int errno;*/ /* is input correct ? */ if ((!send_str) || (!numbytes)) return -1; size = 7; /* routine which parse report into 4-bytes packet */ for (i=0; i<(numbytes/size); i++) { USB_buff_pom[0] = 0x37; USB_buff_pom[1] = send_str[(i*7)]; USB_buff_pom[2] = send_str[(i*7)+1]; USB_buff_pom[3] = send_str[(i*7)+2]; USB_buff_pom[4] = send_str[(i*7)+3]; USB_buff_pom[5] = send_str[(i*7)+4]; USB_buff_pom[6] = send_str[(i*7)+5]; USB_buff_pom[7] = send_str[(i*7)+6]; err = usb_bulk_write(udev, 0x2, (usb_ctrl_charbuf) USB_buff_pom, 8, 1000); if (err < 0) { upsdebug_with_errno(3, "USB: Send_USB_Packet: send_usb_packet, err = %d %s ", err, nut_usb_strerror(err)); return err; } ussleep(USB_WRITE_DELAY); } /* send rest of packet */ if (numbytes % size) { i = numbytes/size; memset(USB_buff_pom, '0', sizeof(USB_buff_pom)); USB_buff_pom[0] = 0x30+(numbytes%7); if ((i*7) 0) upsdebugx(3, "read: %02X %02X %02X %02X %02X %02X %02X %02X", inBuf[0], inBuf[1], inBuf[2], inBuf[3], inBuf[4], inBuf[5], inBuf[6], inBuf[7]); if (err < 0){ upsdebug_with_errno(3, "USB: Get_USB_Packet: send_usb_packet, err = %d %s ", err, nut_usb_strerror(err)); return err; } /* copy to buffer */ size = (unsigned char)(inBuf[0]) & 0x07; if (size) memcpy(buffer, &inBuf[1], size); if (size > INT_MAX) return -1; return (int)size; } static int cypress_command(uint8_t *buffer, uint8_t *buf, uint16_t length, uint16_t buflen) { int loop = 0; int ret, i = 0; uint8_t USB_buff[BUFFER_SIZE]; /* read to flush buffer */ riello_init_serial(); /* send packet */ ret = Send_USB_Packet(buffer, length); if (ret < 0) { upsdebugx(3, "Cypress_command send: err %d", ret ); return ret; } upsdebugx(3, "send ok"); memset(buf, 0, buflen); while ((buf_ptr_length < BUFFER_SIZE) && wait_packet) { memset(USB_buff, 0, sizeof(USB_buff)); ret = Get_USB_Packet(USB_buff); /* * Any errors here mean that we are unable to read a reply (which * will happen after successfully writing a command to the UPS) */ if (ret < 0) { upsdebugx(3, "Cypress_command read: err %d", ret ); return ret; } for (i = 0; i < ret; i++ ) { commbyte = USB_buff[i]; riello_parse_serialport(DEV_RIELLOGPSER, buf, gpser_error_control); } loop++; if (loop>300){ wait_packet=0; upsdebugx(1, "wait_packet reset"); } ussleep(10); } upsdebugx(3, "in read: %u", buf_ptr_length); return buf_ptr_length; } static void *cypress_subdriver(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); subdriver_command = &cypress_command; return NULL; } /* Riello (Cypress Semiconductor Corp.) */ #define RIELLO_VENDORID 0x04b4 static usb_device_id_t riello_usb_id[] = { /* various models */ { USB_DEVICE(RIELLO_VENDORID, 0x5500), &cypress_subdriver }, /* Terminating entry */ { 0, 0, NULL } }; static int device_match_func(USBDevice_t *hd, void *privdata) { NUT_UNUSED_VARIABLE(privdata); if (subdriver_command) { return 1; } switch (is_usb_device_supported(riello_usb_id, hd)) { case SUPPORTED: return 1; case POSSIBLY_SUPPORTED: case NOT_SUPPORTED: default: return 0; } } static USBDeviceMatcher_t device_matcher = { &device_match_func, NULL, NULL }; /* * Callback that is called by usb_device_open() that handles USB device * settings prior to accepting the devide. At the very least claim the * device here. Detaching the kernel driver will be handled by the * caller, don't do this here. Return < 0 on error, 0 or higher on * success. */ static int driver_callback(usb_dev_handle *handle, USBDevice_t *device, usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen) { int ret = 0; NUT_UNUSED_VARIABLE(device); NUT_UNUSED_VARIABLE(rdbuf); NUT_UNUSED_VARIABLE(rdlen); /* if ((ret = usb_set_configuration(handle, 1)) < 0) { upslogx(LOG_WARNING, "Can't set USB configuration: %s", nut_usb_strerror(ret)); return -1; } */ if ((ret = usb_claim_interface(handle, 0)) < 0) { upslogx(LOG_WARNING, "Can't claim USB interface: %s", nut_usb_strerror(ret)); return -1; } /* TODO: HID SET_IDLE to 0 (not necessary?) */ return 1; } /* * Generic command processing function. Send a command and read a reply. * Returns < 0 on error, 0 on timeout and the number of bytes read on * success. */ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t buflen) { int ret; if (udev == NULL) { dstate_setinfo("driver.state", "reconnect.trying"); ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, &driver_callback); upsdebugx (3, "riello_command err udev NULL : %d ", ret); if (ret < 0) return ret; dstate_setinfo("driver.state", "reconnect.updateinfo"); upsdrv_initinfo(); /* reconnect usb cable */ dstate_setinfo("driver.state", "quiet"); } ret = (*subdriver_command)(cmd, buf, length, buflen); if (ret >= 0) { upsdebugx (3, "riello_command ok: %d", ret); return ret; } upsdebugx (3, "riello_command err: %d", ret); switch (ret) { case LIBUSB_ERROR_BUSY: /* Device or resource busy */ fatal_with_errno(EXIT_FAILURE, "Got disconnected by another driver"); #ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ #endif #if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */ case -EPERM: /* Operation not permitted */ fatal_with_errno(EXIT_FAILURE, "Permissions problem"); # ifndef HAVE___ATTRIBUTE__NORETURN exit(EXIT_FAILURE); /* Should not get here in practice, but compiler is afraid we can fall through */ # endif #endif case LIBUSB_ERROR_PIPE: /* Broken pipe */ if (usb_clear_halt(udev, 0x81) == 0) { upsdebugx(1, "Stall condition cleared"); break; } #if (defined ETIME) && ETIME && WITH_LIBUSB_0_1 goto fallthrough_case_etime; case -ETIME: /* Timer expired */ fallthrough_case_etime: #endif if (usb_reset(udev) == 0) { upsdebugx(1, "Device reset handled"); } goto fallthrough_case_reconnect; case LIBUSB_ERROR_NO_DEVICE: /* No such device */ case LIBUSB_ERROR_ACCESS: /* Permission denied */ case LIBUSB_ERROR_IO: /* I/O error */ #if WITH_LIBUSB_0_1 /* limit to libusb 0.1 implementation */ case -ENXIO: /* No such device or address */ #endif case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */ fallthrough_case_reconnect: /* Uh oh, got to reconnect! */ dstate_setinfo("driver.state", "reconnect.trying"); usb->close_dev(udev); udev = NULL; break; case LIBUSB_ERROR_TIMEOUT: /* Connection timed out */ upsdebugx (3, "riello_command err: Resource temporarily unavailable"); break; #ifndef WIN32 /* libusb win32 does not know EPROTO and EOVERFLOW, * it only returns EIO for any IO errors */ case LIBUSB_ERROR_OVERFLOW: /* Value too large for defined data type */ # if EPROTO && WITH_LIBUSB_0_1 case -EPROTO: /* Protocol error */ # endif break; #endif /* !WIN32 */ default: break; } return ret; } static int get_ups_nominal(void) { uint8_t length; int recv; length = riello_prepare_gn(&bufOut[0], gpser_error_control); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_GN); if (recv < 0){ upsdebugx (3, "Get nominal err: read byte: %d", recv); return recv; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get nominal Ko: bad CRC or Checksum"); return -1; } /* mandatory */ if (!wait_packet && foundnak) { upsdebugx (3, "Get nominal Ko: command not supported"); return -1; } upsdebugx (3, "Get nominal Ok: read byte: %d", recv); riello_parse_gn(&bufIn[0], &DevData); return 0; } static int get_ups_status(void) { uint8_t numread, length; int recv; length = riello_prepare_rs(&bufOut[0], gpser_error_control); if (input_monophase) numread = LENGTH_RS_MM; else if (output_monophase) numread = LENGTH_RS_TM; else numread = LENGTH_RS_TT; recv = riello_command(&bufOut[0], &bufIn[0], length, numread); if (recv < 0){ upsdebugx (3, "Get status err: read byte: %d", recv); return recv; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get status Ko: bad CRC or Checksum"); return -1; } /* mandatory */ if (!wait_packet && foundnak) { upsdebugx (3, "Get status Ko: command not supported"); return -1; } upsdebugx (3, "Get status Ok: read byte: %d", recv); riello_parse_rs(&bufIn[0], &DevData, numread); return 0; } static int get_ups_extended(void) { uint8_t length; int recv; length = riello_prepare_re(&bufOut[0], gpser_error_control); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_RE); if (recv < 0){ upsdebugx (3, "Get extended err: read byte: %d", recv); return recv; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get extended Ko: bad CRC or Checksum"); return -1; } /* optional */ if (!wait_packet && foundnak) { upsdebugx (3, "Get extended Ko: command not supported"); return 0; } upsdebugx (3, "Get extended Ok: read byte: %d", recv); riello_parse_re(&bufIn[0], &DevData); return 0; } /* Not static, exposed via header. Not used though, currently... */ int get_ups_statuscode(void) { uint8_t length; int recv; length = riello_prepare_rc(&bufOut[0], gpser_error_control); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_RC); if (recv < 0){ upsdebugx (3, "Get statuscode err: read byte: %d", recv); return recv; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get statuscode Ko: bad CRC or Checksum"); return -1; } /* optional */ if (!wait_packet && foundnak) { upsdebugx (3, "Get statuscode Ko: command not supported"); return 0; } upsdebugx (3, "Get statuscode Ok: read byte: %d", recv); riello_parse_rc(&bufIn[0], &DevData); return 0; } static int riello_instcmd(const char *cmdname, const char *extra) { uint8_t length; int recv; uint16_t delay; const char *delay_char; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!riello_test_bit(&DevData.StatusCode[0], 1)) { if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); delay = 0; length = riello_prepare_cs(bufOut, gpser_error_control, delay); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command load.off err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.off Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.off Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.off Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.off.delay")) { int ipv; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); delay_char = dstate_getinfo("ups.delay.shutdown"); ipv = atoi(delay_char); /* With a "char" in the name, might assume we fit... but :) */ if (ipv < 0 || (intmax_t)ipv > (intmax_t)UINT16_MAX) return STAT_INSTCMD_FAILED; delay = (uint16_t)ipv; length = riello_prepare_cs(bufOut, gpser_error_control, delay); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command load.off.delay err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.off.delay Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.off.delay Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.off.delay Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); delay = 0; length = riello_prepare_cr(bufOut, gpser_error_control, delay); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command load.on err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.on Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.on Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.on Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.on.delay")) { int ipv; upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); delay_char = dstate_getinfo("ups.delay.reboot"); ipv = atoi(delay_char); /* With a "char" in the name, might assume we fit... but :) */ if (ipv < 0 || (intmax_t)ipv > (intmax_t)UINT16_MAX) return STAT_INSTCMD_FAILED; delay = (uint16_t)ipv; length = riello_prepare_cr(bufOut, gpser_error_control, delay); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command load.on.delay err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.on.delay Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.on.delay Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.on.delay Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } } else { if (!strcasecmp(cmdname, "shutdown.return")) { int ipv; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); delay_char = dstate_getinfo("ups.delay.shutdown"); ipv = atoi(delay_char); /* With a "char" in the name, might assume we fit... but :) */ if (ipv < 0 || (intmax_t)ipv > (intmax_t)UINT16_MAX) return STAT_INSTCMD_FAILED; delay = (uint16_t)ipv; length = riello_prepare_cs(bufOut, gpser_error_control, delay); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command shutdown.return err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command shutdown.return Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command shutdown.return Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command shutdown.return Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } } if (!strcasecmp(cmdname, "shutdown.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); length = riello_prepare_cd(bufOut, gpser_error_control); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command shutdown.stop err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command shutdown.stop Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command shutdown.stop Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command shutdown.stop Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.panel.start")) { length = riello_prepare_tp(bufOut, gpser_error_control); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command test.panel.start err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command test.panel.start Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command test.panel.start Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command test.panel.start Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); length = riello_prepare_tb(bufOut, gpser_error_control); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_DEF); if (recv < 0) { upsdebugx (3, "Command test.battery.start err: read byte: %d", recv); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command test.battery.start Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command test.battery.start Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command test.battery.start Ok: read byte: %d", recv); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } static int start_ups_comm(void) { uint16_t length; int recv; upsdebugx (2, "entering start_ups_comm()\n"); cypress_setfeatures(); length = riello_prepare_gi(&bufOut[0]); recv = riello_command(&bufOut[0], &bufIn[0], length, LENGTH_GI); if (recv < 0) { upsdebugx (3, "Get identif err: read byte: %d", recv); return recv; } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get identif Ko: bad CRC or Checksum"); return 1; } if (!wait_packet && foundnak) { upsdebugx (3, "Get identif Ko: command not supported"); return 1; } upsdebugx (3, "Get identif Ok: read byte: %d", recv); return 0; } void upsdrv_help(void) { } void upsdrv_makevartable(void) { /* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */ nut_usb_addvars(); addvar(VAR_FLAG, "localcalculation", "Calculate battery charge and runtime locally"); } void upsdrv_initups(void) { const struct { const char *name; int (*command)(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t buflen); } subdriver[] = { { "cypress", &cypress_command }, { NULL, NULL } }; int ret; char *regex_array[USBMATCHER_REGEXP_ARRAY_LIMIT]; char *subdrv = getval("subdriver"); warn_if_bad_usb_port_filename(device_path); regex_array[0] = getval("vendorid"); regex_array[1] = getval("productid"); regex_array[2] = getval("vendor"); regex_array[3] = getval("product"); regex_array[4] = getval("serial"); regex_array[5] = getval("bus"); regex_array[6] = getval("device"); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) regex_array[7] = getval("busport"); #else if (getval("busport")) { upslogx(LOG_WARNING, "\"busport\" is configured for the device, but is not actually handled by current build combination of NUT and libusb (ignored)"); } #endif /* pick up the subdriver name if set explicitly */ if (subdrv) { int i; if (!regex_array[0] || !regex_array[1]) { fatalx(EXIT_FAILURE, "When specifying a subdriver, 'vendorid' and 'productid' are mandatory."); } for (i = 0; subdriver[i].name; i++) { if (strcasecmp(subdrv, subdriver[i].name)) { continue; } subdriver_command = subdriver[i].command; break; } if (!subdriver_command) { fatalx(EXIT_FAILURE, "Subdriver \"%s\" not found!", subdrv); } } ret = USBNewRegexMatcher(®ex_matcher, regex_array, REG_ICASE | REG_EXTENDED); switch (ret) { case -1: fatal_with_errno(EXIT_FAILURE, "USBNewRegexMatcher"); case 0: break; /* all is well */ default: fatalx(EXIT_FAILURE, "invalid regular expression: %s", regex_array[ret]); } /* link the matchers */ regex_matcher->next = &device_matcher; ret = usb->open_dev(&udev, &usbdevice, regex_matcher, &driver_callback); if (ret < 0) { fatalx(EXIT_FAILURE, "No supported devices found. Please check your device availability with 'lsusb'\n" "and make sure you have an up-to-date version of NUT. If this does not help,\n" "try running the driver with at least 'subdriver', 'vendorid' and 'productid'\n" "options specified. Please refer to the man page for details about these options\n" "(man 8 riello_usb).\n"); } if (!subdriver_command) { fatalx(EXIT_FAILURE, "No subdriver selected"); } /* create a new matcher for later reopening */ ret = USBNewExactMatcher(&reopen_matcher, &usbdevice); if (ret) { fatal_with_errno(EXIT_FAILURE, "USBNewExactMatcher"); } /* link the matchers */ reopen_matcher->next = regex_matcher; dstate_setinfo("ups.vendorid", "%04x", usbdevice.VendorID); dstate_setinfo("ups.productid", "%04x", usbdevice.ProductID); } void upsdrv_initinfo(void) { int ret; const char *valN = NULL, *valL = NULL, *valH = NULL; ret = start_ups_comm(); if (ret < 0) fatalx(EXIT_FAILURE, "No communication with UPS"); else if (ret > 0) fatalx(EXIT_FAILURE, "Bad checksum or NACK"); else upsdebugx(2, "Communication with UPS established"); if (testvar("localcalculation")) { localcalculation = 1; upsdebugx(1, "Will guesstimate battery charge and runtime " "instead of trusting device readings (if any); " "consider also setting default.battery.voltage.low " "and default.battery.voltage.high for this device"); } dstate_setinfo("driver.parameter.localcalculation", "%d", localcalculation); riello_parse_gi(&bufIn[0], &DevData); gpser_error_control = DevData.Identif_bytes[4]-0x30; if ((DevData.Identif_bytes[0] == '1') || (DevData.Identif_bytes[0] == '2')) input_monophase = 1; else { input_monophase = 0; dstate_setinfo("input.phases", "%d", 3); dstate_setinfo("input.phases", "%d", 3); dstate_setinfo("input.bypass.phases", "%d", 3); } if ((DevData.Identif_bytes[0] == '1') || (DevData.Identif_bytes[0] == '3')) output_monophase = 1; else { output_monophase = 0; dstate_setinfo("output.phases", "%d", 3); } dstate_setinfo("device.mfr", "RPS S.p.a."); dstate_setinfo("device.model", "%s", (unsigned char*) DevData.ModelStr); dstate_setinfo("device.serial", "%s", (unsigned char*) DevData.Identification); dstate_setinfo("device.type", "ups"); dstate_setinfo("ups.mfr", "RPS S.p.a."); dstate_setinfo("ups.model", "%s", (unsigned char*) DevData.ModelStr); dstate_setinfo("ups.serial", "%s", (unsigned char*) DevData.Identification); dstate_setinfo("ups.firmware", "%s", (unsigned char*) DevData.Version); /* Is it set by user default/override configuration? * NOTE: "valN" is also used for a check just below. */ valN = dstate_getinfo("battery.voltage.nominal"); if (valN) { batt_volt_nom = strtod(valN, NULL); upsdebugx(1, "Using battery.voltage.nominal=%.1f " "likely coming from user configuration", batt_volt_nom); } if (get_ups_nominal() == 0) { dstate_setinfo("ups.realpower.nominal", "%u", DevData.NomPowerKW); dstate_setinfo("ups.power.nominal", "%u", DevData.NomPowerKVA); dstate_setinfo("output.voltage.nominal", "%u", DevData.NominalUout); dstate_setinfo("output.frequency.nominal", "%.1f", DevData.NomFout/10.0); /* Is it set by user default/override configuration (see just above)? */ if (valN) { upsdebugx(1, "...instead of battery.voltage.nominal=%u " "reported by the device", DevData.NomUbat); } else { dstate_setinfo("battery.voltage.nominal", "%u", DevData.NomUbat); batt_volt_nom = (double)DevData.NomUbat; } dstate_setinfo("battery.capacity", "%u", DevData.NomBatCap); } else { /* TOTHINK: Check the momentary reading of battery.voltage * or would it be too confusing (especially if it is above * 12V and might correspond to a discharged UPS when the * driver starts up after an outage?) * NOTE: DevData.Ubat would be scaled by 10! */ if (!valN) { /* The nominal was not already set by user configuration... */ upsdebugx(1, "Using built-in default battery.voltage.nominal=%.1f", batt_volt_nom); dstate_setinfo("battery.voltage.nominal", "%.1f", batt_volt_nom); } } /* We have a nominal voltage by now - either from user configuration * or from the device itself (or initial defaults for 12V). Do we have * any low/high range from HW/FW or defaults from ups.conf? */ valL = dstate_getinfo("battery.voltage.low"); valH = dstate_getinfo("battery.voltage.high"); { /* scoping */ /* Pick a suitable low/high range (or keep built-in default). * The factor may be a count of battery packs in the UPS. */ int times12 = batt_volt_nom / 12; if (times12 > 1) { /* Scale up the range for 24V (X=2) etc. */ upsdebugx(3, "%s: Using %i times the voltage range of 12V PbAc battery", __func__, times12); batt_volt_low *= times12; batt_volt_high *= times12; } } if (!valL && !valH) { /* Both not set (NULL) => pick by nominal (X times 12V above). */ upsdebugx(3, "Neither battery.voltage.low=%.1f " "nor battery.voltage.high=%.1f is set via " "driver configuration or by device; keeping " "at built-in default value (aligned " "with battery.voltage.nominal=%.1f)", batt_volt_low, batt_volt_high, batt_volt_nom); } else { if (valL) { batt_volt_low = strtod(valL, NULL); upsdebugx(2, "%s: Using battery.voltage.low=%.1f from device or settings", __func__, batt_volt_low); } if (valH) { batt_volt_high = strtod(valH, NULL); upsdebugx(2, "%s: Using battery.voltage.high=%.1f from device or settings", __func__, batt_volt_high); } /* If just one of those is set, then what? */ if (valL || valH) { upsdebugx(1, "WARNING: Only one of battery.voltage.low=%.1f " "or battery.voltage.high=%.1f is set via " "driver configuration; keeping the other " "at built-in default value (aligned " "with battery.voltage.nominal=%.1f)", batt_volt_low, batt_volt_high, batt_volt_nom); } else { upsdebugx(1, "Both of battery.voltage.low=%.1f " "or battery.voltage.high=%.1f are set via " "driver configuration; not aligning " "with battery.voltage.nominal=%.1f", batt_volt_low, batt_volt_high, batt_volt_nom); } } /* Whatever the origin, make the values known via dstate */ dstate_setinfo("battery.voltage.low", "%.1f", batt_volt_low); dstate_setinfo("battery.voltage.high", "%.1f", batt_volt_high); /* commands ----------------------------------------------- */ dstate_addcmd("load.off"); dstate_addcmd("load.on"); dstate_addcmd("load.off.delay"); dstate_addcmd("load.on.delay"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stop"); dstate_addcmd("test.battery.start"); dstate_addcmd("test.panel.start"); dstate_setinfo("ups.delay.shutdown", "%u", offdelay); dstate_setflags("ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.shutdown", 3); dstate_setinfo("ups.delay.reboot", "%u", bootdelay); dstate_setflags("ups.delay.reboot", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.reboot", 3); /* install handlers */ /* upsh.setvar = hid_set_value; setvar; */ /* note: for a transition period, these data are redundant! */ /* dstate_setinfo("device.mfr", "skel manufacturer"); */ /* dstate_setinfo("device.model", "longrun 15000"); */ upsh.instcmd = riello_instcmd; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ int retry; /* maybe try to detect the UPS here, but try a shutdown even if it doesn't respond at first if possible */ /* replace with a proper shutdown function */ /* you may have to check the line status since the commands for toggling power are frequently different for OL vs. OB */ /* OL: this must power cycle the load if possible */ /* OB: the load must remain off until the power returns */ for (retry = 1; retry <= MAXTRIES; retry++) { /* By default, abort a previously requested shutdown * (if any) and schedule a new one from this moment. */ if (riello_instcmd("shutdown.stop", NULL) != STAT_INSTCMD_HANDLED) { continue; } if (riello_instcmd("shutdown.return", NULL) != STAT_INSTCMD_HANDLED) { continue; } upslogx(LOG_ERR, "Shutting down"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); return; } upslogx(LOG_ERR, "Shutdown failed!"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_updateinfo(void) { uint8_t getextendedOK; static int countlost = 0; int stat; int battcharge; float battruntime; float upsloadfactor; #ifdef RIELLO_DYNAMIC_BATTVOLT_INFO const char *val = NULL; #endif upsdebugx(1, "countlost %d",countlost); if (countlost > 0){ upsdebugx(1, "Communication with UPS is lost: status read failed!"); if (countlost == COUNTLOST) { dstate_datastale(); upslogx(LOG_WARNING, "Communication with UPS is lost: status read failed!"); } } stat = get_ups_status(); upsdebugx(1, "get_ups_status() %d",stat ); if (stat < 0) { if (countlost < COUNTLOST) countlost++; return; } if (get_ups_extended() == 0) getextendedOK = 1; else getextendedOK = 0; if (countlost == COUNTLOST) upslogx(LOG_NOTICE, "Communication with UPS is re-established!"); dstate_setinfo("input.frequency", "%.2f", DevData.Finp/10.0); dstate_setinfo("input.bypass.frequency", "%.2f", DevData.Fbypass/10.0); dstate_setinfo("output.frequency", "%.2f", DevData.Fout/10.0); dstate_setinfo("battery.voltage", "%.1f", DevData.Ubat/10.0); #ifdef RIELLO_DYNAMIC_BATTVOLT_INFO /* Can be set via default.* or override.* driver options * if not served by the device HW/FW */ val = dstate_getinfo("battery.voltage.low"); if (val) { batt_volt_low = strtod(val, NULL); } val = dstate_getinfo("battery.voltage.high"); if (val) { batt_volt_high = strtod(val, NULL); } #endif if (localcalculation) { /* NOTE: at this time "localcalculation" is a configuration toggle. * Maybe later it can be replaced by a common "runtimecal" setting. */ /* Considered "Ubat" physical range here (e.g. 10.7V to 12.9V) is * seen as "107" or "129" integers in the DevData properties: */ uint16_t Ubat_low = batt_volt_low * 10; /* e.g. 107 */ uint16_t Ubat_high = batt_volt_high * 10; /* e.g. 129 */ static int batt_volt_logged = 0; if (!batt_volt_logged) { upsdebugx(0, "\nUsing battery.voltage.low=%.1f and " "battery.voltage.high=%.1f for \"localcalculation\" " "guesstimates of battery.charge and battery.runtime", batt_volt_low, batt_volt_high); batt_volt_logged = 1; } battcharge = ((DevData.Ubat <= Ubat_high) && (DevData.Ubat >= Ubat_low)) ? (((DevData.Ubat - Ubat_low)*100) / (Ubat_high - Ubat_low)) : ((DevData.Ubat < Ubat_low) ? 0 : 100); battruntime = (DevData.NomBatCap * DevData.NomUbat * 3600.0/DevData.NomPowerKW) * (battcharge/100.0); upsloadfactor = (DevData.Pout1 > 0) ? (DevData.Pout1/100.0) : 1; dstate_setinfo("battery.charge", "%d", battcharge); dstate_setinfo("battery.runtime", "%.0f", battruntime/upsloadfactor); } else { if (!localcalculation_logged) { upsdebugx(0, "\nIf you don't see values for battery.charge and " "battery.runtime or values are incorrect," "try setting \"localcalculation\" flag in \"ups.conf\" " "options section for this driver!\n"); localcalculation_logged = 1; } if ((DevData.BatCap < 0xFFFF) && (DevData.BatTime < 0xFFFF)) { /* Use values reported by the driver unless they are marked * invalid/unknown by HW/FW (all bits in the word are set). */ dstate_setinfo("battery.charge", "%u", DevData.BatCap); dstate_setinfo("battery.runtime", "%u", (unsigned int)DevData.BatTime*60); } } if (DevData.Tsystem == 255) { /* Use values reported by the driver unless they are marked * invalid/unknown by HW/FW (all bits in the word are set). */ /*dstate_setinfo("ups.temperature", "%u", 0);*/ upsdebugx(4, "Reported temperature value is 0xFF, " "probably meaning \"-1\" for error or " "missing sensor - ignored"); } else if (DevData.Tsystem < 0xFF) { dstate_setinfo("ups.temperature", "%u", DevData.Tsystem); } if (input_monophase) { dstate_setinfo("input.voltage", "%u", DevData.Uinp1); dstate_setinfo("input.bypass.voltage", "%u", DevData.Ubypass1); } else { dstate_setinfo("input.L1-N.voltage", "%u", DevData.Uinp1); dstate_setinfo("input.L2-N.voltage", "%u", DevData.Uinp2); dstate_setinfo("input.L3-N.voltage", "%u", DevData.Uinp3); dstate_setinfo("input.bypass.L1-N.voltage", "%u", DevData.Ubypass1); dstate_setinfo("input.bypass.L2-N.voltage", "%u", DevData.Ubypass2); dstate_setinfo("input.bypass.L3-N.voltage", "%u", DevData.Ubypass3); } if (output_monophase) { dstate_setinfo("output.voltage", "%u", DevData.Uout1); dstate_setinfo("output.power.percent", "%u", DevData.Pout1); dstate_setinfo("ups.load", "%u", DevData.Pout1); } else { dstate_setinfo("output.L1-N.voltage", "%u", DevData.Uout1); dstate_setinfo("output.L2-N.voltage", "%u", DevData.Uout2); dstate_setinfo("output.L3-N.voltage", "%u", DevData.Uout3); dstate_setinfo("output.L1.power.percent", "%u", DevData.Pout1); dstate_setinfo("output.L2.power.percent", "%u", DevData.Pout2); dstate_setinfo("output.L3.power.percent", "%u", DevData.Pout3); dstate_setinfo("ups.load", "%u", (unsigned int)(DevData.Pout1+DevData.Pout2+DevData.Pout3)/3); } status_init(); /* AC Fail */ if (riello_test_bit(&DevData.StatusCode[0], 1)) status_set("OB"); else status_set("OL"); /* LowBatt */ if ((riello_test_bit(&DevData.StatusCode[0], 1)) && (riello_test_bit(&DevData.StatusCode[0], 0))) status_set("LB"); /* Standby */ if (!riello_test_bit(&DevData.StatusCode[0], 3)) status_set("OFF"); /* On Bypass */ if (riello_test_bit(&DevData.StatusCode[1], 3)) status_set("BYPASS"); /* Overload */ if (riello_test_bit(&DevData.StatusCode[4], 2)) status_set("OVER"); /* Buck */ if (riello_test_bit(&DevData.StatusCode[1], 0)) status_set("TRIM"); /* Boost */ if (riello_test_bit(&DevData.StatusCode[1], 1)) status_set("BOOST"); /* Replace battery */ if (riello_test_bit(&DevData.StatusCode[2], 0)) status_set("RB"); /* Charging battery */ if (riello_test_bit(&DevData.StatusCode[2], 2)) status_set("CHRG"); status_commit(); dstate_dataok(); if (getextendedOK) { dstate_setinfo("output.L1.power", "%u", DevData.Pout1VA); dstate_setinfo("output.L2.power", "%u", DevData.Pout2VA); dstate_setinfo("output.L3.power", "%u", DevData.Pout3VA); dstate_setinfo("output.L1.realpower", "%u", DevData.Pout1W); dstate_setinfo("output.L2.realpower", "%u", DevData.Pout2W); dstate_setinfo("output.L3.realpower", "%u", DevData.Pout3W); dstate_setinfo("output.L1.current", "%u", DevData.Iout1); dstate_setinfo("output.L2.current", "%u", DevData.Iout2); dstate_setinfo("output.L3.current", "%u", DevData.Iout3); } poll_interval = 2; countlost = 0; /* if (get_ups_statuscode() != 0) upsdebugx(2, "Communication is lost"); else { }*/ /* * ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS); * * if (ret < STATUS_LEN) { * upslogx(LOG_ERR, "Short read from UPS"); * dstate_datastale(); * return; * } */ /* dstate_setinfo("var.name", ""); */ /* if (ioctl(upsfd, TIOCMGET, &flags)) { * upslog_with_errno(LOG_ERR, "TIOCMGET"); * dstate_datastale(); * return; * } */ /* status_init(); * * if (ol) * status_set("OL"); * else * status_set("OB"); * ... * * status_commit(); * * dstate_dataok(); */ /* * poll_interval = 2; */ } void upsdrv_cleanup(void) { usb->close_dev(udev); USBFreeExactMatcher(reopen_matcher); USBFreeRegexMatcher(regex_matcher); free(usbdevice.Vendor); free(usbdevice.Product); free(usbdevice.Serial); free(usbdevice.Bus); free(usbdevice.Device); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) free(usbdevice.BusPort); #endif } nut-2.8.4/drivers/huawei-mib.h0000644000175000017500000000021514670526611013140 00000000000000#ifndef HUAWEI_MIB_H #define HUAWEI_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t huawei; #endif /* HUAWEI_MIB_H */ nut-2.8.4/drivers/gamatronic.c0000644000175000017500000002765115044656702013246 00000000000000/* gamatronic.c * * SEC UPS Driver ported to the new NUT API for Gamatronic UPS Usage. * * TODO: Replace lots of printf() by upslogx() or upsdebugx() below! * * Copyright (C) * 2001 John Marley * 2002 Jules Taplin * 2002 Eric Lawson * 2005 Arnaud Quette * 2005 Nadav Moskovitch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "serial.h" #include "gamatronic.h" #include "nut_stdint.h" #define DRIVER_NAME "Gamatronic UPS driver" #define DRIVER_VERSION "0.08" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "John Marley \n" \ "Jules Taplin \n" \ "Eric Lawson \n" \ "Arnaud Quette \n" \ "Nadav Moskovitch ", DRV_STABLE, { NULL } }; #define ENDCHAR '\r' #define IGNCHARS "" #define SER_WAIT_SEC 1 /* allow 3.0 sec for ser_get calls */ #define SER_WAIT_USEC 0 /* Reasons for this number are lost in history; protocol docs at * https://networkupstools.org/protocols/sec-protocol.html and * https://networkupstools.org/protocols/us9003.html specify 128 * bytes as the max data length in a message; +5 chars for meta * data and +1 for `\0` termination yields maybe 134 as the limit. */ /* FIXME: Some methods get a buffer and assume its length. * This should normally be a parameter! */ #define GAMATRONIC_BUF_LEN 140 /* Forward decls */ static int instcmd(const char *cmdname, const char *extra); static int sec_upsrecv (char *buf) { char lenbuf[4]; int ret; ser_get_line(upsfd, buf, GAMATRONIC_BUF_LEN, ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); if (buf[0] == SEC_MSG_STARTCHAR) { switch (buf[1]) { case SEC_NAK: return(-1); case SEC_ACK: return(0); case SEC_DATAMSG: strncpy(lenbuf, buf+2, 3); lenbuf[3] = '\0'; ret = atoi(lenbuf); if (ret > GAMATRONIC_BUF_LEN) { upsdebugx(1, "%s: got a longer response message " "than expected for protocol: %d (%s) > %d", __func__, ret, lenbuf, GAMATRONIC_BUF_LEN); ret = GAMATRONIC_BUF_LEN; } if (ret > 0) { /* Note: ser_get_line() returns a * safely zero-terminated string */ memmove(buf, buf+5, (GAMATRONIC_BUF_LEN - 5)); return(ret); } /* else (ret <= 0) : */ upsdebugx(1, "%s: invalid response message length: %s", __func__, lenbuf); return (-2); default: return(-2); } } else return (-2); } static ssize_t sec_cmd(const char mode, const char *command, char *msgbuf, ssize_t *buflen) { char msg[GAMATRONIC_BUF_LEN]; ssize_t ret; memset(msg, 0, sizeof(msg)); /* create the message string */ if (*buflen > 0) { snprintf(msg, sizeof(msg), "%c%c%03zd%s%s", SEC_MSG_STARTCHAR, mode, (*buflen)+3, command, msgbuf); } else { snprintf(msg, sizeof(msg), "%c%c003%s", SEC_MSG_STARTCHAR, mode, command); } upsdebugx(1, "PC-->UPS: \"%s\"",msg); ret = ser_send(upsfd, "%s", msg); upsdebugx(1, " send returned: %" PRIiSIZE, ret); if (ret == -1) return -1; ret = sec_upsrecv(msg); if (ret < 0) return -1; strncpy(msgbuf, msg, (size_t)ret); upsdebugx(1, "UPS<--PC: \"%s\"",msg); /* *(msgbuf+ret) = '\0'; */ *buflen = ret; return ret; } static void addquery(const char *cmd, int field, int varnum, int pollflag) { int q; for (q=0; q 0) { if (strcmp(sec_varlist[sqv(q,f)].value, r) != 0) { #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic ignored "-Wformat-truncation" #endif /* NOTE: We intentionally limit the amount * of characters picked from "r" buffer * into respectively sized "*.value" */ int len = snprintf(sec_varlist[sqv(q,f)].value, sizeof(sec_varlist[sqv(q,f)].value), "%s", r); if (len < 0) { upsdebugx(1, "%s: got an error while extracting value", __func__); } if ((intmax_t)len > (intmax_t)sizeof(sec_varlist[sqv(q,f)].value) || (intmax_t)strnlen(r, sizeof(retbuf)) > (intmax_t)sizeof(sec_varlist[sqv(q,f)].value) ) { upsdebugx(1, "%s: value was truncated", __func__); } #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic pop #endif sec_setinfo(sqv(q,f), r); } /* If SEC VAR is alarm and it's on, add it to the alarm property */ if (sec_varlist[sqv(q,f)].flags & FLAG_ALARM && strcmp(r,"1")== 0) { alarm_set(sec_varlist[sqv(q,f)].name); } } if (n == NULL) break; r = n+1; } } } void upsdrv_initinfo(void) { ssize_t msglen; int v; char *a, *p, avail_list[300]; /* find out which variables/commands this UPS supports */ msglen = 0; sec_cmd(SEC_POLLCMD, SEC_AVAILP1, avail_list, &msglen); p = avail_list + msglen; if (p != avail_list) *p++ = ','; msglen = 0; sec_cmd(SEC_POLLCMD, SEC_AVAILP2, p, &msglen); *(p+msglen) = '\0'; if (strlen(avail_list) == 0) { fatalx(EXIT_FAILURE, "No available variables found!"); } a = avail_list; while ((p = strtok(a, ",")) != NULL) { a = NULL; v = atoi(p); /* don't bother adding a write-only variable */ if (sec_varlist[v].flags == FLAG_WONLY) continue; addquery(sec_varlist[v].cmd, sec_varlist[v].field, v, sec_varlist[v].poll); } /* poll one time values */ sec_poll(FLAG_POLLONCE); printf("UPS: %s %s\n", dstate_getinfo("ups.mfr"), dstate_getinfo("ups.model")); /* commands ----------------------------------------------- */ dstate_addcmd("shutdown.return"); /* install handlers */ upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { alarm_init(); /* poll status values values */ sec_poll(FLAG_POLL); alarm_commit(); update_pseudovars(); dstate_dataok(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = do_loop_shutdown_commands("shutdown.return", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); /* if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ser_send_buf(upsfd, ...); return STAT_INSTCMD_HANDLED; } */ if (!strcasecmp(cmdname, "shutdown.return")) { ssize_t msglen; char msgbuf[SMALLBUF]; msglen = snprintf(msgbuf, sizeof(msgbuf), "-1"); upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); sec_cmd(SEC_SETCMD, SEC_SHUTDOWN, msgbuf, &msglen); msglen = snprintf(msgbuf, sizeof(msgbuf), "1"); sec_cmd(SEC_SETCMD, SEC_AUTORESTART, msgbuf, &msglen); msglen = snprintf(msgbuf, sizeof(msgbuf), "2"); sec_cmd(SEC_SETCMD, SEC_SHUTTYPE,msgbuf, &msglen); msglen = snprintf(msgbuf, sizeof(msgbuf), "5"); sec_cmd(SEC_SETCMD, SEC_SHUTDOWN, msgbuf, &msglen); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { /* allow '-x xyzzy' */ /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */ /* allow '-x foo=' */ /* addvar(VAR_VALUE, "foo", "Override foo setting"); */ } static void setup_serial(const char *port) { char temp[GAMATRONIC_BUF_LEN]; int i; ssize_t ret; /* Detect the ups baudrate */ for (i=0; i<5; i++) { ser_set_speed(upsfd, device_path, baud_rates[i].rate); ret = ser_send(upsfd, "^P003MAN"); ret = sec_upsrecv(temp); if (ret >= -1) break; } if (i == 5) { printf("Can't talk to UPS on port %s!\n",port); printf("Check the cabling and portname and try again\n"); printf("Please note that this driver only support UPS Models with SEC Protocol\n"); ser_close(upsfd, device_path); exit (1); } else printf("Connected to UPS on %s baudrate: %" PRIuSIZE "\n", port, baud_rates[i].name); } void upsdrv_initups(void) { upsfd = ser_open(device_path); setup_serial(device_path); /* upsfd = ser_open(device_path); */ /* ser_set_speed(upsfd, device_path, B1200); */ /* probe ups type */ /* to get variables and flags from the command line, use this: * * first populate with upsdrv_buildvartable above, then... * * set flag foo : /bin/driver -x foo * set variable 'cable' to '1234' : /bin/driver -x cable=1234 * * to test flag foo in your code: * * if (testvar("foo")) * do_something(); * * to show the value of cable: * * if ((cable == getval("cable"))) * printf("cable is set to %s\n", cable); * else * printf("cable is not set!\n"); * * don't use NULL pointers - test the return result first! */ /* the upsh handlers can't be done here, as they get initialized * shortly after upsdrv_initups returns to main. */ } void upsdrv_cleanup(void) { /* free(dynamic_mem); */ ser_close(upsfd, device_path); } nut-2.8.4/drivers/eaton-pdu-pulizzi-mib.c0000644000175000017500000001650615000601404015241 00000000000000/* eaton-pdu-pulizzi-mib.c - data to monitor Eaton ePDUs branded as: * G1 Pulizzi Monitored and Switched ePDUs * * Copyright (C) 2008 - 2017 * Arnaud Quette * Arnaud Quette * Copyright (C) 2015 - 2017 * Jim Klimov * * Supported by Eaton * and previously MGE Office Protection Systems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "eaton-pdu-pulizzi-mib.h" /* Pulizzi Monitored ePDU (Basic model, SNMP only) * FIXME: to be completed * * Warning: there are 2 versions: * - SA built MI.mib (old MIB) * #define PULIZZI1_OID_MIB ".1.3.6.1.4.1.20677.3.1.1" * #define PULIZZI1_OID_MODEL_NAME ".1.3.6.1.4.1.20677.3.1.1.1.2.0" * - Eaton-Powerware-Monitored-ePDU_1.0.E.mib (new MIB) Vertical SW */ /* Pulizzi Switched ePDU */ #define EATON_PULIZZI_SW_MIB_VERSION "0.50" #define PULIZZI_SW_OID_MIB ".1.3.6.1.4.1.20677.3.1.1" #define PULIZZI_SW_OID_MODEL_NAME ".1.3.6.1.4.1.20677.2.1.1.0" /* Some buggy FW also report sysOID = ".1.3.6.1.4.1.20677.1" */ #define EATON_PULIZZI_SWITCHED1_SYSOID ".1.3.6.1.4.1.20677.1" #define EATON_PULIZZI_SWITCHED2_SYSOID ".1.3.6.1.4.1.20677.2" static info_lkp_t pulizzi_sw_outlet_status_info[] = { info_lkp_default(1, "on"), info_lkp_default(2, "off"), info_lkp_sentinel }; /* simply remap the above status to "yes" */ static info_lkp_t pulizzi_sw_outlet_switchability_info[] = { info_lkp_default(1, "yes"), info_lkp_default(2, "yes"), info_lkp_sentinel }; /* Snmp2NUT lookup table for Eaton Pulizzi Switched ePDU MIB */ static snmp_info_t eaton_pulizzi_switched_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "EATON | Powerware", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, PULIZZI_SW_OID_MODEL_NAME, "Switched ePDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.macaddr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.20677.2.2.6.0", "unknown", 0, NULL), /* UPS page */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "EATON", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, PULIZZI_SW_OID_MODEL_NAME, "Switched ePDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* FIXME: to be moved to the device collection! */ snmp_info_default("ups.date", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.20677.2.1.4.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.time", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.20677.2.1.3.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* Outlet page */ /* Note: outlet.count is deduced, with guesstimate_outlet_count() */ snmp_info_default("outlet.id", 0, 1, NULL, "0", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, NULL, "All outlets", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.current", 0, 1.0, ".1.3.6.1.4.1.20677.2.8.6.4.2.0", NULL, 0, NULL), snmp_info_default("outlet.voltage", 0, 1.0, ".1.3.6.1.4.1.20677.2.8.6.4.1.0", NULL, 0, NULL), snmp_info_default("outlet.power", 0, 1.0, ".1.3.6.1.4.1.20677.2.8.6.4.3.0", NULL, 0, NULL), /* outlet template definition * Notes: * - indexes start from 1, ie outlet.1 => .1 * - the first definition is used to determine the base index (ie 0 or 1) * - outlet.count is estimated, based on the below OID iteration capabilities */ snmp_info_default("outlet.%i.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.20677.2.6.1.%i.1.0", NULL, SU_FLAG_STATIC | SU_FLAG_OK | SU_OUTLET, NULL), snmp_info_default("outlet.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.20677.2.6.3.%i.0", NULL, SU_FLAG_OK | SU_OUTLET, &pulizzi_sw_outlet_status_info[0]), snmp_info_default("outlet.%i.id", 0, 1, NULL, "%i", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK | SU_OUTLET, NULL), /* we use the same OID as outlet.n.status..., to expose switchability */ snmp_info_default("outlet.%i.switchable", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.20677.2.6.3.%i.0", "yes", SU_FLAG_STATIC | SU_FLAG_OK | SU_OUTLET, &pulizzi_sw_outlet_switchability_info[0]), /* FIXME: need to be added to the namespace! */ snmp_info_default("outlet.%i.delay.reboot", ST_FLAG_RW, 1, ".1.3.6.1.4.1.20677.2.6.1.%i.5.0", NULL, SU_OUTLET, NULL), /* "outlet1SequenceTime" is used for global sequence */ snmp_info_default("outlet.%i.delay.start", ST_FLAG_RW, 1, ".1.3.6.1.4.1.20677.2.6.1.%i.4.0", NULL, SU_OUTLET, NULL), /* instant commands. */ /* FIXME: not exposed as "outlet.load...", or otherwise specific processing applies (template instanciation) */ snmp_info_default("load.on", 0, 1, ".1.3.6.1.4.1.20677.2.6.2.1.0", "1", SU_TYPE_CMD, NULL), snmp_info_default("load.off", 0, 1, ".1.3.6.1.4.1.20677.2.6.2.1.0", "2", SU_TYPE_CMD, NULL), snmp_info_default("load.on.delay", 0, 1, ".1.3.6.1.4.1.20677.2.6.2.1.0", "3", SU_TYPE_CMD, NULL), snmp_info_default("load.off.delay", 0, 1, ".1.3.6.1.4.1.20677.2.6.2.1.0", "4", SU_TYPE_CMD, NULL), /* WARNING: outlet 1 => index 2, so SU_CMD_OFFSET! */ snmp_info_default("outlet.%i.load.on", 0, 1, ".1.3.6.1.4.1.20677.2.6.2.%i.0", "1", SU_TYPE_CMD | SU_OUTLET | SU_CMD_OFFSET, NULL), snmp_info_default("outlet.%i.load.off", 0, 1, ".1.3.6.1.4.1.20677.2.6.2.%i.0", "2", SU_TYPE_CMD | SU_OUTLET | SU_CMD_OFFSET, NULL), snmp_info_default("outlet.%i.load.cycle", 0, 1, ".1.3.6.1.4.1.20677.2.6.2.%i.0", "3", SU_TYPE_CMD | SU_OUTLET | SU_CMD_OFFSET, NULL), /* end of structure. */ snmp_info_sentinel }; /*mib2nut_info_t pulizzi_monitored = { "pulizzi_monitored", EATON_PULIZZI_MIB_VERSION, NULL, PULIZZI1_OID_MODEL_NAME, eaton_pulizzi_monitored_mib, PULIZZI1_OID_MIB };*/ mib2nut_info_t pulizzi_switched1 = { "pulizzi_switched1", EATON_PULIZZI_SW_MIB_VERSION, NULL, EATON_PULIZZI_SWITCHED1_SYSOID, eaton_pulizzi_switched_mib, EATON_PULIZZI_SWITCHED1_SYSOID, NULL }; mib2nut_info_t pulizzi_switched2 = { "pulizzi_switched2", EATON_PULIZZI_SW_MIB_VERSION, NULL, EATON_PULIZZI_SWITCHED1_SYSOID, eaton_pulizzi_switched_mib, EATON_PULIZZI_SWITCHED2_SYSOID, NULL }; nut-2.8.4/drivers/riello_ser.c0000644000175000017500000011242615044656702013254 00000000000000/* * riello_ser.c: support for Riello serial protocol based UPSes * * A document describing the protocol implemented by this driver can be * found online at "https://www.networkupstools.org/protocols/riello/PSGPSER-0104.pdf" * and "https://www.networkupstools.org/protocols/riello/PSSENTR-0100.pdf". * * Copyright (C) 2012 - Elio Parisi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Reference of the derivative work: blazer driver */ #include "config.h" /* must be the first header */ #include "common.h" /* for upsdebugx() etc */ #include #ifdef WIN32 # include "wincompat.h" #endif /* WIN32 */ #include "main.h" #include "serial.h" #include "timehead.h" /* * // The serial driver has no need for HID structures/code currently * // (maybe there is/was a plan for sharing something between siblings). * // Note that HID is tied to libusb or libshut definitions at the moment. #include "hidparser.h" #include "hidtypes.h" */ #include "riello.h" #define DRIVER_NAME "Riello serial driver" #define DRIVER_VERSION "0.15" #define DEFAULT_OFFDELAY 5 /*!< seconds (max 0xFF) */ #define DEFAULT_BOOTDELAY 5 /*!< seconds (max 0xFF) */ /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Elio Parisi ", DRV_EXPERIMENTAL, { NULL } }; static uint8_t bufOut[BUFFER_SIZE]; static uint8_t bufIn[BUFFER_SIZE]; static uint8_t gpser_error_control; static uint8_t typeRielloProtocol; static uint8_t input_monophase; static uint8_t output_monophase; static unsigned int offdelay = DEFAULT_OFFDELAY; static unsigned int bootdelay = DEFAULT_BOOTDELAY; static TRielloData DevData; /* Flag for estimation of battery.runtime and battery.charge */ static int localcalculation = 0; static int localcalculation_logged = 0; /* NOTE: Do not change these default, they refer to battery.voltage.nominal=12.0 * and used in related maths later */ static double batt_volt_nom = 12.0; static double batt_volt_low = 10.4; static double batt_volt_high = 13.0; /********************************************************************** * char_read (char *bytes, size_t size, int read_timeout) * * reads size bytes from the serial port * * bytes - buffer to store the data * size - size of the data to get * read_timeout - serial timeout (in milliseconds) * * return -1 on error, -2 on timeout, nb_bytes_readen on success * * See also select_read() in common.c (TODO: standardize codebase) * *********************************************************************/ static ssize_t char_read (char *bytes, size_t size, int read_timeout) { ssize_t readen = 0; #ifndef WIN32 int rc = 0; struct timeval serial_timeout; fd_set readfs; FD_ZERO (&readfs); FD_SET (upsfd, &readfs); serial_timeout.tv_usec = (read_timeout % 1000) * 1000; serial_timeout.tv_sec = (read_timeout / 1000); rc = select (upsfd + 1, &readfs, NULL, NULL, &serial_timeout); if (0 == rc) return -2; /* timeout */ if (FD_ISSET (upsfd, &readfs)) { #else /* WIN32 */ DWORD timeout; COMMTIMEOUTS TOut; timeout = read_timeout; /* recast */ GetCommTimeouts(upsfd, &TOut); TOut.ReadIntervalTimeout = MAXDWORD; TOut.ReadTotalTimeoutMultiplier = 0; TOut.ReadTotalTimeoutConstant = timeout; SetCommTimeouts(upsfd, &TOut); #endif /* WIN32 */ ssize_t now; #ifndef WIN32 now = read (upsfd, bytes, size - (size_t)readen); #else /* WIN32 */ /* FIXME? for some reason this compiles, but the first * arg to the method should be serial_handler_t* - not * a HANDLE as upsfd is (in main.c)... then again, many * other drivers seem to use it just fine... */ now = w32_serial_read(upsfd, bytes, size - (size_t)readen, timeout); #endif /* WIN32 */ if (now < 0) { return -1; } else { readen += now; } #ifndef WIN32 } else { return -1; } #endif /* !WIN32 */ return readen; } /********************************************************************** * serial_read (int read_timeout) * * return data one byte at a time * * read_timeout - serial timeout (in milliseconds) * * returns 0 on success, -1 on error, -2 on timeout * **********************************************************************/ static ssize_t serial_read (int read_timeout, unsigned char *readbuf) { static unsigned char cache[512]; static unsigned char *cachep = cache; static unsigned char *cachee = cache; ssize_t recv; *readbuf = '\0'; /* if still data in cache, get it */ if (cachep < cachee) { *readbuf = *cachep++; return 0; /* return (int) *cachep++; */ } recv = char_read ((char *)cache, 1, read_timeout); if ((recv == -1) || (recv == -2)) return recv; cachep = cache; cachee = cache + recv; cachep = cache; cachee = cache + recv; if (recv) { upsdebugx(5,"received: %02x", *cachep); *readbuf = *cachep++; return 0; } return -1; } static void riello_serialcomm(uint8_t* arg_bufIn, uint8_t typedev) { time_t realt, nowt; uint8_t commb = 0; realt = time(NULL); while (wait_packet) { serial_read(1000, &commb); nowt = time(NULL); commbyte = commb; riello_parse_serialport(typedev, arg_bufIn, gpser_error_control); if ((nowt - realt) > 4) break; } } static int get_ups_nominal(void) { uint8_t length; riello_init_serial(); length = riello_prepare_gn(&bufOut[0], gpser_error_control); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Communication error while writing to port"); return -1; } riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get nominal Ko: bad CRC or Checksum"); return -1; } /* mandatory */ if (!wait_packet && foundnak) { upsdebugx (3, "Get nominal Ko: command not supported"); return -1; } upsdebugx (3, "Get nominal Ok: received byte %u", buf_ptr_length); riello_parse_gn(&bufIn[0], &DevData); return 0; } static int get_ups_status(void) { uint8_t numread, length; riello_init_serial(); length = riello_prepare_rs(&bufOut[0], gpser_error_control); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Communication error while writing to port"); return -1; } if (input_monophase) numread = LENGTH_RS_MM; else if (output_monophase) numread = LENGTH_RS_TM; else numread = LENGTH_RS_TT; riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get status Ko: bad CRC or Checksum"); return -1; } /* mandatory */ if (!wait_packet && foundnak) { upsdebugx (3, "Get status Ko: command not supported"); return -1; } upsdebugx (3, "Get status Ok: received byte %u", buf_ptr_length); riello_parse_rs(&bufIn[0], &DevData, numread); return 0; } static int get_ups_extended(void) { uint8_t length; riello_init_serial(); length = riello_prepare_re(&bufOut[0], gpser_error_control); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Communication error while writing to port"); return -1; } riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get extended Ko: bad CRC or Checksum"); return -1; } /* optonal */ if (!wait_packet && foundnak) { upsdebugx (3, "Get extended Ko: command not supported"); return 0; } upsdebugx (3, "Get extended Ok: received byte %u", buf_ptr_length); riello_parse_re(&bufIn[0], &DevData); return 0; } /* Not static, exposed via header. Not used though, currently... */ int get_ups_statuscode(void) { uint8_t length; riello_init_serial(); length = riello_prepare_rc(&bufOut[0], gpser_error_control); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Communication error while writing to port"); return -1; } riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get statuscode Ko: bad CRC or Checksum"); return -1; } /* optional */ if (!wait_packet && foundnak) { upsdebugx (3, "Get statuscode Ko: command not supported"); return 0; } upsdebugx (3, "Get statuscode Ok: received byte %u", buf_ptr_length); riello_parse_rc(&bufIn[0], &DevData); return 0; } static int get_ups_sentr(void) { uint8_t length; riello_init_serial(); bufOut[0] = requestSENTR; if (requestSENTR == SENTR_EXT176) { bufOut[1] = 103; bufOut[2] = 1; bufOut[3] = 0; bufOut[4] = 24; length = 5; } else length = 1; if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Communication error while writing to port"); return -1; } riello_serialcomm(&bufIn[0], DEV_RIELLOSENTRY); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get sentry Ko: bad CRC or Checksum"); return -1; } /* mandatory */ if (!wait_packet && foundnak) { upsdebugx (3, "Get sentry Ko: command not supported"); return -1; } upsdebugx (3, "Get sentry Ok: received byte %u", buf_ptr_length); riello_parse_sentr(&bufIn[0], &DevData); return 0; } static int riello_instcmd(const char *cmdname, const char *extra) { uint8_t length; uint16_t delay; const char *delay_char; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!riello_test_bit(&DevData.StatusCode[0], 1)) { if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); delay = 0; riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) length = riello_prepare_cs(bufOut, gpser_error_control, delay); else length = riello_prepare_shutsentr(bufOut, delay); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command load.off communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.off Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.off Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.off Ok"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.off.delay")) { int ipv; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); delay_char = dstate_getinfo("ups.delay.shutdown"); ipv = atoi(delay_char); if (ipv < 0 || (intmax_t)ipv > (intmax_t)UINT16_MAX) return STAT_INSTCMD_FAILED; delay = (uint16_t)ipv; riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) length = riello_prepare_cs(bufOut, gpser_error_control, delay); else length = riello_prepare_shutsentr(bufOut, delay); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command load.off delay communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.off.delay Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.off.delay Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.off delay Ok"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); delay = 0; riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) length = riello_prepare_cr(bufOut, gpser_error_control, delay); else { length = riello_prepare_setrebsentr(bufOut, delay); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command load.on communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.on Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.on Ko: command not supported"); return STAT_INSTCMD_FAILED; } length = riello_prepare_rebsentr(bufOut, delay); } if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command load.on communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.on Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.on Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.on Ok"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.on.delay")) { int ipv; upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); delay_char = dstate_getinfo("ups.delay.reboot"); ipv = atoi(delay_char); if (ipv < 0 || (intmax_t)ipv > (intmax_t)UINT16_MAX) return STAT_INSTCMD_FAILED; delay = (uint16_t)ipv; riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) length = riello_prepare_cr(bufOut, gpser_error_control, delay); else { length = riello_prepare_setrebsentr(bufOut, delay); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command load.on delay communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.on delay Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.on delay Ko: command not supported"); return STAT_INSTCMD_FAILED; } length = riello_prepare_rebsentr(bufOut, delay); } if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command load.on delay communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command load.on.delay Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command load.on.delay Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command load.on delay Ok"); return STAT_INSTCMD_HANDLED; } } else { if (!strcasecmp(cmdname, "shutdown.return")) { int ipv; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); delay_char = dstate_getinfo("ups.delay.shutdown"); ipv = atoi(delay_char); if (ipv < 0 || (intmax_t)ipv > (intmax_t)UINT16_MAX) return STAT_INSTCMD_FAILED; delay = (uint16_t)ipv; riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) length = riello_prepare_cs(bufOut, gpser_error_control, delay); else length = riello_prepare_shutsentr(bufOut, delay); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command shutdown.return communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command shutdown.return Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command shutdown.return Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command shutdown.return Ok"); return STAT_INSTCMD_HANDLED; } } if (!strcasecmp(cmdname, "shutdown.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) length = riello_prepare_cd(bufOut, gpser_error_control); else length = riello_prepare_cancelsentr(bufOut); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command shutdown.stop communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command shutdown.stop Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command shutdown.stop Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command shutdown.stop Ok"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.panel.start")) { riello_init_serial(); length = riello_prepare_tp(bufOut, gpser_error_control); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command test.panel.start communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command test.panel.start Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command test.panel.start Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command test.panel.start Ok"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) length = riello_prepare_tb(bufOut, gpser_error_control); else length = riello_prepare_tbsentr(bufOut); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Command test.battery.start communication error"); return STAT_INSTCMD_FAILED; } riello_serialcomm(&bufIn[0], typeRielloProtocol); if (!wait_packet && foundbadcrc) { upsdebugx (3, "Command battery.start Ko: bad CRC or Checksum"); return STAT_INSTCMD_FAILED; } if (!wait_packet && foundnak) { upsdebugx (3, "Command battery.start Ko: command not supported"); return STAT_INSTCMD_FAILED; } upsdebugx (3, "Command test.battery.start Ok"); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } static int start_ups_comm(void) { uint8_t length; upsdebugx (2, "entering start_ups_comm()\n"); riello_init_serial(); if (typeRielloProtocol == DEV_RIELLOGPSER) { length = riello_prepare_gi(&bufOut[0]); if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Communication error while writing to port"); return -1; } riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); } else { bufOut[0] = 192; length = 1; if (ser_send_buf(upsfd, bufOut, length) == 0) { upsdebugx (3, "Communication error while writing to port"); return -1; } riello_serialcomm(&bufIn[0], DEV_RIELLOSENTRY); } if (!wait_packet && foundbadcrc) { upsdebugx (3, "Get identif Ko: bad CRC or Checksum"); return 1; } if (!wait_packet && foundnak) { upsdebugx (3, "Get identif Ko: command not supported"); return 1; } upsdebugx (3, "Get identif Ok: received byte %u", buf_ptr_length); return 0; } void upsdrv_initinfo(void) { int ret; const char *valN = NULL, *valL = NULL, *valH = NULL; ret = start_ups_comm(); if (ret < 0) fatalx(EXIT_FAILURE, "No communication with UPS"); else if (ret > 0) fatalx(EXIT_FAILURE, "Bad checksum or NACK"); else upsdebugx(2, "Communication with UPS established"); if (testvar("localcalculation")) { localcalculation = 1; upsdebugx(1, "Will guesstimate battery charge and runtime " "instead of trusting device readings (if any); " "consider also setting default.battery.voltage.low " "and default.battery.voltage.high for this device"); } dstate_setinfo("driver.parameter.localcalculation", "%d", localcalculation); if (typeRielloProtocol == DEV_RIELLOGPSER) riello_parse_gi(&bufIn[0], &DevData); else riello_parse_sentr(&bufIn[0], &DevData); gpser_error_control = DevData.Identif_bytes[4]-0x30; if ((DevData.Identif_bytes[0] == '1') || (DevData.Identif_bytes[0] == '2')) input_monophase = 1; else { input_monophase = 0; dstate_setinfo("input.phases", "%d", 3); dstate_setinfo("input.phases", "%d", 3); dstate_setinfo("input.bypass.phases", "%d", 3); } if ((DevData.Identif_bytes[0] == '1') || (DevData.Identif_bytes[0] == '3')) output_monophase = 1; else { output_monophase = 0; dstate_setinfo("output.phases", "%d", 3); } dstate_setinfo("device.mfr", "RPS S.p.a."); dstate_setinfo("device.model", "%s", (unsigned char*) DevData.ModelStr); dstate_setinfo("device.serial", "%s", (unsigned char*) DevData.Identification); dstate_setinfo("device.type", "ups"); dstate_setinfo("ups.mfr", "RPS S.p.a."); dstate_setinfo("ups.model", "%s", (unsigned char*) DevData.ModelStr); dstate_setinfo("ups.serial", "%s", (unsigned char*) DevData.Identification); dstate_setinfo("ups.firmware", "%s", (unsigned char*) DevData.Version); /* Is it set by user default/override configuration? * NOTE: "valN" is also used for a check just below. */ valN = dstate_getinfo("battery.voltage.nominal"); if (valN) { batt_volt_nom = strtod(valN, NULL); upsdebugx(1, "Using battery.voltage.nominal=%.1f " "likely coming from user configuration", batt_volt_nom); } if (typeRielloProtocol == DEV_RIELLOGPSER) { if (get_ups_nominal() == 0) { dstate_setinfo("ups.realpower.nominal", "%u", DevData.NomPowerKW); dstate_setinfo("ups.power.nominal", "%u", DevData.NomPowerKVA); dstate_setinfo("output.voltage.nominal", "%u", DevData.NominalUout); dstate_setinfo("output.frequency.nominal", "%.1f", DevData.NomFout/10.0); /* Is it set by user default/override configuration (see just above)? */ if (valN) { upsdebugx(1, "...instead of battery.voltage.nominal=%u " "reported by the device", DevData.NomUbat); } else { dstate_setinfo("battery.voltage.nominal", "%u", DevData.NomUbat); batt_volt_nom = (double)DevData.NomUbat; } dstate_setinfo("battery.capacity", "%u", DevData.NomBatCap); } } else { if (get_ups_sentr() == 0) { dstate_setinfo("ups.realpower.nominal", "%u", DevData.NomPowerKW); dstate_setinfo("ups.power.nominal", "%u", DevData.NomPowerKVA); dstate_setinfo("output.voltage.nominal", "%u", DevData.NominalUout); dstate_setinfo("output.frequency.nominal", "%.1f", DevData.NomFout/10.0); /* Is it set by user default/override configuration (see just above)? */ if (valN) { upsdebugx(1, "...instead of battery.voltage.nominal=%u " "reported by the device", DevData.NomUbat); } else { dstate_setinfo("battery.voltage.nominal", "%u", DevData.NomUbat); batt_volt_nom = (double)DevData.NomUbat; } dstate_setinfo("battery.capacity", "%u", DevData.NomBatCap); } else { /* TOTHINK: Check the momentary reading of battery.voltage * or would it be too confusing (especially if it is above * 12V and might correspond to a discharged UPS when the * driver starts up after an outage?) * NOTE: DevData.Ubat would be scaled by 10! */ if (!valN) { /* The nominal was not already set by user configuration... */ upsdebugx(1, "Using built-in default battery.voltage.nominal=%.1f", batt_volt_nom); dstate_setinfo("battery.voltage.nominal", "%.1f", batt_volt_nom); } } } /* We have a nominal voltage by now - either from user configuration * or from the device itself (or initial defaults for 12V). Do we have * any low/high range from HW/FW or defaults from ups.conf? */ valL = dstate_getinfo("battery.voltage.low"); valH = dstate_getinfo("battery.voltage.high"); { /* scoping */ /* Pick a suitable low/high range (or keep built-in default). * The factor may be a count of battery packs in the UPS. */ int times12 = batt_volt_nom / 12; if (times12 > 1) { /* Scale up the range for 24V (X=2) etc. */ upsdebugx(3, "%s: Using %i times the voltage range of 12V PbAc battery", __func__, times12); batt_volt_low *= times12; batt_volt_high *= times12; } } if (!valL && !valH) { /* Both not set (NULL) => pick by nominal (X times 12V above). */ upsdebugx(3, "Neither battery.voltage.low=%.1f " "nor battery.voltage.high=%.1f is set via " "driver configuration or by device; keeping " "at built-in default value (aligned " "with battery.voltage.nominal=%.1f)", batt_volt_low, batt_volt_high, batt_volt_nom); } else { if (valL) { batt_volt_low = strtod(valL, NULL); upsdebugx(2, "%s: Using battery.voltage.low=%.1f from device or settings", __func__, batt_volt_low); } if (valH) { batt_volt_high = strtod(valH, NULL); upsdebugx(2, "%s: Using battery.voltage.high=%.1f from device or settings", __func__, batt_volt_high); } /* If just one of those is set, then what? */ if (valL || valH) { upsdebugx(1, "WARNING: Only one of battery.voltage.low=%.1f " "or battery.voltage.high=%.1f is set via " "driver configuration; keeping the other " "at built-in default value (aligned " "with battery.voltage.nominal=%.1f)", batt_volt_low, batt_volt_high, batt_volt_nom); } else { upsdebugx(1, "Both of battery.voltage.low=%.1f " "or battery.voltage.high=%.1f are set via " "driver configuration; not aligning " "with battery.voltage.nominal=%.1f", batt_volt_low, batt_volt_high, batt_volt_nom); } } /* Whatever the origin, make the values known via dstate */ dstate_setinfo("battery.voltage.low", "%.1f", batt_volt_low); dstate_setinfo("battery.voltage.high", "%.1f", batt_volt_high); /* commands ----------------------------------------------- */ dstate_addcmd("load.off"); dstate_addcmd("load.on"); dstate_addcmd("load.off.delay"); dstate_addcmd("load.on.delay"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stop"); dstate_addcmd("test.battery.start"); dstate_setinfo("ups.delay.shutdown", "%u", offdelay); dstate_setflags("ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.shutdown", 3); dstate_setinfo("ups.delay.reboot", "%u", bootdelay); dstate_setflags("ups.delay.reboot", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.reboot", 3); if (typeRielloProtocol == DEV_RIELLOGPSER) dstate_addcmd("test.panel.start"); /* install handlers */ /* upsh.setvar = hid_set_value; setvar; */ upsh.instcmd = riello_instcmd; } void upsdrv_updateinfo(void) { uint8_t getextendedOK; static int countlost = 0; int stat; unsigned int battcharge; float battruntime; float upsloadfactor; #ifdef RIELLO_DYNAMIC_BATTVOLT_INFO const char *val = NULL; #endif upsdebugx(1, "countlost %d",countlost); if (countlost > 0){ upsdebugx(1, "Communication with UPS is lost: status read failed!"); if (countlost == COUNTLOST) { dstate_datastale(); upslogx(LOG_WARNING, "Communication with UPS is lost: status read failed!"); } } if (typeRielloProtocol == DEV_RIELLOGPSER) { stat = get_ups_status(); upsdebugx(1, "get_ups_status() %d", stat ); } else { stat = get_ups_sentr(); upsdebugx(1, "get_ups_sentr() %d", stat ); } if (stat < 0) { if (countlost < COUNTLOST) countlost++; return; } if (typeRielloProtocol == DEV_RIELLOGPSER) { if (get_ups_extended() == 0) getextendedOK = 1; else getextendedOK = 0; } else getextendedOK = 1; if (countlost == COUNTLOST) upslogx(LOG_NOTICE, "Communication with UPS is re-established!"); dstate_setinfo("input.frequency", "%.2f", DevData.Finp/10.0); dstate_setinfo("input.bypass.frequency", "%.2f", DevData.Fbypass/10.0); dstate_setinfo("output.frequency", "%.2f", DevData.Fout/10.0); dstate_setinfo("battery.voltage", "%.1f", DevData.Ubat/10.0); #ifdef RIELLO_DYNAMIC_BATTVOLT_INFO /* Can be set via default.* or override.* driver options * if not served by the device HW/FW */ val = dstate_getinfo("battery.voltage.low"); if (val) { batt_volt_low = strtod(val, NULL); } val = dstate_getinfo("battery.voltage.high"); if (val) { batt_volt_high = strtod(val, NULL); } #endif if (localcalculation) { /* NOTE: at this time "localcalculation" is a configuration toggle. * Maybe later it can be replaced by a common "runtimecal" setting. */ /* Considered "Ubat" physical range here (e.g. 10.7V to 12.9V) is * seen as "107" or "129" integers in the DevData properties: */ uint16_t Ubat_low = batt_volt_low * 10; /* e.g. 107 */ uint16_t Ubat_high = batt_volt_high * 10; /* e.g. 129 */ static int batt_volt_logged = 0; if (!batt_volt_logged) { upsdebugx(0, "\nUsing battery.voltage.low=%.1f and " "battery.voltage.high=%.1f for \"localcalculation\" " "guesstimates of battery.charge and battery.runtime", batt_volt_low, batt_volt_high); batt_volt_logged = 1; } battcharge = ((DevData.Ubat <= Ubat_high) && (DevData.Ubat >= Ubat_low)) ? (((DevData.Ubat - Ubat_low)*100) / (Ubat_high - Ubat_low)) : ((DevData.Ubat < Ubat_low) ? 0 : 100); battruntime = (DevData.NomBatCap * DevData.NomUbat * 3600.0/DevData.NomPowerKW) * (battcharge/100.0); upsloadfactor = (DevData.Pout1 > 0) ? (DevData.Pout1/100.0) : 1; dstate_setinfo("battery.charge", "%u", battcharge); dstate_setinfo("battery.runtime", "%.0f", battruntime/upsloadfactor); } else { if (!localcalculation_logged) { upsdebugx(0, "\nIf you don't see values for battery.charge and " "battery.runtime or values are incorrect," "try setting \"localcalculation\" flag in \"ups.conf\" " "options section for this driver!\n"); localcalculation_logged = 1; } if ((DevData.BatCap < 0xFFFF) && (DevData.BatTime < 0xFFFF)) { /* Use values reported by the driver unless they are marked * invalid/unknown by HW/FW (all bits in the word are set). */ dstate_setinfo("battery.charge", "%u", DevData.BatCap); dstate_setinfo("battery.runtime", "%u", (unsigned int)DevData.BatTime*60); } } if (DevData.Tsystem == 255) { /* Use values reported by the driver unless they are marked * invalid/unknown by HW/FW (all bits in the word are set). */ /*dstate_setinfo("ups.temperature", "%u", 0);*/ upsdebugx(4, "Reported temperature value is 0xFF, " "probably meaning \"-1\" for error or " "missing sensor - ignored"); } else if (DevData.Tsystem < 0xFF) { dstate_setinfo("ups.temperature", "%u", DevData.Tsystem); } if (input_monophase) { dstate_setinfo("input.voltage", "%u", DevData.Uinp1); dstate_setinfo("input.bypass.voltage", "%u", DevData.Ubypass1); } else { dstate_setinfo("input.L1-N.voltage", "%u", DevData.Uinp1); dstate_setinfo("input.L2-N.voltage", "%u", DevData.Uinp2); dstate_setinfo("input.L3-N.voltage", "%u", DevData.Uinp3); dstate_setinfo("input.bypass.L1-N.voltage", "%u", DevData.Ubypass1); dstate_setinfo("input.bypass.L2-N.voltage", "%u", DevData.Ubypass2); dstate_setinfo("input.bypass.L3-N.voltage", "%u", DevData.Ubypass3); } if (output_monophase) { dstate_setinfo("output.voltage", "%u", DevData.Uout1); dstate_setinfo("output.power.percent", "%u", DevData.Pout1); dstate_setinfo("ups.load", "%u", DevData.Pout1); } else { dstate_setinfo("output.L1-N.voltage", "%u", DevData.Uout1); dstate_setinfo("output.L2-N.voltage", "%u", DevData.Uout2); dstate_setinfo("output.L3-N.voltage", "%u", DevData.Uout3); dstate_setinfo("output.L1.power.percent", "%u", DevData.Pout1); dstate_setinfo("output.L2.power.percent", "%u", DevData.Pout2); dstate_setinfo("output.L3.power.percent", "%u", DevData.Pout3); dstate_setinfo("ups.load", "%u", (unsigned int)(DevData.Pout1+DevData.Pout2+DevData.Pout3)/3); } status_init(); /* AC Fail */ if (riello_test_bit(&DevData.StatusCode[0], 1)) status_set("OB"); else status_set("OL"); /* LowBatt */ if ((riello_test_bit(&DevData.StatusCode[0], 1)) && (riello_test_bit(&DevData.StatusCode[0], 0))) status_set("LB"); /* Standby */ if (!riello_test_bit(&DevData.StatusCode[0], 3)) status_set("OFF"); /* On Bypass */ if (riello_test_bit(&DevData.StatusCode[1], 3)) status_set("BYPASS"); /* Overload */ if (riello_test_bit(&DevData.StatusCode[4], 2)) status_set("OVER"); /* Buck */ if (riello_test_bit(&DevData.StatusCode[1], 0)) status_set("TRIM"); /* Boost */ if (riello_test_bit(&DevData.StatusCode[1], 1)) status_set("BOOST"); /* Replace battery */ if (riello_test_bit(&DevData.StatusCode[2], 0)) status_set("RB"); /* Charging battery */ if (riello_test_bit(&DevData.StatusCode[2], 2)) status_set("CHRG"); status_commit(); dstate_dataok(); if (getextendedOK) { dstate_setinfo("output.L1.power", "%u", DevData.Pout1VA); dstate_setinfo("output.L2.power", "%u", DevData.Pout2VA); dstate_setinfo("output.L3.power", "%u", DevData.Pout3VA); dstate_setinfo("output.L1.realpower", "%u", DevData.Pout1W); dstate_setinfo("output.L2.realpower", "%u", DevData.Pout2W); dstate_setinfo("output.L3.realpower", "%u", DevData.Pout3W); dstate_setinfo("output.L1.current", "%u", DevData.Iout1); dstate_setinfo("output.L2.current", "%u", DevData.Iout2); dstate_setinfo("output.L3.current", "%u", DevData.Iout3); } poll_interval = 2; countlost = 0; /* if (get_ups_statuscode() != 0) upsdebugx(2, "Communication is lost"); else { }*/ /* * poll_interval = 2; */ } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ int retry; /* maybe try to detect the UPS here, but try a shutdown even if it doesn't respond at first if possible */ /* replace with a proper shutdown function */ /* you may have to check the line status since the commands for toggling power are frequently different for OL vs. OB */ /* OL: this must power cycle the load if possible */ /* OB: the load must remain off until the power returns */ upsdebugx(2, "upsdrv Shutdown execute"); for (retry = 1; retry <= MAXTRIES; retry++) { /* By default, abort a previously requested shutdown * (if any) and schedule a new one from this moment. */ if (riello_instcmd("shutdown.stop", NULL) != STAT_INSTCMD_HANDLED) { continue; } if (riello_instcmd("shutdown.return", NULL) != STAT_INSTCMD_HANDLED) { continue; } upslogx(LOG_ERR, "Shutting down"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); return; } upslogx(LOG_ERR, "Shutdown failed!"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } /* static int setvar(const char *varname, const char *val) { upsdebug_SET_STARTING(varname, val); if (!strcasecmp(varname, "ups.test.interval")) { ser_send_buf(upsfd, ...); return STAT_SET_HANDLED; } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } */ void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { /* allow '-x xyzzy' */ /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */ /* allow '-x foo=' */ /* addvar(VAR_VALUE, "foo", "Override foo setting"); */ addvar(VAR_FLAG, "localcalculation", "Calculate battery charge and runtime locally"); } void upsdrv_initups(void) { upsdebugx(2, "entering upsdrv_initups()"); upsfd = ser_open(device_path); riello_comm_setup(device_path); /* probe ups type */ /* to get variables and flags from the command line, use this: * * first populate with upsdrv_buildvartable above, then... * * set flag foo : /bin/driver -x foo * set variable 'cable' to '1234' : /bin/driver -x cable=1234 * * to test flag foo in your code: * * if (testvar("foo")) * do_something(); * * to show the value of cable: * * if ((cable = getval("cable"))) * printf("cable is set to %s\n", cable); * else * printf("cable is not set!\n"); * * don't use NULL pointers - test the return result first! */ /* the upsh handlers can't be done here, as they get initialized * shortly after upsdrv_initups returns to main. */ /* don't try to detect the UPS here */ /* initialise communication */ } void upsdrv_cleanup(void) { /* free(dynamic_mem); */ ser_close(upsfd, device_path); } void riello_comm_setup(const char *port) { uint8_t length; upsdebugx(2, "set baudrate 9600"); ser_set_speed(upsfd, device_path, B9600); upsdebugx(2, "try to detect SENTR"); riello_init_serial(); bufOut[0] = 192; ser_send_buf(upsfd, bufOut, 1); riello_serialcomm(&bufIn[0], DEV_RIELLOSENTRY); if (buf_ptr_length == 103) { typeRielloProtocol = DEV_RIELLOSENTRY; upslogx(LOG_INFO, "Connected to UPS SENTR on %s with baudrate %d", port, 9600); return; } upsdebugx(2, "try to detect GPSER"); riello_init_serial(); length = riello_prepare_gi(&bufOut[0]); ser_send_buf(upsfd, bufOut, length); riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); if (!wait_packet && !foundbadcrc && !foundnak) { typeRielloProtocol = DEV_RIELLOGPSER; upslogx(LOG_INFO, "Connected to UPS GPSER on %s with baudrate %d", port, 9600); return; } upsdebugx(2, "set baudrate 1200"); ser_set_speed(upsfd, device_path, B1200); upsdebugx(2, "try to detect SENTR"); riello_init_serial(); bufOut[0] = 192; ser_send_buf(upsfd, bufOut, 1); riello_serialcomm(&bufIn[0], DEV_RIELLOSENTRY); if (buf_ptr_length == 103) { typeRielloProtocol = DEV_RIELLOSENTRY; upslogx(LOG_INFO, "Connected to UPS SENTR on %s with baudrate %d", port, 1200); return; } upsdebugx(2, "try to detect GPSER"); riello_init_serial(); length = riello_prepare_gi(&bufOut[0]); ser_send_buf(upsfd, bufOut, length); riello_serialcomm(&bufIn[0], DEV_RIELLOGPSER); if (!wait_packet && !foundbadcrc && !foundnak) { typeRielloProtocol = DEV_RIELLOGPSER; upslogx(LOG_INFO, "Connected to UPS GPSER on %s with baudrate %d", port, 1200); return; } fatalx(EXIT_FAILURE, "Can't connect to the UPS on port %s!\n", port); } nut-2.8.4/drivers/powerp-txt.c0000644000175000017500000003641015044656702013244 00000000000000/* * powerp-txt.c - Model specific routines for CyberPower text * protocol UPSes * * Copyright (C) * 2007 Doug Reynolds * 2007-2008 Arjen de Korte * 2012-2016 Timothy Pearson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Throughout this driver, READ and WRITE comments are shown. These are * the typical commands to and replies from the UPS that was used for * decoding the protocol (with a serial logger). */ #include "main.h" #include "serial.h" #include "nut_stdint.h" #include "powerp-txt.h" #include #define POWERPANEL_TEXT_VERSION "Powerpanel-Text 0.64" typedef struct { float i_volt; float o_volt; int o_load; int b_chrg; unsigned char has_u_temp; int u_temp; float i_freq; unsigned char flags[2]; unsigned char has_b_volt; float b_volt; unsigned char has_o_freq; float o_freq; unsigned char has_runtime; int runtime; } status_t; static long ondelay = 1; /* minutes */ static long offdelay = 60; /* seconds */ static char powpan_answer[SMALLBUF]; static struct { const char *var; const char *get; const char *set; } vartab[] = { { "input.transfer.high", "P6\r", "C2:%03d\r" }, { "input.transfer.low", "P7\r", "C3:%03d\r" }, { "battery.charge.low", "P8\r", "C4:%02d\r" }, { NULL, NULL, NULL } }; static struct { const char *cmd; const char *command; } cmdtab[] = { { "test.battery.start.quick", "T\r" }, { "test.battery.start.deep", "TL\r" }, { "test.battery.stop", "CT\r" }, { "beeper.enable", "C7:1\r" }, { "beeper.disable", "C7:0\r" }, { "beeper.on", NULL }, { "beeper.off", NULL }, { "shutdown.stop", "C\r" }, { NULL, NULL } }; static ssize_t powpan_command(const char *command) { ssize_t ret; ser_flush_io(upsfd); ret = ser_send_pace(upsfd, UPSDELAY, "%s", command); if (ret < 0) { upsdebug_with_errno(3, "send"); return -1; } if (ret == 0) { upsdebug_with_errno(3, "send: timeout"); return -1; } upsdebug_hex(3, "send", command, strlen(command)); usleep(100000); ret = ser_get_line(upsfd, powpan_answer, sizeof(powpan_answer), ENDCHAR, IGNCHAR, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 0) { upsdebug_with_errno(3, "read"); upsdebug_hex(4, " \\_", powpan_answer, strlen(powpan_answer)); return -1; } if (ret == 0) { upsdebugx(3, "read: timeout"); upsdebug_hex(4, " \\_", powpan_answer, strlen(powpan_answer)); return -1; } upsdebug_hex(3, "read", powpan_answer, (size_t)ret); return ret; } static int powpan_instcmd(const char *cmdname, const char *extra) { int i; char command[SMALLBUF]; if (!strcasecmp(cmdname, "beeper.off")) { /* compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.off' command has been renamed to 'beeper.disable'"); return powpan_instcmd("beeper.disable", NULL); } if (!strcasecmp(cmdname, "beeper.on")) { /* compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.on' command has been renamed to 'beeper.enable'"); return powpan_instcmd("beeper.enable", NULL); } /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); for (i = 0; cmdtab[i].cmd != NULL; i++) { if (strcasecmp(cmdname, cmdtab[i].cmd)) { continue; } upslog_INSTCMD_POWERSTATE_CHECKED(cmdname, extra); if ((powpan_command(cmdtab[i].command) == 2) && (!strcasecmp(powpan_answer, "#0"))) { return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_FAILED(cmdname, extra); return STAT_INSTCMD_FAILED; } if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if (offdelay < 60) { snprintf(command, sizeof(command), "Z.%ld\r", offdelay / 6); } else { snprintf(command, sizeof(command), "Z%02ld\r", offdelay / 60); } } else if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if (offdelay < 60) { snprintf(command, sizeof(command), "S.%ld\r", offdelay / 6); } else { snprintf(command, sizeof(command), "S%02ld\r", offdelay / 60); } } else if (!strcasecmp(cmdname, "shutdown.reboot")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if (offdelay < 60) { snprintf(command, sizeof(command), "S.%ldR%04ld\r", offdelay / 6, ondelay); } else { snprintf(command, sizeof(command), "S%02ldR%04ld\r", offdelay / 60, ondelay); } } else { upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } if ((powpan_command(command) == 2) && (!strcasecmp(powpan_answer, "#0"))) { return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_FAILED(cmdname, extra); return STAT_INSTCMD_FAILED; } static int powpan_setvar(const char *varname, const char *val) { char command[SMALLBUF]; int i; upsdebug_SET_STARTING(varname, val); for (i = 0; vartab[i].var != NULL; i++) { if (strcasecmp(varname, vartab[i].var)) { continue; } if (!strcasecmp(val, dstate_getinfo(varname))) { upslogx(LOG_INFO, "%s: [%s] no change for variable [%s]", __func__, val, varname); return STAT_SET_HANDLED; } snprintf_dynamic(command, sizeof(command), vartab[i].set, "%d", atoi(val)); if ((powpan_command(command) == 2) && (!strcasecmp(powpan_answer, "#0"))) { dstate_setinfo(varname, "%s", val); return STAT_SET_HANDLED; } upslog_SET_FAILED(varname, val); return STAT_SET_UNKNOWN; /* FIXME: ..._FAILED? */ } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } static void powpan_initinfo(void) { int i; char *s; dstate_setinfo("ups.delay.start", "%ld", 60 * ondelay); dstate_setinfo("ups.delay.shutdown", "%ld", offdelay); /* * NOTE: The reply is already in the buffer, since the P4\r command * was used for autodetection of the UPS. No need to do it again. */ if ((s = strtok(&powpan_answer[1], ",")) != NULL) { dstate_setinfo("ups.model", "%s", str_rtrim(s, ' ')); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("ups.firmware", "%s", s); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("ups.serial", "%s", s); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("ups.mfr", "%s", str_rtrim(s, ' ')); } /* * WRITE P3\r * READ #12.0,002,008.0,00\r * #12,2x1,12,0,1,8\r (CST135XLU) */ if (powpan_command("P3\r") > 0) { if ((s = strtok(&powpan_answer[1], ",")) != NULL) { dstate_setinfo("battery.voltage.nominal", "%f", strtod(s, NULL)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("battery.packs", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("battery.capacity", "%f", strtod(s, NULL)); } } /* * WRITE P2\r * READ #1200,0720,120,47,63\r * #1350,810,120,57,63,11.3\r (CST135XLU) */ if (powpan_command("P2\r") > 0) { if ((s = strtok(&powpan_answer[1], ",")) != NULL) { dstate_setinfo("ups.power.nominal", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("ups.realpower.nominal", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("input.voltage.nominal", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("input.frequency.low", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("input.frequency.high", "%li", strtol(s, NULL, 10)); } } /* * WRITE P1\r * READ #120,138,088,20\r * #120,139,100,0,300\r (CST135XLU) */ if (powpan_command("P1\r") > 0) { if ((s = strtok(&powpan_answer[1], ",")) != NULL) { dstate_setinfo("input.voltage.nominal", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("input.transfer.high", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("input.transfer.low", "%li", strtol(s, NULL, 10)); } if ((s = strtok(NULL, ",")) != NULL) { dstate_setinfo("battery.charge.low", "%li", strtol(s, NULL, 10)); } } for (i = 0; cmdtab[i].cmd != NULL; i++) { dstate_addcmd(cmdtab[i].cmd); } for (i = 0; vartab[i].var != NULL; i++) { if (!dstate_getinfo(vartab[i].var)) { continue; } if (powpan_command(vartab[i].get) < 1) { continue; } if ((s = strtok(&powpan_answer[1], ",")) != NULL) { dstate_setflags(vartab[i].var, ST_FLAG_RW); dstate_addenum(vartab[i].var, "%li", strtol(s, NULL, 10)); } while ((s = strtok(NULL, ",")) != NULL) { dstate_addenum(vartab[i].var, "%li", strtol(s, NULL, 10)); } } /* * WRITE P5\r * READ #\r */ if (powpan_command("P5\r") > 0) { /* * Looking at the format of the commands "P\r" it seems likely * that this command exists also. Let's see if someone cares to * tell us if it does (should be visible when running with -DDDDD). */ } /* * WRITE P9\r * READ #\r */ if (powpan_command("P9\r") > 0) { /* * Looking at the format of the commands "P\r" it seems likely * that this command exists also. Let's see if someone cares to * tell us if it does (should be visible when running with -DDDDD). */ } /* * Cancel pending shutdown. * WRITE C\r * READ #0\r */ powpan_command("C\r"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); dstate_addcmd("shutdown.reboot"); } static ssize_t powpan_status(status_t *status) { ssize_t ret; ssize_t i; ssize_t valid = 0; int code = -1; char value[32]; ssize_t ofs = 0; char seen_i_freq = 0; memset(status, 0, sizeof(status_t)); /* * WRITE D\r * READ #I119.0O119.0L000B100T027F060.0S..\r * #I118.0O118.0L029B100F060.0R0218S..\r * #I118.1O118.1L13B100V27.5F60.0HF60.0R65Q1.4S\x80\x84\xc0\x88\x80W\r (CST135XLU) * 01234567890123456789012345678901234567890123 * 0 1 2 3 4 */ ret = powpan_command("D\r"); if (ret <= 0) return -1; if (powpan_answer[0] != '#') { upsdebugx(2, "Expected start character '#', but got '%c'", powpan_answer[0]); return -1; } for (i = 1; i <= ret; i++) { if (i == ret || isalpha((unsigned char)(powpan_answer[i]))) { value[ofs++] = '\0'; valid++; switch (code) { case 'I': status->i_volt = strtof(value, NULL); break; case 'O': status->o_volt = strtof(value, NULL); break; case 'L': status->o_load = strtol(value, NULL, 10); break; case 'B': status->b_chrg = strtol(value, NULL, 10); break; case 'V': status->b_volt = strtof(value, NULL); status->has_b_volt = 1; break; case 'T': status->u_temp = strtol(value, NULL, 10); status->has_u_temp = 1; break; case 'F': status->i_freq = strtof(value, NULL); seen_i_freq = 1; break; case 'H': status->o_freq = strtof(value, NULL); status->has_o_freq = 1; break; case 'R': status->runtime = strtol(value, NULL, 10); status->has_runtime = 1; break; case 'S': memcpy(&status->flags, value, 2); break; default: /* We didn't really find valid data */ valid--; break; } code = powpan_answer[i]; ofs = 0; /* * Depending on device/firmware, the output frequency is coded as * either an H, HF, or a second F (seen once transfered to battery) */ if (seen_i_freq && code == 'F') code = 'H'; continue; } value[ofs++] = powpan_answer[i]; } /* if we didn't get at least 3 values consider it a failure */ if (valid < 3) { upsdebugx(4, "Parsing status string failed"); return -1; } return 0; } static int powpan_updateinfo(void) { status_t status; if (powpan_status(&status)) { return -1; } dstate_setinfo("input.voltage", "%.1f", status.i_volt); dstate_setinfo("output.voltage", "%.1f", status.o_volt); dstate_setinfo("ups.load", "%d", status.o_load); dstate_setinfo("input.frequency", "%.1f", status.i_freq); if (status.has_u_temp) { dstate_setinfo("ups.temperature", "%d", status.u_temp); } dstate_setinfo("battery.charge", "%d", status.b_chrg); if (status.has_b_volt) { dstate_setinfo("battery.voltage", "%.1f", status.b_volt); if (status.b_volt > 20.0 && status.b_volt < 28.0) { dstate_setinfo("battery.voltage.nominal", "%f", 24.0); } } if (status.has_o_freq) { dstate_setinfo("output.frequency", "%.1f", status.o_freq); } if (status.has_runtime) { dstate_setinfo("battery.runtime", "%d", status.runtime*60); } status_init(); if (status.flags[0] & 0x40) { status_set("OB"); } else { status_set("OL"); } if (status.flags[0] & 0x20) { status_set("LB"); } /* !OB && !TEST */ if (!(status.flags[0] & 0x48)) { if (status.o_volt < 0.5 * status.i_volt) { upsdebugx(2, "%s: output voltage too low", __func__); } else if (status.o_volt < 0.95 * status.i_volt) { status_set("TRIM"); } else if (status.o_volt < 1.05 * status.i_volt) { /* ignore */ } else if (status.o_volt < 1.5 * status.i_volt) { status_set("BOOST"); } else { upsdebugx(2, "%s: output voltage too high", __func__); } } if (status.flags[0] & 0x08) { status_set("TEST"); } if (status.flags[0] == 0) { status_set("OFF"); } status_commit(); return (status.flags[0] & 0x40) ? 1 : 0; } static ssize_t powpan_initups(void) { ssize_t ret; int i; upsdebugx(1, "Trying text protocol..."); ser_set_speed(upsfd, device_path, B2400); /* This fails for many devices, so don't bother to complain */ powpan_command("\r\r"); for (i = 0; i < MAXTRIES; i++) { const char *val; /* * WRITE P4\r * READ #BC1200 ,1.600,000000000000,CYBER POWER * #CST135XLU,BF01403AAH2,CR7EV2002320,CyberPower Systems Inc.,,, * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ ret = powpan_command("P4\r"); if (ret < 1) { continue; } if (ret < 46) { upsdebugx(2, "Expected 46 bytes, but only got %" PRIiSIZE, ret); continue; } if (powpan_answer[0] != '#') { upsdebugx(2, "Expected start character '#', but got '%c'", powpan_answer[0]); continue; } val = getval("ondelay"); if (val) { ondelay = strtol(val, NULL, 10); } if ((ondelay < 0) || (ondelay > 9999)) { fatalx(EXIT_FAILURE, "Start delay '%ld' out of range [0..9999]", ondelay); } val = getval("offdelay"); if (val) { offdelay = strtol(val, NULL, 10); } if ((offdelay < 6) || (offdelay > 600)) { fatalx(EXIT_FAILURE, "Shutdown delay '%ld' out of range [6..600]", offdelay); } /* Truncate to nearest setable value */ if (offdelay < 60) { offdelay -= (offdelay % 6); } else { offdelay -= (offdelay % 60); } return ret; } return -1; } subdriver_t powpan_text = { "text", POWERPANEL_TEXT_VERSION, powpan_instcmd, powpan_setvar, powpan_initups, powpan_initinfo, powpan_updateinfo }; nut-2.8.4/drivers/hidparser.c0000664000175000017500000006163015000733203013060 00000000000000/* * hidparser.c: HID Parser * * This file is part of the MGE UPS SYSTEMS HID Parser * * Copyright (C) * 1998-2003 MGE UPS SYSTEMS, Luc Descotils * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * -------------------------------------------------------------------------- */ #include "config.h" /* must be first */ #include #include #include "hidparser.h" #include "nut_stdint.h" /* for int8_t, int16_t, int32_t */ #include "common.h" /* for fatalx() */ static const uint8_t ItemSize[4] = { 0, 1, 2, 4 }; /* * HIDParser struct * -------------------------------------------------------------------------- */ /* FIXME? Should this structure remain with reasonable fixed int types, * or changed to align with libusb API version and usb_ctrl_* typedefs? */ typedef struct { const unsigned char *ReportDesc; /* Report Descriptor */ size_t ReportDescSize; /* Size of Report Descriptor */ uint16_t Pos; /* Store current pos in descriptor */ uint8_t Item; /* Store current Item */ uint32_t Value; /* Store current Value */ HIDData_t Data; /* Store current environment */ uint8_t OffsetTab[MAX_REPORT][4]; /* Store ID, Type, offset & timestamp of report */ uint8_t ReportCount; /* Store Report Count */ uint8_t Count; /* Store local report count */ uint16_t UPage; /* Global UPage */ HIDNode_t UsageTab[USAGE_TAB_SIZE]; /* Usage stack */ uint8_t UsageSize; /* Design number of usage used */ } HIDParser_t; /* return 1 + the position of the leftmost "1" bit of an int, or 0 if none. */ static inline unsigned int hibit(unsigned long x) { unsigned int res = 0; while (x > 0xff) { x >>= 8; res += 8; } while (x) { x >>= 1; res += 1; } return res; } /* Note: The USB HID specification states that Local items do not carry over to the next Main item (version 1.11, section 6.2.2.8). Therefore the local state must be reset after each main item. In particular, any unused usages on the Usage tabs must be discarded and must not carry over to the next Main item. Some APC equipment actually sends multiple redundant "usage" commands for a single control, so resetting the local state is important. */ /* Also note: UsageTab[0] is used as the usage of the next control, even if UsageSize=0. Therefore, this must be initialized */ static void ResetLocalState(HIDParser_t* pParser) { pParser->UsageSize = 0; memset(pParser->UsageTab, 0, sizeof(pParser->UsageTab)); } /* * GetReportOffset * * Return pointer on current offset value for Report designed by * ReportID/ReportType * -------------------------------------------------------------------------- */ static uint8_t *GetReportOffset(HIDParser_t* pParser, const uint8_t ReportID, const uint8_t ReportType) { int Pos; for (Pos = 0; Pos < MAX_REPORT; Pos++) { if (pParser->OffsetTab[Pos][0] == 0) { pParser->OffsetTab[Pos][0] = ReportID; pParser->OffsetTab[Pos][1] = ReportType; pParser->OffsetTab[Pos][2] = 0; } if (pParser->OffsetTab[Pos][0] != ReportID) { continue; } if (pParser->OffsetTab[Pos][1] != ReportType) { continue; } return &pParser->OffsetTab[Pos][2]; } return NULL; } /* * FormatValue(uint32_t Value, uint8_t Size) * Format Value to fit with long format with respect of negative values * -------------------------------------------------------------------------- */ static long FormatValue(uint32_t Value, uint8_t Size) { switch(Size) { case 1: return (long)(int8_t)Value; case 2: return (long)(int16_t)Value; case 4: return (long)(int32_t)Value; default: return (long)Value; } } /* * HIDParse(HIDParser_t* pParser, HIDData_t *pData) * * Analyse Report descriptor stored in HIDParser struct and store local and * global context. * Return in pData the last object found. * Return -1 when there is no other Item to parse, 1 if a new object was found * or 0 if a continuation of a previous object was found. * -------------------------------------------------------------------------- */ static int HIDParse(HIDParser_t *pParser, HIDData_t *pData) { int Found = -1, i; while ((Found < 0) && (pParser->Pos < pParser->ReportDescSize)) { /* Get new pParser->Item if current pParser->Count is empty */ if (pParser->Count == 0) { pParser->Item = pParser->ReportDesc[pParser->Pos++]; pParser->Value = 0; for (i = 0; i < ItemSize[pParser->Item & SIZE_MASK]; i++) { pParser->Value += (uint32_t)(pParser->ReportDesc[(pParser->Pos)+i]) << (8*i); } /* Pos on next item */ pParser->Pos += ItemSize[pParser->Item & SIZE_MASK]; } switch (pParser->Item & ITEM_MASK) { case ITEM_UPAGE: /* Copy UPage in Usage stack */ pParser->UPage=(uint16_t)pParser->Value; break; case ITEM_USAGE: /* Copy global or local UPage if any, in Usage stack */ if ((pParser->Item & SIZE_MASK) > 2) { pParser->UsageTab[pParser->UsageSize] = pParser->Value; } else { pParser->UsageTab[pParser->UsageSize] = ((HIDNode_t)(pParser->UPage) << 16) | (pParser->Value & 0xFFFF); } /* Increment Usage stack size */ pParser->UsageSize++; break; case ITEM_COLLECTION: /* Get UPage/Usage from UsageTab and store them in pParser->Data.Path */ pParser->Data.Path.Node[pParser->Data.Path.Size] = pParser->UsageTab[0]; pParser->Data.Path.Size++; /* Unstack UPage/Usage from UsageTab (never remove the last) */ if (pParser->UsageSize > 0) { int j; for (j = 0; j < pParser->UsageSize; j++) { pParser->UsageTab[j] = pParser->UsageTab[j+1]; } /* Remove Usage */ pParser->UsageSize--; } /* Get Index if any */ if (pParser->Value >= 0x80) { pParser->Data.Path.Node[pParser->Data.Path.Size] = 0x00ff0000 | (pParser->Value & 0x7F); pParser->Data.Path.Size++; } ResetLocalState(pParser); break; case ITEM_END_COLLECTION : pParser->Data.Path.Size--; /* Remove Index if any */ if((pParser->Data.Path.Node[pParser->Data.Path.Size] & 0xffff0000) == 0x00ff0000) { pParser->Data.Path.Size--; } ResetLocalState(pParser); break; case ITEM_FEATURE: case ITEM_INPUT: case ITEM_OUTPUT: if (pParser->UsageTab[0] != 0x00000000) { /* An object was found if the path does not end with 0x00000000 */ Found = 1; } else { /* It is a continuation of a previous object */ Found = 0; } /* Get new pParser->Count from global value */ if(pParser->Count == 0) { pParser->Count = pParser->ReportCount; } /* Get UPage/Usage from UsageTab and store them in pParser->Data.Path */ pParser->Data.Path.Node[pParser->Data.Path.Size] = pParser->UsageTab[0]; pParser->Data.Path.Size++; /* Unstack UPage/Usage from UsageTab (never remove the last) */ if(pParser->UsageSize > 0) { int j; for (j = 0; j < pParser->UsageSize; j++) { pParser->UsageTab[j] = pParser->UsageTab[j+1]; } /* Remove Usage */ pParser->UsageSize--; } /* Copy data type */ pParser->Data.Type = (uint8_t)(pParser->Item & ITEM_MASK); /* Copy data attribute */ pParser->Data.Attribute = (uint8_t)pParser->Value; /* Store offset */ pParser->Data.Offset = *GetReportOffset(pParser, pParser->Data.ReportID, (uint8_t)(pParser->Item & ITEM_MASK)); /* Get Object in pData */ /* -------------------------------------------------------------------------- */ memcpy(pData, &pParser->Data, sizeof(HIDData_t)); /* -------------------------------------------------------------------------- */ /* Increment Report Offset */ *GetReportOffset(pParser, pParser->Data.ReportID, (uint8_t)(pParser->Item & ITEM_MASK)) += pParser->Data.Size; /* Remove path last node */ pParser->Data.Path.Size--; /* Decrement count */ pParser->Count--; if (pParser->Count == 0) { ResetLocalState(pParser); } break; case ITEM_REP_ID : pParser->Data.ReportID = (uint8_t)pParser->Value; break; case ITEM_REP_SIZE : pParser->Data.Size = (uint8_t)pParser->Value; break; case ITEM_REP_COUNT : pParser->ReportCount = (uint8_t)pParser->Value; break; case ITEM_UNIT_EXP : pParser->Data.UnitExp = (int8_t)pParser->Value; if (pParser->Data.UnitExp > 7) { pParser->Data.UnitExp |= 0xF0; } break; case ITEM_UNIT : /* TOTHINK: Are there cases where Unit is not-signed, * but a Value too big becomes signed after casting -- * and unintentionally so? */ pParser->Data.Unit = (long)pParser->Value; break; case ITEM_LOG_MIN : pParser->Data.LogMin = FormatValue(pParser->Value, ItemSize[pParser->Item & SIZE_MASK]); break; case ITEM_LOG_MAX : pParser->Data.LogMax = FormatValue(pParser->Value, ItemSize[pParser->Item & SIZE_MASK]); /* HACK: If treating the value as signed (FormatValue(...)) * results in a LogMax that is less than the LogMin * value then it is likely that the LogMax value has * been incorrectly encoded by the UPS firmware * (field was too short and overflowed into sign bit). * In that case, reinterpret it as an unsigned number * and log the problem. See also *_fix_report_desc() * methods that follow up in some *-hid.c subdrivers. * This hack is not correct in the sense that it only * looks at the LogMin value for this item, whereas * the HID spec says that Logical values persist in * global state. * Note the values MAY be signed or unsigned, according * to rules and circumstances explored below. * * RATIONALE: per discussions such as: * * https://github.com/networkupstools/nut/issues/1512#issuecomment-1238310056 * The encoding of small integers in the logical/physical * min/max fields (in fact, I think in anywhere they * encode integers) is independent of the size of * the (feature) field they end up referring to. * One should use the smallest size encoding * (0, 1, 2, or 4 bytes are the options) that can * represent, as a signed quantity, the value you * need to encode. See HID spec 1.11, sec 6.2.2.2 * "Short Items". Given a 16 bit report field, with * logical values 0..65535, it should use a 0 byte * encoding for the logical minimum (0x14, rather * than 0x15 0x00) and a 4-byte encoding for the * logical maximum (0x27 0xFF 0xFF 0x00 0x00). * Their encoding choice does suggest you cannot * have an unsigned 32-bit report item with logical * maximum >2147483647 (unless you assume, as I did, * that "if max < min" then it's just a bad encoding * of a positive number that ran into the sign bit). * * https://github.com/networkupstools/nut/pull/2718#issuecomment-2547021458 * This is what the spec says (page labelled 19 of * hid1_11.pdf, physical page 29 of 97) -- * 5.8 Format of Multibyte Numeric Values * Multibyte numeric values in reports are * represented in little-endian format, with the * least significant byte at the lowest address. * The Logical Minimum and Logical Maximum values * identify the range of values that will be found * in a report. * If Logical Minimum and Logical Maximum are * both positive values then a sign bit is * unnecessary in the report field and the * contents of a field can be assumed to * be an unsigned value. * Otherwise, all integer values are signed * values represented in 2's complement format. * Floating point values are not allowed. * * https://github.com/networkupstools/nut/pull/2718#issuecomment-2547065141 * The number of bytes in the encoding of the * LogMin and LogMax fields is only loosely tied * to the "Size" of the field that they are * describing -- but the implementers on the * UPS side don't seem to quite get that. * It's all starting to come back to me... * If you're trying to describe a report field * that is 16-bits and has (unsigned) values * from 0..65535 range, then you SHOULD have * a LogMin field containing value 0, and * a LogMax field that contains value 65535. * Since all numeric fields are interpreted as * signed "two's-complement" values (except for * that note above about the *report values*, * NOT the values in the report description), to * encode such a LogMax field you would have to * express the *LogMax field* in a 4-byte encoding * in the *report description*. * That's independent of the ultimate 2-byte * *report value* that these LogMin and LogMax * are describing. * We suppose that some coder at the UPS company * took a shortcut, and set not only "LogMin = 0", * but also effectively "LogMax = -1" (because they * used a 2-byte encoding with all bits set, not a * 4-byte encoding), and then NUT is left to decide * what they actually intended. * My interpretation of that is that they're trying * to say e.g. 0..65535, because if they had meant * 0..32767 they would have just written that (as * 0..7FFF which fits in the signed 2-byte repr.), * but unless they're actually trying to represent * e.g. voltages over 327 V, deciding that the * limit is a signed 32767 should also be fine. * * ...and maybe some in other tickets * * TL;DR: there is likely a mis-understanding * of the USB spec by firmware developers. */ if (pParser->Data.LogMax < pParser->Data.LogMin) { upslogx(LOG_WARNING, "%s: LogMax is less than LogMin. " "Vendor HID report descriptor may be incorrect; " "interpreting LogMax %ld as %u in ReportID: 0x%02x", __func__, pParser->Data.LogMax, pParser->Value, pParser->Data.ReportID); pParser->Data.assumed_LogMax = true; pParser->Data.LogMax = (long) pParser->Value; } break; case ITEM_PHY_MIN : pParser->Data.PhyMin=FormatValue(pParser->Value, ItemSize[pParser->Item & SIZE_MASK]); pParser->Data.have_PhyMin = 1; break; case ITEM_PHY_MAX : pParser->Data.PhyMax=FormatValue(pParser->Value, ItemSize[pParser->Item & SIZE_MASK]); pParser->Data.have_PhyMax = 1; break; case ITEM_LONG : /* can't handle long items, but should at least skip them */ pParser->Pos += (uint8_t)(pParser->Value & 0xff); break; default: break; } } /* while ((Found < 0) && (pParser->Pos < pParser->ReportDescSize)) */ if(pParser->Data.Path.Size >= PATH_SIZE) upslogx(LOG_ERR, "%s: HID path too long", __func__); if(pParser->ReportDescSize >= REPORT_DSC_SIZE) upslogx(LOG_ERR, "%s: Report descriptor too big", __func__); if(pParser->UsageSize >= USAGE_TAB_SIZE) upslogx(LOG_ERR, "%s: HID Usage too high", __func__); /* FIXME: comparison is always false due to limited range of data type [-Werror=type-limits] * with ReportID being uint8_t and MAX_REPORT being 500 currently */ /* if(pParser->Data.ReportID >= MAX_REPORT) upslogx(LOG_ERR, "%s: Too many HID reports", __func__); */ return Found; } /* * FindObject * Get pData characteristics from pData->Path * Return TRUE if object was found * -------------------------------------------------------------------------- */ int FindObject(HIDDesc_t *pDesc_arg, HIDData_t *pData) { HIDData_t *pFoundData = FindObject_with_Path(pDesc_arg, &pData->Path, pData->Type); if (!pFoundData) { return 0; } memcpy(pData, pFoundData, sizeof(*pData)); return 1; } /* * FindObject_with_Path * Get pData item with given Path and Type. Return NULL if not found. * -------------------------------------------------------------------------- */ HIDData_t *FindObject_with_Path(HIDDesc_t *pDesc_arg, HIDPath_t *Path, uint8_t Type) { size_t i; for (i = 0; i < pDesc_arg->nitems; i++) { HIDData_t *pData = &pDesc_arg->item[i]; if (pData->Type != Type) { continue; } if (memcmp(pData->Path.Node, Path->Node, (Path->Size) * sizeof(HIDNode_t))) { continue; } return pData; } return NULL; } /* * FindObject_with_ID * Get pData item with given ReportID, Offset, and Type. Return NULL * if not found. * -------------------------------------------------------------------------- */ HIDData_t *FindObject_with_ID(HIDDesc_t *pDesc_arg, uint8_t ReportID, uint8_t Offset, uint8_t Type) { size_t i; for (i = 0; i < pDesc_arg->nitems; i++) { HIDData_t *pData = &pDesc_arg->item[i]; if (pData->ReportID != ReportID) { continue; } if (pData->Type != Type) { continue; } if (pData->Offset != Offset) { continue; } return pData; } return NULL; } /* * FindObject_with_ID_Node * Get pData item with given ReportID and Node. Return NULL if not found. * -------------------------------------------------------------------------- */ HIDData_t *FindObject_with_ID_Node(HIDDesc_t *pDesc_arg, uint8_t ReportID, HIDNode_t Node) { size_t i; for (i = 0; i < pDesc_arg->nitems; i++) { HIDData_t *pData = &pDesc_arg->item[i]; HIDPath_t *pPath; uint8_t size; if (pData->ReportID != ReportID) { continue; } pPath = &pData->Path; size = pPath->Size; if (size == 0 || pPath->Node[size-1] != Node) { continue; } return pData; } return NULL; } /* * GetValue * Extract data from a report stored in Buf. * Use Offset, Size, LogMin, and LogMax of pData. * Return response in *pValue. * -------------------------------------------------------------------------- */ void GetValue(const unsigned char *Buf, HIDData_t *pData, long *pValue) { /* Note: https://github.com/networkupstools/nut/issues/1023 This conversion code can easily be sensitive to 32- vs. 64- bit compilation environments. Consider the possibility of overflow in 32-bit representations when computing with extreme values, for example LogMax-LogMin+1. Test carefully in both environments if changing any declarations. */ int Weight, Bit; unsigned long mask, signbit, magMax, magMin; long value = 0; Bit = pData->Offset + 8; /* First byte of report is report ID */ for (Weight = 0; Weight < pData->Size; Weight++, Bit++) { int State = Buf[Bit >> 3] & (1 << (Bit & 7)); if(State) { value += (1L << Weight); } } /* translate Value into a signed/unsigned value in the range LogMin..LogMax, as appropriate. See HID spec, p.38: "If both the Logical Minimum and Logical Maximum extents are defined as positive values (0 or greater), then the report field can be assumed to be an unsigned value. Otherwise, all integer values are signed values represented in 2's complement format." Also note that the variable can take values from LogMin (inclusive) to LogMax (inclusive), so there are LogMax - LogMin + 1 possible values. Special cases arise if the value that has been read lies outside the interval LogMin..LogMax. Some devices, notably the APC Back-UPS BF500, do this. In one case I observed, LogMin=0, LogMax=0xffff, Size=32, and the supplied value is 0xffffffff80080a00. Presumably they expect us to throw away the higher-order bits, and use 0x0a00, rather than choosing the closest value in the interval, which would be 0xffff. However, if LogMax - LogMin + 1 isn't a power of 2, it is not clear what "throwing away higher-order bits" exacly means, so we try to do something sensible. -PS */ /* determine representation without sign bit */ magMax = pData->LogMax >= 0 ? (unsigned long)(pData->LogMax) : (unsigned long)(-(pData->LogMax + 1)); magMin = pData->LogMin >= 0 ? (unsigned long)(pData->LogMin) : (unsigned long)(-(pData->LogMin + 1)); /* calculate where the sign bit will be if needed */ signbit = 1L << hibit(magMax > magMin ? magMax : magMin); /* but only include sign bit in mask if negative numbers are involved */ mask = (signbit - 1) | ((pData->LogMin < 0) ? signbit : 0); /* throw away excess high order bits (which may contain garbage) */ value = (long)((unsigned long)(value) & mask); /* sign-extend it, if appropriate */ if (pData->LogMin < 0 && ((unsigned long)(value) & signbit) != 0) { value |= ~mask; } /* clamp returned value to range [LogMin..LogMax] */ if (value < pData->LogMin) { value = pData->LogMin; } else if (value > pData->LogMax) { value = pData->LogMax; } *pValue = value; return; } /* * SetValue * Set a data in a report stored in Buf. Use Value, Offset and Size of pData. * Return response in Buf. * -------------------------------------------------------------------------- */ void SetValue(const HIDData_t *pData, unsigned char *Buf, long Value) { int Weight, Bit; Bit = pData->Offset + 8; /* First byte of report is report ID */ for (Weight = 0; Weight < pData->Size; Weight++, Bit++) { long State = Value & (1L << Weight); if (State) { Buf[Bit >> 3] |= (1 << (Bit & 7)); } else { Buf[Bit >> 3] &= ~(1 << (Bit & 7)); } } } /* ---------------------------------------------------------------------- */ /* parse HID Report Descriptor. Input: byte array ReportDesc[n]. Output: parsed data structure. Returns allocated HIDDesc structure on success, NULL on failure with errno set. Note: the value returned by this function must be freed with Free_ReportDesc(). */ HIDDesc_t *Parse_ReportDesc(const usb_ctrl_charbuf ReportDesc, const usb_ctrl_charbufsize n) { int ret = 0; HIDDesc_t *pDesc_var; HIDParser_t *parser; pDesc_var = calloc(1, sizeof(*pDesc_var)); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if (!pDesc_var || n < 0 || (uintmax_t)n > SIZE_MAX ) { return NULL; } #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif pDesc_var->item = calloc(MAX_REPORT, sizeof(*pDesc_var->item)); if (!pDesc_var->item) { Free_ReportDesc(pDesc_var); return NULL; } parser = calloc(1, sizeof(*parser)); if (!parser) { Free_ReportDesc(pDesc_var); return NULL; } parser->ReportDesc = (const unsigned char *)ReportDesc; parser->ReportDescSize = (const size_t)n; for (pDesc_var->nitems = 0; pDesc_var->nitems < MAX_REPORT; pDesc_var->nitems += (size_t)ret) { uint8_t id; size_t max; ret = HIDParse(parser, &pDesc_var->item[pDesc_var->nitems]); if (ret < 0) { break; } id = pDesc_var->item[pDesc_var->nitems].ReportID; /* calculate bit range of this item within report */ max = pDesc_var->item[pDesc_var->nitems].Offset + pDesc_var->item[pDesc_var->nitems].Size; /* convert to bytes */ max = (max + 7) >> 3; /* update report length */ if (max > pDesc_var->replen[id]) { pDesc_var->replen[id] = max; } } /* Sanity check: are there remaining HID objects that can't * be processed? */ if ((pDesc_var->nitems == MAX_REPORT) && (parser->Pos < parser->ReportDescSize)) upslogx(LOG_ERR, "ERROR in %s: Too many HID objects", __func__); free(parser); if (pDesc_var->nitems == 0) { Free_ReportDesc(pDesc_var); return NULL; } pDesc_var->item = realloc(pDesc_var->item, pDesc_var->nitems * sizeof(*pDesc_var->item)); return pDesc_var; } /* free a parsed report descriptor, as allocated by Parse_ReportDesc() */ void Free_ReportDesc(HIDDesc_t *pDesc_arg) { if (!pDesc_arg) { return; } free(pDesc_arg->item); free(pDesc_arg); } nut-2.8.4/drivers/hpe-pdu-mib.h0000644000175000017500000000206714670526611013227 00000000000000/* hpe-pdu-mib.h - subdriver to monitor HPE ePDU SNMP devices with NUT * * Copyright (C) * 2011 - 2016 Arnaud Quette * 2019 Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef HPE_EPDU_MIB_H #define HPE_EPDU_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t hpe_pdu; #endif /* HPE_EPDU_MIB_H */ nut-2.8.4/drivers/bestfortress.c0000644000175000017500000004216015044656702013637 00000000000000/* bestfortress.c - model specific routines for (very) old Best Power Fortress Copyright (C) 2002 Russell Kroll (skeleton) (C) 2002 Holger Dietze (C) 2009 Stuart D. Gathman This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "main.h" #include "serial.h" #include "nut_stdint.h" #define UPSDELAY 50000 /* 50 ms delay required for reliable operation */ #define SER_WAIT_SEC 2 /* allow 2.0 sec for ser_get calls */ #define SER_WAIT_USEC 0 #define ENDCHAR '\r' #define IGNCHARS " \n" #if defined(__sgi) && ! defined(__GNUC__) #define inline __inline #endif #define DRIVER_NAME "Best Fortress UPS driver" #define DRIVER_VERSION "0.13" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Holger Dietze \n" "Stuart D. Gathman \n", DRV_EXPERIMENTAL, { NULL } }; /* * Choose 20s for off delay, reading the tea leaves from other drivers. */ static const char *shutdown_delay = "20"; /* * Logging plan: * CRIT: executing poweroff * ERR: indicates a bug in nut * WARNING: indicates a serious misconfiguration that will cause nut * to fail to function * NOTICE: rare situations without a planned reporting path (none so * far) * INFO: One message each for startup, first establishment of comms * DEBUG: Loss/restore of comms, and perhaps things that are normally * reported via other daemons (on battery, low battery) * D1: Things that happen rarely (startup/shutdown, param set, instant * commands) * D2: ? * D3: trace of communications * D4: more io than necessary to see working communications * D5: log even succesful acks */ static int instcmd (const char *cmdname, const char *extra); static int upsdrv_setvar (const char *varname, const char *val); /* Rated maximum VA output as configured by the user. */ static int maxload = 0; /* * NB: Not called for shutdown. */ void upsdrv_initinfo(void) { dstate_setinfo("ups.mfr", "Best Power"); dstate_setinfo("ups.model", "Fortress"); dstate_setinfo("battery.voltage.nominal", "24"); /*dstate_setinfo ("alarm.overload", "0");*/ /* Flag */ /*dstate_setinfo ("alarm.temp", "0");*/ /* Flag */ if (maxload) dstate_setinfo("ups.load", "0"); dstate_setinfo("output.voltamps", "0"); /* tunable via front panel: (european voltage level) parameter factory default range INFO_LOWXFER 196 V p7=nnn 160-210 INFO_HIGHXFER 254 V p8=nnn 215-274 INFO_LOBATTIME 2 min p2=n 1-5 comm mode p6=0 dumb DONT USE (will lose access to parameter setting!) p6=1 B1200 p6=2 B2400 P6=3 B4800 p6=4 B9600 maybe cycle through speeds to autodetect? echo off e0 echo on e1 */ dstate_setinfo("input.transfer.low", "%s", ""); dstate_setflags("input.transfer.low", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("input.transfer.low", 3); dstate_setinfo("input.transfer.high", "%s", ""); dstate_setflags("input.transfer.high", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("input.transfer.high", 3); dstate_setinfo("battery.runtime.low", "%s", ""); dstate_setflags("battery.runtime.low", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("battery.runtime.low", 3); upsh.instcmd = instcmd; upsh.setvar = upsdrv_setvar; dstate_addcmd("shutdown.return"); dstate_addcmd("load.off"); } /* convert hex digit to int */ static inline int fromhex (char c) { return (c >= '0' && c <= '9') ? c - '0' : (c >= 'A' && c <= 'F') ? c - 'A' + 10 : (c >= 'a' && c <= 'f') ? c - 'a' + 10 : 0; } /* do checksumming on UPS response */ static int checksum (char * s) { int i; int sum; for (i = 40, sum = 0; s[0] && s[1] && i > 0; i--, s += 2) { sum += (fromhex (s[0]) << 4) + fromhex (s[1]); } return sum; } /* set info to integer value */ static inline int setinfo_int (const char *key, const char * s, size_t len) { char buf[10]; int val; if (len > sizeof(buf)) len = sizeof(buf)-1; strncpy (buf, s, len); buf[len] = 0; val = atoi(buf); dstate_setinfo (key, "%d", val); return val; } /* set info to integer value (for runtime remaining) value is expressed in minutes, but desired in seconds */ static inline void setinfo_int_minutes (const char *key, const char * s, size_t len) { char buf[10]; if (len > sizeof(buf)) len = sizeof(buf)-1; strncpy (buf, s, len); buf[len] = 0; dstate_setinfo (key, "%d", 60*atoi (buf)); } /* set info to float value */ static inline void setinfo_float (const char *key, const char * fmt, const char * s, size_t len, double factor) { char buf[10]; if (len > sizeof(buf)) len = sizeof(buf)-1; strncpy (buf, s, len); buf[len] = 0; dstate_setinfo_dynamic (key, fmt, "%f", factor * (double)(atoi (buf))); } static int upssend(const char *fmt,...) { int ret; char buf[1024], *p; va_list ap; unsigned int sent = 0; useconds_t d_usec = UPSDELAY; va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used locally with * fixed strings (and args) */ ret = vsnprintf(buf, sizeof(buf), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); /* Why do we not upsflushin here? */ upsdebugx(3, "%s: sending %d bytes <%s>", __func__, ret, buf); if ((ret < 1) || (ret >= (int) sizeof(buf))) upslogx(LOG_ERR, "%s: vsnprintf needed more than %d bytes", __func__, (int) sizeof(buf)); for (p = buf; *p && sent < INT_MAX - 1; p++) { #ifndef WIN32 if (write(upsfd, p, 1) != 1) #else /* WIN32 */ DWORD bytes_written; BOOL res; res = WriteFile(upsfd, p, 1, &bytes_written,NULL); if (res == 0 || bytes_written == 0) #endif /* WIN32 */ return -1; /* Note: LGTM.com analysis warns that here * "Comparison is always true because d_usec >= 2" * since we initialize with UPSDELAY above. * Do not remove this check just in case that * initialization changes, or run-time value * becomes modified, in later iterations. */ if (d_usec > 0) usleep(d_usec); sent++; if (sent >= INT_MAX) { upslogx(LOG_ERR, "%s: sent >= INT_MAX, aborting", __func__); } } if (ret != (int) sent) { upsdebugx(1, "%s: ret %d != sent %u", __func__, ret, sent); } return (int)sent; } static ssize_t upsrecv(char *buf,size_t bufsize,char ec,const char *ic) { ssize_t nread; nread = ser_get_line(upsfd, buf, bufsize - 1, ec, ic, SER_WAIT_SEC, SER_WAIT_USEC); /* \todo is buf null terminated? */ upsdebugx(4, "%s: read %" PRIiSIZE " <%s>", __func__, nread, buf); return nread; } static ssize_t upsflushin(int f, int verbose, const char *ignset) { NUT_UNUSED_VARIABLE(f); upsdebugx(4, "%s: begin", __func__); return ser_flush_in(upsfd, ignset, verbose); } /* read out UPS and store info */ void upsdrv_updateinfo(void) { char temp[256]; char *p = NULL; int loadva; size_t len = 0; ssize_t recv; int retry; char ch; int checksum_ok = -1, is_online = 1, is_off, low_batt, trimming, boosting; upsdebugx(2, "%s: begin", __func__); for (retry = 0; retry < 5; ++retry) { upsflushin (0, 0, "\r "); upssend ("f\r"); while (ser_get_char(upsfd, &ch, 0, UPSDELAY) > 0 && ch != '\n'); /* response starts with \r\n */ temp[2] = 0; do { if ((recv = upsrecv (temp+2, sizeof temp - 2, ENDCHAR, IGNCHARS)) <= 0) { upsdebugx(1, "%s: upsrecv failed, " "retrying without counting", __func__); upsflushin (0, 0, "\r "); upssend ("f\r"); while (ser_get_char(upsfd, &ch, 0, UPSDELAY) > 0 && ch != '\n'); /* response starts with \r\n */ } } while (temp[2] == 0); upsdebugx(3, "%s: received %" PRIiSIZE " bytes (try %i)", __func__, recv, retry); /* syslog (LOG_DAEMON | LOG_NOTICE,"ups: got %d chars '%s'\n", recv, temp + 2); */ /* status example: 000000000001000000000000012201210000001200014500000280600000990025000000000301BE 000000000001000000000000012401230000001200014800000280600000990025000000000301B7 |Vi||Vo| |Io||Psou| |Vb||f| |tr||Ti| CS 000000000001000000000000023802370000000200004700000267500000990030000000000301BD 1 1 2 2 3 3 4 4 5 5 6 6 7 7 78 0 5 0 5 0 5 0 5 0 5 0 5 0 5 0 5 90 */ /* last bytes are a checksum: interpret response as hex string, sum of all bytes must be zero */ checksum_ok = ( (checksum (temp+2) & 0xff) == 0 ); /* setinfo (INFO_, ""); */ if (!checksum_ok) { upsdebug_hex(5, "upsdrv_updateinfo: " "checksum failure buffer hex", temp, (size_t)recv); upsdebug_ascii(5, "upsdrv_updateinfo: " "checksum failure buffer ascii", temp, (size_t)recv); } /* I can't figure out why this is missing the first two chars. But the first two chars are not used, so just set them to zero when missing. */ len = strlen(temp+2); temp[0] = '0'; temp[1] = '0'; p = temp+2; if (len == 78) p = temp; else if (len != 80) checksum_ok = 0; if (checksum_ok) break; upsdebugx(1, "%s: failed to read status try %d", __func__, retry); sleep(SER_WAIT_SEC); } if (!p || len < 1 || checksum_ok < 0) { /* \todo: Analyze/fix code and rewrite message. */ upsdebugx(2, "%s: pointer to data not initialized after processing", __func__); dstate_datastale(); return; } if (!checksum_ok) { upsdebugx(2, "%s: checksum corruption", __func__); upsdebug_hex(3, "buffer", temp, (size_t)len); dstate_datastale(); return; } /* Log assuming ASCII which it 99% is. \todo Improve. */ upsdebugx(3, "%s: %s", __func__, p); setinfo_int ("input.voltage", p+24,4); setinfo_int ("output.voltage", p+28,4); setinfo_float ("battery.voltage", "%.1f", p+50,4, 0.1); setinfo_float ("output.current", "%.1f", p+36,4, 0.1); loadva = setinfo_int ("output.voltamps", p+40,6); if (maxload) dstate_setinfo ("ups.load", "%d", loadva * 100 / maxload); setinfo_float ("input.frequency", "%.1f", p+54,3, 0.1); setinfo_int_minutes ("battery.runtime", p+58,4); setinfo_int ("ups.temperature", p+62,4); is_online = p[17] == '0'; low_batt = fromhex(p[21]) & 8 || fromhex(p[20]) & 1; is_off = p[11] == '0'; trimming = p[33] == '1'; boosting = 0; /* FIXME, don't know which bit gets set (brownouts are very rare here and I can't simulate one) */ status_init(); if (low_batt) status_set("LB"); else if (trimming) status_set("TRIM"); else if (boosting) status_set("BOOST"); else status_set(is_online ? (is_off ? "OFF" : "OL") : "OB"); /* setinfo(INFO_STATUS, "%s%s", * (util < lownorm) ? "BOOST ", "", * (util > highnorm) ? "TRIM ", "", * ((flags & TIOCM_CD) == 0) ? "" : "LB ", * ((flags & TIOCM_CTS) == TIOCM_CTS) ? "OB" : "OL"); */ status_commit(); dstate_dataok(); } /* Parameter setting */ /* all UPS tunable parameters are set with command 'p%d=%s' */ static int setparam (int parameter, int dlen, const char * data) { char reply[80]; upsdebugx(2, "%s: begin", __func__); /* Note the use of "%*s" - parameter (int)dlen specifies * the string width reserved for data */ upssend ("p%d=%*s\r", parameter, dlen, data); if (upsrecv (reply, sizeof(reply), ENDCHAR, "") < 0) { upsdebugx(1, "%s: did not get reply", __func__); return 0; } if (strncmp (reply, "OK", 2) == 0) { upsdebugx(5, "%s: reply OK", __func__); return 1; } else { upsdebugx(1, "%s: reply NOT ok", __func__); return 0; } } /* ups_setsuper: set super-user access (allows setting variables) */ static void ups_setsuper (int super) { setparam (999, super ? 4 : 0, super ? "2639" : ""); } /* sets whether UPS will reapply power after it has shut down and line * power returns. */ static void autorestart (int restart) { ups_setsuper (1); setparam (1, 1, restart ? "1" : "0"); ups_setsuper (0); } /* set UPS parameters */ static int upsdrv_setvar (const char *var, const char * data) { int parameter; size_t len = strlen(data); upsdebug_SET_STARTING(var, data); upsdebugx(1, "%s: (%" PRIuSIZE " bytes)", __func__, len); if (strcmp("input.transfer.low", var) == 0) { parameter = 7; } else if (strcmp("input.transfer.high", var) == 0) { parameter = 8; } else if (strcmp("battery.runtime.low", var) == 0) { parameter = 2; } else { /* * \todo Figure out if we get here by a code error or * by the user asking for a variable that does not * exist. If the former, change to LOG_ERR and if the * latter change to LOG_DEBUG. */ upslog_SET_UNKNOWN(var, data); return STAT_SET_UNKNOWN; } ups_setsuper (1); assert (len < INT_MAX); if (setparam (parameter, (int)len, data)) { dstate_setinfo (var, "%*s", (int)len, data); } ups_setsuper (0); return STAT_SET_HANDLED; } /* * The "power down and maybe return command" is "OFF %d\r", with a * delay in seconds before poweroff. As a special case, "OFF 0" does * not shut down. The UPS will power on the load when power returns * (or after a delay if power is not out), according to the front panel * parameter, or the value set via `autorestart()`. */ /* * This is equivalent to the `shutdown.return` instant command, but * invoked with `-k`. * \todo Reduce duplication. */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = -1; upsdebugx(2, "%s: begin", __func__); ret = do_loop_shutdown_commands("shutdown.return", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); upsdebugx(2, "%s: end", __func__); } static int instcmd (const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "load.off")) { /* upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); */ upslogx(LOG_INSTCMD_POWERSTATE, "%s: %s: OFF/stayoff in 1s", __func__, cmdname); autorestart (0); upssend ("OFF1\r"); return STAT_INSTCMD_HANDLED; } else if (!strcasecmp(cmdname, "shutdown.return")) { const char *grace; upsdebugx(2, "%s: %s: start", __func__, cmdname); grace = dstate_getinfo("ups.delay.shutdown"); if (!grace) { upsdebugx(1, "%s: ups.delay.shutdown is NULL!", __func__); /* Pick a different value than 20 so we can see it in the logs. */ grace = "30"; } /* upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); */ upslogx(LOG_INSTCMD_POWERSTATE, "%s: OFF/restart in %s seconds", __func__, grace); /* Start again, overriding front panel setting. */ autorestart (1); upssend ("OFF%s\r", grace); /* I'm nearly dead, Jim */ upsdebugx(2, "%s: %s: end", __func__, cmdname); return STAT_INSTCMD_HANDLED; } /* \todo Software error or user error? */ upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { addvar (VAR_VALUE, "baudrate", "serial line speed"); addvar (VAR_VALUE, "max_load", "rated VA load VA"); } static struct { const char * val; speed_t speed; } speed_table[] = { {"1200", B1200}, {"2400", B2400}, {"4800", B4800}, {"9600", B9600}, {NULL, B1200}, }; /* * Called first, for normal operation and for shutdown. */ void upsdrv_initups(void) { speed_t speed = B1200; char * speed_val = getval("baudrate"); char * max_load = getval("max_load"); upsdebugx(1, "%s: begin", __func__); if (max_load) maxload = atoi(max_load); if (speed_val) { int i; for (i=0; speed_table[i].val; i++) { if (strcmp (speed_val, speed_table[i].val) == 0) break; } speed = speed_table[i].speed; } upsfd = ser_open(device_path); if (INVALID_FD(upsfd)) { upslogx(LOG_WARNING, "%s: failed to open %s", __func__, device_path); /* \todo: Deal with the failure */ } /* ser_set_speed returns int 0 always; fatal if ioctl fails */ ser_set_speed(upsfd, device_path, speed); upsdebugx(1, "%s: opened %s speed %s upsfd %d", __func__, device_path, speed_val ? speed_val : "DEFAULT", upsfd); /* Set early so that it is in place for shutdown. */ dstate_setinfo("ups.delay.shutdown", "%s", shutdown_delay); upsdebugx(1, "%s: end", __func__); } void upsdrv_cleanup(void) { upsdebugx(1, "%s: begin/end", __func__); } nut-2.8.4/drivers/eaton-ups-pxg-mib.c0000644000175000017500000012170515000601404014346 00000000000000/* eaton-ups-pxg-mib.c - data to monitor Eaton / Powerware PXG UPS with NUT * (using MIBs described in stdupsv1.mib and Xups.mib) * Previously known as powerware-mib.c for "pw" mapping, * later split into several subdrivers * * Copyright (C) * 2005-2006 Olli Savia * 2005-2006 Niels Baggesen * 2015-2022 Eaton (author: Arnaud Quette ) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "eaton-ups-pxg-mib.h" #if WITH_SNMP_LKP_FUN /* FIXME: shared helper code, need to be put in common */ #include "eaton-pdu-marlin-helpers.h" #endif #define EATON_PXG_MIB_VERSION "0.105" /* Powerware UPS newer PXGX UPS cards (BladeUPS, ...) */ #define EATON_PXGX_SYSOID ".1.3.6.1.4.1.534.2.12" /* SNMP OIDs set */ #define PW_OID_MFR_NAME "1.3.6.1.4.1.534.1.1.1.0" /* XUPS-MIB::xupsIdentManufacturer.0 */ #define PW_OID_MODEL_NAME "1.3.6.1.4.1.534.1.1.2.0" /* XUPS-MIB::xupsIdentModel.0 */ #define PW_OID_FIRMREV "1.3.6.1.4.1.534.1.1.3.0" /* XUPS-MIB::xupsIdentSoftwareVersion.0 */ #define PW_OID_BATT_RUNTIME "1.3.6.1.4.1.534.1.2.1.0" /* XUPS-MIB::xupsBatTimeRemaining.0 */ #define PW_OID_BATT_VOLTAGE "1.3.6.1.4.1.534.1.2.2.0" /* XUPS-MIB::xupsBatVoltage.0 */ #define PW_OID_BATT_CURRENT "1.3.6.1.4.1.534.1.2.3.0" /* XUPS-MIB::xupsBatCurrent.0 */ #define PW_OID_BATT_CHARGE "1.3.6.1.4.1.534.1.2.4.0" /* XUPS-MIB::xupsBatCapacity.0 */ #define PW_OID_BATT_STATUS "1.3.6.1.4.1.534.1.2.5.0" /* XUPS-MIB::xupsBatteryAbmStatus.0 */ #define PW_OID_IN_FREQUENCY "1.3.6.1.4.1.534.1.3.1.0" /* XUPS-MIB::xupsInputFrequency.0 */ #define PW_OID_IN_LINE_BADS "1.3.6.1.4.1.534.1.3.2.0" /* XUPS-MIB::xupsInputLineBads.0 */ #define PW_OID_IN_LINES "1.3.6.1.4.1.534.1.3.3.0" /* XUPS-MIB::xupsInputNumPhases.0 */ #define PW_OID_IN_VOLTAGE "1.3.6.1.4.1.534.1.3.4.1.2" /* XUPS-MIB::xupsInputVoltage */ #define PW_OID_IN_CURRENT "1.3.6.1.4.1.534.1.3.4.1.3" /* XUPS-MIB::xupsInputCurrent */ #define PW_OID_IN_POWER "1.3.6.1.4.1.534.1.3.4.1.4" /* XUPS-MIB::xupsInputWatts */ #define PW_OID_OUT_LOAD "1.3.6.1.4.1.534.1.4.1.0" /* XUPS-MIB::xupsOutputLoad.0 */ #define PW_OID_OUT_FREQUENCY "1.3.6.1.4.1.534.1.4.2.0" /* XUPS-MIB::xupsOutputFrequency.0 */ #define PW_OID_OUT_LINES "1.3.6.1.4.1.534.1.4.3.0" /* XUPS-MIB::xupsOutputNumPhases.0 */ #define PW_OID_OUT_VOLTAGE "1.3.6.1.4.1.534.1.4.4.1.2" /* XUPS-MIB::xupsOutputVoltage */ #define PW_OID_OUT_CURRENT "1.3.6.1.4.1.534.1.4.4.1.3" /* XUPS-MIB::xupsOutputCurrent */ #define PW_OID_OUT_POWER "1.3.6.1.4.1.534.1.4.4.1.4" /* XUPS-MIB::xupsOutputWatts */ #define PW_OID_POWER_STATUS "1.3.6.1.4.1.534.1.4.5.0" /* XUPS-MIB::xupsOutputSource.0 */ #define PW_OID_BY_FREQUENCY "1.3.6.1.4.1.534.1.5.1.0" /* XUPS-MIB::xupsBypassFrequency.0 */ #define PW_OID_BY_LINES "1.3.6.1.4.1.534.1.5.2.0" /* XUPS-MIB::xupsBypassNumPhases.0 */ #define PW_OID_BY_VOLTAGE "1.3.6.1.4.1.534.1.5.3.1.2" /* XUPS-MIB::xupsBypassVoltage */ #define PW_OID_BATTEST_START "1.3.6.1.4.1.534.1.8.1" /* XUPS-MIB::xupsTestBattery set to startTest(1) to initiate test*/ #define PW_OID_CONT_OFFDELAY "1.3.6.1.4.1.534.1.9.1.0" /* XUPS-MIB::xupsControlOutputOffDelay */ #define PW_OID_CONT_ONDELAY "1.3.6.1.4.1.534.1.9.2.0" /* XUPS-MIB::xupsControlOutputOnDelay */ #define PW_OID_CONT_OFFT_DEL "1.3.6.1.4.1.534.1.9.3" /* XUPS-MIB::xupsControlOutputOffTrapDelay */ #define PW_OID_CONT_ONT_DEL "1.3.6.1.4.1.534.1.9.4" /* XUPS-MIB::xupsControlOutputOnTrapDelay */ #define PW_OID_CONT_LOAD_SHED_AND_RESTART "1.3.6.1.4.1.534.1.9.6" /* XUPS-MIB::xupsLoadShedSecsWithRestart */ #define PW_OID_CONF_OVOLTAGE "1.3.6.1.4.1.534.1.10.1.0" /* XUPS-MIB::xupsConfigOutputVoltage.0 */ #define PW_OID_CONF_IVOLTAGE "1.3.6.1.4.1.534.1.10.2.0" /* XUPS-MIB::xupsConfigInputVoltage.0 */ #define PW_OID_CONF_POWER "1.3.6.1.4.1.534.1.10.3.0" /* XUPS-MIB::xupsConfigOutputWatts.0 */ #define PW_OID_CONF_FREQ "1.3.6.1.4.1.534.1.10.4.0" /* XUPS-MIB::xupsConfigOutputFreq.0 */ #define PW_OID_ALARMS "1.3.6.1.4.1.534.1.7.1.0" /* XUPS-MIB::xupsAlarms */ #define PW_OID_ALARM_OB "1.3.6.1.4.1.534.1.7.3" /* XUPS-MIB::xupsOnBattery */ #define PW_OID_ALARM_LB "1.3.6.1.4.1.534.1.7.4" /* XUPS-MIB::xupsLowBattery */ #define IETF_OID_AGENTREV "1.3.6.1.2.1.33.1.1.4.0" /* UPS-MIB::upsIdentAgentSoftwareVersion.0 */ #define IETF_OID_IDENT "1.3.6.1.2.1.33.1.1.5.0" /* UPS-MIB::upsIdentName.0 */ #define IETF_OID_CONF_OUT_VA "1.3.6.1.2.1.33.1.9.5.0" /* UPS-MIB::upsConfigOutputVA.0 */ #define IETF_OID_CONF_RUNTIME_LOW "1.3.6.1.2.1.33.1.9.7.0" /* UPS-MIB::upsConfigLowBattTime.0 */ #define IETF_OID_LOAD_LEVEL "1.3.6.1.2.1.33.1.4.4.1.5" /* UPS-MIB::upsOutputPercentLoad */ #define IETF_OID_AUTO_RESTART "1.3.6.1.2.1.33.1.8.5.0" /* UPS-MIB::upsAutoRestart */ /* Delay before powering off in seconds */ #define DEFAULT_OFFDELAY 30 /* Delay before powering on in seconds */ #define DEFAULT_ONDELAY 20 /* Default shutdown.return delay in seconds */ #define DEFAULT_SHUTDOWNDELAY 0 static info_lkp_t eaton_pxg_alarm_ob[] = { info_lkp_default(1, "OB"), info_lkp_default(2, ""), info_lkp_sentinel }; static info_lkp_t eaton_pxg_alarm_lb[] = { info_lkp_default(1, "LB"), info_lkp_default(2, ""), info_lkp_sentinel }; static info_lkp_t eaton_pxg_pwr_info[] = { info_lkp_default(0, "OFF"), /* off */ info_lkp_default(1, "OL"), /* systemNormal */ info_lkp_default(2, "OL"), /* systemNormalUPSRedundant */ info_lkp_default(3, "OL"), /* systemNormalNotRedundant */ info_lkp_default(4, "OB"), /* systemOnDCSource*/ info_lkp_default(5, "OB LB"), /* systemOnDCSourceShutdownImminent */ info_lkp_default(6, "OL"), /* systemNormalBypassNotAvailable */ info_lkp_default(7, "OL"), /* systemNormalOnLine */ info_lkp_default(8, "OL"), /* systemNormalEnergySaverSystem */ info_lkp_default(9, "OL"), /* systemNormalVMMS */ info_lkp_default(10, "OL"), /* systemNormalHRS */ info_lkp_default(13, "OL OVER"), /* outputOverload */ info_lkp_default(14, "OL TRIM"), /* systemNormalOnBuck */ info_lkp_default(15, "OL BOOST"), /* systemNormalOnBoost */ info_lkp_default(16, "BYPASS"), /* onBypass */ info_lkp_default(17, "BYPASS"), /* onBypassStarting */ info_lkp_default(18, "BYPASS"), /* onBypassReady */ info_lkp_default(32, "BYPASS"), /* onMaintenanceBypass */ info_lkp_default(33, "OL BYPASS"), /* onMBSUPSOnLine */ info_lkp_default(34, "BYPASS"), /* onMBSUPSOnBypass */ info_lkp_default(35, "OFF BYPASS"), /* onMBSUPSOff */ info_lkp_default(36, "OB BYPASS"), /* onMBSUPSOnBattery */ info_lkp_default(37, "OL"), /* onMBSUPSOnLineESS */ info_lkp_default(38, "OL"), /* onMBSUPSOnLineVMMS */ info_lkp_default(39, "OL"), /* onMBSUPSOnLineHRS */ info_lkp_default(40, "OL"), /* onMBSStarting */ info_lkp_default(41, "OL"), /* onMBSReady */ info_lkp_default(48, "OFF"), /* loadOff */ info_lkp_default(49, "OFF"), /* loadOffStarting */ info_lkp_default(50, "OFF"), /* loadOffReady */ info_lkp_default(64, "OL"), /* supportingLoad */ info_lkp_default(80, "OL"), /* systemNormalSP */ info_lkp_default(81, "OL"), /* systemNormalEnergySaverSystemSP */ info_lkp_default(96, "BYPASS"), /* systemOnBypassSP */ info_lkp_default(100, "BYPASS"), /* systemOnManualMaintenanceBypassSP (0x64) */ info_lkp_default(224, "OL OVER"), /* loadSegmentOverload (0x64) */ info_lkp_default(240, "OB"), /* systemOnDCSourceSP */ info_lkp_default(241, "OFF"), /* systemOffSP */ info_lkp_sentinel }; /* FIXME: mapped to (experimental.)ups.type, but * should be output.source or ups.mode (need RFC) * to complement the above ups.status * along with having ups.type as described hereafter*/ /* FIXME: should be used by ups.mode or output.source (need RFC); * Note: this define is not set via project options; code was hidden with * original commit to "snmp-ups: support newer Genepi management cards"; * un-hidden to make it "experimental.*" namespace during backporting */ #ifndef USE_PW_MODE_INFO # define USE_PW_MODE_INFO 1 #endif #if USE_PW_MODE_INFO static info_lkp_t eaton_pxg_mode_info[] = { info_lkp_default(1, ""), info_lkp_default(2, ""), info_lkp_default(3, "normal"), info_lkp_default(4, ""), info_lkp_default(5, ""), info_lkp_default(6, ""), info_lkp_default(7, ""), info_lkp_default(8, "parallel capacity"), info_lkp_default(9, "parallel redundancy"), info_lkp_default(10, "high efficiency"), /* Extended status values, * FIXME: check for source and completion */ info_lkp_default(240, ""), /* battery (0xF0) */ info_lkp_default(100, ""), /* maintenanceBypass (0x64) */ info_lkp_default(96, ""), /* Bypass (0x60) */ info_lkp_default(81, "high efficiency"), /* high efficiency (0x51) */ info_lkp_default(80, "normal"), /* normal (0x50) */ info_lkp_default(64, ""), /* UPS supporting load, normal degraded mode (0x40) */ info_lkp_default(16, ""), /* none (0x10) */ info_lkp_sentinel }; #endif /* USE_PW_MODE_INFO */ /* FIXME: may be standardized * extracted from bcmxcp.c->BCMXCP_TOPOLOGY_*, Make some common definitions */ static info_lkp_t eaton_pxg_topology_info[] = { info_lkp_default(0x0000, ""), /* None; use the Table of Elements */ info_lkp_default(0x0010, "Off-line switcher, Single Phase"), info_lkp_default(0x0020, "Line-Interactive UPS, Single Phase"), info_lkp_default(0x0021, "Line-Interactive UPS, Two Phase"), info_lkp_default(0x0022, "Line-Interactive UPS, Three Phase"), info_lkp_default(0x0030, "Dual AC Input, On-Line UPS, Single Phase"), info_lkp_default(0x0031, "Dual AC Input, On-Line UPS, Two Phase"), info_lkp_default(0x0032, "Dual AC Input, On-Line UPS, Three Phase"), info_lkp_default(0x0040, "On-Line UPS, Single Phase"), info_lkp_default(0x0041, "On-Line UPS, Two Phase"), info_lkp_default(0x0042, "On-Line UPS, Three Phase"), info_lkp_default(0x0050, "Parallel Redundant On-Line UPS, Single Phase"), info_lkp_default(0x0051, "Parallel Redundant On-Line UPS, Two Phase"), info_lkp_default(0x0052, "Parallel Redundant On-Line UPS, Three Phase"), info_lkp_default(0x0060, "Parallel for Capacity On-Line UPS, Single Phase"), info_lkp_default(0x0061, "Parallel for Capacity On-Line UPS, Two Phase"), info_lkp_default(0x0062, "Parallel for Capacity On-Line UPS, Three Phase"), info_lkp_default(0x0102, "System Bypass Module, Three Phase"), info_lkp_default(0x0122, "Hot-Tie Cabinet, Three Phase"), info_lkp_default(0x0200, "Outlet Controller, Single Phase"), info_lkp_default(0x0222, "Dual AC Input Static Switch Module, 3 Phase"), info_lkp_sentinel }; /* Legacy implementation */ static info_lkp_t eaton_pxg_battery_abm_status[] = { info_lkp_default(1, "CHRG"), info_lkp_default(2, "DISCHRG"), /* info_lkp_default(3, "Floating"), info_lkp_default(4, "Resting"), info_lkp_default(5, "Unknown"), */ info_lkp_sentinel }; static info_lkp_t eaton_pxg_abm_status_info[] = { info_lkp_default(1, "charging"), info_lkp_default(2, "discharging"), info_lkp_default(3, "floating"), info_lkp_default(4, "resting"), info_lkp_default(5, "unknown"), /* Undefined - ABM is not activated */ info_lkp_default(6, "disabled"), /* ABM Charger Disabled */ info_lkp_sentinel }; static info_lkp_t eaton_pxg_batt_test_info[] = { info_lkp_default(1, "Unknown"), info_lkp_default(2, "Done and passed"), info_lkp_default(3, "Done and error"), info_lkp_default(4, "In progress"), info_lkp_default(5, "Not supported"), info_lkp_default(6, "Inhibited"), info_lkp_default(7, "Scheduled"), info_lkp_sentinel }; static info_lkp_t eaton_pxg_yes_no_info[] = { info_lkp_default(1, "yes"), info_lkp_default(2, "no"), info_lkp_sentinel }; static info_lkp_t eaton_pxg_outlet_status_info[] = { info_lkp_default(1, "on"), info_lkp_default(2, "off"), info_lkp_default(3, "on"), /* pendingOff, transitional status */ info_lkp_default(4, "off"), /* pendingOn, transitional status */ /* info_lkp_default(5, ""), // unknown */ /* info_lkp_default(6, ""), // reserved */ info_lkp_default(7, "off"), /* Failed in Closed position */ info_lkp_default(8, "on"), /* Failed in Open position */ info_lkp_sentinel }; static info_lkp_t eaton_pxg_ambient_drycontacts_info[] = { info_lkp_default(-1, "unknown"), info_lkp_default(1, "opened"), info_lkp_default(2, "closed"), info_lkp_default(3, "opened"), /* openWithNotice */ info_lkp_default(4, "closed"), /* closedWithNotice */ info_lkp_sentinel }; #if WITH_SNMP_LKP_FUN /* Note: eaton_sensor_temperature_unit_fun() is defined in eaton-pdu-marlin-helpers.c * and su_temperature_read_fun() is in snmp-ups.c * Future work for DMF might provide same-named routines via LUA-C gateway. */ # if WITH_SNMP_LKP_FUN_DUMMY /* Temperature unit consideration */ const char *eaton_sensor_temperature_unit_fun(void *raw_snmp_value) { /* snmp_value here would be a (long*) */ NUT_UNUSED_VARIABLE(raw_snmp_value); return "unknown"; } /* FIXME: please DMF, though this should be in snmp-ups.c or equiv. */ const char *su_temperature_read_fun(void *raw_snmp_value) { /* snmp_value here would be a (long*) */ NUT_UNUSED_VARIABLE(raw_snmp_value); return "dummy"; }; # endif /* WITH_SNMP_LKP_FUN_DUMMY */ static info_lkp_t eaton_pxg_sensor_temperature_unit_info[] = { info_lkp_fun_vp2s(0, "dummy", eaton_sensor_temperature_unit_fun), info_lkp_sentinel }; static info_lkp_t eaton_pxg_sensor_temperature_read_info[] = { info_lkp_fun_vp2s(0, "dummy", su_temperature_read_fun), info_lkp_sentinel }; #else /* if not WITH_SNMP_LKP_FUN: */ /* FIXME: For now, DMF codebase falls back to old implementation with static * lookup/mapping tables for this, which can easily go into the DMF XML file. */ static info_lkp_t eaton_pxg_sensor_temperature_unit_info[] = { info_lkp_default(0, "kelvin"), info_lkp_default(1, "celsius"), info_lkp_default(2, "fahrenheit"), info_lkp_sentinel }; #endif /* WITH_SNMP_LKP_FUN */ static info_lkp_t eaton_pxg_ambient_drycontacts_polarity_info[] = { info_lkp_default(0, "normal-opened"), info_lkp_default(1, "normal-closed"), info_lkp_sentinel }; static info_lkp_t eaton_pxg_ambient_drycontacts_state_info[] = { info_lkp_default(0, "inactive"), info_lkp_default(1, "active"), info_lkp_sentinel }; static info_lkp_t eaton_pxg_emp002_ambient_presence_info[] = { info_lkp_default(0, "unknown"), info_lkp_default(2, "yes"), /* communicationOK */ info_lkp_default(3, "no"), /* communicationLost */ info_lkp_sentinel }; /* extracted from drivers/eaton-pdu-marlin-mib.c -> marlin_threshold_status_info */ static info_lkp_t eaton_pxg_threshold_status_info[] = { info_lkp_default(0, "good"), /* No threshold triggered */ info_lkp_default(1, "warning-low"), /* Warning low threshold triggered */ info_lkp_default(2, "critical-low"), /* Critical low threshold triggered */ info_lkp_default(3, "warning-high"), /* Warning high threshold triggered */ info_lkp_default(4, "critical-high"), /* Critical high threshold triggered */ info_lkp_sentinel }; /* extracted from drivers/eaton-pdu-marlin-mib.c -> marlin_threshold_xxx_alarms_info */ static info_lkp_t eaton_pxg_threshold_temperature_alarms_info[] = { info_lkp_default(0, ""), /* No threshold triggered */ info_lkp_default(1, "low temperature warning!"), /* Warning low threshold triggered */ info_lkp_default(2, "low temperature critical!"), /* Critical low threshold triggered */ info_lkp_default(3, "high temperature warning!"), /* Warning high threshold triggered */ info_lkp_default(4, "high temperature critical!"), /* Critical high threshold triggered */ info_lkp_sentinel }; static info_lkp_t eaton_pxg_threshold_humidity_alarms_info[] = { info_lkp_default(0, ""), /* No threshold triggered */ info_lkp_default(1, "low humidity warning!"), /* Warning low threshold triggered */ info_lkp_default(2, "low humidity critical!"), /* Critical low threshold triggered */ info_lkp_default(3, "high humidity warning!"), /* Warning high threshold triggered */ info_lkp_default(4, "high humidity critical!"), /* Critical high threshold triggered */ info_lkp_sentinel }; /* Snmp2NUT lookup table */ static snmp_info_t eaton_pxg_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* FIXME: miss device page! */ /* UPS page */ /* info_type, info_flags, info_len, OID, dfl, flags, oid2info, setvar */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_MFR_NAME, "", SU_FLAG_STATIC, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_MODEL_NAME, "", SU_FLAG_STATIC, NULL), /* FIXME: the 2 "firmware" entries below should be SU_FLAG_SEMI_STATIC */ snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_FIRMREV, "", 0, NULL), snmp_info_default("ups.firmware.aux", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_AGENTREV, "", 0, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, IETF_OID_IDENT, "", SU_FLAG_STATIC, NULL), snmp_info_default("ups.load", 0, 1.0, PW_OID_OUT_LOAD, "", 0, NULL), /* FIXME: should be removed in favor of output.power */ snmp_info_default("ups.power", 0, 1.0, PW_OID_OUT_POWER ".1", "", 0, NULL), /* Duplicate of the above entry, but pointing at the first index */ /* xupsOutputWatts.1.0; Value (Integer): 300 */ snmp_info_default("ups.power", 0, 1.0, "1.3.6.1.4.1.534.1.4.4.1.4.1.0", "", 0, NULL), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_POWER_STATUS, "OFF", SU_STATUS_PWR, &eaton_pxg_pwr_info[0]), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_ALARM_OB, "", SU_STATUS_BATT, &eaton_pxg_alarm_ob[0]), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_ALARM_LB, "", SU_STATUS_BATT, &eaton_pxg_alarm_lb[0]), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_BATT_STATUS, "", SU_STATUS_BATT, &eaton_pxg_battery_abm_status[0]), #if USE_PW_MODE_INFO /* FIXME: should be ups.mode or output.source (need RFC) */ /* Note: this define is not set via project options; code hidden with * commit to "snmp-ups: support newer Genepi management cards" */ snmp_info_default("experimental.ups.type", ST_FLAG_STRING, SU_INFOSIZE, PW_OID_POWER_STATUS, "", SU_FLAG_STATIC | SU_FLAG_OK, &eaton_pxg_mode_info[0]), #endif /* USE_PW_MODE_INFO */ /* xupsTopologyType.0; Value (Integer): 32 */ snmp_info_default("ups.type", ST_FLAG_STRING, SU_INFOSIZE, "1.3.6.1.4.1.534.1.13.1.0", "", SU_FLAG_STATIC | SU_FLAG_OK, &eaton_pxg_topology_info[0]), /* FIXME: should be removed in favor of their output. equivalent! */ snmp_info_default("ups.realpower.nominal", 0, 1.0, PW_OID_CONF_POWER, "", 0, NULL), /* FIXME: should be removed in favor of output.power.nominal */ snmp_info_default("ups.power.nominal", 0, 1.0, IETF_OID_CONF_OUT_VA, "", 0, NULL), /* XUPS-MIB::xupsEnvAmbientTemp.0 */ snmp_info_default("ups.temperature", 0, 1.0, "1.3.6.1.4.1.534.1.6.1.0", "", 0, NULL), /* FIXME: These 2 data needs RFC! */ /* XUPS-MIB::xupsEnvAmbientLowerLimit.0 */ snmp_info_default("ups.temperature.low", ST_FLAG_RW, 1.0, "1.3.6.1.4.1.534.1.6.2.0", "", 0, NULL), /* XUPS-MIB::xupsEnvAmbientUpperLimit.0 */ snmp_info_default("ups.temperature.high", ST_FLAG_RW, 1.0, "1.3.6.1.4.1.534.1.6.3.0", "", 0, NULL), /* XUPS-MIB::xupsTestBatteryStatus */ snmp_info_default("ups.test.result", ST_FLAG_STRING, SU_INFOSIZE, "1.3.6.1.4.1.534.1.8.2.0", "", 0, &eaton_pxg_batt_test_info[0]), /* UPS-MIB::upsAutoRestart */ snmp_info_default("ups.start.auto", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, "1.3.6.1.2.1.33.1.8.5.0", "", SU_FLAG_OK, &eaton_pxg_yes_no_info[0]), /* XUPS-MIB::xupsBatteryAbmStatus.0 */ snmp_info_default("battery.charger.status", ST_FLAG_STRING, SU_INFOSIZE, "1.3.6.1.4.1.534.1.2.5.0", "", SU_STATUS_BATT, &eaton_pxg_abm_status_info[0]), /* Battery page */ snmp_info_default("battery.charge", 0, 1.0, PW_OID_BATT_CHARGE, "", 0, NULL), snmp_info_default("battery.runtime", 0, 1.0, PW_OID_BATT_RUNTIME, "", 0, NULL), snmp_info_default("battery.voltage", 0, 1.0, PW_OID_BATT_VOLTAGE, "", 0, NULL), snmp_info_default("battery.current", 0, 0.1, PW_OID_BATT_CURRENT, "", 0, NULL), snmp_info_default("battery.runtime.low", 0, 60.0, IETF_OID_CONF_RUNTIME_LOW, "", 0, NULL), snmp_info_default("battery.date", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.1.2.6.0", NULL, SU_FLAG_OK, &su_convert_to_iso_date_info[FUNMAP_USDATE_TO_ISODATE]), /* Output page */ snmp_info_default("output.phases", 0, 1.0, PW_OID_OUT_LINES, "", 0, NULL), /* XUPS-MIB::xupsOutputFrequency.0 */ snmp_info_default("output.frequency", 0, 0.1, "1.3.6.1.4.1.534.1.4.2.0", "", 0, NULL), /* XUPS-MIB::xupsConfigOutputFreq.0 */ snmp_info_default("output.frequency.nominal", 0, 0.1, "1.3.6.1.4.1.534.1.10.4.0", "", 0, NULL), /* XUPS-MIB::xupsOutputVoltage.1 */ snmp_info_default("output.voltage", 0, 1.0, "1.3.6.1.4.1.534.1.4.4.1.2.1", "", SU_OUTPUT_1, NULL), /* Duplicate of the above entry, but pointing at the first index */ /* xupsOutputVoltage.1.0; Value (Integer): 230 */ snmp_info_default("output.voltage", 0, 1.0, "1.3.6.1.4.1.534.1.4.4.1.2.1.0", "", SU_OUTPUT_1, NULL), /* XUPS-MIB::xupsConfigOutputVoltage.0 */ snmp_info_default("output.voltage.nominal", 0, 1.0, "1.3.6.1.4.1.534.1.10.1.0", "", 0, NULL), /* XUPS-MIB::xupsConfigLowOutputVoltageLimit.0 */ snmp_info_default("output.voltage.low", 0, 1.0, ".1.3.6.1.4.1.534.1.10.6.0", "", 0, NULL), /* XUPS-MIB::xupsConfigHighOutputVoltageLimit.0 */ snmp_info_default("output.voltage.high", 0, 1.0, ".1.3.6.1.4.1.534.1.10.7.0", "", 0, NULL), snmp_info_default("output.current", 0, 1.0, PW_OID_OUT_CURRENT ".1", "", SU_OUTPUT_1, NULL), /* Duplicate of the above entry, but pointing at the first index */ /* xupsOutputCurrent.1.0; Value (Integer): 0 */ snmp_info_default("output.current", 0, 1.0, "1.3.6.1.4.1.534.1.4.4.1.3.1.0", "", SU_OUTPUT_1, NULL), snmp_info_default("output.realpower", 0, 1.0, PW_OID_OUT_POWER ".1", "", SU_OUTPUT_1, NULL), /* Duplicate of the above entry, but pointing at the first index */ /* Name/OID: xupsOutputWatts.1.0; Value (Integer): 1200 */ snmp_info_default("output.realpower", 0, 1.0, "1.3.6.1.4.1.534.1.4.4.1.4.1.0", "", 0, NULL), /* Duplicate of "ups.realpower.nominal" * FIXME: map either ups or output, but not both (or have an auto-remap) */ snmp_info_default("output.realpower.nominal", 0, 1.0, PW_OID_CONF_POWER, "", 0, NULL), snmp_info_default("output.L1-N.voltage", 0, 1.0, PW_OID_OUT_VOLTAGE ".1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2-N.voltage", 0, 1.0, PW_OID_OUT_VOLTAGE ".2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3-N.voltage", 0, 1.0, PW_OID_OUT_VOLTAGE ".3", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L1.current", 0, 1.0, PW_OID_OUT_CURRENT ".1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2.current", 0, 1.0, PW_OID_OUT_CURRENT ".2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3.current", 0, 1.0, PW_OID_OUT_CURRENT ".3", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L1.realpower", 0, 1.0, PW_OID_OUT_POWER ".1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2.realpower", 0, 1.0, PW_OID_OUT_POWER ".2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3.realpower", 0, 1.0, PW_OID_OUT_POWER ".3", "", SU_OUTPUT_3, NULL), /* FIXME: should better be output.Lx.load */ snmp_info_default("output.L1.power.percent", 0, 1.0, IETF_OID_LOAD_LEVEL ".1", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L2.power.percent", 0, 1.0, IETF_OID_LOAD_LEVEL ".2", "", SU_OUTPUT_3, NULL), snmp_info_default("output.L3.power.percent", 0, 1.0, IETF_OID_LOAD_LEVEL ".3", "", SU_OUTPUT_3, NULL), snmp_info_default("output.voltage.nominal", 0, 1.0, PW_OID_CONF_OVOLTAGE, "", 0, NULL), /* Input page */ snmp_info_default("input.phases", 0, 1.0, PW_OID_IN_LINES, "", 0, NULL), snmp_info_default("input.frequency", 0, 0.1, PW_OID_IN_FREQUENCY, "", 0, NULL), snmp_info_default("input.voltage", 0, 1.0, PW_OID_IN_VOLTAGE ".0", "", SU_INPUT_1, NULL), /* Duplicate of the above entry, but pointing at the first index */ /* xupsInputVoltage.1[.0]; Value (Integer): 245 */ snmp_info_default("input.voltage", 0, 1.0, "1.3.6.1.4.1.534.1.3.4.1.2.1", "", SU_INPUT_1, NULL), /* XUPS-MIB::xupsConfigInputVoltage.0 */ snmp_info_default("input.voltage.nominal", 0, 1.0, "1.3.6.1.4.1.534.1.10.2.0", "", 0, NULL), snmp_info_default("input.current", 0, 0.1, PW_OID_IN_CURRENT ".0", "", SU_INPUT_1, NULL), snmp_info_default("input.L1-N.voltage", 0, 1.0, PW_OID_IN_VOLTAGE ".1", "", SU_INPUT_3, NULL), snmp_info_default("input.L2-N.voltage", 0, 1.0, PW_OID_IN_VOLTAGE ".2", "", SU_INPUT_3, NULL), snmp_info_default("input.L3-N.voltage", 0, 1.0, PW_OID_IN_VOLTAGE ".3", "", SU_INPUT_3, NULL), snmp_info_default("input.L1.current", 0, 1.0, PW_OID_IN_CURRENT ".1", "", SU_INPUT_3, NULL), snmp_info_default("input.L2.current", 0, 1.0, PW_OID_IN_CURRENT ".2", "", SU_INPUT_3, NULL), snmp_info_default("input.L3.current", 0, 1.0, PW_OID_IN_CURRENT ".3", "", SU_INPUT_3, NULL), snmp_info_default("input.L1.realpower", 0, 1.0, PW_OID_IN_POWER ".1", "", SU_INPUT_3, NULL), snmp_info_default("input.L2.realpower", 0, 1.0, PW_OID_IN_POWER ".2", "", SU_INPUT_3, NULL), snmp_info_default("input.L3.realpower", 0, 1.0, PW_OID_IN_POWER ".3", "", SU_INPUT_3, NULL), snmp_info_default("input.quality", 0, 1.0, PW_OID_IN_LINE_BADS, "", 0, NULL), /* FIXME: this segfaults! do we assume the same number of bypass phases as input phases? snmp_info_default("input.bypass.phases", 0, 1.0, PW_OID_BY_LINES, "", 0, NULL), */ snmp_info_default("input.bypass.frequency", 0, 0.1, PW_OID_BY_FREQUENCY, "", 0, NULL), snmp_info_default("input.bypass.voltage", 0, 1.0, PW_OID_BY_VOLTAGE ".0", "", SU_INPUT_1, NULL), /* Duplicate of the above entry, but pointing at the first index */ /* xupsBypassVoltage.1.0; Value (Integer): 244 */ snmp_info_default("input.bypass.voltage", 0, 1.0, "1.3.6.1.4.1.534.1.5.3.1.2.1.0", "", SU_INPUT_1, NULL), snmp_info_default("input.bypass.L1-N.voltage", 0, 1.0, PW_OID_BY_VOLTAGE ".1", "", SU_INPUT_3, NULL), snmp_info_default("input.bypass.L2-N.voltage", 0, 1.0, PW_OID_BY_VOLTAGE ".2", "", SU_INPUT_3, NULL), snmp_info_default("input.bypass.L3-N.voltage", 0, 1.0, PW_OID_BY_VOLTAGE ".3", "", SU_INPUT_3, NULL), /* Outlet page */ /* Master outlet id always equal to 0 */ snmp_info_default("outlet.id", 0, 1, NULL, "0", SU_FLAG_STATIC , NULL), /* XUPS-MIB:: xupsSwitchable.0 */ snmp_info_default("outlet.switchable", 0, 1, ".1.3.6.1.4.1.534.1.9.7.0", NULL, SU_FLAG_STATIC , &eaton_pxg_yes_no_info[0]), /* XUPS-MIB::xupsNumReceptacles; Value (Integer): 2 */ snmp_info_default("outlet.count", 0, 1, ".1.3.6.1.4.1.534.1.12.1.0", NULL, SU_FLAG_STATIC, NULL), /* XUPS-MIB::xupsRecepIndex.X; Value (Integer): X */ snmp_info_default("outlet.%i.id", 0, 1, ".1.3.6.1.4.1.534.1.12.2.1.1.%i", NULL, SU_FLAG_STATIC | SU_OUTLET, NULL), /* This MIB does not provide outlets switchability info. So map to a nearby OID, for data activation, and map all values to "yes" */ snmp_info_default("outlet.%i.switchable", 0, 1, ".1.3.6.1.4.1.534.1.12.2.1.1.%i", NULL, SU_FLAG_STATIC | SU_OUTLET, NULL), /* XUPS-MIB::xupsRecepStatus.X; Value (Integer): 1 */ snmp_info_default("outlet.%i.status", 0, 1, ".1.3.6.1.4.1.534.1.12.2.1.2.%i", NULL, SU_OUTLET, &eaton_pxg_outlet_status_info[0]), /* Ambient collection */ /* EMP001 (legacy) mapping */ /* XUPS-MIB::xupsEnvRemoteTemp.0 */ snmp_info_default("ambient.temperature", 0, 1.0, "1.3.6.1.4.1.534.1.6.5.0", "", 0, NULL), /* XUPS-MIB::xupsEnvRemoteTempLowerLimit.0 */ snmp_info_default("ambient.temperature.low", ST_FLAG_RW, 1.0, "1.3.6.1.4.1.534.1.6.9.0", "", 0, NULL), /* XUPS-MIB::xupsEnvRemoteTempUpperLimit.0 */ snmp_info_default("ambient.temperature.high", ST_FLAG_RW, 1.0, "1.3.6.1.4.1.534.1.6.10.0", "", 0, NULL), /* XUPS-MIB::xupsEnvRemoteHumidity.0 */ snmp_info_default("ambient.humidity", 0, 1.0, "1.3.6.1.4.1.534.1.6.6.0", "", 0, NULL), /* XUPS-MIB::xupsEnvRemoteHumidityLowerLimit.0 */ snmp_info_default("ambient.humidity.low", ST_FLAG_RW, 1.0, "1.3.6.1.4.1.534.1.6.11.0", "", 0, NULL), /* XUPS-MIB::xupsEnvRemoteHumidityUpperLimit.0 */ snmp_info_default("ambient.humidity.high", ST_FLAG_RW, 1.0, "1.3.6.1.4.1.534.1.6.12.0", "", 0, NULL), /* XUPS-MIB::xupsContactDescr.n */ snmp_info_default("ambient.contacts.1.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.1.6.8.1.4.1", "", 0, NULL), snmp_info_default("ambient.contacts.2.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.1.6.8.1.4.2", "", 0, NULL), /* XUPS-MIB::xupsContactState.n */ snmp_info_default("ambient.contacts.1.status", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.1.6.8.1.3.1", "", 0, &eaton_pxg_ambient_drycontacts_info[0]), snmp_info_default("ambient.contacts.2.status", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.1.6.8.1.3.2", "", 0, &eaton_pxg_ambient_drycontacts_info[0]), /* EMP002 (EATON EMP MIB) mapping, including daisychain support */ /* Warning: indexes start at '1' not '0'! */ /* sensorCount.0 */ snmp_info_default("ambient.count", ST_FLAG_RW, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.1.0", "", 0, NULL), /* CommunicationStatus.n */ snmp_info_default("ambient.%i.present", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.1.4.1.1.%i", NULL, SU_AMBIENT_TEMPLATE, &eaton_pxg_emp002_ambient_presence_info[0]), /* sensorName.n: OctetString EMPDT1H1C2 @1 */ snmp_info_default("ambient.%i.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.3.1.1.%i", "", SU_AMBIENT_TEMPLATE, NULL), /* sensorManufacturer.n */ snmp_info_default("ambient.%i.mfr", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.6.%i", "", SU_AMBIENT_TEMPLATE, NULL), /* sensorModel.n */ snmp_info_default("ambient.%i.model", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.7.%i", "", SU_AMBIENT_TEMPLATE, NULL), /* sensorSerialNumber.n */ snmp_info_default("ambient.%i.serial", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.9.%i", "", SU_AMBIENT_TEMPLATE, NULL), /* sensorUuid.n */ snmp_info_default("ambient.%i.id", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.2.%i", "", SU_AMBIENT_TEMPLATE, NULL), /* sensorAddress.n */ snmp_info_default("ambient.%i.address", 0, 1, ".1.3.6.1.4.1.534.6.8.1.1.2.1.4.%i", "", SU_AMBIENT_TEMPLATE, NULL), /* sensorFirmwareVersion.n */ snmp_info_default("ambient.%i.firmware", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.1.2.1.10.%i", "", SU_AMBIENT_TEMPLATE, NULL), /* temperatureUnit.1 * MUST be before the temperature data reading! */ snmp_info_default("ambient.%i.temperature.unit", 0, 1.0, ".1.3.6.1.4.1.534.6.8.1.2.5.0", "", SU_AMBIENT_TEMPLATE, &eaton_pxg_sensor_temperature_unit_info[0]), /* temperatureValue.n.1 */ #if WITH_SNMP_LKP_FUN snmp_info_default("ambient.%i.temperature", 0, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE, &eaton_pxg_sensor_temperature_read_info[0]), #else snmp_info_default("ambient.%i.temperature", 0, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), #endif snmp_info_default("ambient.%i.temperature.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.2.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE, &eaton_pxg_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.2.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE, &eaton_pxg_threshold_temperature_alarms_info[0]), /* FIXME: ambient.n.temperature.{minimum,maximum} */ /* temperatureThresholdLowCritical.n.1 */ snmp_info_default("ambient.%i.temperature.low.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.6.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* temperatureThresholdLowWarning.n.1 */ snmp_info_default("ambient.%i.temperature.low.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.5.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* temperatureThresholdHighWarning.n.1 */ snmp_info_default("ambient.%i.temperature.high.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.7.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* temperatureThresholdHighCritical.n.1 */ snmp_info_default("ambient.%i.temperature.high.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.2.2.1.8.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* humidityValue.n.1 */ snmp_info_default("ambient.%i.humidity", 0, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), snmp_info_default("ambient.%i.humidity.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.3.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE, &eaton_pxg_threshold_status_info[0]), snmp_info_default("ups.alarm", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.3.3.1.1.%i.1", NULL, SU_AMBIENT_TEMPLATE, &eaton_pxg_threshold_humidity_alarms_info[0]), /* FIXME: consider ambient.n.humidity.{minimum,maximum} */ /* humidityThresholdLowCritical.n.1 */ snmp_info_default("ambient.%i.humidity.low.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.6.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* humidityThresholdLowWarning.n.1 */ snmp_info_default("ambient.%i.humidity.low.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.5.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* humidityThresholdHighWarning.n.1 */ snmp_info_default("ambient.%i.humidity.high.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.7.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* humidityThresholdHighCritical.n.1 */ snmp_info_default("ambient.%i.humidity.high.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.534.6.8.1.3.2.1.8.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), /* digitalInputName.n.{1,2} */ snmp_info_default("ambient.%i.contacts.1.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.2.1.1.%i.1", "", SU_AMBIENT_TEMPLATE, NULL), snmp_info_default("ambient.%i.contacts.2.name", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.2.1.1.%i.2", "", SU_AMBIENT_TEMPLATE, NULL), /* digitalInputPolarity.n */ snmp_info_default("ambient.%i.contacts.1.config", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.4.2.1.3.%i.1", "", SU_AMBIENT_TEMPLATE, &eaton_pxg_ambient_drycontacts_polarity_info[0]), snmp_info_default("ambient.%i.contacts.2.config", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.6.8.1.4.2.1.3.%i.2", "", SU_AMBIENT_TEMPLATE, &eaton_pxg_ambient_drycontacts_polarity_info[0]), /* XUPS-MIB::xupsContactState.n */ snmp_info_default("ambient.%i.contacts.1.status", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.3.1.3.%i.1", "", SU_AMBIENT_TEMPLATE, &eaton_pxg_ambient_drycontacts_state_info[0]), snmp_info_default("ambient.%i.contacts.2.status", ST_FLAG_STRING, 1.0, ".1.3.6.1.4.1.534.6.8.1.4.3.1.3.%i.2", "", SU_AMBIENT_TEMPLATE, &eaton_pxg_ambient_drycontacts_state_info[0]), /* instant commands */ snmp_info_default("test.battery.start.quick", 0, 1, PW_OID_BATTEST_START, "", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* Shed load and restart when line power back on; cannot be canceled */ snmp_info_default("shutdown.return", 0, DEFAULT_SHUTDOWNDELAY, PW_OID_CONT_LOAD_SHED_AND_RESTART, "", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* Cancel output off, by writing 0 to xupsControlOutputOffDelay */ snmp_info_default("shutdown.stop", 0, 0, PW_OID_CONT_OFFDELAY, "", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* XUPS-MIB::xupsControlOutputOffDelay */ /* load off after 1 sec, shortest possible delay; 0 cancels */ snmp_info_default("load.off", 0, 1, PW_OID_CONT_OFFDELAY, "1", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* Delayed version, parameter is mandatory (so dfl is NULL)! */ snmp_info_default("load.off.delay", 0, 1, PW_OID_CONT_OFFDELAY, NULL, SU_TYPE_CMD | SU_FLAG_OK, NULL), /* XUPS-MIB::xupsControlOutputOnDelay */ /* load on after 1 sec, shortest possible delay; 0 cancels */ snmp_info_default("load.on", 0, 1, PW_OID_CONT_ONDELAY, "1", SU_TYPE_CMD | SU_FLAG_OK, NULL), /* Delayed version, parameter is mandatory (so dfl is NULL)! */ snmp_info_default("load.on.delay", 0, 1, PW_OID_CONT_ONDELAY, NULL, SU_TYPE_CMD | SU_FLAG_OK, NULL), /* Delays handling: * 0-n :Time in seconds until the command is issued * -1:Cancel a pending Off/On command */ /* XUPS-MIB::xupsRecepOffDelaySecs.n */ snmp_info_default("outlet.%i.load.off", 0, 1, ".1.3.6.1.4.1.534.1.12.2.1.3.%i", "0", SU_TYPE_CMD | SU_OUTLET, NULL), /* XUPS-MIB::xupsRecepOnDelaySecs.n */ snmp_info_default("outlet.%i.load.on", 0, 1, ".1.3.6.1.4.1.534.1.12.2.1.4.%i", "0", SU_TYPE_CMD | SU_OUTLET, NULL), /* Delayed version, parameter is mandatory (so dfl is NULL)! */ snmp_info_default("outlet.%i.load.off.delay", 0, 1, ".1.3.6.1.4.1.534.1.12.2.1.3.%i", NULL, SU_TYPE_CMD | SU_OUTLET, NULL), /* XUPS-MIB::xupsRecepOnDelaySecs.n */ snmp_info_default("outlet.%i.load.on.delay", 0, 1, ".1.3.6.1.4.1.534.1.12.2.1.4.%i", NULL, SU_TYPE_CMD | SU_OUTLET, NULL), snmp_info_default("ups.alarms", 0, 1.0, PW_OID_ALARMS, "", 0, NULL), /* end of structure. */ snmp_info_sentinel } ; static alarms_info_t eaton_pxg_alarms[] = { /* xupsLowBattery */ { PW_OID_ALARM_LB, "LB", NULL }, /* xupsOutputOverload */ { ".1.3.6.1.4.1.534.1.7.7", "OVER", "Output overload!" }, /* xupsInternalFailure */ { ".1.3.6.1.4.1.534.1.7.8", NULL, "Internal failure!" }, /* xupsBatteryDischarged */ { ".1.3.6.1.4.1.534.1.7.9", NULL, "Battery discharged!" }, /* xupsInverterFailure */ { ".1.3.6.1.4.1.534.1.7.10", NULL, "Inverter failure!" }, /* xupsOnBypass * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.11", "BYPASS", "On bypass!" }, /* xupsBypassNotAvailable * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.12", NULL, "Bypass not available!" }, /* xupsOutputOff * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.13", "OFF", "Output off!" }, /* xupsInputFailure * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.14", NULL, "Input failure!" }, /* xupsBuildingAlarm * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.15", NULL, "Building alarm!" }, /* xupsShutdownImminent */ { ".1.3.6.1.4.1.534.1.7.16", NULL, "Shutdown imminent!" }, /* xupsOnInverter * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.17", NULL, "On inverter!" }, /* xupsBreakerOpen * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.20", NULL, "Breaker open!" }, /* xupsAlarmBatteryBad */ { ".1.3.6.1.4.1.534.1.7.23", "RB", "Battery bad!" }, /* xupsOutputOffAsRequested * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.24", "OFF", "Output off as requested!" }, /* xupsDiagnosticTestFailed * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.25", NULL, "Diagnostic test failure!" }, /* xupsCommunicationsLost */ { ".1.3.6.1.4.1.534.1.7.26", NULL, "Communication with UPS lost!" }, /* xupsUpsShutdownPending */ { ".1.3.6.1.4.1.534.1.7.27", NULL, "Shutdown pending!" }, /* xupsAmbientTempBad */ { ".1.3.6.1.4.1.534.1.7.29", NULL, "Bad ambient temperature!" }, /* xupsLossOfRedundancy */ { ".1.3.6.1.4.1.534.1.7.30", NULL, "Redundancy lost!" }, /* xupsAlarmTempBad */ { ".1.3.6.1.4.1.534.1.7.31", NULL, "Bad temperature!" }, /* xupsAlarmChargerFailed */ { ".1.3.6.1.4.1.534.1.7.32", NULL, "Charger failure!" }, /* xupsAlarmFanFailure */ { ".1.3.6.1.4.1.534.1.7.33", NULL, "Fan failure!" }, /* xupsAlarmFuseFailure */ { ".1.3.6.1.4.1.534.1.7.34", NULL, "Fuse failure!" }, /* xupsPowerSwitchBad */ { ".1.3.6.1.4.1.534.1.7.35", NULL, "Powerswitch failure!" }, /* xupsModuleFailure */ { ".1.3.6.1.4.1.534.1.7.36", NULL, "Parallel or composite module failure!" }, /* xupsOnAlternatePowerSource * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.37", NULL, "Using alternative power source!" }, /* xupsAltPowerNotAvailable * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.38", NULL, "Alternative power source unavailable!" }, /* xupsRemoteTempBad */ { ".1.3.6.1.4.1.534.1.7.40", NULL, "Bad remote temperature!" }, /* xupsRemoteHumidityBad */ { ".1.3.6.1.4.1.534.1.7.41", NULL, "Bad remote humidity!" }, /* xupsAlarmOutputBad */ { ".1.3.6.1.4.1.534.1.7.42", NULL, "Bad output condition!" }, /* xupsAlarmAwaitingPower * FIXME: informational (not an alarm), * to RFC'ed for device.event? */ { ".1.3.6.1.4.1.534.1.7.43", NULL, "Awaiting power!" }, /* xupsOnMaintenanceBypass * FIXME: informational (not an alarm), * to RFC'ed for device.event? * FIXME: NUT currently doesn't distinguish between Maintenance and * Automatic Bypass (both published as "ups.alarm: BYPASS) * Should we make the distinction? */ { ".1.3.6.1.4.1.534.1.7.44", "BYPASS", "On maintenance bypass!" }, /* end of structure. */ { NULL, NULL, NULL } } ; mib2nut_info_t eaton_pxg_ups = { "eaton_pxg_ups", EATON_PXG_MIB_VERSION, NULL, PW_OID_MODEL_NAME, eaton_pxg_mib, EATON_PXGX_SYSOID , eaton_pxg_alarms }; nut-2.8.4/drivers/macosx-ups.c0000644000175000017500000003334115044656702013212 00000000000000/* Bridge driver to read Mac OS X UPS status (as displayed in Energy Saver control panel) * * Copyright (C) 2011-2012, 2015 Charles Lepple * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "config.h" #include "main.h" #include "attribute.h" #include #include "CoreFoundation/CoreFoundation.h" #include "IOKit/ps/IOPowerSources.h" #include "IOKit/ps/IOPSKeys.h" #define DRIVER_NAME "Mac OS X UPS meta-driver" #define DRIVER_VERSION "1.43" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Charles Lepple ", DRV_EXPERIMENTAL, { NULL } }; #if 0 #define CFRelease(ref) do { upsdebugx(3, "%s:%d: CFRelease(%p)", __FILE__, __LINE__, ref); CFRelease(ref); } while(0) #endif static CFStringRef g_power_source_name = NULL; static double max_capacity_value = 100.0; /*! Copy the current power dictionary. * * Caller must release power dictionary when finished with it. */ static CFDictionaryRef copy_power_dictionary(CFStringRef power_source_name) { CFTypeRef power_sources_info, power_source; CFArrayRef sources_list; CFDictionaryRef this_power_dictionary, power_dictionary = NULL; CFStringRef this_power_source_name; CFIndex num_keys, index; power_sources_info = IOPSCopyPowerSourcesInfo(); assert(power_sources_info); upsdebugx(6, "%s: Got power_sources_info:", __func__); if(nut_debug_level >= 6) CFShow(power_sources_info); upsdebugx(5, "power_source_name = "); if(nut_debug_level >= 5) CFShow(power_source_name); upsdebugx(6, "end power_source_name"); sources_list = IOPSCopyPowerSourcesList(power_sources_info); num_keys = CFArrayGetCount(sources_list); for(index=0; index < num_keys; index++) { upsdebugx(6, "%s: Getting power source %ld/%ld...", __func__, index+1, num_keys); power_source = CFArrayGetValueAtIndex(sources_list, index); assert(power_source); upsdebugx(6, "%s: power source %ld = ", __func__, index+1); if(nut_debug_level >= 6) CFShow(power_source); this_power_dictionary = IOPSGetPowerSourceDescription(power_sources_info, power_source); assert(this_power_dictionary); this_power_source_name = CFDictionaryGetValue(this_power_dictionary, CFSTR(kIOPSNameKey)); assert(this_power_source_name); if(!CFStringCompare(this_power_source_name, power_source_name, 0)) { power_dictionary = this_power_dictionary; CFRetain(power_dictionary); break; } } if(power_dictionary) { upsdebugx(5, "CFShowing 'power_dictionary'"); if(nut_debug_level >= 5) CFShow(power_dictionary); } /* Get a new power_sources_info next time: */ CFRelease(power_sources_info); CFRelease(sources_list); return power_dictionary; } void upsdrv_initinfo(void) { /* try to detect the UPS here - call fatal_with_errno(EXIT_FAILURE, ) if it fails */ char device_name_buf[80] = ""; CFStringRef device_type_cfstr, device_name_cfstr; CFPropertyListRef power_dictionary; CFNumberRef max_capacity; upsdebugx(1, "upsdrv_initinfo()"); dstate_setinfo("device.mfr", "(unknown)"); dstate_setinfo("ups.mfr", "(unknown)"); power_dictionary = copy_power_dictionary(g_power_source_name); device_type_cfstr = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSTypeKey)); if(device_type_cfstr && !CFStringCompare(device_type_cfstr, CFSTR(kIOPSInternalBatteryType), 0)) { dstate_setinfo("device.type", "battery"); } upsdebugx(2, "Getting 'Name' key"); device_name_cfstr = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSNameKey)); if (!device_name_cfstr) { fatalx(EXIT_FAILURE, "Couldn't retrieve 'Name' key from power dictionary."); } CFRetain(device_name_cfstr); CFStringGetCString(device_name_cfstr, device_name_buf, sizeof(device_name_buf), kCFStringEncodingUTF8); upsdebugx(2, "Got name: %s", device_name_buf); CFRelease(device_name_cfstr); dstate_setinfo("device.model", "%s", device_name_buf); dstate_setinfo("ups.model", "%s", device_name_buf); max_capacity = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSMaxCapacityKey)); if(max_capacity) { CFRetain(max_capacity); CFNumberGetValue(max_capacity, kCFNumberDoubleType, &max_capacity_value); CFRelease(max_capacity); upsdebugx(3, "Max Capacity = %.f units (usually 100)", max_capacity_value); if(max_capacity_value != 100.0) { upsdebugx(1, "Max Capacity: %f != 100", max_capacity_value); } } /* upsh.instcmd = instcmd; */ CFRelease(power_dictionary); } void upsdrv_updateinfo(void) { CFPropertyListRef power_dictionary; CFStringRef power_source_state; CFNumberRef battery_voltage, battery_runtime; CFNumberRef current_capacity; CFBooleanRef is_charging; /* double max_capacity_value = 100.0; */ double current_capacity_value; upsdebugx(1, "upsdrv_updateinfo()"); power_dictionary = copy_power_dictionary( g_power_source_name ); if(!power_dictionary) { dstate_datastale(); return; } status_init(); /* Retrieve OL/OB state */ power_source_state = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSPowerSourceStateKey)); assert(power_source_state); CFRetain(power_source_state); upsdebugx(3, "Power Source State:"); if(nut_debug_level >= 3) CFShow(power_source_state); if(!CFStringCompare(power_source_state, CFSTR(kIOPSACPowerValue), 0)) { status_set("OL"); } else { status_set("OB"); } CFRelease(power_source_state); /* Retrieve CHRG state */ is_charging = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSIsChargingKey)); if(is_charging) { Boolean is_charging_value; is_charging_value = CFBooleanGetValue(is_charging); if(is_charging_value) { status_set("CHRG"); } } status_commit(); /* Retrieve battery voltage */ battery_voltage = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSVoltageKey)); if(battery_voltage) { int battery_voltage_value; CFNumberGetValue(battery_voltage, kCFNumberIntType, &battery_voltage_value); upsdebugx(2, "battery_voltage = %d mV", battery_voltage_value); dstate_setinfo("battery.voltage", "%.3f", battery_voltage_value/1000.0); } /* Retrieve battery runtime */ battery_runtime = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSTimeToEmptyKey)); if(battery_runtime) { double battery_runtime_value; CFNumberGetValue(battery_runtime, kCFNumberDoubleType, &battery_runtime_value); upsdebugx(2, "battery_runtime = %.f minutes", battery_runtime_value); if(battery_runtime_value > 0) { dstate_setinfo("battery.runtime", "%d", (int)(battery_runtime_value*60)); } else { dstate_delinfo("battery.runtime"); } } else { dstate_delinfo("battery.runtime"); } /* Retrieve current capacity */ current_capacity = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSCurrentCapacityKey)); if(current_capacity) { CFNumberGetValue(current_capacity, kCFNumberDoubleType, ¤t_capacity_value); upsdebugx(2, "Current Capacity = %.f/%.f units", current_capacity_value, max_capacity_value); if(max_capacity_value > 0) { dstate_setinfo("battery.charge", "%.f", 100.0 * current_capacity_value / max_capacity_value); } } /* TODO: it should be possible to set poll_interval (and maxage in the * server) to an absurdly large value, and use notify(3) to get * updates. */ /* * poll_interval = 2; */ dstate_dataok(); CFRelease(power_dictionary); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ /* maybe try to detect the UPS here, but try a shutdown even if it doesn't respond at first if possible */ /* NOTE: Mac OS X already has shutdown routines - this driver is more for monitoring and notification purposes. Still, there is a key that might be useful to set in SystemConfiguration land. */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); /* you may have to check the line status since the commands for toggling power are frequently different for OL vs. OB */ /* OL: this must power cycle the load if possible */ /* OB: the load must remain off until the power returns */ } /* static int instcmd(const char *cmdname, const char *extra) { / * May be used in logging below, but not as a command argument * / NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ser_send_buf(upsfd, ...); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } */ /* TODO: There is a configuration file here: /Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist with several keys under UPSDefaultThresholds: * UPSShutdownAfterMinutes * UPSShutdownAtLevel * UPSShutdownAtMinutesLeft It is not likely that these keys can be written, but they might be good values for NUT variables. In conjunction with 'ignorelb' and a delta, this could be used to synthesize a LB status right before the computer shuts down. */ /* static int setvar(const char *varname, const char *val) { upsdebug_SET_STARTING(varname, val); if (!strcasecmp(varname, "ups.test.interval")) { ser_send_buf(upsfd, ...); return STAT_SET_HANDLED; } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } */ void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { /* allow '-x xyzzy' */ /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */ /* allow '-x foo=' */ /* addvar(VAR_VALUE, "foo", "Override foo setting"); */ addvar(VAR_VALUE, "model", "Regular Expression to match power source model name"); } void upsdrv_initups(void) { CFArrayRef power_source_key_list; CFIndex num_keys, index; CFDictionaryRef power_dictionary; CFTypeRef power_blob; CFStringRef potential_key, potential_model = NULL; char *model_name; /* regex(3) */ char potential_model_name[256]; regex_t model_regex; int ret = 0; upsdebugx(3, "upsdrv_initups(): Power Sources blob:"); /* upsfd = ser_open(device_path); */ /* ser_set_speed(upsfd, device_path, B1200); */ power_blob = IOPSCopyPowerSourcesInfo(); if(!power_blob) { fatalx(EXIT_FAILURE, "Couldn't retrieve Power Sources blob"); } if(nut_debug_level >= 3) CFShow(power_blob); /* The CFDictionary through 10.9 has changed to a CFArray, * so this part is no longer applicable: */ #if 0 /* Note: original value of device_name is derived from * device_path (value of port parameter) in main.c */ if(!strcmp(device_name, "auto")) { device_name = "/UPS"; } upsdebugx(2, "Matching power supply key names against regex '%s'", device_name); ret = regcomp(&name_regex, device_name, REG_EXTENDED|REG_NOSUB|REG_ICASE); if(ret) { fatalx(EXIT_FAILURE, "Failed to compile regex from 'port' parameter: '%s'.", device_name); } #endif if((model_name = getval("model"))) { upsdebugx(2, "Matching power supply model names against regex '%s'", model_name); ret = regcomp(&model_regex, model_name, REG_EXTENDED|REG_NOSUB|REG_ICASE); if(ret) { fatalx(EXIT_FAILURE, "Failed to compile regex from 'model' parameter: '%s'.", model_name); } } power_source_key_list = IOPSCopyPowerSourcesList(power_blob); num_keys = CFArrayGetCount(power_source_key_list); upsdebugx(1, "Number of power supplies found: %d", (int)num_keys); if(nut_debug_level >= 3) CFShow(power_source_key_list); if(num_keys < 1) { /* bail */ fatalx(EXIT_FAILURE, "Couldn't find any UPS or battery. Is your UPS shown in the 'Energy Saver' control panel?"); } for(index=0; index < num_keys; index++) { upsdebugx(2, "Retrieving power source #%ld", index+1); potential_key = CFArrayGetValueAtIndex(power_source_key_list, index); upsdebugx(3, "Power source key/index:"); if(nut_debug_level >= 3) CFShow(potential_key); power_dictionary = IOPSGetPowerSourceDescription(power_blob, potential_key); assert(power_dictionary); CFRetain(power_dictionary); upsdebugx(2, "Getting 'Name' key (UPS model)"); potential_model = CFDictionaryGetValue(power_dictionary, CFSTR(kIOPSNameKey)); CFRetain(potential_model); if(CFStringGetCString(potential_model, potential_model_name, sizeof(potential_model_name), kCFStringEncodingUTF8)) { upsdebugx(1, " model name: %s", potential_model_name); } else { upsdebugx(1, " (failed to retrieve 'Name')"); } CFRelease(power_dictionary); if(model_name) { ret = regexec(&model_regex, potential_model_name, 0,0,0); if(!ret) { upsdebugx(2, "Matched model name"); break; } } CFRelease(potential_model); } if(model_name) { regfree(&model_regex); } if(ret) { if(model_name) { fatalx(EXIT_FAILURE, "Couldn't find UPS or battery matching 'model' (%s)", model_name); } else { fatalx(EXIT_FAILURE, "Couldn't find an UPS or battery."); } } g_power_source_name = potential_model; /* the upsh handlers can't be done here, as they get initialized * shortly after upsdrv_initups returns to main. */ /* don't try to detect the UPS here */ /* do stuff */ } void upsdrv_cleanup(void) { upsdebugx(1, "Cleanup: release references"); CFRelease(g_power_source_name); /* free(dynamic_mem); */ /* ser_close(upsfd, device_path); */ } nut-2.8.4/drivers/failover.c0000644000175000017500000017000315044656702012717 00000000000000/* failover.c - UPS Failover Driver Copyright (C) 2025 - Sebastian Kuttnig This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "main.h" #include "failover.h" #include "nut_stdint.h" #include "parseconf.h" #include "timehead.h" #include "upsdrvquery.h" #define DRIVER_NAME "UPS Failover Driver" #define DRIVER_VERSION "0.01" upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Sebastian Kuttnig ", DRV_EXPERIMENTAL, { NULL } }; static status_filters_t arg_status_filters; static int arg_init_timeout = DEFAULT_INIT_TIMEOUT; static int arg_dead_timeout = DEFAULT_DEAD_TIMEOUT; static int arg_relog_timeout = DEFAULT_RELOG_TIMEOUT; static int arg_noprimary_timeout = DEFAULT_NO_PRIMARY_TIMEOUT; static int arg_maxconnfails = DEFAULT_MAX_CONNECT_FAILS; static int arg_coolofftimeout = DEFAULT_CONNECTION_COOLOFF; static int arg_fsdmode = DEFAULT_FSD_MODE; static int arg_strict_filtering = DEFAULT_STRICT_FILTERING; static int arg_check_runtime = DEFAULT_CHECK_RUNTIME; static int init_time_elapsed; static int primaries_gone; static time_t drv_startup_time; static time_t primaries_gone_time; static ups_device_t **ups_list; static ups_device_t *primary_ups; static ups_device_t *last_primary_ups; static size_t ups_count; static size_t ups_alive_count; static size_t ups_online_count; static size_t ups_primary_count; static int instcmd(const char *cmdname, const char *extra); static int setvar(const char *varname, const char *val); static void handle_arguments(void); static void parse_port_argument(void); static void parse_status_filters(void); static void handle_connections(void); static void export_driver_state(void); static void handle_no_primaries(void); static int handle_init_time(const ups_device_t *primary_candidate); static int ups_connect(ups_device_t *ups); static int ups_read_data(ups_device_t *ups); static void ups_disconnect(ups_device_t *ups); static int ups_parse_protocol(ups_device_t *ups, size_t numargs, char **arg); static int is_ups_alive(ups_device_t *ups); static void ups_is_alive(ups_device_t *ups); static void ups_is_dead(ups_device_t *ups); static void ups_is_online(ups_device_t *ups); static void ups_is_offline(ups_device_t *ups); static ups_device_t *get_primary_candidate(void); static int ups_passes_status_filters(const ups_device_t *ups); static int has_better_runtime(int rt, int rt_low, int best_rt, int best_rt_low, int mode); static void ups_promote_primary(ups_device_t *ups); static void ups_demote_primary(ups_device_t *ups); static void ups_export_dstate(ups_device_t *ups); static void ups_clean_dstate(const ups_device_t *ups); static int ups_get_cmd_pos(const ups_device_t *ups, const char *cmd); static int ups_add_cmd(ups_device_t *ups, const char *val); static int ups_del_cmd(ups_device_t *ups, const char *val); static int ups_get_var_pos(const ups_device_t *ups, const char *key); static int ups_set_var(ups_device_t *ups, const char *key, const char *value); static int ups_del_var(ups_device_t *ups, const char *key); static int ups_set_var_flags(ups_device_t *ups, const char *key, const int flag); static int ups_set_var_aux(ups_device_t *ups, const char *key, const long aux); static int ups_add_range(ups_device_t *ups, const char *varkey, const int min, const int max); static int ups_del_range(ups_device_t *ups, const char *varkey, const int min, const int max); static int ups_add_enum(ups_device_t *ups, const char *varkey, const char *enumval); static int ups_del_enum(ups_device_t *ups, const char *varkey, const char *enumval); static void free_status_filters(void); static void ups_free_ups_state(ups_device_t *ups); static void ups_free_var_state(ups_var_t *var); static const char *rewrite_driver_prefix(const char *in, char *out, size_t outlen); static int str_arg_to_int(const char *arg, const char *argval, int *destvar, int defval, int min, int max); static ssize_t csv_arg_to_array(const char *arg, const char *argcsv, char ***array, size_t *countvar); static inline void ups_set_flag(ups_device_t *ups, ups_flags_t flag); static inline void ups_clear_flag(ups_device_t *ups, ups_flags_t flag); static inline int ups_has_flag(const ups_device_t *ups, ups_flags_t flag); void upsdrv_initups(void) { handle_arguments(); } void upsdrv_initinfo(void) { char buf[SMALLBUF]; size_t i = 0; int required = -1; for (i = 0; i < ups_count; ++i) { ups_device_t *ups = ups_list[i]; ups_connect(ups); required = snprintf(buf, sizeof(buf), "%s.force.ignore", ups->socketname); dstate_addcmd(buf); if ((size_t)required >= sizeof(buf)) { upslogx(LOG_WARNING, "%s: truncated administrative command size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)required, sizeof(buf), buf); } required = snprintf(buf, sizeof(buf), "%s.force.primary", ups->socketname); dstate_addcmd(buf); if ((size_t)required >= sizeof(buf)) { upslogx(LOG_WARNING, "%s: truncated administrative command size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)required, sizeof(buf), buf); } } if (!ups_alive_count) { upslogx(LOG_WARNING, "%s: none of the tracked UPS drivers were connectable", __func__); } status_init(); status_set("WAIT"); status_commit(); time(&drv_startup_time); upsh.instcmd = instcmd; upsh.setvar = setvar; dstate_dataok(); } void upsdrv_updateinfo(void) { ups_device_t *primary_candidate = NULL; handle_connections(); primary_candidate = get_primary_candidate(); export_driver_state(); if (handle_init_time(primary_candidate)) { return; } if (!primary_candidate) { handle_no_primaries(); return; } if (primaries_gone) { if (primary_candidate == primary_ups) { /* Special handling for fsdmode 0 where primary was never demoted */ upslogx(LOG_NOTICE, "%s: [%s] was declared to be a suitable primary (again)", __func__, primary_candidate->socketname); ups_clean_dstate(primary_candidate); primary_candidate->force_dstate_export = 1; } primaries_gone = 0; primaries_gone_time = 0; } if (primary_ups != primary_candidate) { ups_promote_primary(primary_candidate); } else { ups_export_dstate(primary_ups); } if(!ups_has_flag(primary_candidate, UPS_FLAG_DATA_OK)) { dstate_datastale(); return; } dstate_dataok(); } void upsdrv_shutdown(void) { upslogx(LOG_ERR, "%s: %s: Shutdown is not supported by this proxying driver. " "Upstream drivers may implement their own shutdown handling, which would be " "called directly or by upsdrvctl to shut down any specific upstream driver.", progname, __func__); if (handling_upsdrv_shutdown > 0) { set_exit_flag(EF_EXIT_FAILURE); } } void upsdrv_help(void) { } void upsdrv_makevartable(void) { char buf[SMALLBUF]; snprintf(buf, sizeof(buf), "Grace period in seconds during which no primaries found are " "acceptable (for driver startup) (default: %d)", arg_init_timeout); addvar(VAR_VALUE, "inittime", buf); snprintf(buf, sizeof(buf), "Grace period in seconds after which a non-responsive UPS " "driver is considered dead (default: %d)", arg_dead_timeout); addvar(VAR_VALUE, "deadtime", buf); snprintf(buf, sizeof(buf), "Grace period in seconds until connection failures are logged " "again (to reduce spamming logs) (default: %d)", arg_relog_timeout); addvar(VAR_VALUE, "relogtime", buf); snprintf(buf, sizeof(buf), "Grace period in seconds until 'fsdmode' is entered into after " "not finding any primaries (default: %d)", arg_noprimary_timeout); addvar(VAR_VALUE, "noprimarytime", buf); snprintf(buf, sizeof(buf), "Maximum amount of failures connecting to a driver until " "'coolofftime' is entered into (default: %d)", arg_maxconnfails); addvar(VAR_VALUE, "maxconnfails", buf); snprintf(buf, sizeof(buf), "Period in seconds during which driver connections are not " "retried after exceeding 'maxconnfails' (default: %d)", arg_coolofftimeout); addvar(VAR_VALUE, "coolofftime", buf); snprintf(buf, sizeof(buf), "Sets no primary behavior (0: last primary data + stale, 1: no " "data + alarm + stale, 2: no data + fsd + alarm) (default: %d)", arg_fsdmode); addvar(VAR_VALUE, "fsdmode", buf); snprintf(buf, sizeof(buf), "Sets if runtime remaining variables should resolve ties for non-OL priorities " "3 and lower (0: disabled, 1: runtime, 2: runtime low, 3: both) (default: %d)", arg_check_runtime); addvar(VAR_VALUE, "checkruntime", buf); snprintf(buf, sizeof(buf), "Sets if only the given status filters should be considered for " "UPS driver to be electable as primary (default: %d)", arg_strict_filtering); addvar(VAR_VALUE, "strictfiltering", buf); addvar(VAR_VALUE, "status_have_any", "Comma separated list of status tokens, any present qualifies " "the UPS driver for primary (default: unset)"); addvar(VAR_VALUE, "status_have_all", "Comma separated list of status tokens, only all present " "qualifies the UPS driver for primary (default: unset)"); addvar(VAR_VALUE, "status_nothave_any", "Comma separated list of status tokens, any present disqualifies " "the UPS driver for primary (default: unset)"); addvar(VAR_VALUE, "status_nothave_all", "Comma separated list of status tokens, only all present " "disqualifies the UPS driver for primary (default: unset)"); } void upsdrv_cleanup(void) { size_t i = 0; for (i = 0; i < ups_count; ++i) { ups_device_t *ups = ups_list[i]; if (ups) { if (primary_ups == ups) { primary_ups = NULL; } if (last_primary_ups == ups) { last_primary_ups = NULL; } ups_disconnect(ups); /* free conn + ctx */ ups_free_ups_state(ups); /* free status, vars, subvars + cmds */ if (ups->socketname) { free(ups->socketname); ups->socketname = NULL; } free(ups); ups_list[i] = NULL; } } if (ups_list) { free(ups_list); ups_list = NULL; } free_status_filters(); /* free status filters */ } static int instcmd(const char *cmdname, const char *extra) { size_t i = 0; upsdebug_INSTCMD_STARTING(cmdname, extra); for (i = 0; i < ups_count; ++i) { ups_device_t *ups = ups_list[i]; size_t len = strlen(ups->socketname); if (!strncmp(cmdname, ups->socketname, len)) { const char *subcmd = cmdname + len; if (!strcmp(subcmd, ".force.ignore")) { time_t now; int ignoreval = 0; if (extra && !str_to_int(extra, &ignoreval, 10)) { upslogx(LOG_INSTCMD_CONVERSION_FAILED, "%s: " "conversion failed setting [force_ignore] to [%s] on [%s]", __func__, extra, ups->socketname); return STAT_INSTCMD_CONVERSION_FAILED; } time(&now); ups->force_ignore = ignoreval; ups->force_ignore_time = ignoreval ? now : 0; upslogx(LOG_NOTICE, "%s: set [force_ignore] to [%d] on [%s]", __func__, ups->force_ignore, ups->socketname); return STAT_INSTCMD_HANDLED; } if (!strcmp(subcmd, ".force.primary")) { time_t now; int primaryval = 0; if (extra && !str_to_int(extra, &primaryval, 10)) { upslogx(LOG_INSTCMD_CONVERSION_FAILED, "%s: " "conversion failed setting [force_primary] to [%s] on [%s]", __func__, extra, ups->socketname); return STAT_INSTCMD_CONVERSION_FAILED; } time(&now); ups->force_primary = primaryval; ups->force_primary_time = primaryval ? now : 0; upslogx(LOG_NOTICE, "%s: set [force_primary] to [%d] on [%s]", __func__, ups->force_primary, ups->socketname); return STAT_INSTCMD_HANDLED; } } } if (!primary_ups) { upslogx(LOG_INSTCMD_FAILED, "%s: received [%s] [%s], but" "there is currently no elected primary able to handle it", __func__, cmdname, NUT_STRARG(extra)); return STAT_INSTCMD_FAILED; } if(ups_get_cmd_pos(primary_ups, cmdname) >= 0) { const char *cmd = NULL; char msgbuf[SMALLBUF]; struct timeval tv; ssize_t cmdret = -1; int required = -1; if (!strncmp(cmdname, "upstream.", 9)) { cmd = cmdname + 9; upsdebugx(3, "%s: rewriting from [%s] to [%s] for upstream driver", __func__, cmdname, cmd); } else { cmd = cmdname; } if (extra) { required = snprintf(msgbuf, sizeof(msgbuf), "INSTCMD %s %s\n", cmd, extra); } else { required = snprintf(msgbuf, sizeof(msgbuf), "INSTCMD %s\n", cmd); } if ((size_t)required >= sizeof(msgbuf)) { upslogx(LOG_WARNING, "%s: truncated INSTCMD command size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)required, sizeof(msgbuf), msgbuf); } tv.tv_sec = CONN_CMD_TIMEOUT; tv.tv_usec = 0; cmdret = upsdrvquery_oneshot_sockfn(primary_ups->socketname, msgbuf, NULL, 0, &tv); if (cmdret >= 0) { upslogx(LOG_NOTICE, "%s: sent [%s] [%s], " "received response code: [%" PRIiSIZE "]", __func__, cmdname, NUT_STRARG(extra), cmdret); return cmdret; } else { upslog_with_errno(LOG_INSTCMD_FAILED, "%s: sent [%s] [%s], " "received no response code due to socket failure", __func__, cmdname, NUT_STRARG(extra)); return STAT_INSTCMD_FAILED; } } upslogx(LOG_INSTCMD_UNKNOWN, "%s: received [%s] [%s], " "but it is not among the primary's supported commands", __func__, cmdname, NUT_STRARG(extra)); return STAT_INSTCMD_UNKNOWN; } static int setvar(const char *varname, const char *val) { upsdebug_SET_STARTING(varname, val); if (!primary_ups) { upslogx(LOG_SET_FAILED, "%s: received [%s] [%s], but " "there is currently no elected primary able to handle it", __func__, varname, val); return STAT_SET_FAILED; } if(ups_get_var_pos(primary_ups, varname) >= 0) { const char *var = NULL; char msgbuf[SMALLBUF]; struct timeval tv; ssize_t cmdret = -1; int required = -1; if (!strncmp(varname, "upstream.", 9)) { var = varname + 9; upsdebugx(3, "%s: rewriting from [%s] to [%s] for upstream driver", __func__, varname, var); } else { var = varname; } required = snprintf(msgbuf, sizeof(msgbuf), "SET %s \"%s\"\n", var, val); if ((size_t)required >= sizeof(msgbuf)) { upslogx(LOG_WARNING, "%s: truncated SET command size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)required, sizeof(msgbuf), msgbuf); } tv.tv_sec = CONN_CMD_TIMEOUT; tv.tv_usec = 0; cmdret = upsdrvquery_oneshot_sockfn(primary_ups->socketname, msgbuf, NULL, 0, &tv); if (cmdret >= 0) { upslogx(LOG_NOTICE, "%s: sent [%s] [%s], " "received response code: [%" PRIiSIZE "]", __func__, varname, val, cmdret); return cmdret; } else { upslog_with_errno(LOG_SET_FAILED, "%s: sent [%s] [%s], " "received no response code due to socket failure", __func__, varname, val); return STAT_SET_FAILED; } } upslogx(LOG_SET_UNKNOWN, "%s: received [%s] [%s], " "but it is not among the primary's supported variables", __func__, varname, val); return STAT_SET_UNKNOWN; } static void handle_arguments(void) { parse_port_argument(); parse_status_filters(); str_arg_to_int("inittime", getval("inittime"), &arg_init_timeout, DEFAULT_INIT_TIMEOUT, 0, INT_MAX); str_arg_to_int("deadtime", getval("deadtime"), &arg_dead_timeout, DEFAULT_DEAD_TIMEOUT, 0, INT_MAX); str_arg_to_int("relogtime", getval("relogtime"), &arg_relog_timeout, DEFAULT_RELOG_TIMEOUT, 0, INT_MAX); str_arg_to_int("noprimarytime", getval("noprimarytime"), &arg_noprimary_timeout, DEFAULT_NO_PRIMARY_TIMEOUT, 0, INT_MAX); str_arg_to_int("maxconnfails", getval("maxconnfails"), &arg_maxconnfails, DEFAULT_MAX_CONNECT_FAILS, 0, INT_MAX); str_arg_to_int("coolofftime", getval("coolofftime"), &arg_coolofftimeout, DEFAULT_CONNECTION_COOLOFF, 0, INT_MAX); str_arg_to_int("fsdmode", getval("fsdmode"), &arg_fsdmode, DEFAULT_FSD_MODE, 0, 2); str_arg_to_int("checkruntime", getval("checkruntime"), &arg_check_runtime, DEFAULT_CHECK_RUNTIME, 0, 3); str_arg_to_int("strictfiltering", getval("strictfiltering"), &arg_strict_filtering, DEFAULT_STRICT_FILTERING, 0, 1); } static void parse_port_argument(void) { char *tmp = NULL; char *token = NULL; const char *str = device_path; if (!device_path) { fatalx(EXIT_FAILURE, "%s: %s: device_path ('port' argument) is NULL", progname, __func__); } tmp = xstrdup(str); token = strtok(tmp, ","); while (token) { ups_device_t *new_ups = NULL; str_trim_space(token); if (*token == '\0') { token = strtok(NULL, ","); continue; } new_ups = xcalloc(1, sizeof(**ups_list)); new_ups->socketname = xstrdup(token); ups_list = xrealloc(ups_list, sizeof(*ups_list) * (ups_count + 1)); ups_list[ups_count] = new_ups; ups_count++; upsdebugx(1, "%s: [%s]: was added to the list of tracked UPS drivers", __func__, new_ups->socketname); token = strtok(NULL, ","); } free(tmp); tmp = NULL; } static void parse_status_filters(void) { csv_arg_to_array("status_have_any", getval("status_have_any"), &arg_status_filters.have_any, &arg_status_filters.have_any_count); csv_arg_to_array("status_have_all", getval("status_have_all"), &arg_status_filters.have_all, &arg_status_filters.have_all_count); csv_arg_to_array("status_nothave_any", getval("status_nothave_any"), &arg_status_filters.nothave_any, &arg_status_filters.nothave_any_count); csv_arg_to_array("status_nothave_all", getval("status_nothave_all"), &arg_status_filters.nothave_all, &arg_status_filters.nothave_all_count); } static void handle_connections(void) { size_t i = 0; for (i = 0; i < ups_count; ++i) { ups_device_t *ups = ups_list[i]; if (!ups_has_flag(ups, UPS_FLAG_ALIVE) && !ups_connect(ups)) { /* Reconnecting a dead UPS has failed... skip it */ continue; } else if (!is_ups_alive(ups)) { /* UPS is dead long enough... disconnect it */ upslogx(LOG_WARNING, "%s: [%s]: connection to UPS driver was lost (declared dead)", __func__, ups->socketname); ups_disconnect(ups); continue; } if (ups_read_data(ups) < 0 ) { /* Socket failure... warrants immediate disconnect */ upslog_with_errno(LOG_ERR, "%s: [%s]: connection to UPS driver was lost (socket failure)", __func__, ups->socketname); ups_disconnect(ups); } } } static void export_driver_state(void) { dstate_setinfo("driver.stats.alive_drivers", "%" PRIuSIZE, ups_alive_count); dstate_setinfo("driver.stats.online_drivers", "%" PRIuSIZE, ups_online_count); dstate_setinfo("driver.stats.primary_drivers", "%" PRIuSIZE, ups_primary_count); dstate_setinfo("driver.stats.total_drivers", "%" PRIuSIZE, ups_count); if (primary_ups) { dstate_setinfo("driver.primary.socketname", "%s", primary_ups->socketname); dstate_setinfo("driver.primary.priority", "%d", primary_ups->priority); dstate_setinfo("driver.primary.stats.cmds", "%" PRIuSIZE, primary_ups->cmd_count); dstate_setinfo("driver.primary.stats.vars", "%" PRIuSIZE, primary_ups->var_count); } else { dstate_delinfo("driver.primary.socketname"); dstate_delinfo("driver.primary.priority"); dstate_delinfo("driver.primary.stats.cmds"); dstate_delinfo("driver.primary.stats.vars"); } upsdebugx(5, "%s: exported internal driver state to dstate", __func__); } static void handle_no_primaries(void) { time_t now; double elapsed; if (!primaries_gone_time) { time(&primaries_gone_time); } if (primary_ups && arg_fsdmode > 0) { ups_demote_primary(primary_ups); } time(&now); elapsed = difftime(now, primaries_gone_time); if (elapsed > arg_noprimary_timeout) { if (!primaries_gone) { upslogx(LOG_WARNING, "%s: none of the tracked UPS drivers are suitable primaries", __func__); } switch (arg_fsdmode) { case 0: if (!primaries_gone) { upslogx(LOG_WARNING, "%s: 'fsdmode' is [0]: " "keeping last primary and declaring data stale immediately", __func__); } dstate_datastale(); break; case 1: if (!primaries_gone) { upslogx(LOG_WARNING, "%s: 'fsdmode' is [1]: " "demoting last primary, raising alarm, and declaring data stale " "after another %d seconds elapse to ensure full ALARM propagation", __func__, ALARM_PROPAG_TIME); } /* dstate is already clean at this point, hence no _init() calls */ alarm_set("No suitable primaries for failover"); alarm_commit(); status_commit(); /* publish ALARM */ if (elapsed < arg_noprimary_timeout + ALARM_PROPAG_TIME) { /* make sure ALARM propagates to all clients first... */ dstate_dataok(); } else { /* ... and then eventually declare the data as stale */ dstate_datastale(); } break; case 2: if (!primaries_gone) { upslogx(LOG_WARNING, "%s: 'fsdmode' is [2]: " "demoting last primary, raising alarm, and setting FSD", __func__); } /* dstate is already clean at this point, hence no _init() calls */ status_set("FSD"); alarm_set("No suitable primaries for failover"); alarm_commit(); status_commit(); /* publish ALARM + FSD */ dstate_dataok(); break; default: /* Should never happen, as we validate the argument */ if (!primaries_gone) { upslogx(LOG_WARNING, "%s: 'fsdmode' has unknown value [%d]: " "keeping last primary and declaring data stale immediately", __func__, arg_fsdmode); } dstate_datastale(); break; } primaries_gone = 1; } else { upslogx(LOG_WARNING, "%s: No suitable primaries, " "waiting for one to emerge... (%.0fs of %ds max)", __func__, elapsed, arg_noprimary_timeout); dstate_dataok(); } } static int handle_init_time(const ups_device_t *primary_candidate) { if (!init_time_elapsed) { time_t now; double elapsed; time(&now); elapsed = difftime(now, drv_startup_time); if (!primary_candidate && elapsed <= arg_init_timeout) { upslogx(LOG_NOTICE, "%s: still waiting for " "first primary to emerge... (%.0fs of %ds max), if this was " "too short for drivers to start, consider increasing 'inittime'", __func__, elapsed, arg_init_timeout); dstate_dataok(); return 1; } init_time_elapsed = 1; } return 0; } static int ups_connect(ups_device_t *ups) { time_t now; double elapsed; int ret = 0; int report_failure = 1; udq_pipe_conn_t *conn = NULL; time(&now); elapsed = difftime(now, ups->last_failure_time); if (ups->failure_count > arg_maxconnfails && elapsed <= arg_coolofftimeout) { upsdebugx(4, "%s: [%s]: not retrying in cooloff phase (%.0fs < %ds max)", __func__, ups->socketname, elapsed, arg_coolofftimeout); return 0; } if (nut_debug_level < 1 && elapsed <= arg_relog_timeout) { report_failure = 0; nut_upsdrvquery_debug_level = 0; } else { report_failure = 1; nut_upsdrvquery_debug_level = NUT_UPSDRVQUERY_DEBUG_LEVEL_DEFAULT; } conn = upsdrvquery_connect(ups->socketname); if (conn) { pconf_init(&ups->parse_ctx, NULL); ups->conn = conn; upslogx(LOG_NOTICE, "%s: [%s]: connection is now established", __func__, ups->socketname); if (upsdrvquery_write(ups->conn, "DUMPALL\n") >= 0) { ups_free_ups_state(ups); /* free any previous state */ ups->force_dstate_export = 1; ups->runtime = -1; ups->runtime_low = -1; ups_is_alive(ups); time(&ups->last_heard_time); ups->failure_count = 0; ups->last_failure_time = 0; upsdebugx(2, "%s: [%s]: requested first batch of data (DUMPALL)", __func__, ups->socketname); ret = 1; } else { if (report_failure) { upslog_with_errno(LOG_ERR, "%s: [%s]: communication failed " "sending DUMPALL, disconnecting and re-trying it later", __func__, ups->socketname); } ups_disconnect(ups); ups->failure_count++; ups->last_failure_time = now; ret = 0; } } else { if (report_failure) { upslog_with_errno(LOG_ERR, "%s: [%s]: failed to establish connection", __func__, ups->socketname); } ups->failure_count++; ups->last_failure_time = now; ret = 0; } nut_upsdrvquery_debug_level = NUT_UPSDRVQUERY_DEBUG_LEVEL_DEFAULT; return ret; } static int ups_read_data(ups_device_t *ups) { int i = 0; ssize_t ret; struct timeval tv; tv.tv_sec = CONN_READ_TIMEOUT; tv.tv_usec = 0; ret = upsdrvquery_read_timeout(ups->conn, tv); if (ret == -1) { upsdebug_with_errno(2, "%s: [%s]: read from UPS driver has failed", __func__, ups->socketname); return ret; } if (ret == -2) { upsdebug_with_errno(2, "%s: [%s]: read from UPS driver has timed out", __func__, ups->socketname); return ret; } for (i = 0; i < ret; ++i) { switch (pconf_char(&ups->parse_ctx, ups->conn->buf[i])) { case 1: if (ups_parse_protocol(ups, ups->parse_ctx.numargs, ups->parse_ctx.arglist)) { time(&ups->last_heard_time); } continue; case 0: continue; /* no complete line yet */ default: upsdebug_with_errno(2, "%s: [%s]: parse error on read data: %s", __func__, ups->socketname, ups->parse_ctx.errmsg); return -1; } } return ret; } static void ups_disconnect(ups_device_t *ups) { ups_is_dead(ups); pconf_finish(&ups->parse_ctx); ups->flags = UPS_FLAG_NONE; if (ups->conn) { upsdrvquery_close(ups->conn); free(ups->conn); ups->conn = NULL; } upsdebugx(2, "%s: [%s]: connection was destroyed", __func__, ups->socketname); } static int ups_parse_protocol(ups_device_t *ups, size_t numargs, char **arg) { char buf[SMALLBUF]; const char *varptr = NULL; int required = -1; if (numargs < 1) { goto skip_out; } if (!strcasecmp(arg[0], "PONG")) { upsdebugx(6, "%s: [%s]: got PONG from UPS driver", __func__, ups->socketname); return 1; } if (!strcasecmp(arg[0], "DUMPDONE")) { upsdebugx(6, "%s: [%s]: got DUMPDONE from UPS driver", __func__, ups->socketname); ups_set_flag(ups, UPS_FLAG_DUMPED); return 1; } if (!strcasecmp(arg[0], "DATASTALE")) { upsdebugx(6, "%s: [%s]: got DATASTALE from UPS driver", __func__, ups->socketname); ups_clear_flag(ups, UPS_FLAG_DATA_OK); return 1; } if (!strcasecmp(arg[0], "DATAOK")) { upsdebugx(6, "%s: [%s]: got DATAOK from UPS driver", __func__, ups->socketname); ups_set_flag(ups, UPS_FLAG_DATA_OK); return 1; } if (numargs < 2) { goto skip_out; } /* DELCMD */ if (!strcasecmp(arg[0], "DELCMD")) { upsdebugx(6, "%s: [%s]: got DELCMD [%s] from UPS driver", __func__, ups->socketname, arg[1]); required = snprintf(buf, sizeof(buf), "upstream.%s", arg[1]); if ((size_t)required >= sizeof(buf)) { upslogx(LOG_WARNING, "%s: truncated DELCMD command size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)required, sizeof(buf), buf); } ups_del_cmd(ups, buf); return 1; } /* ADDCMD */ if (!strcasecmp(arg[0], "ADDCMD")) { upsdebugx(6, "%s: [%s]: got ADDCMD [%s] from UPS driver", __func__, ups->socketname, arg[1]); required = snprintf(buf, sizeof(buf), "upstream.%s", arg[1]); if ((size_t)required >= sizeof(buf)) { upslogx(LOG_WARNING, "%s: truncated ADDCMD command size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)required, sizeof(buf), buf); } ups_add_cmd(ups, buf); return 1; } /* DELINFO */ if (!strcasecmp(arg[0], "DELINFO")) { varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); upsdebugx(6, "%s: [%s]: got DELINFO [%s] from UPS driver", __func__, ups->socketname, arg[1]); ups_del_var(ups, varptr); return 1; } if (numargs < 3) { goto skip_out; } /* SETFLAGS ... */ if (!strcasecmp(arg[0], "SETFLAGS")) { size_t i = 0; int varflags = 0; varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); upsdebugx(6, "%s: [%s]: got SETFLAGS [%s] from UPS driver", __func__, ups->socketname, arg[1]); for (i = 2; i < numargs; ++i) { if (!strcasecmp(arg[i], "RW")) { varflags |= ST_FLAG_RW; } else if (!strcasecmp(arg[i], "STRING")) { varflags |= ST_FLAG_STRING; } else if (!strcasecmp(arg[i], "NUMBER")) { varflags |= ST_FLAG_NUMBER; } else { upsdebugx(6, "%s: [%s]: got unknown SETFLAGS [%s] from UPS driver", __func__, ups->socketname, arg[i]); } } ups_set_var_flags(ups, varptr, varflags); return 1; } /* SETAUX */ if (!strcasecmp(arg[0], "SETAUX")) { long auxval; varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); if (str_to_long(arg[2], &auxval, 10)) { upsdebugx(6, "%s: [%s]: got SETAUX [%s] from UPS driver", __func__, ups->socketname, arg[1]); ups_set_var_aux(ups, varptr, auxval); } else { upsdebugx(5, "%s: [%s]: got non-numeric SETAUX [%s] from UPS driver", __func__, ups->socketname, arg[1]); } return 1; } /* DELENUM */ if (!strcasecmp(arg[0], "DELENUM")) { varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); upsdebugx(6, "%s: [%s]: got DELENUM [%s] from UPS driver", __func__, ups->socketname, arg[1]); ups_del_enum(ups, varptr, arg[2]); return 1; } /* ADDENUM */ if (!strcasecmp(arg[0], "ADDENUM")) { varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); upsdebugx(6, "%s: [%s]: got ADDENUM [%s] from UPS driver", __func__, ups->socketname, arg[1]); ups_add_enum(ups, varptr, arg[2]); return 1; } /* SETINFO */ if (!strcasecmp(arg[0], "SETINFO")) { varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); upsdebugx(6, "%s: [%s]: got SETINFO [%s] from UPS driver", __func__, ups->socketname, arg[1]); if (!strcmp(arg[1], "ups.status")) { if (ups->status) { free(ups->status); ups->status = NULL; } ups->status = xstrdup(arg[2]); if(str_contains_token(arg[2], "OL")) { ups_is_online(ups); } else { ups_is_offline(ups); } } if (!strcmp(arg[1], "battery.runtime")) { if (!str_to_int(arg[2], &ups->runtime, 10)) { ups->runtime = -1; } } if (!strcmp(arg[1], "battery.runtime.low")) { if (!str_to_int(arg[2], &ups->runtime_low, 10)) { ups->runtime_low = -1; } } ups_set_var(ups, varptr, arg[2]); return 1; } if (numargs < 4) { goto skip_out; } /* DELRANGE */ if (!strcasecmp(arg[0], "DELRANGE")) { int minval; int maxval; varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); if (str_to_int(arg[2], &minval, 10) && str_to_int(arg[3], &maxval, 10)) { upsdebugx(6, "%s: [%s]: got DELRANGE [%s] from UPS driver", __func__, ups->socketname, arg[1]); ups_del_range(ups, varptr, minval, maxval); } else { upsdebugx(5, "%s: [%s]: got non-numeric DELRANGE [%s] from UPS driver", __func__, ups->socketname, arg[1]); } return 1; } /* ADDRANGE */ if (!strcasecmp(arg[0], "ADDRANGE")) { int minval; int maxval; varptr = rewrite_driver_prefix(arg[1], buf, sizeof(buf)); if (str_to_int(arg[2], &minval, 10) && str_to_int(arg[3], &maxval, 10)) { upsdebugx(6, "%s: [%s]: got ADDRANGE [%s] from UPS driver", __func__, ups->socketname, arg[1]); ups_add_range(ups, varptr, minval, maxval); } else { upsdebugx(5, "%s: [%s]: got non-numeric ADDRANGE [%s] from UPS driver", __func__, ups->socketname, arg[1]); } return 1; } skip_out: if (nut_debug_level > 0) { char msgbuf[LARGEBUF]; size_t i = 0; int len = -1; memset(msgbuf, 0, sizeof(msgbuf)); for (i = 0; i < numargs; ++i) { len = snprintfcat(msgbuf, sizeof(msgbuf), "[%s] ", arg[i]); } if (len > 0) { msgbuf[len - 1] = '\0'; } if ((size_t)len >= sizeof(msgbuf)) { upsdebugx(6, "%s: truncated DBG output size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)len, sizeof(msgbuf), msgbuf); } upsdebugx(6, "%s: [%s]: ignored protocol line with %" PRIuSIZE " keyword(s): %s", __func__, ups->socketname, numargs, numargs < 1 ? "" : msgbuf); } return 0; } static int is_ups_alive(ups_device_t *ups) { time_t now; double elapsed; if (!ups->conn || INVALID_FD(ups->conn->sockfd)) { upsdebugx(2, "%s: [%s]: socket connection lost - declaring it dead", __func__, ups->socketname); return 0; } time(&now); elapsed = difftime(now, ups->last_heard_time); if ((elapsed > (arg_dead_timeout / 3)) && (difftime(now, ups->last_pinged_time) > (arg_dead_timeout / 3))) { nut_upsdrvquery_debug_level = 0; upsdrvquery_write(ups->conn, "PING\n"); nut_upsdrvquery_debug_level = NUT_UPSDRVQUERY_DEBUG_LEVEL_DEFAULT; upsdebugx(3, "%s: [%s]: have not heard from driver, sent a PING to it", __func__, ups->socketname); ups->last_pinged_time = now; } if (elapsed > arg_dead_timeout) { upsdebugx(2, "%s: [%s]: did not hear from driver " "for at least %.0fs (of %ds max) - declaring it dead", __func__, ups->socketname, elapsed, arg_dead_timeout); return 0; } return 1; } static void ups_is_alive(ups_device_t *ups) { if (!ups_has_flag(ups, UPS_FLAG_ALIVE)) { ups_set_flag(ups, UPS_FLAG_ALIVE); ups_alive_count++; upsdebugx(2, "%s: [%s]: is now alive (alive devices: %" PRIuSIZE ")", __func__, ups->socketname, ups_alive_count); } } static void ups_is_dead(ups_device_t *ups) { if (ups_has_flag(ups, UPS_FLAG_ALIVE)) { ups_alive_count--; upsdebugx(2, "%s: [%s]: is now dead " "with (last known) status [%s] (alive devices: %" PRIuSIZE ")", __func__, ups->socketname, NUT_STRARG(ups->status), ups_alive_count); } if (ups_has_flag(ups, UPS_FLAG_ONLINE)) { ups_online_count--; upsdebugx(3, "%s: [%s]: was online with (last known) " "status [%s] and is now dead (online devices: %" PRIuSIZE ")", __func__, ups->socketname, NUT_STRARG(ups->status), ups_online_count); } } static void ups_is_online(ups_device_t *ups) { if (!ups_has_flag(ups, UPS_FLAG_ONLINE)) { ups_set_flag(ups, UPS_FLAG_ONLINE); ups_online_count++; upsdebugx(2, "%s: [%s]: is now online " "with status [%s] (online devices: %" PRIuSIZE ")", __func__, ups->socketname, NUT_STRARG(ups->status), ups_online_count); } } static void ups_is_offline(ups_device_t *ups) { if (ups_has_flag(ups, UPS_FLAG_ONLINE)) { ups_clear_flag(ups, UPS_FLAG_ONLINE); ups_online_count--; upsdebugx(2, "%s: [%s]: is now offline " "with status [%s] (online devices: %" PRIuSIZE ")", __func__, ups->socketname, NUT_STRARG(ups->status), ups_online_count); } } static ups_device_t *get_primary_candidate(void) { time_t now; size_t i = 0; size_t primaries = 0; int best_priority = 100; int best_runtime = -1; int best_runtime_low = -1; ups_device_t *best_choice = NULL; time(&now); for (i = 0; i < ups_count; ++i) { int priority = PRIORITY_SKIPPED; ups_device_t *ups = ups_list[i]; double elapsed_ignore = (ups->force_ignore > 0) ? difftime(now, ups->force_ignore_time) : 0; double elapsed_force = (ups->force_primary > 0) ? difftime(now, ups->force_primary_time) : 0; if (ups->force_primary > 0 && (ups->force_primary_time == 0 || elapsed_force > ups->force_primary)) { ups->force_primary = 0; ups->force_primary_time = 0; } else if (ups->force_primary == 0 && ups->force_primary_time > 0) { ups->force_primary_time = 0; } if (ups->force_ignore > 0 && (ups->force_ignore_time == 0 || elapsed_ignore > ups->force_ignore)) { ups->force_ignore = 0; ups->force_ignore_time = 0; } else if (ups->force_ignore == 0 && ups->force_ignore_time > 0) { ups->force_ignore_time = 0; } if (ups_has_flag(ups, (ups_flags_t)(UPS_FLAG_ALIVE | UPS_FLAG_DUMPED))) { if (ups->force_ignore < 0) { ups->priority = PRIORITY_SKIPPED; upsdebugx(4, "%s: [%s]: is permanently ignored and was not considered", __func__, ups->socketname); continue; } else if (ups->force_ignore > 0 && elapsed_ignore <= ups->force_ignore) { ups->priority = PRIORITY_SKIPPED; upsdebugx(4, "%s: [%s]: is currently ignored and not considered (%.0fs of %ds)", __func__, ups->socketname, elapsed_ignore, ups->force_ignore); continue; } else if (ups->force_primary < 0) { priority = PRIORITY_FORCED; upsdebugx(4, "%s: [%s]: is permanently forced to highest priority", __func__, ups->socketname); } else if (ups->force_primary > 0 && elapsed_force <= ups->force_primary) { priority = PRIORITY_FORCED; upsdebugx(4, "%s: [%s]: is currently forced to highest priority (%.0fs of %ds)", __func__, ups->socketname, elapsed_force, ups->force_primary); } else if (ups_passes_status_filters(ups)) { priority = PRIORITY_STATUSFILTERS; } else if (arg_strict_filtering) { upsdebugx(4, "%s: [%s]: 'strict_filtering' is enabled, considering " "only status filters, but not the default set of lower priorities", __func__, ups->socketname); } else if (ups_has_flag(ups, (ups_flags_t)(UPS_FLAG_DATA_OK | UPS_FLAG_ONLINE))) { priority = PRIORITY_ONLINE; } else if (ups_has_flag(ups, UPS_FLAG_DATA_OK)) { priority = PRIORITY_BATTERY; } else { priority = PRIORITY_STALE; } } if (priority >= 0) { int rt = ups->runtime; int rt_low = ups->runtime_low; primaries++; if (priority < best_priority) { best_choice = ups; best_priority = priority; best_runtime = rt; best_runtime_low = rt_low; } else if (priority == best_priority && arg_check_runtime && priority >= PRIORITY_BATTERY) { /* All devices are not fully online and runtime checking is enabled, compare values: */ if (has_better_runtime(rt, rt_low, best_runtime, best_runtime_low, arg_check_runtime)) { best_choice = ups; best_runtime = rt; best_runtime_low = rt_low; } } upsdebugx(4, "%s: [%s]: is a candidate (priority [%d], runtime [%d]/[%d])", __func__, ups->socketname, priority, rt, rt_low); } ups->priority = priority; } ups_primary_count = primaries; if (best_choice) { upsdebugx(4, "%s: [%s]: is best candidate (priority [%d], runtime [%d]/[%d])", __func__, best_choice->socketname, best_priority, best_runtime, best_runtime_low); } return best_choice; } static int ups_passes_status_filters(const ups_device_t *ups) { size_t i = 0; if (!ups->status || *ups->status == '\0') { upsdebugx(4, "%s: [%s]: no status is available, disregarding filtering", __func__, ups->socketname); return 0; } if (arg_status_filters.have_any_count == 0 && arg_status_filters.have_all_count == 0 && arg_status_filters.nothave_any_count == 0 && arg_status_filters.nothave_all_count == 0) { upsdebugx(5, "%s: [%s]: no status filters are set, disregarding filtering", __func__, ups->socketname); return 0; } for (i = 0; i < arg_status_filters.nothave_any_count; ++i) { if (str_contains_token(ups->status, arg_status_filters.nothave_any[i])) { upsdebugx(4, "%s: [%s]: nothave_any: [%s] was found, excluded", __func__, ups->socketname, arg_status_filters.nothave_any[i]); return 0; } } for (i = 0; i < arg_status_filters.have_all_count; ++i) { if (!str_contains_token(ups->status, arg_status_filters.have_all[i])) { upsdebugx(4, "%s: [%s]: have_all: [%s] not found, excluded", __func__, ups->socketname, arg_status_filters.have_all[i]); return 0; } } if (arg_status_filters.nothave_all_count > 0) { int all_found = 1; for (i = 0; i < arg_status_filters.nothave_all_count; ++i) { if (!str_contains_token(ups->status, arg_status_filters.nothave_all[i])) { all_found = 0; break; } } if (all_found) { upsdebugx(4, "%s: [%s]: nothave_all: all were found, excluded", __func__, ups->socketname); return 0; } } if (arg_status_filters.have_any_count > 0) { int any_found = 0; for (i = 0; i < arg_status_filters.have_any_count; ++i) { if (str_contains_token(ups->status, arg_status_filters.have_any[i])) { any_found = 1; break; } } if (!any_found) { upsdebugx(4, "%s: [%s]: have_any: none were found, excluded", __func__, ups->socketname); return 0; } } return 1; } static int has_better_runtime(int rt, int rt_low, int best_rt, int best_rt_low, int mode) { switch (mode) { case 1: /* compare runtime */ return rt > best_rt; case 2: /* compare runtime low */ return rt_low > best_rt_low; case 3: /* compare runtime + runtime low */ return (rt > best_rt && rt_low > best_rt_low); default: /* invalid mode */ return 0; } } static void ups_promote_primary(ups_device_t *ups) { if (!ups || primary_ups == ups) { upslogx(LOG_WARNING, "%s: Unsupported function call, " "argument was either NULL or a UPS driver already declared as primary. " "Please notify the NUT developers (on GitHub) to check this driver's code.", __func__); return; } if (primary_ups) { ups_demote_primary(primary_ups); } primary_ups = ups; primary_ups->force_dstate_export = 1; ups_set_flag(ups, UPS_FLAG_PRIMARY); upslogx(LOG_NOTICE, "%s: [%s]: was promoted " "to primary with status [%s] and priority [%d]", __func__, primary_ups->socketname, NUT_STRARG(primary_ups->status), primary_ups->priority); ups_export_dstate(primary_ups); } static void ups_demote_primary(ups_device_t *ups) { last_primary_ups = ups; primary_ups = NULL; ups_clear_flag(last_primary_ups, UPS_FLAG_PRIMARY); upslogx(LOG_NOTICE, "%s: [%s]: is no longer " "primary with (last known) status [%s] and priority [%d]", __func__, last_primary_ups->socketname, NUT_STRARG(last_primary_ups->status), last_primary_ups->priority); ups_clean_dstate(last_primary_ups); } static void ups_export_dstate(ups_device_t *ups) { size_t i = 0; if (ups->force_dstate_export) { status_init(); alarm_init(); } for (i = 0; i < ups->cmd_count; ++i) { ups_cmd_t *cmd = ups->cmd_list[i]; if (cmd->needs_export || ups->force_dstate_export) { dstate_addcmd(cmd->value); upsdebugx(5, "%s: [%s]: exported command to dstate: [%s]", __func__, ups->socketname, cmd->value); cmd->needs_export = 0; } } for (i = 0; i < ups->var_count; ++i) { ups_var_t *var = ups->var_list[i]; if (var->needs_export || ups->force_dstate_export) { size_t j = 0; if (!strcmp(var->key, "ups.alarm")) { alarm_init(); alarm_set(var->value); alarm_commit(); status_commit(); /* publish ALARM */ upsdebugx(5, "%s: [%s]: exported UPS alarm to dstate: [%s] : [%s]", __func__, ups->socketname, var->key, var->value); } else if (!strcmp(var->key, "ups.status")) { status_init(); status_set(var->value); status_commit(); upsdebugx(5, "%s: [%s]: exported UPS status to dstate: [%s] : [%s]", __func__, ups->socketname, var->key, var->value); } else { dstate_setinfo(var->key, "%s", var->value); upsdebugx(5, "%s: [%s]: exported variable to dstate: [%s] : [%s]", __func__, ups->socketname, var->key, var->value); } if (var->flags) { dstate_setflags(var->key, var->flags); upsdebugx(5, "%s: [%s]: exported variable flags to dstate: [%s] : [%d]", __func__, ups->socketname, var->key, var->flags); } if (var->aux) { dstate_setaux(var->key, var->aux); upsdebugx(5, "%s: [%s]: exported variable aux to dstate: [%s] : [%ld]", __func__, ups->socketname, var->key, var->aux); } for (j = 0; j < var->enum_count; ++j) { dstate_addenum(var->key, "%s", var->enum_list[j]); upsdebugx(5, "%s: [%s]: exported variable enum to dstate: [%s] : [%s]", __func__, ups->socketname, var->key, var->enum_list[j]); } for (j = 0; j < var->range_count; ++j) { dstate_addrange(var->key, var->range_list[j]->min, var->range_list[j]->max); upsdebugx(5, "%s: [%s]: exported variable range to dstate: [%s] : min=[%d] : max=[%d]", __func__, ups->socketname, var->key, var->range_list[j]->min, var->range_list[j]->max); } var->needs_export = 0; } } if (ups->force_dstate_export) { alarm_commit(); status_commit(); } ups->force_dstate_export = 0; } static void ups_clean_dstate(const ups_device_t *ups) { size_t i = 0; status_init(); alarm_init(); for (i = 0; i < ups->cmd_count; ++i) { dstate_delcmd(ups->cmd_list[i]->value); upsdebugx(5, "%s: [%s]: removed command from dstate: [%s]", __func__, ups->socketname, ups->cmd_list[i]->value); } for (i = 0; i < ups->var_count; ++i) { dstate_delinfo(ups->var_list[i]->key); upsdebugx(5, "%s: [%s]: removed variable from dstate: [%s]", __func__, ups->socketname, ups->var_list[i]->key); } alarm_commit(); status_commit(); } static int ups_get_cmd_pos(const ups_device_t *ups, const char *cmd) { size_t i = 0; for (i = 0; i < ups->cmd_count; ++i) { if (!strcmp(ups->cmd_list[i]->value, cmd)) { return i; } } return -1; } static int ups_add_cmd(ups_device_t *ups, const char *val) { ups_cmd_t *new_cmd = NULL; if (ups_get_cmd_pos(ups, val) >= 0) { return 0; } if (ups->cmd_count >= ups->cmd_allocs) { ups->cmd_list = xrealloc(ups->cmd_list, sizeof(*ups->cmd_list) * (ups->cmd_allocs + CMD_ALLOC_BATCH)); memset(ups->cmd_list + ups->cmd_allocs, 0, sizeof(*ups->cmd_list) * CMD_ALLOC_BATCH); ups->cmd_allocs = ups->cmd_allocs + CMD_ALLOC_BATCH; } new_cmd = xcalloc(1, sizeof(**ups->cmd_list)); new_cmd->value = xstrdup(val); new_cmd->needs_export = 1; ups->cmd_list[ups->cmd_count] = new_cmd; ups->cmd_count++; upsdebugx(5, "%s: [%s]: added to ups->cmd_list: [%s]", __func__, ups->socketname, val); return 1; } static int ups_del_cmd(ups_device_t *ups, const char *val) { int cmd_pos = ups_get_cmd_pos(ups, val); if (cmd_pos >= 0) { ups_cmd_t *cmd = ups->cmd_list[cmd_pos]; size_t i = 0; if (primary_ups == ups) { dstate_delcmd(val); upsdebugx(5, "%s: [%s]: removed command from dstate: [%s]", __func__, ups->socketname, val); } free(cmd->value); free(cmd); for (i = cmd_pos; i < ups->cmd_count - 1; ++i) { ups->cmd_list[i] = ups->cmd_list[i + 1]; } ups->cmd_list[ups->cmd_count - 1] = NULL; ups->cmd_count--; if (ups->cmd_count == 0) { free(ups->cmd_list); ups->cmd_list = NULL; ups->cmd_allocs = 0; } else if (ups->cmd_count % CMD_ALLOC_BATCH == 0) { ups->cmd_list = xrealloc(ups->cmd_list, sizeof(*ups->cmd_list) * ups->cmd_count); ups->cmd_allocs = ups->cmd_count; } upsdebugx(5, "%s: [%s]: removed from ups->cmd_list: [%s]", __func__, ups->socketname, val); return 1; } upsdebugx(6, "%s: [%s]: not found in ups->cmd_list: [%s]", __func__, ups->socketname, val); return 0; } static int ups_get_var_pos(const ups_device_t *ups, const char *key) { size_t i = 0; for (i = 0; i < ups->var_count; ++i) { if (!strcmp(ups->var_list[i]->key, key)) { return i; } } return -1; } static int ups_set_var(ups_device_t *ups, const char *key, const char *value) { ups_var_t *new_var = NULL; int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { ups_var_t *var = ups->var_list[var_pos]; if (strcmp(var->value, value)) { free(var->value); var->value = xstrdup(value); var->needs_export = 1; upsdebugx(5, "%s: [%s]: updated in ups->var_list: [%s] : [%s]", __func__, ups->socketname, key, value); return 1; } else { upsdebugx(6, "%s: [%s]: unchanged in ups->var_list: [%s] : [%s]", __func__, ups->socketname, key, value); return 1; } } if (ups->var_count >= ups->var_allocs) { ups->var_list = xrealloc(ups->var_list, sizeof(*ups->var_list) * (ups->var_allocs + VAR_ALLOC_BATCH)); memset(ups->var_list + ups->var_allocs, 0, sizeof(*ups->var_list) * VAR_ALLOC_BATCH); ups->var_allocs = ups->var_allocs + VAR_ALLOC_BATCH; } new_var = xcalloc(1, sizeof(**ups->var_list)); new_var->key = xstrdup(key); new_var->value = xstrdup(value); new_var->needs_export = 1; ups->var_list[ups->var_count] = new_var; ups->var_count++; upsdebugx(5, "%s: [%s]: stored in ups->var_list: [%s] : [%s]", __func__, ups->socketname, key, value); return 1; } static int ups_del_var(ups_device_t *ups, const char *key) { int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { ups_var_t *var = ups->var_list[var_pos]; size_t i = 0; if (primary_ups == ups) { if (!strcmp(key, "ups.alarm")) { alarm_init(); alarm_commit(); status_commit(); /* clear ALARM */ upsdebugx(5, "%s: [%s]: cleared UPS alarm from dstate: [%s]", __func__, ups->socketname, key); } if (!strcmp(key, "ups.status")) { status_init(); status_commit(); /* clear STATUS */ upsdebugx(5, "%s: [%s]: cleared UPS status from dstate: [%s]", __func__, ups->socketname, key); } dstate_delinfo(key); upsdebugx(5, "%s: [%s]: removed variable from dstate: [%s]", __func__, ups->socketname, key); } ups_free_var_state(var); free(var); for (i = var_pos; i < ups->var_count - 1; ++i) { ups->var_list[i] = ups->var_list[i + 1]; } ups->var_list[ups->var_count - 1] = NULL; ups->var_count--; if (ups->var_count == 0) { free(ups->var_list); ups->var_list = NULL; ups->var_allocs = 0; } else if (ups->var_count % VAR_ALLOC_BATCH == 0) { ups->var_list = xrealloc(ups->var_list, sizeof(*ups->var_list) * ups->var_count); ups->var_allocs = ups->var_count; } upsdebugx(5, "%s: [%s]: removed from ups->var_list: [%s]", __func__, ups->socketname, key); return 1; } upsdebugx(6, "%s: [%s]: not found in ups->var_list: [%s]", __func__, ups->socketname, key); return 0; } static int ups_set_var_flags(ups_device_t *ups, const char *key, const int flags) { int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { ups_var_t *var = ups->var_list[var_pos]; if (var->flags == flags) { upsdebugx(6, "%s: [%s]: unchanged flags in ups->var_list: [%s] : [%d]", __func__, ups->socketname, key, flags); return 0; } var->flags = flags; var->needs_export = 1; upsdebugx(5, "%s: [%s]: stored flags in ups->var_list: [%s] : [%d]", __func__, ups->socketname, key, flags); return 1; } upsdebugx(6, "%s: [%s]: not found in ups->var_list: [%s]", __func__, ups->socketname, key); return 0; } static int ups_set_var_aux(ups_device_t *ups, const char *key, const long aux) { int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { ups_var_t *var = ups->var_list[var_pos]; if (var->aux == aux) { upsdebugx(6, "%s: [%s]: unchanged aux in ups->var_list: [%s] : [%ld]", __func__, ups->socketname, key, aux); return 0; } var->aux = aux; var->needs_export = 1; upsdebugx(5, "%s: [%s]: stored aux in ups->var_list: [%s] : [%ld]", __func__, ups->socketname, key, aux); return 1; } upsdebugx(6, "%s: [%s]: not found in ups->var_list: [%s]", __func__, ups->socketname, key); return 0; } static int ups_add_range(ups_device_t *ups, const char *key, const int min, const int max) { int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { var_range_t *new_range = NULL; ups_var_t *var = ups->var_list[var_pos]; size_t i = 0; for (i = 0; i < var->range_count; ++i) { if (var->range_list[i]->min == min && var->range_list[i]->max == max) { upsdebugx(6, "%s: [%s]: unchanged in ups->var_list->range_list: [%s] : min=[%d] : max=[%d]", __func__, ups->socketname, key, min, max); return 0; } } if (var->range_count >= var->range_allocs) { var->range_list = xrealloc(var->range_list, sizeof(*var->range_list) * (var->range_allocs + SUBVAR_ALLOC_BATCH)); memset(var->range_list + var->range_allocs, 0, sizeof(*var->range_list) * SUBVAR_ALLOC_BATCH); var->range_allocs = var->range_allocs + SUBVAR_ALLOC_BATCH; } new_range = xcalloc(1, sizeof(**var->range_list)); new_range->min = min; new_range->max = max; var->range_list[var->range_count] = new_range; var->range_count++; var->needs_export = 1; upsdebugx(5, "%s: [%s]: added to ups->var_list->range_list: [%s] : min=[%d] : max=[%d]", __func__, ups->socketname, key, min, max); return 1; } upsdebugx(6, "%s: [%s]: not found in ups->var_list: [%s]", __func__, ups->socketname, key); return 0; } static int ups_del_range(ups_device_t *ups, const char *key, const int min, const int max) { int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { ups_var_t *var = ups->var_list[var_pos]; size_t i = 0; for (i = 0; i < var->range_count; ++i) { if (var->range_list[i]->min == min && var->range_list[i]->max == max) { size_t j = 0; if (primary_ups == ups) { dstate_delrange(key, min, max); upsdebugx(5, "%s: [%s]: removed range from dstate: [%s] : min=[%d] : max=[%d]", __func__, ups->socketname, key, min, max); } free(var->range_list[i]); for (j = i; j < var->range_count - 1; ++j) { var->range_list[j] = var->range_list[j + 1]; } var->range_list[var->range_count - 1] = NULL; var->range_count--; if (var->range_count == 0) { free(var->range_list); var->range_list = NULL; var->range_allocs = 0; } else if (var->range_count % SUBVAR_ALLOC_BATCH == 0) { var->range_list = xrealloc(var->range_list, sizeof(*var->range_list) * var->range_count); var->range_allocs = var->range_count; } upsdebugx(5, "%s: [%s]: deleted from ups->var_list->range_list: [%s] : min=[%d] : max=[%d]", __func__, ups->socketname, key, min, max); return 1; } } } upsdebugx(6, "%s: [%s]: not found in ups->var_list: [%s]", __func__, ups->socketname, key); return 0; } static int ups_add_enum(ups_device_t *ups, const char *key, const char *val) { int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { ups_var_t *var = ups->var_list[var_pos]; size_t i = 0; for (i = 0; i < var->enum_count; ++i) { if (!strcmp(var->enum_list[i], val)) { return 0; } } if (var->enum_count >= var->enum_allocs) { var->enum_list = xrealloc(var->enum_list, sizeof(*var->enum_list) * (var->enum_allocs + SUBVAR_ALLOC_BATCH)); memset(var->enum_list + var->enum_allocs, 0, sizeof(*var->enum_list) * SUBVAR_ALLOC_BATCH); var->enum_allocs = var->enum_allocs + SUBVAR_ALLOC_BATCH; } var->enum_list[var->enum_count] = xstrdup(val); var->enum_count++; var->needs_export = 1; upsdebugx(5, "%s: [%s]: added to ups->var_list->enum_list: [%s] : [%s]", __func__, ups->socketname, key, val); return 1; } upsdebugx(6, "%s: [%s]: not found in ups->var_list: [%s]", __func__, ups->socketname, key); return 0; } static int ups_del_enum(ups_device_t *ups, const char *key, const char *val) { int var_pos = ups_get_var_pos(ups, key); if (var_pos >= 0) { ups_var_t *var = ups->var_list[var_pos]; size_t i = 0; for (i = 0; i < var->enum_count; ++i) { if (!strcmp(var->enum_list[i], val)) { size_t j = 0; if (primary_ups == ups) { dstate_delenum(key, val); upsdebugx(5, "%s: [%s]: removed enum from dstate: [%s] : [%s]", __func__, ups->socketname, key, val); } free(var->enum_list[i]); for (j = i; j < var->enum_count - 1; ++j) { var->enum_list[j] = var->enum_list[j + 1]; } var->enum_list[var->enum_count - 1] = NULL; var->enum_count--; if (var->enum_count == 0) { free(var->enum_list); var->enum_list = NULL; var->enum_allocs = 0; } else if (var->enum_count % SUBVAR_ALLOC_BATCH == 0) { var->enum_list = xrealloc(var->enum_list, sizeof(*var->enum_list) * var->enum_count); var->enum_allocs = var->enum_count; } upsdebugx(5, "%s: [%s]: deleted from ups->var_list->enum_list: [%s] : [%s]", __func__, ups->socketname, key, val); return 1; } } } upsdebugx(6, "%s: [%s]: not found in ups->var_list: [%s]", __func__, ups->socketname, key); return 0; } static void free_status_filters(void) { size_t i = 0; if (arg_status_filters.have_any) { for (i = 0; i < arg_status_filters.have_any_count; ++i) { free(arg_status_filters.have_any[i]); arg_status_filters.have_any[i] = NULL; } free(arg_status_filters.have_any); arg_status_filters.have_any = NULL; arg_status_filters.have_any_count = 0; } if (arg_status_filters.have_all) { for (i = 0; i < arg_status_filters.have_all_count; ++i) { free(arg_status_filters.have_all[i]); arg_status_filters.have_all[i] = NULL; } free(arg_status_filters.have_all); arg_status_filters.have_all = NULL; arg_status_filters.have_all_count = 0; } if (arg_status_filters.nothave_any) { for (i = 0; i < arg_status_filters.nothave_any_count; ++i) { free(arg_status_filters.nothave_any[i]); arg_status_filters.nothave_any[i] = NULL; } free(arg_status_filters.nothave_any); arg_status_filters.nothave_any = NULL; arg_status_filters.nothave_any_count = 0; } if (arg_status_filters.nothave_all) { for (i = 0; i < arg_status_filters.nothave_all_count; ++i) { free(arg_status_filters.nothave_all[i]); arg_status_filters.nothave_all[i] = NULL; } free(arg_status_filters.nothave_all); arg_status_filters.nothave_all = NULL; arg_status_filters.nothave_all_count = 0; } } static void ups_free_ups_state(ups_device_t *ups) { size_t i = 0; if (ups->var_list) { for (i = 0; i < ups->var_count; ++i) { if (ups->var_list[i]) { ups_free_var_state(ups->var_list[i]); free(ups->var_list[i]); ups->var_list[i] = NULL; } } free(ups->var_list); ups->var_list = NULL; ups->var_count = 0; ups->var_allocs = 0; } if (ups->cmd_list) { for (i = 0; i < ups->cmd_count; ++i) { if (ups->cmd_list[i]) { if (ups->cmd_list[i]->value) { free(ups->cmd_list[i]->value); ups->cmd_list[i]->value = NULL; } free(ups->cmd_list[i]); ups->cmd_list[i] = NULL; } } free(ups->cmd_list); ups->cmd_list = NULL; ups->cmd_count = 0; ups->cmd_allocs = 0; } if (ups->status) { free(ups->status); ups->status = NULL; } } static void ups_free_var_state(ups_var_t *var) { size_t i = 0; if (var->key) { free(var->key); var->key = NULL; } if (var->value) { free(var->value); var->value = NULL; } if (var->enum_list) { for (i = 0; i < var->enum_count; ++i) { if (var->enum_list[i]) { free(var->enum_list[i]); var->enum_list[i] = NULL; } } free(var->enum_list); var->enum_list = NULL; var->enum_count = 0; var->enum_allocs = 0; } if (var->range_list) { for (i = 0; i < var->range_count; ++i) { if (var->range_list[i]) { free(var->range_list[i]); var->range_list[i] = NULL; } } free(var->range_list); var->range_list = NULL; var->range_count = 0; var->range_allocs = 0; } } static const char *rewrite_driver_prefix(const char *in, char *out, size_t outlen) { int required = -1; if (!strncmp(in, "driver.", 7)) { required = snprintf(out, outlen, "upstream.%s", in); if ((size_t)required >= outlen) { upslogx(LOG_WARNING, "%s: truncated variable name size " "[%" PRIuSIZE "] exceeds buffer of size [%" PRIuSIZE "]: %s", __func__, (size_t)required, outlen, out); } return out; } return in; } static int str_arg_to_int(const char *arg, const char *argval, int *destvar, int defval, int min, int max) { if (!arg || !argval || !destvar) { return 0; } if (str_to_int(argval, destvar, 10)) { if ((min != INT_MIN && *destvar < min) || (max != INT_MAX && *destvar > max)) { upslogx(LOG_ERR, "%s: '%s' value [%d] out of range [%d..%d], " "set to the default '%s' value of [%d] instead", __func__, arg, *destvar, min, max, arg, defval); *destvar = defval; return 0; } upsdebugx(1, "%s: set '%s' to [%d] from configuration", __func__, arg, *destvar); return 1; } upslogx(LOG_ERR, "%s: invalid '%s' of [%s] from configuration, " "set to the default '%s' value of [%d] instead", __func__, arg, argval, arg, defval); *destvar = defval; return 0; } static ssize_t csv_arg_to_array(const char *arg, const char *argcsv, char ***array, size_t *countvar) { char *tmp = NULL; char *token = NULL; char *str = NULL; ssize_t count = 0; if (!arg || !argcsv || !array || !countvar) { return -1; } if (*argcsv == '\0') { return 0; } tmp = xstrdup(argcsv); token = strtok(tmp, ","); while (token) { str_trim_space(token); if (*token == '\0') { token = strtok(NULL, ","); continue; } str = xstrdup(token); *array = xrealloc(*array, sizeof(**array) * (*countvar + 1)); (*array)[*countvar] = str; (*countvar)++; count++; upsdebugx(1, "%s: added [%s] to [%s] from configuration", __func__, str, arg); token = strtok(NULL, ","); } free(tmp); tmp = NULL; return count; } static inline void ups_set_flag(ups_device_t *ups, ups_flags_t flag) { ups->flags |= flag; } static inline void ups_clear_flag(ups_device_t *ups, ups_flags_t flag) { ups->flags &= ~flag; } static inline int ups_has_flag(const ups_device_t *ups, ups_flags_t flags) { return (ups->flags & flags) == flags; } nut-2.8.4/drivers/apcupsd-ups.h0000644000175000017500000001575014670526611013367 00000000000000/* apcupsd-ups.h - NUT client driver to apcupsd Copyright (C) 2005 - 2010 Arnaud Quette This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_APCUPSD_UPS_H_SEEN #define NUT_APCUPSD_UPS_H_SEEN 1 /* from usbhid-ups.h */ /* --------------------------------------------------------------- */ /* Struct & data for ups.status processing */ /* --------------------------------------------------------------- */ typedef struct { const char *status_str; /* ups.status string */ int status_value; /* ups.status value */ } status_lkp_t; #define STATUS_CAL 1 /* calibration */ #define STATUS_TRIM 2 /* SmartTrim */ #define STATUS_BOOST 4 /* SmartBoost */ #define STATUS_OL 8 /* on line */ #define STATUS_OB 16 /* on battery */ #define STATUS_OVER 32 /* overload */ #define STATUS_LB 64 /* low battery */ #define STATUS_RB 128 /* replace battery */ #define STATUS_BYPASS 256 /* on bypass */ #define STATUS_OFF 512 /* ups is off */ #define STATUS_CHRG 1024 /* charging */ #define STATUS_DISCHRG 2048 /* discharging */ /* static status_lkp_t status_info[] = { { "CAL", STATUS_CAL }, { "TRIM", STATUS_TRIM }, { "BOOST", STATUS_BOOST }, { "OL", STATUS_OL }, { "OB", STATUS_OB }, { "OVER", STATUS_OVER }, { "LB", STATUS_LB }, { "RB", STATUS_RB }, { "BYPASS", STATUS_BYPASS }, { "OFF", STATUS_OFF }, { "CHRG", STATUS_CHRG }, { "DISCHRG", STATUS_DISCHRG }, { "NULL", 0 }, }; */ /* from usbhid-ups.h */ typedef struct { char hid_value; /* HID value */ char *nut_value; /* NUT value */ } info_enum_t; /* --------------------------------------------------------------- */ /* Structure containing information about how to get/set data */ /* from/to the UPS and convert these to/from NUT standard */ /* --------------------------------------------------------------- */ typedef struct { const char *apcupsd_item; const char *info_type; /* NUT variable name */ int info_flags; /* NUT flags (to set in addinfo) */ float info_len; /* if ST_FLAG_STRING: length of the string */ /* if HU_TYPE_CMD: command value ; multiplier (or max len) otherwise */ const char *default_value; /* if HU_FLAG_ABSENT: default value ; format otherwise */ int drv_flags; /* */ char **var_values; /* all possible values for this variable (allows to check data...) */ /* FIXME: "void *" so we can have bound or enum */ /* interpreter interpret; */ /* FFE: interpreter fct, NULL if not needed */ } apcuspd_info_t; /* data flags */ #define DU_FLAG_NONE 0 #define DU_FLAG_INIT 1 /* intialy show element to upsd */ #define DU_FLAG_STATUS 2 #define DU_FLAG_DATE 4 #define DU_FLAG_TIME 8 #define DU_FLAG_FW1 16 #define DU_FLAG_FW2 32 #define DU_FLAG_PRESERVE 64 /* ------------ */ /* Data table */ /* ------------ */ static apcuspd_info_t nut_data[] = { { NULL, "ups.mfr", ST_FLAG_STRING | ST_FLAG_RW, 32, "APC", DU_FLAG_INIT, NULL }, { "MODEL", "ups.model", ST_FLAG_STRING | ST_FLAG_RW, 32, "Unknown UPS", DU_FLAG_INIT, NULL }, { "STATUS", "ups.status", ST_FLAG_STRING | ST_FLAG_RW, 32, "OFF", DU_FLAG_INIT|DU_FLAG_STATUS, NULL }, { "SERIALNO", "ups.serial", ST_FLAG_STRING | ST_FLAG_RW, 32, NULL, DU_FLAG_NONE, NULL }, { "LOADPCT", "ups.load", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "DATE", "ups.time", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_TIME, NULL }, { "DATE", "ups.date", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_DATE, NULL }, { "MANDATE", "ups.mfr.date", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL }, { "FIRMWARE", "ups.firmware", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_FW1, NULL }, { "FIRMWARE", "ups.firmware.aux", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_FW2, NULL }, { "ITEMP", "ups.temperature", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "UPSNAME", "ups.id", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL }, { "DWAKE", "ups.delay.start", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, { "DSHUTD", "ups.delay.shutdown", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, { "STESTI", "ups.test.interval", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, { "SELFTEST", "ups.test.result", ST_FLAG_STRING | ST_FLAG_RW, 16, NULL, DU_FLAG_NONE, NULL }, { "LINEV", "input.voltage", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "MAXLINEV", "input.voltage.maximum", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "MINLINEV", "input.voltage.minimum", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "NOMINV", "input.voltage.nominal", 0, 1, "%.0f", DU_FLAG_NONE, NULL }, { "NOMOUTV", "output.voltage.nominal", 0, 1, "%.0f", DU_FLAG_NONE, NULL }, { "LASTXFER", "input.transfer.reason", ST_FLAG_STRING | ST_FLAG_RW, 32, NULL, DU_FLAG_NONE, NULL }, { "LOTRANS", "input.transfer.low", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "HITRANS", "input.transfer.high", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "SENSE", "input.sensitivity", ST_FLAG_STRING | ST_FLAG_RW, 1, NULL, DU_FLAG_NONE, NULL }, { "LINEFREQ", "input.frequency", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "OUTPUTV", "output.voltage", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "LINEFREQ", "output.frequency", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "BCHARGE", "battery.charge", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_PRESERVE, NULL }, { "MBATTCHG", "battery.charge.low", ST_FLAG_RW, 1, "%.0f", DU_FLAG_NONE, NULL }, { "BATTDATE", "battery.date", ST_FLAG_STRING /* | ST_FLAG_RW */, 16, NULL, DU_FLAG_DATE, NULL }, { "BATTV", "battery.voltage", 0, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "NOMBATTV", "battery.voltage.nominal", 0, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "TIMELEFT", "battery.runtime", ST_FLAG_RW, 60, "%1.1f", DU_FLAG_PRESERVE, NULL }, { "MINTIMEL", "battery.runtime.low", ST_FLAG_RW, 60, "%.0f", DU_FLAG_NONE, NULL }, { "RETPCT", "battery.charge.restart", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "NOMPOWER", "ups.realpower.nominal", 0, 1, "%1.1f", DU_FLAG_INIT, NULL }, { "LOAD_W", "ups.realpower", 0, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "LOADAPNT", "power.percent", ST_FLAG_RW, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "OUTCURNT", "output.current", 0, 1, "%1.2f", DU_FLAG_NONE, NULL }, { "LOAD_VA", "ups.power", 0, 1, "%1.1f", DU_FLAG_NONE, NULL }, { "NOMAPNT", "ups.power.nominal", 0, 1, "%.0f", DU_FLAG_INIT, NULL }, { NULL, NULL, 0, 0, NULL, DU_FLAG_NONE, NULL } }; #endif /* NUT_APCUPSD_UPS_H_SEEN */ nut-2.8.4/drivers/legrand-hid.c0000644000175000017500000002257514777753336013315 00000000000000/* legrand-hid.c - subdriver to monitor Legrand USB/HID devices with NUT * * Copyright (C) * 2003 - 2012 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * 2013 Charles Lepple * 2018 Gabriele Taormina , for Legrand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "common.h" #include "usbhid-ups.h" #include "legrand-hid.h" #include "main.h" #include "usb-common.h" #define LEGRAND_HID_VERSION "Legrand HID 0.2" /* Legrand VendorID and ProductID */ #define LEGRAND_VID 0x1cb0 /* Legrand */ #define LEGRAND_PID_PDU 0x0038 /* Keor PDU model (800VA) */ #define LEGRAND_PID_SP 0x0032 /* Keor SP model (600, 800, 1000, 1500, 2000VA version) */ static void *disable_interrupt_pipe(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); if (!use_interrupt_pipe) return NULL; use_interrupt_pipe = FALSE; upslogx(LOG_INFO, "interrupt pipe disabled (add 'pollonly' flag to 'ups.conf' to get rid of this message)"); return NULL; } /* USB IDs device table */ static usb_device_id_t legrand_usb_device_table[] = { { USB_DEVICE(LEGRAND_VID, LEGRAND_PID_PDU), disable_interrupt_pipe }, /* Legrand Keor PDU */ { USB_DEVICE(LEGRAND_VID, LEGRAND_PID_SP), disable_interrupt_pipe }, /* Legrand Keor SP */ /* Terminating entry */ { 0, 0, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* LEGRAND usage table */ static usage_lkp_t legrand_usage_lkp[] = { { NULL, 0 } }; static usage_tables_t legrand_utab[] = { legrand_usage_lkp, hid_usage_lkp, NULL, }; static const char *legrand_times10(double value) { static char buf[20]; snprintf(buf, sizeof(buf), "%0.1f", value * 10); return buf; } static info_lkp_t legrand_times10_info[] = { { 0, NULL, legrand_times10, NULL }, { 0, NULL, NULL, NULL } }; static const char *legrand_times100k(double value) { static char buf[20]; snprintf(buf, sizeof(buf), "%0.1f", value * 100000); return buf; } static info_lkp_t legrand_times100k_info[] = { { 0, NULL, legrand_times100k, NULL }, { 0, NULL, NULL, NULL } }; static const char *legrand_times1M(double value) { static char buf[20]; snprintf(buf, sizeof(buf), "%0.1f", value * 1000000); return buf; } static info_lkp_t legrand_times1M_info[] = { { 0, NULL, legrand_times1M, NULL }, { 0, NULL, NULL, NULL } }; static const char *legrand_times10M(double value) { static char buf[20]; snprintf(buf, sizeof(buf), "%0.1f", value * 10000000); return buf; } static info_lkp_t legrand_times10M_info[] = { { 0, NULL, legrand_times10M, NULL }, { 0, NULL, NULL, NULL } }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t legrand_hid2nut[] = { /* Input Data */ { "input.voltage", 0, 0, "UPS.Input.Voltage", NULL, "%.0f", 0, NULL }, { "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%.0f", 0, legrand_times1M_info }, { "input.transfer.high", 0, 0, "UPS.Input.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.transfer.high", 0, 0, "UPS.PowerConverter.Output.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, legrand_times10_info }, { "input.transfer.low", 0, 0, "UPS.Input.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.transfer.low", 0, 0, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.voltage.nominal", 0, 0, "UPS.Input.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* Battery Data */ { "battery.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, divide_by_10_conversion }, { "battery.voltage.nominal", 0, 0, "UPS.BatterySystem.Battery.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.0f", 0, divide_by_10_conversion }, { "battery.voltage", 0, 0, "UPS.BatterySystem.Battery.Voltage", NULL, "%.0f", 0, legrand_times100k_info }, { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.runtime", 0, 0, "UPS.PowerSummary.RuntimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "battery.charge.low", 0, 0, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* Output Data */ { "output.voltage", 0, 0, "UPS.Output.Voltage", NULL, "%.0f", 0, NULL }, { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.0f", 0, legrand_times10M_info }, { "output.frequency", 0, 0, "UPS.Output.Frequency", NULL, "%.0f", 0, NULL }, { "ups.load", 0, 0, "UPS.Output.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.load", 0, 0, "UPS.OutletSystem.Outlet.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.realpower.nominal", 0, 0, "UPS.Output.ConfigActivePower", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "ups.realpower.nominal", 0, 0, "UPS.Flow.ConfigApparentPower", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* UPS Status */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.Output.Overload", NULL, NULL, HU_FLAG_QUICK_POLL, overload_info }, /* Delays */ { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.OutletSystem.Outlet.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL }, { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.OutletSystem.Outlet.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL }, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Output.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL }, { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Output.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL }, { "load.off.delay", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "load.off.delay", 0, 0, "UPS.Output.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.Output.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, /* Battery Testing */ { "test.battery.start.quick", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "test.battery.start.deep", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "2", HU_TYPE_CMD, NULL }, { "test.battery.stop", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "3", HU_TYPE_CMD, NULL }, { "test.battery.start.quick", 0, 0, "UPS.Output.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "test.battery.start.deep", 0, 0, "UPS.Output.Test", NULL, "2", HU_TYPE_CMD, NULL }, { "test.battery.stop", 0, 0, "UPS.Output.Test", NULL, "3", HU_TYPE_CMD, NULL }, /* Buzzer */ { "beeper.enable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *legrand_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *legrand_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "Legrand"; } static const char *legrand_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int legrand_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(legrand_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) return 1; possibly_supported("Legrand", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t legrand_subdriver = { LEGRAND_HID_VERSION, legrand_claim, legrand_utab, legrand_hid2nut, legrand_format_model, legrand_format_mfr, legrand_format_serial, fix_report_desc, }; nut-2.8.4/drivers/tripplite-hid.h0000644000175000017500000000221014670526611013664 00000000000000/* tripplite-hid.h - data to monitor Tripp Lite USB/HID devices with NUT * * Copyright (C) * 2003 - 2005 Arnaud Quette * 2005 Peter Selinger * * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef TRIPPLITE_HID_H #define TRIPPLITE_HID_H #include "usbhid-ups.h" extern subdriver_t tripplite_subdriver; #endif /* TRIPPLITE_HID_H */ nut-2.8.4/drivers/powerp-bin.c0000644000175000017500000004024015044656702013171 00000000000000/* * powerp-bin.c - Model specific routines for CyberPower binary * protocol UPSes * * Copyright (C) * 2007 Doug Reynolds * 2007-2009 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Throughout this driver, READ and WRITE comments are shown. These are * the typical commands to and replies from the UPS that was used for * decoding the protocol (with a serial logger). */ #include "main.h" #include "serial.h" #include "powerp-bin.h" #include "nut_stdint.h" #include "nut_float.h" #include #define POWERPANEL_BIN_VERSION "Powerpanel-Binary 0.64" typedef struct { unsigned char start; unsigned char i_volt; unsigned char o_volt; unsigned char o_load; unsigned char fill_4; unsigned char b_chrg; unsigned char u_temp; unsigned char i_freq; unsigned char fill_8; unsigned char flags[4]; unsigned char stop; } status_t; typedef struct { const char *val; const char command; } valtab_t; static enum { PR = 0, OP = 1 } type = PR; static unsigned char powpan_answer[SMALLBUF]; /* PR series */ static const valtab_t tran_high_pr[] = { { "138", -9 }, { "139", -8 }, { "140", -7 }, { "141", -6 }, { "142", -5 }, { "143", -4 }, { "144", -3 }, { "145", -2 }, { "146", -1 }, { "147", 0 }, { NULL, 0 } }; /* OP series */ static const valtab_t tran_high_op[] = { { "140", -5 }, { "141", -4 }, { "142", -3 }, { "143", -2 }, { "144", -1 }, { "145", 0 }, { "146", +1 }, { "147", +2 }, { "148", +3 }, { "149", +4 }, { "150", +5 }, { NULL, 0 } }; /* PR series */ static const valtab_t tran_low_pr[] = { { "88", 0 }, { "89", +1 }, { "90", +2 }, { "91", +3 }, { "92", +4 }, { "93", +5 }, { "94", +6 }, { "95", +7 }, { "96", +8 }, { "97", +9 }, { NULL, 0 } }; /* OP series */ static const valtab_t tran_low_op[] = { { "85", -5 }, { "86", -4 }, { "87", -3 }, { "88", -2 }, { "89", -1 }, { "90", 0 }, { "91", +1 }, { "92", +2 }, { "93", +3 }, { "94", +4 }, { "95", +5 }, { NULL, 0 } }; /* PR series */ static const valtab_t batt_low_pr[] = { { "25", -6 }, { "30", -5 }, { "35", -3 }, { "40", -1 }, { "45", 0 }, { "50", +2 }, { "55", +4 }, { "60", +6 }, { NULL, 0 } }; /* OP series */ static const valtab_t batt_low_op[] = { { "15", -8 }, { "18", -7 }, { "19", -6 }, { "20", -5 }, { "22", -4 }, { "24", -3 }, { "25", -2 }, { "26", -1 }, { "28", 0 }, { "30", +1 }, { "32", +2 }, { "34", +3 }, { "35", +4 }, { "36", +5 }, { "38", +6 }, { "40", +7 }, { NULL, 0 } }; /* PR series */ static const valtab_t out_volt_pr[] = { { "110", -10 }, { "120", 0 }, { "130", +10 }, { NULL, 0 } }; /* OP series */ static const valtab_t out_volt_op[] = { { "110", -2 }, { "115", -1 }, { "120", 0 }, { "124", +1 }, { "128", +2 }, { "130", +3 }, { NULL, 0 } }; static const valtab_t yes_no_info[] = { { "yes", 2 }, { "no", 0 }, { NULL, 0 } }; /* Older models report the model in a numeric format 'rOnn' */ static const struct { const char *val; const char *model; } modeltab[] = { { "rO10", "OP1000AVR" }, { "rO27", "OP320AVR" }, { "rO29", "OP500AVR" }, { "rO31", "OP800AVR" }, { "rO33", "OP850AVR" }, { "rO37", "OP900AVR" }, { "rO39", "OP650AVR" }, { "rO41", "OP700AVR" }, { "rO43", "OP1250AVR" }, { "rO45", "OP1500AVR" }, { NULL, NULL } }; static const struct { const char *var; const char *get; const char *set; const valtab_t *map[2]; } vartab[] = { { "input.transfer.high", "R\x02\r", "Q\x02%c\r", { tran_high_pr, tran_high_op } }, { "input.transfer.low", "R\x04\r", "Q\x04%c\r", { tran_low_pr, tran_low_op } }, { "battery.charge.low", "R\x08\r", "Q\x08%c\r", { batt_low_pr, batt_low_op } }, { "ups.start.battery", "R\x0F\r", "Q\x0F%c\r", { yes_no_info, yes_no_info } }, { "output.voltage.nominal", "R\x18\r", "Q\x18%c\r", { out_volt_pr, out_volt_op } }, { NULL, NULL, NULL, { NULL, 0 } } }; static const struct { const char *cmd; const char *command; const size_t len; } cmdtab[] = { { "test.battery.start.quick", "T\230\r", 3 }, /* 20 seconds test */ { "test.battery.stop", "CT\r", 3 }, { "beeper.toggle", "B\r", 2 }, { "shutdown.reboot", "S\0\0R\0\1W\r", 8}, /* the shutdown.stayoff command behaves * as shutdown.return when on battery */ { "shutdown.stayoff", "S\0\0W\r", 5 }, { "shutdown.stop", "C\r", 2 }, { NULL, NULL, 0 } }; /* map UPS data to (approximated) input/output voltage */ static int op_volt(unsigned char in) { if (in < 26) { return 0; } return (((float)in * 200 / 230) + 6); } /* map UPS data to (approximated) load */ static int op_load(unsigned char in) { if (in > 108) { return 200; } return (in * 200) / 108; } /* map UPS data to (approximated) charge percentage */ static int op_chrg(unsigned char in) { if (in > 197) { return 100; } if (in < 151) { return 0; } return ((in - 151) * 100) / 46; } /* map UPS data to (approximated) temperature */ static float op_temp(unsigned char in) { return (pow((float)in / 32, 2) + 10); } /* map UPS data to (approximated) frequency */ static float op_freq(unsigned char in) { return (12600.0 / (in + 32)); } static ssize_t powpan_command(const char *buf, size_t bufsize) { ssize_t ret; ser_flush_io(upsfd); ret = ser_send_buf_pace(upsfd, UPSDELAY, buf, bufsize); if (ret < 0) { upsdebug_with_errno(3, "send"); return -1; } if (ret == 0) { upsdebug_with_errno(3, "send: timeout"); return -1; } upsdebug_hex(3, "send", buf, bufsize); usleep(100000); ret = ser_get_buf_len(upsfd, powpan_answer, bufsize-1, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 0) { upsdebug_with_errno(3, "read"); upsdebug_hex(4, " \\_", buf, bufsize-1); return -1; } if (ret == 0) { upsdebugx(3, "read: timeout"); upsdebug_hex(4, " \\_", buf, bufsize-1); return -1; } upsdebug_hex(3, "read", powpan_answer, (size_t)ret); return ret; } static int powpan_instcmd(const char *cmdname, const char *extra) { int i; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); for (i = 0; cmdtab[i].cmd != NULL; i++) { ssize_t ret; if (strcasecmp(cmdname, cmdtab[i].cmd)) { continue; } upslog_INSTCMD_POWERSTATE_CHECKED(cmdname, extra); ret = powpan_command(cmdtab[i].command, cmdtab[i].len); assert(cmdtab[i].len < SSIZE_MAX); if (ret >= 0 && (ret == (ssize_t)(cmdtab[i].len - 1)) && (!memcmp(powpan_answer, cmdtab[i].command, cmdtab[i].len - 1)) ) { return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_FAILED(cmdname, extra); return STAT_INSTCMD_FAILED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } static int powpan_setvar(const char *varname, const char *val) { char command[SMALLBUF]; int i, j; upsdebug_SET_STARTING(varname, val); for (i = 0; vartab[i].var != NULL; i++) { if (strcasecmp(varname, vartab[i].var)) { continue; } if (!strcasecmp(val, dstate_getinfo(varname))) { upslogx(LOG_INFO, "powpan_setvar: [%s] no change for variable [%s]", val, varname); return STAT_SET_HANDLED; } for (j = 0; vartab[i].map[type][j].val != NULL; j++) { if (strcasecmp(val, vartab[i].map[type][j].val)) { continue; } snprintf_dynamic(command, sizeof(command), vartab[i].set, "%c", vartab[i].map[type][j].command); if ((powpan_command(command, 4) == 3) && (!memcmp(powpan_answer, command, 3))) { dstate_setinfo(varname, "%s", val); return STAT_SET_HANDLED; } upslog_SET_FAILED(varname, val); return STAT_SET_UNKNOWN; /* FIXME: ..._FAILED ? */ } upslog_SET_INVALID(varname, val); return STAT_SET_UNKNOWN; /* FIXME: ..._INVALID? */ } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } static void powpan_initinfo(void) { int i, j; char *s; dstate_setinfo("ups.delay.start", "%d", 45); dstate_setinfo("ups.delay.shutdown", "%d", 0); /* almost immediate */ /* * NOTE: The reply is already in the buffer, since the F\r command * was used for autodetection of the UPS. No need to do it again. */ if ((s = strtok((char *)&powpan_answer[1], ".")) != NULL) { for (i = 0; modeltab[i].val != NULL; i++) { if (!strncmp(s, modeltab[i].val, strlen(modeltab[i].val))) { break; } } if (modeltab[i].model) { /* model found in table */ dstate_setinfo("ups.model", "%s", modeltab[i].model); } else { /* report model value as is */ dstate_setinfo("ups.model", "%s", str_rtrim(s, ' ')); } } if ((s = strtok(NULL, ".")) != NULL) { dstate_setinfo("input.voltage.nominal", "%d", (unsigned char)s[0]); } if ((s = strtok(NULL, ".")) != NULL) { dstate_setinfo("input.frequency.nominal", "%d", (unsigned char)s[0]); } if ((s = strtok(NULL, ".")) != NULL) { dstate_setinfo("ups.firmware", "%c.%c%c%c", s[0], s[1], s[2], s[3]); } for (i = 0; cmdtab[i].cmd != NULL; i++) { dstate_addcmd(cmdtab[i].cmd); } for (i = 0; vartab[i].var != NULL; i++) { if (powpan_command(vartab[i].get, 3) < 2) { continue; } for (j = 0; vartab[i].map[type][j].val != NULL; j++) { if (vartab[i].map[type][j].command != powpan_answer[1]) { continue; } dstate_setinfo(vartab[i].var, "%s", vartab[i].map[type][j].val); break; } if (dstate_getinfo(vartab[i].var) == NULL) { upslogx(LOG_WARNING, "warning: [%d] unknown value for [%s]!", powpan_answer[1], vartab[i].var); continue; } dstate_setflags(vartab[i].var, ST_FLAG_RW); for (j = 0; vartab[i].map[type][j].val != NULL; j++) { dstate_addenum(vartab[i].var, "%s", vartab[i].map[type][j].val); } } /* * FIXME: The following commands need to be reverse engineered. It * looks like they are used in detecting the UPS model. To rule out * any incompatibilities, only use them when running in debug mode. */ if (nut_debug_level > 2) { powpan_command("R\x29\r", 3); powpan_command("R\x2B\r", 3); powpan_command("R\x3D\r", 3); } dstate_addcmd("shutdown.stayoff"); dstate_addcmd("shutdown.reboot"); } static ssize_t powpan_status(status_t *status) { ssize_t ret; ser_flush_io(upsfd); /* * WRITE D\r * READ #VVL.CTF.....\r * 01234567890123 */ ret = ser_send_pace(upsfd, UPSDELAY, "D\r"); if (ret < 0) { upsdebug_with_errno(3, "send"); return -1; } if (ret == 0) { upsdebug_with_errno(3, "send: timeout"); return -1; } upsdebug_hex(3, "send", "D\r", 2); usleep(200000); ret = ser_get_buf_len(upsfd, status, sizeof(*status), SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 0) { upsdebug_with_errno(3, "read"); upsdebug_hex(4, " \\_", status, sizeof(*status)); return -1; } if (ret == 0) { upsdebugx(3, "read: timeout"); upsdebug_hex(4, " \\_", status, sizeof(*status)); return -1; } upsdebug_hex(3, "read", status, (size_t)ret); if ((status->flags[0] + status->flags[1]) != 255) { upsdebugx(4, " \\_ : checksum flags[0..1] failed"); return -1; } if ((status->flags[2] + status->flags[3]) != 255) { upsdebugx(4, " \\_ : checksum flags[2..3] failed"); return -1; } return 0; } static int powpan_updateinfo(void) { status_t status; if (powpan_status(&status)) { return -1; } switch (type) { case OP: dstate_setinfo("input.voltage", "%d", op_volt(status.i_volt)); if (status.flags[0] & 0x84) { dstate_setinfo("output.voltage", "%s", dstate_getinfo("output.voltage.nominal")); } else { dstate_setinfo("output.voltage", "%d", op_volt(status.i_volt)); } dstate_setinfo("ups.load", "%d", op_load(status.o_load)); dstate_setinfo("battery.charge", "%d", op_chrg(status.b_chrg)); dstate_setinfo("ups.temperature", "%.1f", op_temp(status.u_temp)); dstate_setinfo("input.frequency", "%.1f", op_freq(status.i_freq)); break; case PR: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) # pragma GCC diagnostic pop #endif dstate_setinfo("input.voltage", "%d", status.i_volt); if (status.flags[0] & 0x84) { dstate_setinfo("output.voltage", "%s", dstate_getinfo("output.voltage.nominal")); } else { dstate_setinfo("output.voltage", "%d", status.o_volt); } dstate_setinfo("ups.load", "%d", status.o_load); dstate_setinfo("battery.charge", "%d", status.b_chrg); dstate_setinfo("ups.temperature", "%d", status.u_temp); dstate_setinfo("input.frequency", "%.1f", (status.i_freq == 0) ? 0.0 : 45.0 + (float)status.i_freq / 10.0); break; } if (status.flags[0] & 0x01) { dstate_setinfo("ups.beeper.status", "enabled"); } else { dstate_setinfo("ups.beeper.status", "disabled"); } status_init(); if (status.flags[0] & 0x80) { status_set("OB"); } else { status_set("OL"); } if (status.flags[0] & 0x40) { status_set("LB"); } /* !OB && !TEST */ if (!(status.flags[0] & 0x84) && status.o_volt) { if (status.o_volt < 0.5 * status.i_volt) { upsdebugx(2, "%s: output voltage too low", __func__); } else if (status.o_volt < 0.95 * status.i_volt) { status_set("TRIM"); } else if (status.o_volt < 1.05 * status.i_volt) { upsdebugx(2, "%s: appears to be in BYPASS state", __func__); } else if (status.o_volt < 1.5 * status.i_volt) { status_set("BOOST"); } else { upsdebugx(2, "%s: output voltage too high", __func__); } } if (status.flags[0] & 0x04) { status_set("TEST"); } if (status.flags[0] == 0) { status_set("OFF"); } status_commit(); return (status.flags[0] & 0x80) ? 1 : 0; } static ssize_t powpan_initups(void) { ssize_t ret; int i; upsdebugx(1, "Trying %s protocol...", powpan_binary.version); ser_set_speed(upsfd, device_path, B1200); /* This fails for many devices, so don't bother to complain */ ser_send_pace(upsfd, UPSDELAY, "\r\r"); for (i = 0; i < MAXTRIES; i++) { ser_flush_io(upsfd); /* * WRITE F\r * READ .PR2200 .x.<.1100 * 01234567890123456789 */ ret = ser_send_pace(upsfd, UPSDELAY, "F\r"); if (ret < 0) { upsdebug_with_errno(3, "send"); continue; } if (ret == 0) { upsdebug_with_errno(3, "send: timeout"); continue; } upsdebug_hex(3, "send", "F\r", 2); usleep(200000); ret = ser_get_line(upsfd, powpan_answer, sizeof(powpan_answer), ENDCHAR, IGNCHAR, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 0) { upsdebug_with_errno(3, "read"); upsdebug_hex(4, " \\_", powpan_answer, strlen((char *)powpan_answer)); continue; } if (ret == 0) { upsdebugx(3, "read: timeout"); upsdebug_hex(4, " \\_", powpan_answer, strlen((char *)powpan_answer)); continue; } upsdebug_hex(3, "read", powpan_answer, (size_t)ret); if (ret < 20) { upsdebugx(2, "Expected 20 bytes but only got %" PRIiSIZE, ret); continue; } if (powpan_answer[0] != '.') { upsdebugx(2, "Expected start character '.' but got '%c'", (char)powpan_answer[0]); continue; } /* See if we need to use the 'old' protocol for the OP series */ if (!strncmp((char *)&powpan_answer[1], "OP", 2)) { type = OP; } /* This is for an older model series, that reports the model numerically */ if (!strncmp((char *)&powpan_answer[1], "rO", 2)) { type = OP; } if (getval("ondelay")) { fatalx(EXIT_FAILURE, "Setting 'ondelay' not supported by %s driver", powpan_binary.version); } if (getval("offdelay")) { fatalx(EXIT_FAILURE, "Setting 'offdelay' not supported by %s driver", powpan_binary.version); } return ret; } return -1; } subdriver_t powpan_binary = { "binary", POWERPANEL_BIN_VERSION, powpan_instcmd, powpan_setvar, powpan_initups, powpan_initinfo, powpan_updateinfo }; nut-2.8.4/drivers/eaton-pdu-nlogic-mib.h0000644000175000017500000000217014777753336015043 00000000000000/* eaton-pdu-nlogic-mib.h - subdriver to monitor eaton-pdu-nlogic SNMP devices with NUT * * Copyright (C) * 2011 - 2016 Arnaud Quette * 2022 Eaton (author: Arnaud Quette ) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef EATON_PDU_NLOGIC_MIB_H #define EATON_PDU_NLOGIC_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t eaton_pdu_nlogic; #endif /* EATON_PDU_NLOGIC_MIB_H */ nut-2.8.4/drivers/huawei-mib.c0000644000175000017500000002756615000601404013133 00000000000000/* huawei-mib.c - subdriver to monitor Huawei SNMP devices with NUT * * Copyright (C) * 2011 - 2012 Arnaud Quette * 2015 Stuart Henderson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "huawei-mib.h" #define HUAWEI_MIB_VERSION "0.40" #define HUAWEI_SYSOID ".1.3.6.1.4.1.8072.3.2.10" #define HUAWEI_UPSMIB ".1.3.6.1.4.1.2011" #define HUAWEI_OID_MODEL_NAME ".1.3.6.1.4.1.2011.6.174.1.2.100.1.2.1" /* To create a value lookup structure (as needed on the 2nd line of the example * below), use the following kind of declaration, outside of the present snmp_info_t[]: * static info_lkp_t huawei_onbatt_info[] = { * info_lkp_default(1, "OB"), * info_lkp_default(2, "OL"), * info_lkp_sentinel * }; */ static info_lkp_t huawei_supplymethod_info[] = { info_lkp_default(1, ""), /* no supply */ info_lkp_default(2, "OL BYPASS"), info_lkp_default(3, "OL"), info_lkp_default(4, "OB"), info_lkp_default(5, ""), /* combined */ info_lkp_default(6, "OL ECO"), info_lkp_default(7, "OB ECO"), info_lkp_sentinel }; static info_lkp_t huawei_battstate_info[] = { info_lkp_default(1, ""), /* not connected */ info_lkp_default(2, ""), /* not charging or discharging */ info_lkp_default(3, ""), /* hibernation */ info_lkp_default(4, ""), /* float */ info_lkp_default(5, "CHRG"), /* equalized charging */ info_lkp_default(6, "DISCHRG"), info_lkp_sentinel }; static info_lkp_t huawei_phase_info[] = { info_lkp_default(1, "1"), info_lkp_default(2, "3"), info_lkp_sentinel }; static info_lkp_t huawei_voltrating_info[] = { info_lkp_default(1, "200"), info_lkp_default(2, "208"), info_lkp_default(3, "220"), info_lkp_default(4, "380"), info_lkp_default(5, "400"), info_lkp_default(6, "415"), info_lkp_default(7, "480"), info_lkp_default(8, "600"), info_lkp_default(9, "690"), info_lkp_sentinel }; static info_lkp_t huawei_freqrating_info[] = { info_lkp_default(1, "50"), info_lkp_default(2, "60"), info_lkp_sentinel }; static info_lkp_t huawei_pwrrating_info[] = { info_lkp_default(1, "80000"), info_lkp_default(2, "100000"), info_lkp_default(3, "120000"), info_lkp_default(4, "160000"), info_lkp_default(5, "200000"), info_lkp_default(6, "30000"), info_lkp_default(7, "40000"), info_lkp_default(8, "60000"), info_lkp_default(9, "2400000"), info_lkp_default(10, "2500000"), info_lkp_default(11, "2800000"), info_lkp_default(12, "3000000"), info_lkp_sentinel }; /* Note: This is currently identical to ietf_test_result_info from IETF MIB * We rename it here to a) allow evolution that may become incompatible; * b) avoid namespace conflicts, especially with DMF loader of named objects */ static info_lkp_t huawei_test_result_info[] = { info_lkp_default(1, "done and passed"), info_lkp_default(2, "done and warning"), info_lkp_default(3, "done and error"), info_lkp_default(4, "aborted"), info_lkp_default(5, "in progress"), info_lkp_default(6, "no test initiated"), info_lkp_sentinel }; /* HUAWEI Snmp2NUT lookup table */ static snmp_info_t huawei_mib[] = { /* Data format: * snmp_info_default(info_type, info_flags, info_len, OID, dfl, flags, oid2info, setvar), * * info_type: NUT INFO_ or CMD_ element name * info_flags: flags to set in addinfo * info_len: length of strings if STR * cmd value if CMD, multiplier otherwise * OID: SNMP OID or NULL * dfl: default value * flags: snmp-ups internal flags (FIXME: ...) * oid2info: lookup table between OID and NUT values * * Example: * snmp_info_default("input.voltage", 0, 0.1, ".1.3.6.1.4.1.705.1.6.2.1.2.1", "", SU_INPUT_1, NULL), * snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.705.1.7.3.0", "", SU_FLAG_OK | SU_STATUS_BATT, huawei_onbatt_info), * * To create a value lookup structure (as needed on the 2nd line), use the * following kind of declaration, outside of the present snmp_info_t[]: * static info_lkp_t huawei_onbatt_info[] = { * info_lkp_default(1, "OB"), * info_lkp_default(2, "OL"), * info_lkp_sentinel * }; */ /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* UPS page */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Huawei", SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.2.100.1.2.1", "Generic SNMP UPS", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.id", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.1.1.2.0", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.time", 0, 1, ".1.3.6.1.4.1.2011.6.174.1.11.1.0", NULL, SU_FLAG_OK, NULL), /* seconds since epoch */ snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.2.100.1.3.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.2.100.1.5.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.status", 0, 1, ".1.3.6.1.4.1.2011.6.174.1.2.101.1.1.1", NULL, SU_FLAG_OK, huawei_supplymethod_info), snmp_info_default("ups.status", 0, 1, ".1.3.6.1.4.1.2011.6.174.1.2.101.1.3.1", NULL, SU_STATUS_BATT | SU_FLAG_OK, huawei_battstate_info), snmp_info_default("ups.test.result", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.2.1.33.1.7.3.0", "", 0, huawei_test_result_info), /* Input page */ /* hwUpsCtrlInputStandard listed in MIB but not present on tested UPS5000-E */ snmp_info_default("input.phases", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.102.100.1.8", "3", SU_FLAG_ABSENT | SU_FLAG_OK, huawei_phase_info), snmp_info_default("input.L1-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.1.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L2-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.2.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L3-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.3.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.frequency", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.4.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L1.current", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.5.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L2.current", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.6.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L3.current", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.7.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L1.powerfactor", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.8.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L2.powerfactor", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.9.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.L3.powerfactor", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.3.100.1.10.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.bypass.L1-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.5.100.1.1.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.bypass.L2-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.5.100.1.2.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.bypass.L3-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.5.100.1.3.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("input.bypass.frequency", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.5.100.1.4.1", NULL, SU_FLAG_OK, NULL), /* Output page */ /* hwUpsCtrlOutputStandard listed in MIB but not present on tested UPS5000-E */ snmp_info_default("output.phases", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.102.100.1.9", "3", SU_FLAG_ABSENT | SU_FLAG_OK, huawei_phase_info), snmp_info_default("output.L1-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.1.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L2-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.2.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L3-N.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.3.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L1.current", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.4.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L2.current", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.5.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L3.current", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.6.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.frequency", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.7.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L1.realpower", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.8.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L1.realpower", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.9.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L1.realpower", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.10.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L1.power", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.11.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L2.power", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.12.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L3.power", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.13.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L1.power.percent", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.14.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L2.power.percent", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.15.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L3.power.percent", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.16.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.voltage.nominal", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.17.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, huawei_voltrating_info), snmp_info_default("output.frequency.nominal", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.18.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, huawei_freqrating_info), snmp_info_default("output.power.nominal", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.2011.6.174.1.2.100.1.6.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, huawei_pwrrating_info), snmp_info_default("output.L1.powerfactor", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.19.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L2.powerfactor", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.20.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("output.L2.powerfactor", 0, 0.01, ".1.3.6.1.4.1.2011.6.174.1.4.100.1.21.1", NULL, SU_FLAG_OK, NULL), /* Battery page */ snmp_info_default("battery.voltage", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.6.100.1.1.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("battery.current", 0, 0.1, ".1.3.6.1.4.1.2011.6.174.1.6.100.1.2.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("battery.charge", 0, 1, ".1.3.6.1.4.1.2011.6.174.1.6.100.1.3.1", NULL, SU_FLAG_OK, NULL), snmp_info_default("battery.runtime", 0, 1, ".1.3.6.1.4.1.2011.6.174.1.6.100.1.4.1", NULL, SU_FLAG_OK, NULL), #if WITH_UNMAPPED_DATA_POINTS snmp_info_default("unmapped.hwUpsBattTest", 0, 1, ".1.3.6.1.4.1.2011.6.174.1.103.101.1.6.1", NULL, SU_FLAG_OK, NULL), #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t huawei = { "huawei", HUAWEI_MIB_VERSION, NULL, HUAWEI_OID_MODEL_NAME, huawei_mib, HUAWEI_SYSOID, NULL }; nut-2.8.4/drivers/eaton-ats16-nmc-mib.c0000644000175000017500000004145215000601404014454 00000000000000/* eaton-ats16-nmc-mib.c - subdriver to monitor Eaton ATS16 NMC SNMP devices with NUT * using legacy NMC cards * * Copyright (C) * 2011-2012 Arnaud Quette * 2016-2020 Eaton (author: Arnaud Quette ) * * Note: this subdriver was initially generated as a "stub" by the * gen-snmp-subdriver script. It must be customized! * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "eaton-ats16-nmc-mib.h" #define EATON_ATS16_NMC_MIB_VERSION "0.21" #define EATON_ATS16_NMC_SYSOID ".1.3.6.1.4.1.705.1" /* legacy NMC */ #define EATON_ATS16_NMC_MODEL ".1.3.6.1.4.1.534.10.2.1.2.0" static info_lkp_t eaton_ats16_nmc_source_info[] = { info_lkp_default(1, "init"), info_lkp_default(2, "diagnosis"), info_lkp_default(3, "off"), info_lkp_default(4, "1"), info_lkp_default(5, "2"), info_lkp_default(6, "safe"), info_lkp_default(7, "fault"), info_lkp_sentinel }; static info_lkp_t eaton_ats16_nmc_sensitivity_info[] = { info_lkp_default(1, "normal"), info_lkp_default(2, "high"), info_lkp_default(3, "low"), info_lkp_sentinel }; static info_lkp_t eaton_ats16_nmc_input_frequency_status_info[] = { info_lkp_default(1, "good"), /* No threshold triggered */ info_lkp_default(2, "out-of-range"), /* Frequency out of range triggered */ info_lkp_sentinel }; static info_lkp_t eaton_ats16_nmc_input_voltage_status_info[] = { info_lkp_default(1, "good"), /* No threshold triggered */ info_lkp_default(2, "derated-range"), /* Voltage derated */ info_lkp_default(3, "out-of-range"), /* Voltage out of range triggered */ info_lkp_default(4, "unknown"), /* "missing" */ info_lkp_sentinel }; static info_lkp_t eaton_ats16_nmc_test_result_info[] = { info_lkp_default(1, "done and passed"), info_lkp_default(2, "done and warning"), info_lkp_default(3, "done and error"), info_lkp_default(4, "aborted"), info_lkp_default(5, "in progress"), info_lkp_default(6, "no test initiated"), info_lkp_sentinel }; static info_lkp_t eaton_ats16_nmc_output_status_info[] = { info_lkp_default(1, "OFF"), /* Output not powered */ info_lkp_default(2, "OL"), /* Output powered */ info_lkp_sentinel }; static info_lkp_t eaton_ats16_nmc_ambient_drycontacts_info[] = { info_lkp_default(-1, "unknown"), info_lkp_default(1, "opened"), info_lkp_default(2, "closed"), info_lkp_default(3, "opened"), /* openWithNotice */ info_lkp_default(4, "closed"), /* closedWithNotice */ info_lkp_sentinel }; /* EATON_ATS_NMC Snmp2NUT lookup table */ static snmp_info_t eaton_ats16_nmc_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device collection */ snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "ats", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /* ats2IdentManufacturer.0 = STRING: EATON */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.1.1.0", "Eaton", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ats2IdentModel.0 = STRING: Eaton ATS */ snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.1.2.0", "ATS", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* FIXME: RFC for device.firmware! */ /* FIXME: the 2 "firmware" entries below should be SU_FLAG_SEMI_STATIC */ /* ats2IdentFWVersion.0 = STRING: 00.00.0009 */ snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.1.3.0", NULL, SU_FLAG_OK, NULL), /* FIXME: RFC for device.firmware.aux! */ /* ats2IdentRelease.0 = STRING: JF */ snmp_info_default("ups.firmware.aux", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.1.4.0", NULL, SU_FLAG_OK, NULL), /* ats2IdentSerialNumber.0 = STRING: GA04F23009 */ snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.1.5.0", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ats2IdentPartNumber.0 = STRING: EATS16N */ snmp_info_default("device.part", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.1.6.0", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ats2IdentAgentVersion.0 = STRING: 301F23C28 */ /* { "unmapped.ats2IdentAgentVersion", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.1.7.0", NULL, SU_FLAG_OK, NULL, NULL }, */ /* ats2InputDephasing.0 = INTEGER: 2 degrees */ /* { "unmapped.ats2InputDephasing", 0, 1, ".1.3.6.1.4.1.534.10.2.2.1.1.0", NULL, SU_FLAG_OK, NULL, NULL }, */ /* Input collection */ /* ats2InputIndex.source1 = INTEGER: source1(1) */ snmp_info_default("input.1.id", 0, 1, ".1.3.6.1.4.1.534.10.2.2.2.1.1.1", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ats2InputIndex.source2 = INTEGER: source2(2) */ snmp_info_default("input.2.id", 0, 1, ".1.3.6.1.4.1.534.10.2.2.2.1.1.2", NULL, SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* ats2InputVoltage.source1 = INTEGER: 2292 0.1 V */ snmp_info_default("input.1.voltage", 0, 0.1, ".1.3.6.1.4.1.534.10.2.2.2.1.2.1", NULL, SU_FLAG_OK, NULL), /* ats2InputVoltage.source2 = INTEGER: 2432 0.1 V */ snmp_info_default("input.2.voltage", 0, 0.1, ".1.3.6.1.4.1.534.10.2.2.2.1.2.2", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusVoltage.source1 = INTEGER: normalRange(1) */ snmp_info_default("input.1.voltage.status", ST_FLAG_STRING, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.5.1", NULL, SU_FLAG_OK, eaton_ats16_nmc_input_voltage_status_info), /* ats2InputStatusVoltage.source2 = INTEGER: normalRange(1) */ snmp_info_default("input.2.voltage.status", ST_FLAG_STRING, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.5.2", NULL, SU_FLAG_OK, eaton_ats16_nmc_input_voltage_status_info), /* ats2InputFrequency.source1 = INTEGER: 500 0.1 Hz */ snmp_info_default("input.1.frequency", 0, 0.1, ".1.3.6.1.4.1.534.10.2.2.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* ats2InputFrequency.source2 = INTEGER: 500 0.1 Hz */ snmp_info_default("input.2.frequency", 0, 0.1, ".1.3.6.1.4.1.534.10.2.2.2.1.3.2", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusFrequency.source1 = INTEGER: good(1) */ snmp_info_default("input.1.frequency.status", ST_FLAG_STRING, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.2.1", NULL, SU_FLAG_OK, eaton_ats16_nmc_input_frequency_status_info), /* ats2InputStatusFrequency.source2 = INTEGER: good(1) */ snmp_info_default("input.2.frequency.status", ST_FLAG_STRING, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.2.2", NULL, SU_FLAG_OK, eaton_ats16_nmc_input_frequency_status_info), /* ats2ConfigSensitivity.0 = INTEGER: normal(1) */ snmp_info_default("input.sensitivity", ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.4.6.0", NULL, SU_FLAG_OK, &eaton_ats16_nmc_sensitivity_info[0]), /* ats2OperationMode.0 = INTEGER: source1(4) */ snmp_info_default("input.source", ST_FLAG_STRING, 1, ".1.3.6.1.4.1.534.10.2.2.4.0", NULL, SU_FLAG_OK, eaton_ats16_nmc_source_info), /* ats2ConfigPreferred.0 = INTEGER: source1(1) */ snmp_info_default("input.source.preferred", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.2.4.5.0", NULL, SU_FLAG_OK, NULL), /* ats2InputDephasing = INTEGER: 181 */ snmp_info_default("input.phase.shift", 0, 1, ".1.3.6.1.4.1.534.10.2.2.1.1.0", NULL, SU_FLAG_OK, NULL), /* Output collection */ /* ats2OutputVoltage.0 = INTEGER: 2304 0.1 V */ snmp_info_default("output.voltage", 0, 0.1, ".1.3.6.1.4.1.534.10.2.2.3.1.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigOutputVoltage.0 = INTEGER: 230 1 V */ snmp_info_default("output.voltage.nominal", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.2.4.4.0", NULL, SU_FLAG_OK, NULL), /* ats2OutputCurrent.0 = INTEGER: 5 0.1 A */ snmp_info_default("output.current", 0, 0.1, ".1.3.6.1.4.1.534.10.2.2.3.2.0", NULL, SU_FLAG_OK, NULL), /* UPS collection */ /* FIXME: RFC for device.test.result! */ /* ats2ConfigTransferTest.0 = INTEGER: noTestInitiated(6) */ snmp_info_default("ups.test.result", 0, 1, ".1.3.6.1.4.1.534.10.2.4.8.0", NULL, SU_FLAG_OK, eaton_ats16_nmc_test_result_info), /* FIXME: RFC for device.status! */ /* ats2StatusOutput.0 = INTEGER: outputPowered(2) */ snmp_info_default("ups.status", 0, 1, ".1.3.6.1.4.1.534.10.2.3.3.2.0", NULL, SU_FLAG_OK, eaton_ats16_nmc_output_status_info), /* Ambient collection */ /* ats2EnvRemoteTemp.0 = INTEGER: 0 degrees Centigrade */ snmp_info_default("ambient.temperature", 0, 0.1, ".1.3.6.1.4.1.534.10.2.5.1.0", NULL, SU_FLAG_OK, NULL), /* ats2EnvRemoteTempLowerLimit.0 = INTEGER: 5 degrees Centigrade */ snmp_info_default("ambient.temperature.low", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.2.5.5.0", NULL, SU_FLAG_OK, NULL), /* ats2EnvRemoteTempUpperLimit.0 = INTEGER: 40 degrees Centigrade */ snmp_info_default("ambient.temperature.high", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.2.5.6.0", NULL, SU_FLAG_OK, NULL), /* ats2EnvRemoteHumidity.0 = INTEGER: 0 percent */ snmp_info_default("ambient.humidity", 0, 0.1, ".1.3.6.1.4.1.534.10.2.5.2.0", NULL, SU_FLAG_OK, NULL), /* ats2EnvRemoteHumidityLowerLimit.0 = INTEGER: 5 percent */ snmp_info_default("ambient.humidity.low", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.2.5.7.0", NULL, SU_FLAG_OK, NULL), /* ats2EnvRemoteHumidityUpperLimit.0 = INTEGER: 90 percent */ snmp_info_default("ambient.humidity.high", ST_FLAG_RW, 1, ".1.3.6.1.4.1.534.10.2.5.8.0", NULL, SU_FLAG_OK, NULL), /* Dry contacts on EMP001 TH module */ /* ats2ContactState.1 = INTEGER: open(1) */ snmp_info_default("ambient.contacts.1.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.5.4.1.3.1", NULL, SU_FLAG_OK, &eaton_ats16_nmc_ambient_drycontacts_info[0]), /* ats2ContactState.2 = INTEGER: open(1) */ snmp_info_default("ambient.contacts.2.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.5.4.1.3.2", NULL, SU_FLAG_OK, &eaton_ats16_nmc_ambient_drycontacts_info[0]), #if WITH_UNMAPPED_DATA_POINTS /* FIXME: Remaining data to be processed */ /* ats2InputStatusDephasing.0 = INTEGER: normal(1) */ snmp_info_default("unmapped.ats2InputStatusDephasing", 0, 1, ".1.3.6.1.4.1.534.10.2.3.1.1.0", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusIndex.source1 = INTEGER: source1(1) */ snmp_info_default("unmapped.ats2InputStatusIndex", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.1.1", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusIndex.source2 = INTEGER: source2(2) */ snmp_info_default("unmapped.ats2InputStatusIndex", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.1.2", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusGood.source1 = INTEGER: voltageAndFreqNormalRange(2) */ snmp_info_default("unmapped.ats2InputStatusGood", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.3.1", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusGood.source2 = INTEGER: voltageAndFreqNormalRange(2) */ snmp_info_default("unmapped.ats2InputStatusGood", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.3.2", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusInternalFailure.source1 = INTEGER: good(1) */ snmp_info_default("unmapped.ats2InputStatusInternalFailure", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.4.1", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusInternalFailure.source2 = INTEGER: good(1) */ snmp_info_default("unmapped.ats2InputStatusInternalFailure", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.4.2", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusUsed.source1 = INTEGER: poweringLoad(2) */ snmp_info_default("unmapped.ats2InputStatusUsed", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.6.1", NULL, SU_FLAG_OK, NULL), /* ats2InputStatusUsed.source2 = INTEGER: notPoweringLoad(1) */ snmp_info_default("unmapped.ats2InputStatusUsed", 0, 1, ".1.3.6.1.4.1.534.10.2.3.2.1.6.2", NULL, SU_FLAG_OK, NULL), /* ats2StatusInternalFailure.0 = INTEGER: good(1) */ snmp_info_default("unmapped.ats2StatusInternalFailure", 0, 1, ".1.3.6.1.4.1.534.10.2.3.3.1.0", NULL, SU_FLAG_OK, NULL), /* ats2StatusOverload.0 = INTEGER: noOverload(1) */ snmp_info_default("unmapped.ats2StatusOverload", 0, 1, ".1.3.6.1.4.1.534.10.2.3.3.3.0", NULL, SU_FLAG_OK, NULL), /* ats2StatusOverTemperature.0 = INTEGER: noOverTemperature(1) */ snmp_info_default("unmapped.ats2StatusOverTemperature", 0, 1, ".1.3.6.1.4.1.534.10.2.3.3.4.0", NULL, SU_FLAG_OK, NULL), /* ats2StatusShortCircuit.0 = INTEGER: noShortCircuit(1) */ snmp_info_default("unmapped.ats2StatusShortCircuit", 0, 1, ".1.3.6.1.4.1.534.10.2.3.3.5.0", NULL, SU_FLAG_OK, NULL), /* ats2StatusCommunicationLost.0 = INTEGER: good(1) */ snmp_info_default("unmapped.ats2StatusCommunicationLost", 0, 1, ".1.3.6.1.4.1.534.10.2.3.3.6.0", NULL, SU_FLAG_OK, NULL), /* ats2StatusConfigurationFailure.0 = INTEGER: good(1) */ snmp_info_default("unmapped.ats2StatusConfigurationFailure", 0, 1, ".1.3.6.1.4.1.534.10.2.3.3.7.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigTimeRTC.0 = Wrong Type (should be Counter32): Gauge32: 19191036 */ snmp_info_default("unmapped.ats2ConfigTimeRTC", 0, 1, ".1.3.6.1.4.1.534.10.2.4.1.1.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigTimeTextDate.0 = STRING: 08/11/1970 */ snmp_info_default("unmapped.ats2ConfigTimeTextDate", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.4.1.2.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigTimeTextTime.0 = STRING: 02/50/36 */ snmp_info_default("unmapped.ats2ConfigTimeTextTime", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.4.1.3.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigInputVoltageRating.0 = INTEGER: 1 1 V */ snmp_info_default("unmapped.ats2ConfigInputVoltageRating", 0, 1, ".1.3.6.1.4.1.534.10.2.4.2.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigInputFrequencyRating.0 = INTEGER: 50 Hz */ snmp_info_default("unmapped.ats2ConfigInputFrequencyRating", 0, 1, ".1.3.6.1.4.1.534.10.2.4.3.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigTransferMode.0 = INTEGER: standard(1) */ snmp_info_default("unmapped.ats2ConfigTransferMode", 0, 1, ".1.3.6.1.4.1.534.10.2.4.7.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigBrownoutLow.0 = INTEGER: 202 1 V */ snmp_info_default("unmapped.ats2ConfigBrownoutLow", 0, 1, ".1.3.6.1.4.1.534.10.2.4.9.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigBrownoutLowDerated.0 = INTEGER: 189 1 V */ snmp_info_default("unmapped.ats2ConfigBrownoutLowDerated", 0, 1, ".1.3.6.1.4.1.534.10.2.4.10.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigBrownoutHigh.0 = INTEGER: 258 1 V */ snmp_info_default("unmapped.ats2ConfigBrownoutHigh", 0, 1, ".1.3.6.1.4.1.534.10.2.4.11.0", NULL, SU_FLAG_OK, NULL), /* ats2ConfigHysteresisVoltage.0 = INTEGER: 5 1 V */ snmp_info_default("unmapped.ats2ConfigHysteresisVoltage", 0, 1, ".1.3.6.1.4.1.534.10.2.4.12.0", NULL, SU_FLAG_OK, NULL), /* Ambient collection */ /* ats2EnvNumContacts.0 = INTEGER: 2 */ snmp_info_default("unmapped.ats2EnvNumContacts", 0, 1, ".1.3.6.1.4.1.534.10.2.5.3.0", NULL, SU_FLAG_OK, NULL), /* ats2ContactIndex.1 = INTEGER: 1 */ snmp_info_default("unmapped.ats2ContactIndex", 0, 1, ".1.3.6.1.4.1.534.10.2.5.4.1.1.1", NULL, SU_FLAG_OK, NULL), /* ats2ContactIndex.2 = INTEGER: 2 */ snmp_info_default("unmapped.ats2ContactIndex", 0, 1, ".1.3.6.1.4.1.534.10.2.5.4.1.1.2", NULL, SU_FLAG_OK, NULL), /* ats2ContactType.1 = INTEGER: notUsed(4) */ snmp_info_default("unmapped.ats2ContactType", 0, 1, ".1.3.6.1.4.1.534.10.2.5.4.1.2.1", NULL, SU_FLAG_OK, NULL), /* ats2ContactType.2 = INTEGER: notUsed(4) */ snmp_info_default("unmapped.ats2ContactType", 0, 1, ".1.3.6.1.4.1.534.10.2.5.4.1.2.2", NULL, SU_FLAG_OK, NULL), /* ats2ContactDescr.1 = STRING: Input #1 */ snmp_info_default("unmapped.ats2ContactDescr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.5.4.1.4.1", NULL, SU_FLAG_OK, NULL), /* ats2ContactDescr.2 = STRING: Input #2 */ snmp_info_default("unmapped.ats2ContactDescr", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.534.10.2.5.4.1.4.2", NULL, SU_FLAG_OK, NULL), #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* end of structure. */ snmp_info_sentinel }; /* Note: keep the legacy definition intact, to avoid breaking compatibility */ /* FIXME: The lines below are duplicated to fix an issue with the code generator (nut-snmpinfo.py -> line is discarding) */ /* Note: * due to a bug in tools/nut-snmpinfo.py, prepending a 2nd mib2nut_info_t * declaration with a comment line results in data extraction not being * done for all entries in the file. Hence the above comment line being * after its belonging declaration! */ /*mib2nut_info_t eaton_ats16_nmc = { "eaton_ats16_nmc", EATON_ATS16_NMC_MIB_VERSION, NULL, EATON_ATS16_NMC_MODEL, eaton_ats16_nmc_mib, EATON_ATS16_NMC_SYSOID, NULL }; */ mib2nut_info_t eaton_ats16_nmc = { "eaton_ats16_nmc", EATON_ATS16_NMC_MIB_VERSION, NULL, EATON_ATS16_NMC_MODEL, eaton_ats16_nmc_mib, EATON_ATS16_NMC_SYSOID, NULL }; nut-2.8.4/drivers/nutdrv_qx_voltronic.h0000644000175000017500000000176314670526611015253 00000000000000/* nutdrv_qx_voltronic.h - Subdriver for Voltronic Power UPSes * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_VOLTRONIC_H #define NUTDRV_QX_VOLTRONIC_H #include "nutdrv_qx.h" extern subdriver_t voltronic_subdriver; #endif /* NUTDRV_QX_VOLTRONIC_H */ nut-2.8.4/drivers/netxml-ups.h0000644000175000017500000000521014777753337013244 00000000000000/* netxml-ups.h Driver data/defines for network XML UPS units Copyright (C) 2008-2009 Arjen de Korte This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NETXML_UPS_H #define NETXML_UPS_H #include "nut_stdint.h" typedef struct { const char *version; /* name of this subdriver */ const char *initups; const char *initinfo; char *configure; /* central configuration */ char *subscribe; /* alarm subscriptions */ char *summary; /* used for quick updates */ char *getobject; char *setobject; int (*startelm_cb)(void *userdata, int parent, const char *nspace, const char *name, const char **atts); int (*cdata_cb)(void *userdata, int state, const char *cdata, size_t len); int (*endelm_cb)(void *userdata, int state, const char *nspace, const char *name); } subdriver_t; /* ---------------------------------------------------------------------- */ /* data for processing boolean values from UPS */ #define STATUS_BIT(x) (ups_status & (uint32_t)1< * (C) 2000 Nigel Metheringham * (C) 2011+ Michal Soltys * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_APCSMART_H_SEEN #define NUT_APCSMART_H_SEEN 1 #define ALT_CABLE_1 "940-0095B" /* * alerts and other stuff for quick reference: * * $ OL * ! OB * % LB * + not LB anymore * # RB * ? OVER * = not OVER anymore * * powering down now (only older models ?), handled by upsread() * otherwise ignored (it doesn't have to be in ignore sets) * * | eeprom change * & check alarm register for fail * ~ ??? */ /* * old ones for reference: * #define IGNCHARS "\015+$|!~%?=#&" * #define POLL_IGNORE "\015&|" * #define POLL_ALERT "$!%+#?=" * #define MINIGNCHARS "\015+$|!" * notice ~ that was present in IGNCHARS, but not in POLL_IGNORE - this kinda * didn't make sense (?); new versions doesn't filter ~, but keep that in mind * in case something obscure surfaces * due to switch to ICANON tty mode, we removed \015 from ignored characters, * as it's handled by IGNCR at read() level */ /* * about CR: * apparently windows is unable to ignore CRs by means of IGNCR flag (or * perhaps there is something else involved); so despite IGNCR we re-aad \015 * to ignore sets for now; see: * http://article.gmane.org/gmane.comp.monitoring.nut.user/7762 * * furthermore, since the canonical/non-canonical mode is user selectable now, * we have to ignore this character explicitly */ #ifndef WIN32 #include #endif /* !WIN32 */ /* Basic UPS reply line structure */ #define ENDCHAR 10 /* APC ends responses with LF (and CR, but it's IGNCRed) */ /* what to ignore during alert aware serial reads */ #define IGN_AACHARS "\015|&" /* what alert_handler() should care about */ #define ALERT_CHARS "$!%+#?=" /* characters ignored by alertless reads */ #define IGN_CHARS IGN_AACHARS ALERT_CHARS /* * these ones are used only during Capability Check read, due to ^Z sending * certain characters such as #; it seems it could be equal to just IGN_CHARS * w/o # old: #define IGN_CCCHARS "|$!+" */ #define IGN_CCCHARS "\015|&$!%+?=" /* capability check ignore set */ /* * Command Set 'a' reports everything - protocol number, alerts and supported * commands */ #define IGN_CSCHARS "" /* command set ignore set */ /* dangerous instant commands must be reconfirmed within a 12 second window */ #define MINCMDTIME 3 #define MAXCMDTIME 15 /* it only does two strings, and they're both the same length */ #define APC_STRLEN 8 #define SER_D0 0x001 /* 0 sec., for flushes */ #define SER_DX 0x002 /* 200 ms for long/repeated cmds, in case of unexpected NAs */ #define SER_D1 0x004 /* 1.5 sec. */ #define SER_D3 0x008 /* 3 sec. (default) */ #define SER_AA 0x010 /* Alert Aware set */ #define SER_CC 0x020 /* Capability Check ign set */ #define SER_CS 0x040 /* Command Set ign set */ #define SER_TO 0x080 /* timeout allowed */ #define SER_HA 0x100 /* handle asterisk */ /* sets of the above (don't test against them, obviously */ /* * Some cmd codes to ignore (nut doesn't expose those, though the driver might * use them internally (e.g. [a]). If you decide to support them at some * point, remember about removing them from here ! */ #define APC_UNR_CMDS "\032\177~')-+8QRYayz" /* --------------- */ /* status bits */ #define APC_STAT_CAL (1L << 0) /* calibration */ #define APC_STAT_TRIM (1L << 1) /* SmartTrim */ #define APC_STAT_BOOST (1L << 2) /* SmartBoost */ #define APC_STAT_OL (1L << 3) /* on line */ #define APC_STAT_OB (1L << 4) /* on battery */ #define APC_STAT_OVER (1L << 5) /* overload */ #define APC_STAT_LB (1L << 6) /* low battery */ #define APC_STAT_RB (1L << 7) /* replace battery */ /* * serial protocol: special commands - initialization and such * these are not exposed as instant commands */ #define APC_STATUS 'Q' #define APC_GOSMART 'Y' #define APC_GODUMB 'R' #define APC_CMDSET 'a' #define APC_CMDSET_FMT "^[0-9]\\.[^.]*\\.[^.]+(\\.[^.]+)?$" #define APC_CAPS '\032' /* ^Z */ #define APC_NEXTVAL '-' #define APC_FW_OLD 'V' #define APC_FW_NEW 'b' #define APC_LBUF 512 #define APC_SBUF 32 /* default a.w.d. value / regex format for command '@' */ #define APC_AWDFMT "^[0-9]{1,3}$" /* sdtype method regex format*/ #define APC_SDFMT "^[0-5]$" /* advorder method regex format*/ #define APC_ADVFMT "^([0-4]{1,5}|[Nn][Oo])$" /* cshdelay format */ #define APC_CSHDFMT "^([0-9]\\.?|[0-9]?\\.[0-9])$" #endif /* NUT_APCSMART_H_SEEN */ nut-2.8.4/drivers/nutdrv_hashx.c0000644000175000017500000005117215044656702013632 00000000000000/* nutdrv_hashx.c - Driver for serial UPS units with #* protocols * * Copyright (C) * 2025 Marco Trevisan (Treviño) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "common.h" #include "config.h" #include "dstate.h" #include "main.h" #include "nut_stdint.h" #include "powerpanel.h" #include "serial.h" #include "str.h" #include "upshandler.h" #include #include #include #define ENDCHAR '\r' #define IGNCHARS "" #define DRIVER_NAME "Generic #* Serial driver" #define DRIVER_VERSION "0.02" #define SESSION_ID "OoNUTisAMAZINGoO" #define SESSION_HASH "74279F35A48F5F13" /* These commands have been tested on an Atlantis Land A03-S1200 */ #define COMMAND_GET_SESSION_HASH "X19" /*-> #16-hex-values */ #define COMMAND_SET_SESSION_ID "K19" /* :value -> Status value */ #define COMMAND_SET_BEEPER_ENABLED "K60" /* :0|1 -> Status value */ #define COMMAND_SET_FREQUENCY_MODE "K39" /* :0|1 -> Status value */ #define COMMAND_GET_BYPASS_CONDITION_MANDATORY "X87" /* -> #\xc7\x97\xf0\xf0 */ #define COMMAND_SET_BYPASS_CONDITION_MANDATORY "K87" /* :0|1 -> Status value */ #define COMMAND_GET_BYPASS_CONDITION_OVERLOAD "X15" /* -> #10 */ #define COMMAND_SET_BYPASS_CONDITION_OVERLOAD "K15" /* :0|1 -> Status value */ #define COMMAND_GET_UPS_DEVICE_INFO "X41" /* -> #1200,PE02022.002,000000000000,000000000000000000 */ #define COMMAND_GET_INPUT_VOLTAGE_SETTINGS "X27" /* -> #230,290,162,10,300 */ #define COMMAND_GET_INPUT_VOLTAGE_UPPER_BOUND "X51" /* -> #290 */ #define COMMAND_GET_INPUT_VOLTAGE_LOWER_BOUND "X60" /* -> #162 */ #define COMMAND_GET_UPS_POWER_INFO "X72" /* -> #1200,0720,230,40,70,05.20 */ #define COMMAND_GET_STATUS "B" /* -> #I239.0O237.0L007B100V27.0F50.1H50.1R040S\x80\0x84\0xd0\x80\x80\0xc0 */ #define COMMAND_START_BATTERY_TEST "A" /* -> Status value */ #define COMMAND_START_BATTERY_RUNTIME_TEST "AH" /* -> Status value */ #define COMMAND_START_BEEPER_TEST "AU" /* -> Status value */ #define COMMAND_STOP_TEST "KA" /* -> Status value */ #define COMMAND_UNKNOWN5 "X5" /* -> #12,2,7,0,5,480 */ #define COMMAND_UNKNOWN71 "X71" /* -> #\x80\x80 */ /* Commands supported by the protocol that PowerMaster+ uses and not supported * by the devices tested so far: * X4 * X5 * X15 * X14 | K14:(0|1) * X17 * X23 * X24 * X27 * X28 * X29 * X30 * X33 * X41 * X43 * X51 * X53 * X58 * X60 * X61 * X71 * X72 * X73 * X80 * X87 * X88 * X98 * X99 */ enum { STATUS_SUCCESS = 0, /* Generic failure */ STATUS_FAILURE = -1, /* If the command is not known or supported by the device */ STATUS_COMMAND_NOT_SUPPORTED = -3, /* When a command parameter is not valid (e.g. "K60:foo") */ STATUS_COMMAND_VALUE_INVALID = -4, /* When a command is currently unavailable (e.g. "AH" while charging ) */ STATUS_COMMAND_UNAVAILABLE = -10, /* Local error: when a parsing error occurred */ STATUS_UNKNOWN_FAILURE = -255, }; upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Marco Trevisan ", DRV_EXPERIMENTAL, { NULL } }; static struct hashx_cmd_t { const char *cmd_name; const char *ups_cmd; } hashx_cmd[] = { { "beeper.enable", COMMAND_SET_BEEPER_ENABLED":1" }, { "beeper.disable", COMMAND_SET_BEEPER_ENABLED":0" }, { "experimental.test.beeper.start", COMMAND_START_BEEPER_TEST }, { "experimental.test.beeper.stop", COMMAND_STOP_TEST }, { "test.battery.start.deep", COMMAND_START_BATTERY_RUNTIME_TEST }, { "test.battery.start.quick", COMMAND_START_BATTERY_TEST }, { "test.battery.stop", COMMAND_STOP_TEST }, { "calibrate.start", COMMAND_START_BATTERY_RUNTIME_TEST }, { "calibrate.stop", COMMAND_STOP_TEST }, }; static int hashx_instcmd(const char *cmd_name, const char *extra); static ssize_t hashx_recv(char *buf, size_t bufsize) { ssize_t nread; nread = ser_get_line(upsfd, buf, bufsize - 1, ENDCHAR, IGNCHAR, SER_WAIT_SEC, SER_WAIT_USEC); assert(nread < (ssize_t) bufsize); buf[nread] = '\0'; if (nut_debug_level >= 4) { char base_msg[128]; int n; n = snprintf(base_msg, sizeof(base_msg), "%s: read %" PRIiSIZE ": ", __func__, nread); assert(n > 0); upsdebug_ascii(4, base_msg, buf, nread); } if (nread > 0 && *buf != '#') { upslogx(LOG_ERR, "Unexpected reply for #-protocol: %s", buf); } return nread; } static int hashx_status_value(char *buf, size_t bufsize) { ssize_t nread; int ret = STATUS_UNKNOWN_FAILURE; if ((nread = hashx_recv(buf, bufsize)) < 2 || nread > 3) { upslogx(LOG_ERR, "Not an UPS status value: %s", buf); return ret; } if (!str_to_int(buf + 1, &ret, 10)) { upslogx(LOG_ERR, "Failed to convert %s to number", buf + 1); return ret; } upsdebugx(5, "Read status is %d", ret); return ret; } static int hashx_send_command(const char *command) { size_t transferred; char buf[16]; int status; if ((transferred = ser_send(upsfd, "%s%c", command, ENDCHAR)) != strlen (command) + 1) { upslogx(LOG_ERR, "%s: Failed to send command: %s", __func__, command); return STATUS_UNKNOWN_FAILURE; } if ((status = hashx_status_value(buf, sizeof(buf))) != STATUS_SUCCESS) { upslogx(LOG_ERR, "%s: unexpected hash protocol response: %s (status %d)", __func__, buf, status); } return status; } /* * This is how PowerMaster+ 1.2.3 does when connecting to the UPS: * [pid 22999] write(219, "\r", 1) = 1 * [pid 22999] write(219, "X19\r", 4) = 4 * [pid 22999] write(219, "K19:RRO3143QJqhb1GCj\r", 21) = 21 * [pid 22999] write(219, "X19\r", 4) = 4 * [pid 22999] write(219, "X41\r", 4) = 4 * [pid 23000] write(219, "\r", 1) = 1 * [pid 23000] write(219, "X41\r", 4) = 4 * [pid 23000] write(219, "B\r", 2) = 2 * [pid 23000] write(219, "X27\r", 4) = 4 * [pid 23000] write(219, "X72\r", 4) = 4 * [pid 23000] write(219, "X5\r", 3) = 3 * [pid 23000] write(219, "X53\r", 4) = 4 * [pid 23000] write(219, "X87\r", 4) = 4 * [pid 23000] write(219, "X28\r", 4) = 4 * [pid 23000] write(219, "X51\r", 4) = 4 * [pid 23000] write(219, "X60\r", 4) = 4 * [pid 23000] write(219, "X15\r", 4) = 4 * [pid 23000] write(219, "K14:0\r", 6) = 6 * [pid 23000] write(219, "X4\r", 3) = 3 * [pid 23000] write(219, "X58\r", 4) = 4 * [pid 23000] write(219, "X30\r", 4) = 4 * [pid 23000] write(219, "X71\r", 4) = 4 * [pid 23000] write(219, "X43\r", 4) = 4 * [pid 23000] write(219, "X73\r", 4) = 4 * [pid 23000] write(219, "X88\r", 4) = 4 * [pid 23000] write(219, "X17\r", 4) = 4 * [pid 23000] write(219, "X98\r", 4) = 4 * [pid 23000] write(219, "X14\r", 4) = 4 * [pid 23000] write(219, "X99\r", 4) = 4 * [pid 23000] write(219, "X29\r", 4) = 4 * [pid 23000] write(219, "X61\r", 4) = 4 * [pid 23000] write(219, "X33\r", 4) = 4 * [pid 23000] write(219, "X23\r", 4) = 4 * [pid 23000] write(219, "X24\r", 4) = 4 * [pid 23000] write(219, "X80\r", 4) = 4 * [pid 23000] write(219, "B\r", 2) = 2 * [pid 23000] write(219, "B\r", 2) = 2 * .... These last ones are the polling requests repeated forever .... */ void upsdrv_initinfo(void) { ssize_t transferred; char buf[256]; char *reply; int status; int ival; double dval; size_t i; for (i = 0; ; ++i) { upsdebugx(4, "Checking if device supports the #-protocol... [%" PRIuSIZE "]", i+1); if ((transferred = ser_send_char(upsfd, ENDCHAR)) != 1) { fatalx(EXIT_FAILURE, "%s: Initialization failure %s", __func__, device_path); } if ((status = hashx_status_value(buf, sizeof(buf))) == -1) { break; } if (i < 3) { continue; } fatalx(EXIT_FAILURE, "%s: unexpected hash protocol response: %s (status %d)", __func__, buf, status); } /* The K19 function needs a 16 bytes value and the device should reply * with an hash or a crc of it, it's not clear what's the algorithm it * uses, but given that the returned value is static, we can just always * send one value we know about, to verify the protocol. */ if ((status = hashx_send_command(COMMAND_SET_SESSION_ID":"SESSION_ID)) != STATUS_SUCCESS) { fatalx(EXIT_FAILURE, "%s: Failed to set session ID: %s", __func__, SESSION_ID); } if ((transferred = ser_send(upsfd, COMMAND_GET_SESSION_HASH"%c", ENDCHAR)) != 4) { fatalx(EXIT_FAILURE, "%s: Failed to get session hash", __func__); } if ((transferred = hashx_recv(buf, sizeof(buf))) != strlen(SESSION_HASH) + 1 || (transferred > 0 && strncmp(buf, "#"SESSION_HASH, sizeof(buf)) != 0)) { fatalx(EXIT_FAILURE, "%s: unexpected hash protocol response: %s", __func__, buf); } /* XXX: Maybe now repeat the same with a random value, without checking * the content of the returned value, but just in case the UPS uses this * value as a "session" identifier, to make sure we are starting a new * one. * Another option could be to keep a list of known request, response * pair values and use them randomly. * However, not doing it for now since it seems unneeded, while just * always reusing the same value works good enough in my tests. */ dstate_setinfo("device.type", "ups"); dstate_setinfo("ups.type", "online"); /* FIXME: We need to understand how PowerManager+ figures this out, * as it supports both On-Line and Line Interactive devices. * Or is it related to the support to the bypass feature? * Maybe it's what `X5` command provides? We need to test more devices! */ dstate_setinfo("ups.mode", "line-interactive"); if ((transferred = ser_send(upsfd, COMMAND_GET_UPS_DEVICE_INFO"%c", ENDCHAR)) != 4) { fatalx(EXIT_FAILURE, "%s: Failed to get UPS info", __func__); } if ((transferred = hashx_recv(buf, sizeof(buf))) < 3) { fatalx(EXIT_FAILURE, "%s: unexpected UPS info response: %s", __func__, buf); } /* This is in the format: * #1200,PE02022.002,000000000000,000000000000000000 * 1 2 3 4 * 1) Model * 2) Firmware version * 3) ??? [maybe device serial number?] * 4) ??? [as above?] */ reply = buf + 1; dstate_setinfo("device.model", "%s", strsep(&reply, ",")); if (reply) { dstate_setinfo("ups.firmware", "%s", strsep(&reply, ",")); } if ((transferred = ser_send(upsfd, COMMAND_GET_INPUT_VOLTAGE_SETTINGS"%c", ENDCHAR)) != 4) { upslogx(LOG_ERR, "%s: Failed to get UPS voltage settings", __func__); } if ((transferred = hashx_recv(buf, sizeof(buf))) < 3) { upslogx(LOG_ERR, "%s: unexpected UPS voltage settings response: %s", __func__, buf); } /* This is in the format: * #230,290,162,10,300 * 1 2 3 4 5 * 1) Supplied power voltage * 2) Power failure voltage upper bound * 3) Power failure voltage lower bound * 4) ??? * 5) ??? */ reply = buf + 1; if (str_to_int(strsep(&reply, ","), &ival, 10)) { dstate_setinfo("input.voltage.nominal", "%d", ival); } if (reply && str_to_int(strsep(&reply, ","), &ival, 10)) { dstate_setinfo("input.voltage.high.critical", "%d", ival); } if (reply && str_to_int(strsep(&reply, ","), &ival, 10)) { dstate_setinfo("input.voltage.low.critical", "%d", ival); } if ((transferred = ser_send(upsfd, COMMAND_GET_UPS_POWER_INFO"%c", ENDCHAR)) != 4) { upslogx(LOG_ERR, "%s: Failed to get UPS power info", __func__); } if ((transferred = hashx_recv(buf, sizeof(buf))) < 3) { upslogx(LOG_ERR, "%s: unexpected UPS power info response: %s", __func__, buf); } /* This is in the format: * #1200,0720,230,40,70,05.20 * 1 2 3 4 5 6 * 1) Volt-Amp nominal rating * 2) Real power nominal rating * 3) Input voltage nominal rating * 4) Frequency rating lower bound * 5) Frequency rating upper bound * 6) Output Current nominal rating */ reply = buf + 1; if (str_to_int(strsep(&reply, ","), &ival, 10)) { dstate_setinfo("ups.power.nominal", "%d", ival); } if (reply && str_to_int(strsep(&reply, ","), &ival, 10)) { dstate_setinfo("ups.realpower.nominal", "%d", ival); } if (reply && str_to_int(strsep(&reply, ","), &ival, 10)) { dstate_setinfo("input.voltage.nominal", "%d", ival); } if (reply && str_to_double(strsep(&reply, ","), &dval, 10)) { dstate_setinfo("input.frequency.low", "%.1f", dval); } if (reply && str_to_double(strsep(&reply, ","), &dval, 10)) { dstate_setinfo("input.frequency.high", "%.1f", dval); } if (reply && str_to_double(strsep(&reply, ","), &dval, 10)) { dstate_setinfo("output.current.nominal", "%.1f", dval); } if (strsep(&reply, ",") != NULL) { upslogx(LOG_WARNING, "This UPS returns unexpected power info fields (%s), " "previously decoded values may have not been correctly assigned!", buf + 1); } upsh.instcmd = hashx_instcmd; for (i = 0; i < sizeof (hashx_cmd) / sizeof (*hashx_cmd); ++i) { dstate_addcmd(hashx_cmd[i].cmd_name); } } void upsdrv_updateinfo(void) { char buf[256]; ssize_t transferred; size_t i; char *status; int ret; float input_voltage = -1; float output_voltage = -1; float battery_voltage = -1; float input_frequency = -1; float output_frequency = -1; int output_load = -1; int battery_charge = -1; int remaining_runtime = -1; char *status_bytes = NULL; size_t status_bytes_size = 0; if ((transferred = ser_send(upsfd, COMMAND_GET_STATUS"%c", ENDCHAR)) != 2) { upslogx(LOG_ERR, "%s: Failed to get status", __func__); dstate_datastale(); return; } if ((transferred = hashx_recv(buf, sizeof(buf))) <= 0) { upslogx(LOG_ERR, "%s: unexpected status response: %s", __func__, buf); dstate_datastale(); return; } /* This is in the format: * #I239.0O237.0L007B100V27.0F50.1H50.1R040S\x80\0x84\0xd0\x80\x80\0xc0 * I O L B V F H R S * I) Input voltage * O) Output voltage * L) Load * B) Battery capacity * V) Battery voltage * F) Utility frequency * H) Output frequency * R) Runtime (in minutes) * S) UPS Status bytes (see below) */ status = buf + 1; if ((ret = sscanf(status, "I%fO%fL%dB%dV%fF%fH%fR%dS", &input_voltage, &output_voltage, &output_load, &battery_charge, &battery_voltage, &input_frequency, &output_frequency, &remaining_runtime)) == EOF || ret < 1) { upslogx(LOG_ERR, "%s: Impossible to parse: %s", __func__, status); dstate_datastale(); return; } upsdebugx(6, "Poll: input voltage %.1f, output voltage %.1f, load balance %d%%, " "battery level: %d%%, battery voltage: %.1f, input frequency: %.1f, " "output frequency %.1f, remaining runtime: %d minutes", input_voltage, output_voltage, output_load, battery_charge, battery_voltage, input_frequency, output_frequency, remaining_runtime); if (input_voltage >= 0) { dstate_setinfo("input.voltage", "%.1f", input_voltage); } if (output_voltage >= 0) { dstate_setinfo("output.voltage", "%.1f", output_voltage); } if (battery_voltage >= 0) { dstate_setinfo("battery.voltage", "%.1f", battery_voltage); } if (input_frequency >= 0) { dstate_setinfo("input.frequency", "%.1f", input_frequency); } if (output_frequency >= 0) { dstate_setinfo("output.frequency", "%.1f", output_frequency); } if (output_load >= 0) { dstate_setinfo("ups.load", "%d", output_load); } if (battery_charge >= 0) { /* In some devices battery.charge.approx seems to be more appropriate */ dstate_setinfo("battery.charge", "%d", battery_charge); } if (remaining_runtime >= 0) { dstate_setinfo("battery.runtime", "%d", remaining_runtime * 60); } if ((status_bytes = strchr(buf, 'S'))) { status_bytes += 1; status_bytes_size = transferred - (status_bytes - buf); } assert(status_bytes != NULL || status_bytes_size == 0); upsdebug_hex(6, "Poll: status bytes", status_bytes, status_bytes_size); if (!status_bytes || status_bytes_size < 5) { upslogx(LOG_ERR, "Status bytes are not enough: %" PRIuSIZE, status_bytes_size); dstate_dataok(); return; } /* Status bytes values: 0 1 2 3 4 5 * On AC, fully charged: 80 84 d0 80 80 c0 * On AC, high battery, charging: 80 84 90 80 80 c0 * Testing battery, fully charged: 88 80 88 88 80 c0 * Testing battery, charging: 88 80 8c 88 80 c0 * ... battery level at 0: 88 80 8c 88 a0 c0 * Runtime Estimation, fully charged: 88 80 c8 88 80 c0 * ... lowest level, charging: a0 84 94 80 a0 c0 * Battery low charging: 80 84 94 80 80 c0 * Battery low charging + beep: 90 84 94 80 80 c0 * Battery very low, charging: 80 84 94 88 a0 c0 * ... after more charge: 80 84 94 80 a0 c0 * ... after more charge: 80 84 94 88 80 c0 * ...testing beep: 90 84 94 88 80 c0 * Discharging from fully: c0 83 88 88 80 c0 * Discharging: c0 83 8c 80 80 c0 * Discharging, more load: c0 83 8c 88 80 c0 * Discharging Battery very low: c0 83 8c 80 a0 c0 * Discharging Battery alarm: e0 83 8c 80 a0 c0 * UPS output off, charging: 80 84 94 80 c0 c0 */ alarm_init(); status_init(); /* Remove the common bit from the status bytes. */ for (i = 0; i < status_bytes_size; ++i) { status_bytes[i] &= ~0x80; } if (status_bytes[0] & 0x08) { upsdebugx(6, "Poll, status: Performing calibration test"); status_set("CAL"); } if (!(status_bytes[1] & 0x04)) { upsdebugx(6, "Poll, status: Running on battery"); dstate_setinfo("battery.charger.status", "discharging"); status_set("OB"); } else if ((status_bytes[2] & 0x50) == 0x50) { upsdebugx(6, "Poll, status: Running on AC"); dstate_setinfo("battery.charger.status", "resting"); status_set("OL"); } else { upsdebugx(6, "Poll, status: Running on AC, battery is charging"); dstate_setinfo("battery.charger.status", "charging"); status_set("OL"); } /* XXX: This happens when battery level is marked as 0 here, but there's * still time until the UPS is actually beeping as the critical low level. * Maybe we should ignore this instead and just consider this state as * only OB and set the LB bit only when critically low? */ if (status_bytes[4] & 0x20) { upsdebugx(6, "Poll, status: Battery is low"); status_set("LB"); } else { upsdebugx(6, "Poll, status: Battery is high"); status_set("HB"); } if (status_bytes[0] & 0x20) { upsdebugx(6, "Poll, status: Battery is critically low"); if ((status_bytes[0] & 0x08)) { alarm_set("TEST MODE: Battery is critically low!"); } else { alarm_set("Battery is critically low, UPS is about to turn off!"); } } if ((status_bytes[4] & 0x40)) { upsdebugx(6, "Poll, status: UPS outlets are off"); status_set("OFF"); } /* TODO: Find out the bit in case of OVER, but I wasn't able to get mine * there, as I was either consuming too much (making it go crazy and in * self-protection) or too low :( */ status_commit(); dstate_dataok(); alarm_commit(); } static int hashx_instcmd(const char *cmd_name, const char *extra) { size_t i; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmd_name, extra); for (i = 0; i < sizeof (hashx_cmd) / sizeof (*hashx_cmd); ++i) { int status; if (strcasecmp(cmd_name, hashx_cmd[i].cmd_name) != 0) { continue; } upslog_INSTCMD_POWERSTATE_CHECKED(cmd_name, extra); if ((status = hashx_send_command(hashx_cmd[i].ups_cmd)) == STATUS_SUCCESS) return STAT_INSTCMD_HANDLED; upslogx(LOG_INSTCMD_FAILED, "Failed to execute command [%s] [%s]: %d", NUT_STRARG(cmd_name), NUT_STRARG(extra), status); return STAT_INSTCMD_FAILED; } upslog_INSTCMD_UNKNOWN(cmd_name, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_shutdown(void) { /* TODO: Find the command used to shutdown... It's definitely supported. */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) { set_exit_flag(EF_EXIT_FAILURE); } } void upsdrv_help(void) { } void upsdrv_makevartable(void) { } void upsdrv_initups(void) { upsdebugx(3, "Opening device %s", device_path); upsfd = ser_open(device_path); if (INVALID_FD_SER(upsfd)) { fatalx(EXIT_FAILURE, "%s: failed to open %s", __func__, device_path); } ser_set_speed(upsfd, device_path, B2400); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/clone-outlet.c0000644000175000017500000002771515044656702013535 00000000000000/* * clone-outlet.c: clone an UPS, treating its outlet as if it were an UPS * (monitoring only) * * Copyright (C) 2009 - Arjen de Korte * Copyright (C) 2024 - Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "parseconf.h" #include "nut_stdint.h" #include #ifndef WIN32 #include #include #endif /* !WIN32 */ #define DRIVER_NAME "Clone outlet UPS driver" #define DRIVER_VERSION "0.08" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Arjen de Korte ", DRV_EXPERIMENTAL, { NULL } }; static struct { struct { char *shutdown; } delay; struct { char *shutdown; } timer; char *status; } prefix = { { NULL }, { NULL }, NULL }; static struct { struct { long shutdown; } delay; struct { long shutdown; } timer; int status; } outlet = { { -1 }, { -1 }, 1 }; static struct { char status[LARGEBUF]; } ups = { "WAIT" }; static int dumpdone = 0; static PCONF_CTX_t sock_ctx; static time_t last_poll = 0, last_heard = 0, last_ping = 0; #ifndef WIN32 /* TODO NUT_WIN32_INCOMPLETE : Why not built in WIN32? */ static time_t last_connfail = 0; #else /* WIN32 */ static char read_buf[SMALLBUF]; static OVERLAPPED read_overlapped; #endif /* WIN32 */ static int parse_args(size_t numargs, char **arg) { if (numargs < 1) { goto skip_out; } if (!strcasecmp(arg[0], "PONG")) { upsdebugx(3, "Got PONG from UPS"); return 1; } if (!strcasecmp(arg[0], "DUMPDONE")) { upsdebugx(3, "UPS: dump is done"); dumpdone = 1; return 1; } if (!strcasecmp(arg[0], "DATASTALE")) { dstate_datastale(); return 1; } if (!strcasecmp(arg[0], "DATAOK")) { dstate_dataok(); return 1; } if (numargs < 2) { goto skip_out; } /* DELINFO */ if (!strcasecmp(arg[0], "DELINFO")) { dstate_delinfo(arg[1]); return 1; } if (numargs < 3) { goto skip_out; } /* SETINFO */ if (!strcasecmp(arg[0], "SETINFO")) { if (!strncasecmp(arg[1], "driver.", 7)) { /* don't pass on upstream driver settings */ return 1; } if (!strcasecmp(arg[1], prefix.delay.shutdown)) { outlet.delay.shutdown = strtol(arg[2], NULL, 10); } if (!strcasecmp(arg[1], prefix.timer.shutdown)) { outlet.timer.shutdown = strtol(arg[2], NULL, 10); } if (!strcasecmp(arg[1], prefix.status)) { outlet.status = strcasecmp(arg[2], "off"); } if (!strcasecmp(arg[1], "ups.status")) { snprintf(ups.status, sizeof(ups.status), "%s", arg[2]); return 1; } dstate_setinfo(arg[1], "%s", arg[2]); return 1; } skip_out: if (nut_debug_level > 0) { char buf[LARGEBUF]; size_t i; int len = -1; memset(buf, 0, sizeof(buf)); for (i = 0; i < numargs; i++) { len = snprintfcat(buf, sizeof(buf), "[%s] ", arg[i]); } if (len > 0) { buf[len - 1] = '\0'; } upsdebugx(3, "%s: ignored protocol line with %" PRIuSIZE " keyword(s): %s", __func__, numargs, numargs < 1 ? "" : buf); } return 0; } static TYPE_FD sstate_connect(void) { TYPE_FD fd; const char *dumpcmd = "DUMPALL\n"; #ifndef WIN32 ssize_t ret; int len; struct sockaddr_un sa; memset(&sa, '\0', sizeof(sa)); sa.sun_family = AF_UNIX; len = snprintf(sa.sun_path, sizeof(sa.sun_path), "%s/%s", dflt_statepath(), device_path); if (len < 0) { fatalx(EXIT_FAILURE, "Can't create a unix domain socket: " "failed to prepare the pathname"); } if ((uintmax_t)len >= (uintmax_t)sizeof(sa.sun_path)) { fatalx(EXIT_FAILURE, "Can't create a unix domain socket: pathname '%s/%s' " "is too long (%" PRIuSIZE ") for 'struct sockaddr_un->sun_path' " "on this system (%" PRIuSIZE ")", dflt_statepath(), device_path, strlen(dflt_statepath()) + 1 + strlen(device_path), sizeof(sa.sun_path)); } fd = socket(AF_UNIX, SOCK_STREAM, 0); if (INVALID_FD(fd)) { upslog_with_errno(LOG_ERR, "Can't create socket for UPS [%s]", device_path); return ERROR_FD; } ret = connect(fd, (struct sockaddr *) &sa, sizeof(sa)); if (ret < 0) { time_t now; close(fd); /* rate-limit complaints - don't spam the syslog */ time(&now); if (difftime(now, last_connfail) < 60) { return ERROR_FD; } last_connfail = now; upslog_with_errno(LOG_ERR, "Can't connect to UPS [%s]", device_path); return ERROR_FD; } ret = fcntl(fd, F_GETFL, 0); if (ret < 0) { upslog_with_errno(LOG_ERR, "fcntl get on UPS [%s] failed", device_path); close(fd); return ERROR_FD; } ret = fcntl(fd, F_SETFL, ret | O_NDELAY); if (ret < 0) { upslog_with_errno(LOG_ERR, "fcntl set O_NDELAY on UPS [%s] failed", device_path); close(fd); return ERROR_FD; } /* get a dump started so we have a fresh set of data */ ret = write(fd, dumpcmd, strlen(dumpcmd)); if (ret != (int)strlen(dumpcmd)) { upslog_with_errno(LOG_ERR, "Initial write to UPS [%s] failed", device_path); close(fd); return ERROR_FD; } /* continued below... */ #else /* WIN32 */ char pipename[NUT_PATH_MAX]; BOOL result = FALSE; snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\%s/%s", dflt_statepath(), device_path); result = WaitNamedPipe(pipename,NMPWAIT_USE_DEFAULT_WAIT); if (result == FALSE) { return ERROR_FD; } fd = CreateFile( pipename, /* pipe name */ GENERIC_READ | /* read and write access */ GENERIC_WRITE, 0, /* no sharing */ NULL, /* default security attributes FIXME */ OPEN_EXISTING, /* opens existing pipe */ FILE_FLAG_OVERLAPPED, /* enable async IO */ NULL); /* no template file */ if (fd == INVALID_HANDLE_VALUE) { upslog_with_errno(LOG_ERR, "Can't connect to UPS [%s]", device_path); return ERROR_FD; } /* get a dump started so we have a fresh set of data */ DWORD bytesWritten = 0; result = WriteFile (fd,dumpcmd,strlen(dumpcmd),&bytesWritten,NULL); if (result == 0 || bytesWritten != strlen(dumpcmd)) { upslog_with_errno(LOG_ERR, "Initial write to UPS [%s] failed", device_path); CloseHandle(fd); return ERROR_FD; } /* Start a read IO so we could wait on the event associated with it */ ReadFile(fd, read_buf, sizeof(read_buf) - 1, /*-1 to be sure to have a trailling 0 */ NULL, &(read_overlapped)); #endif /* WIN32 */ /* sstate_connect() continued for both platforms: */ pconf_init(&sock_ctx, NULL); time(&last_heard); dumpdone = 0; /* set ups.status to "WAIT" while waiting for the driver response to dumpcmd */ status_init(); status_set("WAIT"); status_commit(); upslogx(LOG_INFO, "Connected to UPS [%s]", device_path); return fd; } static void sstate_disconnect(void) { if (INVALID_FD(upsfd)) { /* Already disconnected... or not yet? ;) */ return; } pconf_finish(&sock_ctx); #ifndef WIN32 close(upsfd); #else /* WIN32 */ CloseHandle(upsfd); #endif /* WIN32 */ upsfd = ERROR_FD; } static int sstate_sendline(const char *buf) { ssize_t ret; if (INVALID_FD(upsfd)) { return -1; /* failed */ } #ifndef WIN32 ret = write(upsfd, buf, strlen(buf)); #else /* WIN32 */ DWORD bytesWritten = 0; BOOL result = FALSE; result = WriteFile (upsfd, buf, strlen(buf), &bytesWritten, NULL); if (result == 0) { ret = 0; } else { ret = (int)bytesWritten; } #endif /* WIN32 */ if (ret == (int)strlen(buf)) { return 0; } upslog_with_errno(LOG_NOTICE, "Send to UPS [%s] failed", device_path); return -1; /* failed */ } static int sstate_readline(void) { int i; ssize_t ret; #ifndef WIN32 char buf[SMALLBUF]; if (INVALID_FD(upsfd)) { return -1; /* failed */ } ret = read(upsfd, buf, sizeof(buf)); if (ret < 0) { switch(errno) { case EINTR: case EAGAIN: return 0; default: upslog_with_errno(LOG_WARNING, "Read from UPS [%s] failed", device_path); return -1; } } #else /* WIN32 */ if (INVALID_FD(upsfd)) { return -1; /* failed */ } /* FIXME? I do not see this buf or read_buf filled below */ char *buf = read_buf; DWORD bytesRead; GetOverlappedResult(upsfd, &read_overlapped, &bytesRead, FALSE); ret = bytesRead; #endif /* WIN32 */ for (i = 0; i < ret; i++) { switch (pconf_char(&sock_ctx, buf[i])) { case 1: if (parse_args(sock_ctx.numargs, sock_ctx.arglist)) { time(&last_heard); } continue; case 0: continue; /* haven't gotten a line yet */ default: /* parse error */ upslogx(LOG_NOTICE, "Parse error on sock: %s", sock_ctx.errmsg); return -1; } } return 0; } static int sstate_dead(int maxage) { time_t now; double elapsed; /* an unconnected ups is always dead */ if (INVALID_FD(upsfd)) { upsdebugx(3, "sstate_dead: connection to driver socket for UPS [%s] lost", device_path); return -1; /* dead */ } time(&now); /* ignore DATAOK/DATASTALE unless the dump is done */ if (dumpdone && dstate_is_stale()) { upsdebugx(3, "sstate_dead: driver for UPS [%s] says data is stale", device_path); return -1; /* dead */ } elapsed = difftime(now, last_heard); /* somewhere beyond a third of the maximum time - prod it to make it talk */ if ((elapsed > (maxage / 3)) && (difftime(now, last_ping) > (maxage / 3))) { upsdebugx(3, "Send PING to UPS"); sstate_sendline("PING\n"); last_ping = now; } if (elapsed > maxage) { upsdebugx(3, "sstate_dead: didn't hear from driver for UPS [%s] for %g seconds (max %d)", device_path, elapsed, maxage); return -1; /* dead */ } return 0; } void upsdrv_initinfo(void) { } void upsdrv_updateinfo(void) { time_t now = time(NULL); double d; /* Throttle tight loops to avoid CPU burn, e.g. when the socket to driver * is not in fact connected, so a select() somewhere is not waiting much */ if (last_poll > 0 && (d = difftime(now, last_poll)) < 1.0) { upsdebugx(5, "%s: too little time (%g sec) has passed since last cycle, throttling", __func__, d); usleep(500000); now = time(NULL); } if (sstate_dead(15)) { sstate_disconnect(); extrafd = upsfd = sstate_connect(); return; } if (sstate_readline()) { sstate_disconnect(); return; } status_init(); if (outlet.status == 0) { upsdebugx(2, "OFF flag set (%s: switched off)", prefix.status); status_set("OFF"); } if ((outlet.timer.shutdown > -1) && (outlet.timer.shutdown <= outlet.delay.shutdown)) { upsdebugx(2, "FSD flag set (%s: -1 < [%ld] <= %ld)", prefix.timer.shutdown, outlet.timer.shutdown, outlet.delay.shutdown); status_set("FSD"); } status_set(ups.status); /* FIXME: Split token words? */ status_commit(); last_poll = now; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_help(void) { } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "prefix", "Outlet prefix (mandatory)"); } void upsdrv_initups(void) { char buf[SMALLBUF]; const char *val; val = getval("prefix"); if (!val) { fatalx(EXIT_FAILURE, "Outlet prefix is mandatory for this driver!"); } snprintf(buf, sizeof(buf), "%s.delay.shutdown", val); prefix.delay.shutdown = xstrdup(buf); snprintf(buf, sizeof(buf), "%s.timer.shutdown", val); prefix.timer.shutdown = xstrdup(buf); snprintf(buf, sizeof(buf), "%s.status", val); prefix.status = xstrdup(buf); extrafd = upsfd = sstate_connect(); } void upsdrv_cleanup(void) { free(prefix.delay.shutdown); free(prefix.timer.shutdown); free(prefix.status); sstate_disconnect(); } nut-2.8.4/drivers/generic_gpio_libgpiod.c0000644000175000017500000003065615044656702015424 00000000000000/* generic_gpio_libgpiod.c - gpiod based NUT driver code for GPIO attached UPS devices * * Copyright (C) * 2023 - 2025 Modris Berzonis * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "config.h" #include "main.h" #include "attribute.h" #include "generic_gpio_common.h" #include "generic_gpio_libgpiod.h" #if !(defined WITH_LIBGPIO_VERSION) || !(defined WITH_LIBGPIO_VERSION_STR) || (WITH_LIBGPIO_VERSION == 0) # error "This driver can not be built, requires a known API WITH_LIBGPIO_VERSION to build against" #endif #define DRIVER_NAME "GPIO UPS driver (API " WITH_LIBGPIO_VERSION_STR ")" #define DRIVER_VERSION "1.04" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "ModrisB ", DRV_STABLE, { NULL } }; static void reserve_lines_libgpiod(struct gpioups_t *gpioupsfd, int inner); /* CyberPower 12V open collector state definitions 0 ON BATTERY Low when operating from utility line Open when operating from battery 1 REPLACE BATTERY Low when battery is charged Open when battery fails the Self Test 6 BATTERY MISSING Low when battery is present Open when battery is missing 3 LOW BATTERY Low when battery is near full charge capacity Open when operating from a battery with < 20% capacity NUT supported states OL On line (mains is present) OB On battery (mains is not present) LB Low battery HB High battery RB The battery needs to be replaced CHRG The battery is charging DISCHRG The battery is discharging (inverter is providing load power) BYPASS UPS bypass circuit is active -- no battery protection is available CAL UPS is currently performing runtime calibration (on battery) OFF UPS is offline and is not supplying power to the load OVER UPS is overloaded TRIM UPS is trimming incoming voltage (called "buck" in some hardware) BOOST UPS is boosting incoming voltage FSD Forced Shutdown (restricted use, see the note below) CyberPower rules setting OL=^0;OB=0;LB=3;HB=^3;RB=1;DISCHRG=0&^3;BYPASS=6; */ /* * reserve GPIO lines as per run options and inner parameter: do reservation once * or per each status read */ static void reserve_lines_libgpiod(struct gpioups_t *gpioupsfdlocal, int inner) { struct libgpiod_data_t *libgpiod_data = (struct libgpiod_data_t *)(gpioupsfdlocal->lib_data); upsdebugx(5, "reserve_lines_libgpiod runOptions 0x%x, inner %d", (unsigned int)gpioupsfdlocal->runOptions, inner); if(((gpioupsfdlocal->runOptions&ROPT_REQRES) != 0) == inner) { #if WITH_LIBGPIO_VERSION < 0x00020000 struct gpiod_line_request_config config; int gpioRc; config.consumer=upsdrv_info.name; if(gpioupsfdlocal->runOptions&ROPT_EVMODE) { config.request_type = GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES; upsdebugx(5, "reserve_lines_libgpiod GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES"); } else { config.request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT; upsdebugx(5, "reserve_lines_libgpiod GPIOD_LINE_REQUEST_DIRECTION_INPUT"); } config.flags = 0; /* GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN; */ gpioRc = gpiod_line_request_bulk(&libgpiod_data->gpioLines, &config, NULL); if(gpioRc) fatal_with_errno( LOG_ERR, "GPIO gpiod_line_request_bulk call failed, check for other applications that may have reserved GPIO lines" ); upsdebugx(5, "GPIO gpiod_line_request_bulk with type %d return code %d", config.request_type, gpioRc ); #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ if(!libgpiod_data->request) { libgpiod_data->request = gpiod_chip_request_lines(libgpiod_data->gpioChipHandle, libgpiod_data->config, libgpiod_data->lineConfig); } if(!libgpiod_data->request) { fatalx(LOG_ERR, "Failed to create line request"); } #endif /* WITH_LIBGPIO_VERSION */ } } /* * allocate memeory for libary, open gpiochip * and check lines numbers validity - consistency with h/w chip */ void gpio_open(struct gpioups_t *gpioupsfdlocal) { struct libgpiod_data_t *libgpiod_data = xcalloc(1, sizeof(struct libgpiod_data_t)); gpioupsfdlocal->lib_data = libgpiod_data; #if WITH_LIBGPIO_VERSION < 0x00020000 libgpiod_data->gpioChipHandle = gpiod_chip_open_by_name(gpioupsfdlocal->chipName); #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ if(!strchr(gpioupsfdlocal->chipName, '/')) { char *pathName = xcalloc(strlen(gpioupsfdlocal->chipName)+6, sizeof(char)); strcpy(pathName, "/dev/"); strcat(pathName, gpioupsfdlocal->chipName); libgpiod_data->gpioChipHandle = gpiod_chip_open(pathName); free(pathName); } else { libgpiod_data->gpioChipHandle = gpiod_chip_open(gpioupsfdlocal->chipName); } #endif /* WITH_LIBGPIO_VERSION */ if(!libgpiod_data->gpioChipHandle) fatal_with_errno( LOG_ERR, "Could not open GPIO chip [%s], check chips presence and/or access rights", gpioupsfdlocal->chipName ); else { int gpioRc; #if WITH_LIBGPIO_VERSION < 0x00020000 upslogx(LOG_NOTICE, "GPIO chip [%s] opened", gpioupsfdlocal->chipName); gpioupsfdlocal->chipLinesCount = gpiod_chip_num_lines(libgpiod_data->gpioChipHandle); #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ struct gpiod_chip_info *chipInfo; struct gpiod_line_settings *lineSettings; upslogx(LOG_NOTICE, "GPIO chip [%s] opened, api version 2", gpioupsfdlocal->chipName); chipInfo = gpiod_chip_get_info(libgpiod_data->gpioChipHandle); gpioupsfdlocal->chipLinesCount = gpiod_chip_info_get_num_lines(chipInfo); gpiod_chip_info_free(chipInfo); #endif /* WITH_LIBGPIO_VERSION */ upslogx(LOG_NOTICE, "Find %d lines on GPIO chip [%s]", gpioupsfdlocal->chipLinesCount, gpioupsfdlocal->chipName); if(gpioupsfdlocal->chipLinesCountupsMaxLine) { gpiod_chip_close(libgpiod_data->gpioChipHandle); fatalx( LOG_ERR, "GPIO chip lines count %d smaller than UPS line number used (%d)", gpioupsfdlocal->chipLinesCount, gpioupsfdlocal->upsMaxLine ); } #if WITH_LIBGPIO_VERSION < 0x00020000 gpiod_line_bulk_init(&libgpiod_data->gpioLines); gpiod_line_bulk_init(&libgpiod_data->gpioEventLines); gpioRc = gpiod_chip_get_lines( libgpiod_data->gpioChipHandle, (unsigned int *)gpioupsfdlocal->upsLines, gpioupsfdlocal->upsLinesCount, &libgpiod_data->gpioLines ); #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ libgpiod_data->values = xcalloc(gpioupsfdlocal->upsLinesCount, sizeof(*libgpiod_data->values)); lineSettings = gpiod_line_settings_new(); libgpiod_data->lineConfig = gpiod_line_config_new(); libgpiod_data->config = gpiod_request_config_new(); if(!lineSettings || !libgpiod_data->lineConfig || !libgpiod_data->config) { fatalx(LOG_ERR, "Failed to allocate configuration structures - out of memory"); } gpioRc = gpiod_line_settings_set_direction(lineSettings, GPIOD_LINE_DIRECTION_INPUT); if(gpioRc) { fatal_with_errno(LOG_ERR, "Failed to set lines to GPIOD_LINE_DIRECTION_INPUT"); } gpioRc = gpiod_line_settings_set_edge_detection(lineSettings, GPIOD_LINE_EDGE_BOTH); if(gpioRc) { fatal_with_errno(LOG_ERR, "Failed to set lines to GPIOD_LINE_EDGE_BOTH"); } gpioRc = gpiod_line_config_add_line_settings(libgpiod_data->lineConfig, (unsigned int *)gpioupsfdlocal->upsLines, gpioupsfdlocal->upsLinesCount, lineSettings); if(gpioRc) { fatalx(LOG_ERR, "Failed to attach line settings to line configuration"); } gpiod_request_config_set_consumer(libgpiod_data->config, upsdrv_info.name); gpiod_line_settings_free(lineSettings); #endif if(gpioRc) fatal_with_errno( LOG_ERR, "GPIO line reservation (gpiod_chip_get_lines call) failed with code %d, check for possible issue in rules parameter", gpioRc ); upsdebugx(5, "GPIO gpiod_chip_get_lines return code %d", gpioRc); reserve_lines_libgpiod(gpioupsfdlocal, 0); #if WITH_LIBGPIO_VERSION >= 0x00020000 gpioRc=gpiod_line_request_get_values(libgpiod_data->request, gpioupsfdlocal->upsLinesStates); if(gpioRc==0) { int i; for(i=0; i < gpioupsfdlocal->upsLinesCount; i++) { gpioupsfdlocal->upsLinesStates[i] = libgpiod_data->values[i]; } } #endif /* WITH_LIBGPIO_VERSION */ } } /* * close gpiochip and release allocated memory */ void gpio_close(struct gpioups_t *gpioupsfdlocal) { if(gpioupsfdlocal) { struct libgpiod_data_t *libgpiod_data = (struct libgpiod_data_t *)(gpioupsfdlocal->lib_data); if(libgpiod_data) { #if WITH_LIBGPIO_VERSION >= 0x00020000 if(libgpiod_data->values) { free(libgpiod_data->values); } gpiod_line_config_free(libgpiod_data->lineConfig); gpiod_request_config_free(libgpiod_data->config); #endif /* WITH_LIBGPIO_VERSION */ if(libgpiod_data->gpioChipHandle) { gpiod_chip_close(libgpiod_data->gpioChipHandle); } free(gpioupsfdlocal->lib_data); gpioupsfdlocal->lib_data = NULL; } } } /* * get GPIO line states for all needed lines */ void gpio_get_lines_states(struct gpioups_t *gpioupsfdlocal) { int i; int gpioRc; struct libgpiod_data_t *libgpiod_data = (struct libgpiod_data_t *)(gpioupsfdlocal->lib_data); reserve_lines_libgpiod(gpioupsfdlocal, 1); if(gpioupsfdlocal->runOptions&ROPT_EVMODE) { #if WITH_LIBGPIO_VERSION < 0x00020000 struct timespec timeoutLong = {1,0}; struct gpiod_line_event event; int monRes; upsdebugx(5, "gpio_get_lines_states_libgpiod initial %d, timeout %ld", gpioupsfdlocal->initial, timeoutLong.tv_sec ); if(gpioupsfdlocal->initial) { timeoutLong.tv_sec = 35; } else { gpioupsfdlocal->initial = 1; } upsdebugx(5, "gpio_get_lines_states_libgpiod initial %d, timeout %ld", gpioupsfdlocal->initial, timeoutLong.tv_sec ); gpiod_line_bulk_init(&libgpiod_data->gpioEventLines); monRes=gpiod_line_event_wait_bulk( &libgpiod_data->gpioLines, &timeoutLong, &libgpiod_data->gpioEventLines ); upsdebugx(5, "gpiod_line_event_wait_bulk completed with %d return code and timeout %ld s", monRes, timeoutLong.tv_sec ); if(monRes==1) { int num_lines_local = (int)gpiod_line_bulk_num_lines(&libgpiod_data->gpioEventLines); int j; for(j=0; jgpioEventLines, j ); int eventRc = gpiod_line_event_read(eLine, &event); unsigned int lineOffset = gpiod_line_offset(eLine); event.event_type=0; upsdebugx(5, "Event read return code %d and event type %d for line %u", eventRc, event.event_type, lineOffset ); } } #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ int64_t poll_timeout = 1000000000; // in nanoseconds if(gpioupsfdlocal->initial) { poll_timeout = 35000000000; } else { gpioupsfdlocal->initial = 1; } gpioRc = gpiod_line_request_wait_edge_events(libgpiod_data->request, poll_timeout); #endif /* WITH_LIBGPIO_VERSION */ } for(i=0; i < gpioupsfdlocal->upsLinesCount; i++) { gpioupsfdlocal->upsLinesStates[i] = -1; } #if WITH_LIBGPIO_VERSION < 0x00020000 gpioRc=gpiod_line_get_value_bulk( &libgpiod_data->gpioLines, gpioupsfdlocal->upsLinesStates ); #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ gpioRc=gpiod_line_request_get_values(libgpiod_data->request, libgpiod_data->values); if(gpioRc==0) { for(i=0; i < gpioupsfdlocal->upsLinesCount; i++) { gpioupsfdlocal->upsLinesStates[i] = libgpiod_data->values[i]; } } #endif /* WITH_LIBGPIO_VERSION */ if (gpioRc < 0) fatal_with_errno(LOG_ERR, "GPIO line status read call failed"); upsdebugx(5, "GPIO gpiod_line_get_value_bulk completed with %d return code, status values:", gpioRc ); for(i=0; i < gpioupsfdlocal->upsLinesCount; i++) { upsdebugx(5, "Line%d state = %d", i, gpioupsfdlocal->upsLinesStates[i] ); } if(gpioupsfdlocal->runOptions&ROPT_REQRES) { #if WITH_LIBGPIO_VERSION < 0x00020000 gpiod_line_release_bulk(&libgpiod_data->gpioLines); #else /* #if WITH_LIBGPIO_VERSION >= 0x00020000 */ gpiod_line_request_release(libgpiod_data->request); libgpiod_data->request = NULL; #endif /* WITH_LIBGPIO_VERSION */ } } nut-2.8.4/drivers/oneac.c0000644000175000017500000007147715044656702012214 00000000000000/*vim ts=4*/ /* oneac.c - Driver for Oneac UPS using the Advanced Interface. * * Supported Oneac UPS families in this driver: * EG (late 80s, early 90s, plug-in serial interface card) * ON (early and mid-90s, plug-in serial interface card) * OZ (mid-90s on, DB-25 std., interface slot) * OB (early 2000's on, big cabinet, DB-25 std., interface slot) * * Copyright (C) * 2003 by Eric Lawson * 2012 by Bill Elliot * * This program was sponsored by MGE UPS SYSTEMS, and now Eaton * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * History: * - 2 August 2024. Bill Elliot * Just cleaned up formatting per current NUT standards. * * - 7 February 2012. Bill Elliot * Enhancing the driver for additional capabilities and later units. * * - 28 November 2003. Eric Lawson * More or less complete re-write for NUT 1.5.9 * This was somewhat easier than trying to beat the old driver code * into submission * */ #include "main.h" #include "serial.h" #include "oneac.h" #include "nut_stdint.h" /* Prototypes to allow setting pointer before function is defined */ int setcmd(const char* varname, const char* setvalue); int instcmd(const char *cmdname, const char *extra); #define DRIVER_NAME "Oneac EG/ON/OZ/OB UPS driver" #define DRIVER_VERSION "0.85" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Bill Elliot \n" "Eric Lawson ", DRV_STABLE, { NULL } }; #define SECS 0 /* Serial function wait time*/ #define USEC 500000 /* Rest of serial function wait time*/ #define COMM_TRIES 3 /* Serial retries before "stale" */ static char UpsFamily [3]; /**************************************************************** * Below are functions used only in this oneac driver * ***************************************************************/ /* Since an installed network card may delay responses from the UPS * allow for a repeat of the get request. Also confirm that * the correct number of characters are returned. */ static ssize_t OneacGetResponse (char* chBuff, const size_t BuffSize, int ExpectedCount) { int Retries = 10; /* x/2 seconds max with 500000 USEC */ ssize_t return_val; do { return_val = ser_get_line(upsfd, chBuff, BuffSize, ENDCHAR, IGNCHARS, SECS, USEC); if (return_val == ExpectedCount) { break; } upsdebugx (3, "!OneacGetResponse retry (%" PRIiSIZE ", %d)...", return_val, Retries); } while (--Retries > 0); upsdebugx (4,"OneacGetResponse buffer: %s",chBuff); if (Retries == 0) { upsdebugx (2,"!!OneacGetResponse timeout..."); return_val = 1; /* Comms error */ } else { if (Retries < 10) { upsdebugx (2,"OneacGetResponse recovered (%d)...", Retries); } return_val = 0; /* Good comms */ } return return_val; } static void do_battery_test(void) { char buffer[32]; if (getval("testtime") == NULL) { snprintf(buffer, 3, "%s", DEFAULT_BAT_TEST_TIME); } else { snprintf(buffer, 3, "%s", getval("testtime")); /*the UPS wants this value to always be two characters long*/ /*so put a zero in front of the string, if needed.... */ if (strlen(buffer) < 2) { buffer[2] = '\0'; buffer[1] = buffer[0]; buffer[0] = '0'; } } ser_send(upsfd, "%s%s%s", BAT_TEST_PREFIX, buffer, COMMAND_END); } static int SetOutputAllow(const char* lowval, const char* highval) { char buffer[32]; snprintf(buffer, 4, "%.3s", lowval); /*the UPS wants this value to always be three characters long*/ /*so put a zero in front of the string, if needed.... */ if (strlen(buffer) < 3) { buffer[3] = '\0'; buffer[2] = buffer[1]; buffer[1] = buffer[0]; buffer[0] = '0'; } upsdebugx (2,"SetOutputAllow sending %s%.3s,%.3s...", SETX_OUT_ALLOW, buffer, highval); ser_send(upsfd, "%s%.3s,%.3s%s", SETX_OUT_ALLOW, buffer, highval, COMMAND_END); ser_get_line(upsfd,buffer, sizeof(buffer), ENDCHAR, IGNCHARS, SECS,USEC); if(buffer[0] == DONT_UNDERSTAND) { upsdebugx (2,"SetOutputAllow got asterisk back..."); return 1; /* Invalid command */ } return 0; /* Valid command */ } static void EliminateLeadingZeroes (const char* buff1, int StringSize, char* buff2, const size_t buff2size) { int i = 0; int j = 0; memset(buff2, '\0', buff2size); /* Fill with nulls */ /* Find first non-'0' */ while ((i < (StringSize - 1) && (buff1[i] == '0'))) { i++; } while (i < StringSize) /* Move rest of string */ { buff2[j++] = buff1[i++]; } } /**************************************************************** * Below are the commands that are called by main * ***************************************************************/ void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B9600); /*get the UPS in the right frame of mind*/ ser_send_pace(upsfd, 100, "%s", COMMAND_END); ser_send_pace(upsfd, 100, "%s", COMMAND_END); sleep (1); } void upsdrv_initinfo(void) { int i,j, k; int VRange=0; int timevalue; ssize_t RetValue; char buffer[256], buffer2[32]; /* All families should reply to this request so we can confirm that it is * an ONEAC UPS */ ser_flush_in(upsfd,"",0); ser_send(upsfd,"%c%s", GET_FAMILY,COMMAND_END); if(OneacGetResponse (buffer, sizeof(buffer), 2)) { fatalx(EXIT_FAILURE, "Serial timeout with ONEAC UPS on %s\n", device_path); } else { if (strncmp(buffer, FAMILY_ON, FAMILY_SIZE) != 0 && strncmp(buffer, FAMILY_OZ, FAMILY_SIZE) != 0 && strncmp(buffer, FAMILY_OB, FAMILY_SIZE) != 0 && strncmp(buffer, FAMILY_EG, FAMILY_SIZE) != 0) { fatalx(EXIT_FAILURE, "Did not find an ONEAC UPS on %s\n", device_path); } } /* UPS Model (either EG, ON, OZ or OB series of UPS) */ strncpy(UpsFamily, buffer, FAMILY_SIZE); UpsFamily[2] = '\0'; dstate_setinfo("device.model", "%s",UpsFamily); printf("Found %s family of Oneac UPS\n", UpsFamily); dstate_setinfo("ups.type", "%s", "Line Interactive"); dstate_addcmd("test.battery.start.quick"); dstate_addcmd("test.battery.stop"); dstate_addcmd("test.failure.start"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stop"); dstate_addcmd("shutdown.reboot"); upsh.setvar = setcmd; upsh.instcmd = instcmd; /* set some stuff that shouldn't change after initialization */ /* this stuff is common to all families of UPS */ ser_send(upsfd,"%c%s", GET_ALL, COMMAND_END); if (strncmp(UpsFamily, FAMILY_EG, FAMILY_SIZE) == 0) { RetValue = OneacGetResponse (buffer, sizeof(buffer), GETALL_EG_RESP_SIZE); } else { RetValue = OneacGetResponse (buffer, sizeof(buffer), GETALL_RESP_SIZE); } if(RetValue) { fatalx(EXIT_FAILURE, "Serial timeout(2) with ONEAC UPS on %s\n", device_path); } /* Manufacturer */ dstate_setinfo("device.mfr", "%.5s", buffer); /*firmware revision*/ dstate_setinfo("ups.firmware", "%.3s",buffer+7); /*nominal AC frequency setting --either 50 or 60*/ dstate_setinfo("input.frequency.nominal", "%.2s", buffer+20); dstate_setinfo("output.frequency.nominal", "%.2s", buffer+20); /* Shutdown delay in seconds...can be changed by user */ if (getval("offdelay") == NULL) { dstate_setinfo("ups.delay.shutdown", "0"); } else { dstate_setinfo("ups.delay.shutdown", "%s", getval("offdelay")); } dstate_setflags("ups.delay.shutdown", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("ups.delay.shutdown", GET_SHUTDOWN_RESP_SIZE); /* Setup some ON/OZ/OB only stuff ... i.e. not EG */ if (strncmp(UpsFamily, FAMILY_EG, FAMILY_SIZE) != 0) { dstate_addcmd("reset.input.minmax"); /*nominal input voltage*/ VRange = buffer[26]; /* Keep for later use also */ switch (VRange) /* Will be '1' or '2' */ { case V120AC: dstate_setinfo("input.voltage.nominal", "120"); dstate_setinfo("output.voltage.nominal", "120"); break; case V230AC: dstate_setinfo("input.voltage.nominal", "230"); dstate_setinfo("output.voltage.nominal", "230"); break; default: upslogx(LOG_INFO,"Oneac: " "Invalid nom voltage parameter from UPS [%c]", VRange); } } /* Setup some OZ/OB only stuff */ if ((strncmp (UpsFamily, FAMILY_OZ, FAMILY_SIZE) == 0) || (strncmp (UpsFamily, FAMILY_OB, FAMILY_SIZE) == 0)) { dstate_addcmd("test.panel.start"); dstate_addcmd("test.battery.start.deep"); dstate_addcmd("beeper.enable"); dstate_addcmd("beeper.disable"); dstate_addcmd("beeper.mute"); dstate_setaux("ups.delay.shutdown", GETX_SHUTDOWN_RESP_SIZE); ser_flush_in(upsfd, "", 0); ser_send(upsfd, "%c%s", GETX_ALL_2, COMMAND_END); if(OneacGetResponse (buffer, sizeof(buffer), GETX_ALL2_RESP_SIZE)) { fatalx(EXIT_FAILURE, "Serial timeout(3) with ONEAC UPS on %s\n", device_path); } /* Low and high output trip points */ EliminateLeadingZeroes (buffer+73, 3, buffer2, sizeof(buffer2)); dstate_setinfo("input.transfer.low", "%s", buffer2); dstate_setflags("input.transfer.low", ST_FLAG_STRING | ST_FLAG_RW ); dstate_setaux("input.transfer.low", 3); EliminateLeadingZeroes (buffer+76, 3, buffer2, sizeof(buffer2)); dstate_setinfo("input.transfer.high", "%s", buffer2); dstate_setflags("input.transfer.high", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("input.transfer.high", 3); /* Restart delay */ EliminateLeadingZeroes (buffer+84, 4, buffer2, sizeof(buffer2)); dstate_setinfo("ups.delay.start", "%s", buffer2); dstate_setflags("ups.delay.start", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("ups.delay.start", 4); /* Low Batt at time */ strncpy(buffer2, buffer+82, 2); buffer2[2]='\0'; timevalue = atoi(buffer2) * 60; /* Change minutes to seconds */ dstate_setinfo("battery.runtime.low", "%d", timevalue); dstate_setflags("battery.runtime.low", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("battery.runtime.low", 2); /*Get the actual model string for ON UPS reported as OZ/OB family*/ /*UPS Model (full string)*/ memset(buffer2, '\0', 32); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic ignored "-Wformat-truncation" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRINGOP_TRUNCATION #pragma GCC diagnostic ignored "-Wstringop-truncation" #endif strncpy(buffer2, buffer + 5, 10); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic pop #endif for (i = 9; i >= 0 && buffer2[i] == ' '; --i) { buffer2[i] = '\0'; } dstate_setinfo("device.model", "%s", buffer2); /* Serial number */ dstate_setinfo("device.serial", "%.4s-%.4s", buffer+18, buffer+22); printf("Found %.10s UPS with serial number %.4s-%.4s\n", buffer2, buffer+18, buffer+22); /* Manufacture Date */ dstate_setinfo("ups.mfr.date", "%.6s (yymmdd)", buffer+38); /* Battery Replace Date */ dstate_setinfo("battery.date", "%.6s (yymmdd)", buffer+44); dstate_setflags("battery.date", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("battery.date", 6); /* Real power nominal */ EliminateLeadingZeroes (buffer+55, 5, buffer2, sizeof(buffer2)); dstate_setinfo("ups.realpower.nominal", "%s", buffer2); /* Set up ups.start.auto to be writable */ dstate_setinfo("ups.start.auto", "yes"); dstate_setflags("ups.start.auto", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("ups.start.auto", 3); /* Get output window min/max points from OB or OZ v1.9 or later */ if ((strncmp (UpsFamily, FAMILY_OB, FAMILY_SIZE) == 0) || (strcmp (dstate_getinfo("ups.firmware"), MIN_ALLOW_FW) >= 0 )) { upsdebugx (2,"Can get output window min/max! (%s)", dstate_getinfo("ups.firmware")); ser_send(upsfd, "%s%s", GETX_ALLOW_RANGE, COMMAND_END); if(OneacGetResponse (buffer, sizeof(buffer), GETX_RANGE_RESP_SIZE)) { fatalx(EXIT_FAILURE, "Serial timeout(4) with ONEAC UPS on %s\n",device_path); } strncpy(buffer2, buffer, 3); buffer2[3]='\0'; i = atoi(buffer2); /* Minimum voltage */ #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic ignored "-Wformat-truncation" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRINGOP_TRUNCATION #pragma GCC diagnostic ignored "-Wstringop-truncation" #endif strncpy(buffer2, buffer + 4, 3); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic pop #endif j = atoi(buffer2); /* Maximum voltage */ strncpy(buffer2, buffer+8, 2); buffer2[2]='\0'; k = atoi(buffer2); /* Spread between */ dstate_setinfo("input.transfer.low.min", "%3d", i); dstate_setinfo("input.transfer.low.max", "%3d", j-k); dstate_setinfo("input.transfer.high.min", "%3d", i+k); dstate_setinfo("input.transfer.high.max", "%3d", j); } else { /* Use default values from firmware */ upsdebugx (2, "Using trip defaults (%s)...", dstate_getinfo("ups.firmware")); switch (VRange) /* Held from initial use */ { case V120AC: dstate_setinfo("input.transfer.low.min", "90"); dstate_setinfo("input.transfer.low.max", "120"); dstate_setinfo("input.transfer.high.min", "110"); dstate_setinfo("input.transfer.high.max", "140"); break; case V230AC: dstate_setinfo("input.transfer.low.min", "172"); dstate_setinfo("input.transfer.low.max", "228"); dstate_setinfo("input.transfer.high.min", "212"); dstate_setinfo("input.transfer.high.max", "268"); break; default: ; } } } } void upsdrv_updateinfo(void) { static int CommTry = COMM_TRIES; /* Comm loss counter */ char buffer[256]; /* Main response buffer */ char buffer2[32]; /* Conversion buffer */ char s; ssize_t RetValue; int timevalue; /* Start with EG/ON information */ ser_flush_in(upsfd, "", 0); /*just in case*/ ser_send (upsfd, "%c%s", GET_ALL, COMMAND_END); if (strncmp(UpsFamily, FAMILY_EG, FAMILY_SIZE) == 0) { RetValue = OneacGetResponse (buffer, sizeof(buffer), GETALL_EG_RESP_SIZE); } else { RetValue = OneacGetResponse (buffer, sizeof(buffer), GETALL_RESP_SIZE); } if ((RetValue != 0) && (CommTry == 0)) { ser_comm_fail("Oneac UPS Comm failure continues on port %s", device_path); } else if (RetValue != 0) { if (--CommTry == 0) { ser_comm_fail("Oneac UPS Comm failure on port %s", device_path); dstate_datastale(); } upsdebugx(2,"Oneac: Update serial comm retry value: %d", CommTry); return; } else { CommTry = COMM_TRIES; /* Reset serial retries */ s = buffer[12]; status_init(); alarm_init(); /*take care of the UPS status information*/ if (s == '@') { status_set("OL"); } else { if (s & 0x01) /* On Battery */ { status_set("OB"); } else { status_set("OL"); } if (s & 0x02) /* Low Battery */ { status_set("LB"); } if (s & 0x04) /* General fault */ { dstate_setinfo("ups.test.result","UPS Internal Failure"); } else { dstate_setinfo("ups.test.result","Normal"); } if (s & 0x08) /* Replace Battery */ { status_set("RB"); } /* if (s & 0x10) */ /* High Line */ if (s & 0x20) /* Unit is hot */ { alarm_set("OVERHEAT"); } } /*take care of the reason why the UPS last transferred to battery*/ switch (buffer[13]) { case XFER_BLACKOUT : dstate_setinfo("input.transfer.reason", "Blackout"); break; case XFER_LOW_VOLT : dstate_setinfo("input.transfer.reason", "Low Input Voltage"); break; case XFER_HI_VOLT : dstate_setinfo("input.transfer.reason", "High Input Voltage"); break; case NO_VALUE_YET : dstate_setinfo("input.transfer.reason", "No transfer yet."); break; default : upslogx(LOG_INFO,"Oneac: Unknown reason for UPS battery transfer [%c]", buffer[13]); } /* now update info for only the non-EG families of UPS*/ if (strncmp(UpsFamily, FAMILY_EG, FAMILY_SIZE) != 0) { dstate_setinfo("ups.load", "0%.2s", buffer+31); /* Output ON or OFF? */ if(buffer[27] == NO_VALUE_YET) { status_set("OFF"); } /*battery charge*/ if(buffer[10] == YES) { dstate_setinfo("battery.charge", "0%.2s", buffer+33); } else { dstate_setinfo("battery.charge", "100"); } EliminateLeadingZeroes (buffer+35, 3, buffer2, sizeof(buffer2)); dstate_setinfo("input.voltage", "%s", buffer2); EliminateLeadingZeroes (buffer+38, 3, buffer2, sizeof(buffer2)); dstate_setinfo("input.voltage.minimum", "%s", buffer2); EliminateLeadingZeroes (buffer+41, 3, buffer2, sizeof(buffer2)); dstate_setinfo("input.voltage.maximum", "%s", buffer2); EliminateLeadingZeroes (buffer+44, 3, buffer2, sizeof(buffer2)); dstate_setinfo("output.voltage", "%s", buffer2); if (buffer[15] == NO_VALUE_YET) { dstate_delinfo("ups.timer.shutdown"); } else { /* A shutdown is underway! */ status_set("FSD"); if(buffer[15] != HIGH_COUNT) { EliminateLeadingZeroes (buffer+15, 3, buffer2, sizeof(buffer2)); dstate_setinfo("ups.timer.shutdown", "%s", buffer2); } else { dstate_setinfo("ups.timer.shutdown", "999"); } } if (buffer[47] == YES) { status_set("BOOST"); } } /* Now update info for only the OZ/OB families of UPS */ if ((strncmp(UpsFamily, FAMILY_OZ, FAMILY_SIZE) == 0) || (strncmp(UpsFamily, FAMILY_OB, FAMILY_SIZE) == 0)) { ser_flush_in(upsfd,"",0); /*just in case*/ ser_send (upsfd, "%c%s", GETX_ALL_1, COMMAND_END); RetValue = OneacGetResponse (buffer, sizeof(buffer), GETX_ALL1_RESP_SIZE); if(RetValue) { if (--CommTry == 0) { ser_comm_fail("Oneac (OZ) UPS Comm failure on port %s", device_path); dstate_datastale(); } upsdebugx(2,"Oneac: " "Update (OZ) serial comm retry value: %d", CommTry); } else { CommTry = COMM_TRIES; /* Reset count */ EliminateLeadingZeroes (buffer+57, 5, buffer2, sizeof(buffer2)); dstate_setinfo("ups.realpower", "%s", buffer2); dstate_setinfo("input.frequency", "%.2s.%c", buffer+42, buffer[44]); dstate_setinfo("output.frequency", "%.2s.%c", buffer+76, buffer[78]); EliminateLeadingZeroes (buffer+29, 3, buffer2, sizeof(buffer2)); dstate_setinfo("battery.voltage", "%s.%c", buffer2, buffer[32]); dstate_setinfo("ups.temperature", "%.2s", buffer+13); dstate_setinfo("ups.load", "%.3s", buffer+73); strncpy(buffer2, buffer+19, 4); buffer2[4]='\0'; timevalue = atoi(buffer2) * 60; /* Change mins to secs */ dstate_setinfo("battery.runtime", "%d", timevalue); /* Now some individual requests... */ /* Battery replace date */ ser_send (upsfd, "%c%s", GETX_BATT_REPLACED, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), GETX_DATE_RESP_SIZE)) { dstate_setinfo("battery.date", "%.6s (yymmdd)", buffer); } /* Low and high output trip points */ ser_send (upsfd, "%c%s", GETX_LOW_OUT_ALLOW, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), GETX_ALLOW_RESP_SIZE)) { EliminateLeadingZeroes (buffer, 3, buffer2, sizeof(buffer2)); dstate_setinfo("input.transfer.low", "%s", buffer2); } ser_send (upsfd, "%c%s", GETX_HI_OUT_ALLOW, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), GETX_ALLOW_RESP_SIZE)) { dstate_setinfo("input.transfer.high", "%s", buffer); } /* Restart delay */ ser_send (upsfd, "%c%s", GETX_RESTART_DLY, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), GETX_RSTRT_RESP_SIZE)) { EliminateLeadingZeroes (buffer, 4, buffer2, sizeof(buffer2)); dstate_setinfo("ups.delay.start", "%s", buffer2); } /* Buzzer state */ ser_send (upsfd,"%s%s",GETX_BUZZER_WHAT,COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), 1)) { switch (buffer[0]) { case BUZZER_ENABLED : dstate_setinfo("ups.beeper.status", "enabled"); break; case BUZZER_DISABLED : dstate_setinfo("ups.beeper.status", "disabled"); break; case BUZZER_MUTED : dstate_setinfo("ups.beeper.status", "muted"); break; default : dstate_setinfo("ups.beeper.status", "enabled"); } } /* Auto start setting */ ser_send (upsfd, "%s%s", GETX_AUTO_START, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), 1)) { if (buffer[0] == '0') { dstate_setinfo("ups.start.auto", "yes"); } else { dstate_setinfo("ups.start.auto", "no"); } } /* Low Batt at time */ ser_send (upsfd, "%c%s", GETX_LOW_BATT_TIME, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), 2)) { strncpy(buffer2, buffer, 2); buffer2[2]='\0'; timevalue = atoi(buffer2) * 60; /* Mins to secs */ dstate_setinfo("battery.runtime.low", "%d", timevalue); } /* Shutdown timer */ ser_send (upsfd, "%c%s", GETX_SHUTDOWN, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), GETX_SHUTDOWN_RESP_SIZE)) { /* ON would have handled NO_VALUE_YET and setting FSD * above so only deal with counter value here. */ if (buffer[0] != NO_VALUE_YET) { EliminateLeadingZeroes (buffer, 5, buffer2, sizeof(buffer2)); dstate_setinfo("ups.timer.shutdown", "%s", buffer2); } } /* Restart timer */ ser_send (upsfd, "%s%s", GETX_RESTART_COUNT, COMMAND_END); if(!OneacGetResponse (buffer, sizeof(buffer), GETX_RSTRT_RESP_SIZE)) { if (atoi(buffer) == 0) { dstate_delinfo("ups.timer.start"); } else { EliminateLeadingZeroes (buffer, 4, buffer2, sizeof(buffer2)); dstate_setinfo("ups.timer.start", "%s", buffer2); } } } } alarm_commit(); status_commit(); /* If the comm retry counter is zero then datastale has been set. * We don't want to set dataok or ser_comm_good if that is the case. */ if (CommTry != 0) { dstate_dataok(); ser_comm_good(); } } } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* FIXME: before loop_shutdown_commands(), code directly called * here was identical to "shutdown.reboot", while the driver * shutdown should more reasonably be "shutdown.return" (when * wall power is back) or "shutdown.stayoff". All of these are * implemented in instcmd() here nominally (not sure if named * correctly - better re-check on hardware). */ int ret = do_loop_shutdown_commands("shutdown.reboot", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } void upsdrv_help(void) { printf("\n---------\nNOTE:\n"); printf("You must set the UPS interface card DIP switch to 9600 BPS\n"); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "testtime", "Change battery test time from the 2 minute default."); addvar(VAR_VALUE,"offdelay", "Change shutdown delay time from 0 second default."); } int instcmd(const char *cmdname, const char *extra) { int i; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "test.failure.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ser_send(upsfd, "%s%s", SIM_PWR_FAIL, COMMAND_END); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); i = atoi(dstate_getinfo("ups.delay.shutdown")); if ((strncmp (UpsFamily, FAMILY_OZ, FAMILY_SIZE) == 0) || (strncmp (UpsFamily, FAMILY_OB, FAMILY_SIZE) == 0)) { upsdebugx(3, "Shutdown using %c%d...", DELAYED_SHUTDOWN_PREFIX, i); ser_send(upsfd, "%c%d%s", DELAYED_SHUTDOWN_PREFIX, i, COMMAND_END); } else { upsdebugx(3, "Shutdown using %c%03d...", DELAYED_SHUTDOWN_PREFIX, i); ser_send(upsfd, "%c%03d%s", DELAYED_SHUTDOWN_PREFIX, i, COMMAND_END); } return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.reboot")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ser_send(upsfd, "%s", SHUTDOWN); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ser_send(upsfd, "%c%s", DELAYED_SHUTDOWN_PREFIX, COMMAND_END); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.start.quick")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); do_battery_test(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.start.deep")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ser_send(upsfd, "%s%s", TEST_BATT_DEEP, COMMAND_END); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); if ((strncmp (UpsFamily, FAMILY_EG, FAMILY_SIZE) == 0) || (strncmp (UpsFamily, FAMILY_ON, FAMILY_SIZE) == 0)) { ser_send(upsfd, "%s00%s", BAT_TEST_PREFIX, COMMAND_END); } else { ser_send(upsfd, "%c%s", TEST_ABORT, COMMAND_END); } return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "reset.input.minmax")) { ser_send(upsfd, "%c%s", RESET_MIN_MAX, COMMAND_END); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "beeper.enable")) { ser_send(upsfd, "%c%c%s", SETX_BUZZER_PREFIX, BUZZER_ENABLED, COMMAND_END); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "beeper.disable")) { ser_send(upsfd, "%c%c%s", SETX_BUZZER_PREFIX, BUZZER_DISABLED, COMMAND_END); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "beeper.mute")) { ser_send(upsfd,"%c%c%s", SETX_BUZZER_PREFIX, BUZZER_MUTED, COMMAND_END); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.panel.start")) { ser_send(upsfd,"%s%s", TEST_INDICATORS, COMMAND_END); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } int setcmd(const char* varname, const char* setvalue) { upsdebug_SET_STARTING(varname, setvalue); if (!strcasecmp(varname, "ups.delay.shutdown")) { if ((strncmp (UpsFamily, FAMILY_OZ, FAMILY_SIZE) == 0) || (strncmp (UpsFamily, FAMILY_OB, FAMILY_SIZE) == 0)) { if (atoi(setvalue) > 65535) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upsdebugx(2, "Too big for OZ/OB (>65535)...(%s)", setvalue); return STAT_SET_UNKNOWN; } } else { if (atoi(setvalue) > 999) { /* FIXME: ..._INVALID? ..._CONVERSION_FAILED? */ upsdebugx(2, "Too big for EG/ON (>999)...(%s)", setvalue); return STAT_SET_UNKNOWN; } } dstate_setinfo("ups.delay.shutdown", "%s", setvalue); return STAT_SET_HANDLED; } if (!strcasecmp(varname, "input.transfer.low")) { if (SetOutputAllow(setvalue, dstate_getinfo("input.transfer.high"))) { return STAT_SET_UNKNOWN; } else { dstate_setinfo("input.transfer.low" , "%s", setvalue); return STAT_SET_HANDLED; } } if (!strcasecmp(varname, "input.transfer.high")) { if (SetOutputAllow(dstate_getinfo("input.transfer.low"), setvalue)) { return STAT_SET_UNKNOWN; } else { dstate_setinfo("input.transfer.high" , "%s", setvalue); return STAT_SET_HANDLED; } } if (!strcasecmp(varname, "battery.date")) { if(strlen(setvalue) == GETX_DATE_RESP_SIZE) /* yymmdd (6 chars) */ { ser_send(upsfd, "%s%s%s", SETX_BATTERY_DATE, setvalue, COMMAND_END); dstate_setinfo("battery.date", "%s (yymmdd)", setvalue); return STAT_SET_HANDLED; } else { return STAT_SET_UNKNOWN; } } if (!strcasecmp(varname, "ups.delay.start")) { if (atoi(setvalue) <= 9999) { ser_send(upsfd,"%s%s%s", SETX_RESTART_DELAY, setvalue, COMMAND_END); dstate_setinfo("ups.delay.start", "%s", setvalue); return STAT_SET_HANDLED; } else { return STAT_SET_UNKNOWN; } } if (!strcasecmp(varname, "battery.runtime.low")) { if (atoi(setvalue) <= 99) { ser_send(upsfd,"%s%s%s", SETX_LOWBATT_AT, setvalue, COMMAND_END); dstate_setinfo("battery.runtime.low", "%s", setvalue); return STAT_SET_HANDLED; } else { return STAT_SET_UNKNOWN; } } if (!strcasecmp(varname, "ups.start.auto")) { if (!strcasecmp(setvalue, "yes")) { ser_send(upsfd,"%c0%s", SETX_AUTO_START, COMMAND_END); dstate_setinfo("ups.start.auto", "yes"); return STAT_SET_HANDLED; } else if (!strcasecmp(setvalue, "no")) { ser_send(upsfd,"%c1%s", SETX_AUTO_START, COMMAND_END); dstate_setinfo("ups.start.auto", "no"); return STAT_SET_HANDLED; } return STAT_SET_UNKNOWN; } upslog_SET_UNKNOWN(varname, setvalue); return STAT_SET_UNKNOWN; } nut-2.8.4/drivers/powercom-hid.c0000644000175000017500000006277115033502303013502 00000000000000/* powercom-hid.c - subdriver to monitor PowerCOM USB/HID devices with NUT * * Copyright (C) * 2003 - 2009 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * 2020 - 2024 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" /* for getval() */ #include "usbhid-ups.h" #include "powercom-hid.h" #include "usb-common.h" #define POWERCOM_HID_VERSION "PowerCOM HID 0.71" /* FIXME: experimental flag to be put in upsdrv_info */ /* PowerCOM */ #define POWERCOM_VENDORID 0x0d9f /* USB IDs device table */ static usb_device_id_t powercom_usb_device_table[] = { /* PowerCOM IMP - IMPERIAL Series */ { USB_DEVICE(POWERCOM_VENDORID, 0x00a2), NULL }, /* PowerCOM SKP - Smart KING Pro (all Smart series) */ { USB_DEVICE(POWERCOM_VENDORID, 0x00a3), NULL }, /* PowerCOM WOW */ { USB_DEVICE(POWERCOM_VENDORID, 0x00a4), NULL }, /* PowerCOM VGD - Vanguard */ { USB_DEVICE(POWERCOM_VENDORID, 0x00a5), NULL }, /* PowerCOM BNT - Black Knight Pro */ { USB_DEVICE(POWERCOM_VENDORID, 0x00a6), NULL }, /* PowerCOM Vanguard and BNT-xxxAP */ { USB_DEVICE(POWERCOM_VENDORID, 0x0004), NULL }, { USB_DEVICE(POWERCOM_VENDORID, 0x0001), NULL }, /* Terminating entry */ { 0, 0, NULL } }; static char powercom_scratch_buf[32]; /* Original subdriver code until version 0.7 sent shutdown commands * in a wrong byte order than is needed by devices seen in the field * in 2024. Just in case there are different firmwares, we provide * a toggle to use old behavior. Maybe it was just a bug and nobody * needs this fall-back... */ static char powercom_sdcmd_byte_order_fallback = 0; static const char *powercom_startup_fun(double value) { uint16_t i = value; snprintf(powercom_scratch_buf, sizeof(powercom_scratch_buf), "%d", 60 * (((i & 0x00FF) << 8) + (i >> 8))); upsdebugx(3, "%s: value = %.0f, buf = %s", __func__, value, powercom_scratch_buf); return powercom_scratch_buf; } static double powercom_startup_nuf(const char *value) { const char *s = dstate_getinfo("ups.delay.start"); uint16_t val, command; int iv; iv = atoi(value ? value : s) / 60; if (iv < 0 || (intmax_t)iv > (intmax_t)UINT16_MAX) { upsdebugx(0, "%s: value = %d is not in uint16_t range", __func__, iv); return 0; } /* COMMENTME: What are we doing here, a byte-swap in the word? */ val = (uint16_t)iv; command = (uint16_t)(val << 8); command += (uint16_t)(val >> 8); upsdebugx(3, "%s: value = %s, command = %04X", __func__, value, command); return command; } static info_lkp_t powercom_startup_info[] = { { 0, NULL, powercom_startup_fun, powercom_startup_nuf } }; static const char *powercom_shutdown_fun(double value) { uint16_t i = value; if (powercom_sdcmd_byte_order_fallback) { /* Legacy behavior */ snprintf(powercom_scratch_buf, sizeof(powercom_scratch_buf), "%d", 60 * (i & 0x00FF) + (i >> 8)); } else { /* New default */ snprintf(powercom_scratch_buf, sizeof(powercom_scratch_buf), "%d", 60 * (i >> 8) + (i & 0x00FF)); } upsdebugx(3, "%s: value = %.0f, buf = %s", __func__, value, powercom_scratch_buf); return powercom_scratch_buf; } static double powercom_shutdown_nuf(const char *value) { const char *s = dstate_getinfo("ups.delay.shutdown"); uint16_t val, command; int iv; iv = atoi(value ? value : s); if (iv < 0 || (intmax_t)iv > (intmax_t)UINT16_MAX) { upsdebugx(0, "%s: value = %d is not in uint16_t range", __func__, iv); return 0; } val = (uint16_t)iv; val = val ? val : 1; /* 0 sets the maximum delay */ if (powercom_sdcmd_byte_order_fallback) { /* Legacy behavior */ command = ((uint16_t)((val % 60) << 8)) + (uint16_t)(val / 60); command |= 0x4000; /* AC RESTART NORMAL ENABLE */ } else { /* New default */ command = ((uint16_t)((val / 60) << 8)) + (uint16_t)(val % 60); command |= 0x0040; /* AC RESTART NORMAL ENABLE */ } upsdebugx(3, "%s: value = %s, command = %04X", __func__, value, command); return command; } static info_lkp_t powercom_shutdown_info[] = { { 0, NULL, powercom_shutdown_fun, powercom_shutdown_nuf } }; static double powercom_stayoff_nuf(const char *value) { const char *s = dstate_getinfo("ups.delay.shutdown"); uint16_t val, command; int iv; iv = atoi(value ? value : s); if (iv < 0 || (intmax_t)iv > (intmax_t)UINT16_MAX) { upsdebugx(0, "%s: value = %d is not in uint16_t range", __func__, iv); return 0; } val = (uint16_t)iv; val = val ? val : 1; /* 0 sets the maximum delay */ if (powercom_sdcmd_byte_order_fallback) { /* Legacy behavior */ command = ((uint16_t)((val % 60) << 8)) + (uint16_t)(val / 60); command |= 0x8000; /* AC RESTART NORMAL DISABLE */ } else { /* New default */ command = ((uint16_t)((val / 60) << 8)) + (uint16_t)(val % 60); command |= 0x0080; /* AC RESTART NORMAL DISABLE */ } upsdebugx(3, "%s: value = %s, command = %04X", __func__, value, command); return command; } static info_lkp_t powercom_stayoff_info[] = { { 0, NULL, NULL, powercom_stayoff_nuf } }; static info_lkp_t powercom_beeper_info[] = { { 1, "enabled", NULL, NULL }, { 2, "disabled", NULL, NULL }, /* muted? */ { 0, NULL, NULL, NULL } }; static const char *powercom_voltage_conversion_fun(double value) { static char buf[20]; snprintf(buf, sizeof(buf), "%0.0f", value * 4); return buf; } static info_lkp_t powercom_voltage_conversion[] = { { 0, NULL, powercom_voltage_conversion_fun, NULL } }; static const char *powercom_upsfail_conversion_fun(double value) { if ((long)value & 0x0001) { return "fanfail"; } else { return "!fanfail"; } } static info_lkp_t powercom_upsfail_conversion[] = { { 0, NULL, powercom_upsfail_conversion_fun, NULL } }; static const char *powercom_replacebatt_conversion_fun(double value) { if ((long)value & 0x0002) { return "replacebatt"; } else { return "!replacebatt"; } } static info_lkp_t powercom_replacebatt_conversion[] = { { 0, NULL, powercom_replacebatt_conversion_fun, NULL } }; static const char *powercom_test_conversion_fun(double value) { if ((long)value & 0x0004) { return "cal"; } else { return "!cal"; } } static info_lkp_t powercom_test_conversion[] = { { 0, NULL, powercom_test_conversion_fun, NULL } }; static const char *powercom_shutdownimm_conversion_fun(double value) { if ((long)value & 0x0010) { return "shutdownimm"; } else { return "!shutdownimm"; } } static info_lkp_t powercom_shutdownimm_conversion[] = { { 0, NULL, powercom_shutdownimm_conversion_fun, NULL } }; static const char *powercom_online_conversion_fun(double value) { if ((long)value & 0x0001) { return "!online"; } else { return "online"; } } static info_lkp_t powercom_online_conversion[] = { { 0, NULL, powercom_online_conversion_fun, NULL } }; static const char *powercom_lowbatt_conversion_fun(double value) { if ((long)value & 0x0002) { return "lowbatt"; } else { return "!lowbatt"; } } static info_lkp_t powercom_lowbatt_conversion[] = { { 0, NULL, powercom_lowbatt_conversion_fun, NULL } }; static const char *powercom_trim_conversion_fun(double value) { if (((long)value & 0x0018) == 0x0008) { return "trim"; } else { return "!trim"; } } static info_lkp_t powercom_trim_conversion[] = { { 0, NULL, powercom_trim_conversion_fun, NULL } }; static const char *powercom_boost_conversion_fun(double value) { if (((long)value & 0x0018) == 0x0018) { return "boost"; } else { return "!boost"; } } static info_lkp_t powercom_boost_conversion[] = { { 0, NULL, powercom_boost_conversion_fun, NULL } }; static const char *powercom_overload_conversion_fun(double value) { if ((long)value & 0x0020) { return "overload"; } else { return "!overload"; } } static info_lkp_t powercom_overload_conversion[] = { { 0, NULL, powercom_overload_conversion_fun, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* POWERCOM usage table */ static usage_lkp_t powercom_usage_lkp[] = { { "PowercomUPS", 0x00020004 }, { "PowercomBatterySystem", 0x00020010 }, { "PowercomPowerConverter", 0x00020016 }, { "PowercomInput", 0x0002001a }, { "PowercomOutput", 0x0002001c }, { "PowercomVoltage", 0x00020030 }, { "PowercomFrequency", 0x00020032 }, { "PowercomPercentLoad", 0x00020035 }, { "PowercomTemperature", 0x00020036 }, { "PowercomDelayBeforeStartup", 0x00020056 }, { "PowercomDelayBeforeShutdown", 0x00020057 }, { "PowercomTest", 0x00020058 }, { "PowercomShutdownRequested", 0x00020068 }, { "PowercomInternalChargeController", 0x00020081 }, { "PowercomPrimaryBatterySupport", 0x00020082 }, { "PowercomDesignCapacity", 0x00020083 }, { "PowercomSpecificationInfo", 0x00020084 }, { "PowercomManufacturerDate", 0x00020085 }, { "PowercomSerialNumber", 0x00020086 }, { "PowercomManufacturerName", 0x00020087 }, { "POWERCOM1", 0x0084002f }, { "POWERCOM2", 0xff860060 }, { "POWERCOM3", 0xff860080 }, { "PCMDelayBeforeStartup", 0x00ff0056 }, { "PCMDelayBeforeShutdown", 0x00ff0057 }, { NULL, 0 } }; static usage_tables_t powercom_utab[] = { powercom_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t powercom_hid2nut[] = { { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, 0, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BatteryPresent", NULL, NULL, 0, nobattery_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, 0, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, 0, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.CommunicationLost", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, 0, discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.RemainingTimeLimitExpired", NULL, NULL, 0, timelimitexpired_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, /* { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.POWERCOM3", NULL, "%.0f", 0, NULL }, */ /* { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownRequested", NULL, "%.0f", 0, NULL }, */ /* { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.VoltageNotRegulated", NULL, "%.0f", 0, NULL }, */ { "BOOL", 0, 0, "UPS.PresentStatus.ACPresent", NULL, NULL, 0, online_info }, { "BOOL", 0, 0, "UPS.PresentStatus.BatteryPresent", NULL, NULL, 0, nobattery_info }, { "BOOL", 0, 0, "UPS.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, 0, lowbatt_info }, { "BOOL", 0, 0, "UPS.PresentStatus.Boost", NULL, NULL, 0, boost_info }, { "BOOL", 0, 0, "UPS.PresentStatus.Buck", NULL, NULL, 0, trim_info }, { "BOOL", 0, 0, "UPS.PresentStatus.Charging", NULL, NULL, 0, charging_info }, { "BOOL", 0, 0, "UPS.PresentStatus.CommunicationLost", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PresentStatus.Discharging", NULL, NULL, 0, discharging_info }, { "BOOL", 0, 0, "UPS.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.PresentStatus.Overload", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.PresentStatus.RemainingTimeLimitExpired", NULL, NULL, 0, timelimitexpired_info }, { "BOOL", 0, 0, "UPS.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, /* { "BOOL", 0, 0, "UPS.PresentStatus.POWERCOM3", NULL, "%.0f", 0, NULL }, */ /* { "BOOL", 0, 0, "UPS.PresentStatus.ShutdownRequested", NULL, "%.0f", 0, NULL }, */ /* { "BOOL", 0, 0, "UPS.PresentStatus.Tested", NULL, "%.0f", 0, NULL }, */ /* { "BOOL", 0, 0, "UPS.PresentStatus.VoltageNotRegulated", NULL, "%.0f", 0, NULL }, */ /* * According to the HID PDC specifications, the below values should report battery.voltage(.nominal) * PowerCOM duplicates the output.voltage(.nominal) here, so we ignore them * { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.2f", 0, NULL }, * { "battery.voltage", 0, 0, "UPS.Battery.Voltage", NULL, "%.2f", 0, NULL }, * { "battery.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, * { "battery.voltage.nominal", 0, 0, "UPS.Battery.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, */ { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.charge", 0, 0, "UPS.Battery.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.charge.low", 0, 0, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", 0, NULL }, { "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", 0, NULL }, { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.mfr.date", 0, 0, "UPS.Battery.ManufacturerDate", NULL, "%s", HU_FLAG_STATIC, date_conversion }, { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, #if WITH_UNMAPPED_DATA_POINTS { "unmapped.ups.battery.delaybeforestartup", 0, 0, "UPS.Battery.DelayBeforeStartup", NULL, "%.0f", 0, NULL }, { "unmapped.ups.battery.initialized", 0, 0, "UPS.Battery.Initialized", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ { "ups.beeper.status", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "%s", 0, powercom_beeper_info }, { "ups.beeper.status", 0, 0, "UPS.AudibleAlarmControl", NULL, "%s", 0, powercom_beeper_info }, { "ups.load", 0, 0, "UPS.Output.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.date", 0, 0, "UPS.PowerSummary.ManufacturerDate", NULL, "%s", HU_FLAG_STATIC, date_conversion }, { "ups.test.result", 0, 0, "UPS.Battery.Test", NULL, "%s", 0, test_read_info }, #if WITH_UNMAPPED_DATA_POINTS { "unmapped.ups.powersummary.imanufacturer", 0, 0, "UPS.PowerSummary.iManufacturer", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, { "unmapped.ups.powersummary.iproduct", 0, 0, "UPS.PowerSummary.iProduct", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, { "unmapped.ups.powersummary.iserialnumber", 0, 0, "UPS.PowerSummary.iSerialNumber", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, { "unmapped.ups.iname", 0, 0, "UPS.iName", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, { "unmapped.ups.powersummary.ioeminformation", 0, 0, "UPS.PowerSummary.iOEMInformation", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* The implementation of the HID path UPS.PowerSummary.DelayBeforeStartup is unconventional: * Read: * Byte 7, byte 8 (min) * Write: * Command 4, high byte min, low byte min */ { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerSummary.DelayBeforeStartup", NULL, "60", HU_FLAG_ABSENT, NULL }, { "ups.timer.start", 0, 0, "UPS.PowerSummary.DelayBeforeStartup", NULL, "%.0f", 0, powercom_startup_info }, /* The implementation of the HID path UPS.PowerSummary.DelayBeforeShutdown is unconventional: * Read: * Byte 13, Byte 14 (min, sec) * Write: * If Byte(sec), bit7=0 and bit6=0 Then * If Byte 9, bit0=1 Then command 185, 188, min, sec (OL -> shutdown.return) * If Byte 9, bit0=0 Then command 186, 188, min, sec (OB -> shutdown.stayoff) * If Byte(sec), bit7=0 and bit6=1 * Then command 185, 188, min, sec (shutdown.return) * If Byte(sec), bit7=1 and bit6=0 Then * Then command 186, 188, min, sec (shutdown.stayoff) * If Byte(sec), bit7=1 and bit6=1 Then * No actions */ { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL }, { "ups.timer.shutdown", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, powercom_shutdown_info }, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerSummary.PCMDelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL }, { "ups.timer.shutdown", 0, 0, "UPS.PowerSummary.PCMDelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, powercom_shutdown_info }, { "input.voltage", 0, 0, "UPS.Input.Voltage", NULL, "%.1f", 0, NULL }, { "input.voltage.nominal", 0, 0, "UPS.Input.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.frequency", 0, 0, "UPS.Input.Frequency", NULL, "%.1f", 0, NULL }, { "output.voltage", 0, 0, "UPS.Output.Voltage", NULL, "%.1f", 0, NULL }, { "output.voltage.nominal", 0, 0, "UPS.Output.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "output.frequency", 0, 0, "UPS.Output.Frequency", NULL, "%.1f", 0, NULL }, #if WITH_UNMAPPED_DATA_POINTS { "unmapped.ups.powercom1", 0, 0, "UPS.POWERCOM1", NULL, "%.0f", 0, NULL }, /* broken pipe */ { "unmapped.ups.powercom2", 0, 0, "UPS.POWERCOM2", NULL, "%.0f", 0, NULL }, /* broken pipe */ { "unmapped.ups.powersummary.rechargeable", 0, 0, "UPS.PowerSummary.Rechargeable", NULL, "%.0f", 0, NULL }, { "unmapped.ups.shutdownimminent", 0, 0, "UPS.ShutdownImminent", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* instcmds */ { "beeper.toggle", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.enable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "0", HU_TYPE_CMD, NULL }, { "test.battery.start.quick", 0, 0, "UPS.Battery.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.PowerSummary.DelayBeforeStartup", NULL, NULL, HU_TYPE_CMD, powercom_startup_info }, { "shutdown.return", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, NULL, HU_TYPE_CMD, powercom_shutdown_info }, { "shutdown.stayoff", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, NULL, HU_TYPE_CMD, powercom_stayoff_info }, { "load.on", 0, 0, "UPS.PowerSummary.PCMDelayBeforeStartup", NULL, "0", HU_TYPE_CMD, powercom_startup_info }, { "load.off", 0, 0, "UPS.PowerSummary.PCMDelayBeforeShutdown", NULL, "0", HU_TYPE_CMD, powercom_stayoff_info }, { "shutdown.return", 0, 0, "UPS.PowerSummary.PCMDelayBeforeShutdown", NULL, NULL, HU_TYPE_CMD, powercom_shutdown_info }, { "shutdown.stayoff", 0, 0, "UPS.PowerSummary.PCMDelayBeforeShutdown", NULL, NULL, HU_TYPE_CMD, powercom_stayoff_info }, { "ups.serial", 0, 0, "PowercomUPS.PowercomSerialNumber", NULL, "%s", 0, stringid_conversion }, { "ups.mfr", 0, 0, "PowercomUPS.PowercomManufacturerName", NULL, "%s", 0, stringid_conversion }, #if WITH_UNMAPPED_DATA_POINTS { "UPS.DesignCapacity", 0, 0, "PowercomUPS.PowercomDesignCapacity", NULL, "%.0f", 0, NULL }, /* is always 255 */ #endif /* if WITH_UNMAPPED_DATA_POINTS */ { "ups.mfr.date", 0, 0, "PowercomUPS.PowercomManufacturerDate", NULL, "%s", 0, date_conversion }, { "battery.temperature", 0, 0, "PowercomUPS.PowercomBatterySystem.PowercomTemperature", NULL, "%.0f", 0, NULL }, { "battery.temperature", 0, 0, "UPS.Battery.Temperature", NULL, "%.1f", 0, NULL }, { "battery.charge", 0, 0, "PowercomUPS.PowercomBatterySystem.PowercomVoltage", NULL, "%.0f", 0, NULL }, #if WITH_UNMAPPED_DATA_POINTS { "UPS.BatterySystem.SpecificationInfo", 0, 0, "PowercomUPS.PowercomBatterySystem.PowercomSpecificationInfo", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ { "input.frequency", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomInput.PowercomFrequency", NULL, "%.0f", 0, NULL }, { "input.voltage", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomInput.PowercomVoltage", NULL, "%.0f", 0, powercom_voltage_conversion }, { "output.voltage", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomVoltage", NULL, "%.0f", 0, powercom_voltage_conversion }, { "ups.load", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomPercentLoad", NULL, "%.0f", 0, NULL }, /* flags: 4 - Testing, 8 - Probably mute (it's set on battery with muted beeper and sometimes during ups test) * bit 0 UPS fault (1 = FAILT) * bit 1 Battery status (1 = BAD, 0 = NORMAL) * bit 2 Test mode (1 = TEST, 0 = NORMAL) * bit 3 X * bit 4 Pre-SD count mode (1 = ACTIVE) * bit 5 Schedule count mode (1 = ACTIVE) * bit 6 Disable NO LOAD SHUTDOWN (1 = ACTIVE) * bit 7 0 */ #if WITH_UNMAPPED_DATA_POINTS { "UPS.PowerConverter.Output.InternalChargeController", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomInternalChargeController", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomInternalChargeController", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_upsfail_conversion }, { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomInternalChargeController", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_replacebatt_conversion }, { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomInternalChargeController", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_test_conversion }, { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomInternalChargeController", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_shutdownimm_conversion }, /* flags: 1 - On battery, 2 - Low Battery, 8 - Trim, 8+16 - Boost * bit 0 is line fail (1 = INV, 0 = LINE) * bit 1 is low battery (1 = BAT_ LOW, 0 = NORMAL) * bit 2 X * bit 3 AVR status (1 = AVR, 0 = NO_AVR) * bit 4 AVR mode (1 = BOOST, 0 = BUCK) * bit 5 Load status (1 = OVER LOAD, 0 = NORMAL) * bit 6 X * bit 7 SD mode display */ #if WITH_UNMAPPED_DATA_POINTS { "UPS.PowerConverter.Output.PrimaryBatterySupport", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomPrimaryBatterySupport", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomPrimaryBatterySupport", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_online_conversion }, /* Low battery status may not work */ { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomPrimaryBatterySupport", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_lowbatt_conversion }, { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomPrimaryBatterySupport", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_trim_conversion }, { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomPrimaryBatterySupport", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_boost_conversion }, { "BOOL", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomPrimaryBatterySupport", NULL, NULL, HU_FLAG_QUICK_POLL, powercom_overload_conversion }, { "output.frequency", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomOutput.PowercomFrequency", NULL, "%.0f", 0, NULL }, { "ups.test.result", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomTest", NULL, "%s", 0, test_read_info }, #if WITH_UNMAPPED_DATA_POINTS { "UPS.PowerConverter.ShutdownRequested", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomShutdownRequested", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ { "ups.delay.shutdown", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomDelayBeforeShutdown", NULL, "%.0f", 0, NULL }, { "ups.delay.start", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomDelayBeforeStartup", NULL, "%.0f", 0, NULL }, { "load.off", 0, 0, "PowercomUPS.PowercomPowerConverter.PowercomDelayBeforeShutdown", NULL, "0", HU_TYPE_CMD, NULL }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *powercom_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *powercom_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "PowerCOM"; } static const char *powercom_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int powercom_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(powercom_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: if (hd->ProductID == 0x0002) { upsdebugx(0, "This Powercom device (%04x/%04x) is not supported by usbhid-ups.\n" "Please use the 'powercom' driver instead.\n", hd->VendorID, hd->ProductID); return 0; } /* by default, reject, unless the productid option is given */ if (getval("productid")) { goto accept; } /* report and reject */ possibly_supported("PowerCOM", hd); return 0; case SUPPORTED: if (hd->ProductID == 0x0001) { interrupt_only = 1; interrupt_size = 8; } goto accept; case NOT_SUPPORTED: default: return 0; } accept: powercom_sdcmd_byte_order_fallback = testvar("powercom_sdcmd_byte_order_fallback"); return 1; } subdriver_t powercom_subdriver = { POWERCOM_HID_VERSION, powercom_claim, powercom_utab, powercom_hid2nut, powercom_format_model, powercom_format_mfr, powercom_format_serial, fix_report_desc, }; nut-2.8.4/drivers/nutdrv_qx_masterguard.h0000644000175000017500000000203414670526611015542 00000000000000/* nutdrv_qx_masterguard.h - Subdriver for Masterguard A/E Series * * Copyright (C) * 2020-2021 Edgar Fuß * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version, or a 2-clause BSD License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_MASTERGUARD_H #define NUTDRV_QX_MASTERGUARD_H #include "nutdrv_qx.h" extern subdriver_t masterguard_subdriver; #endif /* NUTDRV_QX_MASTERGUARD_H */ nut-2.8.4/drivers/nutdrv_qx_innovart31.c0000644000175000017500000002353315000736161015221 00000000000000/* nutdrv_qx_innovart31.c - Subdriver for INNOVA RT 3/1 UPSes * * Copyright (C) * 2024 Viktor Drobot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_innovart31.h" #define INNOVART31_VERSION "INNOVART31 0.02" /* Support functions */ static int innovart31_claim(void); static void innovart31_initups(void); static void innovart31_initinfo(void); /* qx2nut lookup table */ static item_t innovart31_qx2nut[] = { /* * > [Q6\r] * < [(227.0 225.6 230.0 50.0 229.9 000.0 000.0 49.9 007 000 000 327.8 000.0 23.0 06932 100 32 00000000 00000000 11\r] * 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 * 0 1 2 3 4 5 6 7 8 9 10 */ /* Common parameters */ { "input.L1-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.L2-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 7, 11, "%.1f", 0, NULL, NULL, NULL }, { "input.L3-N.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 13, 17, "%.1f", 0, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "Q6\r", "", 110, '(', "", 19, 22, "%.1f", 0, NULL, NULL, NULL }, { "output.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 24, 28, "%.1f", 0, NULL, NULL, NULL }, { "output.frequency", 0, NULL, "Q6\r", "", 110, '(', "", 42, 45, "%.1f", 0, NULL, NULL, NULL }, { "ups.load", 0, NULL, "Q6\r", "", 110, '(', "", 47, 49, "%.0f", 0, NULL, NULL, NULL }, { "ups.temperature", 0, NULL, "Q6\r", "", 110, '(', "", 71, 74, "%.1f", 0, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "Q6\r", "", 110, '(', "", 59, 63, "%.1f", 0, NULL, NULL, qx_multiply_battvolt }, { "battery.runtime", 0, NULL, "Q6\r", "", 110, '(', "", 76, 80, "%.0f", 0, NULL, NULL, NULL }, { "battery.charge", 0, NULL, "Q6\r", "", 110, '(', "", 82, 84, "%.0f", 0, NULL, NULL, NULL }, /* * > [WA\r] * < [(001.4 000.0 000.0 001.4 000.0 000.0 001.4 001.4 006.5 000.0 000.0 007 00000000\r] * 01234567890123456789012345678901234567890123456789012345678901234567890123456789 * 0 1 2 3 4 5 6 7 */ /* Output consumption parameters */ { "output.current", 0, NULL, "WA\r", "", 80, '(', "", 49, 53, "%.1f", 0, NULL, NULL, NULL }, { "ups.realpower", 0, NULL, "WA\r", "", 80, '(', "", 37, 41, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, { "ups.power", 0, NULL, "WA\r", "", 80, '(', "", 43, 47, "%.1f", 0, NULL, NULL, qx_multiply_x1000 }, /* * > [BPS\r] * < [(230.4 000.0 000.0 49.9\r] * 012345678901234567890123 * 0 1 2 */ /* Bypass parameters */ { "input.bypass.voltage", 0, NULL, "BPS\r", "", 24, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.bypass.frequency", 0, NULL, "BPS\r", "", 24, '(', "", 19, 22, "%.1f", 0, NULL, NULL, NULL }, /* * > [F\r] * < [#230.0 087 288.0 50.0\r] * 0123456789012345678901 * 0 1 2 */ /* Nominal parameters (ratings) */ { "input.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 1, 5, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.current.nominal", 0, NULL, "F\r", "", 22, '#', "", 7, 9, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "battery.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 11, 15, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.frequency.nominal", 0, NULL, "F\r", "", 22, '#', "", 17, 20, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, /* * > [FW?\r] * < [05516-1100\r] * 01234567890 * 0 1 */ /* Firmware version */ { "ups.firmware", 0, NULL, "FW?\r", "", 0, 0, "", 0, 0, "%s", QX_FLAG_STATIC, NULL, NULL, NULL }, /* * > [SASV07?\r] * < [GASV07DN05K10KB100004 \r] * 0123456789012345678901234567 * 0 1 2 */ /* UPS serial number */ { "ups.serial", 0, NULL, "SASV07?\r", "", 28, 0, "", 7, 0, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* * > [Q1\r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000\r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ /* Status bits */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 38, 38, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Utility Fail (Immediate) */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 39, 39, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Battery Low */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 40, 40, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Bypass/Boost or Buck Active */ { "ups.alarm", 0, NULL, "Q1\r", "", 47, '(', "", 41, 41, NULL, 0, NULL, NULL, blazer_process_status_bits }, /* UPS Failed */ { "ups.type", 0, NULL, "Q1\r", "", 47, '(', "", 42, 42, "%s", QX_FLAG_STATIC, NULL, NULL, blazer_process_status_bits }, /* UPS Type */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 43, 43, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Test in Progress */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 44, 44, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Shutdown Active */ { "ups.beeper.status", 0, NULL, "Q1\r", "", 47, '(', "", 45, 45, "%s", 0, NULL, NULL, blazer_process_status_bits }, /* Beeper status */ /* Instant commands */ /* NB: seems like beeper toggling doesn't work for Innova RT 3/1 by Ippon - UPS simply doesn't respond */ { "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%sR0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, blazer_r_ondelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_ONDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, blazer_r_offdelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_OFFDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* Testing table */ #ifdef TESTING static testing_t innovart31_testing[] = { { "Q6\r", "(227.0 225.6 230.0 50.0 229.9 000.0 000.0 49.9 007 000 000 327.8 000.0 23.0 06932 100 32 00000000 00000000 11\r", -1 }, { "Q1\r", "(215.0 195.0 230.0 014 49.0 22.7 30.0 00000000\r", -1 }, { "WA\r", "(001.4 000.0 000.0 001.4 000.0 000.0 001.4 001.4 006.5 000.0 000.0 007 00000000\r", -1 }, { "BPS\r", "(230.4 000.0 000.0 49.9\r", -1 }, { "F\r", "#230.0 087 288.0 50.0\r", -1 }, { "FW?\r", "05516-1100\r", -1 }, { "SASV07?\r", "GASV07DN05K10KB100004 \r", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0000\r", "", -1 }, { "T04\r", "ACK", -1 }, { "TL\r", "ACK", -1 }, { "T\r", "ACK", -1 }, { "CT\r", "ACK", -1 }, { NULL } }; #endif /* TESTING */ /* == Support functions == */ /* This function allows the subdriver to "claim" a device: return 1 if the device is supported by this subdriver, else 0 */ static int innovart31_claim(void) { /* We need Q6, Q1, WA, BPS, F, FW? and SASV07? to use this subdriver */ struct { char *var; char *cmd; } mandatory[] = { { "input.L1-N.voltage", "Q6" }, { "ups.type", "Q1" }, { "output.current", "WA" }, { "input.bypass.voltage", "BPS" }, { "input.voltage.nominal", "F" }, { "ups.firmware", "FW?" }, { "ups.serial", "SASV07?" }, { NULL, NULL} }; int vari; char *sp; item_t *item; for (vari = 0; mandatory[vari].var; vari++) { sp = mandatory[vari].var; item = find_nut_info(sp, 0, 0); /* Don't know what happened */ if (!item) return 0; /* No reply/Unable to get value */ if (qx_process(item, NULL)) return 0; /* Unable to process value */ if (ups_infoval_set(item) != 1) return 0; } return 1; } /* Subdriver-specific initups */ static void innovart31_initups(void) { blazer_initups_light(innovart31_qx2nut); } /* Subdriver-specific initinfo */ static void innovart31_initinfo(void) { dstate_setinfo("input.phases", "%d", 3); dstate_setinfo("input.bypass.phases", "%d", 1); dstate_setinfo("output.phases", "%d", 1); } /* Subdriver interface */ subdriver_t innovart31_subdriver = { INNOVART31_VERSION, innovart31_claim, innovart31_qx2nut, innovart31_initups, innovart31_initinfo, blazer_makevartable_light, "ACK", "NAK\r", #ifdef TESTING innovart31_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/dstate.c0000644000175000017500000017267515044656702012415 00000000000000/* dstate.c - Network UPS Tools driver-side state management Copyright (C) 2003 Russell Kroll 2008 Arjen de Korte 2012-2017 Arnaud Quette 2020-2025 Jim Klimov 2025 desertwitch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be the first header */ #include #ifndef WIN32 # include # include # include # include # include # include #else /* WIN32 */ # include # include "wincompat.h" #endif /* WIN32 */ #include "common.h" #include "dstate.h" #include "state.h" #include "parseconf.h" #include "attribute.h" #include "nut_stdint.h" static TYPE_FD sockfd = ERROR_FD; #ifndef WIN32 static char *sockfn = NULL; #else /* WIN32 */ static OVERLAPPED connect_overlapped; static char *pipename = NULL; #endif /* WIN32 */ static int stale = 1, alarm_active = 0, alarm_status = 0, ignorelb = 0, alarm_legacy_status = 0; static char status_buf[ST_MAX_VALUE_LEN], alarm_buf[ST_MAX_VALUE_LEN], buzzmode_buf[ST_MAX_VALUE_LEN]; static conn_t *connhead = NULL; static st_tree_t *dtree_root = NULL; static cmdlist_t *cmdhead = NULL; struct ups_handler upsh; #ifndef WIN32 /* this may be a frequent stumbling point for new users, so be verbose here */ static void sock_fail(const char *fn) __attribute__((noreturn)); static void sock_fail(const char *fn) { int sockerr; struct passwd *pwuser; /* save this so it doesn't get overwritten */ sockerr = errno; /* dispense with the usual upslog stuff since we have stderr here */ printf("\nFatal error: unable to create listener socket\n\n"); printf("bind %s failed: %s\n", fn, strerror(sockerr)); /* deal with some common problems */ switch (errno) { case EACCES: pwuser = getpwuid(getuid()); if (pwuser) { printf("\nCurrent user: %s (UID %" PRIiMAX ")\n\n", NUT_STRARG(pwuser->pw_name), (intmax_t)pwuser->pw_uid); } printf("Things to try:\n\n"); printf(" - set different owners or permissions on %s\n\n", dflt_statepath()); printf(" - run this program as some other user " "(try -u )\n"); if (!pwuser) { fatal_with_errno(EXIT_FAILURE, "getpwuid"); } break; case ENOENT: printf("\nThings to try:\n\n"); printf(" - mkdir %s\n", dflt_statepath()); break; case ENOTDIR: printf("\nThings to try:\n\n"); printf(" - rm %s\n\n", dflt_statepath()); printf(" - mkdir %s\n", dflt_statepath()); break; case EADDRINUSE: case EADDRNOTAVAIL: printf("\nThings to try:\n\n"); printf(" - ps -ef | grep '%s'\t(Linux, GNU userland)\n" " - ps -xawwu | grep '%s'\t(BSD, Solaris, embedded)\n" " To check if another copy of the driver is running; if not:\n\n", progname, progname); printf(" - ls -la %s\n To check if a (non-socket) filesystem object already exists there\n\n", fn); printf(" - rm -rf %s\n To remove any offending files (a new driver instance creates its own)\n", fn); break; default: break; } /* * there - that wasn't so bad. every helpful line of code here * prevents one more "help me" mail to the list a year from now */ printf("\n"); fatalx(EXIT_FAILURE, "Exiting."); } #endif /* !WIN32 */ static TYPE_FD sock_open(const char *fn) { TYPE_FD fd; #ifndef WIN32 int ret; struct sockaddr_un ssaddr; check_unix_socket_filename(fn); fd = socket(AF_UNIX, SOCK_STREAM, 0); if (INVALID_FD(fd)) { fatal_with_errno(EXIT_FAILURE, "Can't create a unix domain socket"); } /* keep this around for the unlink() when exiting */ sockfn = xstrdup(fn); ssaddr.sun_family = AF_UNIX; snprintf(ssaddr.sun_path, sizeof(ssaddr.sun_path), "%s", sockfn); unlink(sockfn); /* group gets access so upsd can be a different user but same group */ umask(0007); ret = bind(fd, (struct sockaddr *) &ssaddr, sizeof ssaddr); if (ret < 0) { sock_fail(sockfn); } ret = chmod(sockfn, 0660); if (ret < 0) { fatal_with_errno(EXIT_FAILURE, "chmod(%s, 0660) failed", sockfn); } ret = listen(fd, DS_LISTEN_BACKLOG); if (ret < 0) { fatal_with_errno(EXIT_FAILURE, "listen(%d, %d) failed", fd, DS_LISTEN_BACKLOG); } if (!getenv("NUT_QUIET_INIT_LISTENER")) upslogx(LOG_INFO, "Listening on socket %s", sockfn); #else /* WIN32 */ fd = CreateNamedPipe( fn, /* pipe name */ PIPE_ACCESS_DUPLEX | /* read/write access */ FILE_FLAG_OVERLAPPED, /* async IO */ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, /* max. instances */ ST_SOCK_BUF_LEN, /* output buffer size */ ST_SOCK_BUF_LEN, /* input buffer size */ 0, /* client time-out */ NULL); /* FIXME: default security attribute */ if (INVALID_FD(fd)) { fatal_with_errno(EXIT_FAILURE, "Can't create a state socket (windows named pipe)"); } /* Prepare an async wait on a connection on the pipe */ memset(&connect_overlapped, 0, sizeof(connect_overlapped)); connect_overlapped.hEvent = CreateEvent(NULL, /*Security*/ FALSE, /* auto-reset*/ FALSE, /* inital state = non signaled*/ NULL /* no name*/); if (connect_overlapped.hEvent == NULL) { fatal_with_errno(EXIT_FAILURE, "Can't create event"); } /* Wait for a connection */ ConnectNamedPipe(fd, &connect_overlapped); if (!getenv("NUT_QUIET_INIT_LISTENER")) upslogx(LOG_INFO, "Listening on named pipe %s", fn); #endif /* WIN32 */ return fd; } static void sock_disconnect(conn_t *conn) { #ifndef WIN32 upsdebugx(3, "%s: disconnecting socket %d", __func__, (int)conn->fd); close(conn->fd); #else /* WIN32 */ /* FIXME NUT_WIN32_INCOMPLETE not sure if this is the right way to close a connection */ if (conn->read_overlapped.hEvent != INVALID_HANDLE_VALUE) { CloseHandle(conn->read_overlapped.hEvent); conn->read_overlapped.hEvent = INVALID_HANDLE_VALUE; } upsdebugx(3, "%s: disconnecting named pipe handle %p", __func__, conn->fd); DisconnectNamedPipe(conn->fd); #endif /* WIN32 */ upsdebugx(5, "%s: finishing parsing context", __func__); pconf_finish(&conn->ctx); upsdebugx(5, "%s: relinking the chain of connections", __func__); if (conn->prev) { conn->prev->next = conn->next; } else { connhead = conn->next; } if (conn->next) { conn->next->prev = conn->prev; } else { /* conntail = conn->prev; */ } upsdebugx(5, "%s: freeing the conn object", __func__); free(conn); } static void send_to_all(const char *fmt, ...) { ssize_t ret; char buf[ST_SOCK_BUF_LEN]; size_t buflen; va_list ap; conn_t *conn, *cnext; va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: this code intentionally uses a caller-provided * format string (we should not get it from configs etc. * or the calling methods should check it against their * "fmt_dynamic" expectations). */ ret = vsnprintf(buf, sizeof(buf), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); if (ret < 1) { upsdebugx(2, "%s: nothing to write", __func__); return; } if (ret <= INT_MAX) upsdebugx(5, "%s: %.*s", __func__, (int)(ret-1), buf); buflen = strlen(buf); if (buflen >= SSIZE_MAX) { /* Can't compare buflen to ret... though should not happen with ST_SOCK_BUF_LEN */ upslog_with_errno(LOG_NOTICE, "%s failed: buffered message too large", __func__); return; } for (conn = connhead; conn; conn = cnext) { cnext = conn->next; if (conn->nobroadcast) continue; #ifndef WIN32 ret = write(conn->fd, buf, buflen); #else /* WIN32 */ DWORD bytesWritten = 0; BOOL result = FALSE; result = WriteFile (conn->fd, buf, buflen, &bytesWritten, NULL); if( result == 0 ) { upsdebugx(2, "%s: write failed on handle %p, disconnecting", __func__, conn->fd); sock_disconnect(conn); continue; } else { ret = (ssize_t)bytesWritten; } #endif /* WIN32 */ if ((ret < 1) || (ret != (ssize_t)buflen)) { #ifndef WIN32 upsdebug_with_errno(0, "WARNING: %s: write %" PRIuSIZE " bytes to " "socket %d failed (ret=%" PRIiSIZE "), disconnecting.", __func__, buflen, (int)conn->fd, ret); #else /* WIN32 */ upsdebug_with_errno(0, "WARNING: %s: write %" PRIuSIZE " bytes to " "handle %p failed (ret=%" PRIiSIZE "), disconnecting.", __func__, buflen, conn->fd, ret); #endif /* WIN32 */ upsdebugx(6, "%s: failed write: %s", __func__, buf); sock_disconnect(conn); /* TOTHINK: Maybe fallback elsewhere in other cases? */ if (ret < 0 && errno == EAGAIN && do_synchronous == -1) { upsdebugx(0, "%s: synchronous mode was 'auto', " "will try 'on' for next connections", __func__); do_synchronous = 1; } dstate_setinfo("driver.parameter.synchronous", "%s", (do_synchronous==1)?"yes":((do_synchronous==0)?"no":"auto")); } else { upsdebugx(6, "%s: write %" PRIuSIZE " bytes to socket %d succeeded " "(ret=%" PRIiSIZE "): %s", __func__, buflen, conn->fd, ret, buf); } } } static int send_to_one(conn_t *conn, const char *fmt, ...) { ssize_t ret; va_list ap; char buf[ST_SOCK_BUF_LEN]; size_t buflen; #ifdef WIN32 DWORD bytesWritten = 0; BOOL result = FALSE; #endif /* WIN32 */ va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: this code intentionally uses a caller-provided * format string (we should not get it from configs etc. * or the calling methods should check it against their * "fmt_dynamic" expectations). */ ret = vsnprintf(buf, sizeof(buf), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); upsdebugx(2, "%s: sending %.*s", __func__, (int)strcspn(buf, "\n"), buf); if (ret < 1) { upsdebugx(2, "%s: nothing to write", __func__); return 1; } buflen = strlen(buf); if (buflen >= SSIZE_MAX) { /* Can't compare buflen to ret... though should not happen with ST_SOCK_BUF_LEN */ upslog_with_errno(LOG_NOTICE, "%s failed: buffered message too large", __func__); return 0; /* failed */ } if (ret <= INT_MAX) upsdebugx(5, "%s: %.*s", __func__, (int)(ret-1), buf); /* upsdebugx(0, "%s: writing %" PRIiSIZE " bytes to socket %d: %s", __func__, buflen, conn->fd, buf); */ #ifndef WIN32 ret = write(conn->fd, buf, buflen); #else /* WIN32 */ result = WriteFile (conn->fd, buf, buflen, &bytesWritten, NULL); if( result == 0 ) { ret = 0; } else { ret = (ssize_t)bytesWritten; } #endif /* WIN32 */ if (ret < 0) { /* Hacky bugfix: throttle down for upsd to read that */ #ifndef WIN32 upsdebug_with_errno(1, "%s: had to throttle down to retry " "writing %" PRIuSIZE " bytes to socket %d (ret=%" PRIiSIZE ") : %s", __func__, buflen, (int)conn->fd, ret, buf); #else /* WIN32 */ upsdebug_with_errno(1, "%s: had to throttle down to retry " "writing %" PRIuSIZE " bytes to handle %p (ret=%" PRIiSIZE ") : %s", __func__, buflen, conn->fd, ret, buf); #endif /* WIN32 */ usleep(200); #ifndef WIN32 ret = write(conn->fd, buf, buflen); #else /* WIN32 */ result = WriteFile (conn->fd, buf, buflen, &bytesWritten, NULL); if( result == 0 ) { ret = 0; } else { ret = (ssize_t)bytesWritten; } #endif /* WIN32 */ if (ret == (ssize_t)buflen) { upsdebugx(1, "%s: throttling down helped", __func__); } } if ((ret < 1) || (ret != (ssize_t)buflen)) { #ifndef WIN32 upsdebug_with_errno(0, "WARNING: %s: write %" PRIuSIZE " bytes to " "socket %d failed (ret=%" PRIiSIZE "), disconnecting.", __func__, buflen, (int)conn->fd, ret); #else /* WIN32 */ upsdebug_with_errno(0, "WARNING: %s: write %" PRIuSIZE " bytes to " "handle %p failed (ret=%" PRIiSIZE "), disconnecting.", __func__, buflen, conn->fd, ret); #endif /* WIN32 */ upsdebugx(6, "%s: failed write: %s", __func__, buf); sock_disconnect(conn); /* TOTHINK: Maybe fallback elsewhere in other cases? */ if (ret < 0 && errno == EAGAIN && do_synchronous == -1) { upsdebugx(0, "%s: synchronous mode was 'auto', " "will try 'on' for next connections", __func__); do_synchronous = 1; } dstate_setinfo("driver.parameter.synchronous", "%s", (do_synchronous==1)?"yes":((do_synchronous==0)?"no":"auto")); return 0; /* failed */ } else { #ifndef WIN32 upsdebugx(6, "%s: write %" PRIuSIZE " bytes to socket %d succeeded " "(ret=%" PRIiSIZE "): %s", __func__, buflen, conn->fd, ret, buf); #else /* WIN32 */ upsdebugx(6, "%s: write %" PRIuSIZE " bytes to handle %p succeeded " "(ret=%" PRIiSIZE "): %s", __func__, buflen, conn->fd, ret, buf); #endif /* WIN32 */ } return 1; /* OK */ } static void sock_connect(TYPE_FD sock) { conn_t *conn; #ifndef WIN32 int ret; int fd; struct sockaddr_un sa; # if defined(__hpux) && !defined(_XOPEN_SOURCE_EXTENDED) int salen; # else socklen_t salen; # endif salen = sizeof(sa); fd = accept(sock, (struct sockaddr *) &sa, &salen); if (INVALID_FD(fd)) { upslog_with_errno(LOG_ERR, "%s: accept on unix fd failed", __func__); return; } /* enable nonblocking I/O? * -1 = auto (try async, allow fallback to sync) * 0 = async * 1 = sync */ if (do_synchronous < 1) { upsdebugx(0, "%s: enabling asynchronous mode (%s)", __func__, (do_synchronous<0)?"auto":"fixed"); ret = fcntl(fd, F_GETFL, 0); if (ret < 0) { upslog_with_errno(LOG_ERR, "%s: fcntl get on unix fd failed", __func__); close(fd); return; } ret = fcntl(fd, F_SETFL, ret | O_NDELAY); if (ret < 0) { upslog_with_errno(LOG_ERR, "%s: fcntl set O_NDELAY on unix fd failed", __func__); close(fd); return; } } else { upsdebugx(0, "%s: keeping default synchronous mode", __func__); } conn = (conn_t *)xcalloc(1, sizeof(*conn)); conn->fd = fd; #else /* WIN32 */ /* We have detected a connection on the opened pipe. * So we start by saving its handle and creating * a new pipe for future connection */ conn = xcalloc(1, sizeof(*conn)); conn->fd = sock; /* sockfd is the handle of the connection pending pipe */ sockfd = CreateNamedPipe( pipename, /* pipe name */ PIPE_ACCESS_DUPLEX | /* read/write access */ FILE_FLAG_OVERLAPPED, /* async IO */ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, /* max. instances */ ST_SOCK_BUF_LEN, /* output buffer size */ ST_SOCK_BUF_LEN, /* input buffer size */ 0, /* client time-out */ NULL); /* FIXME: default security attribute */ if (INVALID_FD(sockfd)) { fatal_with_errno(EXIT_FAILURE, "Can't create a state socket (windows named pipe)"); } /* Prepare a new async wait for a connection on the pipe */ CloseHandle(connect_overlapped.hEvent); memset(&connect_overlapped,0,sizeof(connect_overlapped)); connect_overlapped.hEvent = CreateEvent(NULL, /*Security*/ FALSE, /* auto-reset*/ FALSE, /* inital state = non signaled*/ NULL /* no name*/); if(connect_overlapped.hEvent == NULL ) { fatal_with_errno(EXIT_FAILURE, "Can't create event"); } /* Wait for a connection */ ConnectNamedPipe(sockfd,&connect_overlapped); /* A new pipe waiting for new client connection has been created. We could manage the current connection now */ /* Start a read operation on the newly connected pipe so we could wait on the event associated to this IO */ memset(&conn->read_overlapped,0,sizeof(conn->read_overlapped)); memset(conn->buf,0,sizeof(conn->buf)); conn->read_overlapped.hEvent = CreateEvent(NULL, /*Security*/ FALSE, /* auto-reset*/ FALSE, /* inital state = non signaled*/ NULL /* no name*/); if(conn->read_overlapped.hEvent == NULL ) { fatal_with_errno(EXIT_FAILURE, "Can't create event"); } ReadFile (conn->fd, conn->buf, sizeof(conn->buf) - 1, /* -1 to be sure to have a trailling 0 */ NULL, &(conn->read_overlapped)); #endif /* WIN32 */ conn->nobroadcast = 0; conn->readzero = 0; conn->closing = 0; pconf_init(&conn->ctx, NULL); if (connhead) { conn->next = connhead; connhead->prev = conn; } connhead = conn; #ifndef WIN32 upsdebugx(3, "%s: new connection on fd %d", __func__, fd); #else /* WIN32 */ upsdebugx(3, "%s: new connection on handle %p", __func__, sock); #endif /* WIN32 */ } static int st_tree_dump_conn_one_node(st_tree_t *node, conn_t *conn) { enum_t *etmp; range_t *rtmp; if (!send_to_one(conn, "SETINFO %s \"%s\"\n", node->var, node->val)) { return 0; /* write failed, bail out */ } /* send any enums */ for (etmp = node->enum_list; etmp; etmp = etmp->next) { if (!send_to_one(conn, "ADDENUM %s \"%s\"\n", node->var, etmp->val)) { return 0; } } /* send any ranges */ for (rtmp = node->range_list; rtmp; rtmp = rtmp->next) { if (!send_to_one(conn, "ADDRANGE %s %i %i\n", node->var, rtmp->min, rtmp->max)) { return 0; } } /* provide any auxiliary data */ if (node->aux) { if (!send_to_one(conn, "SETAUX %s %ld\n", node->var, node->aux)) { return 0; } } /* finally report any flags */ if (node->flags) { char flist[SMALLBUF]; /* build the list */ snprintf(flist, sizeof(flist), "%s", node->var); if (node->flags & ST_FLAG_RW) { snprintfcat(flist, sizeof(flist), " RW"); } if (node->flags & ST_FLAG_STRING) { snprintfcat(flist, sizeof(flist), " STRING"); } if (node->flags & ST_FLAG_NUMBER) { snprintfcat(flist, sizeof(flist), " NUMBER"); } if (!send_to_one(conn, "SETFLAGS %s\n", flist)) { return 0; } } return 1; /* everything's OK here ... */ } static int st_tree_dump_conn(st_tree_t *node, conn_t *conn) { int ret; if (!node) { return 1; /* not an error */ } if (node->left) { ret = st_tree_dump_conn(node->left, conn); if (!ret) { return 0; /* write failed in the child */ } } if (!st_tree_dump_conn_one_node(node, conn)) return 0; /* one of writes failed, bail out */ if (node->right) { return st_tree_dump_conn(node->right, conn); } return 1; /* everything's OK here ... */ } static int cmd_dump_conn(conn_t *conn) { cmdlist_t *cmd; for (cmd = cmdhead; cmd; cmd = cmd->next) { if (!send_to_one(conn, "ADDCMD %s\n", cmd->name)) { return 0; } } return 1; } static void send_tracking(conn_t *conn, const char *id, int value) { send_to_one(conn, "TRACKING %s %i\n", id, value); } static int sock_arg(conn_t *conn, size_t numarg, char **arg) { #ifdef WIN32 char *sockfn = pipename; /* Just for the report below; not a global var in WIN32 builds */ #endif /* WIN32 */ upsdebugx(6, "%s: Driver on %s is now handling %s with %" PRIuSIZE " args", __func__, sockfn, numarg ? arg[0] : "", numarg); if (numarg < 1) { return 0; } if (!strcasecmp(arg[0], "LOGOUT")) { send_to_one(conn, "OK Goodbye\n"); #ifndef WIN32 upsdebugx(2, "%s: received LOGOUT on socket %d, will be disconnecting", __func__, (int)conn->fd); #else /* WIN32 */ upsdebugx(2, "%s: received LOGOUT on handle %p, will be disconnecting", __func__, conn->fd); #endif /* WIN32 */ /* Let the system flush the reply somehow (or the other * side to just see it) before we drop the pipe */ usleep(1000000); /* err on the safe side, and actually close/free conn separately */ conn->closing = 1; upsdebugx(4, "%s: LOGOUT processing finished", __func__); return 2; } if (!strcasecmp(arg[0], "GETPID")) { send_to_one(conn, "PID %" PRIiMAX "\n", (intmax_t)getpid()); return 1; } if (!strcasecmp(arg[0], "DUMPALL") || !strcasecmp(arg[0], "DUMPSTATUS") || (!strcasecmp(arg[0], "DUMPVALUE") && numarg > 1)) { /* first thing: the staleness flag (see also below) */ if ((stale == 1) && !send_to_one(conn, "DATASTALE\n")) { return 1; } if (!strcasecmp(arg[0], "DUMPALL")) { if (!st_tree_dump_conn(dtree_root, conn)) { return 1; } if (!cmd_dump_conn(conn)) { return 1; } } else { /* A cheaper version of the dump */ char *varname = (!strcasecmp(arg[0], "DUMPSTATUS") ? "ups.status" : (numarg > 1 ? arg[1] : NULL)); st_tree_t *sttmp = (varname ? state_tree_find(dtree_root, varname) : NULL); if (!sttmp) { upsdebugx(1, "%s: %s was requested but currently no %s is known", __func__, arg[0], NUT_STRARG(varname)); } else { if (!st_tree_dump_conn_one_node(sttmp, conn)) return 1; } } if ((stale == 0) && !send_to_one(conn, "DATAOK\n")) { return 1; } send_to_one(conn, "DUMPDONE\n"); return 1; } if (!strcasecmp(arg[0], "PING")) { send_to_one(conn, "PONG\n"); return 1; } if (!strcasecmp(arg[0], "NOBROADCAST")) { char buf[SMALLBUF]; conn->nobroadcast = 1; #ifndef WIN32 snprintf(buf, sizeof(buf), "socket %d", conn->fd); #else /* WIN32 */ snprintf(buf, sizeof(buf), "handle %p", conn->fd); #endif /* WIN32 */ upsdebugx(1, "%s: %s requested NOBROADCAST mode", __func__, buf); return 1; } /* BROADCAST <0|1> */ if (!strcasecmp(arg[0], "BROADCAST")) { int i; char buf[SMALLBUF]; conn->nobroadcast = 0; if (numarg > 1 && str_to_int(arg[1], &i, 10)) { if (i < 1) conn->nobroadcast = 1; } #ifndef WIN32 snprintf(buf, sizeof(buf), "socket %d", conn->fd); #else /* WIN32 */ snprintf(buf, sizeof(buf), "handle %p", conn->fd); #endif /* WIN32 */ upsdebugx(1, "%s: %s requested %sBROADCAST mode", __func__, buf, conn->nobroadcast ? "NO" : ""); return 1; } if (numarg < 2) { return 0; } /* INSTCMD [] [TRACKING ] */ if (!strcasecmp(arg[0], "INSTCMD")) { int ret; char *cmdname = arg[1]; char *cmdparam = NULL; char *cmdid = NULL; /* Check if and/or TRACKING were provided */ if (numarg == 3) { cmdparam = arg[2]; } else if (numarg == 4 && !strcasecmp(arg[2], "TRACKING")) { cmdid = arg[3]; } else if (numarg == 5 && !strcasecmp(arg[3], "TRACKING")) { cmdparam = arg[2]; cmdid = arg[4]; } else if (numarg != 2) { upslogx(LOG_INSTCMD_INVALID, "Malformed INSTCMD request"); return 0; } if (cmdid) upsdebugx(3, "%s: TRACKING = %s", __func__, cmdid); /* try the handler shared by all drivers first */ ret = main_instcmd(cmdname, cmdparam, conn); if (ret != STAT_INSTCMD_UNKNOWN) { /* The command was acknowledged by shared handler, and * either handled successfully, or failed, or was not * valid in current circumstances - in any case, we do * not pass to driver-provided logic. */ /* send back execution result if requested */ if (cmdid) send_tracking(conn, cmdid, ret); /* The command was handled, status is a separate consideration */ return 1; } /* else try other handler(s) */ /* try the driver-provided handler if present */ if (upsh.instcmd) { ret = upsh.instcmd(cmdname, cmdparam); /* send back execution result if requested */ if (cmdid) send_tracking(conn, cmdid, ret); /* The command was handled, status is a separate consideration */ return 1; } if (cmdparam) { upslogx(LOG_INSTCMD_UNKNOWN, "Got INSTCMD '%s' '%s', but driver lacks a handler", NUT_STRARG(cmdname), NUT_STRARG(cmdparam)); } else { upslogx(LOG_INSTCMD_UNKNOWN, "Got INSTCMD '%s', but driver lacks a handler", NUT_STRARG(cmdname)); } /* Send back execution result (here, STAT_INSTCMD_UNKNOWN) * if TRACKING was requested. * Note that in practice we should not get here often: if the * instcmd was not registered, it may be rejected earlier in * call stack, or returned by a driver's handler (for unknown * commands) just a bit above. */ if (cmdid) send_tracking(conn, cmdid, ret); /* The command was handled, status is a separate consideration */ return 1; } if (numarg < 3) { return 0; } /* SET [TRACKING ] */ if (!strcasecmp(arg[0], "SET")) { int ret; char *setid = NULL; /* Check if TRACKING was provided */ if (numarg == 5) { if (!strcasecmp(arg[3], "TRACKING")) { setid = arg[4]; } else { upslogx(LOG_SET_INVALID, "Got SET with unsupported parameters (%s/%s)", arg[3], arg[4]); return 0; } upsdebugx(3, "%s: TRACKING = %s", __func__, setid); } /* try the handler shared by all drivers first */ ret = main_setvar(arg[1], arg[2], conn); if (ret != STAT_SET_UNKNOWN) { /* The command was acknowledged by shared handler, and * either handled successfully, or failed, or was not * valid in current circumstances - in any case, we do * not pass to driver-provided logic. */ /* send back execution result if requested */ if (setid) send_tracking(conn, setid, ret); /* The command was handled, status is a separate consideration */ return 1; } /* else try other handler(s) */ /* try the driver-provided handler if present */ if (upsh.setvar) { ret = upsh.setvar(arg[1], arg[2]); /* send back execution result if requested */ if (setid) send_tracking(conn, setid, ret); /* The command was handled, status is a separate consideration */ return 1; } upslogx(LOG_SET_UNKNOWN, "Got SET, but driver lacks a handler"); return 1; } /* unknown */ return 0; } static void sock_read(conn_t *conn) { ssize_t ret, i; int ret_arg = -1; #ifndef WIN32 char buf[SMALLBUF]; ret = read(conn->fd, buf, sizeof(buf)); if (ret < 0) { switch(errno) { case EINTR: case EAGAIN: return; default: sock_disconnect(conn); return; } } if (ret == 0) { int flags = fcntl(conn->fd, F_GETFL), is_closed = 0; upsdebugx(2, "%s: read() returned 0; flags=%04X O_NDELAY=%04X", __func__, (unsigned int)flags, (unsigned int)O_NDELAY); if (flags & O_NDELAY || O_NDELAY == 0) { /* O_NDELAY with zero bytes means nothing to read but * since read() follows a successful select() with * ready file descriptor, ret shouldn't be 0. * This may also mean that the counterpart has exited * and the file descriptor should be reaped. * e.g. a `driver -c reload -a testups` fires its * message over Unix socket and disconnects. */ is_closed = 1; } else { /* assume we will soon have data waiting in the buffer */ conn->readzero++; upsdebugx(1, "%s: got zero-sized reads %d times in a row", __func__, conn->readzero); if (conn->readzero > DSTATE_CONN_READZERO_THROTTLE_MAX) { is_closed = 2; } else { usleep(DSTATE_CONN_READZERO_THROTTLE_USEC); } } if (is_closed) { upsdebugx(1, "%s: it seems the other side has closed the connection", __func__); sock_disconnect(conn); return; } } else { conn->readzero = 0; } #else /* WIN32 */ char *buf = conn->buf; DWORD bytesRead; BOOL res; res = GetOverlappedResult(conn->fd, &conn->read_overlapped, &bytesRead, FALSE); if( res == 0 ) { upslogx(LOG_INFO, "Read error : %d",(int)GetLastError()); sock_disconnect(conn); return; } ret = bytesRead; /* Special case for signals */ if (!strncmp(conn->buf, COMMAND_STOP, sizeof(COMMAND_STOP))) { set_exit_flag(1); return; } #endif /* WIN32 */ for (i = 0; i < ret; i++) { switch(pconf_char(&conn->ctx, buf[i])) { case 0: /* nothing to parse yet */ continue; case 1: /* try to use it, and complain about unknown commands */ ret_arg = sock_arg(conn, conn->ctx.numargs, conn->ctx.arglist); if (!ret_arg) { size_t arg; upslogx(LOG_INFO, "Unknown command on socket: "); for (arg = 0; arg < conn->ctx.numargs && arg < INT_MAX; arg++) { upslogx(LOG_INFO, "arg %d: %s", (int)arg, conn->ctx.arglist[arg]); } } else if (ret_arg == 2) { /* closed by LOGOUT processing, conn is free()'d */ if (i < ret) upsdebugx(1, "%s: returning early, socket may be not valid anymore", __func__); return; } continue; default: /* nothing parsed */ upslogx(LOG_NOTICE, "Parse error on sock: %s", conn->ctx.errmsg); return; } } #ifdef WIN32 /* Restart async read */ memset(conn->buf,0,sizeof(conn->buf)); ReadFile(conn->fd,conn->buf,sizeof(conn->buf)-1,NULL,&(conn->read_overlapped)); /* -1 to be sure to have a trailling 0 */ #endif /* WIN32 */ } static void sock_close(void) { conn_t *conn, *cnext; if (VALID_FD(sockfd)) { #ifndef WIN32 close(sockfd); if (sockfn) { unlink(sockfn); free(sockfn); sockfn = NULL; } #else /* WIN32 */ FlushFileBuffers(sockfd); CloseHandle(sockfd); #endif /* WIN32 */ sockfd = ERROR_FD; } for (conn = connhead; conn; conn = cnext) { cnext = conn->next; sock_disconnect(conn); } connhead = NULL; /* conntail = NULL; */ } /* interface */ char * dstate_init(const char *prog, const char *devname) { char sockname[NUT_PATH_MAX + 1]; #ifndef WIN32 /* do this here for now */ #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRICT_PROTOTYPES) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wstrict-prototypes" #endif signal(SIGPIPE, SIG_IGN); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_STRICT_PROTOTYPES) # pragma GCC diagnostic pop #endif if (devname) { snprintf(sockname, sizeof(sockname), "%s/%s-%s", dflt_statepath(), prog, devname); } else { snprintf(sockname, sizeof(sockname), "%s/%s", dflt_statepath(), prog); } #else /* WIN32 */ /* upsname (and so devname) is now mandatory so no need to test it */ snprintf(sockname, sizeof(sockname), "\\\\.\\pipe\\%s-%s", prog, devname); pipename = xstrdup(sockname); #endif /* WIN32 */ sockfd = sock_open(sockname); #ifndef WIN32 upsdebugx(2, "%s: sock %s open on fd %d", __func__, sockname, sockfd); #else /* WIN32 */ upsdebugx(2, "%s: sock %s open on handle %p", __func__, sockname, sockfd); #endif /* WIN32 */ /* NOTE: Caller must free this string */ return xstrdup(sockname); } /* returns 1 if timeout expired or data is available on UPS fd, 0 otherwise */ int dstate_poll_fds(struct timeval timeout, TYPE_FD arg_extrafd) { int maxfd = 0; /* Unidiomatic use vs. "sockfd" below, which is "int" on non-WIN32 */ int overrun = 0; conn_t *conn, *cnext; struct timeval now; #ifndef WIN32 int ret; fd_set rfds; FD_ZERO(&rfds); FD_SET(sockfd, &rfds); maxfd = sockfd; if (VALID_FD(arg_extrafd)) { FD_SET(arg_extrafd, &rfds); if (arg_extrafd > maxfd) { maxfd = arg_extrafd; } } for (conn = connhead; conn; conn = conn->next) { FD_SET(conn->fd, &rfds); if (conn->fd > maxfd) { maxfd = conn->fd; } } gettimeofday(&now, NULL); /* number of microseconds should always be positive */ if (timeout.tv_usec < now.tv_usec) { timeout.tv_sec -= 1; timeout.tv_usec += 1000000; } if (timeout.tv_sec < now.tv_sec) { timeout.tv_sec = 0; timeout.tv_usec = 0; overrun = 1; /* no time left */ } else { timeout.tv_sec -= now.tv_sec; timeout.tv_usec -= now.tv_usec; } ret = select(maxfd + 1, &rfds, NULL, NULL, &timeout); if (ret == 0) { return 1; /* timer expired */ } if (ret < 0) { switch (errno) { case EINTR: case EAGAIN: /* ignore interruptions from signals */ break; default: upslog_with_errno(LOG_ERR, "%s: select unix sockets failed", __func__); } return overrun; } if (FD_ISSET(sockfd, &rfds)) { sock_connect(sockfd); } for (conn = connhead; conn; conn = cnext) { cnext = conn->next; if (FD_ISSET(conn->fd, &rfds)) { sock_read(conn); } } for (conn = connhead; conn; conn = cnext) { cnext = conn->next; if (conn->closing) { sock_disconnect(conn); } } /* tell the caller if that fd woke up */ if (VALID_FD(arg_extrafd) && (FD_ISSET(arg_extrafd, &rfds))) { return 1; } #else /* WIN32 */ DWORD ret; HANDLE rfds[32]; DWORD timeout_ms; /* FIXME: Should such table (and limit) be used in reality? */ NUT_UNUSED_VARIABLE(arg_extrafd); /* if (VALID_FD(arg_extrafd)) { rfds[maxfd] = arg_extrafd; maxfd++; } */ gettimeofday(&now, NULL); /* number of microseconds should always be positive */ if (timeout.tv_usec < now.tv_usec) { timeout.tv_sec -= 1; timeout.tv_usec += 1000000; } if (timeout.tv_sec < now.tv_sec) { timeout.tv_sec = 0; timeout.tv_usec = 0; overrun = 1; /* no time left */ } else { timeout.tv_sec -= now.tv_sec; timeout.tv_usec -= now.tv_usec; } timeout_ms = (timeout.tv_sec * 1000) + (timeout.tv_usec / 1000); /* Wait on the read IO of each connections */ for (conn = connhead; conn; conn = conn->next) { rfds[maxfd] = conn->read_overlapped.hEvent; maxfd++; } /* Add the connect event */ rfds[maxfd] = connect_overlapped.hEvent; maxfd++; ret = WaitForMultipleObjects( maxfd, /* number of objects in array */ rfds, /* array of objects */ FALSE, /* wait for any object */ timeout_ms); /* timeout in millisecond */ if (ret == WAIT_TIMEOUT) { return 1; /* timer expired */ } if (ret == WAIT_FAILED) { upslog_with_errno(LOG_ERR, "%s: waitfor failed", __func__); return overrun; } /* Retrieve the signaled connection */ for (conn = connhead; conn != NULL; conn = conn->next) { if( conn->read_overlapped.hEvent == rfds[ret-WAIT_OBJECT_0]) { break; } } /* the connection event handle has been signaled */ if (rfds[ret] == connect_overlapped.hEvent) { sock_connect(sockfd); } /* one of the read event handle has been signaled */ else { if (conn != NULL) { sock_read(conn); } } for (conn = connhead; conn; conn = cnext) { cnext = conn->next; if (conn->closing) { sock_disconnect(conn); } } /* tell the caller if that fd woke up */ /* if (VALID_FD(arg_extrafd) && (ret == arg_extrafd)) { return 1; } */ #endif /* WIN32 */ return overrun; } /****************************************************************** * COMMON ******************************************************************/ int vdstate_setinfo(const char *var, const char *fmt, va_list ap) { int ret; char value[ST_MAX_VALUE_LEN]; #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: this code intentionally uses a caller-provided * format string (we should not get it from configs etc. * or the calling methods should check it against their * "fmt_dynamic" expectations e.g. by using the * dstate_setinfo_dynamic() method). */ vsnprintf(value, sizeof(value), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif ret = state_setinfo(&dtree_root, var, value); if (ret == 1) { send_to_all("SETINFO %s \"%s\"\n", var, value); } return ret; } int dstate_setinfo(const char *var, const char *fmt, ...) { int ret; va_list ap; va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: this code intentionally uses a caller-provided * format string (we should not get it from configs etc. * or the calling methods should check it against their * "fmt_dynamic" expectations e.g. by using the * dstate_setinfo_dynamic() method). */ ret = vdstate_setinfo(var, fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); return ret; } int dstate_setinfo_dynamic(const char *var, const char *fmt_dynamic, const char *fmt_reference, ...) { if (!var || validate_formatting_string(fmt_dynamic, fmt_reference, NUT_DYNAMICFORMATTING_DEBUG_LEVEL) < 0) { return -1; } else { int ret; va_list ap; va_start(ap, fmt_reference); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Using validated formatting string here */ ret = vdstate_setinfo(var, fmt_dynamic, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); return ret; } } int vdstate_addenum(const char *var, const char *fmt, va_list ap) { int ret; char value[ST_MAX_VALUE_LEN]; #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: this code intentionally uses a caller-provided * format string (we should not get it from configs etc. * or the calling methods should check it against their * "fmt_dynamic" expectations e.g. by using the * dstate_addenum_dynamic() method). */ vsnprintf(value, sizeof(value), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif ret = state_addenum(dtree_root, var, value); if (ret == 1) { send_to_all("ADDENUM %s \"%s\"\n", var, value); } return ret; } int dstate_addenum(const char *var, const char *fmt, ...) { int ret; va_list ap; va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: this code intentionally uses a caller-provided * format string (we should not get it from configs etc. * or the calling methods should check it against their * "fmt_dynamic" expectations e.g. by using the * dstate_addenum_dynamic() method). */ ret = vdstate_addenum(var, fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); return ret; } int dstate_addenum_dynamic(const char *var, const char *fmt_dynamic, const char *fmt_reference, ...) { if (!var || validate_formatting_string(fmt_dynamic, fmt_reference, NUT_DYNAMICFORMATTING_DEBUG_LEVEL) < 0) { return -1; } else { int ret; va_list ap; va_start(ap, fmt_reference); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Using validated formatting string here */ ret = vdstate_addenum(var, fmt_dynamic, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); return ret; } } int dstate_addrange(const char *var, const int min, const int max) { int ret; ret = state_addrange(dtree_root, var, min, max); if (ret == 1) { send_to_all("ADDRANGE %s %i %i\n", var, min, max); /* Also add the "NUMBER" flag for ranges */ dstate_addflags(var, ST_FLAG_NUMBER); } return ret; } void dstate_setflags(const char *var, int flags) { st_tree_t *sttmp; char flist[SMALLBUF]; /* find the dtree node for var */ sttmp = state_tree_find(dtree_root, var); if (!sttmp) { upslogx(LOG_ERR, "%s: base variable (%s) does not exist", __func__, var); return; } if (sttmp->flags & ST_FLAG_IMMUTABLE) { upslogx(LOG_WARNING, "%s: base variable (%s) is immutable", __func__, var); return; } if (sttmp->flags == flags) { return; /* no change */ } sttmp->flags = flags; /* build the list */ snprintf(flist, sizeof(flist), "%s", var); if (flags & ST_FLAG_RW) { snprintfcat(flist, sizeof(flist), " RW"); } if (flags & ST_FLAG_STRING) { snprintfcat(flist, sizeof(flist), " STRING"); } if (flags & ST_FLAG_NUMBER) { snprintfcat(flist, sizeof(flist), " NUMBER"); } /* update listeners */ send_to_all("SETFLAGS %s\n", flist); } void dstate_addflags(const char *var, const int addflags) { int flags = state_getflags(dtree_root, var); if (flags == -1) { upslogx(LOG_ERR, "%s: cannot get flags of '%s'", __func__, var); return; } /* Already set */ if ((flags & addflags) == addflags) return; flags |= addflags; dstate_setflags(var, flags); } void dstate_delflags(const char *var, const int delflags) { int flags = state_getflags(dtree_root, var); if (flags == -1) { upslogx(LOG_ERR, "%s: cannot get flags of '%s'", __func__, var); return; } /* Already not set */ if (!(flags & delflags)) return; flags &= ~delflags; dstate_setflags(var, flags); } void dstate_setaux(const char *var, long aux) { st_tree_t *sttmp; /* find the dtree node for var */ sttmp = state_tree_find(dtree_root, var); if (!sttmp) { upslogx(LOG_ERR, "%s: base variable (%s) does not exist", __func__, var); return; } if (sttmp->aux == aux) { return; /* no change */ } sttmp->aux = aux; /* update listeners */ send_to_all("SETAUX %s %ld\n", var, aux); } const char *dstate_getinfo(const char *var) { return state_getinfo(dtree_root, var); } void dstate_addcmd(const char *cmdname) { int ret; ret = state_addcmd(&cmdhead, cmdname); /* update listeners */ if (ret == 1) { send_to_all("ADDCMD %s\n", cmdname); } } int dstate_delinfo(const char *var) { int ret; ret = state_delinfo(&dtree_root, var); /* update listeners */ if (ret == 1) { send_to_all("DELINFO %s\n", var); } return ret; } int dstate_delinfo_olderthan(const char *var, const st_tree_timespec_t *cutoff) { int ret; ret = state_delinfo_olderthan(&dtree_root, var, cutoff); /* update listeners */ if (ret == 1) { send_to_all("DELINFO %s\n", var); } return ret; } int dstate_delenum(const char *var, const char *val) { int ret; ret = state_delenum(dtree_root, var, val); /* update listeners */ if (ret == 1) { send_to_all("DELENUM %s \"%s\"\n", var, val); } return ret; } int dstate_delrange(const char *var, const int min, const int max) { int ret; ret = state_delrange(dtree_root, var, min, max); /* update listeners */ if (ret == 1) { send_to_all("DELRANGE %s %i %i\n", var, min, max); } return ret; } int dstate_delcmd(const char *cmd) { int ret; ret = state_delcmd(&cmdhead, cmd); /* update listeners */ if (ret == 1) { send_to_all("DELCMD %s\n", cmd); } return ret; } void dstate_free(void) { state_infofree(dtree_root); dtree_root = NULL; state_cmdfree(cmdhead); cmdhead = NULL; sock_close(); } const st_tree_t *dstate_getroot(void) { return dtree_root; } const cmdlist_t *dstate_getcmdlist(void) { return cmdhead; } void dstate_dataok(void) { if (stale == 1) { stale = 0; send_to_all("DATAOK\n"); } } void dstate_datastale(void) { if (stale == 0) { stale = 1; send_to_all("DATASTALE\n"); } } int dstate_is_stale(void) { return stale; } /* ups.status management functions - reducing duplication in the drivers */ /* clean out the temp space for a new pass */ void status_init(void) { /* This does not normally change in driver run-time, but can in tests */ ignorelb = (dstate_getinfo("driver.flag.ignorelb") ? 1 : 0); memset(status_buf, 0, sizeof(status_buf)); alarm_status = 0; alarm_legacy_status = 0; } /* check if a status element has been set, return 0 if not, 1 if yes * (considering a whole-word token in temporary status_buf) */ int status_get(const char *buf) { return str_contains_token(status_buf, buf); } /* add a status element */ static int status_set_callback(char *tgt, size_t tgtsize, const char *token) { if (tgt != status_buf || tgtsize != sizeof(status_buf)) { upsdebugx(2, "%s: called for wrong use-case", __func__); return 0; } if (ignorelb && !strcasecmp(token, "LB")) { upsdebugx(2, "%s: ignoring LB flag from device", __func__); return 0; } if (!strcasecmp(token, "ALARM")) { /* Drivers should not do this anymore, but we continue * to support it. The upsmon notifiers do not care where * alarm tokens get set and legacy drivers may still use * this older method. The only real limitations are that * the alarm state is very tightly coupled to the UPS * status, and the ups.alarm variables do not get published * in a controlled manner. Rather, these are very dependent * on the (legacy) driver, and alarm notifications via upsmon * will show placeholder "n/a" if all values are missing. * The status token is ignored to prepend it to other tokens * later, within the status_commit() function. * For more information, see this discussion: * https://github.com/networkupstools/nut/pull/2931#issuecomment-2841705269 */ upsdebugx(6, "%s: caller set ALARM as a status, this is deprecated - please fix the NUT driver code", __func__); alarm_legacy_status = 1; return 0; /* ignore it */ } /* Proceed adding the token */ return 1; } void status_set(const char *buf) { #ifdef DEBUG upsdebugx(3, "%s: '%s'\n", __func__, buf); #endif str_add_unique_token(status_buf, sizeof(status_buf), buf, status_set_callback, NULL); } /* write the status_buf into the externally visible dstate storage */ void status_commit(void) { while (ignorelb) { const char *val, *low; val = dstate_getinfo("battery.charge"); low = dstate_getinfo("battery.charge.low"); if (val && low && (strtol(val, NULL, 10) < strtol(low, NULL, 10))) { snprintfcat(status_buf, sizeof(status_buf), " LB"); upsdebugx(2, "%s: appending LB flag [charge '%s' below '%s']", __func__, val, low); break; } val = dstate_getinfo("battery.runtime"); low = dstate_getinfo("battery.runtime.low"); if (val && low && (strtol(val, NULL, 10) < strtol(low, NULL, 10))) { snprintfcat(status_buf, sizeof(status_buf), " LB"); upsdebugx(2, "%s: appending LB flag [runtime '%s' below '%s']", __func__, val, low); break; } /* LB condition not detected */ break; } if (alarm_active || alarm_legacy_status) { if (*status_buf != '\0') { dstate_setinfo("ups.status", "ALARM %s", status_buf); } else { dstate_setinfo("ups.status", "ALARM"); } } else { dstate_setinfo("ups.status", "%s", status_buf); alarm_legacy_status = 0; /* just to be sure */ } } /* similar functions for experimental.ups.mode.buzzwords, where tracked * dynamically (e.g. due to ECO/ESS/HE/Smart modes supported by the device) */ void buzzmode_init(void) { memset(buzzmode_buf, 0, sizeof(buzzmode_buf)); } int buzzmode_get(const char *buf) { return str_contains_token(buzzmode_buf, buf); } void buzzmode_set(const char *buf) { str_add_unique_token(buzzmode_buf, sizeof(buzzmode_buf), buf, NULL, NULL); } void buzzmode_commit(void) { if (!*buzzmode_buf) { dstate_delinfo("experimental.ups.mode.buzzwords"); return; } dstate_setinfo("experimental.ups.mode.buzzwords", "%s", buzzmode_buf); } /* similar handlers for ups.alarm */ void alarm_init(void) { /* reinit global counter */ alarm_active = 0; device_alarm_init(); } #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtype-limits" #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif void alarm_set(const char *buf) { /* NOTE: Differs from status_set() since we can add whole sentences * here, not just unique tokens. Drivers are encouraged to wrap such * sentences into brackets, especially when many alarms raised at once * are anticipated, for readability. */ int ret; if (strlen(alarm_buf) < 1 || (alarm_status && !strcmp(alarm_buf, "[N/A]"))) { ret = snprintf(alarm_buf, sizeof(alarm_buf), "%s", buf); } else { ret = snprintfcat(alarm_buf, sizeof(alarm_buf), " %s", buf); } if (ret < 0) { /* Should we also try to print the potentially unusable buf? * Generally - likely not. But if it is short enough... * Note: LARGEBUF was the original limit mismatched vs. alarm_buf * size before PR #986. */ char alarm_tmp[LARGEBUF]; int ibuflen; size_t buflen; memset(alarm_tmp, 0, sizeof(alarm_tmp)); /* A bit of complexity to keep both (int)snprintf(...) and (size_t)sizeof(...) happy */ ibuflen = snprintf(alarm_tmp, sizeof(alarm_tmp), "%s", buf); if (ibuflen < 0) { alarm_tmp[0] = 'N'; alarm_tmp[1] = '/'; alarm_tmp[2] = 'A'; alarm_tmp[3] = '\0'; buflen = strlen(alarm_tmp); } else { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) /* Note for gating macros above: unsuffixed HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP * means support of contexts both inside and outside function body, so the push * above and pop below (outside this finction) are not used. */ # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS /* Note that the individual warning pragmas for use inside function bodies * are named without a _INSIDEFUNC suffix, for simplicity and legacy reasons */ # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if ((unsigned long long int)ibuflen < SIZE_MAX) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif buflen = (size_t)ibuflen; } else { buflen = SIZE_MAX; } } upslogx(LOG_ERR, "%s: error setting alarm_buf to: %s%s", __func__, alarm_tmp, ( (buflen < sizeof(alarm_tmp)) ? "" : "..." ) ); } else if ((size_t)ret > sizeof(alarm_buf)) { char alarm_tmp[LARGEBUF]; int ibuflen; size_t buflen; memset(alarm_tmp, 0, sizeof(alarm_tmp)); ibuflen = snprintf(alarm_tmp, sizeof(alarm_tmp), "%s", buf); if (ibuflen < 0) { alarm_tmp[0] = 'N'; alarm_tmp[1] = '/'; alarm_tmp[2] = 'A'; alarm_tmp[3] = '\0'; buflen = strlen(alarm_tmp); } else { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if ((unsigned long long int)ibuflen < SIZE_MAX) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif buflen = (size_t)ibuflen; } else { buflen = SIZE_MAX; } } upslogx(LOG_WARNING, "%s: result was truncated while setting or appending " "alarm_buf (limited to %" PRIuSIZE " bytes), with message: %s%s", __func__, sizeof(alarm_buf), alarm_tmp, ( (buflen < sizeof(alarm_tmp)) ? "" : "..." )); } } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic pop #endif /* write the status_buf into the info array for "ups.alarm" */ void alarm_commit(void) { /* Note this is a bit different from `device_alarm_commit(0);` * because here we also increase AND zero out the alarm count. * alarm_active = 0; device_alarm_commit(0); * would be equivalent, but too intimate for later maintenance. */ if (strlen(alarm_buf) > 0) { dstate_setinfo("ups.alarm", "%s", alarm_buf); alarm_active = 1; } else { dstate_delinfo("ups.alarm"); alarm_active = 0; } } void device_alarm_init(void) { /* only clear the buffer, don't touch the alarms counter */ memset(alarm_buf, 0, sizeof(alarm_buf)); } /* same as above, but writes to "device.X.ups.alarm" or "ups.alarm" */ /* Note that 20 chars below just allow for a 2-digit "X" */ /* FIXME? Shouldn't this be changed to be a LARGEBUF aka sizeof(alarm_buf) ? */ void device_alarm_commit(const int device_number) { char info_name[20]; memset(info_name, 0, 20); if (device_number != 0) /* would then go into "device.%i.alarm" */ snprintf(info_name, 20, "device.%i.ups.alarm", device_number); else /* would then go into "device.alarm" */ snprintf(info_name, 20, "ups.alarm"); /* Daisychain subdevices note: * increase the counter when alarms are present on a subdevice, but * don't decrease the count. Otherwise, we may not get the ALARM flag * in ups.status, while there are some alarms present on device.X */ if (strlen(alarm_buf) > 0) { dstate_setinfo(info_name, "%s", alarm_buf); alarm_active++; } else { dstate_delinfo(info_name); } } /* For devices where we do not have phase-count info (no mapping provided * in the tables), nor in the device data/protocol, we can still guesstimate * and report a value. This routine may also replace an existing value, e.g. * if we've found new data disproving old one (e.g. if the 3-phase UPS was * disbalanced when the driver was started, so we thought it is 1-phase in * practice, and then the additional lines came up loaded, hence the bools * "may_reevaluate" and the readonly flag "may_change_dstate" (so the caller * can query the current apparent situation, without changing any dstates). * It is up to callers to decide if they already have data they want to keep. * The "xput_prefix" is e.g. "input." or "input.bypass." or "output." with * the trailing dot where applicable - we use this string verbatim below. * The "inited_phaseinfo" and "num_phases" are addresses of caller's own * variables to store the flag (if we have successfully inited) and the * discovered amount of phases, or NULL if caller does not want to track it. * * NOTE: The code below can detect if the device is 1, 2 (split phase) or 3 * phases. * * Returns: * -1 Runtime/input error (non fatal, but routine was skipped) * 0 Nothing changed: could not determine a value * 1 A phase value was just determined (and set, if not read-only mode) * 2 Nothing changed: already inited (and may_reevaluate==false) * 3 Nothing changed: detected a value but it is already published * as a dstate; populated inited_phaseinfo and num_phases though */ int dstate_detect_phasecount( const char *xput_prefix, const int may_change_dstate, int *inited_phaseinfo, int *num_phases, const int may_reevaluate ) { /* If caller does not want either of these back - loopback the values below */ int local_inited_phaseinfo = 0, local_num_phases = -1; /* Temporary local value storage */ int old_num_phases = -1, detected_phaseinfo = 0; if (!inited_phaseinfo) inited_phaseinfo = &local_inited_phaseinfo; if (!num_phases) num_phases = &local_num_phases; old_num_phases = *num_phases; upsdebugx(3, "Entering %s('%s', %i, %i, %i, %i)", __func__, xput_prefix, may_change_dstate, *inited_phaseinfo, *num_phases, may_reevaluate); if (!(*inited_phaseinfo) || may_reevaluate) { const char *v1, *v2, *v3, *v0, *v1n, *v2n, *v3n, *v12, *v23, *v31, *c1, *c2, *c3, *c0; char buf[MAX_STRING_SIZE]; /* For concatenation of "xput_prefix" with items we want to query */ size_t xput_prefix_len; size_t bufrw_max; char *bufrw_ptr = NULL; if (!xput_prefix) { upsdebugx(0, "%s(): Bad xput_prefix was passed: it is NULL - function skipped", __func__); return -1; } xput_prefix_len = strlen(xput_prefix); if (xput_prefix_len < 1) { upsdebugx(0, "%s(): Bad xput_prefix was passed: it is empty - function skipped", __func__); return -1; } bufrw_max = sizeof(buf) - xput_prefix_len; if (bufrw_max <= 15) { /* We need to append max ~13 chars per below, so far */ upsdebugx(0, "%s(): Bad xput_prefix was passed: it is too long - function skipped", __func__); return -1; } memset(buf, 0, sizeof(buf)); strncpy(buf, xput_prefix, sizeof(buf)); bufrw_ptr = buf + xput_prefix_len ; /* We either have defined and non-zero (numeric) values below, or NULLs. * Note that as "zero" we should expect any valid numeric representation * of a zero value as some drivers may save strangely formatted values. * For now, we limit the level of paranoia with missing dstate entries, * empty entries, and actual single zero character as contents of the * string. Other obscure cases (string of multiple zeroes, a floating * point zero, surrounding whitespace etc. may be solved if the need * does arise in the future. Arguably, drivers' translation/mapping * tables should take care of this with converion routine and numeric * data type flags. */ #define dstate_getinfo_nonzero(var, suffix) \ do { strncpy(bufrw_ptr, suffix, bufrw_max); \ if ( (var = dstate_getinfo(buf)) ) { \ if ( (var[0] == '0' && var[1] == '\0') || \ (var[0] == '\0') ) { \ var = NULL; \ } \ } \ } while(0) dstate_getinfo_nonzero(v1, "L1.voltage"); dstate_getinfo_nonzero(v2, "L2.voltage"); dstate_getinfo_nonzero(v3, "L3.voltage"); dstate_getinfo_nonzero(v1n, "L1-N.voltage"); dstate_getinfo_nonzero(v2n, "L2-N.voltage"); dstate_getinfo_nonzero(v3n, "L3-N.voltage"); dstate_getinfo_nonzero(v1n, "L1-N.voltage"); dstate_getinfo_nonzero(v12, "L1-L2.voltage"); dstate_getinfo_nonzero(v23, "L2-L3.voltage"); dstate_getinfo_nonzero(v31, "L3-L1.voltage"); dstate_getinfo_nonzero(c1, "L1.current"); dstate_getinfo_nonzero(c2, "L2.current"); dstate_getinfo_nonzero(c3, "L3.current"); dstate_getinfo_nonzero(v0, "voltage"); dstate_getinfo_nonzero(c0, "current"); if ( (v1 && v2 && !v3) || (v1n && v2n && !v3n) || (c1 && c2 && !c3) || (v12 && !v23 && !v31) ) { upsdebugx(5, "%s(): determined a 2-phase case", __func__); *num_phases = 2; *inited_phaseinfo = 1; detected_phaseinfo = 1; } else if ( (v1 && v2 && v3) || (v1n && v2n && v3n) || (c1 && (c2 || c3)) || (c2 && (c1 || c3)) || (c3 && (c1 || c2)) || v12 || v23 || v31 ) { upsdebugx(5, "%s(): determined a 3-phase case", __func__); *num_phases = 3; *inited_phaseinfo = 1; detected_phaseinfo = 1; } else if ( /* We definitely have only one non-zero line */ !v12 && !v23 && !v31 && ( (c0 && !c1 && !c2 && !c3) || (v0 && !v1 && !v2 && !v3) || (c1 && !c2 && !c3) || (!c1 && c2 && !c3) || (!c1 && !c2 && c3) || (v1 && !v2 && !v3) || (!v1 && v2 && !v3) || (!v1 && !v2 && v3) || (v1n && !v2n && !v3n) || (!v1n && v2n && !v3n) || (!v1n && !v2n && v3n) ) ) { *num_phases = 1; *inited_phaseinfo = 1; detected_phaseinfo = 1; upsdebugx(5, "%s(): determined a 1-phase case", __func__); } else { upsdebugx(5, "%s(): could not determine the phase case", __func__); } if (detected_phaseinfo) { const char *oldphases; strncpy(bufrw_ptr, "phases", bufrw_max); oldphases = dstate_getinfo(buf); if (oldphases) { if (atoi(oldphases) == *num_phases) { /* Technically, a bit has changed: we have set the flag which may have been missing before */ upsdebugx(5, "%s(): Nothing changed, with a valid reason; dstate already published with the same value: %s=%s (detected %d)", __func__, buf, oldphases, *num_phases); return 3; } } if ( (*num_phases != old_num_phases) || (!oldphases) ) { if (may_change_dstate) { dstate_setinfo(buf, "%d", *num_phases); upsdebugx(3, "%s(): calculated non-XML value for NUT variable %s was set to %d", __func__, buf, *num_phases); } else { upsdebugx(3, "%s(): calculated non-XML value for NUT variable %s=%d but did not set its dstate (read-only request)", __func__, buf, *num_phases); } return 1; } } upsdebugx(5, "%s(): Nothing changed: could not determine a value", __func__); return 0; } upsdebugx(5, "%s(): Nothing changed, with a valid reason; already inited", __func__); return 2; } /* Dump the data tree (in upsc-like format) to stdout */ /* Actual implementation */ static int dstate_tree_dump(const st_tree_t *node) { int ret; if (!node) { return 1; /* not an error */ } if (node->left) { ret = dstate_tree_dump(node->left); if (!ret) { return 0; /* write failed in the child */ } } printf("%s: %s\n", node->var, node->val); if (node->right) { return dstate_tree_dump(node->right); } return 1; /* everything's OK here ... */ } /* Dump the data tree (in upsc-like format) to stdout */ /* Public interface */ void dstate_dump(void) { const st_tree_t *node; upsdebugx(3, "Entering %s", __func__); node = (const st_tree_t *)dstate_getroot(); fflush(stderr); dstate_tree_dump(node); /* Make sure it lands in one piece and is logged where called */ fflush(stdout); fflush(stderr); } nut-2.8.4/drivers/serial.c0000644000175000017500000003557415044656702012404 00000000000000/* serial.c - common serial port functions for Network UPS Tools drivers Copyright (C) 2003 Russell Kroll This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "common.h" #include "timehead.h" #include "serial.h" #include "main.h" #include "attribute.h" #ifndef WIN32 #include #include #include #endif /* !WIN32 */ #include #include #include #include #ifdef HAVE_UU_LOCK #include #endif #include "nut_stdint.h" static unsigned int comm_failures = 0; static void ser_open_error(const char *port) __attribute__((noreturn)); static void ser_open_error(const char *port) { struct stat fs; #ifndef WIN32 struct passwd *user; struct group *group; #endif /* !WIN32 */ printf("\n"); printf("Unable to open %s: %s\n\n", port, strerror(errno)); /* check for bad port definitions first */ if (stat(port, &fs)) { printf("Things to try:\n\n"); printf(" - Check 'port=' in ups.conf\n\n"); printf(" - Check owner/permissions of all parts of path\n\n"); fatalx(EXIT_FAILURE, "Fatal error: unusable configuration"); } /* TODO NUT_WIN32_INCOMPLETE? */ #ifndef WIN32 user = getpwuid(getuid()); if (user) printf(" Current user id: %s (%d)\n", user->pw_name, (int) user->pw_uid); user = getpwuid(fs.st_uid); if (user) printf("Serial port owner: %s (%d)\n", user->pw_name, (int) fs.st_uid); group = getgrgid(fs.st_gid); if (group) printf("Serial port group: %s (%d)\n", group->gr_name, (int) fs.st_gid); #endif /* !WIN32 */ printf(" Mode of port: %04o\n\n", (unsigned int) fs.st_mode & 07777); printf("Things to try:\n\n"); printf(" - Use another port (with the right permissions)\n\n"); printf(" - Fix the port owner/group or permissions on this port\n\n"); printf(" - Run this driver as another user (upsdrvctl -u or 'user=...' in ups.conf).\n"); printf(" See upsdrvctl(8) and ups.conf(5).\n\n"); fatalx(EXIT_FAILURE, "Fatal error: unusable configuration"); } static void lock_set(TYPE_FD_SER fd, const char *port) { int ret; if (INVALID_FD_SER(fd)) { #ifndef WIN32 fatal_with_errno(EXIT_FAILURE, "lock_set: programming error: fd = %d", fd); #else /* WIN32 */ fatal_with_errno(EXIT_FAILURE, "lock_set: programming error: struct = %p", fd); #endif /* WIN32 */ } if (do_lock_port == 0) return; #ifdef HAVE_UU_LOCK ret = uu_lock(xbasename(port)); if (ret != 0) fatalx(EXIT_FAILURE, "Can't uu_lock %s: %s", xbasename(port), uu_lockerr(ret)); #elif defined(HAVE_FLOCK) ret = flock(fd, LOCK_EX | LOCK_NB); if (ret != 0) fatalx(EXIT_FAILURE, "%s is locked by another process", port); #elif defined(HAVE_LOCKF) lseek(fd, 0L, SEEK_SET); ret = lockf(fd, F_TLOCK, 0L); if (ret != 0) fatalx(EXIT_FAILURE, "%s is locked by another process", port); #else NUT_UNUSED_VARIABLE(port); ret = 0; /* Make compiler happy */ ret = ret; upslog_with_errno(LOG_WARNING, "Warning: no locking method is available"); #endif } /* Non fatal version of ser_open */ TYPE_FD_SER ser_open_nf(const char *port) { TYPE_FD_SER fd; fd = open(port, O_RDWR | O_NOCTTY | O_EXCL | O_NONBLOCK); if (INVALID_FD_SER(fd)) { return ERROR_FD_SER; } lock_set(fd, port); return fd; } TYPE_FD_SER ser_open(const char *port) { TYPE_FD_SER res; res = ser_open_nf(port); if (INVALID_FD_SER(res)) { ser_open_error(port); } return res; } int ser_set_speed_nf(TYPE_FD_SER fd, const char *port, speed_t speed) { struct termios tio; NUT_UNUSED_VARIABLE(port); if (tcgetattr(fd, &tio) != 0) { return -1; } tio.c_cflag = CS8 | CLOCAL | CREAD; tio.c_iflag = IGNPAR; tio.c_oflag = 0; tio.c_lflag = 0; tio.c_cc[VMIN] = 1; tio.c_cc[VTIME] = 0; #ifdef HAVE_CFSETISPEED cfsetispeed(&tio, speed); cfsetospeed(&tio, speed); #else #error This system lacks cfsetispeed() and has no other means to set the speed #endif tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &tio); return 0; } int ser_set_speed(TYPE_FD_SER fd, const char *port, speed_t speed) { int res; res = ser_set_speed_nf(fd,port,speed); if(res == -1) { fatal_with_errno(EXIT_FAILURE, "tcgetattr(%s)", port); } return 0; } #ifndef WIN32 static int ser_set_control(TYPE_FD_SER fd, int line, int state) { if (state) { return ioctl(fd, TIOCMBIS, &line); } else { return ioctl(fd, TIOCMBIC, &line); } } #endif /* !WIN32 */ int ser_set_dtr(TYPE_FD_SER fd, int state) { #ifndef WIN32 return ser_set_control(fd, TIOCM_DTR, state); #else /* WIN32 */ DWORD action; if (state == 0) { action = CLRDTR; } else { action = SETDTR; } /* Success */ if (EscapeCommFunction(fd->handle,action) != 0) { return 0; } return -1; #endif /* WIN32 */ } int ser_set_rts(TYPE_FD_SER fd, int state) { #ifndef WIN32 return ser_set_control(fd, TIOCM_RTS, state); #else /* WIN32 */ DWORD action; if(state == 0) { action = CLRRTS; } else { action = SETRTS; } /* Success */ if( EscapeCommFunction(fd->handle,action) != 0) { return 0; } return -1; #endif /* WIN32 */ } #ifndef WIN32 static int ser_get_control(TYPE_FD_SER fd, int line) { int flags; ioctl(fd, TIOCMGET, &flags); return (flags & line); } #endif /* !WIN32 */ int ser_get_dsr(TYPE_FD_SER fd) { #ifndef WIN32 return ser_get_control(fd, TIOCM_DSR); #else /* WIN32 */ int flags; w32_getcomm(fd->handle, &flags); return (flags & TIOCM_DSR); #endif /* WIN32 */ } int ser_get_cts(TYPE_FD_SER fd) { #ifndef WIN32 return ser_get_control(fd, TIOCM_CTS); #else /* WIN32 */ int flags; w32_getcomm(fd->handle, &flags); return (flags & TIOCM_CTS); #endif /* WIN32 */ } int ser_get_dcd(TYPE_FD_SER fd) { #ifndef WIN32 return ser_get_control(fd, TIOCM_CD); #else /* WIN32 */ int flags; w32_getcomm(fd->handle, &flags); return (flags & TIOCM_CD); #endif /* WIN32 */ } int ser_close(TYPE_FD_SER fd, const char *port) { if (INVALID_FD_SER(fd)) { #ifndef WIN32 fatal_with_errno(EXIT_FAILURE, "ser_close: programming error: fd=%d port=%s", fd, port); #else /* WIN32 */ fatal_with_errno(EXIT_FAILURE, "ser_close: programming error: struct=%p port=%s", fd, port); #endif /* WIN32 */ } if (close(fd) != 0) return -1; #ifdef HAVE_UU_LOCK if (do_lock_port) uu_unlock(xbasename(port)); #endif return 0; } ssize_t ser_send_char(TYPE_FD_SER fd, unsigned char ch) { return ser_send_buf_pace(fd, 0, &ch, 1); } static ssize_t send_formatted(TYPE_FD_SER fd, const char *fmt, va_list va, useconds_t d_usec) { int ret; char buf[LARGEBUF]; #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, technically this one is only used * locally with args whose validity other methods may check */ ret = vsnprintf(buf, sizeof(buf), fmt, va); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif if (ret >= (int)sizeof(buf)) { upslogx(LOG_WARNING, "vsnprintf needed more than %d bytes", (int)sizeof(buf)); } return ser_send_buf_pace(fd, d_usec, buf, strlen(buf)); } /* send the results of the format string with d_usec delay after each char */ ssize_t ser_send_pace(TYPE_FD_SER fd, useconds_t d_usec, const char *fmt, ...) { ssize_t ret; va_list ap; va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used from drivers with * fixed strings (and args). * TODO: Propose a ser_send_pace_dynamic() in case non-static * format strings appear? Currently there are none. */ ret = send_formatted(fd, fmt, ap, d_usec); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); return ret; } /* send the results of the format string with no delay */ ssize_t ser_send(TYPE_FD_SER fd, const char *fmt, ...) { ssize_t ret; va_list ap; va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used from drivers with * fixed strings (and args). * TODO: Propose a ser_send_dynamic() in case non-static * format strings appear? Currently there are none. */ ret = send_formatted(fd, fmt, ap, 0); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); return ret; } /* send buflen bytes from buf with no delay */ ssize_t ser_send_buf(TYPE_FD_SER fd, const void *buf, size_t buflen) { return ser_send_buf_pace(fd, 0, buf, buflen); } /* send buflen bytes from buf with d_usec delay after each char */ ssize_t ser_send_buf_pace(TYPE_FD_SER fd, useconds_t d_usec, const void *buf, size_t buflen) { ssize_t ret = 0; ssize_t sent; const char *data = buf; assert(buflen < SSIZE_MAX); for (sent = 0; sent < (ssize_t)buflen; sent += ret) { /* Conditions above ensure that (buflen - sent) > 0 below */ ret = write(fd, &data[sent], (d_usec == 0) ? (size_t)((ssize_t)buflen - sent) : 1); if (ret < 1) { return ret; } usleep(d_usec); } return sent; } ssize_t ser_get_char(TYPE_FD_SER fd, void *ch, time_t d_sec, useconds_t d_usec) { /* Per standard below, we can cast here, because required ranges are * effectively the same (and signed -1 for suseconds_t), and at most long: * https://pubs.opengroup.org/onlinepubs/009604599/basedefs/sys/types.h.html */ return select_read(fd, ch, 1, d_sec, (suseconds_t)d_usec); } ssize_t ser_get_buf(TYPE_FD_SER fd, void *buf, size_t buflen, time_t d_sec, useconds_t d_usec) { memset(buf, '\0', buflen); return select_read(fd, buf, buflen, d_sec, (suseconds_t)d_usec); } /* keep reading until buflen bytes are received or a timeout occurs */ ssize_t ser_get_buf_len(TYPE_FD_SER fd, void *buf, size_t buflen, time_t d_sec, useconds_t d_usec) { ssize_t ret; ssize_t recv; char *data = buf; assert(buflen < SSIZE_MAX); memset(buf, '\0', buflen); for (recv = 0; recv < (ssize_t)buflen; recv += ret) { ret = select_read(fd, &data[recv], (size_t)((ssize_t)buflen - recv), d_sec, (suseconds_t)d_usec); if (ret < 1) { return ret; } } return recv; } /* reads a line up to , discarding anything else that may follow, with callouts to the handler if anything matches the alertset */ ssize_t ser_get_line_alert(TYPE_FD_SER fd, void *buf, size_t buflen, char endchar, const char *ignset, const char *alertset, void handler(char ch), time_t d_sec, useconds_t d_usec) { ssize_t i, ret; char tmp[64]; char *data = buf; ssize_t count = 0, maxcount; assert(buflen < SSIZE_MAX && buflen > 0); memset(buf, '\0', buflen); maxcount = (ssize_t)buflen - 1; /* for trailing \0 */ while (count < maxcount) { ret = select_read(fd, tmp, sizeof(tmp), d_sec, (suseconds_t)d_usec); if (ret < 1) { return ret; } for (i = 0; i < ret; i++) { if ((count == maxcount) || (tmp[i] == endchar)) { return count; } if (strchr(ignset, tmp[i])) continue; if (strchr(alertset, tmp[i])) { if (handler) handler(tmp[i]); continue; } data[count++] = tmp[i]; } } return count; } /* as above, only with no alertset handling (just a wrapper) */ ssize_t ser_get_line(TYPE_FD_SER fd, void *buf, size_t buflen, char endchar, const char *ignset, time_t d_sec, useconds_t d_usec) { return ser_get_line_alert(fd, buf, buflen, endchar, ignset, "", NULL, d_sec, d_usec); } ssize_t ser_flush_in(TYPE_FD_SER fd, const char *ignset, int verbose) { ssize_t ret, extra = 0; char ch; while ((ret = ser_get_char(fd, &ch, 0, 0)) > 0) { if (strchr(ignset, ch)) continue; extra++; if (verbose == 0) continue; if (isprint((unsigned char)ch & 0xFF)) upslogx(LOG_INFO, "ser_flush_in: read char %c", ch); else upslogx(LOG_INFO, "ser_flush_in: read char 0x%02x", ch); } return extra; } int ser_flush_io(TYPE_FD_SER fd) { return tcflush(fd, TCIOFLUSH); } void ser_comm_fail(const char *fmt, ...) { int ret; char why[SMALLBUF]; va_list ap; /* this means we're probably here because select was interrupted */ if (exit_flag != 0) return; /* ignored, since we're about to exit anyway */ comm_failures++; if ((comm_failures == SER_ERR_LIMIT) || ((comm_failures % SER_ERR_RATE) == 0)) { upslogx(LOG_WARNING, "Warning: excessive comm failures, " "limiting error reporting"); } /* once it's past the limit, only log once every SER_ERR_LIMIT calls */ if ((comm_failures > SER_ERR_LIMIT) && ((comm_failures % SER_ERR_LIMIT) != 0)) return; va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used from drivers with * fixed strings (and args). * TODO: Propose a ser_comm_fail_dynamic() in case non-static * format strings appear? Currently there are none. */ ret = vsnprintf(why, sizeof(why), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif va_end(ap); if ((ret < 1) || (ret >= (int) sizeof(why))) upslogx(LOG_WARNING, "ser_comm_fail: vsnprintf needed " "more than %d bytes", (int)sizeof(why)); upslogx(LOG_WARNING, "Communications with UPS lost: %s", why); } void ser_comm_good(void) { if (comm_failures == 0) return; upslogx(LOG_NOTICE, "Communications with UPS re-established"); comm_failures = 0; } nut-2.8.4/drivers/netvision-mib.c0000644000175000017500000002776015000736161013674 00000000000000/* netvision-mib.c - data to monitor Socomec Sicon UPS equipped * with Netvision WEB/SNMP card/external box with NUT * * Copyright (C) * 2004 Thanos Chatziathanassiou * 2012 Manuel Bouyer * 2015 Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "netvision-mib.h" #define NETVISION_MIB_VERSION "0.45" #define NETVISION_SYSOID ".1.3.6.1.4.1.4555.1.1.1" /* SNMP OIDs set */ #define NETVISION_OID_UPS_MIB ".1.3.6.1.4.1.4555.1.1.1.1" #define NETVISION_OID_UPSIDENTMODEL ".1.3.6.1.4.1.4555.1.1.1.1.1.1.0" #define NETVISION_OID_UPSIDENTFWVERSION ".1.3.6.1.4.1.4555.1.1.1.1.1.2.0" #define NETVISION_OID_UPSIDENTAGENTSWVERSION ".1.3.6.1.4.1.4555.1.1.1.1.1.3.0" #define NETVISION_OID_UPSIDENTUPSSERIALNUMBER ".1.3.6.1.4.1.4555.1.1.1.1.1.4.0" /* UPS Battery */ #define NETVISION_OID_BATTERYSTATUS ".1.3.6.1.4.1.4555.1.1.1.1.2.1.0" static info_lkp_t netvision_batt_info[] = { info_lkp_default(2, ""), /* battery normal */ info_lkp_default(3, "LB"), /* battery low */ info_lkp_default(4, "LB"), /* battery depleted */ info_lkp_default(5, "DISCHRG"), /* battery discharging */ info_lkp_default(6, "RB"), /* battery failure */ info_lkp_sentinel }; /* Battery status: upsAlarmOnBattery */ static info_lkp_t netvision_onbatt_info[] = { info_lkp_default(0, "OL"), /* Online */ info_lkp_default(1, "OB"), /* On battery */ info_lkp_sentinel }; #define NETVISION_OID_SECONDSONBATTERY ".1.3.6.1.4.1.4555.1.1.1.1.2.2.0" #define NETVISION_OID_BATT_RUNTIME_REMAINING ".1.3.6.1.4.1.4555.1.1.1.1.2.3.0" #define NETVISION_OID_BATT_CHARGE ".1.3.6.1.4.1.4555.1.1.1.1.2.4.0" #define NETVISION_OID_BATT_VOLTS ".1.3.6.1.4.1.4555.1.1.1.1.2.5.0" #define NETVISION_OID_INPUT_NUM_LINES ".1.3.6.1.4.1.4555.1.1.1.1.3.1.0" /* 1phase or 3phase UPS input */ #define NETVISION_OID_INPUT_FREQ ".1.3.6.1.4.1.4555.1.1.1.1.3.2.0" #define NETVISION_OID_OUTPUT_NUM_LINES ".1.3.6.1.4.1.4555.1.1.1.1.4.3.0" /* 1phase or 3phase UPS output */ #define NETVISION_OID_OUTPUT_FREQ ".1.3.6.1.4.1.4555.1.1.1.1.4.2.0" #define NETVISION_OID_BYPASS_FREQ ".1.3.6.1.4.1.4555.1.1.1.1.5.1.0" #define NETVISION_OID_BYPASS_NUM_LINES ".1.3.6.1.4.1.4555.1.1.1.1.5.2.0" /* 1phase or 3phase UPS input */ /* three phase ups provide input/output/load for each phase in case of one-phase output, only _P1 should be used */ #define NETVISION_OID_OUT_VOLTAGE_P1 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.2.1" #define NETVISION_OID_OUT_CURRENT_P1 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.3.1" #define NETVISION_OID_OUT_LOAD_PCT_P1 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.4.1" #define NETVISION_OID_IN_VOLTAGE_P1 ".1.3.6.1.4.1.4555.1.1.1.1.3.3.1.5.1" #define NETVISION_OID_IN_CURRENT_P1 ".1.3.6.1.4.1.4555.1.1.1.1.3.3.1.3.1" #define NETVISION_OID_BY_VOLTAGE_P1 ".1.3.6.1.4.1.4555.1.1.1.1.5.3.1.2.1" #define NETVISION_OID_BY_CURRENT_P1 ".1.3.6.1.4.1.4555.1.1.1.1.5.3.1.3.1" #define NETVISION_OID_OUT_VOLTAGE_P2 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.2.2" #define NETVISION_OID_OUT_CURRENT_P2 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.3.2" #define NETVISION_OID_OUT_LOAD_PCT_P2 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.4.2" #define NETVISION_OID_IN_VOLTAGE_P2 ".1.3.6.1.4.1.4555.1.1.1.1.3.3.1.5.2" #define NETVISION_OID_IN_CURRENT_P2 ".1.3.6.1.4.1.4555.1.1.1.1.3.3.1.3.2" #define NETVISION_OID_BY_VOLTAGE_P2 ".1.3.6.1.4.1.4555.1.1.1.1.5.3.1.2.2" #define NETVISION_OID_BY_CURRENT_P2 ".1.3.6.1.4.1.4555.1.1.1.1.5.3.1.3.2" #define NETVISION_OID_OUT_VOLTAGE_P3 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.2.3" #define NETVISION_OID_OUT_CURRENT_P3 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.3.3" #define NETVISION_OID_OUT_LOAD_PCT_P3 ".1.3.6.1.4.1.4555.1.1.1.1.4.4.1.4.3" #define NETVISION_OID_IN_VOLTAGE_P3 ".1.3.6.1.4.1.4555.1.1.1.1.3.3.1.5.3" #define NETVISION_OID_IN_CURRENT_P3 ".1.3.6.1.4.1.4555.1.1.1.1.3.3.1.3.3" #define NETVISION_OID_BY_VOLTAGE_P3 ".1.3.6.1.4.1.4555.1.1.1.1.5.3.1.2.3" #define NETVISION_OID_BY_CURRENT_P3 ".1.3.6.1.4.1.4555.1.1.1.1.5.3.1.3.3" #define NETVISION_OID_OUTPUT_SOURCE ".1.3.6.1.4.1.4555.1.1.1.1.4.1.0" #define NETVISION_OID_CONTROL_STATUS ".1.3.6.1.4.1.4555.1.1.1.1.8.1" #define NETVISION_OID_CONTROL_SHUTDOWN_DELAY ".1.3.6.1.4.1.4555.1.1.1.1.8.2" /* * some of the output sources below are set to empty string; because we * don't know from here if we are online or on batteries. * In this case upsAlarmOnBattery will set the appropriate status. */ static info_lkp_t netvision_output_info[] = { #if 0 /* For reference: from the times before Git until SVN, this mapping * was defined as stashed away in this block of code. It was wrong * at least for MASTERYS 3/3 SYSTEM 60 kVA UPS devices described in * pull request https://github.com/networkupstools/nut/pull/2803 */ info_lkp_default(1, ""), /* output source other */ info_lkp_default(2, ""), /* output source none */ info_lkp_default(3, "OL"), /* output source normal */ info_lkp_default(4, "OL BYPASS"), /* output source bypass */ info_lkp_default(5, "OB"), /* output source battery */ info_lkp_default(6, "OL BOOST"), /* output source booster */ info_lkp_default(7, "OL TRIM"), /* output source reducer */ info_lkp_default(8, "OL"), /* output source standby */ info_lkp_default(9, ""), /* output source ecomode */ #else info_lkp_default(1, ""), /* output source unknown */ info_lkp_default(2, ""), /* output source inverter */ info_lkp_default(3, "OL"), /* output source mains */ info_lkp_default(4, ""), /* output source ecomode */ info_lkp_default(5, "OL BYPASS"), /* output source bypass */ info_lkp_default(6, "OFF"), /* output source standby */ info_lkp_default(7, "OL BYPASS"), /* output source maintenance bypass */ info_lkp_default(8, "OFF"), /* output source off */ info_lkp_default(9, ""), /* output source normal */ #endif info_lkp_sentinel }; /* Snmp2NUT lookup table */ static snmp_info_t netvision_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NETVISION_OID_UPSIDENTAGENTSWVERSION, "SOCOMEC SICON UPS", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, NETVISION_OID_UPSIDENTMODEL, "Generic SNMP UPS", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, NETVISION_OID_UPSIDENTUPSSERIALNUMBER, "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.firmware.aux", ST_FLAG_STRING, SU_INFOSIZE, NETVISION_OID_UPSIDENTFWVERSION, "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, NETVISION_OID_BATTERYSTATUS, "", SU_FLAG_OK | SU_STATUS_BATT, &netvision_batt_info[0]), snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, NETVISION_OID_OUTPUT_SOURCE, "", SU_FLAG_OK | SU_STATUS_PWR, &netvision_output_info[0]), /* upsAlarmOnBattery */ snmp_info_default("ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.4555.1.1.1.1.6.3.2.0", "", SU_FLAG_OK | SU_STATUS_PWR, &netvision_onbatt_info[0]), /* ups load */ snmp_info_default("ups.load", 0, 1, NETVISION_OID_OUT_LOAD_PCT_P1, 0, SU_INPUT_1, NULL), /*ups input,output voltage, output frquency phase 1 */ snmp_info_default("input.phases", 0, 1.0, NETVISION_OID_INPUT_NUM_LINES, NULL, 0, NULL), snmp_info_default("input.frequency", 0, 0.1, NETVISION_OID_INPUT_FREQ, NULL, SU_FLAG_OK, NULL), snmp_info_default("input.voltage", 0, 0.1, NETVISION_OID_IN_VOLTAGE_P1, NULL, SU_INPUT_1, NULL), snmp_info_default("input.current", 0, 0.1, NETVISION_OID_IN_CURRENT_P1, NULL, SU_INPUT_1, NULL), snmp_info_default("input.L1-N.voltage", 0, 0.1, NETVISION_OID_IN_VOLTAGE_P1, NULL, SU_INPUT_3, NULL), snmp_info_default("input.L1.current", 0, 0.1, NETVISION_OID_IN_CURRENT_P1, NULL, SU_INPUT_3, NULL), snmp_info_default("input.L2-N.voltage", 0, 0.1, NETVISION_OID_IN_VOLTAGE_P2, NULL, SU_INPUT_3, NULL), snmp_info_default("input.L2.current", 0, 0.1, NETVISION_OID_IN_CURRENT_P2, NULL, SU_INPUT_3, NULL), snmp_info_default("input.L3-N.voltage", 0, 0.1, NETVISION_OID_IN_VOLTAGE_P3, NULL, SU_INPUT_3, NULL), snmp_info_default("input.L3.current", 0, 0.1, NETVISION_OID_IN_CURRENT_P3, NULL, SU_INPUT_3, NULL), snmp_info_default("output.phases", 0, 1.0, NETVISION_OID_OUTPUT_NUM_LINES, NULL, 0, NULL), snmp_info_default("output.frequency", 0, 0.1, NETVISION_OID_OUTPUT_FREQ, NULL, SU_FLAG_OK, NULL), snmp_info_default("output.voltage", 0, 0.1, NETVISION_OID_OUT_VOLTAGE_P1, NULL, SU_OUTPUT_1, NULL), snmp_info_default("output.current", 0, 0.1, NETVISION_OID_OUT_CURRENT_P1, NULL, SU_OUTPUT_1, NULL), snmp_info_default("output.load", 0, 1.0, NETVISION_OID_OUT_LOAD_PCT_P1, NULL, SU_OUTPUT_1, NULL), snmp_info_default("output.L1-N.voltage", 0, 0.1, NETVISION_OID_OUT_VOLTAGE_P1, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L1.current", 0, 0.1, NETVISION_OID_OUT_CURRENT_P1, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L1.power.percent", 0, 1.0, NETVISION_OID_OUT_LOAD_PCT_P1, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L2-N.voltage", 0, 0.1, NETVISION_OID_OUT_VOLTAGE_P2, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L2.current", 0, 0.1, NETVISION_OID_OUT_CURRENT_P2, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L2.power.percent", 0, 1.0, NETVISION_OID_OUT_LOAD_PCT_P2, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L3-N.voltage", 0, 0.1, NETVISION_OID_OUT_VOLTAGE_P3, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L3.current", 0, 0.1, NETVISION_OID_OUT_CURRENT_P3, NULL, SU_OUTPUT_3, NULL), snmp_info_default("output.L3.power.percent", 0, 1.0, NETVISION_OID_OUT_LOAD_PCT_P3, NULL, SU_OUTPUT_3, NULL), snmp_info_default("input.bypass.phases", 0, 1.0, NETVISION_OID_BYPASS_NUM_LINES, NULL, 0, NULL), snmp_info_default("input.bypass.frequency", 0, 0.1, NETVISION_OID_BYPASS_FREQ, NULL, SU_FLAG_OK, NULL), snmp_info_default("input.bypass.voltage", 0, 0.1, NETVISION_OID_BY_VOLTAGE_P1, NULL, SU_BYPASS_1, NULL), snmp_info_default("input.bypass.current", 0, 0.1, NETVISION_OID_BY_CURRENT_P1, NULL, SU_BYPASS_1, NULL), snmp_info_default("input.bypass.L1-N.voltage", 0, 0.1, NETVISION_OID_BY_VOLTAGE_P1, NULL, SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L1.current", 0, 0.1, NETVISION_OID_BY_CURRENT_P1, NULL, SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L2-N.voltage", 0, 0.1, NETVISION_OID_BY_VOLTAGE_P2, NULL, SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L2.current", 0, 0.1, NETVISION_OID_BY_CURRENT_P2, NULL, SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L3-N.voltage", 0, 0.1, NETVISION_OID_BY_VOLTAGE_P3, NULL, SU_BYPASS_3, NULL), snmp_info_default("input.bypass.L3.current", 0, 0.1, NETVISION_OID_BY_CURRENT_P3, NULL, SU_BYPASS_3, NULL), /* battery info */ snmp_info_default("battery.charge", 0, 1, NETVISION_OID_BATT_CHARGE, "", SU_FLAG_OK, NULL), snmp_info_default("battery.voltage", 0, 0.1, NETVISION_OID_BATT_VOLTS, "", SU_FLAG_OK, NULL), snmp_info_default("battery.runtime", 0, 60, NETVISION_OID_BATT_RUNTIME_REMAINING, "", SU_FLAG_OK, NULL), /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t netvision = { "netvision", NETVISION_MIB_VERSION, NULL, NETVISION_OID_UPSIDENTMODEL, netvision_mib, NETVISION_SYSOID, NULL }; nut-2.8.4/drivers/rhino.c0000644000175000017500000004711115044656702012232 00000000000000/* rhino.c - driver for Microsol Rhino UPS hardware Copyright (C) 2004 Silvino B. Magalhães This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2004/11/13 - Version 0.10 - Initial release 2005/07/07 - Version 0.20 - Initial rhino commands tests 2005/10/25 - Version 0.30 - Operational-1 release 2005/10/26 - Version 0.40 - Operational-2 release 2005/11/29 - Version 0.50 - rhino commands release http://www.microsol.com.br */ #include "config.h" /* must be the first header */ #include #include "main.h" #include "serial.h" #include "nut_float.h" #include "nut_stdint.h" #include "timehead.h" #define DRIVER_NAME "Microsol Rhino UPS driver" #define DRIVER_VERSION "0.56" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Silvino B. Magalhaes ", DRV_STABLE, { NULL } }; #define UPSDELAY 500 /* 0.5 ms delay */ typedef int bool_t; #define false 0 #define true 1 /* rhino commands */ #define CMD_INON 0x0001 #define CMD_INOFF 0x0002 #define CMD_SHUT 0x0004 #define CMD_OUTON 0x0003 #define CMD_OUTOFF 0x0004 #define CMD_PASSON 0x0005 #define CMD_PASSOFF 0x0006 #define CMD_UPSCONT 0x0053 /* xoff - xon protocol */ #define _SOH = 0x01; /* start of header */ #define _EOT = 0x04; /* end of transmission */ #define _ACK = 0x06; /* acknoledge (positive) */ #define _DLE = 0x10; /* data link escape */ #define _XOn = 0x11; /* transmit on */ #define _XOff = 0x13; /* transmit off */ #define _NAK = 0x15; /* negative acknoledge */ #define _SYN = 0x16; /* synchronous idle */ #define _CAN = 0x18; /* cancel */ static int const pacsize = 37; /* size of receive data package */ /* autonomy calcule */ static double const AmpH = 40; /* Amperes-hora da bateria */ static double const VbatMin = 126; /* Tensão mínina das baterias */ static double const VbatNom = 144; /* Tensão nominal das baterias */ static double const FM = 0.32; /* Fator multiplicativo de correção da autonomia */ static double const FA = -2; /* Fator aditivo de correção da autonomia */ static double const ConstInt = 250; /* Consumo interno sem o carregador */ static double const Vin = 220; /* Tensão de entrada */ static int Day, Month, Year; static int dian=0, mesn=0, anon=0, weekn=0; static int ihour,imin, isec; /* unsigned char DaysOnWeek; */ /* char seman[4]; */ /* int FExpansaoBateria; */ /* internal variables */ /* package handshake variables */ /* int ContadorEstouro; */ static bool_t detected; static bool_t SourceFail, Out110, RedeAnterior, OcorrenciaDeFalha; static bool_t RetornoDaRede, SuperAquecimento, SuperAquecimentoAnterior; static bool_t OverCharge, OldOverCharge, CriticBatt, OldCritBatt; static bool_t Flag_inversor, BypassOn, InputOn, OutputOn; static bool_t LowBatt, oldInversorOn; /* data vetor from received and configuration data package - not used yet unsigned char Dados[ 161 ]; */ /* identification group */ static int RhinoModel; /*, imodel; */ static int PotenciaNominal, PowerFactor; /* input group */ static double AppPowerIn, UtilPowerIn, InFreq, InCurrent; static double LimInfEntrada, LimSupEntrada, ValorNominalEntrada; static int FatorPotEntrada; /* output group */ static double OutVoltage, InVoltage, OutCurrent, AppPowerOut; static double UtilPowerOut, OutFreq, LimInfSaida, LimSupSaida, ValorNominalSaida; static int FatorPotSaida; /* battery group */ static int Autonomy, Waiting; static double BattVoltage, Temperature, LimInfBattSrc, LimSupBattSrc; static double LimInfBattInv, LimSupBattInv, BattNonValue; /* general group */ static int BoostVolt, Rendimento; /* status group */ static unsigned char StatusEntrada, StatusSaida, StatusBateria; /* events group */ static unsigned char EventosRede, EventosSaida, EventosBateria; /* Grupo de Programação */ /* Methods */ static void ScanReceivePack(void); static int AutonomyCalc( int ); static void CommReceive(const unsigned char*, ssize_t); static void getbaseinfo(void); static void getupdateinfo(void); static unsigned char RecPack[37]; /* comment on english language */ /* #define PORTUGUESE */ /* The following Portuguese strings are in UTF-8. */ #ifdef PORTUGUESE #define M_UNKN "Modêlo rhino desconhecido\n" #define NO_RHINO "Rhino não detectado! abortando ...\n" #define UPS_DATE "Data no UPS %4d/%02d/%02d\n" #define SYS_DATE "Data do Sistema %4d/%02d/%02d dia da semana %s\n" #define ERR_PACK "Pacote errado\n" #define NO_EVENT "Não há eventos\n" #define UPS_TIME "Hora interna UPS %0d:%02d:%02d\n" #else #define M_UNKN "Unknown rhino model\n" #define NO_RHINO "Rhino not detected! aborting ...\n" #define UPS_DATE "UPS Date %4d/%02d/%02d\n" #define SYS_DATE "System Date %4d/%02d/%02d day of week %s\n" #define ERR_PACK "Wrong package\n" #define NO_EVENT "No events\n" #define UPS_TIME "UPS internal Time %0d:%02d:%02d\n" #endif static int AutonomyCalc( int ia ) /* all models */ { int result = 0; double auton, calc, currin; if( ia ) { if( d_equal(BattVoltage, 0) ) result = 0; else { calc = ( OutVoltage * OutCurrent )* 1.0 / ( 0.08 * BattVoltage ); auton = pow( calc, 1.18 ); if( d_equal(auton, 0) ) result = 0; else { auton = 1.0 / auton; auton = auton * 11.07; calc = ( BattVoltage * 1.0 / 10 ) - 168; result = (int) ( auton * calc * 2.5 ); } } } else { currin = ( UtilPowerOut + ConstInt ) *1.0 / Vin; auton = ( ( ( AmpH *1.0 / currin ) * 60 * ( ( BattVoltage - VbatMin ) * 1.0 /( VbatNom - VbatMin ) ) * FM ) + FA ); if( ( BattVoltage > 129 ) && ( BattVoltage < 144 ) ) result = 133; else result = (int) auton; } return result; } /* Treat received package */ static void ScanReceivePack( void ) { /* model independent data */ Year = RecPack[31] + ( RecPack[32] * 100 ); Month = RecPack[30]; Day = RecPack[29]; /* UPS internal time */ ihour = RecPack[26]; imin = RecPack[27]; isec = RecPack[28]; /* Flag1 */ /* SobreTemp = ( ( 0x01 & RecPack[33]) = 0x01 ); */ /* OutputOn = ( ( 0x02 & RecPack[33]) = 0x02 ); OutputOn */ /* InputOn = ( ( 0x04 & RecPack[33]) = 0x04 ); InputOn */ /* ByPassOn = ( ( 0x08 & RecPack[33]) = 0x08 ); BypassOn */ /* Auto_HAB = ( ( 0x10 & RecPack[33]) = 0x10 ); */ /* Timer_HAB = ( ( 0x20 & RecPack[33]) = 0x20 ); */ /* Boost_Ligado = ( ( 0x40 & RecPack[33]) = 0x40 ); */ /* Bateria_Desc = ( ( 0x80 & RecPack[33]) = 0x80 ); */ /* Flag2 */ /* Quad_Ant_Ent = ( ( 0x01 & RecPack[34]) = 0x01 ); */ /* Quadratura = ( ( 0x02 & RecPack[34]) = 0x02 ); */ /* Termino_XMODEM = ( ( 0x04 & RecPack[34]) = 0x04 ); */ /* Em_Sincronismo = ( ( 0x08 & RecPack[34]) = 0x08 ); */ /* Out110 = ( ( 0x10 & RecPack[34]) = 0x10 ); Out110 */ /* Exec_Beep = ( ( 0x20 & RecPack[34]) = 0x20 ); */ /* LowBatt = ( ( 0x40 & RecPack[34]) = 0x40 ); LowBatt */ /* Boost_Sobre = ( ( 0x80 & RecPack[34]) = 0x80 ); */ /* Flag3 */ /* OverCharge = ( ( 0x01 & RecPack[35]) = 0x01 ); OverCharge */ /* SourceFail = ( ( 0x02 & RecPack[35]) = 0x02 ); SourceFail */ /* RedeAnterior = ( ( 0x04 & RecPack[35]) = 0x04 ); */ /* Cmd_Executado = ( ( 0x08 & RecPack[35]) = 0x08 ); */ /* Exec_Autoteste = ( ( 0x10 & RecPack[35]) = 0x10 ); */ /* Quad_Ant_Sai = ( ( 0x20 & RecPack[35]) = 0x20 ); */ /* ComandoSerial = ( ( 0x40 & RecPack[35]) = 0x40 ); */ /* SobreTensao = ( ( 0x80 & RecPack[35]) = 0x80 ); */ OutputOn = ( ( 0x02 & RecPack[33] ) == 0x02 ); InputOn = ( ( 0x04 & RecPack[33] ) == 0x04 ); BypassOn = ( ( 0x08 & RecPack[33] ) == 0x08 ); Out110 = ( ( 0x10 & RecPack[34] ) == 0x10 ); LowBatt = ( ( 0x40 & RecPack[34] ) == 0x40 ); OverCharge = ( ( 0x01 & RecPack[35] ) == 0x01 ); SourceFail = ( ( 0x02 & RecPack[35] ) == 0x02 ); /* model dependent data read */ PowerFactor = 800; if( RecPack[0] == 0xC2 ) { LimInfBattSrc = 174; LimSupBattSrc = 192;/* 180????? carregador eh 180 (SCOPOS) */ LimInfBattInv = 174; LimSupBattInv = 192;/* 170????? (SCOPOS) */ } else { LimInfBattSrc = 138; LimSupBattSrc = 162;/* 180????? carregador eh 180 (SCOPOS) */ LimInfBattInv = 126; LimSupBattInv = 156;/* 170????? (SCOPOS) */ } BattNonValue = 144; /* VersaoInterna = "R10" + IntToStr( RecPack[1] ); */ InVoltage = RecPack[2]; InCurrent = RecPack[3]; UtilPowerIn = RecPack[4] + RecPack[5] * 256; AppPowerIn = RecPack[6] + RecPack[7] * 256; FatorPotEntrada = RecPack[8]; InFreq = ( RecPack[9] + RecPack[10] * 256 ) * 1.0 / 10; OutVoltage = RecPack[11]; OutCurrent = RecPack[12]; UtilPowerOut = RecPack[13] + RecPack[14] * 256; AppPowerOut = RecPack[15] + RecPack[16] * 256; FatorPotSaida = RecPack[17]; OutFreq = ( RecPack[18] + RecPack[19] * 256 ) * 1.0 / 10; BattVoltage = RecPack[20]; BoostVolt = RecPack[21] + RecPack[22] * 256; Temperature = ( 0x7F & RecPack[23] ); Rendimento = RecPack[24]; /* model independent data */ if( ( BattVoltage < LimInfBattInv ) ) CriticBatt = true; if( BypassOn ) OutVoltage = ( InVoltage * 1.0 / 2 ) + 5; if( SourceFail && RedeAnterior ) /* falha pela primeira vez */ OcorrenciaDeFalha = true; if( !( SourceFail ) && !( RedeAnterior ) ) /* retorno da rede */ RetornoDaRede = true; if( RedeAnterior == !( SourceFail ) ) { RetornoDaRede = false; OcorrenciaDeFalha = false; } RedeAnterior = !( SourceFail ); LimInfSaida = 75; LimSupSaida = 150; ValorNominalSaida = 110; LimInfEntrada = 190; LimSupEntrada = 250; ValorNominalEntrada = 220; if( SourceFail ) { StatusEntrada = 2; RecPack[8] = 200; /* ?????????????????????????????????? */ } else { StatusEntrada = 1; RecPack[8] = 99; /* ??????????????????????????????????? */ } if( OutputOn ) /* Output Status */ StatusSaida = 2; else StatusSaida = 1; if( OverCharge ) StatusSaida = 3; if( CriticBatt ) /* Battery Status */ StatusBateria = 4; else StatusBateria = 1; EventosRede = 0; if( OcorrenciaDeFalha ) EventosRede = 1; if( RetornoDaRede ) EventosRede = 2; /* verify InversorOn */ if( Flag_inversor ) { oldInversorOn = InputOn; Flag_inversor = false; } EventosSaida = 0; if( InputOn && !( oldInversorOn ) ) EventosSaida = 26; if( oldInversorOn && !( InputOn ) ) EventosSaida = 27; oldInversorOn = InputOn; if( SuperAquecimento && !( SuperAquecimentoAnterior ) ) EventosSaida = 12; if( SuperAquecimentoAnterior && !( SuperAquecimento ) ) EventosSaida = 13; SuperAquecimentoAnterior = SuperAquecimento; EventosBateria = 0; OldCritBatt = CriticBatt; if( OverCharge && !( OldOverCharge ) ) EventosSaida = 10; if( OldOverCharge && !( OverCharge ) ) EventosSaida = 11; OldOverCharge = OverCharge; /* autonomy calc. */ if( RecPack[ 0 ] == 0xC2 ) Autonomy = AutonomyCalc( 1 ); else Autonomy = AutonomyCalc( 0 ); } static void CommReceive(const unsigned char *bufptr, ssize_t size) { int i, i_end, CheckSum, chk; if( size == 37 ) Waiting = 0; printf("CommReceive size = %" PRIiSIZE " waiting = %d\n", size, Waiting ); switch( Waiting ) { /* normal package */ case 0: { if( size == 37 ) { i_end = 37; for( i = 0 ; i < i_end ; ++i ) { RecPack[i] = *bufptr; bufptr++; } /* CheckSum verify */ CheckSum = 0; i_end = 36; for( i = 0 ; i < i_end ; ++i ) { chk = RecPack[ i ]; CheckSum = CheckSum + chk; } CheckSum = CheckSum % 256; ser_flush_in(upsfd,"",0); /* clean port */ /* correct package */ if( ( RecPack[0] == 0xC0 || RecPack[0] == 0xC1 || RecPack[0] == 0xC2 || RecPack[0] == 0xC3 ) && ( RecPack[ 36 ] == CheckSum ) ) { if(!(detected)) { RhinoModel = RecPack[0]; detected = true; } switch( RhinoModel ) { case 0xC0: case 0xC1: case 0xC2: case 0xC3: { ScanReceivePack(); break; } default: { printf( M_UNKN ); break; } } } } break; } case 1: { /* dumping package, nothing to do yet */ Waiting = 0; break; } default: break; } Waiting = 0; } static ssize_t send_command( unsigned char cmd ) { static const size_t sizes = 19, iend = 18; size_t i, kount; /*, j, uc; */ unsigned char chk, checksum = 0; ssize_t ret = -1; unsigned char ch, *psend = NULL; if ( !(psend = xmalloc(sizeof(char) * sizes)) ) { upslogx(LOG_ERR, "send_command() failed to allocate buffer"); return -1; } /* mounting buffer to send */ for(i = 0; i < iend; i++ ) { if ( i == 0 ) chk = 0x01; else { if( i == 1 ) chk = cmd; else chk = 0x00; /* 0x20; */ } ch = chk; psend[i] = ch; /* psend[0 - 17] */ if( i > 0 ) /* psend[0] not computed */ checksum = checksum + chk; } ch = checksum; ch = (~( ch) ); /* not ch */ psend[iend] = ch; /* send five times the command */ kount = 0; while ( kount < 5 ) { /* ret = ser_send_buf_pace(upsfd, UPSDELAY, psend, sizes ); */ /* optional delay */ for(i = 0 ; i < sizes ; i++) { ret = ser_send_char( upsfd, psend[i] ); /* usleep ( UPSDELAY ); sending without delay */ } usleep( UPSDELAY ); /* delay between sent command */ kount++; } free (psend); return ret; } static void sendshut( void ) { int i; for(i=0; i < 30000; i++) usleep( UPSDELAY ); /* 15 seconds delay */ if ( send_command( CMD_SHUT ) < 1 ) upslogx(LOG_ERR, "Ups shutdown command sending failed"); else upslogx(LOG_NOTICE, "Ups shutdown command sent"); printf("Ups shutdown command sent\n"); } static void getbaseinfo(void) { unsigned char temp[256]; unsigned char Pacote[37]; ssize_t tam, i, j=0; time_t tmt; struct tm *now; struct tm tmbuf; const char *Model; time( &tmt ); now = localtime_r( &tmt, &tmbuf ); dian = now->tm_mday; mesn = now->tm_mon+1; anon = now->tm_year+1900; weekn = now->tm_wday; /* trying detect rhino model */ while ( ( !detected ) && ( j < 10 ) ) { temp[0] = 0; /* flush temp buffer */ tam = ser_get_buf_len(upsfd, temp, pacsize, 3, 0); if( tam == 37 ) { for( i = 0 ; i < tam ; i++ ) { Pacote[i] = temp[i]; } } j++; if( tam == 37) CommReceive(Pacote, tam); else CommReceive(temp, tam); } if( (!detected) ) { fatalx(EXIT_FAILURE, NO_RHINO ); } switch( RhinoModel ) { case 0xC0: { Model = "Rhino 20.0 kVA"; PotenciaNominal = 20000; break; } case 0xC1: { Model = "Rhino 10.0 kVA"; PotenciaNominal = 10000; break; } case 0xC2: { Model = "Rhino 6.0 kVA"; PotenciaNominal = 6000; break; } case 0xC3: { Model = "Rhino 7.5 kVA"; PotenciaNominal = 7500; break; } default: { Model = "Rhino unknown model"; PotenciaNominal = 0; break; } } /* manufacturer and model */ dstate_setinfo("ups.mfr", "%s", "Microsol"); dstate_setinfo("ups.model", "%s", Model); /* dstate_setinfo("input.transfer.low", "%03.1f", InDownLim); LimInfBattInv ? dstate_setinfo("input.transfer.high", "%03.1f", InUpLim); LimSupBattInv ? */ dstate_addcmd("shutdown.stayoff"); /* CMD_SHUT */ /* there is no reserved words for CMD_INON and CMD_INOFF yet */ /* dstate_addcmd("input.on"); */ /* CMD_INON = 1 */ /* dstate_addcmd("input.off"); */ /* CMD_INOFF = 2 */ dstate_addcmd("load.on"); /* CMD_OUTON = 3 */ dstate_addcmd("load.off"); /* CMD_OUTOFF = 4 */ dstate_addcmd("bypass.start"); /* CMD_PASSON = 5 */ dstate_addcmd("bypass.stop"); /* CMD_PASSOFF = 6 */ printf("Detected %s on %s\n", dstate_getinfo("ups.model"), device_path); } static void getupdateinfo(void) { unsigned char temp[256]; ssize_t tam; temp[0] = 0; /* flush temp buffer */ tam = ser_get_buf_len(upsfd, temp, pacsize, 3, 0); CommReceive(temp, tam); } static int instcmd(const char *cmdname, const char *extra) { ssize_t ret = 0; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "shutdown.stayoff")) { /* shutdown now (one way) */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* send_command( CMD_SHUT ); */ sendshut(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.on")) { /* liga Saida */ upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ret = send_command( 3 ); if ( ret < 1 ) upslogx(LOG_ERR, "send_command 3 failed"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.off")) { /* desliga Saida */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ret = send_command( 4 ); if ( ret < 1 ) upslogx(LOG_ERR, "send_command 4 failed"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "bypass.start")) { /* liga Bypass */ upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ret = send_command( 5 ); if ( ret < 1 ) upslogx(LOG_ERR, "send_command 5 failed"); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "bypass.stop")) { /* desliga Bypass */ upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ret = send_command( 6 ); if ( ret < 1 ) upslogx(LOG_ERR, "send_command 6 failed"); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_initinfo(void) { getbaseinfo(); upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { getupdateinfo(); /* new package for updates */ dstate_setinfo("output.voltage", "%03.1f", OutVoltage); dstate_setinfo("input.voltage", "%03.1f", InVoltage); dstate_setinfo("battery.voltage", "%02.1f", BattVoltage); /* output and bypass tests */ if( OutputOn ) dstate_setinfo("outlet.switchable", "%s", "yes"); else dstate_setinfo("outlet.switchable", "%s", "no"); if( BypassOn ) dstate_setinfo("outlet.1.switchable", "%s", "yes"); else dstate_setinfo("outlet.1.switchable", "%s", "no"); status_init(); if (!SourceFail ) status_set("OL"); /* on line */ else status_set("OB"); /* on battery */ if (Autonomy < 5 ) status_set("LB"); /* low battery */ status_commit(); dstate_setinfo("ups.temperature", "%2.2f", Temperature); dstate_setinfo("input.frequency", "%2.1f", InFreq); dstate_dataok(); } /* power down the attached load immediately */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* basic idea: find out line status and send appropriate command */ /* on line: send normal shutdown, ups will return by itself on utility */ /* on battery: send shutdown+return, ups will cycle and return soon */ if (!SourceFail) /* on line */ { /* FIXME: Both legs of the if-clause send CMD_SHUT, * where is the "forcing"? */ printf("On line, forcing shutdown command...\n"); /* send_command( CMD_SHUT ); */ sendshut(); } else { printf("On battery, sending normal shutdown command...\n"); /* send_command( CMD_SHUT ); */ sendshut(); } } void upsdrv_help(void) { } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "battext", "Battery Extension (0-80)min"); } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B19200); /* dtr and rts setting */ ser_set_dtr(upsfd, 1); ser_set_rts(upsfd, 0); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/eaton-ats16-nm2-mib.h0000644000175000017500000000216314670526611014416 00000000000000/* eaton_ats16-nm2-mib.h - subdriver to monitor Eaton ATS16 NM2 SNMP devices with NUT * * Copyright (C) * 2011-2012 Arnaud Quette * 2016-2017 Eaton (author: Arnaud Quette ) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef EATON_ATS16_NM2_MIB_H #define EATON_ATS16_NM2_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t eaton_ats16_nm2; #endif /* EATON_ATS16_NM2_MIB_H */ nut-2.8.4/drivers/common_voltronic-crc.c0000644000175000017500000001722015044656702015245 00000000000000/* common_voltronic-crc.c - Common CRC routines for Voltronic Power devices * * Copyright (C) * 2014 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "common.h" #include "common_voltronic-crc.h" /* CRC table - filled at runtime by common_voltronic_crc_init() */ static unsigned short crc_table[256]; /* Flag (0/1) just to be sure all is properly initialized */ static int initialized = 0; /* Fill CRC table: this function MUST be called before anything else that needs to perform CRC operations */ static void common_voltronic_crc_init(void) { unsigned short dividend; /* Already been here */ if (initialized) return; /* Compute remainder of each possible dividend */ for (dividend = 0; dividend < 256; dividend++) { unsigned short bit; /* Start with dividend followed by zeros */ unsigned long remainder = dividend << 8; /* Modulo 2 division, a bit at a time */ for (bit = 0; bit < 8; bit++) /* Try to divide the current data bit */ if (remainder & 0x8000) remainder = (remainder << 1) ^ 0x1021; else remainder <<= 1; /* Store the result into the table */ crc_table[dividend] = remainder & 0xffff; } /* Ready, now */ initialized = 1; } /* See header file for details */ unsigned short common_voltronic_crc_compute(const char *input, const size_t len) { unsigned short crc, crc_MSB, crc_LSB; unsigned long remainder = 0; size_t byte; /* Make sure all is ready */ if (!initialized) common_voltronic_crc_init(); /* Divide *input* by the polynomial, a byte at a time */ for (byte = 0; byte < len; byte++) remainder = (remainder << 8) ^ crc_table[(input[byte] ^ (remainder >> 8)) & 0xff]; /* The final remainder is the CRC */ crc = remainder & 0xffff; /* Escape characters with a special meaning */ crc_MSB = (crc >> 8) & 0xff; if ( crc_MSB == 10 || /* LF */ crc_MSB == 13 || /* CR */ crc_MSB == 40 /* ( */ ) crc_MSB++; crc_LSB = crc & 0xff; if ( crc_LSB == 10 || /* LF */ crc_LSB == 13 || /* CR */ crc_LSB == 40 /* ( */ ) crc_LSB++; crc = ((crc_MSB & 0xff) << 8) + crc_LSB; return crc; } /* See header file for details */ unsigned short common_voltronic_crc_calc(const char *input, const size_t inputlen) { size_t len; char *cr = memchr(input, '\r', inputlen); /* No CR, fall back to string length (and hope *input* doesn't contain inner '\0's) */ if (cr == NULL) len = strlen(input); else len = cr - input; /* At least 1 byte expected */ if (!len) return -1; /* Compute (and return) CRC */ return common_voltronic_crc_compute(input, len); } /* See header file for details */ int common_voltronic_crc_calc_and_add(const char *input, const size_t inputlen, char *output, const size_t outputlen) { unsigned short crc, crc_MSB, crc_LSB; size_t len; char *cr = memchr(input, '\r', inputlen); /* No CR, fall back to string length (and hope *input* doesn't contain inner '\0's) */ if (cr == NULL) len = strlen(input); else len = cr - input; /* At least 1 byte expected */ if (!len) return -1; /* To accomodate CRC, *output* must have space for at least 2 bytes more than the actually used size of *input*. * Also, pretend that *input* is a valid null-terminated string and so reserve the final byte in *output* for the terminating '\0'. */ if ( (cr == NULL && outputlen < len + 3) || /* 2-bytes CRC + 1 byte for terminating '\0' */ (cr != NULL && outputlen < len + 4) /* 2-bytes CRC + 1 byte for trailing CR + 1 byte for terminating '\0' */ ) return -1; /* Compute CRC */ crc = common_voltronic_crc_compute(input, len); crc_MSB = (crc >> 8) & 0xff; crc_LSB = crc & 0xff; /* Clear *output* */ memset(output, 0, outputlen); /* Copy *input* to *output* */ memcpy(output, input, len); /* Write CRC to *output* */ output[len++] = crc_MSB; output[len++] = crc_LSB; /* Reinstate the trailing CR in *output*, if appropriate */ if (cr != NULL) output[len++] = '\r'; return (int)len; } /* See header file for details */ int common_voltronic_crc_calc_and_add_m(char *input, const size_t inputlen) { int len; char *buf = xcalloc(inputlen, sizeof(char)); if (!buf) return -1; /* Compute CRC and copy *input*, with CRC added to it, to buf */ len = common_voltronic_crc_calc_and_add(input, inputlen, buf, inputlen); /* Failed */ if (len == -1) { free(buf); return -1; } /* Successfully computed CRC and copied *input*, with CRC added to it, to buf */ /* Clear *input* */ memset(input, 0, inputlen); /* Copy back buf to *input* */ memcpy(input, buf, len); free(buf); return len; } /* See header file for details */ int common_voltronic_crc_check(const char *input, const size_t inputlen) { unsigned short crc, crc_MSB, crc_LSB; char *cr = memchr(input, '\r', inputlen); size_t len; /* No CR, fall back to string length (and hope *input* doesn't contain inner '\0's) */ if (cr == NULL) len = strlen(input); else len = cr - input; /* Minimum length: 1 byte + 2 bytes CRC -> 3 */ if (len < 3) return -1; /* Compute CRC */ crc = common_voltronic_crc_compute(input, len - 2); crc_MSB = (crc >> 8) & 0xff; crc_LSB = crc & 0xff; /* Fail */ if ( crc_MSB != (unsigned char)input[len - 2] || crc_LSB != (unsigned char)input[len - 1] ) return -1; /* Success */ return 0; } /* See header file for details */ int common_voltronic_crc_check_and_remove(const char *input, const size_t inputlen, char *output, const size_t outputlen) { char *cr; size_t len; /* Failed to check *input* CRC */ if (common_voltronic_crc_check(input, inputlen)) return -1; /* *input* successfully validated -> remove CRC bytes */ cr = memchr(input, '\r', inputlen); /* No CR, fall back to string length */ if (cr == NULL) len = strlen(input); else len = cr - input; /* *output* must have space for at least 2 bytes less than the actually used size of *input*. * Also, pretend that *input* is a valid null-terminated string and so reserve the final byte in *output* for the terminating '\0'. */ len -= 2; /* Consider 2-bytes CRC length */ if ( (cr == NULL && outputlen < len + 1) || /* 1 byte for terminating '\0' */ (cr != NULL && outputlen < len + 2) /* 1 byte for terminating '\0' + 1 byte for trailing CR; 2-byte CRC */ ) return -1; /* Clear *output* */ memset(output, 0, outputlen); /* Copy *input* to *output* */ memcpy(output, input, len); /* Reinstate the trailing CR in *output*, if appropriate */ if (cr != NULL) output[len++] = '\r'; return (int)len; } /* See header file for details */ int common_voltronic_crc_check_and_remove_m(char *input, const size_t inputlen) { int len; char *buf = xcalloc(inputlen, sizeof(char)); if (!buf) return -1; /* Check CRC and copy *input*, purged of the CRC, to buf */ len = common_voltronic_crc_check_and_remove(input, inputlen, buf, inputlen); /* Failed */ if (len == -1) { free(buf); return -1; } /* Successfully checked CRC and copied *input*, purged of the CRC, to buf */ /* Clear *input* */ memset(input, 0, inputlen); /* Copy back buf to *input* */ memcpy(input, buf, len); free(buf); return len; } nut-2.8.4/drivers/safenet.h0000644000175000017500000000440014670526611012536 00000000000000/* * safenet.h - defines/macros for the safenet driver * * Copyright (C) 2003 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_SAFENET_H_SEEN #define NUT_SAFENET_H_SEEN 1 /* * The following commands where traced on the serial port. From these, the * COM_POLL_STAT command is just an example of how this command looks. * Inside the driver, we'll overwrite the default with specially crafted * 'random' data (see the comments). */ #define COM_INITIALIZE "ZCADLIOPERJD\r" #define COM_MAINS_TEST "ZFSDERBTRFGY\r" #define COM_BATT_TEST "ZAVLEJFICOPR\r" #define COM_STOP_TEST "ZGWLEJFICOPR\r" #define COM_TOGGLE_BEEP "ZELWSABPMBEQ\r" #define COM_POLL_STAT "ZHDGFGDJELBC\r" /* * The following command is "ZBASdddWLPGE\r", where 'ddd' equals the number of * seconds delay before the UPS switches off. Value must be greater than or * equal to 1. Mapping of the numerals is 0=A, 1=B, 2=C, etc. */ #define SHUTDOWN_RETURN "ZBASAAAWLPGE\r" /* shutdown in 1 second */ /* * The following commands are "ZAFdddRrrrrO\r", where 'ddd' equals the number * of seconds delay before the UPS switches off and 'rrrr' the number of * minutes before it restarts. Both values must be greater than or equal to 1. * Mapping of the numerals is 0=A, 1=B, 2=C, etc. */ #define SHUTDOWN_REBOOT "ZAFAAARAAAAO\r" /* shutdown in 1 second, return after 1 minute */ struct safenet { char onbattery; char dunno_02; char batterylow; char overload; char dunno_05; char silenced; char batteryfail; char systemfail; char systemtest; char dunno_10; }; #endif /* NUT_SAFENET_H_SEEN */ nut-2.8.4/drivers/belkinunv.c0000644000175000017500000011154615044656702013114 00000000000000/* belkinunv.c - driver for newer Belkin models, such as "Belkin Universal UPS" (ca. 2003) Copyright (C) 2003 Peter Selinger This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* SOFT SHUTDOWN WORKAROUND One problem with the Belkin Universal UPS is that it cannot enter a soft shutdown (shut down until AC power returns) unless the batteries are completely depleted. Thus, one cannot just shut off the UPS after operating system shutdown; it will not come back on when the power comes back on. The belkinunv driver should never be used with the -k option. Instead, we provide a "standalone" mode for this driver via some -x options, which is intended to be used in startup and shutdown scripts. Please see the belkinunv(8) man page for details. VARIABLES: battery.charge battery.runtime battery.voltage battery.voltage.nominal input.frequency input.frequency.nominal e.g. 60 for 60Hz input.sensitivity (RW) normal/medium/low input.transfer.high (RW) input.transfer.low (RW) input.voltage input.voltage.maximum input.voltage.minimum input.voltage.nominal output.frequency output.voltage ups.beeper.status (RW) enabled/disabled/muted ups.firmware ups.load ups.model ups.power.nominal e.g. 800 for an 800VA system ups.status ups.temperature ups.test.result ups.delay.restart read-only: time to restart ups.delay.shutdown read-only: time to shutdown ups.type ONLINE/OFFLINE/LINEINT COMMANDS: beeper.disable beeper.enable beeper.mute reset.input.minmax shutdown.reboot shut down load immediately for 1-2 minutes shutdown.reboot.graceful shut down load after 40 seconds for 1-2 minutes shutdown.stayoff shut down load immediately and stay off test.battery.start start 10-second battery test test.battery.stop test.failure.start start "deep" battery test test.failure.stop STATUS FLAGS: OB load is on battery, including during tests OFF load is off OL load is online ACFAIL AC failure OVER overload OVERHEAT overheat COMMFAULT UPS Fault LB low battery CHRG charging DEPLETED battery depleted RB replace battery */ #include "main.h" #include "serial.h" #define DRIVER_NAME "Belkin 'Universal UPS' driver" #define DRIVER_VERSION "0.12" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Peter Selinger ", DRV_STABLE, { NULL } }; /* somewhat arbitrary buffer size - the longest actually occuring message is 18 bytes for the F6C800-UNV. But since message length is arbitrary in principle, we allow for some extra bytes. */ #define MAXMSGSIZE 25 /* definitions of register numbers for Belkin UPS */ #define REG_VOLTRATING 0x01 #define REG_FREQRATING 0x02 #define REG_POWERRATING 0x03 #define REG_BATVOLTRATING 0x04 #define REG_XFER_LO 0x06 #define REG_XFER_LO_MAX 0x07 #define REG_XFER_LO_MIN 0x08 #define REG_XFER_HI 0x09 #define REG_XFER_HI_MAX 0x0a #define REG_XFER_HI_MIN 0x0b #define REG_VOLTSENS 0x0c #define REG_UPSMODEL 0x0d #define REG_UPSMODEL2 0x0e #define REG_FIRMWARE 0x0f #define REG_TESTSTATUS 0x10 #define REG_ALARMSTATUS 0x11 #define REG_SHUTDOWNTIMER 0x15 #define REG_RESTARTTIMER 0x16 #define REG_INPUTVOLT 0x18 #define REG_INPUTFREQ 0x19 #define REG_TEMPERATURE 0x1a #define REG_OUTPUTVOLT 0x1b #define REG_OUTPUTFREQ 0x1c #define REG_LOAD 0x1e #define REG_BATSTAT2 0x1f #define REG_BATVOLT 0x20 #define REG_BATLEVEL 0x21 #define REG_UPSSTATUS 0x22 #define REG_BATSTATUS 0x23 #define REG_TIMELEFT 0x3f /* flags for REG_UPSSTATUS */ #define US_ACFAILURE 0x0001 #define US_OVERLOAD 0x0010 #define US_OFF 0x0020 #define US_OVERHEAT 0x0040 #define US_UPSFAULT 0x0080 #define US_WAITING 0x2000 #define US_BUZZER 0x8000 /* flags for REG_BATSTATUS */ #define BS_LOW 0x04 #define BS_CHARGING 0x10 #define BS_ONBATTERY 0x20 #define BS_DEPLETED 0x40 #define BS_REPLACE 0x80 /* size of an array */ #define asize(x) ((int)(SIZEOF_ARRAY(x))) static const char *upstype[3] = { "ONLINE", "OFFLINE", "LINEINT" }; static const char *voltsens[3] = { "normal", "medium", "low" }; static const char *teststatus[6] = { "no test performed", "test passed", "test failed", "test failed", "test aborted", "test in progress" }; #define ST_OFF 0 #define ST_ONLINE 1 #define ST_BATTERY 2 static const char *status[] = { "UPS is off", /* ST_OFF */ "UPS is on AC power", /* ST_ONLINE */ "UPS is on battery" /* ST_BATTERY */ }; /* some useful strings */ #define ESC "\033" #define COL0 ESC "[G" ESC "[K" /* terminal control: clear line */ static int minutil = -1; static int maxutil = -1; static int xfer_lo_min = -1; static int xfer_lo_max = -1; static int xfer_hi_min = -1; static int xfer_hi_max = -1; int instcmd(const char *cmdname, const char *extra); static int setvar(const char *varname, const char *val); /* ---------------------------------------------------------------------- */ /* a general purpose Belkin-specific function: */ /* calculate a Belkin checksum, i.e., add buf[0]...buf[n-1] */ static unsigned char belkin_checksum(unsigned char *buf, int n) { int i, res; res = 0; for (i=0; i bufsize) { return -1; } r = ser_get_buf_len(upsfd, &buf[0], 1, 3, 0); if (r<0) { upslog_with_errno(LOG_ERR, "Error reading from UPS"); return -1; } else if (r==0) { upslogx(LOG_ERR, "No response from UPS"); return -1; } else if (buf[0]!=0x7e) { upslogx(LOG_ERR, "Garbage read from UPS"); return -1; } n+=r; /* read instruction, size, and register */ if (n+3 > bufsize) { return -1; } r = ser_get_buf_len(upsfd, &buf[1], 3, 3, 0); if (r!=3) { upslogx(LOG_ERR, "Short read from UPS"); return -1; } n+=r; len = buf[2]; /* read data and checksum */ if (n+len > bufsize) { return -1; } /* Casting is okay, len is range-limited to unsigned char */ r = ser_get_buf_len(upsfd, &buf[4], (size_t)len, 3, 0); if (r!=len) { upslogx(LOG_ERR, "Short read from UPS"); return -1; } n+=r; /* check checksum */ if (belkin_checksum(buf, len+3) != buf[len+3]) { upslogx(LOG_ERR, "Bad checksum from UPS"); return -1; } return n; } /* read the value of a string register from UPS. Return NULL on failure, else an allocated string. */ static char *belkin_nut_read_str(unsigned char reg) { unsigned char buf[MAXMSGSIZE]; ssize_t r; size_t len; char *str; /* send the request */ buf[0] = 0x7e; buf[1] = 0x03; buf[2] = 0x02; buf[3] = reg; buf[4] = 0; buf[5] = belkin_checksum(buf, 5); r = ser_send_buf(upsfd, buf, 6); if (r<0) { upslogx(LOG_ERR, "Failed write to UPS"); return NULL; } /* receive the answer */ r = belkin_nut_receive(buf, MAXMSGSIZE); if (r<0) { return NULL; } if ((buf[1]!=0x05 && buf[1]!=0x01) || buf[3] != reg) { upslogx(LOG_ERR, "Invalid response from UPS"); return NULL; } if (buf[1]==0x01) { return NULL; } /* convert the answer to a string */ if (buf[2] < 1) { upslogx(LOG_ERR, "Invalid response from UPS: string too short to be true"); return NULL; } len = buf[2]-1; str = (char *)xmalloc(len+1); memcpy(str, &buf[4], len); str[len]=0; return str; } /* read the value of an integer register from UPS. Return -1 on failure. */ static int belkin_nut_read_int(unsigned char reg) { unsigned char buf[MAXMSGSIZE]; int len; ssize_t r; /* send the request */ buf[0] = 0x7e; buf[1] = 0x03; buf[2] = 0x02; buf[3] = reg; buf[4] = 0; buf[5] = belkin_checksum(buf, 5); r = ser_send_buf(upsfd, buf, 6); if (r<0) { upslogx(LOG_ERR, "Failed write to UPS"); return -1; } /* receive the answer */ r = belkin_nut_receive(buf, MAXMSGSIZE); if (r<0) { return -1; } if ((buf[1]!=0x05 && buf[1]!=0x01) || buf[3] != reg) { upslogx(LOG_ERR, "Invalid response from UPS"); return -1; } if (buf[1]==0x01) { return -1; } /* convert the answer to an integer */ len = buf[2]-1; if (len==1) { return buf[4]; } else if (len==2) { return buf[4] + 256*buf[5]; } else { upslogx(LOG_ERR, "Invalid response from UPS"); return -1; } } /* write the value of an integer register to UPS. Return -1 on failure, else 0 */ static int belkin_nut_write_int(unsigned char reg, int val) { unsigned char buf[MAXMSGSIZE]; ssize_t r; /* send the request */ buf[0] = 0x7e; buf[1] = 0x04; buf[2] = 0x03; buf[3] = reg; buf[4] = val & 0xff; buf[5] = (val>>8) & 0xff; buf[6] = belkin_checksum(buf, 6); r = ser_send_buf(upsfd, buf, 7); if (r<0) { upslogx(LOG_ERR, "Failed write to UPS"); return -1; } /* receive the acknowledgement */ r = belkin_nut_receive(buf, MAXMSGSIZE); if (r<0) { return -1; } if ((buf[1]!=0x02 && buf[1]!=0x01) || buf[3] != reg) { upslogx(LOG_ERR, "Invalid response from UPS"); return -1; } if (buf[1]==0x01) { return -1; } return 0; } /* ---------------------------------------------------------------------- */ /* some private functions for talking to the UPS - "standalone" versions. The functions in this section have _std_ in their name, and they do not use default NUT error handling (this would not be desirable during standalone operation, i.e., when the -x wait option is given). These functions also take an additional file descriptor argument. */ /* Open and prepare a serial port for communication with a Belkin Universal UPS. DEVICE is the name of the serial port. It will be opened in non-blocking read/write mode, and the appropriate communications parameters will be set. The device will also be sent a special signal (clear DTR, set RTS) to cause the UPS to switch from "dumb" to "smart" mode, and any pending data (=garbage) will be discarded. After this call, the device is ready for reading and writing via read(2) and write(2). Return a valid file descriptor on success, or else -1 with errno set. */ static TYPE_FD_SER belkin_std_open_tty(const char *device) { TYPE_FD_SER fd; struct termios tios; #ifndef WIN32 struct flock flock; #endif /* !WIN32 */ char buf[128]; ssize_t r; /* open the device */ fd = open(device, O_RDWR | O_NONBLOCK); if (INVALID_FD_SER(fd)) { return ERROR_FD_SER; } /* set communications parameters: 2400 baud, 8 bits, 1 stop bit, no parity, enable reading, hang up when done, ignore modem control lines. */ memset(&tios, 0, sizeof(tios)); tios.c_cflag = B2400 | CS8 | CREAD | HUPCL | CLOCAL; tios.c_cc[VMIN] = 1; tios.c_cc[VTIME] = 0; r = tcsetattr(fd, TCSANOW, &tios); if (r == -1) { close(fd); return ERROR_FD_SER; } /* signal the UPS to enter "smart" mode. This is done by setting RTS and dropping DTR for at least 0.25 seconds. RTS and DTR refer to two specific pins in the 9-pin serial connector. Note: this must be done for at least 0.25 seconds for the UPS to react. Ignore any errors, as this probably means we are not on a "real" serial port. */ ser_set_dtr(upsfd, 0); ser_set_rts(upsfd, 1); /* flush both directions of serial port: throw away all data in transit */ r = ser_flush_io(fd); if (r == -1) { close(fd); return ERROR_FD_SER; } #ifndef WIN32 /* lock the port */ memset(&flock, 0, sizeof(flock)); flock.l_type = F_RDLCK; r = fcntl(fd, F_SETLK, &flock); if (r == -1) { close(fd); return ERROR_FD_SER; } #else /* WIN32 */ /* TODO: port to WIN32 */ NUT_WIN32_INCOMPLETE_DETAILED("port locking"); #endif /* WIN32 */ /* sleep at least 0.25 seconds for the UPS to wake up. Belkin's own software sleeps 1 second, so that's what we do, too. */ usleep(1000000); /* flush incoming data again, and read any remaining garbage bytes. There should not be any. */ r = tcflush(fd, TCIFLUSH); if (r == -1) { close(fd); return ERROR_FD_SER; } #ifndef WIN32 r = read(fd, buf, 127); #else /* WIN32 */ /* WIN32 : w32_serial_read is blocking, using select_read with 0ms timeout * is non-blocking */ r = select_read(fd, buf, 127, 0, 0); #endif /* WIN32 */ if (r == -1 && errno != EAGAIN) { close(fd); return ERROR_FD_SER; } /* leave port in non-blocking state */ return fd; } /* blocking read with 1-second timeout (use non-blocking i/o) */ static int belkin_std_upsread(TYPE_FD_SER fd, unsigned char *buf, int n) { int count = 0; ssize_t r; int tries = 0; while (count < n) { #ifndef WIN32 r = read(fd, &buf[count], (size_t)(n-count)); #else /* WIN32 */ /* WIN32 : w32_serial_read is blocking, using select_read * with 0ms timeout is non-blocking */ r = select_read(fd, buf, (size_t)(n-count), 0, 0); #endif /* WIN32 */ if (r==-1 && errno==EAGAIN) { /* non-blocking i/o, no data available */ usleep(100000); tries++; } else if (r == -1) { return -1; } else { count += r; } if (tries > 10) { return -1; } } return count; } /* blocking write with 1-second timeout (use non-blocking i/o) */ static int belkin_std_upswrite(TYPE_FD_SER fd, unsigned char *buf, int n) { int count = 0; ssize_t r; int tries = 0; while (count < n) { r = write(fd, &buf[count], (size_t)(n-count)); if (r==-1 && errno==EAGAIN) { /* non-blocking i/o, no data available */ usleep(100000); tries++; } else if (r == -1) { return -1; } else { count += r; } if (tries > 10) { return -1; } } return count; } /* receive Belkin message from UPS, check for well-formedness (leading byte, checksum). Return length of message, or -1 if not well-formed */ static int belkin_std_receive(TYPE_FD_SER fd, unsigned char *buf, int bufsize) { int r; int n=0; int len; /* read 0x7e */ if (n+1 > bufsize) { return -1; } r = belkin_std_upsread(fd, &buf[0], 1); if (r==-1 || buf[0]!=0x7e) { return -1; } n+=r; /* read instruction, size, and register */ if (n+3 > bufsize) { return -1; } r = belkin_std_upsread(fd, &buf[1], 3); if (r!=3) { return -1; } n+=r; len = buf[2]; /* read data and checksum */ if (n+len > bufsize) { return -1; } r = belkin_std_upsread(fd, &buf[4], len); if (r!=len) { return -1; } n+=r; /* check checksum */ if (belkin_checksum(buf, len+3) != buf[len+3]) { return -1; } return n; } /* read the value of an integer register from UPS. Return -1 on failure. */ static int belkin_std_read_int(TYPE_FD_SER fd, unsigned char reg) { unsigned char buf[MAXMSGSIZE]; int len, r; /* send the request */ buf[0] = 0x7e; buf[1] = 0x03; buf[2] = 0x02; buf[3] = reg; buf[4] = 0; buf[5] = belkin_checksum(buf, 5); r = belkin_std_upswrite(fd, buf, 6); if (r<0) { return -1; } /* receive the answer */ r = belkin_std_receive(fd, buf, MAXMSGSIZE); if (r<0) { return -1; } if ((buf[1]!=0x05 && buf[1]!=0x01) || buf[3] != reg) { return -1; } if (buf[1]==0x01) { return -1; } /* convert the answer to an integer */ len = buf[2]-1; if (len==1) { return buf[4]; } else if (len==2) { return buf[4] + 256*buf[5]; } else { return -1; } } /* write the value of an integer register to UPS. Return -1 on failure, else 0 */ static int belkin_std_write_int(TYPE_FD_SER fd, unsigned char reg, int val) { unsigned char buf[MAXMSGSIZE]; int r; /* send the request */ buf[0] = 0x7e; buf[1] = 0x04; buf[2] = 0x03; buf[3] = reg; buf[4] = val & 0xff; buf[5] = (val>>8) & 0xff; buf[6] = belkin_checksum(buf, 6); r = belkin_std_upswrite(fd, buf, 7); if (r<0) { return -1; } /* receive the acknowledgement */ r = belkin_std_receive(fd, buf, MAXMSGSIZE); if (r<0) { return -1; } if ((buf[1]!=0x02 && buf[1]!=0x01) || buf[3] != reg) { return -1; } if (buf[1]==0x01) { return -1; } return 0; } /* ---------------------------------------------------------------------- */ /* "standalone" program executed when driver is called with the '-x wait' or '-x wait=' flag or option */ /* this function updates the status line, as specified by the smode parameter (0=silent, 1=normal, 2=dumbterminal). This is only done if the status has not changed from the previous call */ static void updatestatus(int smode, const char *fmt, ...) { char buf[1024]; /* static string limit is OK */ static char oldbuf[1024] = { 0 }; static int init = 1; va_list ap; if (smode==0) { return; } if (init) { init = 0; oldbuf[0] = 0; } /* read formatted argument string */ va_start(ap, fmt); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic ignored "-Wformat-nonliteral" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_SECURITY #pragma GCC diagnostic ignored "-Wformat-security" #endif /* Note: Not converting to hardened NUT methods with dynamic * format string checking, this one is used locally with * fixed strings (and args) a few times */ vsnprintf(buf, sizeof(buf), fmt, ap); #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_NONLITERAL #pragma GCC diagnostic pop #endif buf[sizeof(buf)-1] = 0; va_end(ap); if (strcmp(oldbuf, buf)==0) { return; } strcpy(oldbuf, buf); if (smode==2) { /* "dumbterm" version just prints a new line each time */ printf("%s\n", buf); } else { /* "normal" version overwrites same line each time */ printf(COL0 "%s", buf); } fflush(stdout); } /* switch from status line display to normal output mode */ static void endstatus(int smode) { if (smode==1) { fprintf(stdout, "\n"); fflush(stdout); } } static int belkin_wait(void) { int level = 0; /* battery level to wait for */ int smode = 1; /* statusline mode: 0=silent, 1=normal, 2=dumbterm */ int nohang = 0; /* nohang flag */ int flash = 0; /* flash flag */ char *val; int failcount = 0; /* count consecutive failed connection attempts */ int failerrno = 0; TYPE_FD_SER fd; int r; int bs, ov, bl, st; /* read command line '-x' options */ val = getval("wait"); if (val) { level = atoi(val); } if (dstate_getinfo("driver.flag.nohang")) { nohang = 1; } if (dstate_getinfo("driver.flag.flash")) { flash = 1; } if (dstate_getinfo("driver.flag.silent")) { smode = 0; } else if (dstate_getinfo("driver.flag.dumbterm")) { smode = 2; } updatestatus(smode, "Connecting to UPS..."); failcount = 0; fd = ERROR_FD_SER; while (1) { if (failcount >= 3 && nohang) { endstatus(smode); printf("UPS is not responding: %s\n", strerror(failerrno)); return 1; } else if (failcount >= 3) { updatestatus(smode, "UPS is not responding, will keep trying: %s", strerror(failerrno)); } if (INVALID_FD_SER(fd)) { fd = belkin_std_open_tty(device_path); } if (INVALID_FD_SER(fd)) { failcount++; failerrno = errno; sleep(1); continue; } /* wait until the UPS is online and the battery level is >= level */ bs = belkin_std_read_int(fd, REG_BATSTATUS); /* battery status */ if (bs==-1) { failcount++; failerrno = errno; close(fd); fd = ERROR_FD_SER; sleep(1); continue; } ov = belkin_std_read_int(fd, REG_OUTPUTVOLT); /* output voltage */ if (ov==-1) { failcount++; failerrno = errno; close(fd); fd = ERROR_FD_SER; sleep(1); continue; } bl = belkin_std_read_int(fd, REG_BATLEVEL); /* battery level */ if (bl==-1) { failcount++; failerrno = errno; close(fd); fd = ERROR_FD_SER; sleep(1); continue; } /* successfully got data from UPS */ failcount = 0; if (bs & BS_ONBATTERY) { st = ST_BATTERY; } else if (ov>0) { st = ST_ONLINE; } else { st = ST_OFF; } updatestatus(smode, "%s, battery level: %d%%", status[st], bl); if (st == ST_ONLINE && bl >= level) { break; } sleep(1); } /* termination condition reached */ endstatus(smode); if (flash) { printf("Interrupting UPS load for ca. 2 minutes.\n"); r = belkin_std_write_int(fd, REG_RESTARTTIMER, 2); if (r==0) { r = belkin_std_write_int(fd, REG_SHUTDOWNTIMER, 1); } if (r) { printf("Timed shutdown operation failed.\n"); close(fd); return 2; } } close(fd); return 0; } /* ---------------------------------------------------------------------- */ /* functions which interface with main.c */ /* read all hardcoded info about this UPS */ void upsdrv_initinfo(void) { char *str; int val; int i; /* read hard-wired values */ val = belkin_nut_read_int(REG_VOLTRATING); if (val!=-1) { dstate_setinfo("input.voltage.nominal", "%d", val); } val = belkin_nut_read_int(REG_FREQRATING); if (val!=-1) { dstate_setinfo("input.frequency.nominal", "%d", val); } val = belkin_nut_read_int(REG_POWERRATING); if (val!=-1) { dstate_setinfo("ups.power.nominal", "%d", val); } val = belkin_nut_read_int(REG_BATVOLTRATING); if (val!=-1) { dstate_setinfo("battery.voltage.nominal", "%d", val); } xfer_lo_max = belkin_nut_read_int(REG_XFER_LO_MAX); xfer_lo_min = belkin_nut_read_int(REG_XFER_LO_MIN); xfer_hi_max = belkin_nut_read_int(REG_XFER_HI_MAX); xfer_hi_min = belkin_nut_read_int(REG_XFER_HI_MIN); str = belkin_nut_read_str(REG_UPSMODEL); if (str) { dstate_setinfo("ups.model", "%s", str); free(str); } val = belkin_nut_read_int(REG_FIRMWARE); if (val!=-1) { dstate_setinfo("ups.firmware", "%d", (val>>4) & 0xf); dstate_setinfo("ups.type", "%s", upstype[(val & 0x0f) % 3]); } /* read writable values and declare them writable */ val = belkin_nut_read_int(REG_VOLTSENS); if (val!=-1) { dstate_setinfo("input.sensitivity", "%s", (val>=0 && val 0) { status_set("OL"); /* online */ } else { status_set("OFF"); /* off */ } if (us & US_ACFAILURE) { status_set("ACFAIL"); /* AC failure, self-invented */ /* Note: this is not the same as "on battery", because this flag makes sense even during a test, or when the load is off. It simply reflects the status of utility power. A "critical" situation should be OB && BL && ACFAIL. */ } if (us & US_OVERLOAD) { status_set("OVER"); /* overload */ } if (us & US_OVERHEAT) { status_set("OVERHEAT"); /* overheat, self-invented */ } if (us & US_UPSFAULT) { status_set("COMMFAULT"); /* UPS Fault */ } if (bs & BS_LOW) { status_set("LB"); /* low battery */ } if (bs & BS_CHARGING) { status_set("CHRG"); /* charging */ } if (bs & BS_DEPLETED) { status_set("DEPLETED"); /* battery depleted, self-invented */ } if (bs & BS_REPLACE) { status_set("RB"); /* replace battery */ } status_commit(); /* new read everything else */ val = belkin_nut_read_int(REG_XFER_LO); if (val!=-1) { dstate_setinfo("input.transfer.low", "%d", val); } val = belkin_nut_read_int(REG_XFER_HI); if (val!=-1) { dstate_setinfo("input.transfer.high", "%d", val); } val = belkin_nut_read_int(REG_VOLTSENS); if (val!=-1) { dstate_setinfo("input.sensitivity", "%s", (val>=0 && val=0 && val0 && (maxutil==-1 || val>maxutil)) { maxutil = val; } if (val>0 && (minutil==-1 || val' */ addvar(VAR_FLAG, "wait", "Wait for AC power "); addvar(VAR_VALUE, "wait", "Wait for AC power and battery level"); /* allow '-x nohang' */ addvar(VAR_FLAG, "nohang", "In wait mode: quit if UPS dead "); /* allow '-x flash' */ addvar(VAR_FLAG, "flash", "In wait mode: do brief shutdown "); /* allow '-x silent' */ addvar(VAR_FLAG, "silent", "In wait mode: suppress status line "); /* allow '-x dumbterm' */ addvar(VAR_FLAG, "dumbterm", "In wait mode: simpler status line "); } /* prep the serial port */ void upsdrv_initups(void) { /* If '-x wait' or '-x wait=' option given, branch into standalone behavior. */ if (getval("wait") || dstate_getinfo("driver.flag.wait")) { exit(belkin_wait()); } belkin_nut_open_tty(); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/apc-epdu-mib.h0000644000175000017500000000200314777753336013367 00000000000000/* apc-epdu-mib.h - subdriver to monitor apc SNMP easy pdu with NUT * * Copyright (C) * 2011 - 2022 Eric Clappier * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef APC_EPDU_MIB_H #define APC_EPDU_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t apc_pdu_epdu; #endif /* APC_EPDU_MIB_H */ nut-2.8.4/drivers/belkin-hid.c0000664000175000017500000006635715000733176013131 00000000000000/* belkin-hid.c - data to monitor Belkin UPS Systems USB/HID devices with NUT * * Copyright (C) * 2003 - 2008 Arnaud Quette * 2005 Peter Selinger * 2011, 2014 Charles Lepple * 2024 James R. Parks * 2024 Jim Klimov * * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" /* for getval() */ #include "usbhid-ups.h" #include "belkin-hid.h" #include "usb-common.h" #include "nut_float.h" /* For fabs() */ #define BELKIN_HID_VERSION "Belkin/Liebert HID 0.22" /* Belkin */ #define BELKIN_VENDORID 0x050d /* Liebert */ #define LIEBERT_VENDORID 0x10af /*! USB IDs device table. * Note that there are at least two Liebert firmware types which both report * a VID:PID of 10af:0001. The newer ones tend not to have the Belkin broken * Usage Pages (and therefore use standard HID PDC paths) but they have * incorrect exponents for some fields. */ static usb_device_id_t belkin_usb_device_table[] = { /* F6C800-UNV */ { USB_DEVICE(BELKIN_VENDORID, 0x0980), NULL }, /* F6C900-UNV */ { USB_DEVICE(BELKIN_VENDORID, 0x0900), NULL }, /* F6C100-UNV */ { USB_DEVICE(BELKIN_VENDORID, 0x0910), NULL }, /* F6C120-UNV */ { USB_DEVICE(BELKIN_VENDORID, 0x0912), NULL }, /* F6C550-AVR */ { USB_DEVICE(BELKIN_VENDORID, 0x0551), NULL }, /* F6C1250-TW-RK */ { USB_DEVICE(BELKIN_VENDORID, 0x0750), NULL }, /* F6C1500-TW-RK */ { USB_DEVICE(BELKIN_VENDORID, 0x0751), NULL }, /* F6H375-USB */ { USB_DEVICE(BELKIN_VENDORID, 0x0375), NULL }, /* Regulator PRO-USB */ { USB_DEVICE(BELKIN_VENDORID, 0x0f51), NULL }, /* F6C1100-UNV, F6C1200-UNV */ { USB_DEVICE(BELKIN_VENDORID, 0x1100), NULL }, /* Liebert GXT4 UPS */ { USB_DEVICE(LIEBERT_VENDORID, 0x0000), NULL }, /* Liebert PowerSure PSA UPS */ { USB_DEVICE(LIEBERT_VENDORID, 0x0001), NULL }, /* Liebert PowerSure PST UPS */ { USB_DEVICE(LIEBERT_VENDORID, 0x0002), NULL }, /* Liebert PowerSure PSI 1440 */ { USB_DEVICE(LIEBERT_VENDORID, 0x0004), NULL }, /* Liebert GXT3 */ { USB_DEVICE(LIEBERT_VENDORID, 0x0008), NULL }, /* Terminating entry */ { 0, 0, NULL } }; static const char *liebert_online_fun(double value); static const char *liebert_discharging_fun(double value); static const char *liebert_charging_fun(double value); static const char *liebert_lowbatt_fun(double value); static const char *liebert_replacebatt_fun(double value); static const char *liebert_shutdownimm_fun(double value); /* These lookup functions also cover the 1e-7 factor which seems to * be due to a broken report descriptor in certain Liebert units. * Exposed for unit testing - not "static" */ static const char *liebert_config_voltage_fun(double value); static const char *liebert_line_voltage_fun(double value); static double liebert_config_voltage_mult = 1.0; static double liebert_line_voltage_mult = 1.0; static char liebert_conversion_buf[10]; static info_lkp_t liebert_online_info[] = { { 0, NULL, liebert_online_fun, NULL } }; static info_lkp_t liebert_discharging_info[] = { { 0, NULL, liebert_discharging_fun, NULL } }; static info_lkp_t liebert_charging_info[] = { { 0, NULL, liebert_charging_fun, NULL } }; static info_lkp_t liebert_lowbatt_info[] = { { 0, NULL, liebert_lowbatt_fun, NULL } }; static info_lkp_t liebert_replacebatt_info[] = { { 0, NULL, liebert_replacebatt_fun, NULL } }; static info_lkp_t liebert_shutdownimm_info[] = { { 0, NULL, liebert_shutdownimm_fun, NULL } }; static info_lkp_t liebert_config_voltage_info[] = { { 0, NULL, liebert_config_voltage_fun, NULL }, }; static info_lkp_t liebert_line_voltage_info[] = { { 0, NULL, liebert_line_voltage_fun, NULL }, }; static const char *liebert_online_fun(double value) { return value ? "online" : "!online"; } static const char *liebert_discharging_fun(double value) { return value ? "dischrg" : "!dischrg"; } static const char *liebert_charging_fun(double value) { return value ? "chrg" : "!chrg"; } static const char *liebert_lowbatt_fun(double value) { return value ? "lowbatt" : "!lowbatt"; } static const char *liebert_replacebatt_fun(double value) { return value ? "replacebatt" : "!replacebatt"; } static const char *liebert_shutdownimm_fun(double value) { return value ? "shutdownimm" : "!shutdownimm"; } /*! Apply heuristics to Liebert ConfigVoltage for correction of other values. * Logic is weird since the ConfigVoltage item comes after InputVoltage and * OutputVoltage. */ static const char *liebert_config_voltage_fun(double value) { /* Does not fire with devices seen diring investigation for * https://github.com/networkupstools/nut/issues/2370 * as the ones seen serve nominal "config" values as integers * (e.g. "230" for line and "24" for battery). */ if (value < 1) { if (fabs(value - 1e-7) < 1e-9) { liebert_config_voltage_mult = 1e8; liebert_line_voltage_mult = 1e7; /* stomp this in case input voltage was low */ upsdebugx(2, "ConfigVoltage = %g -> assuming correction factor = %g", value, liebert_config_voltage_mult); } else { upslogx(LOG_NOTICE, "ConfigVoltage exponent looks wrong, but not correcting."); } } snprintf(liebert_conversion_buf, sizeof(liebert_conversion_buf), "%.1f", value * liebert_config_voltage_mult); return liebert_conversion_buf; } static const char *liebert_line_voltage_fun(double value) { /* Keep large readings like "230" or "24" as is */ if (value < 1) { int picked_scale = 0; /* NOTE: Start with tiniest scale first */ /* Practical use-case for mult=1e7: * 1.39e-06 => 13.9 * 2.201e-05 => 220.1 * NOTE: The clause below is in fact broken for this use-case, * but was present in sources for ages (worked wrongly with an * integer-oriented abs() so collapsed into "if (0 < 1e-9) {")! * if (fabs(value - 1e-7) < 1e-9) { */ if (fabs(value - 1e-5) < 4*1e-5) { liebert_line_voltage_mult = 1e7; picked_scale = 1; } else /* Practical use-case for mult=1e5: * 0.000273 => 27.3 * 0.001212 => 121.2 */ if (fabs(value - 1e-3) < 4*1e-3) { liebert_line_voltage_mult = 1e5; picked_scale = 1; } if (picked_scale) { upsdebugx(2, "Input/OutputVoltage = %g -> assuming correction factor = %g", value, liebert_line_voltage_mult); } else { upslogx(LOG_NOTICE, "LineVoltage exponent looks wrong, but not correcting."); } } snprintf(liebert_conversion_buf, sizeof(liebert_conversion_buf), "%.1f", value * liebert_line_voltage_mult); return liebert_conversion_buf; } /* some conversion functions specific to Belkin */ /* returns statically allocated string - must not use it again before done with result! */ static const char *belkin_firmware_conversion_fun(double value) { static char buf[20]; snprintf(buf, sizeof(buf), "%ld", (long)value >> 4); return buf; } static info_lkp_t belkin_firmware_conversion[] = { { 0, NULL, belkin_firmware_conversion_fun, NULL } }; static const char *belkin_upstype_conversion_fun(double value) { switch ((long)value & 0x0f) { case 1: return "offline"; case 2: return "line-interactive"; case 3: return "simple online"; case 4: return "simple offline"; case 5: return "simple line-interactive"; default: return "online"; } } static info_lkp_t belkin_upstype_conversion[] = { { 0, NULL, belkin_upstype_conversion_fun, NULL } }; static const char *belkin_sensitivity_conversion_fun(double value) { switch ((long)value) { case 1: return "reduced"; case 2: return "low"; default: return "normal"; } } static info_lkp_t belkin_sensitivity_conversion[] = { { 0, NULL, belkin_sensitivity_conversion_fun, NULL } }; static info_lkp_t belkin_test_info[] = { { 0, "No test initiated", NULL, NULL }, { 1, "Done and passed", NULL, NULL }, { 2, "Done and warning", NULL, NULL }, { 3, "Done and error", NULL, NULL }, { 4, "Aborted", NULL, NULL }, { 5, "In progress", NULL, NULL }, { 0, NULL, NULL, NULL } }; static const char *belkin_overload_conversion_fun(double value) { if ((long)value & 0x0010) { return "overload"; } else { return "!overload"; } } static info_lkp_t belkin_overload_conversion[] = { { 0, NULL, belkin_overload_conversion_fun, NULL } }; static const char *belkin_overheat_conversion_fun(double value) { if ((long)value & 0x0040) { return "overheat"; } else { return "!overheat"; } } static info_lkp_t belkin_overheat_conversion[] = { { 0, NULL, belkin_overheat_conversion_fun, NULL } }; static const char *belkin_commfault_conversion_fun(double value) { if ((long)value & 0x0080) { return "commfault"; } else { return "!commfault"; } } static info_lkp_t belkin_commfault_conversion[] = { { 0, NULL, belkin_commfault_conversion_fun, NULL } }; static const char *belkin_awaitingpower_conversion_fun(double value) { if ((long)value & 0x2000) { return "awaitingpower"; } else { return "!awaitingpower"; } } static info_lkp_t belkin_awaitingpower_conversion[] = { { 0, NULL, belkin_awaitingpower_conversion_fun, NULL } }; static const char *belkin_online_conversion_fun(double value) { if ((long)value & 0x0001) { return "!online"; } else { return "online"; } } static info_lkp_t belkin_online_conversion[] = { { 0, NULL, belkin_online_conversion_fun, NULL } }; static const char *belkin_lowbatt_conversion_fun(double value) { if ((long)value & 0x0004) { return "lowbatt"; } else { return "!lowbatt"; } } static info_lkp_t belkin_lowbatt_conversion[] = { { 0, NULL, belkin_lowbatt_conversion_fun, NULL } }; static const char *belkin_depleted_conversion_fun(double value) { if ((long)value & 0x0040) { return "depleted"; } else { return "!depleted"; } } static info_lkp_t belkin_depleted_conversion[] = { { 0, NULL, belkin_depleted_conversion_fun, NULL } }; static const char *belkin_replacebatt_conversion_fun(double value) { if ((long)value & 0x0080) { return "replacebatt"; } else { return "!replacebatt"; } } static info_lkp_t belkin_replacebatt_conversion[] = { { 0, NULL, belkin_replacebatt_conversion_fun, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* BELKIN usage table */ /* Note: these seem to have been wrongly encoded by Belkin */ /* Pages 84 to 88 are reserved for official HID definition! */ static usage_lkp_t belkin_usage_lkp[] = { { "BELKINConfig", 0x00860026 }, { "BELKINConfigVoltage", 0x00860040 }, /* (V) */ { "BELKINConfigFrequency", 0x00860042 }, /* (Hz) */ { "BELKINConfigApparentPower", 0x00860043 }, /* (VA) */ { "BELKINConfigBatteryVoltage", 0x00860044 }, /* (V) */ { "BELKINConfigOverloadTransfer", 0x00860045 }, /* (%) */ { "BELKINLowVoltageTransfer", 0x00860053 }, /* R/W (V) */ { "BELKINHighVoltageTransfer", 0x00860054 }, /* R/W (V)*/ { "BELKINLowVoltageTransferMax", 0x0086005b }, /* (V) */ { "BELKINLowVoltageTransferMin", 0x0086005c }, /* (V) */ { "BELKINHighVoltageTransferMax", 0x0086005d }, /* (V) */ { "BELKINHighVoltageTransferMin", 0x0086005e }, /* (V) */ { "BELKINControls", 0x00860027 }, { "BELKINLoadOn", 0x00860050 }, /* R/W: write: 1=do action. Read: 0=none, 1=started, 2=in progress, 3=complete */ { "BELKINLoadOff", 0x00860051 }, /* R/W: ditto */ { "BELKINLoadToggle", 0x00860052 }, /* R/W: ditto */ { "BELKINDelayBeforeReboot", 0x00860055 }, /* R/W: write: 0=start shutdown using default delay. */ { "BELKINDelayBeforeStartup", 0x00860056 }, /* R/W (minutes) */ { "BELKINDelayBeforeShutdown", 0x00860057 }, /* R/W (seconds) */ { "BELKINTest", 0x00860058 }, /* R/W: write: 0=no test, 1=quick test, 2=deep test, 3=abort test. Read: 0=no test, 1=passed, 2=warning, 3=error, 4=abort, 5=in progress */ { "BELKINAudibleAlarmControl", 0x0086005a }, /* R/W: 1=disabled, 2=enabled, 3=muted */ { "BELKINDevice", 0x00860029 }, { "BELKINVoltageSensitivity", 0x00860074 }, /* R/W: 0=normal, 1=reduced, 2=low */ { "BELKINModelString", 0x00860075 }, { "BELKINModelStringOffset", 0x00860076 }, /* offset of Model name in Model String */ { "BELKINUPSType", 0x0086007c }, /* high nibble: firmware version. Low nibble: 0=online, 1=offline, 2=line-interactive, 3=simple online, 4=simple offline, 5=simple line-interactive */ { "BELKINPowerState", 0x0086002a }, { "BELKINInput", 0x0086001a }, { "BELKINOutput", 0x0086001c }, { "BELKINBatterySystem", 0x00860010 }, { "BELKINVoltage", 0x00860030 }, /* (0.1 Volt) */ { "BELKINFrequency", 0x00860032 }, /* (0.1 Hz) */ { "BELKINPower", 0x00860034 }, /* (Watt) */ { "BELKINPercentLoad", 0x00860035 }, /* (%) */ { "BELKINTemperature", 0x00860036 }, /* (Celsius) */ { "BELKINCharge", 0x00860039 }, /* (%) */ { "BELKINRunTimeToEmpty", 0x0086006c }, /* (minutes) */ { "BELKINStatus", 0x00860028 }, { "BELKINBatteryStatus", 0x00860022 }, /* 1 byte: bit2=low battery, bit4=charging, bit5=discharging, bit6=battery empty, bit7=replace battery */ { "BELKINPowerStatus", 0x00860021 }, /* 2 bytes: bit0=ac failure, bit4=overload, bit5=load is off, bit6=overheat, bit7=UPS fault, bit13=awaiting power, bit15=alarm status */ { NULL, 0 } }; static usage_tables_t belkin_utab[] = { belkin_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t belkin_hid2nut[] = { /* interpreted Belkin variables */ { "battery.charge", 0, 0, "UPS.BELKINBatterySystem.BELKINCharge", NULL, "%.0f", 0, NULL }, /* { "battery.charge.broken", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, */ { "battery.charge.low", 0, 0, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", 0, NULL }, { "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", 0, NULL }, /* Read only */ { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", 0, stringid_conversion }, { "battery.voltage", 0, 0, "UPS.BELKINBatterySystem.BELKINVoltage", NULL, "%s", 0, divide_by_10_conversion }, { "battery.voltage.nominal", 0, 0, "UPS.BELKINConfig.BELKINConfigBatteryVoltage", NULL, "%.0f", 0, NULL }, { "input.frequency", 0, 0, "UPS.BELKINPowerState.BELKINInput.BELKINFrequency", NULL, "%s", 0, divide_by_10_conversion }, { "input.frequency.nominal", 0, 0, "UPS.BELKINConfig.BELKINConfigFrequency", NULL, "%.0f", 0, NULL }, { "input.sensitivity", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.BELKINDevice.BELKINVoltageSensitivity", NULL, "%s", 0, belkin_sensitivity_conversion }, { "input.transfer.high", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.BELKINConfig.BELKINHighVoltageTransfer", NULL, "%.0f", 0, NULL }, { "input.transfer.high.max", 0, 0, "UPS.BELKINConfig.BELKINHighVoltageTransferMax", NULL, "%.0f", 0, NULL }, { "input.transfer.high.min", 0, 0, "UPS.BELKINConfig.BELKINHighVoltageTransferMin", NULL, "%.0f", 0, NULL }, { "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.BELKINConfig.BELKINLowVoltageTransfer", NULL, "%.0f", 0, NULL }, { "input.transfer.low.max", 0, 0, "UPS.BELKINConfig.BELKINLowVoltageTransferMax", NULL, "%.0f", 0, NULL }, { "input.transfer.low.min", 0, 0, "UPS.BELKINConfig.BELKINLowVoltageTransferMin", NULL, "%.0f", 0, NULL }, { "input.voltage", 0, 0, "UPS.BELKINPowerState.BELKINInput.BELKINVoltage", NULL, "%s", 0, divide_by_10_conversion }, { "input.voltage.nominal", 0, 0, "UPS.BELKINConfig.BELKINConfigVoltage", NULL, "%.0f", 0, NULL }, { "output.frequency", 0, 0, "UPS.BELKINPowerState.BELKINOutput.BELKINFrequency", NULL, "%s", 0, divide_by_10_conversion }, { "output.voltage", 0, 0, "UPS.BELKINPowerState.BELKINOutput.BELKINVoltage", NULL, "%s", 0, divide_by_10_conversion }, { "ups.beeper.status", 0, 0, "UPS.BELKINControls.BELKINAudibleAlarmControl", NULL, "%s", 0, beeper_info }, { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.BELKINControls.BELKINDelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL }, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.BELKINControls.BELKINDelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL }, { "ups.timer.start", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeStartup", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL }, { "ups.timer.shutdown", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL }, { "ups.timer.reboot", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeReboot", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL }, { "ups.firmware", 0, 0, "UPS.BELKINDevice.BELKINUPSType", NULL, "%s", 0, belkin_firmware_conversion }, { "ups.load", 0, 0, "UPS.BELKINPowerState.BELKINOutput.BELKINPercentLoad", NULL, "%.0f", 0, NULL }, { "ups.load.high", 0, 0, "UPS.BELKINConfig.BELKINConfigOverloadTransfer", NULL, "%.0f", 0, NULL }, { "ups.mfr.date", 0, 0, "UPS.PowerSummary.ManufacturerDate", NULL, "%s", 0, date_conversion }, { "ups.power.nominal", 0, 0, "UPS.BELKINConfig.BELKINConfigApparentPower", NULL, "%.0f", 0, NULL }, { "ups.serial", 0, 0, "UPS.PowerSummary.iSerialNumber", NULL, "%s", 0, stringid_conversion }, { "ups.test.result", 0, 0, "UPS.BELKINControls.BELKINTest", NULL, "%s", 0, belkin_test_info }, { "ups.type", 0, 0, "UPS.BELKINDevice.BELKINUPSType", NULL, "%s", 0, belkin_upstype_conversion }, /* Liebert PSA: */ { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL }, /* why .broken above? */ { "input.frequency", 0, 0, "UPS.Input.Frequency", NULL, "%s", 0, divide_by_10_conversion }, { "input.voltage", 0, 0, "UPS.Input.Voltage", NULL, "%s", 0, liebert_line_voltage_info }, { "output.voltage", 0, 0, "UPS.Output.Voltage", NULL, "%s", 0, liebert_line_voltage_info }, /* You would think these next two would be off by the same factor. You'd be wrong. */ { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, liebert_line_voltage_info }, { "battery.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%s", HU_FLAG_STATIC, liebert_config_voltage_info }, { "ups.load", 0, 0, "UPS.Output.PercentLoad", NULL, "%.0f", 0, NULL }, /* Liebert PSI5 */ { "input.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "input.frequency", 0, 0, "UPS.PowerConverter.Input.Frequency", NULL, "%s", 0, divide_by_100_conversion }, { "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%s", 0, liebert_line_voltage_info }, { "output.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%s", 0, divide_by_100_conversion }, { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%s", 0, liebert_line_voltage_info }, { "ups.load", 0, 0, "UPS.OutletSystem.Outlet.PercentLoad", NULL, "%.0f", 0, NULL }, { "battery.voltage", 0, 0, "UPS.BatterySystem.Battery.Voltage", NULL, "%s", 0, liebert_line_voltage_info }, { "battery.voltage.nominal", 0, 0, "UPS.BatterySystem.Battery.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "battery.capacity", 0, 0, "UPS.Flow.ConfigApparentPower", NULL, "%.0f", 0, NULL }, /* status */ { "BOOL", 0, 0, "UPS.PowerSummary.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_discharging_info }, /* might not need to be liebert_* version */ { "BOOL", 0, 0, "UPS.PowerSummary.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.ShutdownImminent", NULL, NULL, 0, liebert_shutdownimm_info }, { "BOOL", 0, 0, "UPS.PowerSummary.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, liebert_shutdownimm_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_replacebatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, liebert_lowbatt_info }, /* { "BOOL", 0, 0, "UPS.PowerSummary.BelowRemainingCapacityLimit", NULL, "%s", 0, lowbatt_info }, broken! */ { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINPowerStatus", NULL, NULL, 0, belkin_overload_conversion }, { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINPowerStatus", NULL, NULL, 0, belkin_overheat_conversion }, { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINPowerStatus", NULL, NULL, 0, belkin_commfault_conversion }, { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINPowerStatus", NULL, NULL, 0, belkin_awaitingpower_conversion }, { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINPowerStatus", NULL, NULL, HU_FLAG_QUICK_POLL, belkin_online_conversion }, { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINBatteryStatus", NULL, NULL, HU_FLAG_QUICK_POLL, belkin_depleted_conversion }, { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINBatteryStatus", NULL, NULL, 0, belkin_replacebatt_conversion }, { "BOOL", 0, 0, "UPS.BELKINStatus.BELKINBatteryStatus", NULL, NULL, HU_FLAG_QUICK_POLL, belkin_lowbatt_conversion }, /* instant commands. */ /* split into subsets while waiting for extradata support * ie: test.battery.start quick */ { "test.battery.start.quick", 0, 0, "UPS.BELKINControls.BELKINTest", NULL, "1", HU_TYPE_CMD, NULL }, { "test.battery.start.deep", 0, 0, "UPS.BELKINControls.BELKINTest", NULL, "2", HU_TYPE_CMD, NULL }, { "test.battery.stop", 0, 0, "UPS.BELKINControls.BELKINTest", NULL, "3", HU_TYPE_CMD, NULL }, { "beeper.on", 0, 0, "UPS.BELKINControls.BELKINAudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.off", 0, 0, "UPS.BELKINControls.BELKINAudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.BELKINControls.BELKINAudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.enable", 0, 0, "UPS.BELKINControls.BELKINAudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.mute", 0, 0, "UPS.BELKINControls.BELKINAudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, { "load.off", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeShutdown", NULL, "1", HU_TYPE_CMD, NULL }, { "load.on", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeStartup", NULL, "1", HU_TYPE_CMD, NULL }, { "load.off.delay", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "shutdown.stop", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, { "shutdown.reboot", 0, 0, "UPS.BELKINControls.BELKINDelayBeforeReboot", NULL, "10", HU_TYPE_CMD, NULL }, /* Note: on my Belkin UPS, there is no way to implement shutdown.return or load.on, even though they should exist in principle. Hopefully other Belkin models will be better designed. Fixme: fill in the appropriate instant commands. For a more detailed description of the problem and a possible (but not yet implemented) workaround, see the belkinunv(8) man page. -PS 2005/08/28 */ #if WITH_UNMAPPED_DATA_POINTS /* added for debugging Liebert GXT3 : */ { "unmapped.ups.powersummary.iserialnumber", 0, 0, "UPS.PowerSummary.iSerialNumber", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.imanufacturer", 0, 0, "UPS.PowerSummary.iManufacturer", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.ioeminformation", 0, 0, "UPS.PowerSummary.iOEMInformation", NULL, "%s", 0, stringid_conversion }, { "unmapped.ups.powersummary.designcapacity", 0, 0, "UPS.PowerSummary.DesignCapacity", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.remainingtimelimit", 0, 0, "UPS.PowerSummary.RemainingTimeLimit", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitymode", 0, 0, "UPS.PowerSummary.CapacityMode", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.rechargeable", 0, 0, "UPS.PowerSummary.Rechargeable", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.batterypresent", 0, 0, "UPS.PowerSummary.BatteryPresent", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.fullchargecapacity", 0, 0, "UPS.PowerSummary.FullChargeCapacity", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitygranularity1", 0, 0, "UPS.PowerSummary.CapacityGranularity1", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitygranularity2", 0, 0, "UPS.PowerSummary.CapacityGranularity2", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.iproduct", 0, 0, "UPS.PowerSummary.iProduct", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *belkin_format_model(HIDDevice_t *hd) { if ((hd->Product) && (strlen(hd->Product) > 0)) { return hd->Product; } return "unknown"; } static const char *belkin_format_mfr(HIDDevice_t *hd) { const char *mfr; mfr = hd->Vendor ? hd->Vendor : "Belkin"; /* trim leading whitespace */ while (*mfr == ' ') { mfr++; } if (strlen(mfr) == 0) { mfr = "Belkin"; } return mfr; } static const char *belkin_format_serial(HIDDevice_t *hd) { char serial[64]; if (hd->Serial) { return hd->Serial; } /* try UPS.PowerSummary.iSerialNumber */ HIDGetItemString(udev, "UPS.PowerSummary.iSerialNumber", serial, sizeof(serial), belkin_utab); if (strlen(serial) < 1) { return NULL; } /* free(hd->Serial); not needed, we already know it is NULL */ hd->Serial = strdup(serial); return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int belkin_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(belkin_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: switch (hd->VendorID) { case BELKIN_VENDORID: /* reject any known non-UPS */ if (hd->ProductID == 0x0218) /* F5U218-MOB 4-Port USB Hub */ return 0; /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("Belkin", hd); return 0; case LIEBERT_VENDORID: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("Liebert", hd); return 0; default: break; } return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t belkin_subdriver = { BELKIN_HID_VERSION, belkin_claim, belkin_utab, belkin_hid2nut, belkin_format_model, belkin_format_mfr, belkin_format_serial, fix_report_desc, }; nut-2.8.4/drivers/apc-iem-mib.h0000644000175000017500000000126614777753336013216 00000000000000#ifndef APC_IEM_MIB_H #define APC_IEM_MIB_H /* * FIXME: The below is needed because the main driver body uses this to determine * whether a conversion from Fahrenheit to Celsius is needed (which really should * be solved in subdriver specific formatting functions, like we do in usbhid-ups * This is used in both snmp-ups.c and apc.c logics. */ /* IEM ambient variables */ /* IEM: integrated environment monitor probe */ #define APCC_OID_IEM_TEMP ".1.3.6.1.4.1.318.1.1.10.2.3.2.1.4.1" #define APCC_OID_IEM_TEMP_UNIT ".1.3.6.1.4.1.318.1.1.10.2.3.2.1.5.1" #define APCC_IEM_FAHRENHEIT 2 #define APCC_OID_IEM_HUMID ".1.3.6.1.4.1.318.1.1.10.2.3.2.1.6.1" #endif /* APC_IEM_MIB_H */ nut-2.8.4/drivers/nutdrv_qx_hunnox.c0000644000175000017500000001515514777753337014565 00000000000000/* nutdrv_qx_hunnox.c - Subdriver for Hunnox protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * 2020 Mariano Jan https://marianojan.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_hunnox.h" #define HUNNOX_VERSION "Hunnox 0.02" /* qx2nut lookup table */ static item_t hunnox_qx2nut[] = { /* * > [Q1\r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000\r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ { "input.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 1, 5, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "input.voltage.fault", 0, NULL, "Q1\r", "", 47, '(', "", 7, 11, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "output.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 13, 17, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "ups.load", 0, NULL, "Q1\r", "", 47, '(', "", 19, 21, "%.0f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "Q1\r", "", 47, '(', "", 23, 26, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 28, 31, "%.2f", QX_FLAG_QUICK_POLL, NULL, NULL, qx_multiply_battvolt }, { "ups.temperature", 0, NULL, "Q1\r", "", 47, '(', "", 33, 36, "%.1f", QX_FLAG_QUICK_POLL, NULL, NULL, NULL }, /* Status bits */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 38, 38, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Utility Fail (Immediate) */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 39, 39, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Battery Low */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 40, 40, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Bypass/Boost or Buck Active */ { "ups.alarm", 0, NULL, "Q1\r", "", 47, '(', "", 41, 41, NULL, 0, NULL, NULL, blazer_process_status_bits }, /* UPS Failed */ { "ups.type", 0, NULL, "Q1\r", "", 47, '(', "", 42, 42, "%s", QX_FLAG_STATIC, NULL, NULL, blazer_process_status_bits }, /* UPS Type */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 43, 43, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Test in Progress */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 44, 44, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Shutdown Active */ { "ups.beeper.status", 0, NULL, "Q1\r", "", 47, '(', "", 45, 45, "%s", 0, NULL, NULL, blazer_process_status_bits }, /* Beeper status */ /* * > [F\r] * < [#220.0 000 024.0 50.0\r] * 0123456789012345678901 * 0 1 2 */ { "input.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 1, 5, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.current.nominal", 0, NULL, "F\r", "", 22, '#', "", 7, 9, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "battery.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 11, 15, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.frequency.nominal", 0, NULL, "F\r", "", 22, '#', "", 17, 20, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, /* * > [FW?\r] * < [#------------- ------ VT12046Q \r] * 012345678901234567890123456789012345678 * 0 1 2 3 */ { "device.mfr", 0, NULL, "FW?\r", "", 39, '#', "", 1, 15, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "device.model", 0, NULL, "FW?\r", "", 39, '#', "", 17, 26, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "ups.firmware", 0, NULL, "FW?\r", "", 39, '#', "", 28, 37, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* Instant commands */ { "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%sR0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, blazer_r_ondelay, NULL, "", 0, 0, "", 0, 0, "0", QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, blazer_r_offdelay, NULL, "", 0, 0, "", 0, 0, "60", QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* Testing table */ #ifdef TESTING static testing_t hunnox_testing[] = { { "Q1\r", "(215.0 195.0 230.0 014 49.0 22.7 30.0 00000000\r", -1 }, { "F\r", "#230.0 000 024.0 50.0\r", -1 }, { "FW?\r", "#NOT_A_LIVE_UPS TESTING TESTING \r", -1 }, { "Q\r", "", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0000\r", "", -1 }, { "T04\r", "", -1 }, { "TL\r", "", -1 }, { "T\r", "", -1 }, { "CT\r", "", -1 }, { NULL } }; #endif /* TESTING */ /* Subdriver-specific initups */ static void hunnox_initups(void) { blazer_initups(hunnox_qx2nut); } /* Subdriver interface */ subdriver_t hunnox_subdriver = { HUNNOX_VERSION, blazer_claim, hunnox_qx2nut, hunnox_initups, NULL, blazer_makevartable, "UPS No Ack", NULL, #ifdef TESTING hunnox_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/emerson-avocent-pdu-mib.h0000644000175000017500000000223714670526611015557 00000000000000/* emerson-avocent-pdu-mib.h - subdriver to monitor Emerson Avocent PDUs with NUT * * Copyright (C) * 2008-2018 Arnaud Quette * 2009 Opengear * 2018 Eaton (Arnaud Quette ) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef EMERSON_AVOCENT_PDU_MIB_H #define EMERSON_AVOCENT_PDU_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t emerson_avocent_pdu; #endif /* EMERSON_AVOCENT_PDU_MIB_H */ nut-2.8.4/drivers/cps-hid.c0000644000175000017500000006401615044656702012445 00000000000000/* cps-hid.c - subdriver to monitor CPS USB/HID devices with NUT * * Copyright (C) * 2003 - 2008 Arnaud Quette * 2005 - 2006 Peter Selinger * 2020 - 2025 Jim Klimov * 2024 Alejandro González * * Note: this subdriver was initially generated as a "stub" by the * gen-usbhid-subdriver script. It must be customized. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" /* for getval() */ #include "nut_float.h" #include "hidparser.h" /* for FindObject_with_ID_Node() */ #include "usbhid-ups.h" #include "cps-hid.h" #include "usb-common.h" #define CPS_HID_VERSION "CyberPower HID 0.84" /* Cyber Power Systems */ #define CPS_VENDORID 0x0764 /* ST Microelectronics */ #define STMICRO_VENDORID 0x0483 /* Please note that USB vendor ID 0x0483 is from ST Microelectronics - * with actual product IDs delegated to different OEMs. * Devices handled in this driver are marketed under Cyber Energy brand. */ /* Values for correcting the HID on some models * where LogMin and LogMax are set incorrectly in the HID. */ #define CPS_VOLTAGE_LOGMIN 0 #define CPS_VOLTAGE_LOGMAX 511 /* Includes safety margin. */ /* Should be a realistic max value covering most affected UPS. */ #define CPS_NOMINALPWR_LOGMAX 2048 /*! Battery voltage scale factor. * For some devices, the reported battery voltage is off by factor * of 1.5 so we need to apply a scale factor to it to get the real * battery voltage. By default, the factor is 1 (no scaling). * Similarly, some firmwares do not report the exponent well, so * frequency values are seen as e.g. "499.0" (in "0.1 Hz" units not * explicitly stated), instead of "49.9 Hz". */ static double battery_scale = 1, input_freq_scale = 1, output_freq_scale = 1; static int might_need_battery_scale = 0, might_need_freq_scale = 0; static int battery_scale_checked = 0, input_freq_scale_checked = 0, output_freq_scale_checked = 0; /*! If the ratio of the battery voltage to the nominal battery voltage exceeds * this factor, we assume that the battery voltage needs to be scaled by 2/3. */ static const double battery_voltage_sanity_check = 1.4; static void *cps_battery_scale(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); might_need_battery_scale = 1; might_need_freq_scale = 1; return NULL; } /* USB IDs device table */ static usb_device_id_t cps_usb_device_table[] = { /* 900AVR/BC900D */ { USB_DEVICE(CPS_VENDORID, 0x0005), NULL }, /* Dynex DX-800U?, CP1200AVR/BC1200D, CP825AVR-G, CP1000AVRLCD, CP1000PFCLCD, CP1500C, CP550HG, etc. */ { USB_DEVICE(CPS_VENDORID, 0x0501), &cps_battery_scale }, /* OR2200LCDRM2U, OR700LCDRM1U, PR6000LCDRTXL5U, CP1350EPFCLCD */ { USB_DEVICE(CPS_VENDORID, 0x0601), NULL }, /* Cyber Energy branded devices by CPS */ { USB_DEVICE(STMICRO_VENDORID, 0xa430), NULL }, /* Terminating entry */ { 0, 0, NULL } }; /*! Adjusts frequency if it is order(s) of magnitude off * is_input = 1 for input.frequency and 0 for output.frequency */ static void cps_adjust_frequency_scale(double freq_report, int is_input) { const char *freq_low_str, *freq_high_str, *freq_nom_str; double freq_low = 0, freq_high = 0, freq_nom = 0; if ((is_input && input_freq_scale_checked) || (!is_input && output_freq_scale_checked)) return; /* May be not available from device itself; but still * may be set by user as default/override options; * if not, we default for 50Hz and/or 60Hz range +- 10%. */ freq_nom_str = dstate_getinfo(is_input ? "input.frequency.nominal" : "output.frequency.nominal"); freq_low_str = dstate_getinfo(is_input ? "input.frequency.low" : "output.frequency.low"); freq_high_str = dstate_getinfo(is_input ? "input.frequency.high" : "output.frequency.high"); if (freq_nom_str) freq_nom = strtod(freq_nom_str, NULL); if (freq_low_str) freq_low = strtod(freq_low_str, NULL); if (freq_high_str) freq_high = strtod(freq_high_str, NULL); if (d_equal(freq_nom, 0)) { if (45 < freq_low && freq_low <= 50) freq_nom = 50; else if (50 <= freq_high && freq_high <= 55) freq_nom = 50; else if (45 < freq_report && freq_report <= 55) freq_nom = 50; else if (450 < freq_report && freq_report <= 550) freq_nom = 50; else if (55 < freq_low && freq_low <= 60) freq_nom = 60; else if (60 <= freq_high && freq_high <= 65) freq_nom = 60; else if (55 < freq_report && freq_report <= 65) freq_nom = 60; else if (550 < freq_report && freq_report <= 650) freq_nom = 60; upsdebugx(3, "%s: '%sput.frequency.nominal' is %s, guessed %0.1f%s", __func__, is_input ? "in" : "out", NUT_STRARG(freq_nom_str), d_equal(freq_nom, 0) ? 55 : freq_nom, d_equal(freq_nom, 0) ? " (50 or 60Hz range)" : ""); } if (d_equal(freq_low, 0)) { if (d_equal(freq_nom, 0)) freq_low = 45.0; else freq_low = freq_nom * 0.95; upsdebugx(3, "%s: '%sput.frequency.low' is %s, defaulting to %0.1f", __func__, is_input ? "in" : "out", NUT_STRARG(freq_low_str), freq_low); } if (d_equal(freq_high, 0)) { if (d_equal(freq_nom, 0)) freq_high = 65.0; else freq_high = freq_nom * 1.05; upsdebugx(3, "%s: '%sput.frequency.high' is %s, defaulting to %0.1f", __func__, is_input ? "in" : "out", NUT_STRARG(freq_high_str), freq_high); } if (freq_low <= freq_report && freq_report <= freq_high) { if (is_input) { input_freq_scale = 1.0; input_freq_scale_checked = 1; } else { output_freq_scale = 1.0; output_freq_scale_checked = 1; } /* We should be here once per freq type... */ upsdebugx(1, "%s: Determined scaling factor " "needed for '%sput.frequency': 1.0", __func__, is_input ? "in" : "out"); } else if (freq_low <= freq_report/10.0 && freq_report/10.0 <= freq_high) { if (is_input) { input_freq_scale = 0.1; input_freq_scale_checked = 1; } else { output_freq_scale = 0.1; output_freq_scale_checked = 1; } /* We should be here once per freq type... */ upsdebugx(1, "%s: Determined scaling factor " "needed for '%sput.frequency': 0.1", __func__, is_input ? "in" : "out"); } else { /* We might return here, so do not log too loudly */ upsdebugx(2, "%s: Could not determine scaling factor " "needed for '%sput.frequency', will report " "it as is (and might detect better later)", __func__, is_input ? "in" : "out"); } } /* returns statically allocated string - must not use it again before done with result! */ static const char *cps_input_freq_fun(double value) { static char buf[8]; if (might_need_freq_scale) { cps_adjust_frequency_scale(value, 1); } upsdebugx(5, "%s: input_freq_scale = %.3f", __func__, input_freq_scale); snprintf(buf, sizeof(buf), "%.1f", input_freq_scale * value); return buf; } static info_lkp_t cps_input_freq[] = { { 0, NULL, &cps_input_freq_fun, NULL } }; /* returns statically allocated string - must not use it again before done with result! */ static const char *cps_output_freq_fun(double value) { static char buf[8]; if (might_need_freq_scale) { cps_adjust_frequency_scale(value, 0); } upsdebugx(5, "%s: output_freq_scale = %.3f", __func__, output_freq_scale); snprintf(buf, sizeof(buf), "%.1f", output_freq_scale * value); return buf; } static info_lkp_t cps_output_freq[] = { { 0, NULL, &cps_output_freq_fun, NULL } }; /*! Adjusts @a battery_scale if voltage is well above nominal. */ static void cps_adjust_battery_scale(double batt_volt) { const char *batt_volt_nom_str; double batt_volt_nom; if(battery_scale_checked) { return; } batt_volt_nom_str = dstate_getinfo("battery.voltage.nominal"); if(!batt_volt_nom_str) { upsdebugx(2, "%s: 'battery.voltage.nominal' not available yet; skipping scale determination", __func__); return; } batt_volt_nom = strtod(batt_volt_nom_str, NULL); if(d_equal(batt_volt_nom, 0)) { upsdebugx(3, "%s: 'battery.voltage.nominal' is %s", __func__, batt_volt_nom_str); return; } if( (batt_volt / batt_volt_nom) > battery_voltage_sanity_check ) { upslogx(LOG_INFO, "%s: battery readings will be scaled by 2/3", __func__); battery_scale = 2.0/3; } battery_scale_checked = 1; } /* returns statically allocated string - must not use it again before done with result! */ static const char *cps_battvolt_fun(double value) { static char buf[8]; if(might_need_battery_scale) { cps_adjust_battery_scale(value); } upsdebugx(5, "%s: battery_scale = %.3f", __func__, battery_scale); snprintf(buf, sizeof(buf), "%.1f", battery_scale * value); return buf; } static info_lkp_t cps_battvolt[] = { { 0, NULL, &cps_battvolt_fun, NULL } }; /* returns statically allocated string - must not use it again before done with result! */ static const char *cps_battcharge_fun(double value) { static char buf[8]; /* clamp battery charge to 100% */ snprintf(buf, sizeof(buf), "%.0f", value < 100.0 ? value : 100.0); return buf; } static info_lkp_t cps_battcharge[] = { { 0, NULL, &cps_battcharge_fun, NULL } }; static const char *cps_battstatus_fun(double value) { static char buf[8]; /* assumes `UPS.PowerSummary.FullChargeCapacity` is in %, which should be for */ /* UPSes that conform to the USB HID spec, given how we read `battery.charge` */ snprintf(buf, sizeof(buf), "%.0f%%", value); return buf; } static info_lkp_t cps_battstatus[] = { { 0, NULL, &cps_battstatus_fun, NULL } }; static info_lkp_t cps_sensitivity_info[] = { { 0, "low", NULL, NULL }, { 1, "normal", NULL, NULL }, { 2, "high", NULL, NULL }, { 0, NULL, NULL, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* CPS usage table */ static usage_lkp_t cps_usage_lkp[] = { { "CPSFirmwareVersion", 0xff0100d0 }, { "CPSInputSensitivity", 0xff010043 }, { NULL, 0x0 } }; static usage_tables_t cps_utab[] = { cps_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t cps_hid2nut[] = { #if WITH_UNMAPPED_DATA_POINTS { "unmapped.ups.powersummary.rechargeable", 0, 0, "UPS.PowerSummary.Rechargeable", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitymode", 0, 0, "UPS.PowerSummary.CapacityMode", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.designcapacity", 0, 0, "UPS.PowerSummary.DesignCapacity", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitygranularity1", 0, 0, "UPS.PowerSummary.CapacityGranularity1", NULL, "%.0f", 0, NULL }, { "unmapped.ups.powersummary.capacitygranularity2", 0, 0, "UPS.PowerSummary.CapacityGranularity2", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ /* Battery page */ { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", 0, stringid_conversion }, { "battery.mfr.date", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Battery.ManufacturerDate", NULL, "%s", HU_FLAG_SEMI_STATIC, date_conversion }, { "battery.mfr.date", 0, 0, "UPS.PowerSummary.iOEMInformation", NULL, "%s", 0, stringid_conversion }, { "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", 0, NULL }, { "battery.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%s", 0, cps_battcharge }, { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.runtime.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.RemainingTimeLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, cps_battvolt }, { "battery.status", 0, 0, "UPS.PowerSummary.FullChargeCapacity", NULL, "%s", 0, cps_battstatus }, /* UPS page */ { "ups.load", 0, 0, "UPS.Output.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.beeper.status", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "%s", 0, beeper_info }, { "ups.test.result", 0, 0, "UPS.Output.Test", NULL, "%s", 0, test_read_info }, { "ups.power", 0, 0, "UPS.Output.ApparentPower", NULL, "%.0f", 0, NULL }, { "ups.power.nominal", 0, 0, "UPS.Output.ConfigApparentPower", NULL, "%.0f", 0, NULL }, { "ups.realpower", 0, 0, "UPS.Output.ActivePower", NULL, "%.0f", 0, NULL }, { "ups.realpower.nominal", 0, 0, "UPS.Output.ConfigActivePower", NULL, "%.0f", 0, NULL }, { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Output.DelayBeforeStartup", NULL, DEFAULT_ONDELAY_CPS, HU_FLAG_ABSENT, NULL}, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Output.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY_CPS, HU_FLAG_ABSENT, NULL}, { "ups.timer.start", 0, 0, "UPS.Output.DelayBeforeStartup", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.shutdown", 0, 0, "UPS.Output.DelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.reboot", 0, 0, "UPS.Output.DelayBeforeReboot", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.firmware", 0, 0, "UPS.PowerSummary.CPSFirmwareVersion", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, { "ups.temperature", 0, 0, "UPS.PowerSummary.Temperature", NULL, "%s", 0, kelvin_celsius_conversion }, /* Special case: ups.status & ups.alarm */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyCharged", NULL, NULL, 0, fullycharged_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.RemainingTimeLimitExpired", NULL, NULL, 0, timelimitexpired_info }, { "BOOL", 0, 0, "UPS.Output.Boost", NULL, NULL, 0, boost_info }, { "BOOL", 0, 0, "UPS.Output.Overload", NULL, NULL, 0, overload_info }, /* Input page */ /* FIXME: Check if something like "UPS.Flow([N]?).ConfigFrequency" * is available for "input.frequency.nominal" */ { "input.frequency", 0, 0, "UPS.Input.Frequency", NULL, "%.1f", 0, cps_input_freq }, { "input.voltage.nominal", 0, 0, "UPS.Input.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "input.voltage", 0, 0, "UPS.Input.Voltage", NULL, "%.1f", 0, NULL }, { "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Input.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.high", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Input.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, /* used by CP1350EPFCLCD; why oh why "UPS.Output"?.. */ { "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Output.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.high", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Output.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.sensitivity", ST_FLAG_RW | ST_FLAG_STRING, 0, "UPS.Output.CPSInputSensitivity", NULL, "%s", HU_FLAG_SEMI_STATIC | HU_FLAG_ENUM, cps_sensitivity_info }, /* Output page */ /* FIXME: Check if something like "UPS.Flow([N]?).ConfigFrequency" * is available for "output.frequency.nominal" */ { "output.frequency", 0, 0, "UPS.Output.Frequency", NULL, "%.1f", 0, cps_output_freq }, { "output.voltage", 0, 0, "UPS.Output.Voltage", NULL, "%.1f", 0, NULL }, { "output.voltage.nominal", 0, 0, "UPS.Output.ConfigVoltage", NULL, "%.0f", 0, NULL }, /* instant commands. */ { "test.battery.start.quick", 0, 0, "UPS.Output.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "test.battery.start.deep", 0, 0, "UPS.Output.Test", NULL, "2", HU_TYPE_CMD, NULL }, { "test.battery.stop", 0, 0, "UPS.Output.Test", NULL, "3", HU_TYPE_CMD, NULL }, { "load.off.delay", 0, 0, "UPS.Output.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY_CPS, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.Output.DelayBeforeStartup", NULL, DEFAULT_ONDELAY_CPS, HU_TYPE_CMD, NULL }, { "shutdown.stop", 0, 0, "UPS.Output.DelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, { "shutdown.reboot", 0, 0, "UPS.Output.DelayBeforeReboot", NULL, "10", HU_TYPE_CMD, NULL }, { "beeper.on", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.off", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, { "beeper.enable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.mute", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *cps_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *cps_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "CPS"; } static const char *cps_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int cps_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(cps_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("CyberPower", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } /* CPS Models like CP900EPFCLCD/CP1500PFCLCDa return a syntactically * legal but incorrect Report Descriptor whereby the Input High Transfer * Max/Min values are used for the Output Voltage Usage Item limits. * Additionally the Input Voltage LogMax is set incorrectly for EU models. * This corrects them by finding and applying fixed * voltage limits as being more appropriate. */ static int cps_fix_report_desc(HIDDevice_t *pDev, HIDDesc_t *pDesc_arg) { HIDData_t *pData; int retval = 0; int vendorID = pDev->VendorID; int productID = pDev->ProductID; if (vendorID != CPS_VENDORID || (productID != 0x0501 && productID != 0x0601)) { upsdebugx(3, "NOT Attempting Report Descriptor fix for UPS: " "Vendor: %04x, Product: %04x " "(vendor/product not matched)", (unsigned int)vendorID, (unsigned int)productID); return 0; } if (disable_fix_report_desc) { upsdebugx(3, "NOT Attempting Report Descriptor fix for UPS: " "Vendor: %04x, Product: %04x " "(got disable_fix_report_desc in config)", (unsigned int)vendorID, (unsigned int)productID); return 0; } upsdebugx(3, "Attempting Report Descriptor fix for UPS: " "Vendor: %04x, Product: %04x", (unsigned int)vendorID, (unsigned int)productID); /* Apply the fix cautiously by looking for input voltage, * high voltage transfer and output voltage report usages. * If the output voltage log min/max equals high voltage * transfer log min/max, then the bug is present. * * To fix it set both the input and output voltages to our * pre-defined settings CPS_VOLTAGE_LOGMIN/CPS_VOLTAGE_LOGMAX. */ if ((pData=FindObject_with_ID_Node(pDesc_arg, 16 /* 0x10 */, USAGE_POW_HIGH_VOLTAGE_TRANSFER))) { long hvt_logmin = pData->LogMin; long hvt_logmax = pData->LogMax; upsdebugx(4, "Original Report Descriptor: hvt input " "LogMin: %ld LogMax: %ld", hvt_logmin, hvt_logmax); if ((pData=FindObject_with_ID_Node(pDesc_arg, 18 /* 0x12 */, USAGE_POW_VOLTAGE))) { long output_logmin = pData->LogMin; long output_logmax = pData->LogMax; upsdebugx(4, "Original Report Descriptor: output " "LogMin: %ld LogMax: %ld", output_logmin, output_logmax); if (hvt_logmin == output_logmin && hvt_logmax == output_logmax) { pData->LogMin = CPS_VOLTAGE_LOGMIN; pData->LogMax = CPS_VOLTAGE_LOGMAX; upsdebugx(3, "Fixing Report Descriptor: " "set Output Voltage LogMin = %d, LogMax = %d", CPS_VOLTAGE_LOGMIN, CPS_VOLTAGE_LOGMAX); if ((pData=FindObject_with_ID_Node(pDesc_arg, 15 /* 0x0F */, USAGE_POW_VOLTAGE))) { long input_logmin = pData->LogMin; long input_logmax = pData->LogMax; upsdebugx(4, "Original Report Descriptor: input " "LogMin: %ld LogMax: %ld", input_logmin, input_logmax); /* TOTHINK: Should this be still about * the *HIGH* Voltage Transfer? Or LOW? */ if (hvt_logmin == input_logmin && hvt_logmax == input_logmax) { pData->LogMin = CPS_VOLTAGE_LOGMIN; pData->LogMax = CPS_VOLTAGE_LOGMAX; upsdebugx(3, "Fixing Report Descriptor: " "set Input Voltage LogMin = %d, LogMax = %d", CPS_VOLTAGE_LOGMIN, CPS_VOLTAGE_LOGMAX); } } retval = 1; } } } if ((pData=FindObject_with_ID_Node(pDesc_arg, 18 /* 0x12 */, USAGE_POW_VOLTAGE))) { HIDData_t *output_pData = pData; long output_logmin = output_pData->LogMin; long output_logmax = output_pData->LogMax; bool output_logmax_assumed = output_pData->assumed_LogMax; if ((pData=FindObject_with_ID_Node(pDesc_arg, 15 /* 0x0F */, USAGE_POW_VOLTAGE))) { HIDData_t *input_pData = pData; long input_logmin = input_pData->LogMin; long input_logmax = input_pData->LogMax; bool input_logmax_assumed = input_pData->assumed_LogMax; if ( (output_logmax_assumed || input_logmax_assumed) /* && output_logmax != input_logmax */ ) { /* We often get 0x0F ReportdId LogMax=65535 * and 0x12 ReportdId LogMax=255 because of * wrong encoding. See e.g. analysis at * https://github.com/networkupstools/nut/issues/1512#issuecomment-1224652911 */ upsdebugx(4, "Original Report Descriptor: output 0x12 " "LogMin: %ld LogMax: %ld (assumed: %s) Size: %" PRIu8, output_logmin, output_logmax, output_logmax_assumed ? "yes" : "no", output_pData->Size); upsdebugx(4, "Original Report Descriptor: input 0x0f " "LogMin: %ld LogMax: %ld (assumed: %s) Size: %" PRIu8, input_logmin, input_logmax, input_logmax_assumed ? "yes" : "no", input_pData->Size); /* First pass: try our hard-coded limits */ if (output_logmax_assumed && output_logmax < CPS_VOLTAGE_LOGMAX) { output_logmax = CPS_VOLTAGE_LOGMAX; } if (input_logmax_assumed && input_logmax < CPS_VOLTAGE_LOGMAX) { input_logmax = CPS_VOLTAGE_LOGMAX; } /* Second pass: align the two */ if (output_logmax_assumed && output_logmax < input_logmax) { output_logmax = input_logmax; } else if (input_logmax_assumed && input_logmax < output_logmax) { input_logmax = output_logmax; } /* Second pass: cut off according to bit-size * of each value */ if (input_logmax_assumed && input_pData->Size > 1 && input_pData->Size <= sizeof(long)*8 ) { /* Note: usually values are signed, but * here we are about compensating for * poorly encoded maximums, so limit by * 2^(size)-1, e.g. for "size==16" the * limit should be "2^16 - 1 = 65535"; * note that in HIDParse() we likely * set 65535 here in that case. See * also comments there (hidparser.c) * discussing signed/unsigned nuances. */ /* long sizeMax = (1L << (input_pData->Size - 1)) - 1; */ long sizeMax = (1L << (input_pData->Size)) - 1; if (input_logmax > sizeMax) { input_logmax = sizeMax; } } if (output_logmax_assumed && output_pData->Size > 1 && output_pData->Size <= sizeof(long)*8 ) { /* See comment above */ /* long sizeMax = (1L << (output_pData->Size - 1)) - 1; */ long sizeMax = (1L << (output_pData->Size)) - 1; if (output_logmax > sizeMax) { output_logmax = sizeMax; } } if (input_logmax != input_pData->LogMax) { upsdebugx(3, "Fixing Report Descriptor: " "set Input Voltage LogMax = %ld", input_logmax); input_pData->LogMax = input_logmax; retval = 1; } if (output_logmax != output_pData->LogMax) { upsdebugx(3, "Fixing Report Descriptor: " "set Output Voltage LogMax = %ld", output_logmax); output_pData->LogMax = output_logmax; retval = 1; } } } } /* Fix for nominal power reporting getting clipped by a too restrictive LogMax. */ if ((pData=FindObject_with_ID_Node(pDesc_arg, 24 /* 0x18 */, USAGE_POW_CONFIG_ACTIVE_POWER))) { long power_logmax = pData->LogMax; upsdebugx(4, "Original Report Descriptor: ConfigActivePower " "LogMin: %ld LogMax: %ld", pData->LogMin, power_logmax); if (power_logmax < CPS_NOMINALPWR_LOGMAX) { /* Set a generous maximum value that will not restrict UPS reporting. * * Current findings suggest that the values sent by the UPS are * accurate, but then get clipped by a too strict LogMax threshold: * https://github.com/networkupstools/nut/issues/2917#issuecomment-2832243477 */ pData->LogMax = CPS_NOMINALPWR_LOGMAX; upsdebugx(3, "Fixing Report Descriptor: " "set ConfigActivePower LogMax = %ld", pData->LogMax); retval = 1; } } if (!retval) { /* We did not `return 1` above, so... */ upsdebugx(3, "SKIPPED Report Descriptor fix for UPS: " "Vendor: %04x, Product: %04x " "(problematic conditions not matched)", (unsigned int)vendorID, (unsigned int)productID); } return retval; } subdriver_t cps_subdriver = { CPS_HID_VERSION, cps_claim, cps_utab, cps_hid2nut, cps_format_model, cps_format_mfr, cps_format_serial, cps_fix_report_desc, }; nut-2.8.4/drivers/hpe-pdu3-cis-mib.h0000644000175000017500000000213114777753336014074 00000000000000/* hpe_pdu_cis-mib.h - subdriver to monitor HPE_PDU_CIS SNMP devices with NUT * * Copyright (C) * 2011 - 2016 Arnaud Quette * 2022 Eaton (author: Arnaud Quette ) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef HPE_PDU3_CIS_MIB_H #define HPE_PDU3_CIS_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t hpe_pdu3_cis; #endif /* HPE_PDU3_CIS_MIB_H */ nut-2.8.4/drivers/libusb1.c0000644000175000017500000012377315044667045012467 00000000000000/*! * @file libusb1.c * @brief Generic USB communication backend (using libusb 1.0) * * @author Copyright (C) 2016 Eaton * Copyright (C) 2016 Arnaud Quette * Copyright (C) 2021-2024 Jim Klimov * * The logic of this file is ripped from mge-shut driver (also from * Arnaud Quette), which is a "HID over serial link" UPS driver for * Network UPS Tools * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * -------------------------------------------------------------------------- */ #include "config.h" /* for HAVE_LIBUSB_DETACH_KERNEL_DRIVER flag */ #include "common.h" /* for xmalloc, upsdebugx prototypes */ #include "usb-common.h" #include "nut_libusb.h" #include "nut_stdint.h" #define USB_DRIVER_NAME "USB communication driver (libusb 1.0)" #define USB_DRIVER_VERSION "0.50" /* driver description structure */ upsdrv_info_t comm_upsdrv_info = { USB_DRIVER_NAME, USB_DRIVER_VERSION, NULL, 0, { NULL } }; #define MAX_REPORT_SIZE 0x1800 static void nut_libusb_close(libusb_device_handle *udev); /*! Add USB-related driver variables with addvar() and dstate_setinfo(). * This removes some code duplication across the USB drivers. */ void nut_usb_addvars(void) { const struct libusb_version *v = libusb_get_version(); /* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */ addvar(VAR_VALUE, "vendor", "Regular expression to match UPS Manufacturer string"); addvar(VAR_VALUE, "product", "Regular expression to match UPS Product string"); addvar(VAR_VALUE, "serial", "Regular expression to match UPS Serial number"); addvar(VAR_VALUE, "vendorid", "Regular expression to match UPS Manufacturer numerical ID (4 digits hexadecimal)"); addvar(VAR_VALUE, "productid", "Regular expression to match UPS Product numerical ID (4 digits hexadecimal)"); addvar(VAR_VALUE, "bus", "Regular expression to match USB bus name"); addvar(VAR_VALUE, "device", "Regular expression to match USB device name"); addvar(VAR_VALUE, "busport", "Regular expression to match USB bus port name" #if (!defined WITH_USB_BUSPORT) || (!WITH_USB_BUSPORT) /* Not supported by this version of libusb1, * but let's not crash config parsing on * unknown keywords due to such nuances! :) */ " (tolerated but ignored in this build)" #endif ); /* Warning: this feature is inherently non-deterministic! * If you only care to know that at least one of your no-name UPSes is online, * this option can help. If you must really know which one, it will not! */ addvar(VAR_FLAG, "allow_duplicates", "If you have several UPS devices which may not be uniquely " "identified by options above, allow each driver instance with this " "option to take the first match if available, or try another " "(association of driver to device may vary between runs)"); addvar(VAR_VALUE, "usb_set_altinterface", "Force redundant call to usb_set_altinterface() (value=bAlternateSetting; default=0)"); addvar(VAR_VALUE, "usb_config_index", "Deeper tuning of USB communications for complex devices"); addvar(VAR_VALUE, "usb_hid_rep_index", "Deeper tuning of USB communications for complex devices"); addvar(VAR_VALUE, "usb_hid_desc_index", "Deeper tuning of USB communications for complex devices"); addvar(VAR_VALUE, "usb_hid_ep_in", "Deeper tuning of USB communications for complex devices"); addvar(VAR_VALUE, "usb_hid_ep_out", "Deeper tuning of USB communications for complex devices"); #ifdef LIBUSB_API_VERSION dstate_setinfo("driver.version.usb", "libusb-%u.%u.%u (API: 0x%08X)", v->major, v->minor, v->micro, (unsigned int)LIBUSB_API_VERSION); #else /* no LIBUSB_API_VERSION */ dstate_setinfo("driver.version.usb", "libusb-%u.%u.%u", v->major, v->minor, v->micro); #endif /* LIBUSB_API_VERSION */ upsdebugx(1, "Using USB implementation: %s", dstate_getinfo("driver.version.usb")); } /* invoke matcher against device */ static inline int matches(USBDeviceMatcher_t *matcher, USBDevice_t *device) { if (!matcher) { return 1; } return matcher->match_function(device, matcher->privdata); } /*! If needed, set the USB alternate interface. * * In NUT 2.7.2 and earlier, the following call was made unconditionally: * usb_set_altinterface(udev, 0); * * Although harmless on Linux and *BSD, this extra call prevents old Tripp Lite * devices from working on Mac OS X (presumably the OS is already setting * altinterface to 0). */ static int nut_libusb_set_altinterface(libusb_device_handle *udev) { int altinterface = 0, ret = 0; char *alt_string, *endp = NULL; if(testvar("usb_set_altinterface")) { alt_string = getval("usb_set_altinterface"); if(alt_string) { altinterface = (int)strtol(alt_string, &endp, 10); if(endp && !(endp[0] == 0)) { upslogx(LOG_WARNING, "%s: '%s' is not a valid number", __func__, alt_string); } if(altinterface < 0 || altinterface > 255) { upslogx(LOG_WARNING, "%s: setting bAlternateInterface to %d will probably not work", __func__, altinterface); } } /* set default interface */ upsdebugx(2, "%s: calling libusb_set_interface_alt_setting(udev, %d, %d)", __func__, usb_subdriver.hid_rep_index, altinterface); ret = libusb_set_interface_alt_setting(udev, usb_subdriver.hid_rep_index, altinterface); if(ret != 0) { upslogx(LOG_WARNING, "%s: libusb_set_interface_alt_setting(udev, %d, %d) returned %d (%s)", __func__, usb_subdriver.hid_rep_index, altinterface, ret, libusb_strerror((enum libusb_error)ret) ); } upslogx(LOG_NOTICE, "%s: libusb_set_interface_alt_setting() should not be necessary - " "please email the nut-upsdev list with information about your UPS.", __func__); } else { upsdebugx(3, "%s: skipped libusb_set_interface_alt_setting(udev, %d, 0)", __func__, usb_subdriver.hid_rep_index); } return ret; } static void nut_libusb_subdriver_defaults(usb_communication_subdriver_t *subdriver) { if (!getval("usb_config_index")) subdriver->usb_config_index = LIBUSB_DEFAULT_CONF_INDEX; if (!getval("usb_hid_rep_index")) subdriver->hid_rep_index = LIBUSB_DEFAULT_INTERFACE; if (!getval("usb_hid_desc_index")) subdriver->hid_desc_index = LIBUSB_DEFAULT_DESC_INDEX; if (!getval("usb_hid_ep_in")) subdriver->hid_ep_in = LIBUSB_DEFAULT_HID_EP_IN; if (!getval("usb_hid_ep_out")) subdriver->hid_ep_out = LIBUSB_DEFAULT_HID_EP_OUT; } /* On success, fill in the curDevice structure and return the report * descriptor length. On failure, return -1. * Note: When callback is not NULL, the report descriptor will be * passed to this function together with the udev and USBDevice_t * information. This callback should return a value > 0 if the device * is accepted, or < 1 if not. If it isn't accepted, the next device * (if any) will be tried, until there are no more devices left. */ static int nut_libusb_open(libusb_device_handle **udevp, USBDevice_t *curDevice, USBDeviceMatcher_t *matcher, int (*callback)(libusb_device_handle *udev, USBDevice_t *hd, usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen) ) { #if (defined HAVE_LIBUSB_DETACH_KERNEL_DRIVER) || (defined HAVE_LIBUSB_DETACH_KERNEL_DRIVER_NP) int retries; #endif /* libusb-1.0 usb_ctrl_charbufsize is uint16_t and we * want the rdlen vars signed - so taking a wider type */ int32_t rdlen1, rdlen2; /* report descriptor length, method 1+2 */ USBDeviceMatcher_t *m; libusb_device **devlist; ssize_t devcount = 0; size_t devnum; struct libusb_device_descriptor dev_desc; struct libusb_config_descriptor *conf_desc = NULL; const struct libusb_interface_descriptor *if_desc; libusb_device_handle *udev; uint8_t bus_num, device_addr; #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) uint8_t bus_port; #endif int ret, res; unsigned char buf[20]; const unsigned char *p; char string[256]; int i; int count_open_EACCESS = 0; int count_open_errors = 0; int count_open_attempts = 0; /* report descriptor */ unsigned char rdbuf[MAX_REPORT_SIZE]; int32_t rdlen; static int usb_hid_number_opts_parsed = 0; if (!usb_hid_number_opts_parsed) { const char *s; unsigned short us = 0; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE # pragma GCC diagnostic ignored "-Wtautological-type-limit-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if ((s = getval("usb_config_index"))) { if (!str_to_ushort(s, &us, 16) || (us > USB_CTRL_CFGINDEX_MAX)) { fatalx(EXIT_FAILURE, "%s: could not parse usb_config_index", __func__); } usb_subdriver.usb_config_index = (usb_ctrl_cfgindex)us; } if ((s = getval("usb_hid_rep_index"))) { if (!str_to_ushort(s, &us, 16) || (us > USB_CTRL_REPINDEX_MAX)) { fatalx(EXIT_FAILURE, "%s: could not parse usb_hid_rep_index", __func__); } usb_subdriver.hid_rep_index = (usb_ctrl_repindex)us; } if ((s = getval("usb_hid_desc_index"))) { if (!str_to_ushort(s, &us, 16) || (us > USB_CTRL_DESCINDEX_MAX)) { fatalx(EXIT_FAILURE, "%s: could not parse usb_hid_desc_index", __func__); } usb_subdriver.hid_desc_index = (usb_ctrl_descindex)us; } if ((s = getval("usb_hid_ep_in"))) { if (!str_to_ushort(s, &us, 16) || (us > USB_CTRL_ENDPOINT_MAX)) { fatalx(EXIT_FAILURE, "%s: could not parse usb_hid_ep_in", __func__); } usb_subdriver.hid_ep_in = (usb_ctrl_endpoint)us; } if ((s = getval("usb_hid_ep_out"))) { if (!str_to_ushort(s, &us, 16) || (us > USB_CTRL_ENDPOINT_MAX)) { fatalx(EXIT_FAILURE, "%s: could not parse usb_hid_ep_out", __func__); } usb_subdriver.hid_ep_out = (usb_ctrl_endpoint)us; } #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE) ) # pragma GCC diagnostic pop #endif usb_hid_number_opts_parsed = 1; } /* libusb base init */ if (libusb_init(NULL) < 0) { libusb_exit(NULL); fatal_with_errno(EXIT_FAILURE, "Failed to init libusb 1.0"); } /* TODO: Find a place for this, from Windows branch made for libusb0.c */ /* #ifdef WIN32 struct usb_bus *busses; busses = usb_get_busses(); #endif // WIN32 */ #ifndef __linux__ /* SUN_LIBUSB (confirmed to work on Solaris and FreeBSD) */ /* Causes a double free corruption in linux if device is detached! */ /* nut_libusb_close(*udevp); */ if (*udevp) libusb_close(*udevp); #endif devcount = libusb_get_device_list(NULL, &devlist); /* devcount may be < 0, loop will get skipped; * its SSIZE_MAX < SIZE_MAX for devnum */ for (devnum = 0; (ssize_t)devnum < devcount; devnum++) { /* int if_claimed = 0; */ libusb_device *device = devlist[devnum]; count_open_attempts++; libusb_get_device_descriptor(device, &dev_desc); upsdebugx(2, "Checking device %" PRIuSIZE " of %" PRIiSIZE " (%04X/%04X)", devnum + 1, devcount, dev_desc.idVendor, dev_desc.idProduct); /* supported vendors are now checked by the supplied matcher */ /* open the device */ ret = libusb_open(device, udevp); if (ret != 0) { upsdebugx(1, "Failed to open device (%04X/%04X), skipping: %s", dev_desc.idVendor, dev_desc.idProduct, libusb_strerror((enum libusb_error)ret)); count_open_errors++; if (ret == LIBUSB_ERROR_ACCESS) { count_open_EACCESS++; } continue; } udev = *udevp; /* collect the identifying information of this device. Note that this is safe, because there's no need to claim an interface for this (and therefore we do not yet need to detach any kernel drivers). */ free(curDevice->Vendor); free(curDevice->Product); free(curDevice->Serial); free(curDevice->Bus); free(curDevice->Device); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) free(curDevice->BusPort); #endif memset(curDevice, '\0', sizeof(*curDevice)); /* Keep the list of items in sync with those matched by * drivers/libusb0.c and tools/nut-scanner/scan_usb.c: */ bus_num = libusb_get_bus_number(device); curDevice->Bus = (char *)malloc(4); if (curDevice->Bus == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } sprintf(curDevice->Bus, "%03d", bus_num); device_addr = libusb_get_device_address(device); curDevice->Device = (char *)malloc(4); if (curDevice->Device == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } if (device_addr > 0) { /* 0 means not available, e.g. lack of platform support */ sprintf(curDevice->Device, "%03d", device_addr); } else { if (devnum <= 999) { /* Log visibly so users know their number discovered * from `lsusb` or `dmesg` (if any) was ignored */ upsdebugx(0, "%s: invalid libusb device address %" PRIu8 ", " "falling back to enumeration order counter %" PRIuSIZE, __func__, device_addr, devnum); sprintf(curDevice->Device, "%03d", (int)devnum); } else { upsdebugx(1, "%s: invalid libusb device address %" PRIu8, __func__, device_addr); free(curDevice->Device); curDevice->Device = NULL; } } #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) bus_port = libusb_get_port_number(device); curDevice->BusPort = (char *)malloc(4); if (curDevice->BusPort == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } if (bus_port > 0) { sprintf(curDevice->BusPort, "%03d", bus_port); } else { upsdebugx(1, "%s: invalid libusb bus number %i", __func__, bus_port); free(curDevice->BusPort); curDevice->BusPort = NULL; } #endif curDevice->VendorID = dev_desc.idVendor; curDevice->ProductID = dev_desc.idProduct; curDevice->bcdDevice = dev_desc.bcdDevice; if (dev_desc.iManufacturer) { ret = nut_usb_get_string(udev, dev_desc.iManufacturer, string, sizeof(string)); if (ret > 0) { curDevice->Vendor = strdup(string); if (curDevice->Vendor == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } } else { upsdebugx(1, "%s: get Manufacturer string failed", __func__); } } if (dev_desc.iProduct) { ret = nut_usb_get_string(udev, dev_desc.iProduct, string, sizeof(string)); if (ret > 0) { curDevice->Product = strdup(string); if (curDevice->Product == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } } else { upsdebugx(1, "%s: get Product string failed", __func__); } } if (dev_desc.iSerialNumber) { ret = nut_usb_get_string(udev, dev_desc.iSerialNumber, string, sizeof(string)); if (ret > 0) { curDevice->Serial = strdup(string); if (curDevice->Serial == NULL) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "Out of memory"); } } else { upsdebugx(1, "%s: get Serial Number string failed", __func__); } } upsdebugx(2, "- VendorID: %04x", curDevice->VendorID); upsdebugx(2, "- ProductID: %04x", curDevice->ProductID); upsdebugx(2, "- Manufacturer: %s", curDevice->Vendor ? curDevice->Vendor : "unknown"); upsdebugx(2, "- Product: %s", curDevice->Product ? curDevice->Product : "unknown"); upsdebugx(2, "- Serial Number: %s", curDevice->Serial ? curDevice->Serial : "unknown"); upsdebugx(2, "- Bus: %s", curDevice->Bus ? curDevice->Bus : "unknown"); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) upsdebugx(2, "- Bus Port: %s", curDevice->BusPort ? curDevice->BusPort : "unknown"); #endif upsdebugx(2, "- Device: %s", curDevice->Device ? curDevice->Device : "unknown"); upsdebugx(2, "- Device release number: %04x", curDevice->bcdDevice); /* FIXME: extend to Eaton OEMs (HP, IBM, ...) */ if ((curDevice->VendorID == 0x463) && (curDevice->bcdDevice == 0x0202)) { if (!getval("usb_hid_desc_index")) usb_subdriver.hid_desc_index = 1; } upsdebugx(2, "Trying to match device"); for (m = matcher; m; m=m->next) { ret = matches(m, curDevice); if (ret==0) { upsdebugx(2, "Device does not match - skipping"); goto next_device; } else if (ret==-1) { libusb_free_device_list(devlist, 1); fatal_with_errno(EXIT_FAILURE, "matcher"); #ifndef HAVE___ATTRIBUTE__NORETURN # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunreachable-code" # endif goto next_device; # if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) # pragma GCC diagnostic pop # endif #endif } else if (ret==-2) { upsdebugx(2, "matcher: unspecified error"); goto next_device; } } /* If we got here, none of the matchers said * that the device is not what we want. */ upsdebugx(2, "Device matches"); upsdebugx(2, "Reading configuration descriptor %d of %d", usb_subdriver.usb_config_index+1, dev_desc.bNumConfigurations); ret = libusb_get_config_descriptor(device, (uint8_t)usb_subdriver.usb_config_index, &conf_desc); /*ret = libusb_get_active_config_descriptor(device, &conf_desc);*/ if (ret < 0) upsdebugx(2, "result: %i (%s)", ret, libusb_strerror((enum libusb_error)ret)); /* Now we have matched the device we wanted. Claim it. */ #if defined(HAVE_LIBUSB_KERNEL_DRIVER_ACTIVE) && defined(HAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVER) /* Due to the way FreeBSD implements libusb_set_auto_detach_kernel_driver(), * check to see if the kernel driver is active before setting * the auto-detach flag. Otherwise, libusb_claim_interface() * with the auto-detach flag only works if the driver is * running as root. * * Is the kernel driver active? Consider the unimplemented * return code to be equivalent to inactive here. */ if((ret = libusb_kernel_driver_active(udev, usb_subdriver.hid_rep_index)) == 1) { upsdebugx(3, "libusb_kernel_driver_active() returned 1 (driver active)"); /* Try the auto-detach kernel driver method. * This function is not available on FreeBSD 10.1-10.3 */ if ((ret = libusb_set_auto_detach_kernel_driver (udev, 1)) != LIBUSB_SUCCESS) { upsdebugx(1, "failed to set kernel driver auto-detach " "driver flag for USB device: %s", libusb_strerror((enum libusb_error)ret)); } else { upsdebugx(2, "successfully set kernel driver auto-detach flag"); } } else { upsdebugx(3, "libusb_kernel_driver_active() returned %d: %s", ret, libusb_strerror((enum libusb_error)ret)); } #endif #if (defined HAVE_LIBUSB_DETACH_KERNEL_DRIVER) || (defined HAVE_LIBUSB_DETACH_KERNEL_DRIVER_NP) /* Then, try the explicit detach method. * This function is available on FreeBSD 10.1-10.3 */ # ifdef WIN32 /* TODO: Align with libusb1 - initially from Windows branch made against libusb0 */ libusb_set_configuration(udev, 1); # endif /* WIN32 */ retries = 3; while ((ret = libusb_claim_interface(udev, usb_subdriver.hid_rep_index)) != LIBUSB_SUCCESS) { upsdebugx(2, "failed to claim USB device: %s", libusb_strerror((enum libusb_error)ret)); if (ret == LIBUSB_ERROR_BUSY && testvar("allow_duplicates")) { upsdebugx(2, "Configured to allow_duplicates so looking for another similar device"); goto next_device; } # ifdef HAVE_LIBUSB_DETACH_KERNEL_DRIVER if ((ret = libusb_detach_kernel_driver(udev, usb_subdriver.hid_rep_index)) != LIBUSB_SUCCESS) { # else /* if defined HAVE_LIBUSB_DETACH_KERNEL_DRIVER_NP) */ if ((ret = libusb_detach_kernel_driver_np(udev, usb_subdriver.hid_rep_index)) != LIBUSB_SUCCESS) { # endif if (ret == LIBUSB_ERROR_NOT_FOUND) { /* logged as "Entity not found" if this persists */ upsdebugx(2, "Kernel driver already detached"); } else { upsdebugx(1, "failed to detach kernel driver from USB device: %s", libusb_strerror((enum libusb_error)ret)); } } else { upsdebugx(2, "detached kernel driver from USB device..."); } if (retries-- > 0) { continue; } libusb_free_config_descriptor(conf_desc); libusb_free_device_list(devlist, 1); fatalx(EXIT_FAILURE, "Can't claim USB device [%04x:%04x]@%d/%d/%d: %s", curDevice->VendorID, curDevice->ProductID, usb_subdriver.usb_config_index, usb_subdriver.hid_rep_index, usb_subdriver.hid_desc_index, libusb_strerror((enum libusb_error)ret)); } #else if ((ret = libusb_claim_interface(udev, usb_subdriver.hid_rep_index)) != LIBUSB_SUCCESS ) { if (ret == LIBUSB_ERROR_BUSY && testvar("allow_duplicates")) { upsdebugx(2, "Configured to allow_duplicates so looking for another similar device"); goto next_device; } libusb_free_config_descriptor(conf_desc); libusb_free_device_list(devlist, 1); fatalx(EXIT_FAILURE, "Can't claim USB device [%04x:%04x]@%d/%d/%d: %s", curDevice->VendorID, curDevice->ProductID, usb_subdriver.usb_config_index, usb_subdriver.hid_rep_index, usb_subdriver.hid_desc_index, libusb_strerror((enum libusb_error)ret)); } #endif /* if_claimed = 1; */ upsdebugx(2, "Claimed interface %d successfully", usb_subdriver.hid_rep_index); nut_libusb_set_altinterface(udev); /* Did the driver provide a callback method for any further * device acceptance checks (e.g. when same ID is supported * by several sub-drivers, differing by vendor/model strings)? */ if (!callback) { libusb_free_config_descriptor(conf_desc); libusb_free_device_list(devlist, 1); return 1; } if (!conf_desc) { /* ?? this should never happen */ upsdebugx(2, " Couldn't retrieve config descriptor [%04x:%04x]@%d", curDevice->VendorID, curDevice->ProductID, usb_subdriver.usb_config_index ); goto next_device; } rdlen1 = -1; rdlen2 = -1; /* Get HID descriptor */ /* FIRST METHOD: ask for HID descriptor directly. */ /* libusb0: USB_ENDPOINT_IN + 1 */ res = libusb_control_transfer(udev, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_STANDARD|LIBUSB_RECIPIENT_INTERFACE, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_HID << 8) + usb_subdriver.hid_desc_index, usb_subdriver.hid_rep_index, buf, 0x9, USB_TIMEOUT); if (res < 0) { upsdebugx(2, "Unable to get HID descriptor (%s)", libusb_strerror((enum libusb_error)res)); } else if (res < 9) { upsdebugx(2, "HID descriptor too short (expected %d, got %d)", 9, res); } else { upsdebugx(2, "Retrieved HID descriptor (expected %d, got %d)", 9, res); upsdebug_hex(3, "HID descriptor, method 1", buf, 9); rdlen1 = ((uint8_t)buf[7]) | (((uint8_t)buf[8]) << 8); } if (rdlen1 < -1) { upsdebugx(2, "Warning: HID descriptor, method 1 failed"); } upsdebugx(3, "HID descriptor length (method 1) %d", rdlen1); /* SECOND METHOD: find HID descriptor among "extra" bytes of interface descriptor, i.e., bytes tucked onto the end of descriptor 2. */ /* Note: on some broken UPS's (e.g. Tripp Lite Smart1000LCD), only this second method gives the correct result */ /* for now, we always assume configuration 0, interface 0, altsetting 0, as above. */ if_desc = &(conf_desc->interface[usb_subdriver.hid_rep_index].altsetting[0]); for (i = 0; i < if_desc->extra_length; i += if_desc->extra[i]) { upsdebugx(4, "i=%d, extra[i]=%02x, extra[i+1]=%02x", i, if_desc->extra[i], if_desc->extra[i+1]); if (i+9 <= if_desc->extra_length && if_desc->extra[i] >= 9 && if_desc->extra[i+1] == 0x21) { p = &if_desc->extra[i]; upsdebug_hex(3, "HID descriptor, method 2", p, 9); rdlen2 = ((uint8_t)p[7]) | (((uint8_t)p[8]) << 8); break; } } /* we can now free the config descriptor */ libusb_free_config_descriptor(conf_desc); if (rdlen2 < -1) { upsdebugx(2, "Warning: HID descriptor, method 2 failed"); } upsdebugx(3, "HID descriptor length (method 2) %d", rdlen2); /* when available, always choose the second value, as it seems to be more reliable (it is the one reported e.g. by lsusb). Note: if the need arises, can change this to use the maximum of the two values instead. */ if ((curDevice->VendorID == 0x463) && (curDevice->bcdDevice == 0x0202)) { upsdebugx(1, "Eaton device v2.02. Using full report descriptor"); rdlen = rdlen1; } else { rdlen = rdlen2 >= 0 ? rdlen2 : rdlen1; } if (rdlen < 0) { upsdebugx(2, "Unable to retrieve any HID descriptor"); goto next_device; } if (rdlen1 >= 0 && rdlen2 >= 0 && rdlen1 != rdlen2) { upsdebugx(2, "Warning: two different HID descriptors retrieved " "(Reportlen = %d vs. %d)", rdlen1, rdlen2); } upsdebugx(2, "HID descriptor length %d", rdlen); if (rdlen > (int)sizeof(rdbuf)) { upsdebugx(2, "HID descriptor too long %d (max %d)", rdlen, (int)sizeof(rdbuf)); goto next_device; } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif if ((uintmax_t)rdlen > UINT16_MAX) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic pop #endif upsdebugx(2, "HID descriptor too long %d (max %" PRIuMAX ")", rdlen, (uintmax_t)UINT16_MAX); goto next_device; } /* libusb0: USB_ENDPOINT_IN + 1 */ res = libusb_control_transfer(udev, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_STANDARD|LIBUSB_RECIPIENT_INTERFACE, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8) + usb_subdriver.hid_desc_index, usb_subdriver.hid_rep_index, rdbuf, (uint16_t)rdlen, USB_TIMEOUT); if (res < 0) { upsdebug_with_errno(2, "Unable to get Report descriptor"); goto next_device; } if (res < rdlen) { #ifndef WIN32 upsdebugx(2, "Warning: report descriptor too short " "(expected %d, got %d)", rdlen, res); #else /* WIN32 */ /* https://github.com/networkupstools/nut/issues/1690#issuecomment-1455206002 */ upsdebugx(0, "Warning: report descriptor too short " "(expected %d, got %d)", rdlen, res); upsdebugx(0, "Please check your Windows Device Manager: " "perhaps the UPS was recognized by default OS\n" "driver such as HID UPS Battery (hidbatt.sys, " "hidusb.sys or similar). It could have been\n" "\"restored\" by Windows Update. You can try " "https://zadig.akeo.ie/ to handle it with\n" "either WinUSB, libusb0.sys or libusbK.sys."); #endif /* WIN32 */ rdlen = res; /* correct rdlen if necessary */ } if (rdlen < USB_CTRL_CHARBUFSIZE_MIN || (uintmax_t)rdlen > (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX ) { upsdebugx(2, "Report descriptor length is out of range on this device: " "should be %" PRIdMAX " < %d < %" PRIuMAX, (intmax_t)USB_CTRL_CHARBUFSIZE_MIN, rdlen, (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX); goto next_device; } res = callback(udev, curDevice, rdbuf, (usb_ctrl_charbufsize)rdlen); if (res < 1) { upsdebugx(2, "Caller doesn't like this device"); goto next_device; } upsdebugx(2, "Report descriptor retrieved (Reportlen = %d)", rdlen); upsdebugx(2, "Found HID device"); upsdebugx(3, "Using default, detected or customized USB HID numbers: " "usb_config_index=%d usb_hid_rep_index=%d " "usb_hid_desc_index=%d " "usb_hid_ep_in=%d usb_hid_ep_out=%d", usb_subdriver.usb_config_index, usb_subdriver.hid_rep_index, usb_subdriver.hid_desc_index, usb_subdriver.hid_ep_in, usb_subdriver.hid_ep_out ); fflush(stdout); libusb_free_device_list(devlist, 1); return rdlen; next_device: /* usb_release_interface() sometimes blocks and goes into uninterruptible sleep. So don't do it. */ /* if (if_claimed) libusb_release_interface(udev, usb_subdriver.hid_rep_index); */ libusb_close(udev); /* reset any parameters modified by unmatched drivers back to defaults */ nut_libusb_subdriver_defaults(&usb_subdriver); } /* If we got here, we did not return a successfully chosen device above */ *udevp = NULL; libusb_free_device_list(devlist, 1); upsdebugx(2, "libusb1: No appropriate HID device found"); fflush(stdout); if (devcount < 1 || count_open_attempts == 0) { upslogx(LOG_WARNING, "libusb1: Could not open any HID devices: " "no USB buses (or devices) found"); } else if (count_open_errors > 0 && count_open_errors == count_open_EACCESS ) { upslogx(LOG_WARNING, "libusb1: Could not open any HID devices: " "insufficient permissions on everything"); if (count_open_attempts > count_open_errors) { upslogx(LOG_WARNING, "libusb1: except %d devices " "tried but not matching the " "requested criteria", count_open_attempts - count_open_errors); } suggest_NDE_conflict(); /* FIXME: Wiki names are inherently volatile; * maybe keep a more persistent copy in the * NUT-website with some knowledge-base ID? */ upsdebugx(1, "For more ideas, please check a NUT GitHub Wiki page named like " "https://github.com/networkupstools/nut/wiki/%%22Insufficient-permissions%%22-when-starting-USB-drivers"); } #ifdef WIN32 upsdebugx(0, "Please check your Windows Device Manager: " "perhaps the UPS was recognized by default OS\n" "driver such as HID UPS Battery (hidbatt.sys, " "hidusb.sys or similar). It could have been\n" "\"restored\" by Windows Update. You can try " "https://zadig.akeo.ie/ to handle it with\n" "either WinUSB, libusb0.sys or libusbK.sys."); #endif /* WIN32 */ return -1; } /* * Error handler for usb_get/set_* functions. Return value > 0 success, * 0 unknown or temporary failure (ignored), < 0 permanent failure (reconnect) */ static int nut_libusb_strerror(const int ret, const char *desc) { if (ret > 0) { return ret; } switch(ret) { #if 0 /* FIXME: not sure how to map these ones! */ case LIBUSB_ERROR_INVALID_PARAM: /** Invalid parameter */ /** System call interrupted (perhaps due to signal) */ case LIBUSB_ERROR_INTERRUPTED: /** Insufficient memory */ case LIBUSB_ERROR_NO_MEM: #endif case LIBUSB_ERROR_BUSY: /** Resource busy */ case LIBUSB_ERROR_NO_DEVICE: /** No such device (it may have been disconnected) */ case LIBUSB_ERROR_ACCESS: /** Access denied (insufficient permissions) */ case LIBUSB_ERROR_IO: /** Input/output error */ case LIBUSB_ERROR_NOT_FOUND: /** Entity not found */ case LIBUSB_ERROR_PIPE: /** Pipe error */ /** Operation not supported or unimplemented on this platform */ case LIBUSB_ERROR_NOT_SUPPORTED: upslogx(LOG_DEBUG, "%s: %s", desc, libusb_strerror((enum libusb_error)ret)); return ret; case LIBUSB_ERROR_TIMEOUT: /** Operation timed out */ upsdebugx(2, "%s: Connection timed out", desc); return 0; #ifndef WIN32 case LIBUSB_ERROR_OVERFLOW: /** Overflow */ # ifdef EPROTO /* FIXME: not sure how to map this one! */ case -EPROTO: /* Protocol error */ # endif upsdebugx(2, "%s: %s", desc, libusb_strerror((enum libusb_error)ret)); return 0; #endif /* !WIN32 */ case LIBUSB_SUCCESS: /** TOTHINK: Should this be quiet? */ case LIBUSB_ERROR_OTHER: /** Other error */ default: /** Undetermined, log only */ upslogx(LOG_DEBUG, "%s: %s", desc, libusb_strerror((enum libusb_error)ret)); return 0; } } /* return the report of ID=type in report * return -1 on failure, report length on success */ /* Expected evaluated types for the API: * static int nut_libusb_get_report(libusb_device_handle *udev, * int ReportId, unsigned char *raw_buf, int ReportSize) */ static int nut_libusb_get_report( libusb_device_handle *udev, usb_ctrl_repindex ReportId, usb_ctrl_charbuf raw_buf, usb_ctrl_charbufsize ReportSize) { int ret; upsdebugx(4, "Entering libusb_get_report"); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif if (!udev || ReportId < 0 || (uintmax_t)ReportId > UINT16_MAX || ReportSize < 0 || (uintmax_t)ReportSize > UINT16_MAX ) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic pop #endif return 0; } /* libusb0: USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE */ ret = libusb_control_transfer(udev, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, 0x01, /* HID_REPORT_GET */ (uint16_t)ReportId + (0x03<<8), /* HID_REPORT_TYPE_FEATURE */ usb_subdriver.hid_rep_index, raw_buf, (uint16_t)ReportSize, USB_TIMEOUT); /* Ignore "protocol stall" (for unsupported request) on control endpoint */ if (ret == LIBUSB_ERROR_PIPE) { return 0; } return nut_libusb_strerror(ret, __func__); } /* Expected evaluated types for the API: * static int nut_libusb_set_report(libusb_device_handle *udev, * int ReportId, unsigned char *raw_buf, int ReportSize) */ static int nut_libusb_set_report( libusb_device_handle *udev, usb_ctrl_repindex ReportId, usb_ctrl_charbuf raw_buf, usb_ctrl_charbufsize ReportSize) { int ret; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif if (!udev || ReportId < 0 || (uintmax_t)ReportId > UINT16_MAX || ReportSize < 0 || (uintmax_t)ReportSize > UINT16_MAX ) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic pop #endif return 0; } /* libusb0: USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE */ ret = libusb_control_transfer(udev, LIBUSB_ENDPOINT_OUT|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE, 0x09, /* HID_REPORT_SET = 0x09*/ (uint16_t)ReportId + (0x03<<8), /* HID_REPORT_TYPE_FEATURE */ usb_subdriver.hid_rep_index, raw_buf, (uint16_t)ReportSize, USB_TIMEOUT); /* Ignore "protocol stall" (for unsupported request) on control endpoint */ if (ret == LIBUSB_ERROR_PIPE) { return 0; } return nut_libusb_strerror(ret, __func__); } /* Expected evaluated types for the API: * static int nut_libusb_get_string(libusb_device_handle *udev, * uint8_t StringIdx, unsigned char *buf, uint16_t buflen) */ static int nut_libusb_get_string( libusb_device_handle *udev, usb_ctrl_strindex StringIdx, char *buf, usb_ctrl_charbufsize buflen) { int ret; if (!udev || StringIdx < 1 || buflen < 1) { return -1; } ret = nut_usb_get_string(udev, (uint8_t)StringIdx, buf, (int)buflen); /** 0 can be seen as an empty string, or as LIBUSB_SUCCESS for * logging below - also tends to happen */ if (ret == 0) { size_t len = strlen(buf); upsdebugx(2, "%s: nut_usb_get_string() returned " "0 (might be just LIBUSB_SUCCESS code), " "actual buf length is %" PRIuSIZE, __func__, len); /* if (len) */ return len; /* else may log "nut_libusb_get_string: Success" and return 0 below */ } return nut_libusb_strerror(ret, __func__); } /* Expected evaluated types for the API: * static int nut_libusb_get_interrupt(libusb_device_handle *udev, * unsigned char *buf, int bufsize, int timeout) */ static int nut_libusb_get_interrupt( libusb_device_handle *udev, usb_ctrl_charbuf buf, usb_ctrl_charbufsize bufsize, usb_ctrl_timeout_msec timeout) { int ret, tmpbufsize; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif if (!udev || bufsize < 0 || (uintmax_t)bufsize > (uintmax_t)INT_MAX ) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic pop #endif return -1; } /* NOTE: With all the fuss about word sized arguments, * the libusb_interrupt_transfer() lengths are about ints: * int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle, * unsigned char endpoint, unsigned char *data, int length, * int *actual_length, unsigned int timeout); */ tmpbufsize = (int)bufsize; /* FIXME: hardcoded interrupt EP => need to get EP descr for IF descr */ /* ret = libusb_interrupt_transfer(udev, 0x81, buf, bufsize, &bufsize, timeout); */ /* libusb0: ret = usb_interrupt_read(udev, USB_ENDPOINT_IN + usb_subdriver.hid_ep_in, (char *)buf, bufsize, timeout); */ /* Interrupt EP is LIBUSB_ENDPOINT_IN with offset defined in hid_ep_in, which is 0 by default, unless overridden in subdriver. */ ret = libusb_interrupt_transfer(udev, LIBUSB_ENDPOINT_IN + usb_subdriver.hid_ep_in, (unsigned char *)buf, tmpbufsize, &tmpbufsize, timeout); /* Clear stall condition */ if (ret == LIBUSB_ERROR_PIPE) { ret = libusb_clear_halt(udev, 0x81); } /* In case of success, return the operation size, as done with libusb 0.1 */ if (ret == LIBUSB_SUCCESS) { if (tmpbufsize < 0 || (uintmax_t)tmpbufsize > (uintmax_t)USB_CTRL_CHARBUFSIZE_MAX ) { return -1; } ret = (usb_ctrl_charbufsize)tmpbufsize; } return nut_libusb_strerror(ret, __func__); } static void nut_libusb_close(libusb_device_handle *udev) { if (!udev) { return; } /* usb_release_interface() sometimes blocks and goes * into uninterruptible sleep. So don't do it. */ /* libusb_release_interface(udev, usb_subdriver.hid_rep_index); */ libusb_close(udev); libusb_exit(NULL); } usb_communication_subdriver_t usb_subdriver = { USB_DRIVER_NAME, USB_DRIVER_VERSION, nut_libusb_open, nut_libusb_close, nut_libusb_get_report, nut_libusb_set_report, nut_libusb_get_string, nut_libusb_get_interrupt, LIBUSB_DEFAULT_CONF_INDEX, LIBUSB_DEFAULT_INTERFACE, LIBUSB_DEFAULT_DESC_INDEX, LIBUSB_DEFAULT_HID_EP_IN, LIBUSB_DEFAULT_HID_EP_OUT }; nut-2.8.4/drivers/mge-hid.c0000644000175000017500000032041115044656702012422 00000000000000/* mge-hid.c - data to monitor Eaton / MGE HID (USB and serial) devices * * Copyright (C) * 2003 - 2015 Arnaud Quette * 2015 - 2024 Eaton / Arnaud Quette * 2020 - 2025 Jim Klimov * 2024 - 2025 "DaRK AnGeL" <28630321+masterwishx@users.noreply.github.com> * * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* TODO list: * - better processing of FW info: * * some models (HP R5000) include firmware.aux (00.01.0021;00.01.00) * * other (9130) need more processing (0128 => 1.28) * ... * - better handling of input.transfer.* (need dstate_addrange) * - outlet management logic (Ie, for outlet.X.load.{on,off}.delay * => use outlet.X.delay.{start,stop} */ #include "main.h" /* for getval() */ #include "usbhid-ups.h" #include "mge-hid.h" #include "nut_float.h" #include "timehead.h" #ifdef WIN32 # include "wincompat.h" # ifndef LDOUBLE # ifdef HAVE_LONG_DOUBLE # define LDOUBLE long double # else # define LDOUBLE double # endif # endif #endif /* WIN32 */ #define MGE_HID_VERSION "MGE HID 1.55" /* (prev. MGE Office Protection Systems, prev. MGE UPS SYSTEMS) */ /* Eaton */ #define MGE_VENDORID 0x0463 /* Dell */ #define DELL_VENDORID 0x047c /* Powerware */ #define POWERWARE_VENDORID 0x0592 /* Hewlett Packard */ #define HP_VENDORID 0x03f0 /* AEG */ #define AEG_VENDORID 0x2b2d /* Note that normally this VID is handled by Liebert/Phoenixtec HID mapping, * here it is just for for AEG PROTECT NAS devices: */ /* Phoenixtec Power Co., Ltd */ #define PHOENIXTEC 0x06da /* IBM */ #define IBM_VENDORID 0x04b3 /* KSTAR under Berkeley Varitronics Systems ID */ #define KSTAR_VENDORID 0x09d6 #if !((defined SHUT_MODE) && SHUT_MODE) #include "usb-common.h" /* USB IDs device table */ static usb_device_id_t mge_usb_device_table[] = { /* various models */ { USB_DEVICE(MGE_VENDORID, 0x0001), NULL }, { USB_DEVICE(MGE_VENDORID, 0xffff), NULL }, /* various models */ { USB_DEVICE(DELL_VENDORID, 0xffff), NULL }, /* PW 9140 */ { USB_DEVICE(POWERWARE_VENDORID, 0x0004), NULL }, /* R/T3000 */ { USB_DEVICE(HP_VENDORID, 0x1fe5), NULL }, /* R/T3000 */ { USB_DEVICE(HP_VENDORID, 0x1fe6), NULL }, /* various models */ { USB_DEVICE(HP_VENDORID, 0x1fe7), NULL }, { USB_DEVICE(HP_VENDORID, 0x1fe8), NULL }, /* PROTECT B / NAS */ { USB_DEVICE(AEG_VENDORID, 0xffff), NULL }, { USB_DEVICE(PHOENIXTEC, 0xffff), NULL }, /* 6000 VA LCD 4U Rack UPS; 5396-1Kx */ { USB_DEVICE(IBM_VENDORID, 0x0001), NULL }, /* MasterPower MF-UPS650VA under KSTAR vendorid (can also be under MGE) * MicroPower models were also reported */ { USB_DEVICE(KSTAR_VENDORID, 0x0001), NULL }, /* Terminating entry */ { 0, 0, NULL } }; #endif /* !SHUT_MODE => USB */ typedef enum { MGE_DEFAULT_OFFLINE = 0, MGE_PEGASUS = 0x100, MGE_3S = 0x110, /* All offline models have type value < 200! */ MGE_DEFAULT = 0x200, /* for line-interactive and online models */ MGE_EVOLUTION = 0x300, /* MGE Evolution series */ MGE_EVOLUTION_650, MGE_EVOLUTION_850, MGE_EVOLUTION_1150, MGE_EVOLUTION_S_1250, MGE_EVOLUTION_1550, MGE_EVOLUTION_S_1750, MGE_EVOLUTION_2000, MGE_EVOLUTION_S_2500, MGE_EVOLUTION_S_3000, MGE_PULSAR_M = 0x400, /* MGE Pulsar M series */ MGE_PULSAR_M_2200, MGE_PULSAR_M_3000, MGE_PULSAR_M_3000_XL, EATON_5P = 0x500, /* Eaton 5P / 5PX / 5SC series; possibly 5S also */ EATON_9E = 0x900 /* Eaton 9E entry-level / 9SX / 9PX series */ } models_type_t; /* Default to line-interactive or online (ie, not offline). * This is then overridden for offline, through mge_model_names */ static models_type_t mge_type = MGE_DEFAULT; /* Countries definition, for region specific settings and features */ typedef enum { COUNTRY_UNKNOWN = -1, COUNTRY_EUROPE = 0, COUNTRY_US, /* Special European models, which also supports 200 / 208 V */ COUNTRY_EUROPE_208, COUNTRY_WORLDWIDE, COUNTRY_AUSTRALIA, } country_code_t; static int country_code = COUNTRY_UNKNOWN; static char mge_scratch_buf[20]; /* ABM - Advanced Battery Monitoring *********************************** * Synthesis table * HID data | Charger in ABM mode | Charger in Constant mode | Error | Good | * UPS.BatterySystem.Charger.ABMEnable | 1 | 0 | | | * UPS.PowerSummary.PresentStatus.ACPresent | On utility | On battery | On utility | On battery | | | * Charger ABM mode | Charging | Floating | Resting | Discharging | Disabled | Disabled | | | * UPS.BatterySystem.Charger.Mode | 1 | 3 | 4 | 2 | 6 | 6 | | | * UPS.BatterySystem.Charger.Status | 1 | 2 | 3 | 4 | 6 | 6 | 0 | 1 | * UPS.PowerSummary.PresentStatus.Charging | 1 | 1 | 1 | 0 | 1 | 0 | | | * UPS.PowerSummary.PresentStatus.Discharging | 0 |  0 |  0 | 1 | 0 | 1 | | | * * Notes (from David G. Miller) to understand ABM status: * * When supporting ABM, when a UPS powers up or returns from battery, or * ends the ABM rest mode, it enters charge mode. * Some UPSs run a different charger reference voltage during charge mode * but all the newer models should not be doing that, but basically once * the battery voltage reaches the charger reference level * (should be 2.3 volts/cell) = 13.8v battery(6 cells), the charger is considered in float mode. * Some UPSs will not annunciate float mode until the charger power starts falling from * the maximum level indicating the battery is truly at the float voltage or in float mode. * The %charge level is based on battery voltage and the charge mode timer * (should be 48 hours) and some UPSs add in a value that's related to charger * power output. So you can have UPS that enters float mode with anywhere * from 80% or greater battery capacity. * float mode is not important from the software's perspective, it's there to * help determine if the charger is advancing correctly. * So in float mode, the charger is charging the battery, so by definition you * can assert the CHRG flag in NUT when in "float" mode or "charge" mode. * When in "rest" mode the charger is not delivering anything to the battery, * but it will when the ABM cycle(28 days) ends, or a battery discharge occurs * and utility returns. This is when the ABM status should be "resting". * If a battery failure is detected that disables the charger, it should be * reporting "off" in the ABM charger status. * Of course when delivering load power from the battery, the ABM status is * discharging. * * UPS.BatterySystem.Charger.ChargerType: * * This HID path has been seen to denote the charger type of the UPS. * At present it is unclear whether deductions about ABM being enabled * should be made from it, even though it seems to be changing when a * UPS that is ABM-capable is manually enabling and disabling its ABM. * For example, the Eaton 5P850I has been seen with a ChargerType of 0 * when having ABM disabled, and ChargerType of 4 when ABM was enabled. * According to the known values, however, the ChargerType should have * either remained the same (if only to display general charger ability) * or changed to ChargerType of 5 (for constant charge mode) - and not 0: * * { 0, "None", NULL, NULL }, * { 1, "Extended (CLA)", NULL, NULL }, * { 2, "Large extension", NULL, NULL }, * { 3, "Extra large extension (XL)", NULL, NULL }, * { 4, "ABM", NULL, NULL }, * { 5, "Constant Charge (CC)", NULL, NULL }, * * For this reason, ABM being enabled remains controlled only through the * one HID path known to be consistent: UPS.BatterySystem.Charger.ABMEnable */ #define ABM_UNKNOWN -1 #define ABM_DISABLED 0 #define ABM_ENABLED 1 /* Define internal flags to process the different ABM paths as seen in HID: * ABM_PATH_STATUS --> UPS.BatterySystem.Charger.Status * ABM_PATH_MODE --> UPS.BatterySystem.Charger.Mode */ #define ABM_PATH_UNKNOWN -1 #define ABM_PATH_STATUS 0 #define ABM_PATH_MODE 1 /* Internal flag to process battery status (CHRG/DISCHRG) and ABM */ static int advanced_battery_monitoring = ABM_UNKNOWN; /* Internal flag to process the different ABM paths as seen in HID */ static int advanced_battery_path = ABM_PATH_UNKNOWN; /* TODO: Lifted from strptime.c... maybe should externalize the fallback? * NOTE: HAVE_DECL_* are always defined, 0 or 1. Many other flags are not. */ #if ! HAVE_DECL_ROUND # ifndef WIN32 static long round (double value) # else static long round (LDOUBLE value) # endif { long intpart; intpart = (long)value; value = value - intpart; if (value >= 0.5) intpart++; return intpart; } #endif /* HAVE_DECL_ROUND */ /* Used to store internally if ABM is enabled or not */ static const char *eaton_abm_enabled_fun(double value) { int abm_enabled_value = (int)value; switch (abm_enabled_value) { case ABM_DISABLED: advanced_battery_monitoring = ABM_DISABLED; upsdebugx(2, "ABM status is: disabled (%i)", abm_enabled_value); break; case ABM_ENABLED: advanced_battery_monitoring = ABM_ENABLED; upsdebugx(2, "ABM status is: enabled (%i)", abm_enabled_value); break; default: advanced_battery_monitoring = ABM_UNKNOWN; upsdebugx(2, "ABM status is: unknown (%i)", abm_enabled_value); break; } /* Return NULL, not to get the value published! */ return NULL; } static info_lkp_t eaton_abm_enabled_info[] = { { 0, "dummy", eaton_abm_enabled_fun, NULL }, { 0, NULL, NULL, NULL } }; /* ABM Path: UPS.BatterySystem.Charger.Mode (battery.charger.mode.status) */ static const char *eaton_abm_path_mode_fun(double value) { int abm_path_mode_value = (int)value; /* If unknown/disabled ABM, reset ABM path to give UPS a chance to use another once re-enabled */ if (advanced_battery_monitoring == ABM_UNKNOWN || advanced_battery_monitoring == ABM_DISABLED) { advanced_battery_path = ABM_PATH_UNKNOWN; return NULL; } /* If ABM_ENABLED and not yet initialized set ABM path to ABM_PATH_MODE */ if (advanced_battery_monitoring == ABM_ENABLED && advanced_battery_path == ABM_PATH_UNKNOWN) { advanced_battery_path = ABM_PATH_MODE; upsdebugx(2, "Set ABM path to: ABM_PATH_MODE (%i)", abm_path_mode_value); } /* Return NULL, not to get the value published! */ return NULL; } static info_lkp_t eaton_abm_path_mode_info[] = { { 0, "dummy", eaton_abm_path_mode_fun, NULL }, { 0, NULL, NULL, NULL } }; /* ABM Path: UPS.BatterySystem.Charger.Status (battery.charger.type.status) */ static const char *eaton_abm_path_status_fun(double value) { int abm_path_status_value = (int)value; /* If unknown/disabled ABM, reset ABM path to give UPS a chance to use another once re-enabled */ if (advanced_battery_monitoring == ABM_UNKNOWN || advanced_battery_monitoring == ABM_DISABLED) { advanced_battery_path = ABM_PATH_UNKNOWN; return NULL; } /* If ABM_ENABLED and not yet initialized set ABM path to ABM_PATH_STATUS */ if (advanced_battery_monitoring == ABM_ENABLED && advanced_battery_path == ABM_PATH_UNKNOWN) { advanced_battery_path = ABM_PATH_STATUS; upsdebugx(2, "Set ABM path to: ABM_PATH_STATUS (%i)", abm_path_status_value); } /* Return NULL, not to get the value published! */ return NULL; } static info_lkp_t eaton_abm_path_status_info[] = { { 0, "dummy", eaton_abm_path_status_fun, NULL }, { 0, NULL, NULL, NULL } }; /* Note 1: This point will need more clarification! */ # if 0 /* Used to store internally if ABM is enabled or not (for legacy units) */ static const char *eaton_abm_enabled_legacy_fun(double value) { advanced_battery_monitoring = value; upsdebugx(2, "ABM is %s (legacy data)", (advanced_battery_monitoring==1)?"enabled":"disabled"); /* Return NULL, not to get the value published! */ return NULL; } static info_lkp_t eaton_abm_enabled_legacy_info[] = { { 0, "dummy", eaton_abm_enabled_legacy_fun, NULL }, { 0, NULL, NULL, NULL } }; #endif /* if 0 */ /* Used to process ABM status text (for battery.charger.status) */ static const char *eaton_abm_status_fun(double value) { int abm_status_value = (int)value; /* Don't process if ABM is unknown or disabled */ if (advanced_battery_monitoring == ABM_UNKNOWN || advanced_battery_monitoring == ABM_DISABLED) { /* Clear any previously published data, in case * the user has switched off ABM */ dstate_delinfo("battery.charger.status"); return NULL; } /* ABM Path: UPS.BatterySystem.Charger.Status (battery.charger.type.status) * as more recent and seen with 9 series devices (and possibly others): */ if (advanced_battery_path == ABM_PATH_STATUS) { switch (abm_status_value) { case 1: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "charging"); break; case 2: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "floating"); break; case 3: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "resting"); break; case 4: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "discharging"); break; case 6: /* ABM Charger Disabled */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "off"); break; case 5: /* Undefined - ABM is not activated */ default: /* Return NULL, not to get the value published! */ return NULL; } } /* ABM Path: UPS.BatterySystem.Charger.Mode (battery.charger.mode.status) * as more common and for any other ABM paths not (yet) recognized: */ else { switch (abm_status_value) { case 1: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "charging"); break; case 2: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "discharging"); break; case 3: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "floating"); break; case 4: snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "resting"); break; case 6: /* ABM Charger Disabled */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "off"); break; case 5: /* Undefined - ABM is not activated */ default: /* Return NULL, not to get the value published! */ return NULL; } } upsdebugx(2, "ABM charger status is: %s (%i)", mge_scratch_buf, abm_status_value); return mge_scratch_buf; } static info_lkp_t eaton_abm_status_info[] = { { 1, "dummy", eaton_abm_status_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t eaton_charger_type_info[] = { { 0, "None", NULL, NULL }, { 1, "Extended (CLA)", NULL, NULL }, { 2, "Large extension", NULL, NULL }, { 3, "Extra large extension (XL)", NULL, NULL }, { 4, "ABM", NULL, NULL }, { 5, "Constant Charge (CC)", NULL, NULL }, { 0, NULL, NULL, NULL } }; /* Used to process ABM status flags, for ups.status (CHRG/DISCHRG) */ static const char *eaton_abm_chrg_dischrg_fun(double value) { int abm_chrg_dischrg_value = (int)value; /* Don't process if ABM is unknown or disabled */ if (advanced_battery_monitoring == ABM_UNKNOWN || advanced_battery_monitoring == ABM_DISABLED) return NULL; /* ABM Path: UPS.BatterySystem.Charger.Status (battery.charger.type.status) * as more recent and seen with 9 series devices (and possibly others): */ if (advanced_battery_path == ABM_PATH_STATUS) { switch (abm_chrg_dischrg_value) { case 1: /* charging status */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "chrg"); break; case 2: /* floating status */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "chrg"); break; case 4: /* discharging status */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "dischrg"); break; case 6: /* ABM Charger Disabled */ case 3: /* resting, nothing to publish! (?) */ case 5: /* Undefined - ABM is not activated */ default: /* Return NULL, not to get the value published! */ return NULL; } } /* ABM Path: UPS.BatterySystem.Charger.Mode (battery.charger.mode.status) * as more common and for any other ABM paths not (yet) recognized: */ else { switch (abm_chrg_dischrg_value) { case 1: /* charging status */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "chrg"); break; case 3: /* floating status */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "chrg"); break; case 2: /* discharging status */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "dischrg"); break; case 6: /* ABM Charger Disabled */ case 4: /* resting, nothing to publish! (?) */ case 5: /* Undefined - ABM is not activated */ default: /* Return NULL, not to get the value published! */ return NULL; } } upsdebugx(2, "ABM charger flag is: %s (%i)", mge_scratch_buf, abm_chrg_dischrg_value); return mge_scratch_buf; } static info_lkp_t eaton_abm_chrg_dischrg_info[] = { { 1, "dummy", eaton_abm_chrg_dischrg_fun, NULL }, { 0, NULL, NULL, NULL } }; /* ABM also implies that standard CHRG/DISCHRG are processed according * to weither ABM is enabled or not... * If ABM is disabled, we publish these legacy status * Otherwise, we don't publish on ups.status, but only battery.charger.status */ /* FIXME: we may prefer to publish the CHRG/DISCHRG status * on battery.charger.status?! */ static const char *eaton_abm_check_dischrg_fun(double value) { if (advanced_battery_monitoring == ABM_UNKNOWN || advanced_battery_monitoring == ABM_DISABLED) { if (d_equal(value, 1)) { snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "dischrg"); } else { snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "!dischrg"); } } else { /* Else, ABM is enabled, we should return NULL, * not to get the value published! * However, clear flags that would persist in case of prior * publication in ABM-disabled mode */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "!dischrg"); } return mge_scratch_buf; } static info_lkp_t eaton_discharging_info[] = { { 1, "dummy", eaton_abm_check_dischrg_fun, NULL }, { 0, NULL, NULL, NULL } }; static const char *eaton_abm_check_chrg_fun(double value) { if (advanced_battery_monitoring == ABM_UNKNOWN || advanced_battery_monitoring == ABM_DISABLED) { if (d_equal(value, 1)) { snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "chrg"); } else { snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "!chrg"); } } else { /* Else, ABM is enabled, we should return NULL, * not to get the value published! * However, clear flags that would persist in case of prior * publication in ABM-disabled mode */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s", "!chrg"); } return mge_scratch_buf; } static info_lkp_t eaton_charging_info[] = { { 1, "dummy", eaton_abm_check_chrg_fun, NULL }, { 0, NULL, NULL, NULL } }; /* The HID path 'UPS.PowerSummary.Time' reports Unix time (ie the number of * seconds since 1970-01-01 00:00:00. This has to be split between ups.date and * ups.time */ static const char *mge_date_conversion_fun(double value) { time_t sec = value; struct tm tmbuf; if (strftime(mge_scratch_buf, sizeof(mge_scratch_buf), "%Y/%m/%d", localtime_r(&sec, &tmbuf)) == 10) { return mge_scratch_buf; } upsdebugx(3, "%s: can't compute date %g", __func__, value); return NULL; } static const char *mge_time_conversion_fun(double value) { time_t sec = value; struct tm tmbuf; if (strftime(mge_scratch_buf, sizeof(mge_scratch_buf), "%H:%M:%S", localtime_r(&sec, &tmbuf)) == 8) { return mge_scratch_buf; } upsdebugx(3, "%s: can't compute time %g", __func__, value); return NULL; } #ifdef HAVE_STRPTIME /* Conversion back retrieve ups.time to build the full unix time */ static double mge_date_conversion_nuf(const char *value) { struct tm mge_tm; /* build a full value (date) + time string */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s %s", value, dstate_getinfo("ups.time")); if (strptime(mge_scratch_buf, "%Y/%m/%d %H:%M:%S", &mge_tm) != NULL) { return mktime(&mge_tm); } upsdebugx(3, "%s: can't compute date %s", __func__, value); return 0; } /* Conversion back retrieve ups.date to build the full unix time */ static double mge_time_conversion_nuf(const char *value) { struct tm mge_tm; /* build a full date + value (time) string */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%s %s", dstate_getinfo("ups.date"), value); if (strptime(mge_scratch_buf, "%Y/%m/%d %H:%M:%S", &mge_tm) != NULL) { return mktime(&mge_tm); } upsdebugx(3, "%s: can't compute time %s", __func__, value); return 0; } static info_lkp_t mge_date_conversion[] = { { 0, NULL, mge_date_conversion_fun, mge_date_conversion_nuf }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_time_conversion[] = { { 0, NULL, mge_time_conversion_fun, mge_time_conversion_nuf }, { 0, NULL, NULL, NULL } }; #else static info_lkp_t mge_date_conversion[] = { { 0, NULL, mge_date_conversion_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_time_conversion[] = { { 0, NULL, mge_time_conversion_fun, NULL }, { 0, NULL, NULL, NULL } }; #endif /* HAVE_STRPTIME */ /* The HID path 'UPS.PowerSummary.ConfigVoltage' only reports * 'battery.voltage.nominal' for specific UPS series. * Ignore the value for other series (default behavior). */ static const char *mge_battery_voltage_nominal_fun(double value) { switch (mge_type & 0xFF00) /* Ignore model byte */ { case MGE_EVOLUTION: if (mge_type == MGE_EVOLUTION_650) { value = 12.0; } break; case MGE_PULSAR_M: case EATON_5P: case EATON_9E: /* Presumably per https://github.com/networkupstools/nut/issues/1925#issuecomment-1562342854 */ break; default: return NULL; } snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.0f", value); return mge_scratch_buf; } static info_lkp_t mge_battery_voltage_nominal[] = { { 0, NULL, mge_battery_voltage_nominal_fun, NULL }, { 0, NULL, NULL, NULL } }; /* The HID path 'UPS.PowerSummary.Voltage' only reports * 'battery.voltage' for specific UPS series. * Ignore the value for other series (default behavior). */ static const char *mge_battery_voltage_fun(double value) { switch (mge_type & 0xFF00) /* Ignore model byte */ { case MGE_EVOLUTION: case MGE_PULSAR_M: case EATON_5P: case EATON_9E: /* Presumably per https://github.com/networkupstools/nut/issues/1925#issuecomment-1562342854 */ break; default: return NULL; } snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.1f", value); return mge_scratch_buf; } static info_lkp_t mge_battery_voltage[] = { { 0, NULL, mge_battery_voltage_fun, NULL }, { 0, NULL, NULL, NULL } }; static const char *mge_powerfactor_conversion_fun(double value) { snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.2f", value / 100); return mge_scratch_buf; } static info_lkp_t mge_powerfactor_conversion[] = { { 0, NULL, mge_powerfactor_conversion_fun, NULL }, { 0, NULL, NULL, NULL } }; static const char *mge_battery_capacity_fun(double value) { snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.2f", value / 3600); return mge_scratch_buf; } static info_lkp_t mge_battery_capacity[] = { { 0, NULL, mge_battery_capacity_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t eaton_enable_disable_info[] = { { 0, "disabled", NULL, NULL }, { 1, "enabled", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_upstype_conversion[] = { { 1, "offline / line interactive", NULL, NULL }, { 2, "online", NULL, NULL }, { 3, "online - unitary/parallel", NULL, NULL }, { 4, "online - parallel with hot standy", NULL, NULL }, { 5, "online - hot standby redundancy", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_sensitivity_info[] = { { 0, "normal", NULL, NULL }, { 1, "high", NULL, NULL }, { 2, "low", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_emergency_stop[] = { { 1, "Emergency stop!", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_wiring_fault[] = { { 1, "Wiring fault!", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_config_failure[] = { { 1, "Fatal EEPROM fault!", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_inverter_volthi[] = { { 1, "Inverter AC voltage too high!", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_inverter_voltlo[] = { { 1, "Inverter AC voltage too low!", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_short_circuit[] = { { 1, "Output short circuit!", NULL, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t mge_onbatt_info[] = { { 1, "!online", NULL, NULL }, { 0, "online", NULL, NULL }, { 0, NULL, NULL, NULL } }; /* allow limiting to ups.model = Protection Station, Ellipse Eco * and 3S (US 750 and AUS 700 only!) */ static const char *eaton_check_pegasus_fun(double value) { switch (mge_type & 0xFF00) /* Ignore model byte */ { case MGE_PEGASUS: break; case MGE_3S: /* Only consider non European models */ if (country_code != COUNTRY_EUROPE) break; return NULL; default: return NULL; } /* FIXME: Expected values (not checked for) seem to be 10, 25 or 60 * according to originally improperly defined mapping table. * Should we check for these numbers explicitly? * What should we do with others (if any) -- accept (least surprise) * or reject? */ snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.0f", value); return mge_scratch_buf; } /* FIXME/Note: If a mapping method is used, numeric/string mapping values * (and lines other than first) are in fact ignored for that direction, * but can be still useful for opposite */ static info_lkp_t pegasus_threshold_info[] = { { 10, "10", eaton_check_pegasus_fun, NULL }, { 25, "25", eaton_check_pegasus_fun, NULL }, { 60, "60", eaton_check_pegasus_fun, NULL }, { 0, NULL, NULL, NULL } }; /* allow limiting standard yes/no info (here, to enable ECO mode) to * ups.model = Protection Station, Ellipse Eco and 3S (US 750 and AUS 700 only!) * this allows to enable special flags used in hid_info_t entries (Ie RW) */ static const char *pegasus_yes_no_info_fun(double value) { switch (mge_type & 0xFF00) /* Ignore model byte */ { case MGE_PEGASUS: break; case MGE_3S: /* Only consider non European models */ if (country_code != COUNTRY_EUROPE) break; return NULL; default: return NULL; } return (d_equal(value, 0)) ? "no" : "yes"; } /* Conversion back of yes/no info */ static double pegasus_yes_no_info_nuf(const char *value) { switch (mge_type & 0xFF00) /* Ignore model byte */ { case MGE_PEGASUS: break; case MGE_3S: /* Only consider non European models */ if (country_code != COUNTRY_EUROPE) break; return 0; default: return 0; } if (!strncmp(value, "yes", 3)) return 1; else /* assuming "no" */ return 0; } static info_lkp_t pegasus_yes_no_info[] = { { 0, "dummy", pegasus_yes_no_info_fun, pegasus_yes_no_info_nuf }, { 0, NULL, NULL, NULL } }; static info_lkp_t outlet_eco_yes_no_info[] = { { 0, "The outlet is not ECO controlled", NULL, NULL }, { 1, "The outlet is ECO controlled", NULL, NULL }, { 0, NULL, NULL, NULL } }; /* Function to check if the current High Efficiency (aka ECO) mode voltage/frequency is within the configured limits */ static const char *eaton_input_eco_mode_check_range(double value) { double bypass_voltage; double eco_low_transfer; double eco_high_transfer; double out_voltage_nominal; double out_frequency_nominal; double bypass_frequency; double frequency_range_transfer; double lower_frequency_limit; double upper_frequency_limit; double lower_voltage_limit; double upper_voltage_limit; /* Get the ECO mode voltage/frequency and transfer points */ const char *bypass_voltage_str = dstate_getinfo("input.bypass.voltage"); const char *eco_low_transfer_str = dstate_getinfo("input.transfer.eco.low"); const char *eco_high_transfer_str = dstate_getinfo("input.transfer.eco.high"); const char *out_voltage_nominal_str = dstate_getinfo("output.voltage.nominal"); const char *out_frequency_nominal_str = dstate_getinfo("output.frequency.nominal"); const char *frequency_range_transfer_str = dstate_getinfo("input.transfer.frequency.eco.range"); const char *bypass_frequency_str = dstate_getinfo("input.bypass.frequency"); if ((int)value != 1) { upsdebugx(1, "%s: wrong 'value' parameter '%f' for this method, should be '1'", __func__, value); return NULL; } errno = 0; if (bypass_voltage_str == NULL || bypass_frequency_str == NULL || out_voltage_nominal_str == NULL || out_frequency_nominal_str == NULL ) { upsdebugx(2, "%s: Failed to get values: " "input.bypass.voltage = %s, " "input.bypass.frequency = %s, " "output.voltage.nominal = %s, " "output.frequency.nominal = %s", __func__, NUT_STRARG(bypass_voltage_str), NUT_STRARG(bypass_frequency_str), NUT_STRARG(out_voltage_nominal_str), NUT_STRARG(out_frequency_nominal_str)); /* Disable ECO mode switching, do not enter ECO mode */ dstate_setinfo("input.eco.switchable", "normal"); upsdebugx(1, "%s: Disable ECO mode due to missing input/output variables.", __func__); errno = EINVAL; return NULL; } /* In case we don't have ECO transfer limit variables * but still have ability to enter Bypass/ECO modes, * will use default limits later in code. * Possibly reported by debug log for 9SX1000i https://github.com/networkupstools/nut/issues/2685 */ if (eco_low_transfer_str == NULL || eco_high_transfer_str == NULL || frequency_range_transfer_str == NULL ) { upsdebugx(2, "%s: Failed to get values (but can use defaults): " "input.transfer.eco.low = %s, " "input.transfer.eco.high = %s, " "input.transfer.frequency.eco.range = %s", __func__, NUT_STRARG(eco_low_transfer_str), NUT_STRARG(eco_high_transfer_str), NUT_STRARG(frequency_range_transfer_str)); /* Do not return NULL here, we will use default values for limits */ } str_to_double(bypass_voltage_str, &bypass_voltage, 10); str_to_double(eco_low_transfer_str, &eco_low_transfer, 10); str_to_double(eco_high_transfer_str, &eco_high_transfer, 10); str_to_double(out_voltage_nominal_str, &out_voltage_nominal, 10); str_to_double(out_frequency_nominal_str, &out_frequency_nominal, 10); str_to_double(frequency_range_transfer_str, &frequency_range_transfer, 10); str_to_double(bypass_frequency_str, &bypass_frequency, 10); /* Default values if user-defined limits are not available or out of range * 5% below nominal output voltage * 5% above nominal output voltage * 5% below/above output frequency nominal */ /* Set the frequency limit */ if (frequency_range_transfer > 0) { lower_frequency_limit = out_frequency_nominal - (out_frequency_nominal / 100 * frequency_range_transfer); upper_frequency_limit = out_frequency_nominal + (out_frequency_nominal / 100 * frequency_range_transfer); } else { /* Set default values if user-defined limits are not available or out of range */ lower_frequency_limit = out_frequency_nominal - (out_frequency_nominal / 100 * 5); upper_frequency_limit = out_frequency_nominal + (out_frequency_nominal / 100 * 5); } /* Set the voltage limit */ if (eco_low_transfer > 0 && eco_high_transfer > 0) { lower_voltage_limit = eco_low_transfer; upper_voltage_limit = eco_high_transfer; } else { /* Set default values if user-defined limits are not available or out of range */ lower_voltage_limit = out_voltage_nominal * 0.95; upper_voltage_limit = out_voltage_nominal * 1.05; } /* Check if limits are within valid range */ if ((bypass_voltage >= lower_voltage_limit && bypass_voltage <= upper_voltage_limit) && (bypass_frequency >= lower_frequency_limit && bypass_frequency <= upper_frequency_limit) ) { const char *oldval = dstate_getinfo("input.eco.switchable"); if (!oldval || strcmp(oldval, "ECO")) { upsdebugx(1, "%s: Entering ECO mode due to input conditions being within the transfer limits.", __func__); } else { upsdebugx(4, "%s: Still in ECO mode due to input conditions being within the transfer limits.", __func__); } buzzmode_set("vendor:mge-hid:ECO"); errno = 0; return "ECO"; /* Enter ECO mode */ } else { const char *oldval = dstate_getinfo("input.eco.switchable"); /* Condensed debug messages for out of range voltage and frequency */ if (bypass_voltage < lower_voltage_limit || bypass_voltage > upper_voltage_limit) { upsdebugx(2, "%s: Input Bypass voltage is outside ECO transfer limits: %.1f V", __func__, bypass_voltage); } if (bypass_frequency < lower_frequency_limit || bypass_frequency > upper_frequency_limit) { upsdebugx(2, "%s: Input Bypass frequency is outside ECO transfer limits: %.1f Hz", __func__, bypass_frequency); } /* Disable ECO mode switching, do not enter ECO mode */ dstate_setinfo("input.eco.switchable", "normal"); buzzmode_set("vendor:mge-hid:normal"); if (!oldval || strcmp(oldval, "normal")) { upsdebugx(1, "%s: Disable ECO mode due to input conditions being outside the transfer limits.", __func__); } else { upsdebugx(4, "%s: Still without ECO mode due to input conditions being outside the transfer limits.", __func__); } /* NOT "errno = EINVAL;" here */ errno = 0; return NULL; /* FIXME? Return "normal"? */ } } /* If we are called, it means the status is on? */ static const char *eaton_input_ess_mode_report(double value) { NUT_UNUSED_VARIABLE(value); buzzmode_set("vendor:mge-hid:ESS"); return "ESS"; } /* High Efficiency (aka ECO) mode, Energy Saver System (aka ESS) mode makes sense for UPS like (93PM G2, 9395P) */ static const char *eaton_input_buzzwordmode_report(double value) { errno = 0; switch ((long)value) { case 0: return "normal"; case 1: /* "ECO" where suitable; lots of other activity done */ /* NOTE: "ECO" = tested on 9SX model and working fine, * but the 9E model can get stuck in ECO mode, see * https://github.com/networkupstools/nut/issues/2719 */ return eaton_input_eco_mode_check_range(value); case 2: /* "ESS" and internal buzzmode_set() */ return eaton_input_ess_mode_report(value); default: errno = EINVAL; return NULL; } } static double eaton_input_buzzwordmode_setvar_nuf(const char *value) { errno = 0; if (!value || !*value) { errno = EINVAL; return -1; } if (!strcmp(value, "normal") || !strcmp(value, "vendor:mge-hid:normal")) { return 0; } if (!strcmp(value, "ECO") || !strcmp(value, "vendor:mge-hid:ECO")) { return 1; } if (!strcmp(value, "ESS") || !strcmp(value, "vendor:mge-hid:ESS")) { return 2; } errno = EINVAL; return -1; } static info_lkp_t eaton_input_eco_mode_on_off_info[] = { { 0, "dummy", eaton_input_buzzwordmode_report, eaton_input_buzzwordmode_setvar_nuf }, { 0, NULL, NULL, NULL } }; /* Function to check if the current Bypass transfer voltage/frequency * is within the configured limits (for value==1) */ static const char *eaton_input_bypass_check_range(double value) { double bypass_voltage; double bypass_low_transfer; double bypass_high_transfer; double out_voltage_nominal; double bypass_frequency; double frequency_range_transfer; double lower_frequency_limit; double upper_frequency_limit; double lower_voltage_limit; double upper_voltage_limit; double out_frequency_nominal; /* Get the Bypass mode voltage/frequency and transfer points */ const char *bypass_voltage_str = dstate_getinfo("input.bypass.voltage"); const char *bypass_low_transfer_str = dstate_getinfo("input.transfer.bypass.low"); const char *bypass_high_transfer_str = dstate_getinfo("input.transfer.bypass.high"); const char *out_voltage_nominal_str = dstate_getinfo("output.voltage.nominal"); const char *bypass_frequency_str = dstate_getinfo("input.bypass.frequency"); const char *frequency_range_transfer_str = dstate_getinfo("input.transfer.frequency.bypass.range"); const char *out_frequency_nominal_str = dstate_getinfo("output.frequency.nominal"); errno = 0; if (d_equal(value, 0)) return "disabled"; if (!(d_equal(value, 1))) { errno = EINVAL; return NULL; } /* assuming value==1 */ if (bypass_voltage_str == NULL || bypass_frequency_str == NULL || out_voltage_nominal_str == NULL || out_frequency_nominal_str == NULL ) { upsdebugx(2, "%s: Failed to get values: " "input.bypass.voltage = %s, " "input.bypass.frequency = %s, " "output.voltage.nominal = %s, " "output.frequency.nominal = %s", __func__, NUT_STRARG(bypass_voltage_str), NUT_STRARG(bypass_frequency_str), NUT_STRARG(out_voltage_nominal_str), NUT_STRARG(out_frequency_nominal_str)); /* Disable Bypass mode switching, do not enter Bypass mode */ dstate_setinfo("input.bypass.switch.off", "off"); upsdebugx(1, "%s: Disable Bypass mode due to missing input/output variables.", __func__); errno = EINVAL; return NULL; } /* In case we dont have Bypass transfer limit variables but still have ability to enter Bypass mode */ if (bypass_low_transfer_str == NULL || bypass_high_transfer_str == NULL || frequency_range_transfer_str == NULL ) { upsdebugx(2, "%s: Failed to get values: " "input.transfer.bypass.low = %s, " "input.transfer.bypass.high = %s, " "input.transfer.frequency.bypass.range = %s", __func__, NUT_STRARG(bypass_low_transfer_str), NUT_STRARG(bypass_high_transfer_str), NUT_STRARG(frequency_range_transfer_str)); /* Do not return NULL here, we will use default values for limits */ } str_to_double(bypass_voltage_str, &bypass_voltage, 10); str_to_double(bypass_low_transfer_str, &bypass_low_transfer, 10); str_to_double(bypass_high_transfer_str, &bypass_high_transfer, 10); str_to_double(out_voltage_nominal_str, &out_voltage_nominal, 10); str_to_double(bypass_frequency_str, &bypass_frequency, 10); str_to_double(frequency_range_transfer_str, &frequency_range_transfer, 10); str_to_double(out_frequency_nominal_str, &out_frequency_nominal, 10); /* Default values if user-defined limits are not available or out of range * 20% below nominal output voltage * 15% above nominal output voltage * 10% below/above output frequency nominal */ /* Set the frequency limit */ if (frequency_range_transfer > 0) { lower_frequency_limit = out_frequency_nominal - (out_frequency_nominal / 100 * frequency_range_transfer); upper_frequency_limit = out_frequency_nominal + (out_frequency_nominal / 100 * frequency_range_transfer); } else { /* Set default values if user-defined limits are not available or out of range */ lower_frequency_limit = out_frequency_nominal - (out_frequency_nominal / 100 * 10); upper_frequency_limit = out_frequency_nominal + (out_frequency_nominal / 100 * 10); } /* Set the voltage limit */ if (bypass_low_transfer > 0 && bypass_high_transfer > 0) { lower_voltage_limit = bypass_low_transfer; upper_voltage_limit = bypass_high_transfer; } else { /* Set default values if user-defined limits are not available or out of range */ lower_voltage_limit = out_voltage_nominal * 0.8; upper_voltage_limit = out_voltage_nominal * 1.15; } /* Check if limits are within valid range */ if ((bypass_voltage >= lower_voltage_limit && bypass_voltage <= upper_voltage_limit) && (bypass_frequency >= lower_frequency_limit && bypass_frequency <= upper_frequency_limit) ) { upsdebugx(1, "%s: Entering Bypass mode due to input conditions being within the transfer limits.", __func__); errno = 0; return "on"; /* Enter Bypass mode */ } else { /* Condensed debug messages for out of range voltage and frequency */ if (bypass_voltage < lower_voltage_limit || bypass_voltage > upper_voltage_limit) { upsdebugx(1, "%s: Input Bypass voltage is outside Bypass transfer limits: %.1f V", __func__, bypass_voltage); } if (bypass_frequency < lower_frequency_limit || bypass_frequency > upper_frequency_limit) { upsdebugx(1, "%s: Input Bypass frequency is outside Bypass transfer limits: %.1f Hz", __func__, bypass_frequency); } /* Disable Bypass mode switching, do not enter Bypass mode */ dstate_setinfo("input.bypass.switch.off", "off"); upsdebugx(1, "%s: Disable Bypass mode due to input conditions being outside the transfer limits.", __func__); /* NOT "errno = EINVAL;" here */ errno = 0; return NULL; } } /* Automatic Bypass mode on * Mapping back is simply tabular */ static info_lkp_t eaton_input_bypass_mode_on_info[] = { { 0, "disabled", eaton_input_bypass_check_range, NULL }, { 1, "on", eaton_input_bypass_check_range, NULL }, { 0, NULL, NULL, NULL } }; /* Automatic Bypass mode off (switch on inverter) */ static info_lkp_t eaton_input_bypass_mode_off_info[] = { { 0, "disabled", NULL, NULL }, { 1, "off", NULL, NULL }, { 0, NULL, NULL, NULL } }; /* Function to start or stop ECO(HE) Mode automatically instead of manually starting/stoping Bypass and then ECO(HE) Mode */ static const char *eaton_input_eco_mode_auto_on_off_fun(double value) { const char *bypass_switch_str = NULL; const char *eco_switchable_str = NULL; if ((int)value == 1) { /* Check if input.bypass.switch.on is disabled and set it to 'on' */ bypass_switch_str = dstate_getinfo("input.bypass.switch.on"); if (!strcmp(bypass_switch_str, "disabled")) { /* Enter Bypass mode */ bypass_switch_str = eaton_input_bypass_check_range(value); upsdebugx(1, "%s: Entering auto Bypass mode.", __func__); } else { upsdebugx(1, "%s: Bypass switch on state is: %s , must be disabled before switching on", __func__, bypass_switch_str); return NULL; } /* Check if input.eco.switchable is normal and set it to 'ECO' */ eco_switchable_str = dstate_getinfo("input.eco.switchable"); if (!strcmp(eco_switchable_str, "normal")) { /* Enter ECO mode */ eco_switchable_str = eaton_input_eco_mode_check_range(value); upsdebugx(1, "%s: Entering ECO mode.", __func__); } else { upsdebugx(1, "%s: ECO switch state is: %s , must be normal before switching to ECO", __func__, eco_switchable_str); return NULL; } upsdebugx(1, "%s: ECO Mode was enabled after switching to Bypass Mode", __func__); return "on"; } else { /* Check if input.bypass.switch.off is disabled and set it to 'off' */ bypass_switch_str = dstate_getinfo("input.bypass.switch.off"); if (!strcmp(bypass_switch_str, "disabled")) { /* Exit Bypass mode */ setvar("input.bypass.switch.off", "off"); upsdebugx(1, "%s: Exiting auto Bypass mode.", __func__); } else { upsdebugx(1, "%s: Bypass switch off state is: %s , must be disabled before switching off", __func__, bypass_switch_str); return NULL; } /* Check if input.eco.switchable is 'ECO' and set it to normal */ eco_switchable_str = dstate_getinfo("input.eco.switchable"); if (!strcmp(eco_switchable_str, "ECO")) { /* Exit ECO mode */ setvar("input.eco.switchable", "normal"); buzzmode_set("vendor:mge-hid:normal"); upsdebugx(1, "%s: Exiting ECO mode.", __func__); /* Get the updated value of input.eco.switchable after setting it to "normal */ eco_switchable_str = dstate_getinfo("input.eco.switchable"); } else { upsdebugx(1, "%s: ECO switch state is: %s , must be ECO before switching to normal", __func__, eco_switchable_str); return NULL; } upsdebugx(1, "%s: ECO Mode was disabled after switching from Bypass Mode", __func__); return "off"; } } /* Conversion back of eaton_input_eco_mode_auto_on_off_fun() */ static double eaton_input_eco_mode_auto_on_off_nuf(const char *value) { const char *bypass_switch_str = NULL; const char *eco_switchable_str = NULL; if (!strcmp(value, "1")) { bypass_switch_str = dstate_getinfo("input.bypass.switch.on"); if (!strcmp(bypass_switch_str, "disabled")) { bypass_switch_str = eaton_input_bypass_check_range(1); } else { upsdebugx(1, "%s: Bypass switch on state is: %s , must be disabled before switching on", __func__, bypass_switch_str); return 0; } eco_switchable_str = dstate_getinfo("input.eco.switchable"); if (!strcmp(eco_switchable_str, "normal")) { eco_switchable_str = eaton_input_eco_mode_check_range(1); } else { upsdebugx(1, "%s: ECO switch state is: %s , must be normal before switching to ECO", __func__, eco_switchable_str); return 0; } upsdebugx(1, "%s: ECO Mode was enabled after switching to Bypass Mode", __func__); return 1; } else { bypass_switch_str = dstate_getinfo("input.bypass.switch.off"); if (!strcmp(bypass_switch_str, "disabled")) { setvar("input.bypass.switch.off", "off"); } else { upsdebugx(1, "%s: Bypass switch off state is: %s , must be disabled before switching off", __func__, bypass_switch_str); return 1; } eco_switchable_str = dstate_getinfo("input.eco.switchable"); if (!strcmp(eco_switchable_str, "ECO")) { setvar("input.eco.switchable", "normal"); buzzmode_set("vendor:mge-hid:normal"); /* Get the updated value of input.eco.switchable after setting it to "normal */ eco_switchable_str = dstate_getinfo("input.eco.switchable"); } else { upsdebugx(1, "%s: ECO switch state is: %s , must be ECO before switching to normal", __func__, eco_switchable_str); return 1; } upsdebugx(1, "%s: ECO Mode was disabled after switching from Bypass Mode", __func__); return 0; } } /* High Efficiency (aka ECO) mode for auto start/stop commands */ static info_lkp_t eaton_input_eco_mode_auto_on_off_info[] = { { 0, "dummy", eaton_input_eco_mode_auto_on_off_fun, eaton_input_eco_mode_auto_on_off_nuf }, { 0, NULL, NULL, NULL } }; /* Determine country using UPS.PowerSummary.Country. * If not present: * if PowerConverter.Output.Voltage >= 200 => "Europe" * else default to "US" */ static const char *eaton_check_country_fun(double value) { country_code = value; /* Return NULL, not to get the value published! */ return NULL; } static info_lkp_t eaton_check_country_info[] = { { 0, "dummy", eaton_check_country_fun, NULL }, { 0, NULL, NULL, NULL } }; /* When UPS.PowerConverter.Output.ActivePower is not present, * compute a realpower approximation using available data */ static const char *eaton_compute_realpower_fun(double value) { const char *str_ups_load = dstate_getinfo("ups.load"); const char *str_power_nominal = dstate_getinfo("ups.power.nominal"); const char *str_powerfactor = dstate_getinfo("output.powerfactor"); float powerfactor = 0.80; int power_nominal = 0; int ups_load = 0; double realpower = 0; NUT_UNUSED_VARIABLE(value); if (str_power_nominal && str_ups_load) { /* Extract needed values */ ups_load = atoi(str_ups_load); power_nominal = atoi(str_power_nominal); if (str_powerfactor) powerfactor = atof(str_powerfactor); /* Compute the value */ realpower = round(ups_load * 0.01 * power_nominal * powerfactor); snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.0f", realpower); upsdebugx(1, "eaton_compute_realpower_fun(%s)", mge_scratch_buf); return mge_scratch_buf; } /* else can't process */ /* Return NULL, not to get the value published! */ return NULL; } static info_lkp_t eaton_compute_realpower_info[] = { { 0, "dummy", eaton_compute_realpower_fun, NULL }, { 0, NULL, NULL, NULL } }; /* Limit nominal output voltage according to HV or LV models */ static const char *nominal_output_voltage_fun(double value) { static long nominal = -1; if (nominal < 0) { nominal = value; } switch ((long)nominal) { /* LV models */ case 100: case 110: case 120: case 127: switch ((long)value) { case 100: case 110: case 120: case 127: break; default: return NULL; } break; /* line-interactive and online support 200/208 and 220/230/240*/ /* HV models */ /* 208V */ case 200: case 208: switch ((long)value) { case 200: case 208: break; /* 230V */ case 220: case 230: case 240: if ((mge_type & 0xFF00) >= MGE_DEFAULT) break; return NULL; default: return NULL; } break; /* HV models */ /* 230V */ case 220: case 230: case 240: switch ((long)value) { case 200: case 208: /* line-interactive and online also support 200 / 208 V * So break on offline models */ if ((mge_type & 0xFF00) < MGE_DEFAULT) return NULL; /* FIXME: Some European models ("5130 RT 3000") also * support both HV values */ if (country_code == COUNTRY_EUROPE_208) break; /* explicit fallthrough: */ goto fallthrough_value; case 220: case 230: case 240: fallthrough_value: break; default: return NULL; } break; default: upsdebugx(3, "%s: can't autodetect settable voltages from %g", __func__, value); } snprintf(mge_scratch_buf, sizeof(mge_scratch_buf), "%.0f", value); return mge_scratch_buf; } /* FIXME/Note: If a mapping method is used, numeric/string mapping values * (and lines other than first) are in fact ignored for that direction, * but can be still useful for opposite */ static info_lkp_t nominal_output_voltage_info[] = { /* line-interactive, starting with Evolution, support both HV values */ /* HV models */ /* 208V */ { 200, "200", nominal_output_voltage_fun, NULL }, { 208, "208", nominal_output_voltage_fun, NULL }, /* HV models */ /* 230V */ { 220, "220", nominal_output_voltage_fun, NULL }, { 230, "230", nominal_output_voltage_fun, NULL }, { 240, "240", nominal_output_voltage_fun, NULL }, /* LV models */ { 100, "100", nominal_output_voltage_fun, NULL }, { 110, "110", nominal_output_voltage_fun, NULL }, { 120, "120", nominal_output_voltage_fun, NULL }, { 127, "127", nominal_output_voltage_fun, NULL }, { 0, NULL, NULL, NULL } }; /* Limit reporting "online / !online" to when "!off" */ static const char *eaton_converter_online_fun(double value) { unsigned ups_status = ups_status_get(); if (ups_status & STATUS(OFF)) return NULL; else return (d_equal(value, 0)) ? "!online" : "online"; } static info_lkp_t eaton_converter_online_info[] = { { 0, "dummy", eaton_converter_online_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t eaton_outlet_protection_status_info[] = { { 0, "not powered", NULL, NULL }, { 1, "not protected", NULL, NULL }, { 2, "protected", NULL, NULL }, { 0, NULL, NULL, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* Eaton / MGE HID usage table */ static usage_lkp_t mge_usage_lkp[] = { { "Undefined", 0xffff0000 }, { "STS", 0xffff0001 }, { "Environment", 0xffff0002 }, { "Statistic", 0xffff0003 }, { "StatisticSystem", 0xffff0004 }, { "USB", 0xffff0005 }, /* 0xffff0005-0xffff000f => Reserved */ { "Phase", 0xffff0010 }, { "PhaseID", 0xffff0011 }, { "Chopper", 0xffff0012 }, { "ChopperID", 0xffff0013 }, { "Inverter", 0xffff0014 }, { "InverterID", 0xffff0015 }, { "Rectifier", 0xffff0016 }, { "RectifierID", 0xffff0017 }, { "LCMSystem", 0xffff0018 }, { "LCMSystemID", 0xffff0019 }, { "LCMAlarm", 0xffff001a }, { "LCMAlarmID", 0xffff001b }, { "HistorySystem", 0xffff001c }, { "HistorySystemID", 0xffff001d }, { "Event", 0xffff001e }, { "EventID", 0xffff001f }, { "CircuitBreaker", 0xffff0020 }, { "TransferForbidden", 0xffff0021 }, { "OverallAlarm", 0xffff0022 }, /* renamed to Alarm in Eaton SW! */ { "Dephasing", 0xffff0023 }, { "BypassBreaker", 0xffff0024 }, { "PowerModule", 0xffff0025 }, { "PowerRate", 0xffff0026 }, { "PowerSource", 0xffff0027 }, { "CurrentPowerSource", 0xffff0028 }, { "RedundancyLevel", 0xffff0029 }, { "RedundancyLost", 0xffff002a }, { "NotificationStatus", 0xffff002b }, { "ProtectionLost", 0xffff002c }, { "ConfigurationFailure", 0xffff002d }, { "CompatibilityFailure", 0xffff002e }, /* 0xffff002e-0xffff003f => Reserved */ { "SwitchType", 0xffff0040 }, /* renamed to Type in Eaton SW! */ { "ConverterType", 0xffff0041 }, { "FrequencyConverterMode", 0xffff0042 }, { "AutomaticRestart", 0xffff0043 }, { "ForcedReboot", 0xffff0044 }, { "TestPeriod", 0xffff0045 }, { "EnergySaving", 0xffff0046 }, { "StartOnBattery", 0xffff0047 }, { "Schedule", 0xffff0048 }, { "DeepDischargeProtection", 0xffff0049 }, { "ShortCircuit", 0xffff004a }, { "ExtendedVoltageMode", 0xffff004b }, { "SensitivityMode", 0xffff004c }, { "RemainingCapacityLimitSetting", 0xffff004d }, { "ExtendedFrequencyMode", 0xffff004e }, { "FrequencyConverterModeSetting", 0xffff004f }, { "LowVoltageBoostTransfer", 0xffff0050 }, { "HighVoltageBoostTransfer", 0xffff0051 }, { "LowVoltageBuckTransfer", 0xffff0052 }, { "HighVoltageBuckTransfer", 0xffff0053 }, { "OverloadTransferEnable", 0xffff0054 }, { "OutOfToleranceTransferEnable", 0xffff0055 }, { "ForcedTransferEnable", 0xffff0056 }, { "LowVoltageBypassTransfer", 0xffff0057 }, { "HighVoltageBypassTransfer", 0xffff0058 }, { "FrequencyRangeBypassTransfer", 0xffff0059 }, { "LowVoltageEcoTransfer", 0xffff005a }, { "HighVoltageEcoTransfer", 0xffff005b }, { "FrequencyRangeEcoTransfer", 0xffff005c }, { "ShutdownTimer", 0xffff005d }, { "StartupTimer", 0xffff005e }, { "RestartLevel", 0xffff005f }, { "PhaseOutOfRange", 0xffff0060 }, { "CurrentLimitation", 0xffff0061 }, { "ThermalOverload", 0xffff0062 }, { "SynchroSource", 0xffff0063 }, { "FuseFault", 0xffff0064 }, { "ExternalProtectedTransfert", 0xffff0065 }, { "ExternalForcedTransfert", 0xffff0066 }, { "Compensation", 0xffff0067 }, { "EmergencyStop", 0xffff0068 }, { "PowerFactor", 0xffff0069 }, { "PeakFactor", 0xffff006a }, { "ChargerType", 0xffff006b }, { "HighPositiveDCBusVoltage", 0xffff006c }, { "LowPositiveDCBusVoltage", 0xffff006d }, { "HighNegativeDCBusVoltage", 0xffff006e }, { "LowNegativeDCBusVoltage", 0xffff006f }, { "FrequencyRangeTransfer", 0xffff0070 }, { "WiringFaultDetection", 0xffff0071 }, { "ControlStandby", 0xffff0072 }, { "ShortCircuitTolerance", 0xffff0073 }, { "VoltageTooHigh", 0xffff0074 }, { "VoltageTooLow", 0xffff0075 }, { "DCBusUnbalanced", 0xffff0076 }, { "FanFailure", 0xffff0077 }, { "WiringFault", 0xffff0078 }, { "Floating", 0xffff0079 }, { "OverCurrent", 0xffff007a }, { "RemainingActivePower", 0xffff007b }, { "Energy", 0xffff007c }, { "Threshold", 0xffff007d }, { "OverThreshold", 0xffff007e }, /* 0xffff007f => Reserved */ { "Sensor", 0xffff0080 }, { "LowHumidity", 0xffff0081 }, { "HighHumidity", 0xffff0082 }, { "LowTemperature", 0xffff0083 }, { "HighTemperature", 0xffff0084 }, { "ECOControl", 0xffff0085 }, { "Efficiency", 0xffff0086 }, { "ABMEnable", 0xffff0087 }, { "NegativeCurrent", 0xffff0088 }, { "AutomaticStart", 0xffff0089 }, /* 0xffff008a-0xffff008f => Reserved */ { "Count", 0xffff0090 }, { "Timer", 0xffff0091 }, { "Interval", 0xffff0092 }, { "TimerExpired", 0xffff0093 }, { "Mode", 0xffff0094 }, { "Country", 0xffff0095 }, { "State", 0xffff0096 }, { "Time", 0xffff0097 }, { "Code", 0xffff0098 }, { "DataValid", 0xffff0099 }, { "ToggleTimer", 0xffff009a }, { "BypassTransferDelay", 0xffff009b }, { "HysteresisVoltageTransfer", 0xffff009c }, { "SlewRate", 0xffff009d }, /* 0xffff009e-0xffff009f => Reserved */ { "PDU", 0xffff00a0 }, { "Breaker", 0xffff00a1 }, { "BreakerID", 0xffff00a2 }, { "OverVoltage", 0xffff00a3 }, { "Tripped", 0xffff00a4 }, { "OverEnergy", 0xffff00a5 }, { "OverHumidity", 0xffff00a6 }, { "ConfigurationReset", 0xffff00a7 }, /* renamed from LCDControl in Eaton SW! */ { "Level", 0xffff00a8 }, { "PDUType", 0xffff00a9 }, { "ReactivePower", 0xffff00aa }, { "Pole", 0xffff00ab }, { "PoleID", 0xffff00ac }, { "Reset", 0xffff00ad }, { "WatchdogReset", 0xffff00ae }, /* 0xffff00af-0xffff00df => Reserved */ { "iDesignator", 0xffff00ba }, { "COPIBridge", 0xffff00e0 }, { "Gateway", 0xffff00e1 }, { "System", 0xffff00e5 }, { "Status", 0xffff00e9 }, /* 0xffff00ee-0xffff00ef => Reserved */ { "iModel", 0xffff00f0 }, { "iVersion", 0xffff00f1 }, { "iTechnicalLevel", 0xffff00f2 }, { "iPartNumber", 0xffff00f3 }, { "iReferenceNumber", 0xffff00f4 }, { "iGang", 0xffff00f5 }, /* 0xffff00f6-0xffff00ff => Reserved */ /* end of table */ { NULL, 0 } }; static usage_tables_t mge_utab[] = { mge_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* Model Name formating entries */ /* --------------------------------------------------------------- */ typedef struct { const char *iProduct; const char *iModel; models_type_t type; /* enumerated model type */ const char *name; /* optional (defaults to " " if NULL) */ } models_name_t; /* * Do not remove models from this list, but instead comment them * out if not needed. This allows us to quickly add overrides for * specific models only, should this be needed. */ static models_name_t mge_model_names [] = { /* Ellipse models */ { "ELLIPSE", "300", MGE_DEFAULT_OFFLINE, "ellipse 300" }, { "ELLIPSE", "500", MGE_DEFAULT_OFFLINE, "ellipse 500" }, { "ELLIPSE", "650", MGE_DEFAULT_OFFLINE, "ellipse 650" }, { "ELLIPSE", "800", MGE_DEFAULT_OFFLINE, "ellipse 800" }, { "ELLIPSE", "1200", MGE_DEFAULT_OFFLINE, "ellipse 1200" }, /* Ellipse Premium models */ { "ellipse", "PR500", MGE_DEFAULT_OFFLINE, "ellipse premium 500" }, { "ellipse", "PR650", MGE_DEFAULT_OFFLINE, "ellipse premium 650" }, { "ellipse", "PR800", MGE_DEFAULT_OFFLINE, "ellipse premium 800" }, { "ellipse", "PR1200", MGE_DEFAULT_OFFLINE, "ellipse premium 1200" }, /* Ellipse "Pro" */ { "ELLIPSE", "600", MGE_DEFAULT_OFFLINE, "Ellipse 600" }, { "ELLIPSE", "750", MGE_DEFAULT_OFFLINE, "Ellipse 750" }, { "ELLIPSE", "1000", MGE_DEFAULT_OFFLINE, "Ellipse 1000" }, { "ELLIPSE", "1500", MGE_DEFAULT_OFFLINE, "Ellipse 1500" }, /* Ellipse MAX */ { "Ellipse MAX", "600", MGE_DEFAULT_OFFLINE, NULL }, { "Ellipse MAX", "850", MGE_DEFAULT_OFFLINE, NULL }, { "Ellipse MAX", "1100", MGE_DEFAULT_OFFLINE, NULL }, { "Ellipse MAX", "1500", MGE_DEFAULT_OFFLINE, NULL }, /* Protection Center */ { "PROTECTIONCENTER", "420", MGE_DEFAULT_OFFLINE, "Protection Center 420" }, { "PROTECTIONCENTER", "500", MGE_DEFAULT_OFFLINE, "Protection Center 500" }, { "PROTECTIONCENTER", "675", MGE_DEFAULT_OFFLINE, "Protection Center 675" }, /* Protection Station, supports Eco control */ { "Protection Station", "500", MGE_PEGASUS, NULL }, { "Protection Station", "650", MGE_PEGASUS, NULL }, { "Protection Station", "800", MGE_PEGASUS, NULL }, /* Ellipse ECO, also supports Eco control */ { "Ellipse ECO", "650", MGE_PEGASUS, NULL }, { "Ellipse ECO", "800", MGE_PEGASUS, NULL }, { "Ellipse ECO", "1200", MGE_PEGASUS, NULL }, { "Ellipse ECO", "1600", MGE_PEGASUS, NULL }, /* 3S, also supports Eco control on some models (AUS 700 and US 750)*/ { "3S", "450", MGE_DEFAULT_OFFLINE, NULL }, /* US only */ { "3S", "550", MGE_DEFAULT_OFFLINE, NULL }, /* US 120V + EU 230V + AUS 240V */ { "3S", "700", MGE_3S, NULL }, /* EU 230V + AUS 240V (w/ eco control) */ { "3S", "750", MGE_3S, NULL }, /* US 120V (w/ eco control) */ /* Evolution models */ { "Evolution", "500", MGE_DEFAULT, "Pulsar Evolution 500" }, { "Evolution", "800", MGE_DEFAULT, "Pulsar Evolution 800" }, { "Evolution", "1100", MGE_DEFAULT, "Pulsar Evolution 1100" }, { "Evolution", "1500", MGE_DEFAULT, "Pulsar Evolution 1500" }, { "Evolution", "2200", MGE_DEFAULT, "Pulsar Evolution 2200" }, { "Evolution", "3000", MGE_DEFAULT, "Pulsar Evolution 3000" }, { "Evolution", "3000XL", MGE_DEFAULT, "Pulsar Evolution 3000 XL" }, /* Newer Evolution models */ { "Evolution", "650", MGE_EVOLUTION_650, NULL }, { "Evolution", "850", MGE_EVOLUTION_850, NULL }, { "Evolution", "1150", MGE_EVOLUTION_1150, NULL }, { "Evolution", "S 1250", MGE_EVOLUTION_S_1250, NULL }, { "Evolution", "1550", MGE_EVOLUTION_1550, NULL }, { "Evolution", "S 1750", MGE_EVOLUTION_S_1750, NULL }, { "Evolution", "2000", MGE_EVOLUTION_2000, NULL }, { "Evolution", "S 2500", MGE_EVOLUTION_S_2500, NULL }, { "Evolution", "S 3000", MGE_EVOLUTION_S_3000, NULL }, /* Eaton 5P */ { "Eaton 5P", "650", EATON_5P, "5P 650" }, { "Eaton 5P", "850", EATON_5P, "5P 850" }, { "Eaton 5P", "1150", EATON_5P, "5P 1150" }, { "Eaton 5P", "1550", EATON_5P, "5P 1550" }, /* Eaton 5PX, names assumed per VA numbers in * https://www.eaton.com/gb/en-gb/catalog/backup-power-ups-surge-it-power-distribution/eaton-5px-ups-emea.html#tab-2 * and a user report in https://github.com/networkupstools/nut/issues/2380 * Fixes for actual product/model names reported via USB are welcome */ { "Eaton 5PX", "1500", EATON_5P, NULL }, { "Eaton 5PX", "2200", EATON_5P, NULL }, { "Eaton 5PX", "3000", EATON_5P, NULL }, /* Eaton 5SC, names assumed per VA numbers in * https://www.eaton.com/gb/en-gb/site-search.html.searchTerm$5sc.tabs$all.html * and a user report in https://github.com/networkupstools/nut/issues/2380 * Fixes for actual product/model names reported via USB are welcome */ { "Eaton 5SC", "500", EATON_5P, NULL }, { "Eaton 5SC", "750", EATON_5P, NULL }, { "Eaton 5SC", "1000", EATON_5P, NULL }, { "Eaton 5SC", "1500", EATON_5P, NULL }, { "Eaton 5SC", "2200", EATON_5P, NULL }, { "Eaton 5SC", "3000", EATON_5P, NULL }, /* Eaton 5S, sort of: * Per https://github.com/networkupstools/nut/issues/2380#issuecomment-2705813132 * a device marketed as Eaton "5S1200AU" self-identified as an "Ellipse PRO" in * USB metadata; the trailing space after "1200 " was significant for matching it. */ { "Ellipse PRO", "1200 ", EATON_5P, "Eaton 5S1200" }, /* Eaton 9E entry-level series per discussions in * https://github.com/networkupstools/nut/issues/1925 * https://github.com/networkupstools/nut/issues/2380 * https://github.com/networkupstools/nut/issues/2492 */ { "Eaton 9E", "1000", EATON_9E, "9E1000" }, { "Eaton 9E", "1000i", EATON_9E, "9E1000i" }, { "Eaton 9E", "1000iau", EATON_9E, "9E1000iau" }, { "Eaton 9E", "1000ir", EATON_9E, "9E1000ir" }, { "Eaton 9E", "2000", EATON_9E, "9E2000" }, { "Eaton 9E", "2000i", EATON_9E, "9E2000i" }, { "Eaton 9E", "2000iau", EATON_9E, "9E2000iau" }, { "Eaton 9E", "2000ir", EATON_9E, "9E2000ir" }, { "Eaton 9E", "3000", EATON_9E, "9E3000" }, { "Eaton 9E", "3000i", EATON_9E, "9E3000i" }, { "Eaton 9E", "3000iau", EATON_9E, "9E3000iau" }, { "Eaton 9E", "3000ir", EATON_9E, "9E3000ir" }, { "Eaton 9E", "3000ixl", EATON_9E, "9E3000ixl" }, { "Eaton 9E", "3000ixlau", EATON_9E, "9E3000ixlau" }, /* https://github.com/networkupstools/nut/issues/1925#issuecomment-1609262963 * if we failed to get iManufacturer, iProduct and iSerialNumber but saw * the UPS.Flow.[4].ConfigApparentPower (the "2000" or "3000" part here) */ { "unknown", "1000", EATON_9E, "9E1000i (presumed)" }, { "unknown", "2000", EATON_9E, "9E2000i (presumed)" }, { "unknown", "3000", EATON_9E, "9E3000i (presumed)" }, /* Eaton 9SX series per discussions in * https://github.com/networkupstools/nut/issues/2685 * https://www.eaton.com/gb/en-gb/site-search.html.searchTerm$9sx.tabs$all.html */ { "Eaton 9SX", "700i", EATON_9E, "9SX700i" }, { "Eaton 9SX", "1000i", EATON_9E, "9SX1000i" }, { "Eaton 9SX", "1000im", EATON_9E, "9SX1000im" }, { "Eaton 9SX", "1500i", EATON_9E, "9SX1500i" }, { "Eaton 9SX", "2000i", EATON_9E, "9SX2000i" }, { "Eaton 9SX", "3000i", EATON_9E, "9SX3000i" }, { "Eaton 9SX", "3000im", EATON_9E, "9SX3000im" }, { "Eaton 9SX", "1000ir", EATON_9E, "9SX1000ir" }, { "Eaton 9SX", "1500ir", EATON_9E, "9SX1500ir" }, { "Eaton 9SX", "2000ir", EATON_9E, "9SX2000ir" }, { "Eaton 9SX", "3000ir", EATON_9E, "9SX3000ir" }, /* Eaton 9PX series * https://www.eaton.com/gb/en-gb/site-search.html.searchTerm$9px.tabs$all.html */ { "Eaton 9PX", "1000irt2u", EATON_9E, "9px1000irt2u" }, { "Eaton 9PX", "1500irt2u", EATON_9E, "9px1500irt2u" }, { "Eaton 9PX", "1500irtm", EATON_9E, "9px1500irtm" }, { "Eaton 9PX", "2200irt2u", EATON_9E, "9px2200irt2u" }, { "Eaton 9PX", "2200irt3u", EATON_9E, "9px2200irt3u" }, { "Eaton 9PX", "3000irt2u", EATON_9E, "9px3000irt2u" }, { "Eaton 9PX", "3000irt3u", EATON_9E, "9px3000irt3u" }, { "Eaton 9PX", "3000irtm", EATON_9E, "9px3000irtm" }, /* Pulsar M models */ { "PULSAR M", "2200", MGE_PULSAR_M_2200, NULL }, { "PULSAR M", "3000", MGE_PULSAR_M_3000, NULL }, { "PULSAR M", "3000 XL", MGE_PULSAR_M_3000_XL, NULL }, /* Eaton'ified names */ { "EX", "2200", MGE_PULSAR_M_2200, NULL }, { "EX", "3000", MGE_PULSAR_M_3000, NULL }, { "EX", "3000 XL", MGE_PULSAR_M_3000, NULL }, /* Pulsar models (TBR) */ /* { "Pulsar", "700", MGE_DEFAULT, NULL }, */ /* { "Pulsar", "1000", MGE_DEFAULT, NULL }, */ /* { "Pulsar", "1500", MGE_DEFAULT, NULL }, */ /* { "Pulsar", "1000 RT2U", MGE_DEFAULT, NULL }, */ /* { "Pulsar", "1500 RT2U", MGE_DEFAULT, NULL }, */ /* Eaton'ified names (TBR) */ /* { "EX", "700", MGE_DEFAULT, NULL }, */ /* { "EX", "1000", MGE_DEFAULT, NULL }, */ /* { "EX", "1500", MGE_DEFAULT, NULL }, */ /* { "EX", "1000 RT2U", MGE_DEFAULT, NULL }, */ /* { "EX", "1500 RT2U", MGE_DEFAULT, NULL }, */ /* Pulsar MX models */ { "PULSAR", "MX4000", MGE_DEFAULT, "Pulsar MX 4000 RT" }, { "PULSAR", "MX5000", MGE_DEFAULT, "Pulsar MX 5000 RT" }, /* NOVA models */ { "NOVA AVR", "500", MGE_DEFAULT, "Nova 500 AVR" }, { "NOVA AVR", "600", MGE_DEFAULT, "Nova 600 AVR" }, { "NOVA AVR", "625", MGE_DEFAULT, "Nova 625 AVR" }, { "NOVA AVR", "1100", MGE_DEFAULT, "Nova 1100 AVR" }, { "NOVA AVR", "1250", MGE_DEFAULT, "Nova 1250 AVR" }, /* EXtreme C (EMEA) */ { "EXtreme", "700C", MGE_DEFAULT, "Pulsar EXtreme 700C" }, { "EXtreme", "1000C", MGE_DEFAULT, "Pulsar EXtreme 1000C" }, { "EXtreme", "1500C", MGE_DEFAULT, "Pulsar EXtreme 1500C" }, { "EXtreme", "1500CCLA", MGE_DEFAULT, "Pulsar EXtreme 1500C CLA" }, { "EXtreme", "2200C", MGE_DEFAULT, "Pulsar EXtreme 2200C" }, { "EXtreme", "3200C", MGE_DEFAULT, "Pulsar EXtreme 3200C" }, /* EXtreme C (USA, aka "EX RT") */ { "EX", "700RT", MGE_DEFAULT, "Pulsar EX 700 RT" }, { "EX", "1000RT", MGE_DEFAULT, "Pulsar EX 1000 RT" }, { "EX", "1500RT", MGE_DEFAULT, "Pulsar EX 1500 RT" }, { "EX", "2200RT", MGE_DEFAULT, "Pulsar EX 2200 RT" }, { "EX", "3200RT", MGE_DEFAULT, "Pulsar EX 3200 RT" }, /* Comet EX RT three phased */ { "EX", "5RT31", MGE_DEFAULT, "EX 5 RT 3:1" }, { "EX", "7RT31", MGE_DEFAULT, "EX 7 RT 3:1" }, { "EX", "11RT31", MGE_DEFAULT, "EX 11 RT 3:1" }, /* Comet EX RT mono phased */ { "EX", "5RT", MGE_DEFAULT, "EX 5 RT" }, { "EX", "7RT", MGE_DEFAULT, "EX 7 RT" }, { "EX", "11RT", MGE_DEFAULT, "EX 11 RT" }, /* Galaxy 3000 */ { "GALAXY", "3000_10", MGE_DEFAULT, "Galaxy 3000 10 kVA" }, { "GALAXY", "3000_15", MGE_DEFAULT, "Galaxy 3000 15 kVA" }, { "GALAXY", "3000_20", MGE_DEFAULT, "Galaxy 3000 20 kVA" }, { "GALAXY", "3000_30", MGE_DEFAULT, "Galaxy 3000 30 kVA" }, /* end of structure. */ { NULL, NULL, 0, NULL } }; /* --------------------------------------------------------------- */ /* Data lookup table (HID <-> NUT) */ /* --------------------------------------------------------------- */ static hid_info_t mge_hid2nut[] = { /* Device collection */ /* Just declared to call *hid2info */ { "device.country", ST_FLAG_STRING, 20, "UPS.PowerSummary.Country", NULL, "Europe", HU_FLAG_STATIC, eaton_check_country_info }, { "device.usb.version", ST_FLAG_STRING, 20, "UPS.System.USB.iVersion", NULL, NULL, HU_FLAG_STATIC, stringid_conversion }, /* FIXME */ /* { "device.usb.mode", ST_FLAG_STRING, 20, "UPS.System.USB.Mode", NULL, NULL, HU_FLAG_STATIC, stringid_conversion }, */ /* not useful ,not a string (1 to set in bootloader ) */ /*{ "device.gateway.power.rate", ST_FLAG_STRING, 20, "UPS.System.Gateway.PowerRate", NULL, NULL, HU_FLAG_STATIC, stringid_conversion }, */ /* not useful , not a string (level of power provided by the UPS to the network card */ /* Battery page */ { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerSummary.RemainingCapacityLimitSetting", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.charge.low", 0, 0, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_STATIC , NULL }, /* Read only */ { "battery.charge.restart", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.PowerSummary.RestartLevel", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.capacity", 0, 0, "UPS.BatterySystem.Battery.DesignCapacity", NULL, "%s", HU_FLAG_STATIC, mge_battery_capacity }, /* conversion needed from As to Ah */ { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.runtime.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.RemainingTimeLimit", NULL, "%.0f", 0, NULL }, { "battery.runtime.elapsed", 0, 0, "UPS.StatisticSystem.Input.[1].Statistic.[1].Time", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL }, { "battery.runtime.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.RemainingTimeLimit", NULL, "%.0f", 0, NULL }, { "battery.temperature", 0, 0, "UPS.BatterySystem.Battery.Temperature", NULL, "%s", 0, kelvin_celsius_conversion }, { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, { "battery.voltage", 0, 0, "UPS.BatterySystem.Voltage", NULL, "%.1f", 0, NULL }, { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, mge_battery_voltage }, { "battery.voltage.nominal", 0, 0, "UPS.BatterySystem.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "battery.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%s", HU_FLAG_STATIC, mge_battery_voltage_nominal }, { "battery.protection", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.BatterySystem.Battery.DeepDischargeProtection", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info }, { "battery.energysave", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Input.[3].EnergySaving", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info }, { "battery.energysave.load", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Input.[3].ConfigPercentLoad", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, /* Current implementation */ { "battery.energysave.delay", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Input.[3].EnergySaving.ShutdownTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, /* Newer implementation */ { "battery.energysave.delay", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Input.[3].ShutdownTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.energysave.realpower", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Input.[3].ConfigActivePower", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, /* ABM (Advanced Battery Monitoring) processing * Must be processed before the BOOL status */ /* Not published, just to store internally if ABM is enabled or disabled */ { "battery.charger.abm.status", 0, 0, "UPS.BatterySystem.Charger.ABMEnable", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_enabled_info }, /* * Process two different ABM paths (each of which expose different values for CHRG/DISCHRG in ABM-enabled paths) */ /* Not published, used to internally decide and store taken ABM path */ { "battery.charger.mode.status", 0, 0, "UPS.BatterySystem.Charger.Mode", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_path_mode_info }, { "battery.charger.type.status", 0, 0, "UPS.BatterySystem.Charger.Status", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_path_status_info }, /* Published ABM status for the respective taken ABM path */ { "battery.charger.status", 0, 0, "UPS.BatterySystem.Charger.Mode", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_status_info }, { "battery.charger.status", 0, 0, "UPS.BatterySystem.Charger.Status", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_status_info }, /* Same as the one above, but for legacy units */ /* Refer to Note 1 (This point will need more clarification!) { "battery.charger.status", 0, 0, "UPS.BatterySystem.Charger.PresentStatus.Used", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_enabled_legacy_info }, */ /* Published battery charger type (can be ABM, CC, ...) */ { "battery.charger.type", 0, 0, "UPS.BatterySystem.Charger.ChargerType", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_charger_type_info }, /* UPS page */ { "ups.efficiency", 0, 0, "UPS.PowerConverter.Output.Efficiency", NULL, "%.0f", 0, NULL }, { "ups.firmware", 0, 0, "UPS.PowerSummary.iVersion", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, { "ups.load", 0, 0, "UPS.PowerSummary.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.load.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.Flow.[4].ConfigPercentLoad", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL}, { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL}, { "ups.timer.start", 0, 0, "UPS.PowerSummary.DelayBeforeStartup", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.shutdown", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.reboot", 0, 0, "UPS.PowerSummary.DelayBeforeReboot", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.test.result", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "%s", 0, test_read_info }, { "ups.test.interval", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.BatterySystem.Battery.TestPeriod", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, /* Duplicate data for some units (such as 3S) that use a different path * Only the first valid one will be used */ { "ups.beeper.status", 0 ,0, "UPS.BatterySystem.Battery.AudibleAlarmControl", NULL, "%s", HU_FLAG_SEMI_STATIC, beeper_info }, { "ups.beeper.status", 0 ,0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "%s", HU_FLAG_SEMI_STATIC, beeper_info }, { "ups.beeper.status", 0 ,0, "UPS.AudibleAlarmControl", NULL, "%s", HU_FLAG_SEMI_STATIC, beeper_info }, /* yonesmit - support for Masterpower MF-UPS650VA */ { "ups.temperature", 0, 0, "UPS.PowerSummary.Temperature", NULL, "%s", 0, kelvin_celsius_conversion }, { "ups.power", 0, 0, "UPS.PowerConverter.Output.ApparentPower", NULL, "%.0f", 0, NULL }, { "ups.L1.power", 0, 0, "UPS.PowerConverter.Output.Phase.[1].ApparentPower", NULL, "%.0f", 0, NULL }, { "ups.L2.power", 0, 0, "UPS.PowerConverter.Output.Phase.[2].ApparentPower", NULL, "%.0f", 0, NULL }, { "ups.L3.power", 0, 0, "UPS.PowerConverter.Output.Phase.[3].ApparentPower", NULL, "%.0f", 0, NULL }, { "ups.power.nominal", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "ups.realpower", 0, 0, "UPS.PowerConverter.Output.ActivePower", NULL, "%.0f", 0, NULL }, /* When not available, process an approximation from other data, * but map to apparent power to be called */ { "ups.realpower", 0, 0, "UPS.Flow.[4].ConfigApparentPower", NULL, "-1", 0, eaton_compute_realpower_info }, { "ups.L1.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[1].ActivePower", NULL, "%.0f", 0, NULL }, { "ups.L2.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[2].ActivePower", NULL, "%.0f", 0, NULL }, { "ups.L3.realpower", 0, 0, "UPS.PowerConverter.Output.Phase.[3].ActivePower", NULL, "%.0f", 0, NULL }, { "ups.realpower.nominal", 0, 0, "UPS.Flow.[4].ConfigActivePower", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "ups.start.auto", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Input.[1].AutomaticRestart", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info }, { "ups.start.battery", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Input.[3].StartOnBattery", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info }, { "ups.start.reboot", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.ForcedReboot", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info }, { "ups.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.PresentStatus.Switchable", NULL, "%s", HU_FLAG_SEMI_STATIC | HU_FLAG_ENUM, eaton_enable_disable_info }, #ifdef HAVE_STRPTIME { "ups.date", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.Time", NULL, "%s", 0, mge_date_conversion }, { "ups.time", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.Time", NULL, "%s", 0, mge_time_conversion }, #else { "ups.date", 0, 0, "UPS.PowerSummary.Time", NULL, "%s", 0, mge_date_conversion }, { "ups.time", 0, 0, "UPS.PowerSummary.Time", NULL, "%s", 0, mge_time_conversion }, #endif /* HAVE_STRPTIME */ { "ups.type", 0, 0, "UPS.PowerConverter.ConverterType", NULL, "%s", HU_FLAG_STATIC, mge_upstype_conversion }, /* Special case: boolean values that are mapped to ups.status and ups.alarm */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[3].PresentStatus.Used", NULL, NULL, 0, mge_onbatt_info }, #if 0 /* NOTE: see entry with eaton_converter_online_info below now */ { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.Used", NULL, NULL, 0, online_info }, #endif /* These 2 ones are used when ABM is disabled */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, eaton_discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, eaton_charging_info }, /* And this one when ABM is enabled (same as battery.charger.status) */ { "BOOL", 0, 0, "UPS.BatterySystem.Charger.Mode", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_chrg_dischrg_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Charger.Status", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_abm_chrg_dischrg_info }, /* FIXME: on Dell, the above requires an "AND" with "UPS.BatterySystem.Charger.Mode = 1" */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, /* Output overload, Level 1 (FIXME: add the level?) */ { "BOOL", 0, 0, "UPS.PowerConverter.Output.Overload.[1].PresentStatus.OverThreshold", NULL, NULL, 0, overload_info }, /* Output overload, Level 2 (FIXME: add the level?) */ { "BOOL", 0, 0, "UPS.PowerConverter.Output.Overload.[2].PresentStatus.OverThreshold", NULL, NULL, 0, overload_info }, /* Output overload, Level 3 (FIXME: add the level?) */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, /* FIXME: on Dell, the above requires an "AND" with "UPS.BatterySystem.Battery.Test = 3 " */ { "BOOL", 0, 0, "UPS.LCMSystem.LCMAlarm.[2].PresentStatus.TimerExpired", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.Buck", NULL, NULL, 0, trim_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.Boost", NULL, NULL, 0, boost_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.VoltageOutOfRange", NULL, NULL, 0, vrange_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.FrequencyOutOfRange", NULL, NULL, 0, frange_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Good", NULL, NULL, 0, off_info }, /* NOTE: UPS.PowerConverter.Input.[1].PresentStatus.Used" must only be considered when not "OFF", * and must hence be after "UPS.PowerSummary.PresentStatus.Good" */ { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.Used", NULL, NULL, 0, eaton_converter_online_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[2].PresentStatus.Used", NULL, NULL, 0, bypass_auto_info }, /* Automatic bypass */ /* NOTE: entry [3] is above as mge_onbatt_info */ { "BOOL", 0, 0, "UPS.PowerConverter.Input.[4].PresentStatus.Used", NULL, NULL, 0, bypass_manual_info }, /* Manual bypass */ { "BOOL", 0, 0, "UPS.PowerConverter.Input.[5].PresentStatus.Used", NULL, NULL, 0, eco_mode_info }, /* ECO(HE), ESS Mode */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FanFailure", NULL, NULL, 0, fanfail_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.Present", NULL, NULL, 0, nobattery_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Charger.PresentStatus.InternalFailure", NULL, NULL, 0, chargerfail_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Charger.PresentStatus.VoltageTooHigh", NULL, NULL, 0, battvolthi_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.VoltageTooHigh", NULL, NULL, 0, battvolthi_info }, /* Battery DC voltage too high! */ { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.VoltageTooHigh", NULL, NULL, 0, battvolthi_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Charger.PresentStatus.VoltageTooLow", NULL, NULL, 0, battvoltlo_info }, { "BOOL", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.VoltageTooLow", NULL, NULL, 0, mge_onbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.InternalFailure", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.OverTemperature", NULL, NULL, 0, overheat_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, /* Vendor specific ups.alarm */ { "ups.alarm", 0, 0, "UPS.PowerSummary.PresentStatus.EmergencyStop", NULL, NULL, 0, mge_emergency_stop }, { "ups.alarm", 0, 0, "UPS.PowerConverter.Input.[1].PresentStatus.WiringFault", NULL, NULL, 0, mge_wiring_fault }, { "ups.alarm", 0, 0, "UPS.PowerSummary.PresentStatus.ConfigurationFailure", NULL, NULL, 0, mge_config_failure }, { "ups.alarm", 0, 0, "UPS.PowerConverter.Inverter.PresentStatus.VoltageTooHigh", NULL, NULL, 0, mge_inverter_volthi }, { "ups.alarm", 0, 0, "UPS.PowerConverter.Inverter.PresentStatus.VoltageTooLow", NULL, NULL, 0, mge_inverter_voltlo }, { "ups.alarm", 0, 0, "UPS.PowerConverter.Output.PresentStatus.ShortCircuit", NULL, NULL, 0, mge_short_circuit }, /* Input page */ { "input.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Voltage", NULL, "%.1f", 0, NULL }, { "input.L1-N.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[1].Voltage", NULL, "%.1f", 0, NULL }, { "input.L2-N.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[2].Voltage", NULL, "%.1f", 0, NULL }, { "input.L3-N.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[3].Voltage", NULL, "%.1f", 0, NULL }, { "input.L1-L2.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[12].Voltage", NULL, "%.1f", 0, NULL }, { "input.L2-L3.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[23].Voltage", NULL, "%.1f", 0, NULL }, { "input.L3-L1.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[31].Voltage", NULL, "%.1f", 0, NULL }, { "input.voltage.nominal", 0, 0, "UPS.Flow.[1].ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.current", 0, 0, "UPS.PowerConverter.Input.[1].Current", NULL, "%.2f", 0, NULL }, { "input.L1.current", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[1].Current", NULL, "%.1f", 0, NULL }, { "input.L2.current", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[2].Current", NULL, "%.1f", 0, NULL }, { "input.L3.current", 0, 0, "UPS.PowerConverter.Input.[1].Phase.[3].Current", NULL, "%.1f", 0, NULL }, { "input.current.nominal", 0, 0, "UPS.Flow.[1].ConfigCurrent", NULL, "%.2f", HU_FLAG_STATIC, NULL }, { "input.frequency", 0, 0, "UPS.PowerConverter.Input.[1].Frequency", NULL, "%.1f", 0, NULL }, { "input.frequency.nominal", 0, 0, "UPS.Flow.[1].ConfigFrequency", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* same as "input.transfer.boost.low" */ { "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.eco.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageEcoTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.bypass.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageBypassTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.boost.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageBoostTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.boost.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.HighVoltageBoostTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.trim.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageBuckTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, /* same as "input.transfer.trim.high" */ { "input.transfer.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.eco.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.HighVoltageEcoTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.bypass.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.HighVoltageBypassTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.frequency.bypass.range", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.FrequencyRangeBypassTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.frequency.eco.range", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.FrequencyRangeEcoTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.hysteresis", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.HysteresisVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.bypass.forced", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerConverter.Input.[2].ForcedTransferEnable", NULL, "%.0f", HU_FLAG_SEMI_STATIC, eaton_enable_disable_info }, { "input.transfer.bypass.overload", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerConverter.Input.[2].OverloadTransferEnable", NULL, "%.0f", HU_FLAG_SEMI_STATIC, eaton_enable_disable_info }, { "input.transfer.bypass.outlimits", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerConverter.Input.[2].OutOfToleranceTransferEnable", NULL, "%.0f", HU_FLAG_SEMI_STATIC, eaton_enable_disable_info }, { "input.transfer.trim.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.HighVoltageBuckTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.sensitivity", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerConverter.Output.SensitivityMode", NULL, "%s", HU_FLAG_SEMI_STATIC, mge_sensitivity_info }, { "input.voltage.extended", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.ExtendedVoltageMode", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info }, { "input.frequency.extended", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.ExtendedFrequencyMode", NULL, "%s", HU_FLAG_SEMI_STATIC, yes_no_info }, /* Bypass page */ { "input.bypass.voltage", 0, 0, "UPS.PowerConverter.Input.[2].Voltage", NULL, "%.1f", HU_FLAG_QUICK_POLL, NULL }, { "input.bypass.L1-N.voltage", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[1].Voltage", NULL, "%.1f", 0, NULL }, { "input.bypass.L2-N.voltage", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[2].Voltage", NULL, "%.1f", 0, NULL }, { "input.bypass.L3-N.voltage", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[3].Voltage", NULL, "%.1f", 0, NULL }, { "input.bypass.L1-L2.voltage", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[12].Voltage", NULL, "%.1f", 0, NULL }, { "input.bypass.L2-L3.voltage", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[23].Voltage", NULL, "%.1f", 0, NULL }, { "input.bypass.L3-L1.voltage", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[31].Voltage", NULL, "%.1f", 0, NULL }, { "input.bypass.voltage.nominal", 0, 0, "UPS.Flow.[2].ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.bypass.current", 0, 0, "UPS.PowerConverter.Input.[2].Current", NULL, "%.2f", 0, NULL }, { "input.bypass.L1.current", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[1].Current", NULL, "%.1f", 0, NULL }, { "input.bypass.L2.current", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[2].Current", NULL, "%.1f", 0, NULL }, { "input.bypass.L3.current", 0, 0, "UPS.PowerConverter.Input.[2].Phase.[3].Current", NULL, "%.1f", 0, NULL }, { "input.bypass.current.nominal", 0, 0, "UPS.Flow.[2].ConfigCurrent", NULL, "%.2f", HU_FLAG_STATIC, NULL }, { "input.bypass.frequency", 0, 0, "UPS.PowerConverter.Input.[2].Frequency", NULL, "%.1f", HU_FLAG_QUICK_POLL, NULL }, { "input.bypass.frequency.nominal", 0, 0, "UPS.Flow.[2].ConfigFrequency", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* Auto Bypass Mode on/off, to use when 'input.transfer.bypass.forced' is enabled */ { "input.bypass.switch.on", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerConverter.Input.[2].SwitchOnControl", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_input_bypass_mode_on_info }, { "input.bypass.switch.off", ST_FLAG_RW | ST_FLAG_STRING, 12, "UPS.PowerConverter.Input.[2].SwitchOffControl", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_input_bypass_mode_off_info }, /* Transfer on automatic Bypass switch with rules 'input.transfer.bypass.overload' and 'input.transfer.bypass.outlimits' */ { "input.bypass.switchable", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerConverter.Input.[2].Switchable", NULL, "%.0f", HU_FLAG_SEMI_STATIC, eaton_enable_disable_info }, /* Output page */ { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.1f", 0, NULL }, { "output.L1-N.voltage", 0, 0, "UPS.PowerConverter.Output.Phase.[1].Voltage", NULL, "%.1f", 0, NULL }, { "output.L2-N.voltage", 0, 0, "UPS.PowerConverter.Output.Phase.[2].Voltage", NULL, "%.1f", 0, NULL }, { "output.L3-N.voltage", 0, 0, "UPS.PowerConverter.Output.Phase.[3].Voltage", NULL, "%.1f", 0, NULL }, { "output.L1-L2.voltage", 0, 0, "UPS.PowerConverter.Output.Phase.[12].Voltage", NULL, "%.1f", 0, NULL }, { "output.L2-L3.voltage", 0, 0, "UPS.PowerConverter.Output.Phase.[23].Voltage", NULL, "%.1f", 0, NULL }, { "output.L3-L1.voltage", 0, 0, "UPS.PowerConverter.Output.Phase.[31].Voltage", NULL, "%.1f", 0, NULL }, { "output.voltage.nominal", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.Flow.[4].ConfigVoltage", NULL, "%.0f", HU_FLAG_SEMI_STATIC | HU_FLAG_ENUM, nominal_output_voltage_info }, { "output.current", 0, 0, "UPS.PowerConverter.Output.Current", NULL, "%.2f", 0, NULL }, { "output.L1.current", 0, 0, "UPS.PowerConverter.Output.Phase.[1].Current", NULL, "%.1f", 0, NULL }, { "output.L2.current", 0, 0, "UPS.PowerConverter.Output.Phase.[2].Current", NULL, "%.1f", 0, NULL }, { "output.L3.current", 0, 0, "UPS.PowerConverter.Output.Phase.[3].Current", NULL, "%.1f", 0, NULL }, { "output.current.nominal", 0, 0, "UPS.Flow.[4].ConfigCurrent", NULL, "%.2f", 0, NULL }, { "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%.1f", 0, NULL }, /* FIXME: can be RW (50/60) (or on .nominal)? */ { "output.frequency.nominal", 0, 0, "UPS.Flow.[4].ConfigFrequency", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "output.powerfactor", 0, 0, "UPS.PowerConverter.Output.PowerFactor", NULL, "%s", 0, mge_powerfactor_conversion }, /* Outlet page (using MGE UPS SYSTEMS - PowerShare technology) */ { "outlet.id", 0, 0, "UPS.OutletSystem.Outlet.[1].OutletID", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "outlet.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, "UPS.OutletSystem.Outlet.[1].OutletID", NULL, "Main Outlet", HU_FLAG_ABSENT, NULL }, { "outlet.switchable", 0, 0, "UPS.OutletSystem.Outlet.[1].PresentStatus.Switchable", NULL, "%s", HU_FLAG_STATIC, yes_no_info }, /* On Protection Station, the line below is the power consumption threshold * on the master outlet used to automatically power off the slave outlets. * Values: 10, 25 (default) or 60 VA. */ { "outlet.power", ST_FLAG_RW | ST_FLAG_STRING, 6, "UPS.OutletSystem.Outlet.[1].ConfigApparentPower", NULL, "%s", HU_FLAG_SEMI_STATIC | HU_FLAG_ENUM, pegasus_threshold_info }, { "outlet.power", 0, 0, "UPS.OutletSystem.Outlet.[1].ApparentPower", NULL, "%.0f", 0, NULL }, { "outlet.realpower", 0, 0, "UPS.OutletSystem.Outlet.[1].ActivePower", NULL, "%.0f", 0, NULL }, { "outlet.current", 0, 0, "UPS.OutletSystem.Outlet.[1].Current", NULL, "%.2f", 0, NULL }, { "outlet.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[1].PowerFactor", NULL, "%.2f", 0, NULL }, /* "%s", 0, mge_powerfactor_conversion }, */ /* First outlet */ { "outlet.1.id", 0, 0, "UPS.OutletSystem.Outlet.[2].OutletID", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "outlet.1.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, "UPS.OutletSystem.Outlet.[2].OutletID", NULL, "PowerShare Outlet 1", HU_FLAG_ABSENT, NULL }, { "outlet.1.switchable", 0, 0, "UPS.OutletSystem.Outlet.[2].PresentStatus.Switchable", NULL, "%s", HU_FLAG_STATIC, yes_no_info }, /* FIXME: should better use UPS.OutletSystem.Outlet.[1].Status? */ { "outlet.1.status", 0, 0, "UPS.OutletSystem.Outlet.[2].PresentStatus.SwitchOn/Off", NULL, "%s", 0, on_off_info }, { "outlet.1.protect.status", 0, 0, "UPS.OutletSystem.Outlet.[1].Status", NULL, "%s", 0, eaton_outlet_protection_status_info }, { "outlet.1.designator", 0, 0, "UPS.OutletSystem.Outlet.[1].iDesignator", NULL, NULL, HU_FLAG_STATIC, stringid_conversion }, /* FIXME */ /* For low end models, with 1 non backup'ed outlet */ { "outlet.1.status", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, "%s", 0, on_off_info }, /* FIXME: change to outlet.1.battery.charge.low, as in mge-xml.c?! */ { "outlet.1.autoswitch.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.OutletSystem.Outlet.[2].RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "outlet.1.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.OutletSystem.Outlet.[2].ShutdownTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "outlet.1.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.OutletSystem.Outlet.[2].StartupTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "outlet.1.power", 0, 0, "UPS.OutletSystem.Outlet.[2].ApparentPower", NULL, "%.0f", 0, NULL }, { "outlet.1.realpower", 0, 0, "UPS.OutletSystem.Outlet.[2].ActivePower", NULL, "%.0f", 0, NULL }, { "outlet.1.current", 0, 0, "UPS.OutletSystem.Outlet.[2].Current", NULL, "%.2f", 0, NULL }, { "outlet.1.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[2].PowerFactor", NULL, "%.2f", 0, NULL }, /* "%s", 0, mge_powerfactor_conversion }, */ /* 0: The outlet is not ECO controlled. / 1 : The outlet is ECO controlled. => Readonly! use some yes_no_info */ { "outlet.1.ecocontrol", 0, 0, "UPS.OutletSystem.Outlet.[2].ECOControl", NULL, "%s", HU_FLAG_SEMI_STATIC, outlet_eco_yes_no_info}, /* Second outlet */ { "outlet.2.id", 0, 0, "UPS.OutletSystem.Outlet.[3].OutletID", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "outlet.2.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, "UPS.OutletSystem.Outlet.[3].OutletID", NULL, "PowerShare Outlet 2", HU_FLAG_ABSENT, NULL }, /* needed for Pegasus to enable master/slave mode: * FIXME: rename to something more suitable (outlet.?) */ { "outlet.2.switchable", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.OutletSystem.Outlet.[3].PresentStatus.Switchable", NULL, "%s", HU_FLAG_SEMI_STATIC, pegasus_yes_no_info }, /* Generic version (RO) for other models */ { "outlet.2.switchable", 0, 0, "UPS.OutletSystem.Outlet.[3].PresentStatus.Switchable", NULL, "%s", 0, yes_no_info }, { "outlet.2.status", 0, 0, "UPS.OutletSystem.Outlet.[3].PresentStatus.SwitchOn/Off", NULL, "%s", 0, on_off_info }, { "outlet.2.protect.status", 0, 0, "UPS.OutletSystem.Outlet.[3].Status", NULL, "%s", 0, eaton_outlet_protection_status_info }, /* FIXME: should better use UPS.OutletSystem.Outlet.[1].Status? */ { "outlet.2.autoswitch.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.OutletSystem.Outlet.[3].RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "outlet.2.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.OutletSystem.Outlet.[3].ShutdownTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "outlet.2.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.OutletSystem.Outlet.[3].StartupTimer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "outlet.2.power", 0, 0, "UPS.OutletSystem.Outlet.[3].ApparentPower", NULL, "%.0f", 0, NULL }, { "outlet.2.realpower", 0, 0, "UPS.OutletSystem.Outlet.[3].ActivePower", NULL, "%.0f", 0, NULL }, { "outlet.2.current", 0, 0, "UPS.OutletSystem.Outlet.[3].Current", NULL, "%.2f", 0, NULL }, { "outlet.2.powerfactor", 0, 0, "UPS.OutletSystem.Outlet.[3].PowerFactor", NULL, "%.2f", 0, NULL }, /* "%s", 0, mge_powerfactor_conversion }, */ /* 0: The outlet is not ECO controlled. / 1 : The outlet is ECO controlled. => Readonly! use some yes_no_info */ { "outlet.2.ecocontrol", 0, 0, "UPS.OutletSystem.Outlet.[3].ECOControl", NULL, "%s", HU_FLAG_SEMI_STATIC, outlet_eco_yes_no_info}, /* instant commands. */ /* splited into subset while waiting for extradata support * ie: test.battery.start quick */ { "test.battery.start.quick", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "test.battery.start.deep", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "2", HU_TYPE_CMD, NULL }, { "test.battery.stop", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "3", HU_TYPE_CMD, NULL }, { "load.off.delay", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.PowerSummary.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "shutdown.stop", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, { "shutdown.reboot", 0, 0, "UPS.PowerSummary.DelayBeforeReboot", NULL, "10", HU_TYPE_CMD, NULL}, { "beeper.off", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.on", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, /* Duplicate commands for some units (such as 3S) that use a different path * Only the first valid one will be used */ { "beeper.mute", 0, 0, "UPS.BatterySystem.Battery.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, { "beeper.mute", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.BatterySystem.Battery.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.enable", 0, 0, "UPS.BatterySystem.Battery.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.enable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, /* yonesmit - support for Masterpower MF-UPS650VA */ { "beeper.enable", 0, 0, "UPS.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, /* yonesmit - support for Masterpower MF-UPS650VA */ /* Command for the outlet collection */ { "outlet.1.load.off", 0, 0, "UPS.OutletSystem.Outlet.[2].DelayBeforeShutdown", NULL, "0", HU_TYPE_CMD, NULL }, { "outlet.1.load.on", 0, 0, "UPS.OutletSystem.Outlet.[2].DelayBeforeStartup", NULL, "0", HU_TYPE_CMD, NULL }, { "outlet.2.load.off", 0, 0, "UPS.OutletSystem.Outlet.[3].DelayBeforeShutdown", NULL, "0", HU_TYPE_CMD, NULL }, { "outlet.2.load.on", 0, 0, "UPS.OutletSystem.Outlet.[3].DelayBeforeStartup", NULL, "0", HU_TYPE_CMD, NULL }, /* Command to switch ECO(HE), ESS Mode */ { "experimental.ecomode.stop", 0, 0, "UPS.PowerConverter.Input.[5].Switchable", NULL, "0", HU_TYPE_CMD, NULL }, { "experimental.ecomode.start", 0, 0, "UPS.PowerConverter.Input.[5].Switchable", NULL, "1", HU_TYPE_CMD, NULL }, { "experimental.essmode.start", 0, 0, "UPS.PowerConverter.Input.[5].Switchable", NULL, "2", HU_TYPE_CMD, NULL }, { "experimental.essmode.stop", 0, 0, "UPS.PowerConverter.Input.[5].Switchable", NULL, "0", HU_TYPE_CMD, NULL }, /* Command to switch ECO(HE) Mode with switch to Automatic Bypass Mode on before */ { "experimental.bypass.ecomode.start", 0, 0, "UPS.PowerConverter.Input.[5].Switchable", NULL, "1", HU_TYPE_CMD, eaton_input_eco_mode_auto_on_off_info }, /* Command to switch from ECO(HE) Mode with switch from Automatic Bypass Mode on before */ { "experimental.bypass.ecomode.stop", 0, 0, "UPS.PowerConverter.Input.[5].Switchable", NULL, "0", HU_TYPE_CMD, eaton_input_eco_mode_auto_on_off_info }, /* Command to switch Automatic Bypass Mode on/off */ { "bypass.start", 0, 0, "UPS.PowerConverter.Input.[2].SwitchOnControl", NULL, "1", HU_TYPE_CMD, NULL }, { "bypass.stop", 0, 0, "UPS.PowerConverter.Input.[2].SwitchOffControl", NULL, "1", HU_TYPE_CMD, NULL }, /* ECO(HE), ESS Mode switch, to use when 'input.bypass.switch.on' is on. * Note that this calls complex logic based on a number of other values * determined in the table above, so this mapping is defined much later. */ { "input.eco.switchable", ST_FLAG_RW | ST_FLAG_STRING, 8, "UPS.PowerConverter.Input.[5].Switchable", NULL, "%.0f", HU_FLAG_QUICK_POLL, eaton_input_eco_mode_on_off_info }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; /* * All the logic for finely formatting the MGE model name and device * type matching (used for device specific values or corrections). * Returns pointer to (dynamically allocated) model name. */ static char *get_model_name(const char *iProduct, const char *iModel) { models_name_t *model = NULL; upsdebugx(2, "get_model_name(%s, %s)\n", iProduct, iModel); /* Search for device type and formatting rules */ for (model = mge_model_names; model->iProduct; model++) { if (model->name) { upsdebugx(2, "comparing with: %s", model->name); } else { upsdebugx(2, "comparing with: %s %s", model->iProduct, model->iModel); } if (strcmp(iProduct, model->iProduct)) { continue; } if (strcmp(iModel, model->iModel)) { continue; } mge_type = model->type; break; } if (!model->name) { /* * Model not found or NULL (use default) so construct * model name by concatenation of iProduct and iModel */ char buf[SMALLBUF]; #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic ignored "-Wformat-truncation" #endif /* NOTE: We intentionally limit the amount of bytes reported */ int len = snprintf(buf, sizeof(buf), "%s %s", iProduct, iModel); if (len < 0) { upsdebugx(1, "%s: got an error while extracting iProduct+iModel value", __func__); } /* NOTE: SMALLBUF here comes from mge_format_model() * buffer definitions below */ if ((intmax_t)len > (intmax_t)sizeof(buf) || ((intmax_t)(strnlen(iProduct, SMALLBUF) + strnlen(iModel, SMALLBUF) + 1 + 1)) > (intmax_t)sizeof(buf) ) { upsdebugx(1, "%s: extracted iProduct+iModel value was truncated", __func__); } #ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_FORMAT_TRUNCATION #pragma GCC diagnostic pop #endif return strdup(buf); } return strdup(model->name); } static const char *mge_format_model(HIDDevice_t *hd) { char product[SMALLBUF]; char model[SMALLBUF]; double value; /* Dell has already a fully formatted name in iProduct */ if (hd->VendorID == DELL_VENDORID) { return hd->Product; } /* Get iProduct and iModel strings */ snprintf(product, sizeof(product), "%s", hd->Product ? hd->Product : "unknown"); HIDGetItemString(udev, "UPS.PowerSummary.iModel", model, sizeof(model), mge_utab); /* Fallback to ConfigApparentPower */ if ((strlen(model) < 1) && (HIDGetItemValue(udev, "UPS.Flow.[4].ConfigApparentPower", &value, mge_utab) == 1 )) { snprintf(model, sizeof(model), "%i", (int)value); } if (strlen(model) > 0) { free(hd->Product); hd->Product = get_model_name(product, model); } return hd->Product; } static const char *mge_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "Eaton"; } static const char *mge_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int mge_claim(HIDDevice_t *hd) { #if (defined SHUT_MODE) && SHUT_MODE NUT_UNUSED_VARIABLE(hd); return 1; #else /* !SHUT_MODE => USB */ int status = is_usb_device_supported(mge_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: switch (hd->VendorID) { case HP_VENDORID: case DELL_VENDORID: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } /* * this vendor makes lots of USB devices that are * not a UPS, so don't use possibly_supported here */ return 0; case PHOENIXTEC: /* The vendorid 0x06da is primarily handled by * liebert-hid, except for (maybe) AEG PROTECT NAS * branded devices */ if (hd->Vendor && strstr(hd->Vendor, "AEG")) { return 1; } if (hd->Product && strstr(hd->Product, "AEG")) { return 1; } /* Let liebert-hid grab this */ return 0; case KSTAR_VENDORID: if (hd->Vendor && strstr(hd->Vendor, "KSTAR")) { return 1; } /* So far we only heard of KSTAR using this ID * in some models (or MGE 0x0463 originally) */ return 0; default: /* Valid for Eaton */ /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("Eaton / MGE", hd); return 0; } case SUPPORTED: switch (hd->VendorID) { case PHOENIXTEC: /* see comments above */ if (hd->Vendor && strstr(hd->Vendor, "AEG")) { return 1; } if (hd->Product && strstr(hd->Product, "AEG")) { return 1; } /* Let liebert-hid grab this */ return 0; case KSTAR_VENDORID: if (hd->Vendor && strstr(hd->Vendor, "KSTAR")) { return 1; } /* So far we only heard of KSTAR using this ID * in some models (or MGE 0x0463 originally) */ return 0; default: break; } return 1; case NOT_SUPPORTED: default: return 0; } #endif /* SHUT_MODE / USB */ } subdriver_t mge_subdriver = { MGE_HID_VERSION, mge_claim, mge_utab, mge_hid2nut, mge_format_model, mge_format_mfr, mge_format_serial, fix_report_desc, }; nut-2.8.4/drivers/baytech-mib.h0000644000175000017500000000022114745410772013275 00000000000000#ifndef BAYTECH_MIB_H #define BAYTECH_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t baytech; #endif /* BAYTECH_MIB_H */ nut-2.8.4/drivers/oneac.h0000644000175000017500000001503014670526611012177 00000000000000/* oneac.h - Driver for Oneac UPS using the Advanced Interface. * * Copyright (C) * 2003 by Eric Lawson * 2012 by Bill Elliot * * This program was sponsored by MGE UPS SYSTEMS, and now Eaton * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUT_ONEAC_H_SEEN #define NUT_ONEAC_H_SEEN 1 /*misc stuff*/ #define ENDCHAR '\r' #define IGNCHARS "\n" #define COMMAND_END "\r\n" #define DEFAULT_BAT_TEST_TIME "02" /*Information requests -- EG level */ #define GET_ALL '%' #define GETALL_EG_RESP_SIZE 22 #define GETALL_RESP_SIZE 48 #define GET_MFR 'M' #define GET_FAMILY 'F' #define GET_VERSION 'N' #define GET_ON_INVERTER 'G' #define GET_BATLOW 'K' #define GET_STATUS 'X' #define GET_LAST_XFER 'W' #define GET_INVERTER_RDY 'I' #define GET_SHUTDOWN 'O' #define GET_TEST_TIME 'Q' #define GET_NOM_FREQ 'H' /*Information requests -- ON level (EG plus these) */ #define GET_NOM_VOLTAGE 'V' #define GET_DISPLAY_CODE 'D' #define GET_CONDITION_CODE 'C' #define GET_PERCENT_LOAD 'P' #define GET_PERCENT_BAT_REM 'T' #define GET_INPUT_LINE_VOLT 'L' #define GET_MIN_INPUT_VOLT 'A' #define GET_MAX_INPUT_VOLT 'E' #define GET_OUTPUT_VOLT 'S' #define GET_BOOSTING 'B' #define GET_SHUTDOWN_RESP_SIZE 3 /*Information requests -- OZ/OB level (ON plus these) */ #define GETX_ALL_1 '&' #define GETX_ALL1_RESP_SIZE 79 #define GETX_OUTSOURCE 'a' #define GETX_FRONTDISP 'b' #define GETX_INT_TEMP 'g' /* Degrees C */ #define GETX_BATT_STAT 'h' /* Unknown(1), Normal, Low, Depleted */ #define GETX_BATT_CHG_PERC 'i' /* 0 - 100 */ #define GETX_EST_MIN_REM 'j' #define GETX_ONBATT_TIME 'k' /* In seconds */ #define GETX_BATT_VOLTS 'l' /* Read as xxx.x */ #define GETX_INP_FREQ 'p' #define GETX_MIN_IN_VOLTS 'q' #define GETX_MAX_IN_VOLTS 'r' #define GETX_IN_VOLTS 's' #define GETX_IN_WATTS 'u' #define GETX_OUT_VOLTS 'v' #define GETX_OUT_WATTS 'x' #define GETX_OUT_LOAD_PERC 'y' #define GETX_OUT_FREQ 'z' #define GETX_ALL_2 '^' #define GETX_ALL2_RESP_SIZE 92 #define GETX_MODEL 'J' #define GETX_FW_REV 'U' /* Read as xx.x */ #define GETX_SERIAL_NUM 'Y' #define GETX_MAN_DATE '$' /* yymmdd */ #define GETX_BATT_REPLACED '+' /* yymmdd */ #define GETX_DATE_RESP_SIZE 6 /* FIXME: Both of the following constants are unused, and the first is not * valid C syntax (breaks LLVM). */ #if 0 #define GETX_UNIT_KVA '''' /* Read as xxx.xx */ #define GETX_UNIT_WATTS "''" /* 2-character string request */ #endif #define GETX_LOW_OUT_ALLOW '[' /* Tap up or inverter at this point */ #define GETX_HI_OUT_ALLOW ']' /* Tap down or inverter at this point */ #define GETX_NOTIFY_DELAY ',' /* Secs of delay for power fail alert */ #define GETX_ALLOW_RESP_SIZE 3 #define GETX_LOW_BATT_TIME '"' /* Low batt alarm at xx minutes */ #define GETX_RESTART_DLY '_' /* Restart delay */ #define GETX_RESTART_COUNT "_?" /* Returns actual counter value */ #define GETX_RSTRT_RESP_SIZE 4 /*Other requests */ #define GETX_SHUTDOWN '}' /* Shutdown counter (..... for none) */ #define GETX_SHUTDOWN_RESP_SIZE 5 #define GETX_BATT_TEST_DAYS "\x02\x1A" /* Days between battery tests */ #define GETX_BUZZER_WHAT "\x07?" /* What is buzzer state */ #define GETX_AUTO_START " 999 on OZ */ #define MIN_ALLOW_FW "1.9" /* At or above provides output allow range */ /*responses*/ #define FAMILY_EG "EG" /* 3 tri-color LEDs and big ON/OFF on front */ #define FAMILY_ON "ON" /* Serial port avail only on interface card */ #define FAMILY_OZ "OZ" /* DB-25 std., plus interface slot */ #define FAMILY_OB "OB" /* Lg. cab with removable modules */ #define FAMILY_SIZE 2 #define YES 'Y' #define NO 'N' #define V230AC '2' #define V120AC '1' #define XFER_BLACKOUT 'B' #define XFER_LOW_VOLT 'L' #define XFER_HI_VOLT 'H' #define BUZZER_ENABLED '1' #define BUZZER_DISABLED '0' #define BUZZER_MUTED '2' /*front panel alarm codes*/ #define CODE_BREAKER_OPEN "c1" /*input circuit breaker open*/ #define CODE_BAT_FUSE_OPEN "c2" /*battery not connected. Open fuse?*/ #define CODE_TOO_HOT "c3" /*UPS too hot*/ #define CODE_CHARGING "c4" /*recharging battery pack*/ #define CODE_LOW_BAT_CAP "c5" /*batteries getting too old*/ #define CODE_OVERLOAD "c8" /*"slight" overload*/ #define CODE_GROSS_OVLE "c9" /*gross overload 1 minute to power off*/ #define CODE_CHRGR_FUSE_OPEN "u1" /*battery charger fuse probably open*/ #endif /* NUT_ONEAC_H_SEEN */ nut-2.8.4/drivers/apcsmart_tabs.h0000644000175000017500000000702014670526611013735 00000000000000/* * apcsmart_tabs.h - tables for apcsmart driver * * Copyright (C) 1999 Russell Kroll * (C) 2000 Nigel Metheringham * (C) 2011+ Michal Soltys * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_APCSMART_TABS_H_SEEN #define NUT_APCSMART_TABS_H_SEEN 1 #include "main.h" #define APC_TABLE_VERSION "version 3.1" /* common flags */ #define APC_PRESENT 0x00000001 /* capability seen on this UPS */ /* instant commands' flags */ #define APC_NASTY 0x00000002 /* Nasty command - must be reconfirmed */ #define APC_REPEAT 0x00000004 /* Command needs sending twice */ /* variables' flags */ #define APC_POLL 0x00000100 /* poll this variable regularly */ #define APC_RW 0x00000200 /* read-write variable */ #define APC_ENUM 0x00000400 /* enumerated type variable */ #define APC_STRING 0x00000800 /* string variable */ #define APC_MULTI 0x00001000 /* there're other vars like that */ #define APC_PACK 0x00002000 /* packed variable */ #define APC_PACK_MAX 4 /* max count of subfields in packed var */ /* variables' format */ #define APC_F_MASK 0xFF000000 /* Mask for apc data formats */ #define APC_F_LEAVE 0x00000000 /* Just pass this through */ #define APC_F_PERCENT 0x01000000 /* Data in a percent format */ #define APC_F_VOLT 0x02000000 /* Data in a voltage format */ #define APC_F_AMP 0x03000000 /* Data in a current/amp format */ #define APC_F_CELSIUS 0x04000000 /* Data in a temp/C format */ #define APC_F_HEX 0x05000000 /* Data in a hex number format */ #define APC_F_DEC 0x06000000 /* Data in a decimal format */ #define APC_F_SECONDS 0x07000000 /* Time in seconds */ #define APC_F_MINUTES 0x08000000 /* Time in minutes */ #define APC_F_HOURS 0x09000000 /* Time in hours */ #define APC_F_REASON 0x0A000000 /* Reason of transfer */ /* instant commands */ #define APC_CMD_CUSTOM 0 /* command uses separate function */ #define APC_CMD_OFF 'Z' #define APC_CMD_ON '\016' /* ^N */ #define APC_CMD_FPTEST 'A' #define APC_CMD_SIMPWF 'U' #define APC_CMD_BTESTTOGGLE 'W' #define APC_CMD_GRACEDOWN '@' #define APC_CMD_SOFTDOWN 'S' #define APC_CMD_SHUTDOWN 'K' #define APC_CMD_CALTOGGLE 'D' #define APC_CMD_BYPTOGGLE '^' typedef struct { const char *name; /* the variable name */ char cmd; /* variable character */ unsigned int flags; /* various flags */ const char *regex; /* variable must match this regex */ size_t nlen0; /* var name + null len */ int cnt; /* curr. count of subs */ } apc_vartab_t; typedef struct { const char *name, *ext; char cmd; int flags; } apc_cmdtab_t; typedef struct { const char *firmware; const char *cmdchars; int flags; } apc_compattab_t; extern apc_vartab_t apc_vartab[]; extern apc_cmdtab_t apc_cmdtab[]; extern apc_compattab_t apc_compattab[]; extern upsdrv_info_t apc_tab_info; #endif /* NUT_APCSMART_TABS_H_SEEN */ nut-2.8.4/drivers/upshandler.h0000644000175000017500000002247415044656702013272 00000000000000/* upshandler.h - function callbacks used by the drivers Copyright (C) 2003 Russell Kroll Copyright (C) 2025 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NUT_UPSHANDLER_H #define NUT_UPSHANDLER_H /* return values for instcmd */ enum { STAT_INSTCMD_HANDLED = 0, /* completed successfully */ STAT_INSTCMD_UNKNOWN, /* unspecified error */ STAT_INSTCMD_INVALID, /* invalid command */ STAT_INSTCMD_FAILED, /* command failed */ STAT_INSTCMD_CONVERSION_FAILED /* could not convert value */ }; /* return values for setvar */ enum { STAT_SET_HANDLED = 0, /* completed successfully */ STAT_SET_UNKNOWN, /* unspecified error */ STAT_SET_INVALID, /* not writeable */ STAT_SET_FAILED, /* writing failed */ STAT_SET_CONVERSION_FAILED /* could not convert value from string */ }; /* structure for funcs that get called by msg parse routine */ struct ups_handler { int (*setvar)(const char *, const char *); int (*instcmd)(const char *, const char *); }; /* Log levels; packagers might want to fiddle with NOTICE vs. WARN or ERR, * maybe even CRIT for shutdown commands?.. or we might eventually tie this * into nut_debug_level run-time verbosity. * Up to NUT v2.8.3 everything was LOG_NOTICE except in a few drivers. * Conversion to these macros allows all drivers to behave consistently. */ #ifndef UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define UPSHANDLER_LOGLEVEL_DIFFERENTIATE 1 /* 0 to LOG_NOTICE everything by default */ #endif #ifndef LOG_INSTCMD_POWERSTATE # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_INSTCMD_POWERSTATE LOG_CRIT # else # define LOG_INSTCMD_POWERSTATE LOG_NOTICE # endif #endif #ifndef LOG_INSTCMD_UNKNOWN # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_INSTCMD_UNKNOWN LOG_WARNING # else # define LOG_INSTCMD_UNKNOWN LOG_NOTICE # endif #endif #ifndef LOG_INSTCMD_INVALID # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_INSTCMD_INVALID LOG_WARNING # else # define LOG_INSTCMD_INVALID LOG_NOTICE # endif #endif #ifndef LOG_INSTCMD_FAILED # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_INSTCMD_FAILED LOG_ERR # else # define LOG_INSTCMD_FAILED LOG_NOTICE # endif #endif #ifndef LOG_INSTCMD_CONVERSION_FAILED # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_INSTCMD_CONVERSION_FAILED LOG_ERR # else # define LOG_INSTCMD_CONVERSION_FAILED LOG_WARNING # endif #endif /* FIXME: Define here and apply in drivers log levels for * mere HANDLED states (INFO?), * like for instcmd about shutdowns (CRIT) in particular; * see bestfortress.c for some practical inspiration. */ #ifndef LOG_SET_UNKNOWN # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_SET_UNKNOWN LOG_WARNING # else # define LOG_SET_UNKNOWN LOG_NOTICE # endif #endif #ifndef LOG_SET_INVALID # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_SET_INVALID LOG_WARNING # else # define LOG_SET_INVALID LOG_NOTICE # endif #endif #ifndef LOG_SET_FAILED # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_SET_FAILED LOG_ERR # else # define LOG_SET_FAILED LOG_NOTICE # endif #endif #ifndef LOG_SET_CONVERSION_FAILED # if UPSHANDLER_LOGLEVEL_DIFFERENTIATE # define LOG_SET_CONVERSION_FAILED LOG_ERR # else # define LOG_SET_CONVERSION_FAILED LOG_WARNING # endif #endif /* Call upslogx() with certain log level and wording/markup, so different * driver programs present a consistent picture to their end-users. */ /* Block of loggers instcmd(), upscmd() et al -- note an argument is optional. * Many drivers have their own detailed messages, but are encouraged to follow * the markup precedent here (NUT_STRARG and all). * If they have non-standard commands (e.g. "experimental.eco*") they can use * the upslog_INSTCMD_POWERSTATE*() macros directly in those clauses. */ #define upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra) do { \ upslogx(LOG_INSTCMD_POWERSTATE, "%s: attempting a power state change operation [%s] [%s] on [%s]", \ __func__, NUT_STRARG(cmdname), NUT_STRARG(extra), NUT_STRARG(upsname)); \ } while(0) /* When calibration goes wrong on an UPS that overestimated itself, * it may suddenly turn off (e.g. old battery never tested before) * DUE TO running the test. */ #define upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra) do { \ upslogx(LOG_INSTCMD_POWERSTATE, "%s: attempting an operation [%s] [%s] which may impact power state on [%s]", \ __func__, NUT_STRARG(cmdname), NUT_STRARG(extra), NUT_STRARG(upsname)); \ } while(0) /* This macro should simplify the call especially for drivers with mapping * tables, where we do not have a preceding "if strcmp" to certainly know * which command string we are acting on (at a cost of checking for several * string matches, so direct-action macros above are preferable where we * know the command for sure). * Patterns matched below follow docs/nut-names.txt (INSTCMD section). */ #define upslog_INSTCMD_POWERSTATE_CHECKED(cmdname, extra) do { \ if (cmdname) { \ if ( \ strstr(cmdname, "shutdown.stop") == cmdname || \ strstr(cmdname, "load.on") == cmdname || \ strstr(cmdname, "test.battery.st") == cmdname || \ strstr(cmdname, "test.failure.st") == cmdname || \ strstr(cmdname, "test.system.st") == cmdname || \ strstr(cmdname, "calibrate.st") == cmdname || \ strstr(cmdname, "bypass.st") == cmdname \ ) { \ upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra) ; \ } else if ( \ strstr(cmdname, "shutdown.") == cmdname || \ strstr(cmdname, "load.off") == cmdname || \ strstr(cmdname, "load.cycle") == cmdname || \ ( strstr(cmdname, "outlet.") == cmdname && ( \ strstr(cmdname, "shutdown.") || \ strstr(cmdname, "load") \ ) ) \ ) { \ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra) ; \ } \ } } while(0) #define upsdebug_INSTCMD_STARTING(cmdname, extra) do { \ upsdebugx(1, "Starting %s::%s('%s', '%s')", \ __FILE__, __func__, NUT_STRARG(cmdname), NUT_STRARG(extra)); \ } while(0) #define upslog_INSTCMD_UNKNOWN(cmdname, extra) do { \ upslogx(LOG_INSTCMD_UNKNOWN, "%s: unknown command [%s] [%s]", \ __func__, NUT_STRARG(cmdname), NUT_STRARG(extra)); \ } while(0) #define upslog_INSTCMD_INVALID(cmdname, extra) do { \ upslogx(LOG_INSTCMD_INVALID, "%s: parameter [%s] is invalid for command [%s]", \ __func__, NUT_STRARG(extra), NUT_STRARG(cmdname)); \ } while(0) #define upslog_INSTCMD_FAILED(cmdname, extra) do { \ upslogx(LOG_INSTCMD_FAILED, "%s: FAILED command [%s] [%s]", \ __func__, NUT_STRARG(cmdname), NUT_STRARG(extra)); \ } while(0) #define upslog_INSTCMD_CONVERSION_FAILED(cmdname, extra) do { \ upslogx(LOG_INSTCMD_CONVERSION_FAILED, "%s: parameter value [%s] is invalid for command [%s]", \ __func__, NUT_STRARG(extra), NUT_STRARG(cmdname)); \ } while(0) /* Note: log only faults; nothing for successful handling */ #define upslog_INSTCMD_RESULT(ret, cmdname, extra) do { \ if (ret == STAT_INSTCMD_FAILED) \ upslog_INSTCMD_FAILED(cmdname, extra); \ else if (ret == STAT_INSTCMD_UNKNOWN) \ upslog_INSTCMD_UNKNOWN(cmdname, extra); \ else if (ret == STAT_INSTCMD_INVALID) \ upslog_INSTCMD_INVALID(cmdname, extra); \ else if (ret == STAT_INSTCMD_CONVERSION_FAILED) \ upslog_INSTCMD_CONVERSION_FAILED(cmdname, extra); \ } while(0) /* setvar(), setcmd() et al -- note they MUST have an argument: */ #define upsdebug_SET_STARTING(varname, value) do { \ upsdebugx(1, "Starting %s::%s('%s', '%s')", \ __FILE__, __func__, NUT_STRARG(varname), NUT_STRARG(value)); \ } while(0) #define upslog_SET_UNKNOWN(varname, value) do { \ upslogx(LOG_SET_UNKNOWN, "%s: unknown variable [%s] [%s]", \ __func__, NUT_STRARG(varname), NUT_STRARG(value)); \ } while(0) #define upslog_SET_INVALID(varname, value) do { \ upslogx(LOG_SET_INVALID, "%s: value [%s] is invalid for variable [%s]", \ __func__, NUT_STRARG(value), NUT_STRARG(varname)); \ } while(0) #define upslog_SET_FAILED(varname, value) do { \ upslogx(LOG_SET_FAILED, "%s: FAILED to set variable [%s] to value [%s]", \ __func__, NUT_STRARG(varname), NUT_STRARG(value)); \ } while(0) #define upslog_SET_CONVERSION_FAILED(cmdname, extra) do { \ upslogx(LOG_SET_CONVERSION_FAILED, "%s: value [%s] is invalid for variable [%s]", \ __func__, NUT_STRARG(extra), NUT_STRARG(cmdname)); \ } while(0) /* Note: log only faults; nothing for successful handling */ #define upslog_SET_RESULT(ret, cmdname, extra) do { \ if (ret == STAT_SET_FAILED) \ upslog_SET_FAILED(cmdname, extra); \ else if (ret == STAT_SET_UNKNOWN) \ upslog_SET_UNKNOWN(cmdname, extra); \ else if (ret == STAT_SET_INVALID) \ upslog_SET_INVALID(cmdname, extra); \ else if (ret == STAT_SET_CONVERSION_FAILED) \ upslog_SET_CONVERSION_FAILED(cmdname, extra); \ } while(0) #endif /* NUT_UPSHANDLER_H */ nut-2.8.4/drivers/delta_ups-mib.h0000644000175000017500000000201014670526611013631 00000000000000/* delta_ups-mib.h - subdriver to monitor delta_ups SNMP devices with NUT * * Copyright (C) * 2011 - 2012 Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DELTA_UPS_MIB_H #define DELTA_UPS_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t delta_ups; #endif /* DELTA_UPS_MIB_H */ nut-2.8.4/drivers/eaton-pdu-marlin-helpers.c0000644000175000017500000000546115044656702015731 00000000000000/* eaton-pdu-marlin-helpers.c - helper routines for eaton-pdu-marlin-mib.c * to monitor Eaton ePDUs branded as: * G2 Marlin SW / MI / MO / MA * G3 Shark SW / MI / MO / MA * * Copyright (C) 2017-2019 * Arnaud Quette * Copyright (C) 2017 * Jim Klimov * * Supported by Eaton * and previously MGE Office Protection Systems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "config.h" /* must be the first header */ #include #include #include "nut_stdint.h" #include "eaton-pdu-marlin-helpers.h" #include "dstate.h" #include "common.h" /* Allow access to temperature_unit */ #include "snmp-ups.h" /* Take string "unitsPresent" (ex: "0,3,4,5"), and count the amount * of "," separators+1 using an inline function */ long marlin_device_count_fun(const char *daisy_dev_list) { long count = 0, i; for (i = 0; daisy_dev_list[i] != '\0'; i++) { if (daisy_dev_list[i] == ',') { /* Each comma means a new device in the list */ count ++; } } if (i > 0 && (daisy_dev_list[i - 1] != ',') ) { /* Non-empty string => at least one device, and no trailing commas */ count ++; } upsdebugx(3, "%s: counted devices in '%s', got %ld", __func__, daisy_dev_list, count); return count; } /* Temperature unit consideration: * only store the device unit, for converting to Celsius. * Don't publish the device unit, since NUT will publish * as Celsius in all cases */ const char *eaton_sensor_temperature_unit_fun(void *raw_snmp_value) { long snmp_value = *((long*)raw_snmp_value); switch (snmp_value) { case 0: /* store the value, for temperature processing */ temperature_unit = TEMPERATURE_KELVIN; break; case 1: /* store the value, for temperature processing */ temperature_unit = TEMPERATURE_CELSIUS; break; case 2: /* store the value, for temperature processing */ temperature_unit = TEMPERATURE_FAHRENHEIT; break; default: /* store the value, for temperature processing */ temperature_unit = TEMPERATURE_UNKNOWN; break; } return "celsius"; } nut-2.8.4/drivers/arduino-hid.h0000644000175000017500000000225114777753336013334 00000000000000/* arduino-hid.h - subdriver to monitor Arduino USB/HID devices with NUT * * Copyright (C) * 2003 - 2009 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * 2021 Alex Bratchik * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef ARDUINO_HID_H #define ARDUINO_HID_H #include "usbhid-ups.h" extern subdriver_t arduino_subdriver; #endif /* ARDUINO_HID_H */ nut-2.8.4/drivers/powervar-hid.c0000664000175000017500000001250515000733176013514 00000000000000/* powervar-hid.c - subdriver to monitor Powervar USB/HID devices with NUT * * Copyright (C) * 2003 - 2012 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * 2013 Charles Lepple * 2019 AMETEK Powervar - Andrew McCartney * * Note: this subdriver was initially generated as a "stub" by the * gen-usbhid-subdriver script. It must be customized. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be first */ #include "usbhid-ups.h" #include "powervar-hid.h" #include "main.h" /* for getval() */ #include "usb-common.h" #define POWERVAR_HID_VERSION "Powervar HID 0.20" /* FIXME: experimental flag to be put in upsdrv_info */ /* Powervar */ #define POWERVAR_VENDORID 0x4234 /* USB IDs device table */ static usb_device_id_t powervar_usb_device_table[] = { /* Powervar */ { USB_DEVICE(POWERVAR_VENDORID, 0x0002), NULL }, /* Terminating entry */ { 0, 0, NULL } }; static usb_communication_subdriver_t *usb = &usb_subdriver; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* POWERVAR usage table */ static usage_lkp_t powervar_usage_lkp[] = { { "POWERVAR1", 0xff000001 }, { NULL, 0 } }; static usage_tables_t powervar_utab[] = { powervar_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t powervar_hid2nut[] = { /* Battery page */ { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", 0, stringid_conversion }, { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.capacity", 0, 0, "UPS.PowerSummary.FullChargeCapacity", NULL, "%.0f", 0, NULL }, { "battery.runtime", 0, 0, "UPS.PowerSummary.RuntimeToEmpty", NULL, "%.0f", 0, NULL }, /* Special case: ups.status & ups.alarm */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, 0, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.RemainingTimeLimitExpired", NULL, NULL, 0, timelimitexpired_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.InternalFailure", NULL, NULL, 0, yes_no_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Good", NULL, NULL, 0, yes_no_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.OverTemperature", NULL, NULL, 0, overheat_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyCharged", NULL, NULL, 0, fullycharged_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyDischarged", NULL, NULL, 0, depleted_info }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *powervar_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *powervar_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "Powervar"; } static const char *powervar_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int powervar_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(powervar_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { if (!getval("usb_hid_rep_index")) usb->hid_rep_index = 1; return 1; } possibly_supported("Powervar", hd); return 0; case SUPPORTED: if (!getval("usb_hid_rep_index")) usb->hid_rep_index = 1; return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t powervar_subdriver = { POWERVAR_HID_VERSION, powervar_claim, powervar_utab, powervar_hid2nut, powervar_format_model, powervar_format_mfr, powervar_format_serial, fix_report_desc, }; nut-2.8.4/drivers/tripplitesu.c0000644000175000017500000006050315044656702013477 00000000000000/* tripplitesu.c - model specific routines for Tripp Lite SmartOnline (SU*) models Copyright (C) 2003 Allan N. Hessenflow This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Notes: The map for commands_available isn't clear. All of the information I have on the Tripp Lite SmartOnline protocol comes from the files TUN.tlp and TUNRT.tlp from their drivers, and some experimentation. One of those files told me what one bit was for in the AVL response, out of 18 that the SU1000RT2U sends or 21 that some other model sends. Later I found a description of the Belkin protocol, which is the same. Unfortunately it gives a definition of the AVL response that conflicts with the one bit I found from TUNRT.tlp, and in fact the response my SU1000RT2U gives, compared to the commands I have found it supports, does not match the Belkin description. So I'm treating the whole field as unknown. It would be nice to be able to use it to determine what variables to make RW. As a workaround, I'm assuming any value I query successfully which also can be set on at least one model, can in fact be set on the one I'm talking to. I didn't just add Tripp Lite support to the existing Belkin driver because I didn't discover that they were the same protocol until after I had put more features in this driver than the Belkin driver has. I'm not calling this a unified Belkin/Tripp Lite driver for a couple of reasons. One is that I don't have a Belkin to test with (and so I explicitly check for Tripp Lite in this drivers initialization - it *may* work fine with a Belkin by simply removing that test). The other reason is that I'd have to come up with a name - I don't know a name for the protocol, and I don't know which company (if either) originated the protocol. Picking one of the companies arbitrarily to name it after just seems wrong. There are a few things still to add. Primarily there's control of individual outlet banks, using (I presume) outlet.n.x variables. I'll probably wait for an example of that to show up in some other driver before adding that, to try to make sure I do it in the way that Russell Kroll envisioned. It also might be nice to give the user control over the delays before shutdown and restart, probably with additional driver parameters. Letting the user turn the buzzer off might be nice too; for that I'd have to investigate whether the command to do that disables it entirely, or just turns it off during the existing alarm condition, to determine whether it would be better implemented through variables or instant commands, and then of course request that those get added to the list of known names. Finally, there are a number of other alarm conditions that can be reported that would be nice to pass on to the user; these would require new variables or new status values. The following parameters (ups.conf) are supported: lowbatt The following variables are supported (RW = read/write): ambient.humidity (1) ambient.temperature (1) battery.charge battery.current (1) battery.temperature battery.voltage battery.voltage.nominal input.frequency input.sensitivity (RW) (1) input.transfer.high (RW) input.transfer.low (RW) input.voltage input.voltage.nominal output.current (1) output.frequency output.voltage output.voltage.nominal ups.firmware ups.id (RW) (1) ups.load ups.mfr ups.model ups.status ups.test.result ups.contacts (1) The following instant commands are supported: load.off load.on shutdown.reboot shutdown.reboot.graceful shutdown.return shutdown.stop test.battery.start test.battery.stop The following ups.status values are supported: BOOST (1) BYPASS LB OB OFF OL OVER (2) RB (2) TRIM (1) (1) these items have not been tested because they are not supported by my SU1000RT2U. (2) these items have not been tested because I haven't tested them. */ #include "main.h" #include "serial.h" #include "nut_stdint.h" #define DRIVER_NAME "Tripp Lite SmartOnline driver" #define DRIVER_VERSION "0.10" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Allan N. Hessenflow ", DRV_EXPERIMENTAL, { NULL } }; #define MAX_RESPONSE_LENGTH 256 static const char *test_result_names[] = { "No test performed", "Passed", "In progress", "General test failed", "Battery failed", "Deep battery test failed", "Aborted" }; static struct { int code; const char *name; } sensitivity[] = { {0, "Normal"}, {1, "Reduced"}, {2, "Low"} }; static struct { int outlet_banks; unsigned long commands_available; } ups; /* bits in commands_available */ #define WDG_AVAILABLE (1UL << 1) /* message types */ #define POLL 'P' #define SET 'S' #define ACCEPT 'A' #define REJECT 'R' #define DATA 'D' /* commands */ #define AUTO_REBOOT "ARB" /* poll/set */ #define AUTO_TEST "ATT" /* poll/set */ #define ATX_REBOOT "ATX" /* poll/set */ #define AVAILABLE "AVL" /* poll */ #define BATTERY_REPLACEMENT_DATE "BRD" /* poll/set */ #define BUZZER_TEST "BTT" /* set */ #define BATTERY_TEST "BTV" /* poll/set */ #define BUZZER "BUZ" /* set */ #define ECONOMIC_MODE "ECO" /* set */ #define ENABLE_BUZZER "EDB" /* set */ #define ENVIRONMENT_INFORMATION "ENV" /* poll */ #define OUTLET_RELAYS "LET" /* poll */ #define MANUFACTURER "MNU" /* poll */ #define MODEL "MOD" /* poll */ #define RATINGS "RAT" /* poll */ #define RELAY_CYCLE "RNF" /* set */ #define RELAY_OFF "ROF" /* set */ #define RELAY_ON "RON" /* set */ #define ATX_RESUME "RSM" /* set */ #define TSU_SHUTDOWN_ACTION "SDA" /* set */ #define TSU_SHUTDOWN_RESTART "SDR" /* set */ #define TSU_SHUTDOWN_TYPE "SDT" /* poll/set */ #define RELAY_STATUS "SOL" /* poll/set */ #define SELECT_OUTPUT_VOLTAGE "SOV" /* poll/set */ #define STATUS_ALARM "STA" /* poll */ #define STATUS_BATTERY "STB" /* poll */ #define STATUS_INPUT "STI" /* poll */ #define STATUS_OUTPUT "STO" /* poll */ #define STATUS_BYPASS "STP" /* poll */ #define TELEPHONE "TEL" /* poll/set */ #define TEST_RESULT "TSR" /* poll */ #define TEST "TST" /* set */ #define TRANSFER_FREQUENCY "TXF" /* poll/set */ #define TRANSFER_VOLTAGE "TXV" /* poll/set */ #define BOOT_DELAY "UBD" /* poll/set */ #define BAUD_RATE "UBR" /* poll/set */ #define IDENTIFICATION "UID" /* poll/set */ #define VERSION_CMD "VER" /* poll */ #define VOLTAGE_SENSITIVITY "VSN" /* poll/set */ #define WATCHDOG "WDG" /* poll/set */ static ssize_t do_command(char type, const char *command, const char *parameters, char *response) { char buffer[SMALLBUF]; size_t count; ssize_t ret; ser_flush_io(upsfd); if (response) { *response = '\0'; } snprintf(buffer, sizeof(buffer), "~00%c%03d%s%s", type, (int)(strlen(command) + strlen(parameters)), command, parameters); ret = ser_send_pace(upsfd, 10000, "%s", buffer); if (ret <= 0) { upsdebug_with_errno(3, "do_command: send [%s]", buffer); return -1; } upsdebugx(3, "do_command: %" PRIiSIZE " bytes sent [%s] -> OK", ret, buffer); ret = ser_get_buf_len(upsfd, (unsigned char *)buffer, 4, 3, 0); if (ret < 0) { upsdebug_with_errno(3, "do_command: read"); return -1; } if (ret == 0) { upsdebugx(3, "do_command: read -> TIMEOUT"); return -1; } buffer[ret] = '\0'; upsdebugx(3, "do_command: %" PRIiSIZE " byted read [%s]", ret, buffer); if (!strcmp(buffer, "~00D")) { int c; ret = ser_get_buf_len(upsfd, (unsigned char *)buffer, 3, 3, 0); if (ret < 0) { upsdebug_with_errno(3, "do_command: read"); return -1; } if (ret == 0) { upsdebugx(3, "do_command: read -> TIMEOUT"); return -1; } buffer[ret] = '\0'; upsdebugx(3, "do_command: %" PRIiSIZE " bytes read [%s]", ret, buffer); c = atoi(buffer); if (c < 0) { upsdebugx(3, "do_command: response not expected to be a negative count!"); return -1; } count = (size_t)c; if (count >= MAX_RESPONSE_LENGTH) { upsdebugx(3, "do_command: response exceeds expected size!"); return -1; } if (count && !response) { upsdebugx(3, "do_command: response not expected!"); return -1; } if (count == 0) { return 0; } ret = ser_get_buf_len(upsfd, (unsigned char *)response, count, 3, 0); if (ret < 0) { upsdebug_with_errno(3, "do_command: read"); return -1; } if (ret == 0) { upsdebugx(3, "do_command: read -> TIMEOUT"); return -1; } response[ret] = '\0'; upsdebugx(3, "do_command: %" PRIiSIZE " bytes read [%s]", ret, response); /* Tripp Lite pads their string responses with spaces. I don't like that, so I remove them. This is safe to do with all responses for this protocol, so I just do that here. */ str_rtrim(response, ' '); return ret; } if (!strcmp(buffer, "~00A")) { return 0; } return -1; } static char *field(char *str, int fieldnum) { while (str && fieldnum--) { str = strchr(str, ';'); if (str) str++; } if (str && *str == ';') return NULL; return str; } static int get_identification(void) { char response[MAX_RESPONSE_LENGTH]; if (do_command(POLL, IDENTIFICATION, "", response) >= 0) { dstate_setinfo("ups.id", "%s", response); return 1; } return 0; } static void set_identification(const char *val) { char response[MAX_RESPONSE_LENGTH]; if (do_command(POLL, IDENTIFICATION, "", response) < 0) return; if (strcmp(val, response)) { strncpy(response, val, MAX_RESPONSE_LENGTH); response[MAX_RESPONSE_LENGTH - 1] = '\0'; do_command(SET, IDENTIFICATION, response, NULL); } } static int get_transfer_voltage_low(void) { char response[MAX_RESPONSE_LENGTH]; char *ptr; if (do_command(POLL, TRANSFER_VOLTAGE, "", response) > 0) { ptr = field(response, 0); if (ptr) dstate_setinfo("input.transfer.low", "%d", atoi(ptr)); return 1; } return 0; } static void set_transfer_voltage_low(int val) { char response[MAX_RESPONSE_LENGTH]; char *ptr; int high; if (do_command(POLL, TRANSFER_VOLTAGE, "", response) <= 0) return; ptr = field(response, 0); if (!ptr || val == atoi(ptr)) return; ptr = field(response, 1); if (!ptr) return; high = atoi(ptr); snprintf(response, sizeof(response), "%d;%d", val, high); do_command(SET, TRANSFER_VOLTAGE, response, NULL); } static int get_transfer_voltage_high(void) { char response[MAX_RESPONSE_LENGTH]; char *ptr; if (do_command(POLL, TRANSFER_VOLTAGE, "", response) > 0) { ptr = field(response, 1); if (ptr) dstate_setinfo("input.transfer.high", "%d", atoi(ptr)); return 1; } return 0; } static void set_transfer_voltage_high(int val) { char response[MAX_RESPONSE_LENGTH]; char *ptr; int low; if (do_command(POLL, TRANSFER_VOLTAGE, "", response) <= 0) return; ptr = field(response, 0); if (!ptr) return; low = atoi(ptr); ptr = field(response, 1); if (!ptr || val == atoi(ptr)) return; snprintf(response, sizeof(response), "%d;%d", low, val); do_command(SET, TRANSFER_VOLTAGE, response, NULL); } static int get_sensitivity(void) { char response[MAX_RESPONSE_LENGTH]; unsigned int i; if (do_command(POLL, VOLTAGE_SENSITIVITY, "", response) <= 0) return 0; for (i = 0; i < SIZEOF_ARRAY(sensitivity); i++) { if (sensitivity[i].code == atoi(response)) { dstate_setinfo("input.sensitivity", "%s", sensitivity[i].name); return 1; } } return 0; } static void set_sensitivity(const char *val) { char parm[20]; unsigned int i; for (i = 0; i < SIZEOF_ARRAY(sensitivity); i++) { if (!strcasecmp(val, sensitivity[i].name)) { snprintf(parm, sizeof(parm), "%u", i); do_command(SET, VOLTAGE_SENSITIVITY, parm, NULL); break; } } } static void auto_reboot(int enable) { char parm[20]; char response[MAX_RESPONSE_LENGTH]; char *ptr; int mode; if (enable) mode = 1; else mode = 2; if (do_command(POLL, AUTO_REBOOT, "", response) <= 0) return; ptr = field(response, 0); if (!ptr || atoi(ptr) != mode) { snprintf(parm, sizeof(parm), "%d", mode); do_command(SET, AUTO_REBOOT, parm, NULL); } } static int instcmd(const char *cmdname, const char *extra) { int i; char parm[20]; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); for (i = 0; i < ups.outlet_banks; i++) { snprintf(parm, sizeof(parm), "%d;1", i + 1); do_command(SET, RELAY_OFF, parm, NULL); } return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); for (i = 0; i < ups.outlet_banks; i++) { snprintf(parm, sizeof(parm), "%d;1", i + 1); do_command(SET, RELAY_ON, parm, NULL); } return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.reboot")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); auto_reboot(1); do_command(SET, TSU_SHUTDOWN_RESTART, "1", NULL); do_command(SET, TSU_SHUTDOWN_ACTION, "10", NULL); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.reboot.graceful")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); auto_reboot(1); do_command(SET, TSU_SHUTDOWN_RESTART, "1", NULL); do_command(SET, TSU_SHUTDOWN_ACTION, "60", NULL); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); auto_reboot(1); do_command(SET, TSU_SHUTDOWN_RESTART, "1", NULL); do_command(SET, TSU_SHUTDOWN_ACTION, "10", NULL); return STAT_INSTCMD_HANDLED; } #if 0 /* doesn't seem to work */ if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); auto_reboot(0); do_command(SET, TSU_SHUTDOWN_ACTION, "10", NULL); return STAT_INSTCMD_HANDLED; } #endif if (!strcasecmp(cmdname, "shutdown.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); do_command(SET, TSU_SHUTDOWN_ACTION, "0", NULL); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); do_command(SET, TEST, "3", NULL); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); do_command(SET, TEST, "0", NULL); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } static int setvar(const char *varname, const char *val) { upsdebug_SET_STARTING(varname, val); if (!strcasecmp(varname, "ups.id")) { set_identification(val); get_identification(); return STAT_SET_HANDLED; } if (!strcasecmp(varname, "input.transfer.low")) { set_transfer_voltage_low(atoi(val)); get_transfer_voltage_low(); return STAT_SET_HANDLED; } if (!strcasecmp(varname, "input.transfer.high")) { set_transfer_voltage_high(atoi(val)); get_transfer_voltage_high(); return STAT_SET_HANDLED; } if (!strcasecmp(varname, "input.sensitivity")) { set_sensitivity(val); get_sensitivity(); return STAT_SET_HANDLED; } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } static int init_comm(void) { size_t i, bit; char response[MAX_RESPONSE_LENGTH]; ups.commands_available = 0; /* Repeat enumerate command 2x, firmware bug on some units garbles 1st response */ if (do_command(POLL, AVAILABLE, "", response) <= 0){ upslogx(LOG_NOTICE, "init_comm: Initial response malformed, retrying in 300ms"); usleep(3E5); } if (do_command(POLL, AVAILABLE, "", response) <= 0) return 0; i = strlen(response); for (bit = 0; bit < i; bit++) if (response[i - bit - 1] == '1') ups.commands_available |= (1UL << bit); if (do_command(POLL, MANUFACTURER, "", response) <= 0) return 0; if (strcmp(response, "Tripp Lite")) return 0; return 1; } void upsdrv_initinfo(void) { char response[MAX_RESPONSE_LENGTH]; unsigned int min_low_transfer, max_low_transfer; unsigned int min_high_transfer, max_high_transfer; unsigned int i; char *ptr; if (!init_comm()) fatalx(EXIT_FAILURE, "Unable to detect Tripp Lite SmartOnline UPS on port %s\n", device_path); min_low_transfer = max_low_transfer = 0; min_high_transfer = max_high_transfer = 0; /* get all the read-only fields here */ if (do_command(POLL, MANUFACTURER, "", response) > 0) dstate_setinfo("ups.mfr", "%s", response); if (do_command(POLL, MODEL, "", response) > 0) dstate_setinfo("ups.model", "%s", response); if (do_command(POLL, VERSION_CMD, "", response) > 0) dstate_setinfo("ups.firmware", "%s", response); if (do_command(POLL, RATINGS, "", response) > 0) { ptr = field(response, 0); if (ptr) dstate_setinfo("input.voltage.nominal", "%d", atoi(ptr)); ptr = field(response, 2); if (ptr) { dstate_setinfo("output.voltage.nominal", "%d", atoi(ptr)); } ptr = field(response, 14); if (ptr) dstate_setinfo("battery.voltage.nominal", "%d", atoi(ptr)); ptr = field(response, 10); if (ptr) { int ipv = atoi(ptr); if (ipv >= 0) min_low_transfer = (unsigned int)ipv; } ptr = field(response, 9); if (ptr) { int ipv = atoi(ptr); if (ipv >= 0) max_low_transfer = (unsigned int)ipv; } ptr = field(response, 12); if (ptr) { int ipv = atoi(ptr); if (ipv >= 0) min_high_transfer = (unsigned int)ipv; } ptr = field(response, 11); if (ptr) { int ipv = atoi(ptr); if (ipv >= 0) max_high_transfer = (unsigned int)ipv; } } if (do_command(POLL, OUTLET_RELAYS, "", response) > 0) ups.outlet_banks = atoi(response); /* define things that are settable */ if (get_identification()) { dstate_setflags("ups.id", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.id", 100); } if (get_transfer_voltage_low() && max_low_transfer) { dstate_setflags("input.transfer.low", ST_FLAG_RW); for (i = min_low_transfer; i <= max_low_transfer; i++) dstate_addenum("input.transfer.low", "%u", i); } if (get_transfer_voltage_high() && max_low_transfer) { dstate_setflags("input.transfer.high", ST_FLAG_RW); for (i = min_high_transfer; i <= max_high_transfer; i++) dstate_addenum("input.transfer.high", "%u", i); } if (get_sensitivity()) { dstate_setflags("input.sensitivity", ST_FLAG_RW); for (i = 0; i < SIZEOF_ARRAY(sensitivity); i++) dstate_addenum("input.sensitivity", "%s", sensitivity[i].name); } if (ups.outlet_banks) { dstate_addcmd("load.off"); dstate_addcmd("load.on"); } dstate_addcmd("shutdown.reboot"); dstate_addcmd("shutdown.reboot.graceful"); dstate_addcmd("shutdown.return"); #if 0 /* doesn't work */ dstate_addcmd("shutdown.stayoff"); #endif dstate_addcmd("shutdown.stop"); dstate_addcmd("test.battery.start"); dstate_addcmd("test.battery.stop"); /* add all the variables that change regularly */ upsdrv_updateinfo(); upsh.instcmd = instcmd; upsh.setvar = setvar; printf("Detected %s %s on %s\n", dstate_getinfo("ups.mfr"), dstate_getinfo("ups.model"), device_path); } void upsdrv_updateinfo(void) { char response[MAX_RESPONSE_LENGTH]; char *ptr, *ptr2; int i; int flags; int contacts_set; int low_battery; status_init(); if (do_command(POLL, STATUS_OUTPUT, "", response) <= 0) { dstate_datastale(); return; } ptr = field(response, 0); /* require output status field to exist */ if (!ptr) { dstate_datastale(); return; } switch (atoi(ptr)) { case 0: status_set("OL"); break; case 1: status_set("OB"); break; case 2: status_set("BYPASS"); break; case 3: status_set("OL"); status_set("TRIM"); break; case 4: status_set("OL"); status_set("BOOST"); break; case 5: status_set("BYPASS"); break; case 6: break; case 7: status_set("OFF"); break; default: break; } ptr = field(response, 6); if (ptr) dstate_setinfo("ups.load", "%d", atoi(ptr)); ptr = field(response, 3); if (ptr) dstate_setinfo("output.voltage", "%03.1f", (double) (atoi(ptr)) / 10.0); ptr = field(response, 1); if (ptr) dstate_setinfo("output.frequency", "%03.1f", (double) (atoi(ptr)) / 10.0); ptr = field(response, 4); if (ptr) dstate_setinfo("output.current", "%03.1f", (double) (atoi(ptr)) / 10.0); low_battery = 0; if (do_command(POLL, STATUS_BATTERY, "", response) <= 0) { dstate_datastale(); return; } ptr = field(response, 0); if (ptr && atoi(ptr) == 2) status_set("RB"); ptr = field(response, 1); if (ptr && atoi(ptr)) low_battery = 1; ptr = field(response, 8); if (ptr) dstate_setinfo("battery.temperature", "%d", atoi(ptr)); ptr = field(response, 9); if (ptr) { dstate_setinfo("battery.charge", "%d", atoi(ptr)); ptr2 = getval("lowbatt"); if (ptr2 && atoi(ptr2) > 0 && atoi(ptr2) <= 99 && atoi(ptr) <= atoi(ptr2)) low_battery = 1; } ptr = field(response, 6); if (ptr) dstate_setinfo("battery.voltage", "%03.1f", (double) (atoi(ptr)) / 10.0); ptr = field(response, 7); if (ptr) dstate_setinfo("battery.current", "%03.1f", (double) (atoi(ptr)) / 10.0); if (low_battery) status_set("LB"); if (do_command(POLL, STATUS_ALARM, "", response) <= 0) { dstate_datastale(); return; } ptr = field(response, 3); if (ptr && atoi(ptr)) status_set("OVER"); if (do_command(POLL, STATUS_INPUT, "", response) > 0) { ptr = field(response, 2); if (ptr) dstate_setinfo("input.voltage", "%03.1f", (double) (atoi(ptr)) / 10.0); ptr = field(response, 1); if (ptr) dstate_setinfo("input.frequency", "%03.1f", (double) (atoi(ptr)) / 10.0); } if (do_command(POLL, TEST_RESULT, "", response) > 0) { int r; size_t trsize; r = atoi(response); trsize = SIZEOF_ARRAY(test_result_names); if ((r < 0) || (r >= (int) trsize)) r = 0; dstate_setinfo("ups.test.result", "%s", test_result_names[r]); } if (do_command(POLL, ENVIRONMENT_INFORMATION, "", response) > 0) { ptr = field(response, 0); if (ptr) dstate_setinfo("ambient.temperature", "%d", atoi(ptr)); ptr = field(response, 1); if (ptr) dstate_setinfo("ambient.humidity", "%d", atoi(ptr)); flags = 0; contacts_set = 0; for (i = 0; i < 4; i++) { ptr = field(response, 2 + i); if (ptr) { contacts_set = 1; if (*ptr == '1') flags |= 1 << i; } } if (contacts_set) dstate_setinfo("ups.contacts", "%02X", (unsigned int)flags); } /* if we are here, status is valid */ status_commit(); dstate_dataok(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ char parm[20]; if (!init_comm()) printf("Status failed. Assuming it's on battery and trying a shutdown anyway.\n"); auto_reboot(1); /* in case the power is on, tell it to automatically reboot. if it is off, this has no effect. */ snprintf(parm, sizeof(parm), "%d", 1); /* delay before reboot, in minutes */ do_command(SET, TSU_SHUTDOWN_RESTART, parm, NULL); snprintf(parm, sizeof(parm), "%d", 5); /* delay before shutdown, in seconds */ do_command(SET, TSU_SHUTDOWN_ACTION, parm, NULL); } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x or ups.conf */ void upsdrv_makevartable(void) { addvar(VAR_VALUE, "lowbatt", "Set low battery level, in percent"); } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/nutdrv_qx_gtec.c0000644000175000017500000001722615000736161014141 00000000000000/* nutdrv_qx_gtec.c - Subdriver for Gtec UPSes * * Copyright (C) * 2025 Lukas Turek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_gtec.h" #define GTEC_VERSION "Gtec 0.01" /* Process status letters */ static int gtec_process_status(item_t *item, char *value, const size_t valuelen) { /* Return value is set by letters A/C/M, exactly one of them * * should be present in the status unless the UPS is off */ char *val = "OFF"; char *letters; update_status("OL"); /* UPS is on line unless indicated otherwise */ upsdebugx(10, "%s: Processing status letters %s", __func__, item->value); /* NOTE: The main driver calls status_init() and alarm_init() * * for us in nutdrv_qx.c::upsdrv_updateinfo() */ for (letters = item->value; *letters; letters++) { switch (*letters) { case 'A': /* Utility fail */ val = "!OL"; /* "OB" is not defined in status_info */ break; case 'B': /* Battery low */ update_status("LB"); break; case 'C': /* Bypass/boost active */ val = "BYPASS"; break; case 'D': /* UPS failed */ alarm_set("UPS failed"); break; case 'E': /* Test in progress */ dstate_setinfo("battery.test.status", "Test in progress"); break; case 'F': /* Shutdown active */ update_status("FSD"); break; case 'G': /* Site fault */ alarm_set("Site fault"); break; case 'H': /* EPROM fail */ alarm_set("EPROM fail"); break; case 'I': /* Test passed - Result: OK */ dstate_setinfo("battery.test.status", "Test passed - Result: OK"); break; case 'J': /* Test passed - Result: Failed */ dstate_setinfo("battery.test.status", "Test passed - Result: Failed"); update_status("RB"); break; case 'K': /* Test Result: Battery disconnected */ dstate_setinfo("battery.test.status", "Battery disconnected"); break; case 'L': /* Test status unknown */ dstate_setinfo("battery.test.status", "Test status unknown"); break; case 'M': /* UPS normal mode */ val = "OL"; break; case 'N': /* UPS overload */ update_status("OVER"); break; case 'P': /* Battery disconnected */ alarm_set("Battery disconnected"); break; default: upsdebugx(2, "%s: ignoring unknown status character %c", __func__, *letters); } } /* NOTE: The main driver calls status_commit() and alarm_commit() * * for us in nutdrv_qx.c::upsdrv_updateinfo() */ snprintf(value, valuelen, "%s", val); return 0; } /* qx2nut lookup table */ static item_t gtec_qx2nut[] = { /* * > [Q4\r] * < [(236.7 243.2 212.1 220.1 230.4 002 001 50.0 371 372 041.3 22.9 IM\r] * 012345678901234567890123456789012345678901234567890123456789012345 * 0 1 2 3 4 5 6 */ { "input.voltage", 0, NULL, "Q4\r", "", 64, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.voltage.fault", 0, NULL, "Q4\r", "", 64, '(', "", 19, 23, "%.1f", 0, NULL, NULL, NULL }, { "output.voltage", 0, NULL, "Q4\r", "", 64, '(', "", 25, 29, "%.1f", 0, NULL, NULL, NULL }, { "ups.load", 0, NULL, "Q4\r", "", 64, '(', "", 35, 37, "%.0f", 0, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "Q4\r", "", 64, '(', "", 39, 42, "%.1f", 0, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "Q4\r", "", 64, '(', "", 52, 56, "%.1f", 0, NULL, NULL, NULL }, { "ups.temperature", 0, NULL, "Q4\r", "", 64, '(', "", 58, 61, "%.1f", 0, NULL, NULL, NULL }, { "ups.status", 0, NULL, "Q4\r", "", 64, '(', "", 63, 0, NULL, 0, NULL, NULL, gtec_process_status }, /* * > [F\r] * < [#220.0 000 024.0 50.0\r] * 0123456789012345678901 * 0 1 2 */ { "input.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 1, 5, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.current.nominal", 0, NULL, "F\r", "", 22, '#', "", 7, 9, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "battery.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 11, 15, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.frequency.nominal", 0, NULL, "F\r", "", 22, '#', "", 17, 20, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, /* * > [I\r] * < [#------------- ------ VT12046Q \r] * 012345678901234567890123456789012345678 * 0 1 2 3 */ { "device.mfr", 0, NULL, "I\r", "", 39, '#', "", 1, 15, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "device.model", 0, NULL, "I\r", "", 39, '#', "", 17, 26, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, { "ups.firmware", 0, NULL, "I\r", "", 39, '#', "", 28, 37, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* Instant commands */ { "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%sR0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, blazer_r_ondelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_ONDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, blazer_r_offdelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_OFFDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* Testing table */ #ifdef TESTING static testing_t gtec_testing[] = { { "Q4\r", "(236.7 243.2 212.1 220.1 230.4 002 001 50.0 371 372 041.3 22.9 IM\r", -1 }, { "F\r", "#230.0 000 024.0 50.0\r", -1 }, { "I\r", "#NOT_A_LIVE_UPS TESTING TESTING \r", -1 }, { "Q\r", "", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0000\r", "", -1 }, { "T04\r", "", -1 }, { "TL\r", "", -1 }, { "T\r", "", -1 }, { "CT\r", "", -1 }, { NULL } }; #endif /* TESTING */ /* Subdriver-specific initups */ static void gtec_initups(void) { blazer_initups(gtec_qx2nut); } /* Subdriver interface */ subdriver_t gtec_subdriver = { GTEC_VERSION, blazer_claim, gtec_qx2nut, gtec_initups, NULL, blazer_makevartable, "ACK", NULL, #ifdef TESTING gtec_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/bcmxcp_ser.c0000664000175000017500000002750715000733203013231 00000000000000#include "main.h" #include "bcmxcp.h" #include "bcmxcp_io.h" #include "bcmxcp_ser.h" #include "serial.h" #include "nut_stdint.h" #define SUBDRIVER_NAME "RS-232 communication subdriver" #define SUBDRIVER_VERSION "0.22" /* communication driver description structure */ upsdrv_info_t comm_upsdrv_info = { SUBDRIVER_NAME, SUBDRIVER_VERSION, NULL, 0, { NULL } }; #define PW_MAX_BAUD 5 /* NOT static: also used from nut-scanner, so extern'ed via bcmxcp_ser.h */ pw_baud_rate_t pw_baud_rates[] = { { B19200, 19200 }, { B9600, 9600 }, { B4800, 4800 }, { B2400, 2400 }, { B1200, 1200 }, /* end of structure. */ { 0, 0 } }; /* NOT static: also used from nut-scanner, so extern'ed via bcmxcp_ser.h */ unsigned char BCMXCP_AUTHCMD[4] = {0xCF, 0x69, 0xE8, 0xD5}; /* Authorisation command */ static void send_command(unsigned char *command, size_t command_length) { int retry = 0; ssize_t sent; unsigned char sbuf[1024]; if (command_length > UCHAR_MAX) { upsdebugx (3, "%s: ERROR: command_length too long for the character protocol", __func__); return; } /* Prepare the send buffer */ sbuf[0] = PW_COMMAND_START_BYTE; sbuf[1] = (unsigned char)(command_length); memcpy(sbuf+2, command, command_length); command_length += 2; /* Add checksum */ sbuf[command_length] = calc_checksum(sbuf); command_length += 1; upsdebug_hex (3, "send_command", sbuf, command_length); while (retry++ < PW_MAX_TRY) { if (retry == PW_MAX_TRY) { ser_send_char(upsfd, 0x1d); /* last retry is preceded by a ESC.*/ usleep(250000); } sent = ser_send_buf(upsfd, sbuf, command_length); if (sent < 0) { upslogx(LOG_ERR, "%s(): error reading from ser_send_buf()", __func__); return; } if ((size_t)sent == command_length) { return; } } } void send_read_command(unsigned char command) { send_command(&command, 1); } void send_write_command(unsigned char *command, size_t command_length) { send_command(command, command_length); } /* get the answer of a command from the ups. And check that the answer is for this command */ ssize_t get_answer(unsigned char *data, unsigned char command) { unsigned char my_buf[128]; /* packet has a maximum length of 121+5 bytes */ ssize_t res; size_t length, end_length = 0, endblock = 0, start = 0; unsigned char block_number, sequence, pre_sequence = 0; while (endblock != 1) { do { /* Read PW_COMMAND_START_BYTE byte */ res = ser_get_char(upsfd, my_buf, 1, 0); if (res != 1) { upsdebugx(1, "Receive error (PW_COMMAND_START_BYTE): %" PRIiSIZE ", cmd=%x!!!\n", res, command); return -1; } start++; } while ((my_buf[0] != PW_COMMAND_START_BYTE) && (start < 128)); if (start == 128) { ser_comm_fail("Receive error (PW_COMMAND_START_BYTE): packet not on start!!%x\n", my_buf[0]); return -1; } /* Read block number byte */ res = ser_get_char(upsfd, my_buf + 1, 1, 0); if (res != 1) { ser_comm_fail("Receive error (Block number): %" PRIiSIZE "!!!\n", res); return -1; } block_number = (unsigned char)my_buf[1]; if (command <= 0x43) { if ((command - 0x30) != block_number) { ser_comm_fail("Receive error (Request command): %x!!!\n", block_number); return -1; } } if (command >= 0x89) { if ((command == 0xA0) && (block_number != 0x01)) { ser_comm_fail("Receive error (Requested only mode command): %x!!!\n", block_number); return -1; } if ((command != 0xA0) && (block_number != 0x09)) { ser_comm_fail("Receive error (Control command): %x!!!\n", block_number); return -1; } } /* Read data length byte */ res = ser_get_char(upsfd, my_buf + 2, 1, 0); if (res != 1) { ser_comm_fail("Receive error (length): %" PRIiSIZE "!!!\n", res); return -1; } length = (unsigned char)my_buf[2]; if (length < 1) { ser_comm_fail("Receive error (length): packet length %" PRIxSIZE "!!!\n", length); return -1; } /* Read sequence byte */ res = ser_get_char(upsfd, my_buf + 3, 1, 0); if (res != 1) { ser_comm_fail("Receive error (sequence): %" PRIiSIZE "!!!\n", res); return -1; } sequence = (unsigned char)my_buf[3]; if ((sequence & 0x80) == 0x80) { endblock = 1; } if ((sequence & 0x07) != (pre_sequence + 1)) { ser_comm_fail("Not the right sequence received %x!!!\n", sequence); return -1; } pre_sequence = sequence; /* Try to read all the remaining bytes */ res = ser_get_buf_len(upsfd, my_buf + 4, length, 1, 0); if (res < 0) { ser_comm_fail("%s(): ser_get_buf_len() returned error code %" PRIiSIZE, __func__, res); return res; } if ((size_t)res != length) { ser_comm_fail("Receive error (data): got %" PRIiSIZE " bytes instead of %" PRIuSIZE "!!!\n", res, length); return -1; } /* Get the checksum byte */ res = ser_get_char(upsfd, my_buf + (4 + length), 1, 0); if (res != 1) { ser_comm_fail("Receive error (checksum): %" PRIiSIZE "!!!\n", res); return -1; } /* now we have the whole answer from the ups, we can checksum it */ if (!checksum_test(my_buf)) { ser_comm_fail("checksum error! "); return -1; } memcpy(data+end_length, my_buf + 4, length); end_length += length; } upsdebug_hex (5, "get_answer", data, end_length); ser_comm_good(); assert(end_length < SSIZE_MAX); return (ssize_t)end_length; } static ssize_t command_sequence(unsigned char *command, size_t command_length, unsigned char *answer) { ssize_t bytes_read; int retry = 0; while (retry++ < PW_MAX_TRY) { if (retry == PW_MAX_TRY) { ser_flush_in(upsfd, "", 0); } send_write_command(command, command_length); bytes_read = get_answer(answer, *command); if (bytes_read > 0) { return bytes_read; } } return -1; } /* Sends a single command (length=1). and get the answer */ ssize_t command_read_sequence(unsigned char command, unsigned char *answer) { ssize_t bytes_read; bytes_read = command_sequence(&command, 1, answer); if (bytes_read < 1) { ser_comm_fail("Error executing command"); } return bytes_read; } /* Sends a setup command (length > 1) */ ssize_t command_write_sequence(unsigned char *command, size_t command_length, unsigned char *answer) { ssize_t bytes_read; bytes_read = command_sequence(command, command_length, answer); if (bytes_read < 1) { ser_comm_fail("Error executing command"); } return bytes_read; } void upsdrv_comm_good(void) { ser_comm_good(); } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic push #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtype-limits" #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif static void pw_comm_setup(const char *port) { unsigned char command = PW_SET_REQ_ONLY_MODE; unsigned char id_command = PW_ID_BLOCK_REQ; unsigned char answer[256]; int i = 0; ssize_t ret = -1; speed_t mybaud = 0, baud; if (getval("baud_rate") != NULL) { int br = atoi(getval("baud_rate")); /* Note that atoi() behavior on erroneous input is undefined */ if (br < 0) { upslogx(LOG_ERR, "baud_rate option is invalid"); return; } /* FIXME: speed_t does not define a SPEED_MAX value nor * guarantee that it is an int (just a typedef from * termios.h happens to say that on some systems)... * But since we convert this setting from int, we assume... */ #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) /* Note for gating macros above: unsuffixed HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP * means support of contexts both inside and outside function body, so the push * above and pop below (outside this finction) are not used. */ # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS /* Note that the individual warning pragmas for use inside function bodies * are named without a _INSIDEFUNC suffix, for simplicity and legacy reasons */ # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif switch(sizeof(speed_t)) { case 8: assert (br < INT64_MAX); break; case 4: assert (br < INT32_MAX); break; case 2: assert (br < INT16_MAX); break; default: assert (br < INT_MAX); } #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif baud = (speed_t)br; for (i = 0; i < PW_MAX_BAUD; i++) { if (baud == pw_baud_rates[i].name) { mybaud = pw_baud_rates[i].rate; break; } } if (mybaud == 0) { fatalx(EXIT_FAILURE, "Specified baudrate \"%s\" is invalid!", getval("baud_rate")); } ser_set_speed(upsfd, device_path, mybaud); ser_send_char(upsfd, 0x1d); /* send ESC to take it out of menu */ usleep(90000); send_write_command(BCMXCP_AUTHCMD, 4); usleep(500000); ret = command_sequence(&command, 1, answer); if (ret <= 0) { usleep(500000); ret = command_sequence(&id_command, 1, answer); } if (ret > 0) { /* Cast baud into max length unsigned, despite the POSIX * standard some systems vary in definition of this type */ upslogx(LOG_INFO, "Connected to UPS on %s with baudrate %llu", port, (unsigned long long int)baud); return; } upslogx(LOG_ERR, "No response from UPS on %s with baudrate %llu", port, (unsigned long long int)baud); } upslogx(LOG_INFO, "Attempting to autodect baudrate"); for (i=0; i 0) { upslogx(LOG_INFO, "Connected to UPS on %s with baudrate %" PRIuSIZE, port, pw_baud_rates[i].name); return; } upsdebugx(2, "No response from UPS on %s with baudrate %" PRIuSIZE, port, pw_baud_rates[i].name); } fatalx(EXIT_FAILURE, "Can't connect to the UPS on port %s!\n", port); } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic pop #endif void upsdrv_initups(void) { upsfd = ser_open(device_path); pw_comm_setup(device_path); } void upsdrv_cleanup(void) { /* free(dynamic_mem); */ ser_close(upsfd, device_path); } void upsdrv_reconnect(void) { } nut-2.8.4/drivers/blazer.c0000644000175000017500000005304315044656702012373 00000000000000/* * blazer.c: driver core for Megatec/Q1 protocol based UPSes * * OBSOLETION WARNING: Please to not base new development on this * codebase, instead create a new subdriver for nutdrv_qx which * generally covers all Megatec/Qx protocol family and aggregates * device support from such legacy drivers over time. * * A document describing the protocol implemented by this driver can be * found online at https://www.networkupstools.org/ups-protocols/megatec.html * * Copyright (C) * 2008,2009 - Arjen de Korte * 2012 - Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "blazer.h" #include "nut_float.h" static long ondelay = 3; /* minutes */ static long offdelay = 30; /* seconds */ static int proto; static int online = 1; static struct { double packs; /* battery voltage multiplier */ struct { double nom; /* nominal runtime on battery (full load) */ double est; /* estimated runtime remaining (full load) */ double exp; /* load exponent */ } runt; struct { double act; /* actual battery voltage */ double high; /* battery float voltage */ double nom; /* nominal battery voltage */ double low; /* battery low voltage */ } volt; struct { double act; /* actual battery charge */ long time; /* recharge time from empty to full */ } chrg; } batt = { 1, { -1, 0, 0 }, { -1, -1, -1, -1 }, { -1, 43200 } }; static struct { double act; /* actual load (reported by UPS) */ double low; /* idle load */ double eff; /* effective load */ } load = { 0, 0.1, 1 }; static time_t lastpoll = 0; /* * This little structure defines the various flavors of the Megatec protocol. * Only the .name and .status are mandatory, .rating and .vendor elements are * optional. If only some models support the last two, fill them in anyway * and tell people to use the 'norating' and 'novendor' options to bypass * getting them. */ static const struct { const char *name; const char *status; const char *rating; const char *vendor; } command[] = { { "megatec", "Q1\r", "F\r", "I\r" }, { "mustek", "QS\r", "F\r", "I\r" }, { "megatec/old", "D\r", "F\r", "I\r" }, { "zinto", "Q1\r", "F\r", "FW?\r" }, { NULL, NULL, NULL, NULL } }; /* * Do whatever we think is needed when we read a battery voltage from the UPS. * Basically all it does now, is guesstimating the battery charge, but this * could be extended. */ static double blazer_battery(const char *ptr, char **endptr) { batt.volt.act = batt.packs * strtod(ptr, endptr); if ((!getval("runtimecal") || !dstate_getinfo("battery.charge")) && (batt.volt.low > 0) && (batt.volt.high > batt.volt.low)) { batt.chrg.act = 100 * (batt.volt.act - batt.volt.low) / (batt.volt.high - batt.volt.low); if (batt.chrg.act < 0) { batt.chrg.act = 0; } if (batt.chrg.act > 100) { batt.chrg.act = 100; } dstate_setinfo("battery.charge", "%.0f", batt.chrg.act); } return batt.volt.act; } /* * Do whatever we think is needed when we read the load from the UPS. */ static double blazer_load(const char *ptr, char **endptr) { load.act = strtod(ptr, endptr); load.eff = pow(load.act / 100, batt.runt.exp); if (load.eff < load.low) { load.eff = load.low; } return load.act; } /* * The battery voltage will quickly return to at least the nominal value after * discharging them. For overlapping battery.voltage.low/high ranges therefore * choose the one with the highest multiplier. */ static double blazer_packs(const char *ptr, char **endptr) { const double packs[] = { 120, 100, 80, 60, 48, 36, 30, 24, 18, 12, 8, 6, 4, 3, 2, 1, 0.5, -1 }; const char *val; int i; val = dstate_getinfo("battery.voltage.nominal"); batt.volt.nom = strtod(val ? val : ptr, endptr); for (i = 0; packs[i] > 0; i++) { if (packs[i] * batt.volt.act > 1.25 * batt.volt.nom) { continue; } if (packs[i] * batt.volt.act < 0.8 * batt.volt.nom) { upslogx(LOG_INFO, "Can't autodetect number of battery packs [%.0f/%.2f]", batt.volt.nom, batt.volt.act); break; } batt.packs = packs[i]; break; } return batt.volt.nom; } static int blazer_status(const char *cmd) { const struct { const char *var; const char *fmt; double (*conv)(const char *, char **); } status[] = { { "input.voltage", "%.1f", strtod }, { "input.voltage.fault", "%.1f", strtod }, { "output.voltage", "%.1f", strtod }, { "ups.load", "%.0f", blazer_load }, { "input.frequency", "%.1f", strtod }, { "battery.voltage", "%.2f", blazer_battery }, { "ups.temperature", "%.1f", strtod }, { NULL, NULL, NULL } }; char buf[SMALLBUF], *val, *last = NULL; int i; /* * > [Q1\r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000\r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ if (blazer_command(cmd, buf, sizeof(buf)) < 46) { upsdebugx(2, "%s: short reply", __func__); return -1; } if (buf[0] != '(') { upsdebugx(2, "%s: invalid start character [%02x]", __func__, buf[0]); return -1; } for (i = 0, val = strtok_r(buf+1, " ", &last); status[i].var; i++, val = strtok_r(NULL, " \r\n", &last)) { if (!val) { upsdebugx(2, "%s: parsing failed", __func__); return -1; } if (strspn(val, "0123456789.") != strlen(val)) { upsdebugx(2, "%s: non numerical value [%s]", __func__, val); continue; } dstate_setinfo_dynamic(status[i].var, status[i].fmt, "%f", status[i].conv(val, NULL)); } if (!val) { upsdebugx(2, "%s: parsing failed", __func__); return -1; } if (strspn(val, "01") != 8) { upsdebugx(2, "Invalid status [%s]", val); return -1; } if (val[7] == '1') { /* Beeper On */ dstate_setinfo("ups.beeper.status", "enabled"); } else { dstate_setinfo("ups.beeper.status", "disabled"); } if (val[4] == '1') { /* UPS Type is Standby (0 is On_line) */ dstate_setinfo("ups.type", "offline / line interactive"); } else { dstate_setinfo("ups.type", "online"); } status_init(); if (val[0] == '1') { /* Utility Fail (Immediate) */ status_set("OB"); online = 0; } else { status_set("OL"); online = 1; } if (val[1] == '1') { /* Battery Low */ status_set("LB"); } if (val[2] == '1') { /* Bypass/Boost or Buck Active */ double vi, vo; vi = strtod(dstate_getinfo("input.voltage"), NULL); vo = strtod(dstate_getinfo("output.voltage"), NULL); if (vo < 0.5 * vi) { upsdebugx(2, "%s: output voltage too low", __func__); } else if (vo < 0.95 * vi) { status_set("TRIM"); } else if (vo < 1.05 * vi) { status_set("BYPASS"); } else if (vo < 1.5 * vi) { status_set("BOOST"); } else { upsdebugx(2, "%s: output voltage too high", __func__); } } if (val[5] == '1') { /* Test in Progress */ status_set("CAL"); } alarm_init(); if (val[3] == '1') { /* UPS Failed */ alarm_set("UPS selftest failed!"); } if (val[6] == '1') { /* Shutdown Active */ alarm_set("Shutdown imminent!"); status_set("FSD"); } alarm_commit(); status_commit(); return 0; } static int blazer_rating(const char *cmd) { const struct { const char *var; const char *fmt; double (*conv)(const char *, char **); } rating[] = { { "input.voltage.nominal", "%.0f", strtod }, { "input.current.nominal", "%.1f", strtod }, { "battery.voltage.nominal", "%.1f", blazer_packs }, { "input.frequency.nominal", "%.0f", strtod }, { NULL, NULL, NULL } }; char buf[SMALLBUF], *val, *last = NULL; int i; /* * > [F\r] * < [#220.0 000 024.0 50.0\r] * 0123456789012345678901 * 0 1 2 */ if (blazer_command(cmd, buf, sizeof(buf)) < 22) { upsdebugx(2, "%s: short reply", __func__); return -1; } if (buf[0] != '#') { upsdebugx(2, "%s: invalid start character [%02x]", __func__, buf[0]); return -1; } for (i = 0, val = strtok_r(buf+1, " ", &last); rating[i].var; i++, val = strtok_r(NULL, " \r\n", &last)) { if (!val) { upsdebugx(2, "%s: parsing failed", __func__); return -1; } if (strspn(val, "0123456789.") != strlen(val)) { upsdebugx(2, "%s: non numerical value [%s]", __func__, val); continue; } dstate_setinfo_dynamic(rating[i].var, rating[i].fmt, "%f", rating[i].conv(val, NULL)); } return 0; } static int blazer_vendor(const char *cmd) { const struct { const char *var; const int len; } information[] = { { "ups.mfr", 15 }, { "ups.model", 10 }, { "ups.firmware", 10 }, { NULL, 0 } }; char buf[SMALLBUF]; int i, index; /* * > [I\r] * < [#------------- ------ VT12046Q \r] * 012345678901234567890123456789012345678 * 0 1 2 3 */ if (blazer_command(cmd, buf, sizeof(buf)) < 39) { upsdebugx(2, "%s: short reply", __func__); return -1; } if (buf[0] != '#') { upsdebugx(2, "%s: invalid start character [%02x]", __func__, buf[0]); return -1; } for (i = 0, index = 1; information[i].var; index += information[i++].len+1) { char val[SMALLBUF]; snprintf(val, sizeof(val), "%.*s", information[i].len, &buf[index]); dstate_setinfo(information[i].var, "%s", str_rtrim(val, ' ')); } return 0; } static int blazer_instcmd(const char *cmdname, const char *extra) { const struct { const char *cmd; const char *ups; } instcmd[] = { { "beeper.toggle", "Q\r" }, { "load.off", "S00R0000\r" }, { "load.on", "C\r" }, { "shutdown.stop", "C\r" }, { "test.battery.start.deep", "TL\r" }, { "test.battery.start.quick", "T\r" }, { "test.battery.stop", "CT\r" }, { NULL, NULL } }; char buf[SMALLBUF] = ""; int i; upsdebug_INSTCMD_STARTING(cmdname, extra); for (i = 0; instcmd[i].cmd; i++) { if (strcasecmp(cmdname, instcmd[i].cmd)) { continue; } snprintf(buf, sizeof(buf), "%s", instcmd[i].ups); /* * If a command is invalid, it will be echoed back * As an exception, Best UPS units will report "ACK" in case of success! * Other UPSes will reply "(ACK" in case of success. */ upslog_INSTCMD_POWERSTATE_CHECKED(cmdname, extra); if (blazer_command(buf, buf, sizeof(buf)) > 0) { if (strncmp(buf, "ACK", 3) && strncmp(buf, "(ACK", 4)) { upslogx(LOG_INSTCMD_FAILED, "instcmd: command [%s] failed", cmdname); return STAT_INSTCMD_FAILED; } } upslogx(LOG_INFO, "instcmd: command [%s] handled", cmdname); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* * Sn: Shutdown after n minutes and then turn on when mains is back * SnRm: Shutdown after n minutes and then turn on after m minutes * Accepted values for n: .2 -> .9 , 01 -> 10 * Accepted values for m: 0001 -> 9999 * Note: "S01R0001" and "S01R0002" may not work on early (GE) * firmware versions. The failure mode is that the UPS turns * off and never returns. The fix is to push the return value * up by 2, i.e. S01R0003, and it will return online properly. * (thus the default of ondelay=3 mins) */ if (ondelay == 0) { if (offdelay < 60) { snprintf(buf, sizeof(buf), "S.%ld\r", offdelay / 6); } else { snprintf(buf, sizeof(buf), "S%02ld\r", offdelay / 60); } } else if (offdelay < 60) { snprintf(buf, sizeof(buf), "S.%ldR%04ld\r", offdelay / 6, ondelay); } else { snprintf(buf, sizeof(buf), "S%02ldR%04ld\r", offdelay / 60, ondelay); } } else if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* * SnR0000 * Shutdown after n minutes and stay off * Accepted values for n: .2 -> .9 , 01 -> 10 */ if (offdelay < 60) { snprintf(buf, sizeof(buf), "S.%ldR0000\r", offdelay / 6); } else { snprintf(buf, sizeof(buf), "S%02ldR0000\r", offdelay / 60); } } else if (!strcasecmp(cmdname, "test.battery.start")) { long delay = extra ? strtol(extra, NULL, 10) : 10; if ((delay < 1) || (delay > 99)) { upslogx(LOG_INSTCMD_FAILED, "instcmd: command [%s] failed, delay [%s] out of range", cmdname, extra); return STAT_INSTCMD_FAILED; } upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); snprintf(buf, sizeof(buf), "T%02ld\r", delay); } else { upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } /* * If a command is invalid, it will be echoed back. * As an exception, Best UPS units will report "ACK" in case of success! * Other UPSes will reply "(ACK" in case of success. */ if (blazer_command(buf, buf, sizeof(buf)) > 0) { if (strncmp(buf, "ACK", 3) && strncmp(buf, "(ACK", 4)) { upslogx(LOG_INSTCMD_FAILED, "instcmd: command [%s] failed", cmdname); return STAT_INSTCMD_FAILED; } } upslogx(LOG_INFO, "instcmd: command [%s] handled", cmdname); return STAT_INSTCMD_HANDLED; } void blazer_makevartable(void) { addvar(VAR_VALUE, "ondelay", "Delay before UPS startup (minutes)"); addvar(VAR_VALUE, "offdelay", "Delay before UPS shutdown (seconds)"); addvar(VAR_VALUE, "runtimecal", "Parameters used for runtime calculation"); addvar(VAR_VALUE, "chargetime", "Nominal charge time for UPS battery"); addvar(VAR_VALUE, "idleload", "Minimum load to be used for runtime calculation"); addvar(VAR_FLAG, "norating", "Skip reading rating information from UPS"); addvar(VAR_FLAG, "novendor", "Skip reading vendor information from UPS"); addvar(VAR_VALUE, "protocol", "Preselect communication protocol (skip autodetection)"); } void blazer_initups(void) { const char *val; val = getval("ondelay"); if (val) { ondelay = strtol(val, NULL, 10); } if ((ondelay < 0) || (ondelay > 9999)) { fatalx(EXIT_FAILURE, "Start delay '%ld' out of range [0..9999]", ondelay); } val = getval("offdelay"); if (val) { offdelay = strtol(val, NULL, 10); } if ((offdelay < 12) || (offdelay > 600)) { fatalx(EXIT_FAILURE, "Shutdown delay '%ld' out of range [12..600]", offdelay); } /* Truncate to nearest setable value */ if (offdelay < 60) { offdelay -= (offdelay % 6); } else { offdelay -= (offdelay % 60); } val = dstate_getinfo("battery.voltage.high"); if (val) { batt.volt.high = strtod(val, NULL); } val = dstate_getinfo("battery.voltage.low"); if (val) { batt.volt.low = strtod(val, NULL); } } static void blazer_initbattery(void) { const char *val; /* If no values were provided by the user in ups.conf, try to guesstimate * battery.charge, but announce it! */ if ( (!d_equal(batt.volt.nom, 1)) && ((d_equal(batt.volt.high, -1)) || (d_equal(batt.volt.low, -1)))) { upslogx(LOG_INFO, "No values provided for battery high/low voltages in ups.conf\n"); /* Basic formula, which should cover most cases */ batt.volt.low = 104 * batt.volt.nom / 120; batt.volt.high = 130 * batt.volt.nom / 120; /* Publish these data too */ dstate_setinfo("battery.voltage.low", "%.2f", batt.volt.low); dstate_setinfo("battery.voltage.high", "%.2f", batt.volt.high); upslogx(LOG_INFO, "Using 'guesstimation' (low: %f, high: %f)!", batt.volt.low, batt.volt.high); } val = getval("runtimecal"); if (val) { double rh, lh, rl, ll; time(&lastpoll); if (sscanf(val, "%lf,%lf,%lf,%lf", &rh, &lh, &rl, &ll) < 4) { fatalx(EXIT_FAILURE, "Insufficient parameters for runtimecal"); } if ((rl < rh) || (rh <= 0)) { fatalx(EXIT_FAILURE, "Parameter out of range (runtime)"); } if ((lh > 100) || (ll > lh) || (ll <= 0)) { fatalx(EXIT_FAILURE, "Parameter out of range (load)"); } batt.runt.exp = log(rl / rh) / log(lh / ll); upsdebugx(2, "battery runtime exponent : %.3f", batt.runt.exp); batt.runt.nom = rh * pow(lh / 100, batt.runt.exp); upsdebugx(2, "battery runtime nominal : %.1f", batt.runt.nom); } else { upslogx(LOG_INFO, "Battery runtime will not be calculated (runtimecal not set)"); return; } if (batt.chrg.act < 0) { batt.volt.low = batt.volt.nom; batt.volt.high = 1.15 * batt.volt.nom; blazer_battery(dstate_getinfo("battery.voltage"), NULL); } val = dstate_getinfo("battery.charge"); if (val) { batt.runt.est = batt.runt.nom * strtod(val, NULL) / 100; upsdebugx(2, "battery runtime estimate : %.1f", batt.runt.est); } else { fatalx(EXIT_FAILURE, "Initial battery charge undetermined"); } val = getval("chargetime"); if (val) { batt.chrg.time = strtol(val, NULL, 10); if (batt.chrg.time <= 0) { fatalx(EXIT_FAILURE, "Charge time out of range [1..s]"); } upsdebugx(2, "battery charge time : %ld", batt.chrg.time); } else { upslogx(LOG_INFO, "No charge time specified, using built in default [%ld seconds]", batt.chrg.time); } val = getval("idleload"); if (val) { load.low = strtod(val, NULL) / 100; if ((load.low < 0) || (load.low > 1)) { fatalx(EXIT_FAILURE, "Idle load out of range [0..100]"); } upsdebugx(2, "minimum load used (idle) : %.3f", load.low); } else { upslogx(LOG_INFO, "No idle load specified, using built in default [%.1f %%]", 100 * load.low); } } void blazer_initinfo(void) { const char *protocol = getval("protocol"); int retry; upsdebugx(0, "Please note that this driver is deprecated and will not receive\n" "new development. If it works for managing your devices - fine,\n" "but if you are running it to try setting up a new device, please\n" "consider the newer nutdrv_qx instead, which should handle all 'Qx'\n" "protocol variants for NUT. (Please also report if your device works\n" "with this driver, but nutdrv_qx would not actually support it with\n" "any subdriver!)\n"); for (proto = 0; command[proto].status; proto++) { int ret = -1; if (protocol && strcasecmp(protocol, command[proto].name)) { upsdebugx(2, "Skipping %s protocol...", command[proto].name); continue; } upsdebugx(2, "Trying %s protocol...", command[proto].name); for (retry = 1; retry <= MAXTRIES; retry++) { ret = blazer_status(command[proto].status); if (ret < 0) { upsdebugx(2, "Status read %d failed", retry); continue; } upsdebugx(2, "Status read in %d tries", retry); break; } if (!ret) { upslogx(LOG_INFO, "Supported UPS detected with %s protocol", command[proto].name); break; } } if (!command[proto].status) { fatalx(EXIT_FAILURE, "No supported UPS detected"); } if (command[proto].rating && !testvar("norating")) { int ret = -1; for (retry = 1; retry <= MAXTRIES; retry++) { ret = blazer_rating(command[proto].rating); if (ret < 0) { upsdebugx(1, "Rating read %d failed", retry); continue; } upsdebugx(2, "Ratings read in %d tries", retry); break; } if (ret) { upslogx(LOG_DEBUG, "Rating information unavailable"); } } if (command[proto].vendor && !testvar("novendor")) { int ret = -1; for (retry = 1; retry <= MAXTRIES; retry++) { ret = blazer_vendor(command[proto].vendor); if (ret < 0) { upsdebugx(1, "Vendor information read %d failed", retry); continue; } upslogx(LOG_INFO, "Vendor information read in %d tries", retry); break; } if (ret) { upslogx(LOG_DEBUG, "Vendor information unavailable"); } } blazer_initbattery(); dstate_setinfo("ups.delay.start", "%ld", 60 * ondelay); dstate_setinfo("ups.delay.shutdown", "%ld", offdelay); dstate_addcmd("beeper.toggle"); dstate_addcmd("load.off"); dstate_addcmd("load.on"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); dstate_addcmd("shutdown.stop"); dstate_addcmd("test.battery.start"); dstate_addcmd("test.battery.start.deep"); dstate_addcmd("test.battery.start.quick"); dstate_addcmd("test.battery.stop"); upsh.instcmd = blazer_instcmd; } void upsdrv_updateinfo(void) { static int retry = 0; if (blazer_status(command[proto].status)) { if (retry < MAXTRIES) { upsdebugx(1, "Communications with UPS lost: status read failed!"); retry++; } else if (retry == MAXTRIES) { upslogx(LOG_WARNING, "Communications with UPS lost: status read failed!"); retry++; } else { dstate_datastale(); } return; } if (getval("runtimecal")) { time_t now; time(&now); if (online) { /* OL */ batt.runt.est += batt.runt.nom * difftime(now, lastpoll) / batt.chrg.time; if (batt.runt.est > batt.runt.nom) { batt.runt.est = batt.runt.nom; } } else { /* OB */ batt.runt.est -= load.eff * difftime(now, lastpoll); if (batt.runt.est < 0) { batt.runt.est = 0; } } dstate_setinfo("battery.charge", "%.0f", 100 * batt.runt.est / batt.runt.nom); dstate_setinfo("battery.runtime", "%.0f", batt.runt.est / load.eff); lastpoll = now; } if (retry > MAXTRIES) { upslogx(LOG_NOTICE, "Communications with UPS re-established"); } retry = 0; dstate_dataok(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int retry; /* Stop pending shutdowns */ for (retry = 1; retry <= MAXTRIES; retry++) { if (blazer_instcmd("shutdown.stop", NULL) != STAT_INSTCMD_HANDLED) { continue; } break; } if (retry > MAXTRIES) { upslogx(LOG_NOTICE, "No shutdown pending"); } /* Shutdown */ for (retry = 1; retry <= MAXTRIES; retry++) { if (blazer_instcmd("shutdown.return", NULL) != STAT_INSTCMD_HANDLED) { continue; } upslogx(LOG_ERR, "Shutting down in %ld seconds", offdelay); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); return; } upslogx(LOG_ERR, "Shutdown failed!"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } nut-2.8.4/drivers/Makefile.in0000644000175000017500000107004615045354760013020 00000000000000# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # Network UPS Tools: drivers VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ @WITH_USB_TRUE@am__append_1 = $(LIBUSB_CFLAGS) @WITH_NEON_TRUE@am__append_2 = $(LIBNEON_CFLAGS) @WITH_LIBPOWERMAN_TRUE@am__append_3 = $(LIBPOWERMAN_CFLAGS) @WITH_IPMI_TRUE@am__append_4 = $(LIBIPMI_CFLAGS) @WITH_GPIO_TRUE@am__append_5 = $(LIBGPIO_CFLAGS) @WITH_MODBUS_TRUE@am__append_6 = $(LIBMODBUS_CFLAGS) @HAVE_LIBREGEX_TRUE@am__append_7 = $(LIBREGEX_CFLAGS) # Temporary, until ported to more OSes @HAVE_LINUX_SERIAL_H_TRUE@am__append_8 = nhs_ser EXTRA_PROGRAMS = $(am__EXEEXT_2) $(am__EXEEXT_4) $(am__EXEEXT_5) \ $(am__EXEEXT_6) $(am__EXEEXT_7) $(am__EXEEXT_8) \ $(am__EXEEXT_9) $(am__EXEEXT_10) $(am__EXEEXT_11) @SOME_DRIVERS_FALSE@driverexec_PROGRAMS = $(am__EXEEXT_10) \ @SOME_DRIVERS_FALSE@ $(am__EXEEXT_12) $(am__EXEEXT_13) \ @SOME_DRIVERS_FALSE@ $(am__EXEEXT_14) $(am__EXEEXT_15) \ @SOME_DRIVERS_FALSE@ $(am__EXEEXT_16) $(am__EXEEXT_18) \ @SOME_DRIVERS_FALSE@ $(am__EXEEXT_20) $(am__EXEEXT_21) \ @SOME_DRIVERS_FALSE@ $(am__EXEEXT_22) $(am__EXEEXT_23) \ @SOME_DRIVERS_FALSE@ $(am__EXEEXT_25) @SOME_DRIVERS_TRUE@driverexec_PROGRAMS = $(DRIVER_BUILD_LIST) \ @SOME_DRIVERS_TRUE@ $(am__EXEEXT_12) $(am__EXEEXT_13) \ @SOME_DRIVERS_TRUE@ $(am__EXEEXT_14) $(am__EXEEXT_15) \ @SOME_DRIVERS_TRUE@ $(am__EXEEXT_16) $(am__EXEEXT_18) \ @SOME_DRIVERS_TRUE@ $(am__EXEEXT_20) $(am__EXEEXT_21) \ @SOME_DRIVERS_TRUE@ $(am__EXEEXT_22) $(am__EXEEXT_23) \ @SOME_DRIVERS_TRUE@ $(am__EXEEXT_25) @SOME_DRIVERS_FALSE@@WITH_SERIAL_TRUE@am__append_9 = $(SERIAL_DRIVERLIST) $(SERIAL_USB_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_SERIAL_FALSE@@WITH_USB_TRUE@am__append_10 = $(SERIAL_USB_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_SNMP_TRUE@am__append_11 = $(SNMP_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_USB_TRUE@am__append_12 = $(USB_LIBUSB_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_NEON_TRUE@am__append_13 = $(NEONXML_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_LIBPOWERMAN_TRUE@am__append_14 = $(POWERMAN_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_IPMI_TRUE@am__append_15 = $(IPMI_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_GPIO_TRUE@am__append_16 = $(GPIO_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_MACOSX_TRUE@am__append_17 = $(MACOSX_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_LINUX_I2C_TRUE@am__append_18 = $(LINUX_I2C_DRIVERLIST) @SOME_DRIVERS_FALSE@@WITH_MODBUS_TRUE@am__append_19 = $(MODBUS_DRIVERLIST) sbin_PROGRAMS = upsdrvctl$(EXEEXT) @WITH_SSL_TRUE@am__append_20 = $(LIBSSL_CFLAGS) @WITH_SSL_TRUE@am__append_21 = $(LIBSSL_LIBS) @WITH_SSL_TRUE@am__append_22 = $(LIBSSL_LDFLAGS_RPATH) @WITH_OPENSSL_FALSE@@WITH_SSL_TRUE@am__append_23 = -UNETSNMP_USE_OPENSSL @WITH_SSL_TRUE@am__append_24 = $(LIBSSL_CFLAGS) @WITH_SSL_TRUE@am__append_25 = $(LIBSSL_LIBS) @WITH_SSL_TRUE@am__append_26 = $(LIBSSL_LDFLAGS_RPATH) @WITH_SSL_TRUE@am__append_27 = $(LIBSSL_CFLAGS) @WITH_SSL_TRUE@am__append_28 = $(LIBSSL_LIBS) @WITH_SSL_TRUE@am__append_29 = $(LIBSSL_LDFLAGS_RPATH) @WITH_FREEIPMI_TRUE@am__append_30 = nut-libfreeipmi.c @WITH_MODBUS_USB_TRUE@am__append_31 = $(LIBUSB_IMPL) hidparser.c usb-common.c @WITH_MODBUS_USB_TRUE@am__append_32 = $(LIBUSB_LIBS) @WITH_SERIAL_TRUE@am__append_33 = -DQX_SERIAL @WITH_SERIAL_TRUE@am__append_34 = libdummy_serial.la $(SERLIBS) @WITH_USB_TRUE@am__append_35 = -DQX_USB @WITH_USB_TRUE@am__append_36 = $(LIBUSB_IMPL) usb-common.c @WITH_USB_TRUE@am__append_37 = $(LIBUSB_LIBS) subdir = drivers ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_c___attribute__.m4 \ $(top_srcdir)/m4/ax_c_pragmas.m4 \ $(top_srcdir)/m4/ax_check_compile_flag.m4 \ $(top_srcdir)/m4/ax_compare_version.m4 \ $(top_srcdir)/m4/ax_realpath.m4 \ $(top_srcdir)/m4/ax_realpath_lib.m4 \ $(top_srcdir)/m4/ax_run_or_link_ifelse.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/m4/nut_arg_with.m4 \ $(top_srcdir)/m4/nut_check_asciidoc.m4 \ $(top_srcdir)/m4/nut_check_aspell.m4 \ $(top_srcdir)/m4/nut_check_bool.m4 \ $(top_srcdir)/m4/nut_check_cppcheck.m4 \ $(top_srcdir)/m4/nut_check_headers_windows.m4 \ $(top_srcdir)/m4/nut_check_libavahi.m4 \ $(top_srcdir)/m4/nut_check_libfreeipmi.m4 \ $(top_srcdir)/m4/nut_check_libgd.m4 \ $(top_srcdir)/m4/nut_check_libgpiod.m4 \ $(top_srcdir)/m4/nut_check_libltdl.m4 \ $(top_srcdir)/m4/nut_check_libmodbus.m4 \ $(top_srcdir)/m4/nut_check_libneon.m4 \ $(top_srcdir)/m4/nut_check_libnetsnmp.m4 \ $(top_srcdir)/m4/nut_check_libnss.m4 \ $(top_srcdir)/m4/nut_check_libopenssl.m4 \ $(top_srcdir)/m4/nut_check_libpowerman.m4 \ $(top_srcdir)/m4/nut_check_libregex.m4 \ $(top_srcdir)/m4/nut_check_libsystemd.m4 \ $(top_srcdir)/m4/nut_check_libusb.m4 \ $(top_srcdir)/m4/nut_check_libwrap.m4 \ $(top_srcdir)/m4/nut_check_os.m4 \ $(top_srcdir)/m4/nut_check_pkgconfig.m4 \ $(top_srcdir)/m4/nut_check_python.m4 \ $(top_srcdir)/m4/nut_check_socketlib.m4 \ $(top_srcdir)/m4/nut_compiler_family.m4 \ $(top_srcdir)/m4/nut_func_getnameinfo_argtypes.m4 \ $(top_srcdir)/m4/nut_report_feature.m4 \ $(top_srcdir)/m4/nut_stash_warnings.m4 \ $(top_srcdir)/m4/nut_type_socklen_t.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(dist_noinst_HEADERS) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = @HAVE_LINUX_SERIAL_H_TRUE@am__EXEEXT_1 = nhs_ser$(EXEEXT) am__EXEEXT_2 = al175$(EXEEXT) bcmxcp$(EXEEXT) belkin$(EXEEXT) \ belkinunv$(EXEEXT) bestfcom$(EXEEXT) bestfortress$(EXEEXT) \ bestuferrups$(EXEEXT) bestups$(EXEEXT) etapro$(EXEEXT) \ everups$(EXEEXT) gamatronic$(EXEEXT) genericups$(EXEEXT) \ isbmex$(EXEEXT) liebert$(EXEEXT) liebert-esp2$(EXEEXT) \ liebert-gxe$(EXEEXT) masterguard$(EXEEXT) metasys$(EXEEXT) \ mge-utalk$(EXEEXT) microdowell$(EXEEXT) microsol-apc$(EXEEXT) \ mge-shut$(EXEEXT) nutdrv_hashx$(EXEEXT) oneac$(EXEEXT) \ optiups$(EXEEXT) powercom$(EXEEXT) powervar_cx_ser$(EXEEXT) \ rhino$(EXEEXT) safenet$(EXEEXT) nutdrv_siemens-sitop$(EXEEXT) \ solis$(EXEEXT) tripplite$(EXEEXT) tripplitesu$(EXEEXT) \ upscode2$(EXEEXT) victronups$(EXEEXT) powerpanel$(EXEEXT) \ blazer_ser$(EXEEXT) ivtscd$(EXEEXT) apcsmart$(EXEEXT) \ apcsmart-old$(EXEEXT) riello_ser$(EXEEXT) sms_ser$(EXEEXT) \ bicker_ser$(EXEEXT) ve-direct$(EXEEXT) $(am__EXEEXT_1) am__EXEEXT_3 = usbhid-ups$(EXEEXT) bcmxcp_usb$(EXEEXT) \ tripplite_usb$(EXEEXT) blazer_usb$(EXEEXT) \ richcomm_usb$(EXEEXT) riello_usb$(EXEEXT) \ powervar_cx_usb$(EXEEXT) nutdrv_atcl_usb$(EXEEXT) am__EXEEXT_4 = $(am__EXEEXT_3) am__EXEEXT_5 = nutdrv_qx$(EXEEXT) am__EXEEXT_6 = snmp-ups$(EXEEXT) am__EXEEXT_7 = netxml-ups$(EXEEXT) am__EXEEXT_8 = macosx-ups$(EXEEXT) am__EXEEXT_9 = asem$(EXEEXT) pijuice$(EXEEXT) hwmon_ina219$(EXEEXT) am__EXEEXT_10 = $(NUTSW_DRIVERLIST_DUMMY_UPS) clone$(EXEEXT) \ clone-outlet$(EXEEXT) failover$(EXEEXT) apcupsd-ups$(EXEEXT) \ skel$(EXEEXT) am__EXEEXT_11 = generic_gpio_libgpiod$(EXEEXT) @SOME_DRIVERS_FALSE@@WITH_SERIAL_TRUE@am__EXEEXT_12 = $(am__EXEEXT_2) \ @SOME_DRIVERS_FALSE@@WITH_SERIAL_TRUE@ $(am__EXEEXT_5) @SOME_DRIVERS_FALSE@@WITH_SERIAL_FALSE@@WITH_USB_TRUE@am__EXEEXT_13 = $(am__EXEEXT_5) @SOME_DRIVERS_FALSE@@WITH_SNMP_TRUE@am__EXEEXT_14 = $(am__EXEEXT_6) @SOME_DRIVERS_FALSE@@WITH_USB_TRUE@am__EXEEXT_15 = $(am__EXEEXT_3) @SOME_DRIVERS_FALSE@@WITH_NEON_TRUE@am__EXEEXT_16 = $(am__EXEEXT_7) am__EXEEXT_17 = powerman-pdu$(EXEEXT) @SOME_DRIVERS_FALSE@@WITH_LIBPOWERMAN_TRUE@am__EXEEXT_18 = \ @SOME_DRIVERS_FALSE@@WITH_LIBPOWERMAN_TRUE@ $(am__EXEEXT_17) am__EXEEXT_19 = nut-ipmipsu$(EXEEXT) @SOME_DRIVERS_FALSE@@WITH_IPMI_TRUE@am__EXEEXT_20 = $(am__EXEEXT_19) @SOME_DRIVERS_FALSE@@WITH_GPIO_TRUE@am__EXEEXT_21 = $(am__EXEEXT_11) @SOME_DRIVERS_FALSE@@WITH_MACOSX_TRUE@am__EXEEXT_22 = $(am__EXEEXT_8) @SOME_DRIVERS_FALSE@@WITH_LINUX_I2C_TRUE@am__EXEEXT_23 = \ @SOME_DRIVERS_FALSE@@WITH_LINUX_I2C_TRUE@ $(am__EXEEXT_9) am__EXEEXT_24 = phoenixcontact_modbus$(EXEEXT) generic_modbus$(EXEEXT) \ huawei-ups2000$(EXEEXT) socomec_jbus$(EXEEXT) \ adelsystem_cbi$(EXEEXT) apc_modbus$(EXEEXT) @SOME_DRIVERS_FALSE@@WITH_MODBUS_TRUE@am__EXEEXT_25 = \ @SOME_DRIVERS_FALSE@@WITH_MODBUS_TRUE@ $(am__EXEEXT_24) am__installdirs = "$(DESTDIR)$(driverexecdir)" "$(DESTDIR)$(sbindir)" PROGRAMS = $(driverexec_PROGRAMS) $(sbin_PROGRAMS) LTLIBRARIES = $(noinst_LTLIBRARIES) libdummy_la_LIBADD = am_libdummy_la_OBJECTS = main.lo dstate.lo libdummy_la_OBJECTS = $(am_libdummy_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = libdummy_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libdummy_la_LDFLAGS) $(LDFLAGS) -o $@ libdummy_mockdrv_la_DEPENDENCIES = \ $(top_builddir)/common/libcommon.la \ $(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libparseconf.la am_libdummy_mockdrv_la_OBJECTS = libdummy_mockdrv_la-main.lo \ libdummy_mockdrv_la-dstate.lo libdummy_mockdrv_la_OBJECTS = $(am_libdummy_mockdrv_la_OBJECTS) libdummy_mockdrv_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(libdummy_mockdrv_la_CFLAGS) $(CFLAGS) \ $(libdummy_mockdrv_la_LDFLAGS) $(LDFLAGS) -o $@ libdummy_serial_la_LIBADD = am_libdummy_serial_la_OBJECTS = serial.lo libdummy_serial_la_OBJECTS = $(am_libdummy_serial_la_OBJECTS) libdummy_serial_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(libdummy_serial_la_LDFLAGS) \ $(LDFLAGS) -o $@ libdummy_upsdrvquery_la_LIBADD = am_libdummy_upsdrvquery_la_OBJECTS = upsdrvquery.lo libdummy_upsdrvquery_la_OBJECTS = \ $(am_libdummy_upsdrvquery_la_OBJECTS) libdummy_upsdrvquery_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(AM_CFLAGS) $(CFLAGS) $(libdummy_upsdrvquery_la_LDFLAGS) \ $(LDFLAGS) -o $@ am__DEPENDENCIES_1 = libserial_nutscan_la_DEPENDENCIES = $(am__DEPENDENCIES_1) am_libserial_nutscan_la_OBJECTS = libserial_nutscan_la-serial.lo \ libserial_nutscan_la-bcmxcp_ser.lo libserial_nutscan_la_OBJECTS = $(am_libserial_nutscan_la_OBJECTS) libserial_nutscan_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(libserial_nutscan_la_CFLAGS) $(CFLAGS) \ $(libserial_nutscan_la_LDFLAGS) $(LDFLAGS) -o $@ am_adelsystem_cbi_OBJECTS = adelsystem_cbi.$(OBJEXT) adelsystem_cbi_OBJECTS = $(am_adelsystem_cbi_OBJECTS) adelsystem_cbi_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_al175_OBJECTS = al175.$(OBJEXT) al175_OBJECTS = $(am_al175_OBJECTS) al175_LDADD = $(LDADD) am__DEPENDENCIES_2 = libdummy_serial.la $(LDADD_DRIVERS) \ $(am__DEPENDENCIES_1) al175_DEPENDENCIES = $(am__DEPENDENCIES_2) am__apc_modbus_SOURCES_DIST = apc_modbus.c libusb0.c libusb1.c \ hidparser.c usb-common.c @WITH_LIBUSB_0_1_FALSE@@WITH_LIBUSB_1_0_TRUE@am__objects_1 = libusb1.$(OBJEXT) @WITH_LIBUSB_0_1_TRUE@am__objects_1 = libusb0.$(OBJEXT) @WITH_MODBUS_USB_TRUE@am__objects_2 = $(am__objects_1) \ @WITH_MODBUS_USB_TRUE@ hidparser.$(OBJEXT) usb-common.$(OBJEXT) am_apc_modbus_OBJECTS = apc_modbus.$(OBJEXT) $(am__objects_2) apc_modbus_OBJECTS = $(am_apc_modbus_OBJECTS) @WITH_MODBUS_USB_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1) apc_modbus_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_3) am_apcsmart_OBJECTS = apcsmart.$(OBJEXT) apcsmart_tabs.$(OBJEXT) apcsmart_OBJECTS = $(am_apcsmart_OBJECTS) am__DEPENDENCIES_4 = $(am__DEPENDENCIES_2) apcsmart_DEPENDENCIES = $(am__DEPENDENCIES_4) $(am__DEPENDENCIES_1) am_apcsmart_old_OBJECTS = apcsmart-old.$(OBJEXT) apcsmart_old_OBJECTS = $(am_apcsmart_old_OBJECTS) apcsmart_old_LDADD = $(LDADD) apcsmart_old_DEPENDENCIES = $(am__DEPENDENCIES_2) am_apcupsd_ups_OBJECTS = apcupsd_ups-apcupsd-ups.$(OBJEXT) apcupsd_ups_OBJECTS = $(am_apcupsd_ups_OBJECTS) apcupsd_ups_DEPENDENCIES = $(LDADD_DRIVERS) apcupsd_ups_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(apcupsd_ups_CFLAGS) \ $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ am_asem_OBJECTS = asem.$(OBJEXT) asem_OBJECTS = $(am_asem_OBJECTS) asem_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_bcmxcp_OBJECTS = bcmxcp.$(OBJEXT) bcmxcp_ser.$(OBJEXT) bcmxcp_OBJECTS = $(am_bcmxcp_OBJECTS) bcmxcp_DEPENDENCIES = $(am__DEPENDENCIES_4) am_bcmxcp_usb_OBJECTS = bcmxcp_usb.$(OBJEXT) bcmxcp.$(OBJEXT) \ usb-common.$(OBJEXT) bcmxcp_usb_OBJECTS = $(am_bcmxcp_usb_OBJECTS) bcmxcp_usb_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_belkin_OBJECTS = belkin.$(OBJEXT) belkin_OBJECTS = $(am_belkin_OBJECTS) belkin_LDADD = $(LDADD) belkin_DEPENDENCIES = $(am__DEPENDENCIES_2) am_belkinunv_OBJECTS = belkinunv.$(OBJEXT) belkinunv_OBJECTS = $(am_belkinunv_OBJECTS) belkinunv_LDADD = $(LDADD) belkinunv_DEPENDENCIES = $(am__DEPENDENCIES_2) am_bestfcom_OBJECTS = bestfcom.$(OBJEXT) bestfcom_OBJECTS = $(am_bestfcom_OBJECTS) bestfcom_LDADD = $(LDADD) bestfcom_DEPENDENCIES = $(am__DEPENDENCIES_2) am_bestfortress_OBJECTS = bestfortress.$(OBJEXT) bestfortress_OBJECTS = $(am_bestfortress_OBJECTS) bestfortress_LDADD = $(LDADD) bestfortress_DEPENDENCIES = $(am__DEPENDENCIES_2) am_bestuferrups_OBJECTS = bestuferrups.$(OBJEXT) bestuferrups_OBJECTS = $(am_bestuferrups_OBJECTS) bestuferrups_LDADD = $(LDADD) bestuferrups_DEPENDENCIES = $(am__DEPENDENCIES_2) am_bestups_OBJECTS = bestups.$(OBJEXT) bestups_OBJECTS = $(am_bestups_OBJECTS) bestups_LDADD = $(LDADD) bestups_DEPENDENCIES = $(am__DEPENDENCIES_2) am_bicker_ser_OBJECTS = bicker_ser.$(OBJEXT) bicker_ser_OBJECTS = $(am_bicker_ser_OBJECTS) bicker_ser_DEPENDENCIES = $(am__DEPENDENCIES_4) am_blazer_ser_OBJECTS = blazer.$(OBJEXT) blazer_ser.$(OBJEXT) blazer_ser_OBJECTS = $(am_blazer_ser_OBJECTS) blazer_ser_DEPENDENCIES = $(am__DEPENDENCIES_4) am__blazer_usb_SOURCES_DIST = blazer.c blazer_usb.c libusb0.c \ libusb1.c usb-common.c am_blazer_usb_OBJECTS = blazer.$(OBJEXT) blazer_usb.$(OBJEXT) \ $(am__objects_1) usb-common.$(OBJEXT) blazer_usb_OBJECTS = $(am_blazer_usb_OBJECTS) blazer_usb_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_clone_OBJECTS = clone.$(OBJEXT) clone_OBJECTS = $(am_clone_OBJECTS) clone_LDADD = $(LDADD) clone_DEPENDENCIES = $(am__DEPENDENCIES_2) am_clone_outlet_OBJECTS = clone-outlet.$(OBJEXT) clone_outlet_OBJECTS = $(am_clone_outlet_OBJECTS) clone_outlet_LDADD = $(LDADD) clone_outlet_DEPENDENCIES = $(am__DEPENDENCIES_2) am_dummy_ups_OBJECTS = dummy_ups-dummy-ups.$(OBJEXT) dummy_ups_OBJECTS = $(am_dummy_ups_OBJECTS) @WITH_SSL_TRUE@am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1) dummy_ups_DEPENDENCIES = $(LDADD_DRIVERS) \ $(top_builddir)/clients/libupsclient.la $(am__DEPENDENCIES_5) dummy_ups_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(dummy_ups_CFLAGS) \ $(CFLAGS) $(dummy_ups_LDFLAGS) $(LDFLAGS) -o $@ am_etapro_OBJECTS = etapro.$(OBJEXT) etapro_OBJECTS = $(am_etapro_OBJECTS) etapro_LDADD = $(LDADD) etapro_DEPENDENCIES = $(am__DEPENDENCIES_2) am_everups_OBJECTS = everups.$(OBJEXT) everups_OBJECTS = $(am_everups_OBJECTS) everups_LDADD = $(LDADD) everups_DEPENDENCIES = $(am__DEPENDENCIES_2) am_failover_OBJECTS = failover.$(OBJEXT) failover_OBJECTS = $(am_failover_OBJECTS) failover_LDADD = $(LDADD) failover_DEPENDENCIES = $(am__DEPENDENCIES_2) am_gamatronic_OBJECTS = gamatronic.$(OBJEXT) gamatronic_OBJECTS = $(am_gamatronic_OBJECTS) gamatronic_LDADD = $(LDADD) gamatronic_DEPENDENCIES = $(am__DEPENDENCIES_2) am_generic_gpio_libgpiod_OBJECTS = generic_gpio_common.$(OBJEXT) \ generic_gpio_libgpiod.$(OBJEXT) generic_gpio_libgpiod_OBJECTS = $(am_generic_gpio_libgpiod_OBJECTS) generic_gpio_libgpiod_DEPENDENCIES = $(LDADD_DRIVERS) \ $(am__DEPENDENCIES_1) am_generic_modbus_OBJECTS = generic_modbus.$(OBJEXT) generic_modbus_OBJECTS = $(am_generic_modbus_OBJECTS) generic_modbus_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_genericups_OBJECTS = genericups.$(OBJEXT) genericups_OBJECTS = $(am_genericups_OBJECTS) genericups_LDADD = $(LDADD) genericups_DEPENDENCIES = $(am__DEPENDENCIES_2) am_huawei_ups2000_OBJECTS = huawei-ups2000.$(OBJEXT) huawei_ups2000_OBJECTS = $(am_huawei_ups2000_OBJECTS) huawei_ups2000_DEPENDENCIES = $(am__DEPENDENCIES_2) \ $(am__DEPENDENCIES_1) am_hwmon_ina219_OBJECTS = hwmon_ina219.$(OBJEXT) hwmon_ina219_OBJECTS = $(am_hwmon_ina219_OBJECTS) hwmon_ina219_DEPENDENCIES = $(LDADD_DRIVERS) am_isbmex_OBJECTS = isbmex.$(OBJEXT) isbmex_OBJECTS = $(am_isbmex_OBJECTS) isbmex_DEPENDENCIES = $(am__DEPENDENCIES_4) am_ivtscd_OBJECTS = ivtscd.$(OBJEXT) ivtscd_OBJECTS = $(am_ivtscd_OBJECTS) ivtscd_LDADD = $(LDADD) ivtscd_DEPENDENCIES = $(am__DEPENDENCIES_2) am_liebert_OBJECTS = liebert.$(OBJEXT) liebert_OBJECTS = $(am_liebert_OBJECTS) liebert_LDADD = $(LDADD) liebert_DEPENDENCIES = $(am__DEPENDENCIES_2) am_liebert_esp2_OBJECTS = liebert-esp2.$(OBJEXT) liebert_esp2_OBJECTS = $(am_liebert_esp2_OBJECTS) liebert_esp2_LDADD = $(LDADD) liebert_esp2_DEPENDENCIES = $(am__DEPENDENCIES_2) am_liebert_gxe_OBJECTS = liebert-gxe.$(OBJEXT) liebert_gxe_OBJECTS = $(am_liebert_gxe_OBJECTS) liebert_gxe_LDADD = $(LDADD) liebert_gxe_DEPENDENCIES = $(am__DEPENDENCIES_2) am_macosx_ups_OBJECTS = macosx-ups.$(OBJEXT) macosx_ups_OBJECTS = $(am_macosx_ups_OBJECTS) macosx_ups_DEPENDENCIES = $(LDADD_DRIVERS) macosx_ups_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(macosx_ups_LDFLAGS) $(LDFLAGS) -o $@ am_masterguard_OBJECTS = masterguard.$(OBJEXT) masterguard_OBJECTS = $(am_masterguard_OBJECTS) masterguard_LDADD = $(LDADD) masterguard_DEPENDENCIES = $(am__DEPENDENCIES_2) am_metasys_OBJECTS = metasys.$(OBJEXT) metasys_OBJECTS = $(am_metasys_OBJECTS) metasys_DEPENDENCIES = $(am__DEPENDENCIES_4) am_mge_shut_OBJECTS = mge_shut-usbhid-ups.$(OBJEXT) \ mge_shut-libshut.$(OBJEXT) mge_shut-libhid.$(OBJEXT) \ mge_shut-hidparser.$(OBJEXT) mge_shut-mge-hid.$(OBJEXT) mge_shut_OBJECTS = $(am_mge_shut_OBJECTS) mge_shut_DEPENDENCIES = $(am__DEPENDENCIES_4) mge_shut_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(mge_shut_CFLAGS) \ $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ am_mge_utalk_OBJECTS = mge-utalk.$(OBJEXT) mge_utalk_OBJECTS = $(am_mge_utalk_OBJECTS) mge_utalk_LDADD = $(LDADD) mge_utalk_DEPENDENCIES = $(am__DEPENDENCIES_2) am_microdowell_OBJECTS = microdowell.$(OBJEXT) microdowell_OBJECTS = $(am_microdowell_OBJECTS) microdowell_LDADD = $(LDADD) microdowell_DEPENDENCIES = $(am__DEPENDENCIES_2) am_microsol_apc_OBJECTS = microsol-apc.$(OBJEXT) \ microsol-common.$(OBJEXT) microsol_apc_OBJECTS = $(am_microsol_apc_OBJECTS) microsol_apc_DEPENDENCIES = $(am__DEPENDENCIES_4) am_netxml_ups_OBJECTS = netxml_ups-netxml-ups.$(OBJEXT) \ netxml_ups-mge-xml.$(OBJEXT) netxml_ups_OBJECTS = $(am_netxml_ups_OBJECTS) netxml_ups_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_5) netxml_ups_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(netxml_ups_CFLAGS) \ $(CFLAGS) $(netxml_ups_LDFLAGS) $(LDFLAGS) -o $@ am_nhs_ser_OBJECTS = nhs_ser.$(OBJEXT) nhs_ser_OBJECTS = $(am_nhs_ser_OBJECTS) nhs_ser_DEPENDENCIES = $(am__DEPENDENCIES_4) am__nut_ipmipsu_SOURCES_DIST = nut-ipmipsu.c nut-libfreeipmi.c @WITH_FREEIPMI_TRUE@am__objects_3 = nut-libfreeipmi.$(OBJEXT) am_nut_ipmipsu_OBJECTS = nut-ipmipsu.$(OBJEXT) $(am__objects_3) nut_ipmipsu_OBJECTS = $(am_nut_ipmipsu_OBJECTS) nut_ipmipsu_DEPENDENCIES = $(am__DEPENDENCIES_4) $(am__DEPENDENCIES_1) am_nutdrv_atcl_usb_OBJECTS = nutdrv_atcl_usb.$(OBJEXT) \ usb-common.$(OBJEXT) nutdrv_atcl_usb_OBJECTS = $(am_nutdrv_atcl_usb_OBJECTS) nutdrv_atcl_usb_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_nutdrv_hashx_OBJECTS = nutdrv_hashx.$(OBJEXT) nutdrv_hashx_OBJECTS = $(am_nutdrv_hashx_OBJECTS) nutdrv_hashx_DEPENDENCIES = $(am__DEPENDENCIES_4) am__nutdrv_qx_SOURCES_DIST = nutdrv_qx.c libusb0.c libusb1.c \ usb-common.c nutdrv_qx_bestups.c nutdrv_qx_blazer-common.c \ nutdrv_qx_innovart31.c nutdrv_qx_innovart33.c \ nutdrv_qx_masterguard.c nutdrv_qx_mecer.c nutdrv_qx_megatec.c \ nutdrv_qx_megatec-old.c nutdrv_qx_mustek.c nutdrv_qx_q1.c \ nutdrv_qx_q2.c nutdrv_qx_q6.c nutdrv_qx_voltronic.c \ common_voltronic-crc.c nutdrv_qx_voltronic-axpert.c \ nutdrv_qx_voltronic-qs.c nutdrv_qx_voltronic-qs-hex.c \ nutdrv_qx_zinto.c nutdrv_qx_hunnox.c nutdrv_qx_ablerex.c \ nutdrv_qx_gtec.c @WITH_LIBUSB_0_1_FALSE@@WITH_LIBUSB_1_0_TRUE@am__objects_4 = nutdrv_qx-libusb1.$(OBJEXT) @WITH_LIBUSB_0_1_TRUE@am__objects_4 = nutdrv_qx-libusb0.$(OBJEXT) @WITH_USB_TRUE@am__objects_5 = $(am__objects_4) \ @WITH_USB_TRUE@ nutdrv_qx-usb-common.$(OBJEXT) am__objects_6 = nutdrv_qx-nutdrv_qx_bestups.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_blazer-common.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_innovart31.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_innovart33.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_masterguard.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_mecer.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_megatec.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_megatec-old.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_mustek.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_q1.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_q2.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_q6.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_voltronic.$(OBJEXT) \ nutdrv_qx-common_voltronic-crc.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_voltronic-axpert.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_voltronic-qs.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_voltronic-qs-hex.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_zinto.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_hunnox.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_ablerex.$(OBJEXT) \ nutdrv_qx-nutdrv_qx_gtec.$(OBJEXT) am_nutdrv_qx_OBJECTS = nutdrv_qx-nutdrv_qx.$(OBJEXT) $(am__objects_5) \ $(am__objects_6) nutdrv_qx_OBJECTS = $(am_nutdrv_qx_OBJECTS) @WITH_SERIAL_TRUE@am__DEPENDENCIES_6 = libdummy_serial.la \ @WITH_SERIAL_TRUE@ $(am__DEPENDENCIES_1) @WITH_USB_TRUE@am__DEPENDENCIES_7 = $(am__DEPENDENCIES_1) nutdrv_qx_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_6) \ $(am__DEPENDENCIES_7) nutdrv_qx_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(nutdrv_qx_CFLAGS) \ $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ am_nutdrv_siemens_sitop_OBJECTS = nutdrv_siemens_sitop.$(OBJEXT) nutdrv_siemens_sitop_OBJECTS = $(am_nutdrv_siemens_sitop_OBJECTS) nutdrv_siemens_sitop_LDADD = $(LDADD) nutdrv_siemens_sitop_DEPENDENCIES = $(am__DEPENDENCIES_2) am_oneac_OBJECTS = oneac.$(OBJEXT) oneac_OBJECTS = $(am_oneac_OBJECTS) oneac_LDADD = $(LDADD) oneac_DEPENDENCIES = $(am__DEPENDENCIES_2) am_optiups_OBJECTS = optiups.$(OBJEXT) optiups_OBJECTS = $(am_optiups_OBJECTS) optiups_LDADD = $(LDADD) optiups_DEPENDENCIES = $(am__DEPENDENCIES_2) am_phoenixcontact_modbus_OBJECTS = phoenixcontact_modbus.$(OBJEXT) phoenixcontact_modbus_OBJECTS = $(am_phoenixcontact_modbus_OBJECTS) phoenixcontact_modbus_DEPENDENCIES = $(LDADD_DRIVERS) \ $(am__DEPENDENCIES_1) am_pijuice_OBJECTS = pijuice.$(OBJEXT) pijuice_OBJECTS = $(am_pijuice_OBJECTS) pijuice_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_powercom_OBJECTS = powercom.$(OBJEXT) powercom_OBJECTS = $(am_powercom_OBJECTS) powercom_DEPENDENCIES = $(am__DEPENDENCIES_4) am_powerman_pdu_OBJECTS = powerman-pdu.$(OBJEXT) powerman_pdu_OBJECTS = $(am_powerman_pdu_OBJECTS) powerman_pdu_DEPENDENCIES = $(am__DEPENDENCIES_4) \ $(am__DEPENDENCIES_1) am_powerpanel_OBJECTS = powerpanel.$(OBJEXT) powerp-bin.$(OBJEXT) \ powerp-txt.$(OBJEXT) powerpanel_OBJECTS = $(am_powerpanel_OBJECTS) powerpanel_DEPENDENCIES = $(am__DEPENDENCIES_4) am_powervar_cx_ser_OBJECTS = \ powervar_cx_ser-powervar_cx_ser.$(OBJEXT) \ powervar_cx_ser-powervar_cx.$(OBJEXT) powervar_cx_ser_OBJECTS = $(am_powervar_cx_ser_OBJECTS) powervar_cx_ser_LDADD = $(LDADD) powervar_cx_ser_DEPENDENCIES = $(am__DEPENDENCIES_2) powervar_cx_ser_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(powervar_cx_ser_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ -o $@ am__powervar_cx_usb_SOURCES_DIST = powervar_cx_usb.c powervar_cx.c \ libusb0.c libusb1.c usb-common.c @WITH_LIBUSB_0_1_FALSE@@WITH_LIBUSB_1_0_TRUE@am__objects_7 = powervar_cx_usb-libusb1.$(OBJEXT) @WITH_LIBUSB_0_1_TRUE@am__objects_7 = \ @WITH_LIBUSB_0_1_TRUE@ powervar_cx_usb-libusb0.$(OBJEXT) am_powervar_cx_usb_OBJECTS = \ powervar_cx_usb-powervar_cx_usb.$(OBJEXT) \ powervar_cx_usb-powervar_cx.$(OBJEXT) $(am__objects_7) \ powervar_cx_usb-usb-common.$(OBJEXT) powervar_cx_usb_OBJECTS = $(am_powervar_cx_usb_OBJECTS) powervar_cx_usb_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) powervar_cx_usb_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(powervar_cx_usb_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ -o $@ am_rhino_OBJECTS = rhino.$(OBJEXT) rhino_OBJECTS = $(am_rhino_OBJECTS) rhino_DEPENDENCIES = $(am__DEPENDENCIES_4) am__richcomm_usb_SOURCES_DIST = richcomm_usb.c libusb0.c libusb1.c \ usb-common.c am_richcomm_usb_OBJECTS = richcomm_usb.$(OBJEXT) $(am__objects_1) \ usb-common.$(OBJEXT) richcomm_usb_OBJECTS = $(am_richcomm_usb_OBJECTS) richcomm_usb_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_riello_ser_OBJECTS = riello.$(OBJEXT) riello_ser.$(OBJEXT) riello_ser_OBJECTS = $(am_riello_ser_OBJECTS) riello_ser_DEPENDENCIES = $(am__DEPENDENCIES_4) am__riello_usb_SOURCES_DIST = riello.c riello_usb.c libusb0.c \ libusb1.c usb-common.c am_riello_usb_OBJECTS = riello.$(OBJEXT) riello_usb.$(OBJEXT) \ $(am__objects_1) usb-common.$(OBJEXT) riello_usb_OBJECTS = $(am_riello_usb_OBJECTS) riello_usb_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_safenet_OBJECTS = safenet.$(OBJEXT) safenet_OBJECTS = $(am_safenet_OBJECTS) safenet_LDADD = $(LDADD) safenet_DEPENDENCIES = $(am__DEPENDENCIES_2) am_skel_OBJECTS = skel.$(OBJEXT) skel_OBJECTS = $(am_skel_OBJECTS) skel_DEPENDENCIES = $(LDADD_DRIVERS) am_sms_ser_OBJECTS = sms_ser.$(OBJEXT) sms_ser_OBJECTS = $(am_sms_ser_OBJECTS) sms_ser_DEPENDENCIES = $(am__DEPENDENCIES_4) am_snmp_ups_OBJECTS = snmp_ups-snmp-ups.$(OBJEXT) \ snmp_ups-snmp-ups-helpers.$(OBJEXT) snmp_ups-apc-mib.$(OBJEXT) \ snmp_ups-apc-pdu-mib.$(OBJEXT) snmp_ups-apc-epdu-mib.$(OBJEXT) \ snmp_ups-baytech-mib.$(OBJEXT) \ snmp_ups-baytech-rpc3nc-mib.$(OBJEXT) \ snmp_ups-bestpower-mib.$(OBJEXT) snmp_ups-compaq-mib.$(OBJEXT) \ snmp_ups-cyberpower-mib.$(OBJEXT) \ snmp_ups-delta_ups-mib.$(OBJEXT) \ snmp_ups-eaton-pdu-genesis2-mib.$(OBJEXT) \ snmp_ups-eaton-pdu-marlin-mib.$(OBJEXT) \ snmp_ups-eaton-pdu-marlin-helpers.$(OBJEXT) \ snmp_ups-eaton-pdu-pulizzi-mib.$(OBJEXT) \ snmp_ups-eaton-pdu-revelation-mib.$(OBJEXT) \ snmp_ups-eaton-pdu-nlogic-mib.$(OBJEXT) \ snmp_ups-eaton-ats16-nmc-mib.$(OBJEXT) \ snmp_ups-eaton-ats16-nm2-mib.$(OBJEXT) \ snmp_ups-apc-ats-mib.$(OBJEXT) \ snmp_ups-eaton-ats30-mib.$(OBJEXT) \ snmp_ups-eaton-ups-pwnm2-mib.$(OBJEXT) \ snmp_ups-eaton-ups-pxg-mib.$(OBJEXT) \ snmp_ups-emerson-avocent-pdu-mib.$(OBJEXT) \ snmp_ups-hpe-pdu-mib.$(OBJEXT) \ snmp_ups-hpe-pdu3-cis-mib.$(OBJEXT) \ snmp_ups-huawei-mib.$(OBJEXT) snmp_ups-ietf-mib.$(OBJEXT) \ snmp_ups-mge-mib.$(OBJEXT) snmp_ups-netvision-mib.$(OBJEXT) \ snmp_ups-raritan-pdu-mib.$(OBJEXT) \ snmp_ups-raritan-px2-mib.$(OBJEXT) snmp_ups-xppc-mib.$(OBJEXT) snmp_ups_OBJECTS = $(am_snmp_ups_OBJECTS) snmp_ups_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_5) snmp_ups_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(snmp_ups_CFLAGS) \ $(CFLAGS) $(snmp_ups_LDFLAGS) $(LDFLAGS) -o $@ am_socomec_jbus_OBJECTS = socomec_jbus.$(OBJEXT) socomec_jbus_OBJECTS = $(am_socomec_jbus_OBJECTS) socomec_jbus_DEPENDENCIES = $(am__DEPENDENCIES_2) \ $(am__DEPENDENCIES_1) am_solis_OBJECTS = solis.$(OBJEXT) solis_OBJECTS = $(am_solis_OBJECTS) solis_DEPENDENCIES = $(am__DEPENDENCIES_4) am_tripplite_OBJECTS = tripplite.$(OBJEXT) tripplite_OBJECTS = $(am_tripplite_OBJECTS) tripplite_DEPENDENCIES = $(am__DEPENDENCIES_4) am__tripplite_usb_SOURCES_DIST = tripplite_usb.c libusb0.c libusb1.c \ usb-common.c am_tripplite_usb_OBJECTS = tripplite_usb.$(OBJEXT) $(am__objects_1) \ usb-common.$(OBJEXT) tripplite_usb_OBJECTS = $(am_tripplite_usb_OBJECTS) tripplite_usb_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_tripplitesu_OBJECTS = tripplitesu.$(OBJEXT) tripplitesu_OBJECTS = $(am_tripplitesu_OBJECTS) tripplitesu_LDADD = $(LDADD) tripplitesu_DEPENDENCIES = $(am__DEPENDENCIES_2) am_upscode2_OBJECTS = upscode2.$(OBJEXT) upscode2_OBJECTS = $(am_upscode2_OBJECTS) upscode2_DEPENDENCIES = $(am__DEPENDENCIES_4) am_upsdrvctl_OBJECTS = upsdrvctl.$(OBJEXT) upsdrvctl_OBJECTS = $(am_upsdrvctl_OBJECTS) upsdrvctl_DEPENDENCIES = $(LDADD_COMMON) libdummy_upsdrvquery.la am__usbhid_ups_SOURCES_DIST = usbhid-ups.c libhid.c libusb0.c \ libusb1.c hidparser.c usb-common.c apc-hid.c arduino-hid.c \ belkin-hid.c cps-hid.c explore-hid.c liebert-hid.c mge-hid.c \ powercom-hid.c tripplite-hid.c idowell-hid.c openups-hid.c \ powervar-hid.c delta_ups-hid.c ecoflow-hid.c ever-hid.c \ legrand-hid.c salicru-hid.c am__objects_8 = apc-hid.$(OBJEXT) arduino-hid.$(OBJEXT) \ belkin-hid.$(OBJEXT) cps-hid.$(OBJEXT) explore-hid.$(OBJEXT) \ liebert-hid.$(OBJEXT) mge-hid.$(OBJEXT) powercom-hid.$(OBJEXT) \ tripplite-hid.$(OBJEXT) idowell-hid.$(OBJEXT) \ openups-hid.$(OBJEXT) powervar-hid.$(OBJEXT) \ delta_ups-hid.$(OBJEXT) ecoflow-hid.$(OBJEXT) \ ever-hid.$(OBJEXT) legrand-hid.$(OBJEXT) salicru-hid.$(OBJEXT) am_usbhid_ups_OBJECTS = usbhid-ups.$(OBJEXT) libhid.$(OBJEXT) \ $(am__objects_1) hidparser.$(OBJEXT) usb-common.$(OBJEXT) \ $(am__objects_8) usbhid_ups_OBJECTS = $(am_usbhid_ups_OBJECTS) usbhid_ups_DEPENDENCIES = $(LDADD_DRIVERS) $(am__DEPENDENCIES_1) am_ve_direct_OBJECTS = ve-direct.$(OBJEXT) ve_direct_OBJECTS = $(am_ve_direct_OBJECTS) ve_direct_DEPENDENCIES = $(am__DEPENDENCIES_4) am_victronups_OBJECTS = victronups.$(OBJEXT) victronups_OBJECTS = $(am_victronups_OBJECTS) victronups_LDADD = $(LDADD) victronups_DEPENDENCIES = $(am__DEPENDENCIES_2) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/adelsystem_cbi.Po \ ./$(DEPDIR)/al175.Po ./$(DEPDIR)/apc-hid.Po \ ./$(DEPDIR)/apc_modbus.Po ./$(DEPDIR)/apcsmart-old.Po \ ./$(DEPDIR)/apcsmart.Po ./$(DEPDIR)/apcsmart_tabs.Po \ ./$(DEPDIR)/apcupsd_ups-apcupsd-ups.Po \ ./$(DEPDIR)/arduino-hid.Po ./$(DEPDIR)/asem.Po \ ./$(DEPDIR)/bcmxcp.Po ./$(DEPDIR)/bcmxcp_ser.Po \ ./$(DEPDIR)/bcmxcp_usb.Po ./$(DEPDIR)/belkin-hid.Po \ ./$(DEPDIR)/belkin.Po ./$(DEPDIR)/belkinunv.Po \ ./$(DEPDIR)/bestfcom.Po ./$(DEPDIR)/bestfortress.Po \ ./$(DEPDIR)/bestuferrups.Po ./$(DEPDIR)/bestups.Po \ ./$(DEPDIR)/bicker_ser.Po ./$(DEPDIR)/blazer.Po \ ./$(DEPDIR)/blazer_ser.Po ./$(DEPDIR)/blazer_usb.Po \ ./$(DEPDIR)/clone-outlet.Po ./$(DEPDIR)/clone.Po \ ./$(DEPDIR)/cps-hid.Po ./$(DEPDIR)/delta_ups-hid.Po \ ./$(DEPDIR)/dstate.Plo ./$(DEPDIR)/dummy_ups-dummy-ups.Po \ ./$(DEPDIR)/ecoflow-hid.Po ./$(DEPDIR)/etapro.Po \ ./$(DEPDIR)/ever-hid.Po ./$(DEPDIR)/everups.Po \ ./$(DEPDIR)/explore-hid.Po ./$(DEPDIR)/failover.Po \ ./$(DEPDIR)/gamatronic.Po ./$(DEPDIR)/generic_gpio_common.Po \ ./$(DEPDIR)/generic_gpio_libgpiod.Po \ ./$(DEPDIR)/generic_modbus.Po ./$(DEPDIR)/genericups.Po \ ./$(DEPDIR)/hidparser.Po ./$(DEPDIR)/huawei-ups2000.Po \ ./$(DEPDIR)/hwmon_ina219.Po ./$(DEPDIR)/idowell-hid.Po \ ./$(DEPDIR)/isbmex.Po ./$(DEPDIR)/ivtscd.Po \ ./$(DEPDIR)/legrand-hid.Po \ ./$(DEPDIR)/libdummy_mockdrv_la-dstate.Plo \ ./$(DEPDIR)/libdummy_mockdrv_la-main.Plo ./$(DEPDIR)/libhid.Po \ ./$(DEPDIR)/libserial_nutscan_la-bcmxcp_ser.Plo \ ./$(DEPDIR)/libserial_nutscan_la-serial.Plo \ ./$(DEPDIR)/libusb0.Po ./$(DEPDIR)/libusb1.Po \ ./$(DEPDIR)/liebert-esp2.Po ./$(DEPDIR)/liebert-gxe.Po \ ./$(DEPDIR)/liebert-hid.Po ./$(DEPDIR)/liebert.Po \ ./$(DEPDIR)/macosx-ups.Po ./$(DEPDIR)/main.Plo \ ./$(DEPDIR)/masterguard.Po ./$(DEPDIR)/metasys.Po \ ./$(DEPDIR)/mge-hid.Po ./$(DEPDIR)/mge-utalk.Po \ ./$(DEPDIR)/mge_shut-hidparser.Po \ ./$(DEPDIR)/mge_shut-libhid.Po ./$(DEPDIR)/mge_shut-libshut.Po \ ./$(DEPDIR)/mge_shut-mge-hid.Po \ ./$(DEPDIR)/mge_shut-usbhid-ups.Po ./$(DEPDIR)/microdowell.Po \ ./$(DEPDIR)/microsol-apc.Po ./$(DEPDIR)/microsol-common.Po \ ./$(DEPDIR)/netxml_ups-mge-xml.Po \ ./$(DEPDIR)/netxml_ups-netxml-ups.Po ./$(DEPDIR)/nhs_ser.Po \ ./$(DEPDIR)/nut-ipmipsu.Po ./$(DEPDIR)/nut-libfreeipmi.Po \ ./$(DEPDIR)/nutdrv_atcl_usb.Po ./$(DEPDIR)/nutdrv_hashx.Po \ ./$(DEPDIR)/nutdrv_qx-common_voltronic-crc.Po \ ./$(DEPDIR)/nutdrv_qx-libusb0.Po \ ./$(DEPDIR)/nutdrv_qx-libusb1.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Po \ ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Po \ ./$(DEPDIR)/nutdrv_qx-usb-common.Po \ ./$(DEPDIR)/nutdrv_siemens_sitop.Po ./$(DEPDIR)/oneac.Po \ ./$(DEPDIR)/openups-hid.Po ./$(DEPDIR)/optiups.Po \ ./$(DEPDIR)/phoenixcontact_modbus.Po ./$(DEPDIR)/pijuice.Po \ ./$(DEPDIR)/powercom-hid.Po ./$(DEPDIR)/powercom.Po \ ./$(DEPDIR)/powerman-pdu.Po ./$(DEPDIR)/powerp-bin.Po \ ./$(DEPDIR)/powerp-txt.Po ./$(DEPDIR)/powerpanel.Po \ ./$(DEPDIR)/powervar-hid.Po \ ./$(DEPDIR)/powervar_cx_ser-powervar_cx.Po \ ./$(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Po \ ./$(DEPDIR)/powervar_cx_usb-libusb0.Po \ ./$(DEPDIR)/powervar_cx_usb-libusb1.Po \ ./$(DEPDIR)/powervar_cx_usb-powervar_cx.Po \ ./$(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Po \ ./$(DEPDIR)/powervar_cx_usb-usb-common.Po ./$(DEPDIR)/rhino.Po \ ./$(DEPDIR)/richcomm_usb.Po ./$(DEPDIR)/riello.Po \ ./$(DEPDIR)/riello_ser.Po ./$(DEPDIR)/riello_usb.Po \ ./$(DEPDIR)/safenet.Po ./$(DEPDIR)/salicru-hid.Po \ ./$(DEPDIR)/serial.Plo ./$(DEPDIR)/skel.Po \ ./$(DEPDIR)/sms_ser.Po ./$(DEPDIR)/snmp_ups-apc-ats-mib.Po \ ./$(DEPDIR)/snmp_ups-apc-epdu-mib.Po \ ./$(DEPDIR)/snmp_ups-apc-mib.Po \ ./$(DEPDIR)/snmp_ups-apc-pdu-mib.Po \ ./$(DEPDIR)/snmp_ups-baytech-mib.Po \ ./$(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Po \ ./$(DEPDIR)/snmp_ups-bestpower-mib.Po \ ./$(DEPDIR)/snmp_ups-compaq-mib.Po \ ./$(DEPDIR)/snmp_ups-cyberpower-mib.Po \ ./$(DEPDIR)/snmp_ups-delta_ups-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-ats30-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Po \ ./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Po \ ./$(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Po \ ./$(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Po \ ./$(DEPDIR)/snmp_ups-hpe-pdu-mib.Po \ ./$(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Po \ ./$(DEPDIR)/snmp_ups-huawei-mib.Po \ ./$(DEPDIR)/snmp_ups-ietf-mib.Po \ ./$(DEPDIR)/snmp_ups-mge-mib.Po \ ./$(DEPDIR)/snmp_ups-netvision-mib.Po \ ./$(DEPDIR)/snmp_ups-raritan-pdu-mib.Po \ ./$(DEPDIR)/snmp_ups-raritan-px2-mib.Po \ ./$(DEPDIR)/snmp_ups-snmp-ups-helpers.Po \ ./$(DEPDIR)/snmp_ups-snmp-ups.Po \ ./$(DEPDIR)/snmp_ups-xppc-mib.Po ./$(DEPDIR)/socomec_jbus.Po \ ./$(DEPDIR)/solis.Po ./$(DEPDIR)/tripplite-hid.Po \ ./$(DEPDIR)/tripplite.Po ./$(DEPDIR)/tripplite_usb.Po \ ./$(DEPDIR)/tripplitesu.Po ./$(DEPDIR)/upscode2.Po \ ./$(DEPDIR)/upsdrvctl.Po ./$(DEPDIR)/upsdrvquery.Plo \ ./$(DEPDIR)/usb-common.Po ./$(DEPDIR)/usbhid-ups.Po \ ./$(DEPDIR)/ve-direct.Po ./$(DEPDIR)/victronups.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(libdummy_la_SOURCES) $(libdummy_mockdrv_la_SOURCES) \ $(libdummy_serial_la_SOURCES) \ $(libdummy_upsdrvquery_la_SOURCES) \ $(libserial_nutscan_la_SOURCES) $(adelsystem_cbi_SOURCES) \ $(al175_SOURCES) $(apc_modbus_SOURCES) $(apcsmart_SOURCES) \ $(apcsmart_old_SOURCES) $(apcupsd_ups_SOURCES) $(asem_SOURCES) \ $(bcmxcp_SOURCES) $(bcmxcp_usb_SOURCES) $(belkin_SOURCES) \ $(belkinunv_SOURCES) $(bestfcom_SOURCES) \ $(bestfortress_SOURCES) $(bestuferrups_SOURCES) \ $(bestups_SOURCES) $(bicker_ser_SOURCES) $(blazer_ser_SOURCES) \ $(blazer_usb_SOURCES) $(clone_SOURCES) $(clone_outlet_SOURCES) \ $(dummy_ups_SOURCES) $(etapro_SOURCES) $(everups_SOURCES) \ $(failover_SOURCES) $(gamatronic_SOURCES) \ $(generic_gpio_libgpiod_SOURCES) $(generic_modbus_SOURCES) \ $(genericups_SOURCES) $(huawei_ups2000_SOURCES) \ $(hwmon_ina219_SOURCES) $(isbmex_SOURCES) $(ivtscd_SOURCES) \ $(liebert_SOURCES) $(liebert_esp2_SOURCES) \ $(liebert_gxe_SOURCES) $(macosx_ups_SOURCES) \ $(masterguard_SOURCES) $(metasys_SOURCES) $(mge_shut_SOURCES) \ $(mge_utalk_SOURCES) $(microdowell_SOURCES) \ $(microsol_apc_SOURCES) $(netxml_ups_SOURCES) \ $(nhs_ser_SOURCES) $(nut_ipmipsu_SOURCES) \ $(nutdrv_atcl_usb_SOURCES) $(nutdrv_hashx_SOURCES) \ $(nutdrv_qx_SOURCES) $(nutdrv_siemens_sitop_SOURCES) \ $(oneac_SOURCES) $(optiups_SOURCES) \ $(phoenixcontact_modbus_SOURCES) $(pijuice_SOURCES) \ $(powercom_SOURCES) $(powerman_pdu_SOURCES) \ $(powerpanel_SOURCES) $(powervar_cx_ser_SOURCES) \ $(powervar_cx_usb_SOURCES) $(rhino_SOURCES) \ $(richcomm_usb_SOURCES) $(riello_ser_SOURCES) \ $(riello_usb_SOURCES) $(safenet_SOURCES) $(skel_SOURCES) \ $(sms_ser_SOURCES) $(snmp_ups_SOURCES) $(socomec_jbus_SOURCES) \ $(solis_SOURCES) $(tripplite_SOURCES) $(tripplite_usb_SOURCES) \ $(tripplitesu_SOURCES) $(upscode2_SOURCES) \ $(upsdrvctl_SOURCES) $(usbhid_ups_SOURCES) \ $(ve_direct_SOURCES) $(victronups_SOURCES) DIST_SOURCES = $(libdummy_la_SOURCES) $(libdummy_mockdrv_la_SOURCES) \ $(libdummy_serial_la_SOURCES) \ $(libdummy_upsdrvquery_la_SOURCES) \ $(libserial_nutscan_la_SOURCES) $(adelsystem_cbi_SOURCES) \ $(al175_SOURCES) $(am__apc_modbus_SOURCES_DIST) \ $(apcsmart_SOURCES) $(apcsmart_old_SOURCES) \ $(apcupsd_ups_SOURCES) $(asem_SOURCES) $(bcmxcp_SOURCES) \ $(bcmxcp_usb_SOURCES) $(belkin_SOURCES) $(belkinunv_SOURCES) \ $(bestfcom_SOURCES) $(bestfortress_SOURCES) \ $(bestuferrups_SOURCES) $(bestups_SOURCES) \ $(bicker_ser_SOURCES) $(blazer_ser_SOURCES) \ $(am__blazer_usb_SOURCES_DIST) $(clone_SOURCES) \ $(clone_outlet_SOURCES) $(dummy_ups_SOURCES) $(etapro_SOURCES) \ $(everups_SOURCES) $(failover_SOURCES) $(gamatronic_SOURCES) \ $(generic_gpio_libgpiod_SOURCES) $(generic_modbus_SOURCES) \ $(genericups_SOURCES) $(huawei_ups2000_SOURCES) \ $(hwmon_ina219_SOURCES) $(isbmex_SOURCES) $(ivtscd_SOURCES) \ $(liebert_SOURCES) $(liebert_esp2_SOURCES) \ $(liebert_gxe_SOURCES) $(macosx_ups_SOURCES) \ $(masterguard_SOURCES) $(metasys_SOURCES) $(mge_shut_SOURCES) \ $(mge_utalk_SOURCES) $(microdowell_SOURCES) \ $(microsol_apc_SOURCES) $(netxml_ups_SOURCES) \ $(nhs_ser_SOURCES) $(am__nut_ipmipsu_SOURCES_DIST) \ $(nutdrv_atcl_usb_SOURCES) $(nutdrv_hashx_SOURCES) \ $(am__nutdrv_qx_SOURCES_DIST) $(nutdrv_siemens_sitop_SOURCES) \ $(oneac_SOURCES) $(optiups_SOURCES) \ $(phoenixcontact_modbus_SOURCES) $(pijuice_SOURCES) \ $(powercom_SOURCES) $(powerman_pdu_SOURCES) \ $(powerpanel_SOURCES) $(powervar_cx_ser_SOURCES) \ $(am__powervar_cx_usb_SOURCES_DIST) $(rhino_SOURCES) \ $(am__richcomm_usb_SOURCES_DIST) $(riello_ser_SOURCES) \ $(am__riello_usb_SOURCES_DIST) $(safenet_SOURCES) \ $(skel_SOURCES) $(sms_ser_SOURCES) $(snmp_ups_SOURCES) \ $(socomec_jbus_SOURCES) $(solis_SOURCES) $(tripplite_SOURCES) \ $(am__tripplite_usb_SOURCES_DIST) $(tripplitesu_SOURCES) \ $(upscode2_SOURCES) $(upsdrvctl_SOURCES) \ $(am__usbhid_ups_SOURCES_DIST) $(ve_direct_SOURCES) \ $(victronups_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac HEADERS = $(dist_noinst_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) A2X = @A2X@ ACLOCAL = @ACLOCAL@ ALTPIDPATH = @ALTPIDPATH@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ ASCIIDOC = @ASCIIDOC@ ASCIIDOC_LINKMANEXT_SECTION_REWRITE = @ASCIIDOC_LINKMANEXT_SECTION_REWRITE@ ASCIIDOC_TEMPLATE_LINKMANEXT = @ASCIIDOC_TEMPLATE_LINKMANEXT@ ASCIIDOC_TEMPLATE_LINKMANEXT2 = @ASCIIDOC_TEMPLATE_LINKMANEXT2@ ASPELL = @ASPELL@ ASPELL_FILTER_LIB_PATH = @ASPELL_FILTER_LIB_PATH@ ASPELL_FILTER_SHARE_PATH = @ASPELL_FILTER_SHARE_PATH@ ASPELL_FILTER_TEX_PATH = @ASPELL_FILTER_TEX_PATH@ AUGPARSE = @AUGPARSE@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BINDIR = @BINDIR@ BSDKVMPROCLIBS = @BSDKVMPROCLIBS@ CC = @CC@ CCACHE_BASEDIR = @CCACHE_BASEDIR@ CCACHE_DIR = @CCACHE_DIR@ CCACHE_NAMESPACE = @CCACHE_NAMESPACE@ CCACHE_PATH = @CCACHE_PATH@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CONFIG_CFLAGS = @CONFIG_CFLAGS@ CONFIG_CPPFLAGS = @CONFIG_CPPFLAGS@ CONFIG_CXXFLAGS = @CONFIG_CXXFLAGS@ CONFIG_FLAGS = @CONFIG_FLAGS@ CONFIG_LDFLAGS = @CONFIG_LDFLAGS@ CONFPATH = @CONFPATH@ CPP = @CPP@ CPPCHECK = @CPPCHECK@ CPPFLAGS = @CPPFLAGS@ CPPUNIT_CFLAGS = @CPPUNIT_CFLAGS@ CPPUNIT_LIBS = @CPPUNIT_LIBS@ CPPUNIT_NUT_CXXFLAGS = @CPPUNIT_NUT_CXXFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH = @CYGPATH@ CYGPATH_W = @CYGPATH_W@ DBLATEX = @DBLATEX@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DEPLOYED_DUMMYUPS = @DEPLOYED_DUMMYUPS@ DEPLOYED_UPSC = @DEPLOYED_UPSC@ DEPLOYED_UPSD = @DEPLOYED_UPSD@ DEPLOYED_UPSIMAGE = @DEPLOYED_UPSIMAGE@ DLLTOOL = @DLLTOOL@ DOC_BUILD_LIST = @DOC_BUILD_LIST@ DOC_CHECK_LIST = @DOC_CHECK_LIST@ DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@ DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@ DRIVER_MAN_LIST = @DRIVER_MAN_LIST@ DRIVER_MAN_LIST_PAGES = @DRIVER_MAN_LIST_PAGES@ DRVPATH = @DRVPATH@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ FORCE_NUT_VERSION = @FORCE_NUT_VERSION@ GDLIB_CONFIG = @GDLIB_CONFIG@ GETENT = @GETENT@ GITLOG_END_POINT = @GITLOG_END_POINT@ GITLOG_START_POINT = @GITLOG_START_POINT@ GREP = @GREP@ HAVE_SYS_SOCKET_H = @HAVE_SYS_SOCKET_H@ HAVE_WINSOCK2_H = @HAVE_WINSOCK2_H@ HAVE_WS2TCPIP_H = @HAVE_WS2TCPIP_H@ ID = @ID@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDD = @LDD@ LDFLAGS = @LDFLAGS@ LDFLAGS_NUT_RPATH = @LDFLAGS_NUT_RPATH@ LDFLAGS_NUT_RPATH_CXX = @LDFLAGS_NUT_RPATH_CXX@ LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@ LIBAVAHI_LIBS = @LIBAVAHI_LIBS@ LIBDIR = @LIBDIR@ LIBGD_CFLAGS = @LIBGD_CFLAGS@ LIBGD_LDFLAGS = @LIBGD_LDFLAGS@ LIBGPIO_CFLAGS = @LIBGPIO_CFLAGS@ LIBGPIO_LIBS = @LIBGPIO_LIBS@ LIBI2C_LIBS = @LIBI2C_LIBS@ LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@ LIBIPMI_LIBS = @LIBIPMI_LIBS@ LIBLTDL_CFLAGS = @LIBLTDL_CFLAGS@ LIBLTDL_LIBS = @LIBLTDL_LIBS@ LIBMODBUS_CFLAGS = @LIBMODBUS_CFLAGS@ LIBMODBUS_LIBS = @LIBMODBUS_LIBS@ LIBNEON_CFLAGS = @LIBNEON_CFLAGS@ LIBNEON_LIBS = @LIBNEON_LIBS@ LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@ LIBNETSNMP_LIBS = @LIBNETSNMP_LIBS@ LIBOBJS = @LIBOBJS@ LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@ LIBPOWERMAN_LIBS = @LIBPOWERMAN_LIBS@ LIBREGEX_LIBS = @LIBREGEX_LIBS@ LIBS = @LIBS@ LIBSSL_CFLAGS = @LIBSSL_CFLAGS@ LIBSSL_LDFLAGS_RPATH = @LIBSSL_LDFLAGS_RPATH@ LIBSSL_LIBS = @LIBSSL_LIBS@ LIBSSL_REQUIRES = @LIBSSL_REQUIRES@ LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@ LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@ LIBTOOL = @LIBTOOL@ LIBTOOL_DEPS = @LIBTOOL_DEPS@ LIBUSB_CFLAGS = @LIBUSB_CFLAGS@ LIBUSB_CONFIG = @LIBUSB_CONFIG@ LIBUSB_LIBS = @LIBUSB_LIBS@ LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@ LIBWRAP_LIBS = @LIBWRAP_LIBS@ LIPO = @LIPO@ LN_S = @LN_S@ LN_S_R = @LN_S_R@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MAN_DIR_AS_BASE = @MAN_DIR_AS_BASE@ MAN_SECTION_API = @MAN_SECTION_API@ MAN_SECTION_API_BASE = @MAN_SECTION_API_BASE@ MAN_SECTION_CFG = @MAN_SECTION_CFG@ MAN_SECTION_CFG_BASE = @MAN_SECTION_CFG_BASE@ MAN_SECTION_CMD_SYS = @MAN_SECTION_CMD_SYS@ MAN_SECTION_CMD_SYS_BASE = @MAN_SECTION_CMD_SYS_BASE@ MAN_SECTION_CMD_USR = @MAN_SECTION_CMD_USR@ MAN_SECTION_CMD_USR_BASE = @MAN_SECTION_CMD_USR_BASE@ MAN_SECTION_MISC = @MAN_SECTION_MISC@ MAN_SECTION_MISC_BASE = @MAN_SECTION_MISC_BASE@ MKDIR_P = @MKDIR_P@ MSGFMT = @MSGFMT@ NETLIBS = @NETLIBS@ NETLIBS_GETADDRS = @NETLIBS_GETADDRS@ NET_SNMP_CONFIG = @NET_SNMP_CONFIG@ NM = @NM@ NMEDIT = @NMEDIT@ NUT_AM_EXPORT_CCACHE_BASEDIR = @NUT_AM_EXPORT_CCACHE_BASEDIR@ NUT_AM_EXPORT_CCACHE_DIR = @NUT_AM_EXPORT_CCACHE_DIR@ NUT_AM_EXPORT_CCACHE_NAMESPACE = @NUT_AM_EXPORT_CCACHE_NAMESPACE@ NUT_AM_EXPORT_CCACHE_PATH = @NUT_AM_EXPORT_CCACHE_PATH@ NUT_AM_MAKE_CAN_EXPORT = @NUT_AM_MAKE_CAN_EXPORT@ NUT_CONFIG_CFLAGS = @NUT_CONFIG_CFLAGS@ NUT_CONFIG_CPPFLAGS = @NUT_CONFIG_CPPFLAGS@ NUT_CONFIG_CXXFLAGS = @NUT_CONFIG_CXXFLAGS@ NUT_CONFIG_LDFLAGS = @NUT_CONFIG_LDFLAGS@ NUT_DATADIR = @NUT_DATADIR@ NUT_LIBEXECDIR = @NUT_LIBEXECDIR@ NUT_MANDIR = @NUT_MANDIR@ NUT_NETVERSION = @NUT_NETVERSION@ NUT_SOURCE_GITREV = @NUT_SOURCE_GITREV@ NUT_SOURCE_GITREV_IS_PRERELEASE = @NUT_SOURCE_GITREV_IS_PRERELEASE@ NUT_SOURCE_GITREV_IS_RELEASE = @NUT_SOURCE_GITREV_IS_RELEASE@ NUT_SOURCE_GITREV_NUMERIC = @NUT_SOURCE_GITREV_NUMERIC@ NUT_SOURCE_GITREV_SEMVER = @NUT_SOURCE_GITREV_SEMVER@ NUT_WEBSITE_BASE = @NUT_WEBSITE_BASE@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OS_NAME = @OS_NAME@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_DURING_CONFIGURE = @PATH_DURING_CONFIGURE@ PATH_SEPARATOR = @PATH_SEPARATOR@ PIDPATH = @PIDPATH@ PKGCONFIGDIR = @PKGCONFIGDIR@ PKG_CONFIG = @PKG_CONFIG@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PORT = @PORT@ POWERDOWNFLAG = @POWERDOWNFLAG@ PREFIX = @PREFIX@ PWDTOOL = @PWDTOOL@ PYTHON = @PYTHON@ PYTHON2 = @PYTHON2@ PYTHON2_SITE_PACKAGES = @PYTHON2_SITE_PACKAGES@ PYTHON3 = @PYTHON3@ PYTHON3_SITE_PACKAGES = @PYTHON3_SITE_PACKAGES@ PYTHON_SITE_PACKAGES = @PYTHON_SITE_PACKAGES@ RANLIB = @RANLIB@ REALPATH = @REALPATH@ RUN_AS_GROUP = @RUN_AS_GROUP@ RUN_AS_USER = @RUN_AS_USER@ SBINDIR = @SBINDIR@ SED = @SED@ SEMLIBS = @SEMLIBS@ SERLIBS = @SERLIBS@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ SOURCE_HIGHLIGHT = @SOURCE_HIGHLIGHT@ STATEPATH = @STATEPATH@ STRIP = @STRIP@ SUN_LIBUSB = @SUN_LIBUSB@ SYSTEMCTL = @SYSTEMCTL@ SYSTEMD_ANALYZE_PROGRAM = @SYSTEMD_ANALYZE_PROGRAM@ SYSTEMD_DAEMON_ARGS_DRIVER = @SYSTEMD_DAEMON_ARGS_DRIVER@ SYSTEMD_DAEMON_ARGS_UPSD = @SYSTEMD_DAEMON_ARGS_UPSD@ SYSTEMD_DAEMON_ARGS_UPSLOG = @SYSTEMD_DAEMON_ARGS_UPSLOG@ SYSTEMD_DAEMON_ARGS_UPSMON = @SYSTEMD_DAEMON_ARGS_UPSMON@ SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER = @SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSD = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSD@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG@ SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON = @SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON@ SYSTEMD_DAEMON_TYPE_DRIVER = @SYSTEMD_DAEMON_TYPE_DRIVER@ SYSTEMD_DAEMON_TYPE_UPSD = @SYSTEMD_DAEMON_TYPE_UPSD@ SYSTEMD_DAEMON_TYPE_UPSLOG = @SYSTEMD_DAEMON_TYPE_UPSLOG@ SYSTEMD_DAEMON_TYPE_UPSMON = @SYSTEMD_DAEMON_TYPE_UPSMON@ SYSTEMD_DAEMON_WATCHDOG_DRIVER = @SYSTEMD_DAEMON_WATCHDOG_DRIVER@ SYSTEMD_DAEMON_WATCHDOG_UPSD = @SYSTEMD_DAEMON_WATCHDOG_UPSD@ SYSTEMD_DAEMON_WATCHDOG_UPSLOG = @SYSTEMD_DAEMON_WATCHDOG_UPSLOG@ SYSTEMD_DAEMON_WATCHDOG_UPSMON = @SYSTEMD_DAEMON_WATCHDOG_UPSMON@ SYSTEMD_SYSTEMCTL_PROGRAM = @SYSTEMD_SYSTEMCTL_PROGRAM@ SYSTEMD_TMPFILES_PROGRAM = @SYSTEMD_TMPFILES_PROGRAM@ TREE_VERSION = @TREE_VERSION@ VALGRIND = @VALGRIND@ VERSION = @VERSION@ WINDMC = @WINDMC@ WINDRES = @WINDRES@ WORDS_BIGENDIAN = @WORDS_BIGENDIAN@ XMLLINT = @XMLLINT@ XSLTPROC = @XSLTPROC@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_DLLTOOL = @ac_ct_DLLTOOL@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ ac_ct_LD = @ac_ct_LD@ ac_ct_OBJDUMP = @ac_ct_OBJDUMP@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ auglensdir = @auglensdir@ auglenstestsdir = @auglenstestsdir@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ cgiexecdir = @cgiexecdir@ datadir = @datadir@ datarootdir = @datarootdir@ devddir = @devddir@ docdir = @docdir@ driverexecdir = @driverexecdir@ dummy_PKG_CONFIG = @dummy_PKG_CONFIG@ dummy_PKG_CONFIG_CFLAGS = @dummy_PKG_CONFIG_CFLAGS@ dummy_PKG_CONFIG_LIBS = @dummy_PKG_CONFIG_LIBS@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ freebsdquirksdir = @freebsdquirksdir@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ hotplugdir = @hotplugdir@ htmldir = @htmldir@ htmldocdir = @htmldocdir@ htmlmandir = @htmlmandir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ now = @now@ nut_with_nut_monitor = @nut_with_nut_monitor@ nut_with_nut_monitor_desktop = @nut_with_nut_monitor_desktop@ nut_with_nut_monitor_dir = @nut_with_nut_monitor_dir@ nut_with_nut_monitor_py2gtk2 = @nut_with_nut_monitor_py2gtk2@ nut_with_nut_monitor_py3qt5 = @nut_with_nut_monitor_py3qt5@ nut_with_nut_monitor_py3qt6 = @nut_with_nut_monitor_py3qt6@ nut_with_pynut = @nut_with_pynut@ nut_with_pynut_py = @nut_with_pynut_py@ nut_with_pynut_py2 = @nut_with_pynut_py2@ nut_with_pynut_py3 = @nut_with_pynut_py3@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ pkgconfigdir = @pkgconfigdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ systemdshutdowndir = @systemdshutdowndir@ systemdsystempresetdir = @systemdsystempresetdir@ systemdsystemunitdir = @systemdsystemunitdir@ systemdtmpfilesdir = @systemdtmpfilesdir@ target = @target@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ udevdir = @udevdir@ # by default, link programs in this directory with libcommon.la # (libtool version of the static lib, in order to access LTLIBOBJS) #FIXME: SERLIBS is only useful for LDADD_DRIVERS_SERIAL not for LDADD_COMMON LDADD_COMMON = \ $(top_builddir)/common/libcommon.la \ $(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libparseconf.la LDADD_DRIVERS = libdummy.la libdummy_upsdrvquery.la $(LDADD_COMMON) LDADD_DRIVERS_SERIAL = libdummy_serial.la $(LDADD_DRIVERS) $(SERLIBS) # most targets are serial drivers, so make this the default LDADD = $(LDADD_DRIVERS_SERIAL) # Avoid per-target CFLAGS, because this will prevent re-use of object # files. In any case, CFLAGS are only -I options, so there is no harm, # but only add them if we really use the target. AM_CFLAGS = -I$(top_srcdir)/include $(am__append_1) $(am__append_2) \ $(am__append_3) $(am__append_4) $(am__append_5) \ $(am__append_6) $(am__append_7) # Allow top-level Makefile override NUTSW_DRIVERLIST_DUMMY_UPS="dummy" to run # a build scenario without this driver (it is in a different dependency) # NOTE: Must be defaulted with EXEEXT to avoid rewrites by automake parser # which defeat the purpose of it being optionally built via `make all/drivers` # in top level. NUTSW_DRIVERLIST_DUMMY_UPS = dummy-ups$(EXEEXT) NUTSW_DRIVERLIST = $(NUTSW_DRIVERLIST_DUMMY_UPS) \ clone clone-outlet failover apcupsd-ups skel SERIAL_DRIVERLIST = al175 bcmxcp belkin belkinunv bestfcom \ bestfortress bestuferrups bestups etapro everups gamatronic \ genericups isbmex liebert liebert-esp2 liebert-gxe masterguard \ metasys mge-utalk microdowell microsol-apc mge-shut \ nutdrv_hashx oneac optiups powercom powervar_cx_ser rhino \ safenet nutdrv_siemens-sitop solis tripplite tripplitesu \ upscode2 victronups powerpanel blazer_ser ivtscd apcsmart \ apcsmart-old riello_ser sms_ser bicker_ser ve-direct \ $(am__append_8) SNMP_DRIVERLIST = snmp-ups USB_LIBUSB_DRIVERLIST = usbhid-ups bcmxcp_usb tripplite_usb \ blazer_usb richcomm_usb riello_usb powervar_cx_usb \ nutdrv_atcl_usb USB_DRIVERLIST = $(USB_LIBUSB_DRIVERLIST) SERIAL_USB_DRIVERLIST = \ nutdrv_qx NEONXML_DRIVERLIST = netxml-ups MACOSX_DRIVERLIST = macosx-ups MODBUS_DRIVERLIST = phoenixcontact_modbus generic_modbus huawei-ups2000 socomec_jbus adelsystem_cbi apc_modbus LINUX_I2C_DRIVERLIST = asem pijuice hwmon_ina219 POWERMAN_DRIVERLIST = powerman-pdu IPMI_DRIVERLIST = nut-ipmipsu GPIO_DRIVERLIST = generic_gpio_libgpiod # ========================================================================== # Driver build details # upsdrvctl: the all-singing all-dancing driver control program upsdrvctl_SOURCES = upsdrvctl.c upsdrvctl_LDADD = $(LDADD_COMMON) libdummy_upsdrvquery.la # serial drivers: all of them use standard LDADD and CFLAGS al175_SOURCES = al175.c apcsmart_SOURCES = apcsmart.c apcsmart_tabs.c apcsmart_LDADD = $(LDADD) $(LIBREGEX_LIBS) apcsmart_old_SOURCES = apcsmart-old.c bcmxcp_SOURCES = bcmxcp.c bcmxcp_ser.c bcmxcp_LDADD = $(LDADD) -lm belkin_SOURCES = belkin.c belkinunv_SOURCES = belkinunv.c bestfcom_SOURCES = bestfcom.c bestfortress_SOURCES = bestfortress.c bestuferrups_SOURCES = bestuferrups.c bestups_SOURCES = bestups.c blazer_ser_SOURCES = blazer.c blazer_ser.c blazer_ser_LDADD = $(LDADD) -lm etapro_SOURCES = etapro.c everups_SOURCES = everups.c gamatronic_SOURCES = gamatronic.c genericups_SOURCES = genericups.c isbmex_SOURCES = isbmex.c isbmex_LDADD = $(LDADD) -lm ivtscd_SOURCES = ivtscd.c liebert_SOURCES = liebert.c liebert_esp2_SOURCES = liebert-esp2.c liebert_gxe_SOURCES = liebert-gxe.c masterguard_SOURCES = masterguard.c metasys_SOURCES = metasys.c metasys_LDADD = $(LDADD) -lm mge_utalk_SOURCES = mge-utalk.c microdowell_SOURCES = microdowell.c microsol_apc_SOURCES = microsol-apc.c microsol-common.c microsol_apc_LDADD = $(LDADD) -lm nhs_ser_SOURCES = nhs_ser.c nhs_ser_LDADD = $(LDADD) -lm nutdrv_hashx_SOURCES = nutdrv_hashx.c nutdrv_hashx_LDADD = $(LDADD) -lm oneac_SOURCES = oneac.c optiups_SOURCES = optiups.c powercom_SOURCES = powercom.c powercom_LDADD = $(LDADD) -lm powerpanel_SOURCES = powerpanel.c powerp-bin.c powerp-txt.c powerpanel_LDADD = $(LDADD) -lm powervar_cx_ser_SOURCES = powervar_cx_ser.c powervar_cx.c powervar_cx_ser_CFLAGS = $(AM_CFLAGS) -DPVAR_SERIAL=1 rhino_SOURCES = rhino.c rhino_LDADD = $(LDADD) -lm safenet_SOURCES = safenet.c nutdrv_siemens_sitop_SOURCES = nutdrv_siemens_sitop.c solis_SOURCES = solis.c solis_LDADD = $(LDADD) -lm tripplite_SOURCES = tripplite.c tripplite_LDADD = $(LDADD) -lm tripplitesu_SOURCES = tripplitesu.c upscode2_SOURCES = upscode2.c upscode2_LDADD = $(LDADD) -lm victronups_SOURCES = victronups.c riello_ser_SOURCES = riello.c riello_ser.c riello_ser_LDADD = $(LDADD) -lm sms_ser_SOURCES = sms_ser.c sms_ser_LDADD = $(LDADD) -lm bicker_ser_SOURCES = bicker_ser.c bicker_ser_LDADD = $(LDADD) -lm ve_direct_SOURCES = ve-direct.c ve_direct_LDADD = $(LDADD) -lm # non-serial drivers: these use custom LDADD and/or CFLAGS # dummy (in NUTSW_DRIVERLIST) dummy_ups_SOURCES = dummy-ups.c dummy_ups_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/clients \ $(am__append_20) dummy_ups_LDADD = $(LDADD_DRIVERS) \ $(top_builddir)/clients/libupsclient.la $(am__append_21) dummy_ups_LDFLAGS = $(AM_LDFLAGS) $(am__append_22) # Clone drivers (in NUTSW_DRIVERLIST) clone_SOURCES = clone.c clone_outlet_SOURCES = clone-outlet.c # failover driver (in NUTSW_DRIVERLIST) failover_SOURCES = failover.c # apcupsd client driver (in NUTSW_DRIVERLIST) apcupsd_ups_SOURCES = apcupsd-ups.c apcupsd_ups_CFLAGS = $(AM_CFLAGS) apcupsd_ups_LDADD = $(LDADD_DRIVERS) # sample skeleton driver (in NUTSW_DRIVERLIST) skel_SOURCES = skel.c skel_LDADD = $(LDADD_DRIVERS) # USB @WITH_LIBUSB_0_1_TRUE@LIBUSB_IMPL = libusb0.c @WITH_LIBUSB_1_0_TRUE@LIBUSB_IMPL = libusb1.c USBHID_UPS_SUBDRIVERS = apc-hid.c arduino-hid.c belkin-hid.c cps-hid.c explore-hid.c \ liebert-hid.c mge-hid.c powercom-hid.c tripplite-hid.c idowell-hid.c \ openups-hid.c powervar-hid.c delta_ups-hid.c ecoflow-hid.c ever-hid.c \ legrand-hid.c salicru-hid.c usbhid_ups_SOURCES = usbhid-ups.c libhid.c $(LIBUSB_IMPL) hidparser.c \ usb-common.c $(USBHID_UPS_SUBDRIVERS) usbhid_ups_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm powervar_cx_usb_SOURCES = powervar_cx_usb.c powervar_cx.c $(LIBUSB_IMPL) usb-common.c powervar_cx_usb_CFLAGS = $(AM_CFLAGS) -DPVAR_USB=1 powervar_cx_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm tripplite_usb_SOURCES = tripplite_usb.c $(LIBUSB_IMPL) usb-common.c tripplite_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm bcmxcp_usb_SOURCES = bcmxcp_usb.c bcmxcp.c usb-common.c bcmxcp_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm blazer_usb_SOURCES = blazer.c blazer_usb.c $(LIBUSB_IMPL) usb-common.c blazer_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm nutdrv_atcl_usb_SOURCES = nutdrv_atcl_usb.c usb-common.c nutdrv_atcl_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) richcomm_usb_SOURCES = richcomm_usb.c $(LIBUSB_IMPL) usb-common.c richcomm_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) riello_usb_SOURCES = riello.c riello_usb.c $(LIBUSB_IMPL) usb-common.c riello_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm # HID-over-serial mge_shut_SOURCES = usbhid-ups.c libshut.c libhid.c hidparser.c mge-hid.c # per-target CFLAGS are necessary here mge_shut_CFLAGS = $(AM_CFLAGS) -DSHUT_MODE=1 mge_shut_LDADD = $(LDADD) -lm # SNMP # Please keep the MIB table below sorted roughly alphabetically (incidentally # by vendor too) to ease maintenance and codebase fork resynchronisations snmp_ups_SOURCES = snmp-ups.c snmp-ups-helpers.c \ apc-mib.c apc-pdu-mib.c apc-epdu-mib.c \ baytech-mib.c baytech-rpc3nc-mib.c bestpower-mib.c \ compaq-mib.c cyberpower-mib.c \ delta_ups-mib.c \ eaton-pdu-genesis2-mib.c eaton-pdu-marlin-mib.c eaton-pdu-marlin-helpers.c \ eaton-pdu-pulizzi-mib.c eaton-pdu-revelation-mib.c eaton-pdu-nlogic-mib.c \ eaton-ats16-nmc-mib.c eaton-ats16-nm2-mib.c apc-ats-mib.c eaton-ats30-mib.c \ eaton-ups-pwnm2-mib.c eaton-ups-pxg-mib.c \ emerson-avocent-pdu-mib.c \ hpe-pdu-mib.c hpe-pdu3-cis-mib.c huawei-mib.c \ ietf-mib.c \ mge-mib.c \ netvision-mib.c \ raritan-pdu-mib.c raritan-px2-mib.c \ xppc-mib.c snmp_ups_CFLAGS = $(AM_CFLAGS) $(LIBNETSNMP_CFLAGS) $(am__append_23) \ $(am__append_24) snmp_ups_LDADD = $(LDADD_DRIVERS) $(LIBNETSNMP_LIBS) -lm \ $(am__append_25) snmp_ups_LDFLAGS = $(AM_LDFLAGS) $(am__append_26) # NEON XML/HTTP netxml_ups_SOURCES = netxml-ups.c mge-xml.c netxml_ups_LDADD = $(LDADD_DRIVERS) $(LIBNEON_LIBS) $(am__append_28) netxml_ups_CFLAGS = $(AM_CFLAGS) $(am__append_27) netxml_ups_LDFLAGS = $(AM_LDFLAGS) $(am__append_29) # Powerman powerman_pdu_SOURCES = powerman-pdu.c powerman_pdu_LDADD = $(LDADD) $(LIBPOWERMAN_LIBS) # IPMI PSU nut_ipmipsu_SOURCES = nut-ipmipsu.c $(am__append_30) # FIXME: Hacky hot-fix for build agents of varying OS generations: # Different versions of IPMI libs requested 'unsigned int *' or 'int *' args: #nut_ipmipsu_CFLAGS = $(AM_CFLAGS) -Wno-pointer-sign nut_ipmipsu_LDADD = $(LDADD) $(LIBIPMI_LIBS) # Mac OS X metadriver macosx_ups_LDADD = $(LDADD_DRIVERS) macosx_ups_LDFLAGS = $(LDFLAGS) -framework IOKit -framework CoreFoundation macosx_ups_SOURCES = macosx-ups.c # Modbus drivers phoenixcontact_modbus_SOURCES = phoenixcontact_modbus.c phoenixcontact_modbus_LDADD = $(LDADD_DRIVERS) $(LIBMODBUS_LIBS) generic_modbus_SOURCES = generic_modbus.c generic_modbus_LDADD = $(LDADD_DRIVERS) $(LIBMODBUS_LIBS) adelsystem_cbi_SOURCES = adelsystem_cbi.c adelsystem_cbi_LDADD = $(LDADD_DRIVERS) $(LIBMODBUS_LIBS) # APC Modbus driver (with support of modbus over different media) # Note that a version of libmodbus built with USB support is also needed # for USB connections. Legacy versions work for Serial and TCP links. apc_modbus_SOURCES = apc_modbus.c $(am__append_31) apc_modbus_LDADD = $(LDADD_DRIVERS) $(LIBMODBUS_LIBS) $(am__append_32) # Huawei UPS2000 driver # (this is both a Modbus and a serial driver) huawei_ups2000_SOURCES = huawei-ups2000.c huawei_ups2000_LDADD = $(LDADD_DRIVERS_SERIAL) $(LIBMODBUS_LIBS) # Socomec JBUS driver # (this is a Modbus driver) socomec_jbus_SOURCES = socomec_jbus.c socomec_jbus_LDADD = $(LDADD_DRIVERS_SERIAL) $(LIBMODBUS_LIBS) # Linux I2C drivers asem_LDADD = $(LDADD_DRIVERS) $(LIBI2C_LIBS) asem_SOURCES = asem.c pijuice_LDADD = $(LDADD_DRIVERS) $(LIBI2C_LIBS) pijuice_SOURCES = pijuice.c hwmon_ina219_LDADD = $(LDADD_DRIVERS) hwmon_ina219_SOURCES = hwmon_ina219.c # GPIO drivers generic_gpio_libgpiod_SOURCES = generic_gpio_common.c generic_gpio_libgpiod.c generic_gpio_libgpiod_LDADD = $(LDADD_DRIVERS) $(LIBGPIO_LIBS) # nutdrv_qx USB/Serial nutdrv_qx_SOURCES = nutdrv_qx.c $(am__append_36) \ $(NUTDRV_QX_SUBDRIVERS) nutdrv_qx_LDADD = $(LDADD_DRIVERS) -lm $(am__append_34) \ $(am__append_37) nutdrv_qx_CFLAGS = $(AM_CFLAGS) $(am__append_33) $(am__append_35) NUTDRV_QX_SUBDRIVERS = \ nutdrv_qx_bestups.c nutdrv_qx_blazer-common.c \ nutdrv_qx_innovart31.c \ nutdrv_qx_innovart33.c \ nutdrv_qx_masterguard.c \ nutdrv_qx_mecer.c nutdrv_qx_megatec.c nutdrv_qx_megatec-old.c \ nutdrv_qx_mustek.c nutdrv_qx_q1.c nutdrv_qx_q2.c nutdrv_qx_q6.c \ nutdrv_qx_voltronic.c common_voltronic-crc.c \ nutdrv_qx_voltronic-axpert.c nutdrv_qx_voltronic-qs.c nutdrv_qx_voltronic-qs-hex.c \ nutdrv_qx_zinto.c \ nutdrv_qx_hunnox.c nutdrv_qx_ablerex.c nutdrv_qx_gtec.c # ---------------------------------------------------------------------- # List of header files. The purpose of this list is not dependency # tracking (which is automatic), but to ensure these files are # distributed by "make dist". dist_noinst_HEADERS = \ apc_modbus.h apc-mib.h apc-iem-mib.h apc-hid.h arduino-hid.h baytech-mib.h baytech-rpc3nc-mib.h bcmxcp.h bcmxcp_ser.h \ bcmxcp_io.h belkin.h belkin-hid.h bestpower-mib.h blazer.h cps-hid.h dstate.h \ dummy-ups.h explore-hid.h failover.h gamatronic.h genericups.h \ generic_gpio_common.h generic_gpio_libgpiod.h \ hidparser.h hidtypes.h ietf-mib.h libhid.h libshut.h nut_libusb.h liebert-hid.h \ main.h mge-hid.h mge-mib.h mge-utalk.h \ mge-xml.h microdowell.h microsol-apc.h microsol-common.h netvision-mib.h netxml-ups.h nut-ipmi.h oneac.h \ powercom.h powerpanel.h powerp-bin.h powerp-txt.h powervar_cx.h raritan-pdu-mib.h \ safenet.h serial.h sms_ser.h snmp-ups.h solis.h tripplite.h tripplite-hid.h \ upshandler.h usb-common.h usbhid-ups.h powercom-hid.h compaq-mib.h idowell-hid.h \ apcsmart.h apcsmart_tabs.h apcsmart-old.h apcupsd-ups.h cyberpower-mib.h riello.h openups-hid.h \ delta_ups-mib.h nutdrv_qx.h nutdrv_qx_bestups.h nutdrv_qx_blazer-common.h \ nutdrv_qx_gtec.h nutdrv_qx_innovart31.h nutdrv_qx_innovart33.h nutdrv_qx_masterguard.h nutdrv_qx_mecer.h nutdrv_qx_ablerex.h \ nutdrv_qx_megatec.h nutdrv_qx_megatec-old.h nutdrv_qx_mustek.h nutdrv_qx_q1.h nutdrv_qx_q2.h nutdrv_qx_q6.h nutdrv_qx_hunnox.h \ nutdrv_qx.h common_voltronic-crc.h nutdrv_qx_voltronic.h \ nutdrv_qx_voltronic-axpert.h nutdrv_qx_voltronic-qs.h nutdrv_qx_voltronic-qs-hex.h \ nutdrv_qx_zinto.h \ upsdrvquery.h \ xppc-mib.h huawei-mib.h eaton-ats16-nmc-mib.h eaton-ats16-nm2-mib.h apc-ats-mib.h raritan-px2-mib.h eaton-ats30-mib.h \ apc-pdu-mib.h apc-epdu-mib.h ecoflow-hid.h ever-hid.h eaton-pdu-genesis2-mib.h eaton-pdu-marlin-mib.h eaton-pdu-marlin-helpers.h \ eaton-pdu-pulizzi-mib.h eaton-pdu-revelation-mib.h emerson-avocent-pdu-mib.h eaton-ups-pwnm2-mib.h eaton-ups-pxg-mib.h legrand-hid.h \ hpe-pdu-mib.h hpe-pdu3-cis-mib.h powervar-hid.h delta_ups-hid.h generic_modbus.h salicru-hid.h adelsystem_cbi.h eaton-pdu-nlogic-mib.h ydn23.h # Define a dummy library so that Automake builds rules for the # corresponding object files. This library is not actually built, # as a final product. It was necessary for Automake-technical reasons, # because per-object CFLAGS can only be specified for libraries, not # for object files. This library is used during the build process, # and is not meant to be installed. # The libdummy_mockdrv.la is used for unit-tests to mock a driver # with near-production codebase but without its standard main(). # Otherwise, also not meant to be installed. EXTRA_LTLIBRARIES = libdummy.la libdummy_serial.la \ libdummy_upsdrvquery.la libdummy_mockdrv.la libdummy_la_SOURCES = main.c dstate.c libdummy_la_LDFLAGS = -no-undefined -static libdummy_serial_la_SOURCES = serial.c libdummy_serial_la_LDFLAGS = -no-undefined -static libdummy_upsdrvquery_la_SOURCES = upsdrvquery.c libdummy_upsdrvquery_la_LDFLAGS = -no-undefined -static libdummy_mockdrv_la_SOURCES = main.c dstate.c libdummy_mockdrv_la_CFLAGS = $(AM_CFLAGS) -DDRIVERS_MAIN_WITHOUT_MAIN=1 libdummy_mockdrv_la_LIBADD = \ $(top_builddir)/common/libcommon.la \ $(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libparseconf.la libdummy_mockdrv_la_LDFLAGS = -static # Also define a library with serial-port UPS routines needed for nut-scanner noinst_LTLIBRARIES = libserial-nutscan.la libserial_nutscan_la_SOURCES = serial.c bcmxcp_ser.c libserial_nutscan_la_LDFLAGS = libserial_nutscan_la_LIBADD = $(SERLIBS) libserial_nutscan_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/clients -I$(top_srcdir)/include -I$(top_srcdir)/drivers CLEANFILES = $(EXTRA_LTLIBRARIES) $(EXTRA_PROGRAMS) MAINTAINERCLEANFILES = Makefile.in .dirstamp all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu drivers/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu drivers/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): install-driverexecPROGRAMS: $(driverexec_PROGRAMS) @$(NORMAL_INSTALL) @list='$(driverexec_PROGRAMS)'; test -n "$(driverexecdir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(driverexecdir)'"; \ $(MKDIR_P) "$(DESTDIR)$(driverexecdir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ || test -f $$p1 \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(driverexecdir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(driverexecdir)$$dir" || exit $$?; \ } \ ; done uninstall-driverexecPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(driverexec_PROGRAMS)'; test -n "$(driverexecdir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(driverexecdir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(driverexecdir)" && rm -f $$files clean-driverexecPROGRAMS: @list='$(driverexec_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list install-sbinPROGRAMS: $(sbin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ || test -f $$p1 \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \ } \ ; done uninstall-sbinPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(sbindir)" && rm -f $$files clean-sbinPROGRAMS: @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list clean-noinstLTLIBRARIES: -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) @list='$(noinst_LTLIBRARIES)'; \ locs=`for p in $$list; do echo $$p; done | \ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ sort -u`; \ test -z "$$locs" || { \ echo rm -f $${locs}; \ rm -f $${locs}; \ } libdummy.la: $(libdummy_la_OBJECTS) $(libdummy_la_DEPENDENCIES) $(EXTRA_libdummy_la_DEPENDENCIES) $(AM_V_CCLD)$(libdummy_la_LINK) $(libdummy_la_OBJECTS) $(libdummy_la_LIBADD) $(LIBS) libdummy_mockdrv.la: $(libdummy_mockdrv_la_OBJECTS) $(libdummy_mockdrv_la_DEPENDENCIES) $(EXTRA_libdummy_mockdrv_la_DEPENDENCIES) $(AM_V_CCLD)$(libdummy_mockdrv_la_LINK) $(libdummy_mockdrv_la_OBJECTS) $(libdummy_mockdrv_la_LIBADD) $(LIBS) libdummy_serial.la: $(libdummy_serial_la_OBJECTS) $(libdummy_serial_la_DEPENDENCIES) $(EXTRA_libdummy_serial_la_DEPENDENCIES) $(AM_V_CCLD)$(libdummy_serial_la_LINK) $(libdummy_serial_la_OBJECTS) $(libdummy_serial_la_LIBADD) $(LIBS) libdummy_upsdrvquery.la: $(libdummy_upsdrvquery_la_OBJECTS) $(libdummy_upsdrvquery_la_DEPENDENCIES) $(EXTRA_libdummy_upsdrvquery_la_DEPENDENCIES) $(AM_V_CCLD)$(libdummy_upsdrvquery_la_LINK) $(libdummy_upsdrvquery_la_OBJECTS) $(libdummy_upsdrvquery_la_LIBADD) $(LIBS) libserial-nutscan.la: $(libserial_nutscan_la_OBJECTS) $(libserial_nutscan_la_DEPENDENCIES) $(EXTRA_libserial_nutscan_la_DEPENDENCIES) $(AM_V_CCLD)$(libserial_nutscan_la_LINK) $(libserial_nutscan_la_OBJECTS) $(libserial_nutscan_la_LIBADD) $(LIBS) adelsystem_cbi$(EXEEXT): $(adelsystem_cbi_OBJECTS) $(adelsystem_cbi_DEPENDENCIES) $(EXTRA_adelsystem_cbi_DEPENDENCIES) @rm -f adelsystem_cbi$(EXEEXT) $(AM_V_CCLD)$(LINK) $(adelsystem_cbi_OBJECTS) $(adelsystem_cbi_LDADD) $(LIBS) al175$(EXEEXT): $(al175_OBJECTS) $(al175_DEPENDENCIES) $(EXTRA_al175_DEPENDENCIES) @rm -f al175$(EXEEXT) $(AM_V_CCLD)$(LINK) $(al175_OBJECTS) $(al175_LDADD) $(LIBS) apc_modbus$(EXEEXT): $(apc_modbus_OBJECTS) $(apc_modbus_DEPENDENCIES) $(EXTRA_apc_modbus_DEPENDENCIES) @rm -f apc_modbus$(EXEEXT) $(AM_V_CCLD)$(LINK) $(apc_modbus_OBJECTS) $(apc_modbus_LDADD) $(LIBS) apcsmart$(EXEEXT): $(apcsmart_OBJECTS) $(apcsmart_DEPENDENCIES) $(EXTRA_apcsmart_DEPENDENCIES) @rm -f apcsmart$(EXEEXT) $(AM_V_CCLD)$(LINK) $(apcsmart_OBJECTS) $(apcsmart_LDADD) $(LIBS) apcsmart-old$(EXEEXT): $(apcsmart_old_OBJECTS) $(apcsmart_old_DEPENDENCIES) $(EXTRA_apcsmart_old_DEPENDENCIES) @rm -f apcsmart-old$(EXEEXT) $(AM_V_CCLD)$(LINK) $(apcsmart_old_OBJECTS) $(apcsmart_old_LDADD) $(LIBS) apcupsd-ups$(EXEEXT): $(apcupsd_ups_OBJECTS) $(apcupsd_ups_DEPENDENCIES) $(EXTRA_apcupsd_ups_DEPENDENCIES) @rm -f apcupsd-ups$(EXEEXT) $(AM_V_CCLD)$(apcupsd_ups_LINK) $(apcupsd_ups_OBJECTS) $(apcupsd_ups_LDADD) $(LIBS) asem$(EXEEXT): $(asem_OBJECTS) $(asem_DEPENDENCIES) $(EXTRA_asem_DEPENDENCIES) @rm -f asem$(EXEEXT) $(AM_V_CCLD)$(LINK) $(asem_OBJECTS) $(asem_LDADD) $(LIBS) bcmxcp$(EXEEXT): $(bcmxcp_OBJECTS) $(bcmxcp_DEPENDENCIES) $(EXTRA_bcmxcp_DEPENDENCIES) @rm -f bcmxcp$(EXEEXT) $(AM_V_CCLD)$(LINK) $(bcmxcp_OBJECTS) $(bcmxcp_LDADD) $(LIBS) bcmxcp_usb$(EXEEXT): $(bcmxcp_usb_OBJECTS) $(bcmxcp_usb_DEPENDENCIES) $(EXTRA_bcmxcp_usb_DEPENDENCIES) @rm -f bcmxcp_usb$(EXEEXT) $(AM_V_CCLD)$(LINK) $(bcmxcp_usb_OBJECTS) $(bcmxcp_usb_LDADD) $(LIBS) belkin$(EXEEXT): $(belkin_OBJECTS) $(belkin_DEPENDENCIES) $(EXTRA_belkin_DEPENDENCIES) @rm -f belkin$(EXEEXT) $(AM_V_CCLD)$(LINK) $(belkin_OBJECTS) $(belkin_LDADD) $(LIBS) belkinunv$(EXEEXT): $(belkinunv_OBJECTS) $(belkinunv_DEPENDENCIES) $(EXTRA_belkinunv_DEPENDENCIES) @rm -f belkinunv$(EXEEXT) $(AM_V_CCLD)$(LINK) $(belkinunv_OBJECTS) $(belkinunv_LDADD) $(LIBS) bestfcom$(EXEEXT): $(bestfcom_OBJECTS) $(bestfcom_DEPENDENCIES) $(EXTRA_bestfcom_DEPENDENCIES) @rm -f bestfcom$(EXEEXT) $(AM_V_CCLD)$(LINK) $(bestfcom_OBJECTS) $(bestfcom_LDADD) $(LIBS) bestfortress$(EXEEXT): $(bestfortress_OBJECTS) $(bestfortress_DEPENDENCIES) $(EXTRA_bestfortress_DEPENDENCIES) @rm -f bestfortress$(EXEEXT) $(AM_V_CCLD)$(LINK) $(bestfortress_OBJECTS) $(bestfortress_LDADD) $(LIBS) bestuferrups$(EXEEXT): $(bestuferrups_OBJECTS) $(bestuferrups_DEPENDENCIES) $(EXTRA_bestuferrups_DEPENDENCIES) @rm -f bestuferrups$(EXEEXT) $(AM_V_CCLD)$(LINK) $(bestuferrups_OBJECTS) $(bestuferrups_LDADD) $(LIBS) bestups$(EXEEXT): $(bestups_OBJECTS) $(bestups_DEPENDENCIES) $(EXTRA_bestups_DEPENDENCIES) @rm -f bestups$(EXEEXT) $(AM_V_CCLD)$(LINK) $(bestups_OBJECTS) $(bestups_LDADD) $(LIBS) bicker_ser$(EXEEXT): $(bicker_ser_OBJECTS) $(bicker_ser_DEPENDENCIES) $(EXTRA_bicker_ser_DEPENDENCIES) @rm -f bicker_ser$(EXEEXT) $(AM_V_CCLD)$(LINK) $(bicker_ser_OBJECTS) $(bicker_ser_LDADD) $(LIBS) blazer_ser$(EXEEXT): $(blazer_ser_OBJECTS) $(blazer_ser_DEPENDENCIES) $(EXTRA_blazer_ser_DEPENDENCIES) @rm -f blazer_ser$(EXEEXT) $(AM_V_CCLD)$(LINK) $(blazer_ser_OBJECTS) $(blazer_ser_LDADD) $(LIBS) blazer_usb$(EXEEXT): $(blazer_usb_OBJECTS) $(blazer_usb_DEPENDENCIES) $(EXTRA_blazer_usb_DEPENDENCIES) @rm -f blazer_usb$(EXEEXT) $(AM_V_CCLD)$(LINK) $(blazer_usb_OBJECTS) $(blazer_usb_LDADD) $(LIBS) clone$(EXEEXT): $(clone_OBJECTS) $(clone_DEPENDENCIES) $(EXTRA_clone_DEPENDENCIES) @rm -f clone$(EXEEXT) $(AM_V_CCLD)$(LINK) $(clone_OBJECTS) $(clone_LDADD) $(LIBS) clone-outlet$(EXEEXT): $(clone_outlet_OBJECTS) $(clone_outlet_DEPENDENCIES) $(EXTRA_clone_outlet_DEPENDENCIES) @rm -f clone-outlet$(EXEEXT) $(AM_V_CCLD)$(LINK) $(clone_outlet_OBJECTS) $(clone_outlet_LDADD) $(LIBS) dummy-ups$(EXEEXT): $(dummy_ups_OBJECTS) $(dummy_ups_DEPENDENCIES) $(EXTRA_dummy_ups_DEPENDENCIES) @rm -f dummy-ups$(EXEEXT) $(AM_V_CCLD)$(dummy_ups_LINK) $(dummy_ups_OBJECTS) $(dummy_ups_LDADD) $(LIBS) etapro$(EXEEXT): $(etapro_OBJECTS) $(etapro_DEPENDENCIES) $(EXTRA_etapro_DEPENDENCIES) @rm -f etapro$(EXEEXT) $(AM_V_CCLD)$(LINK) $(etapro_OBJECTS) $(etapro_LDADD) $(LIBS) everups$(EXEEXT): $(everups_OBJECTS) $(everups_DEPENDENCIES) $(EXTRA_everups_DEPENDENCIES) @rm -f everups$(EXEEXT) $(AM_V_CCLD)$(LINK) $(everups_OBJECTS) $(everups_LDADD) $(LIBS) failover$(EXEEXT): $(failover_OBJECTS) $(failover_DEPENDENCIES) $(EXTRA_failover_DEPENDENCIES) @rm -f failover$(EXEEXT) $(AM_V_CCLD)$(LINK) $(failover_OBJECTS) $(failover_LDADD) $(LIBS) gamatronic$(EXEEXT): $(gamatronic_OBJECTS) $(gamatronic_DEPENDENCIES) $(EXTRA_gamatronic_DEPENDENCIES) @rm -f gamatronic$(EXEEXT) $(AM_V_CCLD)$(LINK) $(gamatronic_OBJECTS) $(gamatronic_LDADD) $(LIBS) generic_gpio_libgpiod$(EXEEXT): $(generic_gpio_libgpiod_OBJECTS) $(generic_gpio_libgpiod_DEPENDENCIES) $(EXTRA_generic_gpio_libgpiod_DEPENDENCIES) @rm -f generic_gpio_libgpiod$(EXEEXT) $(AM_V_CCLD)$(LINK) $(generic_gpio_libgpiod_OBJECTS) $(generic_gpio_libgpiod_LDADD) $(LIBS) generic_modbus$(EXEEXT): $(generic_modbus_OBJECTS) $(generic_modbus_DEPENDENCIES) $(EXTRA_generic_modbus_DEPENDENCIES) @rm -f generic_modbus$(EXEEXT) $(AM_V_CCLD)$(LINK) $(generic_modbus_OBJECTS) $(generic_modbus_LDADD) $(LIBS) genericups$(EXEEXT): $(genericups_OBJECTS) $(genericups_DEPENDENCIES) $(EXTRA_genericups_DEPENDENCIES) @rm -f genericups$(EXEEXT) $(AM_V_CCLD)$(LINK) $(genericups_OBJECTS) $(genericups_LDADD) $(LIBS) huawei-ups2000$(EXEEXT): $(huawei_ups2000_OBJECTS) $(huawei_ups2000_DEPENDENCIES) $(EXTRA_huawei_ups2000_DEPENDENCIES) @rm -f huawei-ups2000$(EXEEXT) $(AM_V_CCLD)$(LINK) $(huawei_ups2000_OBJECTS) $(huawei_ups2000_LDADD) $(LIBS) hwmon_ina219$(EXEEXT): $(hwmon_ina219_OBJECTS) $(hwmon_ina219_DEPENDENCIES) $(EXTRA_hwmon_ina219_DEPENDENCIES) @rm -f hwmon_ina219$(EXEEXT) $(AM_V_CCLD)$(LINK) $(hwmon_ina219_OBJECTS) $(hwmon_ina219_LDADD) $(LIBS) isbmex$(EXEEXT): $(isbmex_OBJECTS) $(isbmex_DEPENDENCIES) $(EXTRA_isbmex_DEPENDENCIES) @rm -f isbmex$(EXEEXT) $(AM_V_CCLD)$(LINK) $(isbmex_OBJECTS) $(isbmex_LDADD) $(LIBS) ivtscd$(EXEEXT): $(ivtscd_OBJECTS) $(ivtscd_DEPENDENCIES) $(EXTRA_ivtscd_DEPENDENCIES) @rm -f ivtscd$(EXEEXT) $(AM_V_CCLD)$(LINK) $(ivtscd_OBJECTS) $(ivtscd_LDADD) $(LIBS) liebert$(EXEEXT): $(liebert_OBJECTS) $(liebert_DEPENDENCIES) $(EXTRA_liebert_DEPENDENCIES) @rm -f liebert$(EXEEXT) $(AM_V_CCLD)$(LINK) $(liebert_OBJECTS) $(liebert_LDADD) $(LIBS) liebert-esp2$(EXEEXT): $(liebert_esp2_OBJECTS) $(liebert_esp2_DEPENDENCIES) $(EXTRA_liebert_esp2_DEPENDENCIES) @rm -f liebert-esp2$(EXEEXT) $(AM_V_CCLD)$(LINK) $(liebert_esp2_OBJECTS) $(liebert_esp2_LDADD) $(LIBS) liebert-gxe$(EXEEXT): $(liebert_gxe_OBJECTS) $(liebert_gxe_DEPENDENCIES) $(EXTRA_liebert_gxe_DEPENDENCIES) @rm -f liebert-gxe$(EXEEXT) $(AM_V_CCLD)$(LINK) $(liebert_gxe_OBJECTS) $(liebert_gxe_LDADD) $(LIBS) macosx-ups$(EXEEXT): $(macosx_ups_OBJECTS) $(macosx_ups_DEPENDENCIES) $(EXTRA_macosx_ups_DEPENDENCIES) @rm -f macosx-ups$(EXEEXT) $(AM_V_CCLD)$(macosx_ups_LINK) $(macosx_ups_OBJECTS) $(macosx_ups_LDADD) $(LIBS) masterguard$(EXEEXT): $(masterguard_OBJECTS) $(masterguard_DEPENDENCIES) $(EXTRA_masterguard_DEPENDENCIES) @rm -f masterguard$(EXEEXT) $(AM_V_CCLD)$(LINK) $(masterguard_OBJECTS) $(masterguard_LDADD) $(LIBS) metasys$(EXEEXT): $(metasys_OBJECTS) $(metasys_DEPENDENCIES) $(EXTRA_metasys_DEPENDENCIES) @rm -f metasys$(EXEEXT) $(AM_V_CCLD)$(LINK) $(metasys_OBJECTS) $(metasys_LDADD) $(LIBS) mge-shut$(EXEEXT): $(mge_shut_OBJECTS) $(mge_shut_DEPENDENCIES) $(EXTRA_mge_shut_DEPENDENCIES) @rm -f mge-shut$(EXEEXT) $(AM_V_CCLD)$(mge_shut_LINK) $(mge_shut_OBJECTS) $(mge_shut_LDADD) $(LIBS) mge-utalk$(EXEEXT): $(mge_utalk_OBJECTS) $(mge_utalk_DEPENDENCIES) $(EXTRA_mge_utalk_DEPENDENCIES) @rm -f mge-utalk$(EXEEXT) $(AM_V_CCLD)$(LINK) $(mge_utalk_OBJECTS) $(mge_utalk_LDADD) $(LIBS) microdowell$(EXEEXT): $(microdowell_OBJECTS) $(microdowell_DEPENDENCIES) $(EXTRA_microdowell_DEPENDENCIES) @rm -f microdowell$(EXEEXT) $(AM_V_CCLD)$(LINK) $(microdowell_OBJECTS) $(microdowell_LDADD) $(LIBS) microsol-apc$(EXEEXT): $(microsol_apc_OBJECTS) $(microsol_apc_DEPENDENCIES) $(EXTRA_microsol_apc_DEPENDENCIES) @rm -f microsol-apc$(EXEEXT) $(AM_V_CCLD)$(LINK) $(microsol_apc_OBJECTS) $(microsol_apc_LDADD) $(LIBS) netxml-ups$(EXEEXT): $(netxml_ups_OBJECTS) $(netxml_ups_DEPENDENCIES) $(EXTRA_netxml_ups_DEPENDENCIES) @rm -f netxml-ups$(EXEEXT) $(AM_V_CCLD)$(netxml_ups_LINK) $(netxml_ups_OBJECTS) $(netxml_ups_LDADD) $(LIBS) nhs_ser$(EXEEXT): $(nhs_ser_OBJECTS) $(nhs_ser_DEPENDENCIES) $(EXTRA_nhs_ser_DEPENDENCIES) @rm -f nhs_ser$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nhs_ser_OBJECTS) $(nhs_ser_LDADD) $(LIBS) nut-ipmipsu$(EXEEXT): $(nut_ipmipsu_OBJECTS) $(nut_ipmipsu_DEPENDENCIES) $(EXTRA_nut_ipmipsu_DEPENDENCIES) @rm -f nut-ipmipsu$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nut_ipmipsu_OBJECTS) $(nut_ipmipsu_LDADD) $(LIBS) nutdrv_atcl_usb$(EXEEXT): $(nutdrv_atcl_usb_OBJECTS) $(nutdrv_atcl_usb_DEPENDENCIES) $(EXTRA_nutdrv_atcl_usb_DEPENDENCIES) @rm -f nutdrv_atcl_usb$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nutdrv_atcl_usb_OBJECTS) $(nutdrv_atcl_usb_LDADD) $(LIBS) nutdrv_hashx$(EXEEXT): $(nutdrv_hashx_OBJECTS) $(nutdrv_hashx_DEPENDENCIES) $(EXTRA_nutdrv_hashx_DEPENDENCIES) @rm -f nutdrv_hashx$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nutdrv_hashx_OBJECTS) $(nutdrv_hashx_LDADD) $(LIBS) nutdrv_qx$(EXEEXT): $(nutdrv_qx_OBJECTS) $(nutdrv_qx_DEPENDENCIES) $(EXTRA_nutdrv_qx_DEPENDENCIES) @rm -f nutdrv_qx$(EXEEXT) $(AM_V_CCLD)$(nutdrv_qx_LINK) $(nutdrv_qx_OBJECTS) $(nutdrv_qx_LDADD) $(LIBS) nutdrv_siemens-sitop$(EXEEXT): $(nutdrv_siemens_sitop_OBJECTS) $(nutdrv_siemens_sitop_DEPENDENCIES) $(EXTRA_nutdrv_siemens_sitop_DEPENDENCIES) @rm -f nutdrv_siemens-sitop$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nutdrv_siemens_sitop_OBJECTS) $(nutdrv_siemens_sitop_LDADD) $(LIBS) oneac$(EXEEXT): $(oneac_OBJECTS) $(oneac_DEPENDENCIES) $(EXTRA_oneac_DEPENDENCIES) @rm -f oneac$(EXEEXT) $(AM_V_CCLD)$(LINK) $(oneac_OBJECTS) $(oneac_LDADD) $(LIBS) optiups$(EXEEXT): $(optiups_OBJECTS) $(optiups_DEPENDENCIES) $(EXTRA_optiups_DEPENDENCIES) @rm -f optiups$(EXEEXT) $(AM_V_CCLD)$(LINK) $(optiups_OBJECTS) $(optiups_LDADD) $(LIBS) phoenixcontact_modbus$(EXEEXT): $(phoenixcontact_modbus_OBJECTS) $(phoenixcontact_modbus_DEPENDENCIES) $(EXTRA_phoenixcontact_modbus_DEPENDENCIES) @rm -f phoenixcontact_modbus$(EXEEXT) $(AM_V_CCLD)$(LINK) $(phoenixcontact_modbus_OBJECTS) $(phoenixcontact_modbus_LDADD) $(LIBS) pijuice$(EXEEXT): $(pijuice_OBJECTS) $(pijuice_DEPENDENCIES) $(EXTRA_pijuice_DEPENDENCIES) @rm -f pijuice$(EXEEXT) $(AM_V_CCLD)$(LINK) $(pijuice_OBJECTS) $(pijuice_LDADD) $(LIBS) powercom$(EXEEXT): $(powercom_OBJECTS) $(powercom_DEPENDENCIES) $(EXTRA_powercom_DEPENDENCIES) @rm -f powercom$(EXEEXT) $(AM_V_CCLD)$(LINK) $(powercom_OBJECTS) $(powercom_LDADD) $(LIBS) powerman-pdu$(EXEEXT): $(powerman_pdu_OBJECTS) $(powerman_pdu_DEPENDENCIES) $(EXTRA_powerman_pdu_DEPENDENCIES) @rm -f powerman-pdu$(EXEEXT) $(AM_V_CCLD)$(LINK) $(powerman_pdu_OBJECTS) $(powerman_pdu_LDADD) $(LIBS) powerpanel$(EXEEXT): $(powerpanel_OBJECTS) $(powerpanel_DEPENDENCIES) $(EXTRA_powerpanel_DEPENDENCIES) @rm -f powerpanel$(EXEEXT) $(AM_V_CCLD)$(LINK) $(powerpanel_OBJECTS) $(powerpanel_LDADD) $(LIBS) powervar_cx_ser$(EXEEXT): $(powervar_cx_ser_OBJECTS) $(powervar_cx_ser_DEPENDENCIES) $(EXTRA_powervar_cx_ser_DEPENDENCIES) @rm -f powervar_cx_ser$(EXEEXT) $(AM_V_CCLD)$(powervar_cx_ser_LINK) $(powervar_cx_ser_OBJECTS) $(powervar_cx_ser_LDADD) $(LIBS) powervar_cx_usb$(EXEEXT): $(powervar_cx_usb_OBJECTS) $(powervar_cx_usb_DEPENDENCIES) $(EXTRA_powervar_cx_usb_DEPENDENCIES) @rm -f powervar_cx_usb$(EXEEXT) $(AM_V_CCLD)$(powervar_cx_usb_LINK) $(powervar_cx_usb_OBJECTS) $(powervar_cx_usb_LDADD) $(LIBS) rhino$(EXEEXT): $(rhino_OBJECTS) $(rhino_DEPENDENCIES) $(EXTRA_rhino_DEPENDENCIES) @rm -f rhino$(EXEEXT) $(AM_V_CCLD)$(LINK) $(rhino_OBJECTS) $(rhino_LDADD) $(LIBS) richcomm_usb$(EXEEXT): $(richcomm_usb_OBJECTS) $(richcomm_usb_DEPENDENCIES) $(EXTRA_richcomm_usb_DEPENDENCIES) @rm -f richcomm_usb$(EXEEXT) $(AM_V_CCLD)$(LINK) $(richcomm_usb_OBJECTS) $(richcomm_usb_LDADD) $(LIBS) riello_ser$(EXEEXT): $(riello_ser_OBJECTS) $(riello_ser_DEPENDENCIES) $(EXTRA_riello_ser_DEPENDENCIES) @rm -f riello_ser$(EXEEXT) $(AM_V_CCLD)$(LINK) $(riello_ser_OBJECTS) $(riello_ser_LDADD) $(LIBS) riello_usb$(EXEEXT): $(riello_usb_OBJECTS) $(riello_usb_DEPENDENCIES) $(EXTRA_riello_usb_DEPENDENCIES) @rm -f riello_usb$(EXEEXT) $(AM_V_CCLD)$(LINK) $(riello_usb_OBJECTS) $(riello_usb_LDADD) $(LIBS) safenet$(EXEEXT): $(safenet_OBJECTS) $(safenet_DEPENDENCIES) $(EXTRA_safenet_DEPENDENCIES) @rm -f safenet$(EXEEXT) $(AM_V_CCLD)$(LINK) $(safenet_OBJECTS) $(safenet_LDADD) $(LIBS) skel$(EXEEXT): $(skel_OBJECTS) $(skel_DEPENDENCIES) $(EXTRA_skel_DEPENDENCIES) @rm -f skel$(EXEEXT) $(AM_V_CCLD)$(LINK) $(skel_OBJECTS) $(skel_LDADD) $(LIBS) sms_ser$(EXEEXT): $(sms_ser_OBJECTS) $(sms_ser_DEPENDENCIES) $(EXTRA_sms_ser_DEPENDENCIES) @rm -f sms_ser$(EXEEXT) $(AM_V_CCLD)$(LINK) $(sms_ser_OBJECTS) $(sms_ser_LDADD) $(LIBS) snmp-ups$(EXEEXT): $(snmp_ups_OBJECTS) $(snmp_ups_DEPENDENCIES) $(EXTRA_snmp_ups_DEPENDENCIES) @rm -f snmp-ups$(EXEEXT) $(AM_V_CCLD)$(snmp_ups_LINK) $(snmp_ups_OBJECTS) $(snmp_ups_LDADD) $(LIBS) socomec_jbus$(EXEEXT): $(socomec_jbus_OBJECTS) $(socomec_jbus_DEPENDENCIES) $(EXTRA_socomec_jbus_DEPENDENCIES) @rm -f socomec_jbus$(EXEEXT) $(AM_V_CCLD)$(LINK) $(socomec_jbus_OBJECTS) $(socomec_jbus_LDADD) $(LIBS) solis$(EXEEXT): $(solis_OBJECTS) $(solis_DEPENDENCIES) $(EXTRA_solis_DEPENDENCIES) @rm -f solis$(EXEEXT) $(AM_V_CCLD)$(LINK) $(solis_OBJECTS) $(solis_LDADD) $(LIBS) tripplite$(EXEEXT): $(tripplite_OBJECTS) $(tripplite_DEPENDENCIES) $(EXTRA_tripplite_DEPENDENCIES) @rm -f tripplite$(EXEEXT) $(AM_V_CCLD)$(LINK) $(tripplite_OBJECTS) $(tripplite_LDADD) $(LIBS) tripplite_usb$(EXEEXT): $(tripplite_usb_OBJECTS) $(tripplite_usb_DEPENDENCIES) $(EXTRA_tripplite_usb_DEPENDENCIES) @rm -f tripplite_usb$(EXEEXT) $(AM_V_CCLD)$(LINK) $(tripplite_usb_OBJECTS) $(tripplite_usb_LDADD) $(LIBS) tripplitesu$(EXEEXT): $(tripplitesu_OBJECTS) $(tripplitesu_DEPENDENCIES) $(EXTRA_tripplitesu_DEPENDENCIES) @rm -f tripplitesu$(EXEEXT) $(AM_V_CCLD)$(LINK) $(tripplitesu_OBJECTS) $(tripplitesu_LDADD) $(LIBS) upscode2$(EXEEXT): $(upscode2_OBJECTS) $(upscode2_DEPENDENCIES) $(EXTRA_upscode2_DEPENDENCIES) @rm -f upscode2$(EXEEXT) $(AM_V_CCLD)$(LINK) $(upscode2_OBJECTS) $(upscode2_LDADD) $(LIBS) upsdrvctl$(EXEEXT): $(upsdrvctl_OBJECTS) $(upsdrvctl_DEPENDENCIES) $(EXTRA_upsdrvctl_DEPENDENCIES) @rm -f upsdrvctl$(EXEEXT) $(AM_V_CCLD)$(LINK) $(upsdrvctl_OBJECTS) $(upsdrvctl_LDADD) $(LIBS) usbhid-ups$(EXEEXT): $(usbhid_ups_OBJECTS) $(usbhid_ups_DEPENDENCIES) $(EXTRA_usbhid_ups_DEPENDENCIES) @rm -f usbhid-ups$(EXEEXT) $(AM_V_CCLD)$(LINK) $(usbhid_ups_OBJECTS) $(usbhid_ups_LDADD) $(LIBS) ve-direct$(EXEEXT): $(ve_direct_OBJECTS) $(ve_direct_DEPENDENCIES) $(EXTRA_ve_direct_DEPENDENCIES) @rm -f ve-direct$(EXEEXT) $(AM_V_CCLD)$(LINK) $(ve_direct_OBJECTS) $(ve_direct_LDADD) $(LIBS) victronups$(EXEEXT): $(victronups_OBJECTS) $(victronups_DEPENDENCIES) $(EXTRA_victronups_DEPENDENCIES) @rm -f victronups$(EXEEXT) $(AM_V_CCLD)$(LINK) $(victronups_OBJECTS) $(victronups_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/adelsystem_cbi.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/al175.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apc-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apc_modbus.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apcsmart-old.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apcsmart.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apcsmart_tabs.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/apcupsd_ups-apcupsd-ups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/arduino-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asem.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bcmxcp.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bcmxcp_ser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bcmxcp_usb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/belkin-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/belkin.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/belkinunv.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bestfcom.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bestfortress.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bestuferrups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bestups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bicker_ser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/blazer.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/blazer_ser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/blazer_usb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clone-outlet.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clone.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cps-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/delta_ups-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dstate.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dummy_ups-dummy-ups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ecoflow-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/etapro.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ever-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/everups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/explore-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/failover.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gamatronic.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generic_gpio_common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generic_gpio_libgpiod.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generic_modbus.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/genericups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hidparser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/huawei-ups2000.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hwmon_ina219.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/idowell-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isbmex.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ivtscd.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/legrand-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdummy_mockdrv_la-dstate.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdummy_mockdrv_la-main.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libserial_nutscan_la-bcmxcp_ser.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libserial_nutscan_la-serial.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libusb0.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libusb1.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liebert-esp2.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liebert-gxe.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liebert-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/liebert.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/macosx-ups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/masterguard.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/metasys.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mge-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mge-utalk.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mge_shut-hidparser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mge_shut-libhid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mge_shut-libshut.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mge_shut-mge-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mge_shut-usbhid-ups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/microdowell.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/microsol-apc.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/microsol-common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netxml_ups-mge-xml.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netxml_ups-netxml-ups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nhs_ser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nut-ipmipsu.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nut-libfreeipmi.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_atcl_usb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_hashx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-common_voltronic-crc.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-libusb0.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-libusb1.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_qx-usb-common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nutdrv_siemens_sitop.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oneac.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openups-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/optiups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/phoenixcontact_modbus.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pijuice.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powercom-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powercom.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powerman-pdu.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powerp-bin.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powerp-txt.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powerpanel.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar_cx_ser-powervar_cx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar_cx_usb-libusb0.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar_cx_usb-libusb1.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar_cx_usb-powervar_cx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/powervar_cx_usb-usb-common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rhino.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/richcomm_usb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/riello.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/riello_ser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/riello_usb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/safenet.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/salicru-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/serial.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/skel.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sms_ser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-apc-ats-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-apc-epdu-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-apc-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-apc-pdu-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-baytech-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-bestpower-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-compaq-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-cyberpower-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-delta_ups-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-ats30-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-hpe-pdu-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-huawei-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-ietf-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-mge-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-netvision-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-raritan-pdu-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-raritan-px2-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-snmp-ups-helpers.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-snmp-ups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snmp_ups-xppc-mib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socomec_jbus.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/solis.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tripplite-hid.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tripplite.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tripplite_usb.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tripplitesu.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upscode2.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upsdrvctl.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upsdrvquery.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/usb-common.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/usbhid-ups.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ve-direct.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/victronups.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @echo '# dummy' >$@-t && $(am__mv) $@-t $@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< libdummy_mockdrv_la-main.lo: main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdummy_mockdrv_la_CFLAGS) $(CFLAGS) -MT libdummy_mockdrv_la-main.lo -MD -MP -MF $(DEPDIR)/libdummy_mockdrv_la-main.Tpo -c -o libdummy_mockdrv_la-main.lo `test -f 'main.c' || echo '$(srcdir)/'`main.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libdummy_mockdrv_la-main.Tpo $(DEPDIR)/libdummy_mockdrv_la-main.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='libdummy_mockdrv_la-main.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdummy_mockdrv_la_CFLAGS) $(CFLAGS) -c -o libdummy_mockdrv_la-main.lo `test -f 'main.c' || echo '$(srcdir)/'`main.c libdummy_mockdrv_la-dstate.lo: dstate.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdummy_mockdrv_la_CFLAGS) $(CFLAGS) -MT libdummy_mockdrv_la-dstate.lo -MD -MP -MF $(DEPDIR)/libdummy_mockdrv_la-dstate.Tpo -c -o libdummy_mockdrv_la-dstate.lo `test -f 'dstate.c' || echo '$(srcdir)/'`dstate.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libdummy_mockdrv_la-dstate.Tpo $(DEPDIR)/libdummy_mockdrv_la-dstate.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dstate.c' object='libdummy_mockdrv_la-dstate.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libdummy_mockdrv_la_CFLAGS) $(CFLAGS) -c -o libdummy_mockdrv_la-dstate.lo `test -f 'dstate.c' || echo '$(srcdir)/'`dstate.c libserial_nutscan_la-serial.lo: serial.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libserial_nutscan_la_CFLAGS) $(CFLAGS) -MT libserial_nutscan_la-serial.lo -MD -MP -MF $(DEPDIR)/libserial_nutscan_la-serial.Tpo -c -o libserial_nutscan_la-serial.lo `test -f 'serial.c' || echo '$(srcdir)/'`serial.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libserial_nutscan_la-serial.Tpo $(DEPDIR)/libserial_nutscan_la-serial.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='serial.c' object='libserial_nutscan_la-serial.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libserial_nutscan_la_CFLAGS) $(CFLAGS) -c -o libserial_nutscan_la-serial.lo `test -f 'serial.c' || echo '$(srcdir)/'`serial.c libserial_nutscan_la-bcmxcp_ser.lo: bcmxcp_ser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libserial_nutscan_la_CFLAGS) $(CFLAGS) -MT libserial_nutscan_la-bcmxcp_ser.lo -MD -MP -MF $(DEPDIR)/libserial_nutscan_la-bcmxcp_ser.Tpo -c -o libserial_nutscan_la-bcmxcp_ser.lo `test -f 'bcmxcp_ser.c' || echo '$(srcdir)/'`bcmxcp_ser.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libserial_nutscan_la-bcmxcp_ser.Tpo $(DEPDIR)/libserial_nutscan_la-bcmxcp_ser.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bcmxcp_ser.c' object='libserial_nutscan_la-bcmxcp_ser.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libserial_nutscan_la_CFLAGS) $(CFLAGS) -c -o libserial_nutscan_la-bcmxcp_ser.lo `test -f 'bcmxcp_ser.c' || echo '$(srcdir)/'`bcmxcp_ser.c apcupsd_ups-apcupsd-ups.o: apcupsd-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(apcupsd_ups_CFLAGS) $(CFLAGS) -MT apcupsd_ups-apcupsd-ups.o -MD -MP -MF $(DEPDIR)/apcupsd_ups-apcupsd-ups.Tpo -c -o apcupsd_ups-apcupsd-ups.o `test -f 'apcupsd-ups.c' || echo '$(srcdir)/'`apcupsd-ups.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/apcupsd_ups-apcupsd-ups.Tpo $(DEPDIR)/apcupsd_ups-apcupsd-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apcupsd-ups.c' object='apcupsd_ups-apcupsd-ups.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(apcupsd_ups_CFLAGS) $(CFLAGS) -c -o apcupsd_ups-apcupsd-ups.o `test -f 'apcupsd-ups.c' || echo '$(srcdir)/'`apcupsd-ups.c apcupsd_ups-apcupsd-ups.obj: apcupsd-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(apcupsd_ups_CFLAGS) $(CFLAGS) -MT apcupsd_ups-apcupsd-ups.obj -MD -MP -MF $(DEPDIR)/apcupsd_ups-apcupsd-ups.Tpo -c -o apcupsd_ups-apcupsd-ups.obj `if test -f 'apcupsd-ups.c'; then $(CYGPATH_W) 'apcupsd-ups.c'; else $(CYGPATH_W) '$(srcdir)/apcupsd-ups.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/apcupsd_ups-apcupsd-ups.Tpo $(DEPDIR)/apcupsd_ups-apcupsd-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apcupsd-ups.c' object='apcupsd_ups-apcupsd-ups.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(apcupsd_ups_CFLAGS) $(CFLAGS) -c -o apcupsd_ups-apcupsd-ups.obj `if test -f 'apcupsd-ups.c'; then $(CYGPATH_W) 'apcupsd-ups.c'; else $(CYGPATH_W) '$(srcdir)/apcupsd-ups.c'; fi` dummy_ups-dummy-ups.o: dummy-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(dummy_ups_CFLAGS) $(CFLAGS) -MT dummy_ups-dummy-ups.o -MD -MP -MF $(DEPDIR)/dummy_ups-dummy-ups.Tpo -c -o dummy_ups-dummy-ups.o `test -f 'dummy-ups.c' || echo '$(srcdir)/'`dummy-ups.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dummy_ups-dummy-ups.Tpo $(DEPDIR)/dummy_ups-dummy-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dummy-ups.c' object='dummy_ups-dummy-ups.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(dummy_ups_CFLAGS) $(CFLAGS) -c -o dummy_ups-dummy-ups.o `test -f 'dummy-ups.c' || echo '$(srcdir)/'`dummy-ups.c dummy_ups-dummy-ups.obj: dummy-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(dummy_ups_CFLAGS) $(CFLAGS) -MT dummy_ups-dummy-ups.obj -MD -MP -MF $(DEPDIR)/dummy_ups-dummy-ups.Tpo -c -o dummy_ups-dummy-ups.obj `if test -f 'dummy-ups.c'; then $(CYGPATH_W) 'dummy-ups.c'; else $(CYGPATH_W) '$(srcdir)/dummy-ups.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/dummy_ups-dummy-ups.Tpo $(DEPDIR)/dummy_ups-dummy-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='dummy-ups.c' object='dummy_ups-dummy-ups.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(dummy_ups_CFLAGS) $(CFLAGS) -c -o dummy_ups-dummy-ups.obj `if test -f 'dummy-ups.c'; then $(CYGPATH_W) 'dummy-ups.c'; else $(CYGPATH_W) '$(srcdir)/dummy-ups.c'; fi` mge_shut-usbhid-ups.o: usbhid-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-usbhid-ups.o -MD -MP -MF $(DEPDIR)/mge_shut-usbhid-ups.Tpo -c -o mge_shut-usbhid-ups.o `test -f 'usbhid-ups.c' || echo '$(srcdir)/'`usbhid-ups.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-usbhid-ups.Tpo $(DEPDIR)/mge_shut-usbhid-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='usbhid-ups.c' object='mge_shut-usbhid-ups.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-usbhid-ups.o `test -f 'usbhid-ups.c' || echo '$(srcdir)/'`usbhid-ups.c mge_shut-usbhid-ups.obj: usbhid-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-usbhid-ups.obj -MD -MP -MF $(DEPDIR)/mge_shut-usbhid-ups.Tpo -c -o mge_shut-usbhid-ups.obj `if test -f 'usbhid-ups.c'; then $(CYGPATH_W) 'usbhid-ups.c'; else $(CYGPATH_W) '$(srcdir)/usbhid-ups.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-usbhid-ups.Tpo $(DEPDIR)/mge_shut-usbhid-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='usbhid-ups.c' object='mge_shut-usbhid-ups.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-usbhid-ups.obj `if test -f 'usbhid-ups.c'; then $(CYGPATH_W) 'usbhid-ups.c'; else $(CYGPATH_W) '$(srcdir)/usbhid-ups.c'; fi` mge_shut-libshut.o: libshut.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-libshut.o -MD -MP -MF $(DEPDIR)/mge_shut-libshut.Tpo -c -o mge_shut-libshut.o `test -f 'libshut.c' || echo '$(srcdir)/'`libshut.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-libshut.Tpo $(DEPDIR)/mge_shut-libshut.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libshut.c' object='mge_shut-libshut.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-libshut.o `test -f 'libshut.c' || echo '$(srcdir)/'`libshut.c mge_shut-libshut.obj: libshut.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-libshut.obj -MD -MP -MF $(DEPDIR)/mge_shut-libshut.Tpo -c -o mge_shut-libshut.obj `if test -f 'libshut.c'; then $(CYGPATH_W) 'libshut.c'; else $(CYGPATH_W) '$(srcdir)/libshut.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-libshut.Tpo $(DEPDIR)/mge_shut-libshut.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libshut.c' object='mge_shut-libshut.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-libshut.obj `if test -f 'libshut.c'; then $(CYGPATH_W) 'libshut.c'; else $(CYGPATH_W) '$(srcdir)/libshut.c'; fi` mge_shut-libhid.o: libhid.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-libhid.o -MD -MP -MF $(DEPDIR)/mge_shut-libhid.Tpo -c -o mge_shut-libhid.o `test -f 'libhid.c' || echo '$(srcdir)/'`libhid.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-libhid.Tpo $(DEPDIR)/mge_shut-libhid.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libhid.c' object='mge_shut-libhid.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-libhid.o `test -f 'libhid.c' || echo '$(srcdir)/'`libhid.c mge_shut-libhid.obj: libhid.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-libhid.obj -MD -MP -MF $(DEPDIR)/mge_shut-libhid.Tpo -c -o mge_shut-libhid.obj `if test -f 'libhid.c'; then $(CYGPATH_W) 'libhid.c'; else $(CYGPATH_W) '$(srcdir)/libhid.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-libhid.Tpo $(DEPDIR)/mge_shut-libhid.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libhid.c' object='mge_shut-libhid.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-libhid.obj `if test -f 'libhid.c'; then $(CYGPATH_W) 'libhid.c'; else $(CYGPATH_W) '$(srcdir)/libhid.c'; fi` mge_shut-hidparser.o: hidparser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-hidparser.o -MD -MP -MF $(DEPDIR)/mge_shut-hidparser.Tpo -c -o mge_shut-hidparser.o `test -f 'hidparser.c' || echo '$(srcdir)/'`hidparser.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-hidparser.Tpo $(DEPDIR)/mge_shut-hidparser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hidparser.c' object='mge_shut-hidparser.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-hidparser.o `test -f 'hidparser.c' || echo '$(srcdir)/'`hidparser.c mge_shut-hidparser.obj: hidparser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-hidparser.obj -MD -MP -MF $(DEPDIR)/mge_shut-hidparser.Tpo -c -o mge_shut-hidparser.obj `if test -f 'hidparser.c'; then $(CYGPATH_W) 'hidparser.c'; else $(CYGPATH_W) '$(srcdir)/hidparser.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-hidparser.Tpo $(DEPDIR)/mge_shut-hidparser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hidparser.c' object='mge_shut-hidparser.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-hidparser.obj `if test -f 'hidparser.c'; then $(CYGPATH_W) 'hidparser.c'; else $(CYGPATH_W) '$(srcdir)/hidparser.c'; fi` mge_shut-mge-hid.o: mge-hid.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-mge-hid.o -MD -MP -MF $(DEPDIR)/mge_shut-mge-hid.Tpo -c -o mge_shut-mge-hid.o `test -f 'mge-hid.c' || echo '$(srcdir)/'`mge-hid.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-mge-hid.Tpo $(DEPDIR)/mge_shut-mge-hid.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mge-hid.c' object='mge_shut-mge-hid.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-mge-hid.o `test -f 'mge-hid.c' || echo '$(srcdir)/'`mge-hid.c mge_shut-mge-hid.obj: mge-hid.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -MT mge_shut-mge-hid.obj -MD -MP -MF $(DEPDIR)/mge_shut-mge-hid.Tpo -c -o mge_shut-mge-hid.obj `if test -f 'mge-hid.c'; then $(CYGPATH_W) 'mge-hid.c'; else $(CYGPATH_W) '$(srcdir)/mge-hid.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mge_shut-mge-hid.Tpo $(DEPDIR)/mge_shut-mge-hid.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mge-hid.c' object='mge_shut-mge-hid.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mge_shut_CFLAGS) $(CFLAGS) -c -o mge_shut-mge-hid.obj `if test -f 'mge-hid.c'; then $(CYGPATH_W) 'mge-hid.c'; else $(CYGPATH_W) '$(srcdir)/mge-hid.c'; fi` netxml_ups-netxml-ups.o: netxml-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -MT netxml_ups-netxml-ups.o -MD -MP -MF $(DEPDIR)/netxml_ups-netxml-ups.Tpo -c -o netxml_ups-netxml-ups.o `test -f 'netxml-ups.c' || echo '$(srcdir)/'`netxml-ups.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netxml_ups-netxml-ups.Tpo $(DEPDIR)/netxml_ups-netxml-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='netxml-ups.c' object='netxml_ups-netxml-ups.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -c -o netxml_ups-netxml-ups.o `test -f 'netxml-ups.c' || echo '$(srcdir)/'`netxml-ups.c netxml_ups-netxml-ups.obj: netxml-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -MT netxml_ups-netxml-ups.obj -MD -MP -MF $(DEPDIR)/netxml_ups-netxml-ups.Tpo -c -o netxml_ups-netxml-ups.obj `if test -f 'netxml-ups.c'; then $(CYGPATH_W) 'netxml-ups.c'; else $(CYGPATH_W) '$(srcdir)/netxml-ups.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netxml_ups-netxml-ups.Tpo $(DEPDIR)/netxml_ups-netxml-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='netxml-ups.c' object='netxml_ups-netxml-ups.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -c -o netxml_ups-netxml-ups.obj `if test -f 'netxml-ups.c'; then $(CYGPATH_W) 'netxml-ups.c'; else $(CYGPATH_W) '$(srcdir)/netxml-ups.c'; fi` netxml_ups-mge-xml.o: mge-xml.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -MT netxml_ups-mge-xml.o -MD -MP -MF $(DEPDIR)/netxml_ups-mge-xml.Tpo -c -o netxml_ups-mge-xml.o `test -f 'mge-xml.c' || echo '$(srcdir)/'`mge-xml.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netxml_ups-mge-xml.Tpo $(DEPDIR)/netxml_ups-mge-xml.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mge-xml.c' object='netxml_ups-mge-xml.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -c -o netxml_ups-mge-xml.o `test -f 'mge-xml.c' || echo '$(srcdir)/'`mge-xml.c netxml_ups-mge-xml.obj: mge-xml.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -MT netxml_ups-mge-xml.obj -MD -MP -MF $(DEPDIR)/netxml_ups-mge-xml.Tpo -c -o netxml_ups-mge-xml.obj `if test -f 'mge-xml.c'; then $(CYGPATH_W) 'mge-xml.c'; else $(CYGPATH_W) '$(srcdir)/mge-xml.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/netxml_ups-mge-xml.Tpo $(DEPDIR)/netxml_ups-mge-xml.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mge-xml.c' object='netxml_ups-mge-xml.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(netxml_ups_CFLAGS) $(CFLAGS) -c -o netxml_ups-mge-xml.obj `if test -f 'mge-xml.c'; then $(CYGPATH_W) 'mge-xml.c'; else $(CYGPATH_W) '$(srcdir)/mge-xml.c'; fi` nutdrv_qx-nutdrv_qx.o: nutdrv_qx.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx.Tpo -c -o nutdrv_qx-nutdrv_qx.o `test -f 'nutdrv_qx.c' || echo '$(srcdir)/'`nutdrv_qx.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx.c' object='nutdrv_qx-nutdrv_qx.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx.o `test -f 'nutdrv_qx.c' || echo '$(srcdir)/'`nutdrv_qx.c nutdrv_qx-nutdrv_qx.obj: nutdrv_qx.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx.Tpo -c -o nutdrv_qx-nutdrv_qx.obj `if test -f 'nutdrv_qx.c'; then $(CYGPATH_W) 'nutdrv_qx.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx.c' object='nutdrv_qx-nutdrv_qx.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx.obj `if test -f 'nutdrv_qx.c'; then $(CYGPATH_W) 'nutdrv_qx.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx.c'; fi` nutdrv_qx-libusb0.o: libusb0.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-libusb0.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-libusb0.Tpo -c -o nutdrv_qx-libusb0.o `test -f 'libusb0.c' || echo '$(srcdir)/'`libusb0.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-libusb0.Tpo $(DEPDIR)/nutdrv_qx-libusb0.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb0.c' object='nutdrv_qx-libusb0.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-libusb0.o `test -f 'libusb0.c' || echo '$(srcdir)/'`libusb0.c nutdrv_qx-libusb0.obj: libusb0.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-libusb0.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-libusb0.Tpo -c -o nutdrv_qx-libusb0.obj `if test -f 'libusb0.c'; then $(CYGPATH_W) 'libusb0.c'; else $(CYGPATH_W) '$(srcdir)/libusb0.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-libusb0.Tpo $(DEPDIR)/nutdrv_qx-libusb0.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb0.c' object='nutdrv_qx-libusb0.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-libusb0.obj `if test -f 'libusb0.c'; then $(CYGPATH_W) 'libusb0.c'; else $(CYGPATH_W) '$(srcdir)/libusb0.c'; fi` nutdrv_qx-libusb1.o: libusb1.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-libusb1.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-libusb1.Tpo -c -o nutdrv_qx-libusb1.o `test -f 'libusb1.c' || echo '$(srcdir)/'`libusb1.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-libusb1.Tpo $(DEPDIR)/nutdrv_qx-libusb1.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb1.c' object='nutdrv_qx-libusb1.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-libusb1.o `test -f 'libusb1.c' || echo '$(srcdir)/'`libusb1.c nutdrv_qx-libusb1.obj: libusb1.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-libusb1.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-libusb1.Tpo -c -o nutdrv_qx-libusb1.obj `if test -f 'libusb1.c'; then $(CYGPATH_W) 'libusb1.c'; else $(CYGPATH_W) '$(srcdir)/libusb1.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-libusb1.Tpo $(DEPDIR)/nutdrv_qx-libusb1.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb1.c' object='nutdrv_qx-libusb1.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-libusb1.obj `if test -f 'libusb1.c'; then $(CYGPATH_W) 'libusb1.c'; else $(CYGPATH_W) '$(srcdir)/libusb1.c'; fi` nutdrv_qx-usb-common.o: usb-common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-usb-common.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-usb-common.Tpo -c -o nutdrv_qx-usb-common.o `test -f 'usb-common.c' || echo '$(srcdir)/'`usb-common.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-usb-common.Tpo $(DEPDIR)/nutdrv_qx-usb-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='usb-common.c' object='nutdrv_qx-usb-common.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-usb-common.o `test -f 'usb-common.c' || echo '$(srcdir)/'`usb-common.c nutdrv_qx-usb-common.obj: usb-common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-usb-common.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-usb-common.Tpo -c -o nutdrv_qx-usb-common.obj `if test -f 'usb-common.c'; then $(CYGPATH_W) 'usb-common.c'; else $(CYGPATH_W) '$(srcdir)/usb-common.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-usb-common.Tpo $(DEPDIR)/nutdrv_qx-usb-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='usb-common.c' object='nutdrv_qx-usb-common.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-usb-common.obj `if test -f 'usb-common.c'; then $(CYGPATH_W) 'usb-common.c'; else $(CYGPATH_W) '$(srcdir)/usb-common.c'; fi` nutdrv_qx-nutdrv_qx_bestups.o: nutdrv_qx_bestups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_bestups.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Tpo -c -o nutdrv_qx-nutdrv_qx_bestups.o `test -f 'nutdrv_qx_bestups.c' || echo '$(srcdir)/'`nutdrv_qx_bestups.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_bestups.c' object='nutdrv_qx-nutdrv_qx_bestups.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_bestups.o `test -f 'nutdrv_qx_bestups.c' || echo '$(srcdir)/'`nutdrv_qx_bestups.c nutdrv_qx-nutdrv_qx_bestups.obj: nutdrv_qx_bestups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_bestups.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Tpo -c -o nutdrv_qx-nutdrv_qx_bestups.obj `if test -f 'nutdrv_qx_bestups.c'; then $(CYGPATH_W) 'nutdrv_qx_bestups.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_bestups.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_bestups.c' object='nutdrv_qx-nutdrv_qx_bestups.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_bestups.obj `if test -f 'nutdrv_qx_bestups.c'; then $(CYGPATH_W) 'nutdrv_qx_bestups.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_bestups.c'; fi` nutdrv_qx-nutdrv_qx_blazer-common.o: nutdrv_qx_blazer-common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_blazer-common.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Tpo -c -o nutdrv_qx-nutdrv_qx_blazer-common.o `test -f 'nutdrv_qx_blazer-common.c' || echo '$(srcdir)/'`nutdrv_qx_blazer-common.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_blazer-common.c' object='nutdrv_qx-nutdrv_qx_blazer-common.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_blazer-common.o `test -f 'nutdrv_qx_blazer-common.c' || echo '$(srcdir)/'`nutdrv_qx_blazer-common.c nutdrv_qx-nutdrv_qx_blazer-common.obj: nutdrv_qx_blazer-common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_blazer-common.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Tpo -c -o nutdrv_qx-nutdrv_qx_blazer-common.obj `if test -f 'nutdrv_qx_blazer-common.c'; then $(CYGPATH_W) 'nutdrv_qx_blazer-common.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_blazer-common.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_blazer-common.c' object='nutdrv_qx-nutdrv_qx_blazer-common.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_blazer-common.obj `if test -f 'nutdrv_qx_blazer-common.c'; then $(CYGPATH_W) 'nutdrv_qx_blazer-common.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_blazer-common.c'; fi` nutdrv_qx-nutdrv_qx_innovart31.o: nutdrv_qx_innovart31.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_innovart31.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Tpo -c -o nutdrv_qx-nutdrv_qx_innovart31.o `test -f 'nutdrv_qx_innovart31.c' || echo '$(srcdir)/'`nutdrv_qx_innovart31.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_innovart31.c' object='nutdrv_qx-nutdrv_qx_innovart31.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_innovart31.o `test -f 'nutdrv_qx_innovart31.c' || echo '$(srcdir)/'`nutdrv_qx_innovart31.c nutdrv_qx-nutdrv_qx_innovart31.obj: nutdrv_qx_innovart31.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_innovart31.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Tpo -c -o nutdrv_qx-nutdrv_qx_innovart31.obj `if test -f 'nutdrv_qx_innovart31.c'; then $(CYGPATH_W) 'nutdrv_qx_innovart31.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_innovart31.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_innovart31.c' object='nutdrv_qx-nutdrv_qx_innovart31.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_innovart31.obj `if test -f 'nutdrv_qx_innovart31.c'; then $(CYGPATH_W) 'nutdrv_qx_innovart31.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_innovart31.c'; fi` nutdrv_qx-nutdrv_qx_innovart33.o: nutdrv_qx_innovart33.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_innovart33.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Tpo -c -o nutdrv_qx-nutdrv_qx_innovart33.o `test -f 'nutdrv_qx_innovart33.c' || echo '$(srcdir)/'`nutdrv_qx_innovart33.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_innovart33.c' object='nutdrv_qx-nutdrv_qx_innovart33.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_innovart33.o `test -f 'nutdrv_qx_innovart33.c' || echo '$(srcdir)/'`nutdrv_qx_innovart33.c nutdrv_qx-nutdrv_qx_innovart33.obj: nutdrv_qx_innovart33.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_innovart33.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Tpo -c -o nutdrv_qx-nutdrv_qx_innovart33.obj `if test -f 'nutdrv_qx_innovart33.c'; then $(CYGPATH_W) 'nutdrv_qx_innovart33.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_innovart33.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_innovart33.c' object='nutdrv_qx-nutdrv_qx_innovart33.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_innovart33.obj `if test -f 'nutdrv_qx_innovart33.c'; then $(CYGPATH_W) 'nutdrv_qx_innovart33.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_innovart33.c'; fi` nutdrv_qx-nutdrv_qx_masterguard.o: nutdrv_qx_masterguard.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_masterguard.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Tpo -c -o nutdrv_qx-nutdrv_qx_masterguard.o `test -f 'nutdrv_qx_masterguard.c' || echo '$(srcdir)/'`nutdrv_qx_masterguard.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_masterguard.c' object='nutdrv_qx-nutdrv_qx_masterguard.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_masterguard.o `test -f 'nutdrv_qx_masterguard.c' || echo '$(srcdir)/'`nutdrv_qx_masterguard.c nutdrv_qx-nutdrv_qx_masterguard.obj: nutdrv_qx_masterguard.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_masterguard.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Tpo -c -o nutdrv_qx-nutdrv_qx_masterguard.obj `if test -f 'nutdrv_qx_masterguard.c'; then $(CYGPATH_W) 'nutdrv_qx_masterguard.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_masterguard.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_masterguard.c' object='nutdrv_qx-nutdrv_qx_masterguard.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_masterguard.obj `if test -f 'nutdrv_qx_masterguard.c'; then $(CYGPATH_W) 'nutdrv_qx_masterguard.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_masterguard.c'; fi` nutdrv_qx-nutdrv_qx_mecer.o: nutdrv_qx_mecer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_mecer.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Tpo -c -o nutdrv_qx-nutdrv_qx_mecer.o `test -f 'nutdrv_qx_mecer.c' || echo '$(srcdir)/'`nutdrv_qx_mecer.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_mecer.c' object='nutdrv_qx-nutdrv_qx_mecer.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_mecer.o `test -f 'nutdrv_qx_mecer.c' || echo '$(srcdir)/'`nutdrv_qx_mecer.c nutdrv_qx-nutdrv_qx_mecer.obj: nutdrv_qx_mecer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_mecer.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Tpo -c -o nutdrv_qx-nutdrv_qx_mecer.obj `if test -f 'nutdrv_qx_mecer.c'; then $(CYGPATH_W) 'nutdrv_qx_mecer.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_mecer.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_mecer.c' object='nutdrv_qx-nutdrv_qx_mecer.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_mecer.obj `if test -f 'nutdrv_qx_mecer.c'; then $(CYGPATH_W) 'nutdrv_qx_mecer.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_mecer.c'; fi` nutdrv_qx-nutdrv_qx_megatec.o: nutdrv_qx_megatec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_megatec.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Tpo -c -o nutdrv_qx-nutdrv_qx_megatec.o `test -f 'nutdrv_qx_megatec.c' || echo '$(srcdir)/'`nutdrv_qx_megatec.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_megatec.c' object='nutdrv_qx-nutdrv_qx_megatec.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_megatec.o `test -f 'nutdrv_qx_megatec.c' || echo '$(srcdir)/'`nutdrv_qx_megatec.c nutdrv_qx-nutdrv_qx_megatec.obj: nutdrv_qx_megatec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_megatec.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Tpo -c -o nutdrv_qx-nutdrv_qx_megatec.obj `if test -f 'nutdrv_qx_megatec.c'; then $(CYGPATH_W) 'nutdrv_qx_megatec.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_megatec.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_megatec.c' object='nutdrv_qx-nutdrv_qx_megatec.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_megatec.obj `if test -f 'nutdrv_qx_megatec.c'; then $(CYGPATH_W) 'nutdrv_qx_megatec.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_megatec.c'; fi` nutdrv_qx-nutdrv_qx_megatec-old.o: nutdrv_qx_megatec-old.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_megatec-old.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Tpo -c -o nutdrv_qx-nutdrv_qx_megatec-old.o `test -f 'nutdrv_qx_megatec-old.c' || echo '$(srcdir)/'`nutdrv_qx_megatec-old.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_megatec-old.c' object='nutdrv_qx-nutdrv_qx_megatec-old.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_megatec-old.o `test -f 'nutdrv_qx_megatec-old.c' || echo '$(srcdir)/'`nutdrv_qx_megatec-old.c nutdrv_qx-nutdrv_qx_megatec-old.obj: nutdrv_qx_megatec-old.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_megatec-old.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Tpo -c -o nutdrv_qx-nutdrv_qx_megatec-old.obj `if test -f 'nutdrv_qx_megatec-old.c'; then $(CYGPATH_W) 'nutdrv_qx_megatec-old.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_megatec-old.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_megatec-old.c' object='nutdrv_qx-nutdrv_qx_megatec-old.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_megatec-old.obj `if test -f 'nutdrv_qx_megatec-old.c'; then $(CYGPATH_W) 'nutdrv_qx_megatec-old.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_megatec-old.c'; fi` nutdrv_qx-nutdrv_qx_mustek.o: nutdrv_qx_mustek.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_mustek.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Tpo -c -o nutdrv_qx-nutdrv_qx_mustek.o `test -f 'nutdrv_qx_mustek.c' || echo '$(srcdir)/'`nutdrv_qx_mustek.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_mustek.c' object='nutdrv_qx-nutdrv_qx_mustek.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_mustek.o `test -f 'nutdrv_qx_mustek.c' || echo '$(srcdir)/'`nutdrv_qx_mustek.c nutdrv_qx-nutdrv_qx_mustek.obj: nutdrv_qx_mustek.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_mustek.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Tpo -c -o nutdrv_qx-nutdrv_qx_mustek.obj `if test -f 'nutdrv_qx_mustek.c'; then $(CYGPATH_W) 'nutdrv_qx_mustek.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_mustek.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_mustek.c' object='nutdrv_qx-nutdrv_qx_mustek.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_mustek.obj `if test -f 'nutdrv_qx_mustek.c'; then $(CYGPATH_W) 'nutdrv_qx_mustek.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_mustek.c'; fi` nutdrv_qx-nutdrv_qx_q1.o: nutdrv_qx_q1.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_q1.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Tpo -c -o nutdrv_qx-nutdrv_qx_q1.o `test -f 'nutdrv_qx_q1.c' || echo '$(srcdir)/'`nutdrv_qx_q1.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_q1.c' object='nutdrv_qx-nutdrv_qx_q1.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_q1.o `test -f 'nutdrv_qx_q1.c' || echo '$(srcdir)/'`nutdrv_qx_q1.c nutdrv_qx-nutdrv_qx_q1.obj: nutdrv_qx_q1.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_q1.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Tpo -c -o nutdrv_qx-nutdrv_qx_q1.obj `if test -f 'nutdrv_qx_q1.c'; then $(CYGPATH_W) 'nutdrv_qx_q1.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_q1.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_q1.c' object='nutdrv_qx-nutdrv_qx_q1.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_q1.obj `if test -f 'nutdrv_qx_q1.c'; then $(CYGPATH_W) 'nutdrv_qx_q1.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_q1.c'; fi` nutdrv_qx-nutdrv_qx_q2.o: nutdrv_qx_q2.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_q2.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Tpo -c -o nutdrv_qx-nutdrv_qx_q2.o `test -f 'nutdrv_qx_q2.c' || echo '$(srcdir)/'`nutdrv_qx_q2.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_q2.c' object='nutdrv_qx-nutdrv_qx_q2.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_q2.o `test -f 'nutdrv_qx_q2.c' || echo '$(srcdir)/'`nutdrv_qx_q2.c nutdrv_qx-nutdrv_qx_q2.obj: nutdrv_qx_q2.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_q2.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Tpo -c -o nutdrv_qx-nutdrv_qx_q2.obj `if test -f 'nutdrv_qx_q2.c'; then $(CYGPATH_W) 'nutdrv_qx_q2.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_q2.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_q2.c' object='nutdrv_qx-nutdrv_qx_q2.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_q2.obj `if test -f 'nutdrv_qx_q2.c'; then $(CYGPATH_W) 'nutdrv_qx_q2.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_q2.c'; fi` nutdrv_qx-nutdrv_qx_q6.o: nutdrv_qx_q6.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_q6.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Tpo -c -o nutdrv_qx-nutdrv_qx_q6.o `test -f 'nutdrv_qx_q6.c' || echo '$(srcdir)/'`nutdrv_qx_q6.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_q6.c' object='nutdrv_qx-nutdrv_qx_q6.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_q6.o `test -f 'nutdrv_qx_q6.c' || echo '$(srcdir)/'`nutdrv_qx_q6.c nutdrv_qx-nutdrv_qx_q6.obj: nutdrv_qx_q6.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_q6.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Tpo -c -o nutdrv_qx-nutdrv_qx_q6.obj `if test -f 'nutdrv_qx_q6.c'; then $(CYGPATH_W) 'nutdrv_qx_q6.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_q6.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_q6.c' object='nutdrv_qx-nutdrv_qx_q6.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_q6.obj `if test -f 'nutdrv_qx_q6.c'; then $(CYGPATH_W) 'nutdrv_qx_q6.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_q6.c'; fi` nutdrv_qx-nutdrv_qx_voltronic.o: nutdrv_qx_voltronic.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic.o `test -f 'nutdrv_qx_voltronic.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic.c' object='nutdrv_qx-nutdrv_qx_voltronic.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic.o `test -f 'nutdrv_qx_voltronic.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic.c nutdrv_qx-nutdrv_qx_voltronic.obj: nutdrv_qx_voltronic.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic.obj `if test -f 'nutdrv_qx_voltronic.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic.c' object='nutdrv_qx-nutdrv_qx_voltronic.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic.obj `if test -f 'nutdrv_qx_voltronic.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic.c'; fi` nutdrv_qx-common_voltronic-crc.o: common_voltronic-crc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-common_voltronic-crc.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-common_voltronic-crc.Tpo -c -o nutdrv_qx-common_voltronic-crc.o `test -f 'common_voltronic-crc.c' || echo '$(srcdir)/'`common_voltronic-crc.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-common_voltronic-crc.Tpo $(DEPDIR)/nutdrv_qx-common_voltronic-crc.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='common_voltronic-crc.c' object='nutdrv_qx-common_voltronic-crc.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-common_voltronic-crc.o `test -f 'common_voltronic-crc.c' || echo '$(srcdir)/'`common_voltronic-crc.c nutdrv_qx-common_voltronic-crc.obj: common_voltronic-crc.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-common_voltronic-crc.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-common_voltronic-crc.Tpo -c -o nutdrv_qx-common_voltronic-crc.obj `if test -f 'common_voltronic-crc.c'; then $(CYGPATH_W) 'common_voltronic-crc.c'; else $(CYGPATH_W) '$(srcdir)/common_voltronic-crc.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-common_voltronic-crc.Tpo $(DEPDIR)/nutdrv_qx-common_voltronic-crc.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='common_voltronic-crc.c' object='nutdrv_qx-common_voltronic-crc.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-common_voltronic-crc.obj `if test -f 'common_voltronic-crc.c'; then $(CYGPATH_W) 'common_voltronic-crc.c'; else $(CYGPATH_W) '$(srcdir)/common_voltronic-crc.c'; fi` nutdrv_qx-nutdrv_qx_voltronic-axpert.o: nutdrv_qx_voltronic-axpert.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic-axpert.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic-axpert.o `test -f 'nutdrv_qx_voltronic-axpert.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic-axpert.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic-axpert.c' object='nutdrv_qx-nutdrv_qx_voltronic-axpert.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic-axpert.o `test -f 'nutdrv_qx_voltronic-axpert.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic-axpert.c nutdrv_qx-nutdrv_qx_voltronic-axpert.obj: nutdrv_qx_voltronic-axpert.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic-axpert.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic-axpert.obj `if test -f 'nutdrv_qx_voltronic-axpert.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic-axpert.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic-axpert.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic-axpert.c' object='nutdrv_qx-nutdrv_qx_voltronic-axpert.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic-axpert.obj `if test -f 'nutdrv_qx_voltronic-axpert.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic-axpert.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic-axpert.c'; fi` nutdrv_qx-nutdrv_qx_voltronic-qs.o: nutdrv_qx_voltronic-qs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic-qs.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic-qs.o `test -f 'nutdrv_qx_voltronic-qs.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic-qs.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic-qs.c' object='nutdrv_qx-nutdrv_qx_voltronic-qs.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic-qs.o `test -f 'nutdrv_qx_voltronic-qs.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic-qs.c nutdrv_qx-nutdrv_qx_voltronic-qs.obj: nutdrv_qx_voltronic-qs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic-qs.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic-qs.obj `if test -f 'nutdrv_qx_voltronic-qs.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic-qs.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic-qs.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic-qs.c' object='nutdrv_qx-nutdrv_qx_voltronic-qs.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic-qs.obj `if test -f 'nutdrv_qx_voltronic-qs.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic-qs.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic-qs.c'; fi` nutdrv_qx-nutdrv_qx_voltronic-qs-hex.o: nutdrv_qx_voltronic-qs-hex.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic-qs-hex.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic-qs-hex.o `test -f 'nutdrv_qx_voltronic-qs-hex.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic-qs-hex.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic-qs-hex.c' object='nutdrv_qx-nutdrv_qx_voltronic-qs-hex.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic-qs-hex.o `test -f 'nutdrv_qx_voltronic-qs-hex.c' || echo '$(srcdir)/'`nutdrv_qx_voltronic-qs-hex.c nutdrv_qx-nutdrv_qx_voltronic-qs-hex.obj: nutdrv_qx_voltronic-qs-hex.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_voltronic-qs-hex.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Tpo -c -o nutdrv_qx-nutdrv_qx_voltronic-qs-hex.obj `if test -f 'nutdrv_qx_voltronic-qs-hex.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic-qs-hex.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic-qs-hex.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_voltronic-qs-hex.c' object='nutdrv_qx-nutdrv_qx_voltronic-qs-hex.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_voltronic-qs-hex.obj `if test -f 'nutdrv_qx_voltronic-qs-hex.c'; then $(CYGPATH_W) 'nutdrv_qx_voltronic-qs-hex.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_voltronic-qs-hex.c'; fi` nutdrv_qx-nutdrv_qx_zinto.o: nutdrv_qx_zinto.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_zinto.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Tpo -c -o nutdrv_qx-nutdrv_qx_zinto.o `test -f 'nutdrv_qx_zinto.c' || echo '$(srcdir)/'`nutdrv_qx_zinto.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_zinto.c' object='nutdrv_qx-nutdrv_qx_zinto.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_zinto.o `test -f 'nutdrv_qx_zinto.c' || echo '$(srcdir)/'`nutdrv_qx_zinto.c nutdrv_qx-nutdrv_qx_zinto.obj: nutdrv_qx_zinto.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_zinto.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Tpo -c -o nutdrv_qx-nutdrv_qx_zinto.obj `if test -f 'nutdrv_qx_zinto.c'; then $(CYGPATH_W) 'nutdrv_qx_zinto.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_zinto.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_zinto.c' object='nutdrv_qx-nutdrv_qx_zinto.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_zinto.obj `if test -f 'nutdrv_qx_zinto.c'; then $(CYGPATH_W) 'nutdrv_qx_zinto.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_zinto.c'; fi` nutdrv_qx-nutdrv_qx_hunnox.o: nutdrv_qx_hunnox.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_hunnox.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Tpo -c -o nutdrv_qx-nutdrv_qx_hunnox.o `test -f 'nutdrv_qx_hunnox.c' || echo '$(srcdir)/'`nutdrv_qx_hunnox.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_hunnox.c' object='nutdrv_qx-nutdrv_qx_hunnox.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_hunnox.o `test -f 'nutdrv_qx_hunnox.c' || echo '$(srcdir)/'`nutdrv_qx_hunnox.c nutdrv_qx-nutdrv_qx_hunnox.obj: nutdrv_qx_hunnox.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_hunnox.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Tpo -c -o nutdrv_qx-nutdrv_qx_hunnox.obj `if test -f 'nutdrv_qx_hunnox.c'; then $(CYGPATH_W) 'nutdrv_qx_hunnox.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_hunnox.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_hunnox.c' object='nutdrv_qx-nutdrv_qx_hunnox.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_hunnox.obj `if test -f 'nutdrv_qx_hunnox.c'; then $(CYGPATH_W) 'nutdrv_qx_hunnox.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_hunnox.c'; fi` nutdrv_qx-nutdrv_qx_ablerex.o: nutdrv_qx_ablerex.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_ablerex.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Tpo -c -o nutdrv_qx-nutdrv_qx_ablerex.o `test -f 'nutdrv_qx_ablerex.c' || echo '$(srcdir)/'`nutdrv_qx_ablerex.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_ablerex.c' object='nutdrv_qx-nutdrv_qx_ablerex.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_ablerex.o `test -f 'nutdrv_qx_ablerex.c' || echo '$(srcdir)/'`nutdrv_qx_ablerex.c nutdrv_qx-nutdrv_qx_ablerex.obj: nutdrv_qx_ablerex.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_ablerex.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Tpo -c -o nutdrv_qx-nutdrv_qx_ablerex.obj `if test -f 'nutdrv_qx_ablerex.c'; then $(CYGPATH_W) 'nutdrv_qx_ablerex.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_ablerex.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_ablerex.c' object='nutdrv_qx-nutdrv_qx_ablerex.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_ablerex.obj `if test -f 'nutdrv_qx_ablerex.c'; then $(CYGPATH_W) 'nutdrv_qx_ablerex.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_ablerex.c'; fi` nutdrv_qx-nutdrv_qx_gtec.o: nutdrv_qx_gtec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_gtec.o -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Tpo -c -o nutdrv_qx-nutdrv_qx_gtec.o `test -f 'nutdrv_qx_gtec.c' || echo '$(srcdir)/'`nutdrv_qx_gtec.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_gtec.c' object='nutdrv_qx-nutdrv_qx_gtec.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_gtec.o `test -f 'nutdrv_qx_gtec.c' || echo '$(srcdir)/'`nutdrv_qx_gtec.c nutdrv_qx-nutdrv_qx_gtec.obj: nutdrv_qx_gtec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -MT nutdrv_qx-nutdrv_qx_gtec.obj -MD -MP -MF $(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Tpo -c -o nutdrv_qx-nutdrv_qx_gtec.obj `if test -f 'nutdrv_qx_gtec.c'; then $(CYGPATH_W) 'nutdrv_qx_gtec.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_gtec.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Tpo $(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='nutdrv_qx_gtec.c' object='nutdrv_qx-nutdrv_qx_gtec.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(nutdrv_qx_CFLAGS) $(CFLAGS) -c -o nutdrv_qx-nutdrv_qx_gtec.obj `if test -f 'nutdrv_qx_gtec.c'; then $(CYGPATH_W) 'nutdrv_qx_gtec.c'; else $(CYGPATH_W) '$(srcdir)/nutdrv_qx_gtec.c'; fi` powervar_cx_ser-powervar_cx_ser.o: powervar_cx_ser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -MT powervar_cx_ser-powervar_cx_ser.o -MD -MP -MF $(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Tpo -c -o powervar_cx_ser-powervar_cx_ser.o `test -f 'powervar_cx_ser.c' || echo '$(srcdir)/'`powervar_cx_ser.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Tpo $(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx_ser.c' object='powervar_cx_ser-powervar_cx_ser.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -c -o powervar_cx_ser-powervar_cx_ser.o `test -f 'powervar_cx_ser.c' || echo '$(srcdir)/'`powervar_cx_ser.c powervar_cx_ser-powervar_cx_ser.obj: powervar_cx_ser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -MT powervar_cx_ser-powervar_cx_ser.obj -MD -MP -MF $(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Tpo -c -o powervar_cx_ser-powervar_cx_ser.obj `if test -f 'powervar_cx_ser.c'; then $(CYGPATH_W) 'powervar_cx_ser.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx_ser.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Tpo $(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx_ser.c' object='powervar_cx_ser-powervar_cx_ser.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -c -o powervar_cx_ser-powervar_cx_ser.obj `if test -f 'powervar_cx_ser.c'; then $(CYGPATH_W) 'powervar_cx_ser.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx_ser.c'; fi` powervar_cx_ser-powervar_cx.o: powervar_cx.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -MT powervar_cx_ser-powervar_cx.o -MD -MP -MF $(DEPDIR)/powervar_cx_ser-powervar_cx.Tpo -c -o powervar_cx_ser-powervar_cx.o `test -f 'powervar_cx.c' || echo '$(srcdir)/'`powervar_cx.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_ser-powervar_cx.Tpo $(DEPDIR)/powervar_cx_ser-powervar_cx.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx.c' object='powervar_cx_ser-powervar_cx.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -c -o powervar_cx_ser-powervar_cx.o `test -f 'powervar_cx.c' || echo '$(srcdir)/'`powervar_cx.c powervar_cx_ser-powervar_cx.obj: powervar_cx.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -MT powervar_cx_ser-powervar_cx.obj -MD -MP -MF $(DEPDIR)/powervar_cx_ser-powervar_cx.Tpo -c -o powervar_cx_ser-powervar_cx.obj `if test -f 'powervar_cx.c'; then $(CYGPATH_W) 'powervar_cx.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_ser-powervar_cx.Tpo $(DEPDIR)/powervar_cx_ser-powervar_cx.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx.c' object='powervar_cx_ser-powervar_cx.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_ser_CFLAGS) $(CFLAGS) -c -o powervar_cx_ser-powervar_cx.obj `if test -f 'powervar_cx.c'; then $(CYGPATH_W) 'powervar_cx.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx.c'; fi` powervar_cx_usb-powervar_cx_usb.o: powervar_cx_usb.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-powervar_cx_usb.o -MD -MP -MF $(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Tpo -c -o powervar_cx_usb-powervar_cx_usb.o `test -f 'powervar_cx_usb.c' || echo '$(srcdir)/'`powervar_cx_usb.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Tpo $(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx_usb.c' object='powervar_cx_usb-powervar_cx_usb.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-powervar_cx_usb.o `test -f 'powervar_cx_usb.c' || echo '$(srcdir)/'`powervar_cx_usb.c powervar_cx_usb-powervar_cx_usb.obj: powervar_cx_usb.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-powervar_cx_usb.obj -MD -MP -MF $(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Tpo -c -o powervar_cx_usb-powervar_cx_usb.obj `if test -f 'powervar_cx_usb.c'; then $(CYGPATH_W) 'powervar_cx_usb.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx_usb.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Tpo $(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx_usb.c' object='powervar_cx_usb-powervar_cx_usb.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-powervar_cx_usb.obj `if test -f 'powervar_cx_usb.c'; then $(CYGPATH_W) 'powervar_cx_usb.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx_usb.c'; fi` powervar_cx_usb-powervar_cx.o: powervar_cx.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-powervar_cx.o -MD -MP -MF $(DEPDIR)/powervar_cx_usb-powervar_cx.Tpo -c -o powervar_cx_usb-powervar_cx.o `test -f 'powervar_cx.c' || echo '$(srcdir)/'`powervar_cx.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-powervar_cx.Tpo $(DEPDIR)/powervar_cx_usb-powervar_cx.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx.c' object='powervar_cx_usb-powervar_cx.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-powervar_cx.o `test -f 'powervar_cx.c' || echo '$(srcdir)/'`powervar_cx.c powervar_cx_usb-powervar_cx.obj: powervar_cx.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-powervar_cx.obj -MD -MP -MF $(DEPDIR)/powervar_cx_usb-powervar_cx.Tpo -c -o powervar_cx_usb-powervar_cx.obj `if test -f 'powervar_cx.c'; then $(CYGPATH_W) 'powervar_cx.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-powervar_cx.Tpo $(DEPDIR)/powervar_cx_usb-powervar_cx.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='powervar_cx.c' object='powervar_cx_usb-powervar_cx.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-powervar_cx.obj `if test -f 'powervar_cx.c'; then $(CYGPATH_W) 'powervar_cx.c'; else $(CYGPATH_W) '$(srcdir)/powervar_cx.c'; fi` powervar_cx_usb-libusb0.o: libusb0.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-libusb0.o -MD -MP -MF $(DEPDIR)/powervar_cx_usb-libusb0.Tpo -c -o powervar_cx_usb-libusb0.o `test -f 'libusb0.c' || echo '$(srcdir)/'`libusb0.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-libusb0.Tpo $(DEPDIR)/powervar_cx_usb-libusb0.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb0.c' object='powervar_cx_usb-libusb0.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-libusb0.o `test -f 'libusb0.c' || echo '$(srcdir)/'`libusb0.c powervar_cx_usb-libusb0.obj: libusb0.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-libusb0.obj -MD -MP -MF $(DEPDIR)/powervar_cx_usb-libusb0.Tpo -c -o powervar_cx_usb-libusb0.obj `if test -f 'libusb0.c'; then $(CYGPATH_W) 'libusb0.c'; else $(CYGPATH_W) '$(srcdir)/libusb0.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-libusb0.Tpo $(DEPDIR)/powervar_cx_usb-libusb0.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb0.c' object='powervar_cx_usb-libusb0.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-libusb0.obj `if test -f 'libusb0.c'; then $(CYGPATH_W) 'libusb0.c'; else $(CYGPATH_W) '$(srcdir)/libusb0.c'; fi` powervar_cx_usb-libusb1.o: libusb1.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-libusb1.o -MD -MP -MF $(DEPDIR)/powervar_cx_usb-libusb1.Tpo -c -o powervar_cx_usb-libusb1.o `test -f 'libusb1.c' || echo '$(srcdir)/'`libusb1.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-libusb1.Tpo $(DEPDIR)/powervar_cx_usb-libusb1.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb1.c' object='powervar_cx_usb-libusb1.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-libusb1.o `test -f 'libusb1.c' || echo '$(srcdir)/'`libusb1.c powervar_cx_usb-libusb1.obj: libusb1.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-libusb1.obj -MD -MP -MF $(DEPDIR)/powervar_cx_usb-libusb1.Tpo -c -o powervar_cx_usb-libusb1.obj `if test -f 'libusb1.c'; then $(CYGPATH_W) 'libusb1.c'; else $(CYGPATH_W) '$(srcdir)/libusb1.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-libusb1.Tpo $(DEPDIR)/powervar_cx_usb-libusb1.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libusb1.c' object='powervar_cx_usb-libusb1.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-libusb1.obj `if test -f 'libusb1.c'; then $(CYGPATH_W) 'libusb1.c'; else $(CYGPATH_W) '$(srcdir)/libusb1.c'; fi` powervar_cx_usb-usb-common.o: usb-common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-usb-common.o -MD -MP -MF $(DEPDIR)/powervar_cx_usb-usb-common.Tpo -c -o powervar_cx_usb-usb-common.o `test -f 'usb-common.c' || echo '$(srcdir)/'`usb-common.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-usb-common.Tpo $(DEPDIR)/powervar_cx_usb-usb-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='usb-common.c' object='powervar_cx_usb-usb-common.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-usb-common.o `test -f 'usb-common.c' || echo '$(srcdir)/'`usb-common.c powervar_cx_usb-usb-common.obj: usb-common.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -MT powervar_cx_usb-usb-common.obj -MD -MP -MF $(DEPDIR)/powervar_cx_usb-usb-common.Tpo -c -o powervar_cx_usb-usb-common.obj `if test -f 'usb-common.c'; then $(CYGPATH_W) 'usb-common.c'; else $(CYGPATH_W) '$(srcdir)/usb-common.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/powervar_cx_usb-usb-common.Tpo $(DEPDIR)/powervar_cx_usb-usb-common.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='usb-common.c' object='powervar_cx_usb-usb-common.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(powervar_cx_usb_CFLAGS) $(CFLAGS) -c -o powervar_cx_usb-usb-common.obj `if test -f 'usb-common.c'; then $(CYGPATH_W) 'usb-common.c'; else $(CYGPATH_W) '$(srcdir)/usb-common.c'; fi` snmp_ups-snmp-ups.o: snmp-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-snmp-ups.o -MD -MP -MF $(DEPDIR)/snmp_ups-snmp-ups.Tpo -c -o snmp_ups-snmp-ups.o `test -f 'snmp-ups.c' || echo '$(srcdir)/'`snmp-ups.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-snmp-ups.Tpo $(DEPDIR)/snmp_ups-snmp-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='snmp-ups.c' object='snmp_ups-snmp-ups.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-snmp-ups.o `test -f 'snmp-ups.c' || echo '$(srcdir)/'`snmp-ups.c snmp_ups-snmp-ups.obj: snmp-ups.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-snmp-ups.obj -MD -MP -MF $(DEPDIR)/snmp_ups-snmp-ups.Tpo -c -o snmp_ups-snmp-ups.obj `if test -f 'snmp-ups.c'; then $(CYGPATH_W) 'snmp-ups.c'; else $(CYGPATH_W) '$(srcdir)/snmp-ups.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-snmp-ups.Tpo $(DEPDIR)/snmp_ups-snmp-ups.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='snmp-ups.c' object='snmp_ups-snmp-ups.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-snmp-ups.obj `if test -f 'snmp-ups.c'; then $(CYGPATH_W) 'snmp-ups.c'; else $(CYGPATH_W) '$(srcdir)/snmp-ups.c'; fi` snmp_ups-snmp-ups-helpers.o: snmp-ups-helpers.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-snmp-ups-helpers.o -MD -MP -MF $(DEPDIR)/snmp_ups-snmp-ups-helpers.Tpo -c -o snmp_ups-snmp-ups-helpers.o `test -f 'snmp-ups-helpers.c' || echo '$(srcdir)/'`snmp-ups-helpers.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-snmp-ups-helpers.Tpo $(DEPDIR)/snmp_ups-snmp-ups-helpers.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='snmp-ups-helpers.c' object='snmp_ups-snmp-ups-helpers.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-snmp-ups-helpers.o `test -f 'snmp-ups-helpers.c' || echo '$(srcdir)/'`snmp-ups-helpers.c snmp_ups-snmp-ups-helpers.obj: snmp-ups-helpers.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-snmp-ups-helpers.obj -MD -MP -MF $(DEPDIR)/snmp_ups-snmp-ups-helpers.Tpo -c -o snmp_ups-snmp-ups-helpers.obj `if test -f 'snmp-ups-helpers.c'; then $(CYGPATH_W) 'snmp-ups-helpers.c'; else $(CYGPATH_W) '$(srcdir)/snmp-ups-helpers.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-snmp-ups-helpers.Tpo $(DEPDIR)/snmp_ups-snmp-ups-helpers.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='snmp-ups-helpers.c' object='snmp_ups-snmp-ups-helpers.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-snmp-ups-helpers.obj `if test -f 'snmp-ups-helpers.c'; then $(CYGPATH_W) 'snmp-ups-helpers.c'; else $(CYGPATH_W) '$(srcdir)/snmp-ups-helpers.c'; fi` snmp_ups-apc-mib.o: apc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-apc-mib.Tpo -c -o snmp_ups-apc-mib.o `test -f 'apc-mib.c' || echo '$(srcdir)/'`apc-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-mib.Tpo $(DEPDIR)/snmp_ups-apc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-mib.c' object='snmp_ups-apc-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-mib.o `test -f 'apc-mib.c' || echo '$(srcdir)/'`apc-mib.c snmp_ups-apc-mib.obj: apc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-apc-mib.Tpo -c -o snmp_ups-apc-mib.obj `if test -f 'apc-mib.c'; then $(CYGPATH_W) 'apc-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-mib.Tpo $(DEPDIR)/snmp_ups-apc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-mib.c' object='snmp_ups-apc-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-mib.obj `if test -f 'apc-mib.c'; then $(CYGPATH_W) 'apc-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-mib.c'; fi` snmp_ups-apc-pdu-mib.o: apc-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-pdu-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-apc-pdu-mib.Tpo -c -o snmp_ups-apc-pdu-mib.o `test -f 'apc-pdu-mib.c' || echo '$(srcdir)/'`apc-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-pdu-mib.Tpo $(DEPDIR)/snmp_ups-apc-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-pdu-mib.c' object='snmp_ups-apc-pdu-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-pdu-mib.o `test -f 'apc-pdu-mib.c' || echo '$(srcdir)/'`apc-pdu-mib.c snmp_ups-apc-pdu-mib.obj: apc-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-pdu-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-apc-pdu-mib.Tpo -c -o snmp_ups-apc-pdu-mib.obj `if test -f 'apc-pdu-mib.c'; then $(CYGPATH_W) 'apc-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-pdu-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-pdu-mib.Tpo $(DEPDIR)/snmp_ups-apc-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-pdu-mib.c' object='snmp_ups-apc-pdu-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-pdu-mib.obj `if test -f 'apc-pdu-mib.c'; then $(CYGPATH_W) 'apc-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-pdu-mib.c'; fi` snmp_ups-apc-epdu-mib.o: apc-epdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-epdu-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-apc-epdu-mib.Tpo -c -o snmp_ups-apc-epdu-mib.o `test -f 'apc-epdu-mib.c' || echo '$(srcdir)/'`apc-epdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-epdu-mib.Tpo $(DEPDIR)/snmp_ups-apc-epdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-epdu-mib.c' object='snmp_ups-apc-epdu-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-epdu-mib.o `test -f 'apc-epdu-mib.c' || echo '$(srcdir)/'`apc-epdu-mib.c snmp_ups-apc-epdu-mib.obj: apc-epdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-epdu-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-apc-epdu-mib.Tpo -c -o snmp_ups-apc-epdu-mib.obj `if test -f 'apc-epdu-mib.c'; then $(CYGPATH_W) 'apc-epdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-epdu-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-epdu-mib.Tpo $(DEPDIR)/snmp_ups-apc-epdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-epdu-mib.c' object='snmp_ups-apc-epdu-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-epdu-mib.obj `if test -f 'apc-epdu-mib.c'; then $(CYGPATH_W) 'apc-epdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-epdu-mib.c'; fi` snmp_ups-baytech-mib.o: baytech-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-baytech-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-baytech-mib.Tpo -c -o snmp_ups-baytech-mib.o `test -f 'baytech-mib.c' || echo '$(srcdir)/'`baytech-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-baytech-mib.Tpo $(DEPDIR)/snmp_ups-baytech-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='baytech-mib.c' object='snmp_ups-baytech-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-baytech-mib.o `test -f 'baytech-mib.c' || echo '$(srcdir)/'`baytech-mib.c snmp_ups-baytech-mib.obj: baytech-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-baytech-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-baytech-mib.Tpo -c -o snmp_ups-baytech-mib.obj `if test -f 'baytech-mib.c'; then $(CYGPATH_W) 'baytech-mib.c'; else $(CYGPATH_W) '$(srcdir)/baytech-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-baytech-mib.Tpo $(DEPDIR)/snmp_ups-baytech-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='baytech-mib.c' object='snmp_ups-baytech-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-baytech-mib.obj `if test -f 'baytech-mib.c'; then $(CYGPATH_W) 'baytech-mib.c'; else $(CYGPATH_W) '$(srcdir)/baytech-mib.c'; fi` snmp_ups-baytech-rpc3nc-mib.o: baytech-rpc3nc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-baytech-rpc3nc-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Tpo -c -o snmp_ups-baytech-rpc3nc-mib.o `test -f 'baytech-rpc3nc-mib.c' || echo '$(srcdir)/'`baytech-rpc3nc-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Tpo $(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='baytech-rpc3nc-mib.c' object='snmp_ups-baytech-rpc3nc-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-baytech-rpc3nc-mib.o `test -f 'baytech-rpc3nc-mib.c' || echo '$(srcdir)/'`baytech-rpc3nc-mib.c snmp_ups-baytech-rpc3nc-mib.obj: baytech-rpc3nc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-baytech-rpc3nc-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Tpo -c -o snmp_ups-baytech-rpc3nc-mib.obj `if test -f 'baytech-rpc3nc-mib.c'; then $(CYGPATH_W) 'baytech-rpc3nc-mib.c'; else $(CYGPATH_W) '$(srcdir)/baytech-rpc3nc-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Tpo $(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='baytech-rpc3nc-mib.c' object='snmp_ups-baytech-rpc3nc-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-baytech-rpc3nc-mib.obj `if test -f 'baytech-rpc3nc-mib.c'; then $(CYGPATH_W) 'baytech-rpc3nc-mib.c'; else $(CYGPATH_W) '$(srcdir)/baytech-rpc3nc-mib.c'; fi` snmp_ups-bestpower-mib.o: bestpower-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-bestpower-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-bestpower-mib.Tpo -c -o snmp_ups-bestpower-mib.o `test -f 'bestpower-mib.c' || echo '$(srcdir)/'`bestpower-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-bestpower-mib.Tpo $(DEPDIR)/snmp_ups-bestpower-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bestpower-mib.c' object='snmp_ups-bestpower-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-bestpower-mib.o `test -f 'bestpower-mib.c' || echo '$(srcdir)/'`bestpower-mib.c snmp_ups-bestpower-mib.obj: bestpower-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-bestpower-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-bestpower-mib.Tpo -c -o snmp_ups-bestpower-mib.obj `if test -f 'bestpower-mib.c'; then $(CYGPATH_W) 'bestpower-mib.c'; else $(CYGPATH_W) '$(srcdir)/bestpower-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-bestpower-mib.Tpo $(DEPDIR)/snmp_ups-bestpower-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bestpower-mib.c' object='snmp_ups-bestpower-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-bestpower-mib.obj `if test -f 'bestpower-mib.c'; then $(CYGPATH_W) 'bestpower-mib.c'; else $(CYGPATH_W) '$(srcdir)/bestpower-mib.c'; fi` snmp_ups-compaq-mib.o: compaq-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-compaq-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-compaq-mib.Tpo -c -o snmp_ups-compaq-mib.o `test -f 'compaq-mib.c' || echo '$(srcdir)/'`compaq-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-compaq-mib.Tpo $(DEPDIR)/snmp_ups-compaq-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='compaq-mib.c' object='snmp_ups-compaq-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-compaq-mib.o `test -f 'compaq-mib.c' || echo '$(srcdir)/'`compaq-mib.c snmp_ups-compaq-mib.obj: compaq-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-compaq-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-compaq-mib.Tpo -c -o snmp_ups-compaq-mib.obj `if test -f 'compaq-mib.c'; then $(CYGPATH_W) 'compaq-mib.c'; else $(CYGPATH_W) '$(srcdir)/compaq-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-compaq-mib.Tpo $(DEPDIR)/snmp_ups-compaq-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='compaq-mib.c' object='snmp_ups-compaq-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-compaq-mib.obj `if test -f 'compaq-mib.c'; then $(CYGPATH_W) 'compaq-mib.c'; else $(CYGPATH_W) '$(srcdir)/compaq-mib.c'; fi` snmp_ups-cyberpower-mib.o: cyberpower-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-cyberpower-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-cyberpower-mib.Tpo -c -o snmp_ups-cyberpower-mib.o `test -f 'cyberpower-mib.c' || echo '$(srcdir)/'`cyberpower-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-cyberpower-mib.Tpo $(DEPDIR)/snmp_ups-cyberpower-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cyberpower-mib.c' object='snmp_ups-cyberpower-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-cyberpower-mib.o `test -f 'cyberpower-mib.c' || echo '$(srcdir)/'`cyberpower-mib.c snmp_ups-cyberpower-mib.obj: cyberpower-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-cyberpower-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-cyberpower-mib.Tpo -c -o snmp_ups-cyberpower-mib.obj `if test -f 'cyberpower-mib.c'; then $(CYGPATH_W) 'cyberpower-mib.c'; else $(CYGPATH_W) '$(srcdir)/cyberpower-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-cyberpower-mib.Tpo $(DEPDIR)/snmp_ups-cyberpower-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='cyberpower-mib.c' object='snmp_ups-cyberpower-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-cyberpower-mib.obj `if test -f 'cyberpower-mib.c'; then $(CYGPATH_W) 'cyberpower-mib.c'; else $(CYGPATH_W) '$(srcdir)/cyberpower-mib.c'; fi` snmp_ups-delta_ups-mib.o: delta_ups-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-delta_ups-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-delta_ups-mib.Tpo -c -o snmp_ups-delta_ups-mib.o `test -f 'delta_ups-mib.c' || echo '$(srcdir)/'`delta_ups-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-delta_ups-mib.Tpo $(DEPDIR)/snmp_ups-delta_ups-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='delta_ups-mib.c' object='snmp_ups-delta_ups-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-delta_ups-mib.o `test -f 'delta_ups-mib.c' || echo '$(srcdir)/'`delta_ups-mib.c snmp_ups-delta_ups-mib.obj: delta_ups-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-delta_ups-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-delta_ups-mib.Tpo -c -o snmp_ups-delta_ups-mib.obj `if test -f 'delta_ups-mib.c'; then $(CYGPATH_W) 'delta_ups-mib.c'; else $(CYGPATH_W) '$(srcdir)/delta_ups-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-delta_ups-mib.Tpo $(DEPDIR)/snmp_ups-delta_ups-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='delta_ups-mib.c' object='snmp_ups-delta_ups-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-delta_ups-mib.obj `if test -f 'delta_ups-mib.c'; then $(CYGPATH_W) 'delta_ups-mib.c'; else $(CYGPATH_W) '$(srcdir)/delta_ups-mib.c'; fi` snmp_ups-eaton-pdu-genesis2-mib.o: eaton-pdu-genesis2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-genesis2-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Tpo -c -o snmp_ups-eaton-pdu-genesis2-mib.o `test -f 'eaton-pdu-genesis2-mib.c' || echo '$(srcdir)/'`eaton-pdu-genesis2-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-genesis2-mib.c' object='snmp_ups-eaton-pdu-genesis2-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-genesis2-mib.o `test -f 'eaton-pdu-genesis2-mib.c' || echo '$(srcdir)/'`eaton-pdu-genesis2-mib.c snmp_ups-eaton-pdu-genesis2-mib.obj: eaton-pdu-genesis2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-genesis2-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Tpo -c -o snmp_ups-eaton-pdu-genesis2-mib.obj `if test -f 'eaton-pdu-genesis2-mib.c'; then $(CYGPATH_W) 'eaton-pdu-genesis2-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-genesis2-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-genesis2-mib.c' object='snmp_ups-eaton-pdu-genesis2-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-genesis2-mib.obj `if test -f 'eaton-pdu-genesis2-mib.c'; then $(CYGPATH_W) 'eaton-pdu-genesis2-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-genesis2-mib.c'; fi` snmp_ups-eaton-pdu-marlin-mib.o: eaton-pdu-marlin-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-marlin-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Tpo -c -o snmp_ups-eaton-pdu-marlin-mib.o `test -f 'eaton-pdu-marlin-mib.c' || echo '$(srcdir)/'`eaton-pdu-marlin-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-marlin-mib.c' object='snmp_ups-eaton-pdu-marlin-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-marlin-mib.o `test -f 'eaton-pdu-marlin-mib.c' || echo '$(srcdir)/'`eaton-pdu-marlin-mib.c snmp_ups-eaton-pdu-marlin-mib.obj: eaton-pdu-marlin-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-marlin-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Tpo -c -o snmp_ups-eaton-pdu-marlin-mib.obj `if test -f 'eaton-pdu-marlin-mib.c'; then $(CYGPATH_W) 'eaton-pdu-marlin-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-marlin-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-marlin-mib.c' object='snmp_ups-eaton-pdu-marlin-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-marlin-mib.obj `if test -f 'eaton-pdu-marlin-mib.c'; then $(CYGPATH_W) 'eaton-pdu-marlin-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-marlin-mib.c'; fi` snmp_ups-eaton-pdu-marlin-helpers.o: eaton-pdu-marlin-helpers.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-marlin-helpers.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Tpo -c -o snmp_ups-eaton-pdu-marlin-helpers.o `test -f 'eaton-pdu-marlin-helpers.c' || echo '$(srcdir)/'`eaton-pdu-marlin-helpers.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-marlin-helpers.c' object='snmp_ups-eaton-pdu-marlin-helpers.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-marlin-helpers.o `test -f 'eaton-pdu-marlin-helpers.c' || echo '$(srcdir)/'`eaton-pdu-marlin-helpers.c snmp_ups-eaton-pdu-marlin-helpers.obj: eaton-pdu-marlin-helpers.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-marlin-helpers.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Tpo -c -o snmp_ups-eaton-pdu-marlin-helpers.obj `if test -f 'eaton-pdu-marlin-helpers.c'; then $(CYGPATH_W) 'eaton-pdu-marlin-helpers.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-marlin-helpers.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-marlin-helpers.c' object='snmp_ups-eaton-pdu-marlin-helpers.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-marlin-helpers.obj `if test -f 'eaton-pdu-marlin-helpers.c'; then $(CYGPATH_W) 'eaton-pdu-marlin-helpers.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-marlin-helpers.c'; fi` snmp_ups-eaton-pdu-pulizzi-mib.o: eaton-pdu-pulizzi-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-pulizzi-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Tpo -c -o snmp_ups-eaton-pdu-pulizzi-mib.o `test -f 'eaton-pdu-pulizzi-mib.c' || echo '$(srcdir)/'`eaton-pdu-pulizzi-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-pulizzi-mib.c' object='snmp_ups-eaton-pdu-pulizzi-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-pulizzi-mib.o `test -f 'eaton-pdu-pulizzi-mib.c' || echo '$(srcdir)/'`eaton-pdu-pulizzi-mib.c snmp_ups-eaton-pdu-pulizzi-mib.obj: eaton-pdu-pulizzi-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-pulizzi-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Tpo -c -o snmp_ups-eaton-pdu-pulizzi-mib.obj `if test -f 'eaton-pdu-pulizzi-mib.c'; then $(CYGPATH_W) 'eaton-pdu-pulizzi-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-pulizzi-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-pulizzi-mib.c' object='snmp_ups-eaton-pdu-pulizzi-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-pulizzi-mib.obj `if test -f 'eaton-pdu-pulizzi-mib.c'; then $(CYGPATH_W) 'eaton-pdu-pulizzi-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-pulizzi-mib.c'; fi` snmp_ups-eaton-pdu-revelation-mib.o: eaton-pdu-revelation-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-revelation-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Tpo -c -o snmp_ups-eaton-pdu-revelation-mib.o `test -f 'eaton-pdu-revelation-mib.c' || echo '$(srcdir)/'`eaton-pdu-revelation-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-revelation-mib.c' object='snmp_ups-eaton-pdu-revelation-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-revelation-mib.o `test -f 'eaton-pdu-revelation-mib.c' || echo '$(srcdir)/'`eaton-pdu-revelation-mib.c snmp_ups-eaton-pdu-revelation-mib.obj: eaton-pdu-revelation-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-revelation-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Tpo -c -o snmp_ups-eaton-pdu-revelation-mib.obj `if test -f 'eaton-pdu-revelation-mib.c'; then $(CYGPATH_W) 'eaton-pdu-revelation-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-revelation-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-revelation-mib.c' object='snmp_ups-eaton-pdu-revelation-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-revelation-mib.obj `if test -f 'eaton-pdu-revelation-mib.c'; then $(CYGPATH_W) 'eaton-pdu-revelation-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-revelation-mib.c'; fi` snmp_ups-eaton-pdu-nlogic-mib.o: eaton-pdu-nlogic-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-nlogic-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Tpo -c -o snmp_ups-eaton-pdu-nlogic-mib.o `test -f 'eaton-pdu-nlogic-mib.c' || echo '$(srcdir)/'`eaton-pdu-nlogic-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-nlogic-mib.c' object='snmp_ups-eaton-pdu-nlogic-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-nlogic-mib.o `test -f 'eaton-pdu-nlogic-mib.c' || echo '$(srcdir)/'`eaton-pdu-nlogic-mib.c snmp_ups-eaton-pdu-nlogic-mib.obj: eaton-pdu-nlogic-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-pdu-nlogic-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Tpo -c -o snmp_ups-eaton-pdu-nlogic-mib.obj `if test -f 'eaton-pdu-nlogic-mib.c'; then $(CYGPATH_W) 'eaton-pdu-nlogic-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-nlogic-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Tpo $(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-pdu-nlogic-mib.c' object='snmp_ups-eaton-pdu-nlogic-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-pdu-nlogic-mib.obj `if test -f 'eaton-pdu-nlogic-mib.c'; then $(CYGPATH_W) 'eaton-pdu-nlogic-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-pdu-nlogic-mib.c'; fi` snmp_ups-eaton-ats16-nmc-mib.o: eaton-ats16-nmc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ats16-nmc-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Tpo -c -o snmp_ups-eaton-ats16-nmc-mib.o `test -f 'eaton-ats16-nmc-mib.c' || echo '$(srcdir)/'`eaton-ats16-nmc-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ats16-nmc-mib.c' object='snmp_ups-eaton-ats16-nmc-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ats16-nmc-mib.o `test -f 'eaton-ats16-nmc-mib.c' || echo '$(srcdir)/'`eaton-ats16-nmc-mib.c snmp_ups-eaton-ats16-nmc-mib.obj: eaton-ats16-nmc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ats16-nmc-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Tpo -c -o snmp_ups-eaton-ats16-nmc-mib.obj `if test -f 'eaton-ats16-nmc-mib.c'; then $(CYGPATH_W) 'eaton-ats16-nmc-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ats16-nmc-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ats16-nmc-mib.c' object='snmp_ups-eaton-ats16-nmc-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ats16-nmc-mib.obj `if test -f 'eaton-ats16-nmc-mib.c'; then $(CYGPATH_W) 'eaton-ats16-nmc-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ats16-nmc-mib.c'; fi` snmp_ups-eaton-ats16-nm2-mib.o: eaton-ats16-nm2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ats16-nm2-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Tpo -c -o snmp_ups-eaton-ats16-nm2-mib.o `test -f 'eaton-ats16-nm2-mib.c' || echo '$(srcdir)/'`eaton-ats16-nm2-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ats16-nm2-mib.c' object='snmp_ups-eaton-ats16-nm2-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ats16-nm2-mib.o `test -f 'eaton-ats16-nm2-mib.c' || echo '$(srcdir)/'`eaton-ats16-nm2-mib.c snmp_ups-eaton-ats16-nm2-mib.obj: eaton-ats16-nm2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ats16-nm2-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Tpo -c -o snmp_ups-eaton-ats16-nm2-mib.obj `if test -f 'eaton-ats16-nm2-mib.c'; then $(CYGPATH_W) 'eaton-ats16-nm2-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ats16-nm2-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ats16-nm2-mib.c' object='snmp_ups-eaton-ats16-nm2-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ats16-nm2-mib.obj `if test -f 'eaton-ats16-nm2-mib.c'; then $(CYGPATH_W) 'eaton-ats16-nm2-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ats16-nm2-mib.c'; fi` snmp_ups-apc-ats-mib.o: apc-ats-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-ats-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-apc-ats-mib.Tpo -c -o snmp_ups-apc-ats-mib.o `test -f 'apc-ats-mib.c' || echo '$(srcdir)/'`apc-ats-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-ats-mib.Tpo $(DEPDIR)/snmp_ups-apc-ats-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-ats-mib.c' object='snmp_ups-apc-ats-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-ats-mib.o `test -f 'apc-ats-mib.c' || echo '$(srcdir)/'`apc-ats-mib.c snmp_ups-apc-ats-mib.obj: apc-ats-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-apc-ats-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-apc-ats-mib.Tpo -c -o snmp_ups-apc-ats-mib.obj `if test -f 'apc-ats-mib.c'; then $(CYGPATH_W) 'apc-ats-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-ats-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-apc-ats-mib.Tpo $(DEPDIR)/snmp_ups-apc-ats-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='apc-ats-mib.c' object='snmp_ups-apc-ats-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-apc-ats-mib.obj `if test -f 'apc-ats-mib.c'; then $(CYGPATH_W) 'apc-ats-mib.c'; else $(CYGPATH_W) '$(srcdir)/apc-ats-mib.c'; fi` snmp_ups-eaton-ats30-mib.o: eaton-ats30-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ats30-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ats30-mib.Tpo -c -o snmp_ups-eaton-ats30-mib.o `test -f 'eaton-ats30-mib.c' || echo '$(srcdir)/'`eaton-ats30-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ats30-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ats30-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ats30-mib.c' object='snmp_ups-eaton-ats30-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ats30-mib.o `test -f 'eaton-ats30-mib.c' || echo '$(srcdir)/'`eaton-ats30-mib.c snmp_ups-eaton-ats30-mib.obj: eaton-ats30-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ats30-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ats30-mib.Tpo -c -o snmp_ups-eaton-ats30-mib.obj `if test -f 'eaton-ats30-mib.c'; then $(CYGPATH_W) 'eaton-ats30-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ats30-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ats30-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ats30-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ats30-mib.c' object='snmp_ups-eaton-ats30-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ats30-mib.obj `if test -f 'eaton-ats30-mib.c'; then $(CYGPATH_W) 'eaton-ats30-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ats30-mib.c'; fi` snmp_ups-eaton-ups-pwnm2-mib.o: eaton-ups-pwnm2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ups-pwnm2-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Tpo -c -o snmp_ups-eaton-ups-pwnm2-mib.o `test -f 'eaton-ups-pwnm2-mib.c' || echo '$(srcdir)/'`eaton-ups-pwnm2-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ups-pwnm2-mib.c' object='snmp_ups-eaton-ups-pwnm2-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ups-pwnm2-mib.o `test -f 'eaton-ups-pwnm2-mib.c' || echo '$(srcdir)/'`eaton-ups-pwnm2-mib.c snmp_ups-eaton-ups-pwnm2-mib.obj: eaton-ups-pwnm2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ups-pwnm2-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Tpo -c -o snmp_ups-eaton-ups-pwnm2-mib.obj `if test -f 'eaton-ups-pwnm2-mib.c'; then $(CYGPATH_W) 'eaton-ups-pwnm2-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ups-pwnm2-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ups-pwnm2-mib.c' object='snmp_ups-eaton-ups-pwnm2-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ups-pwnm2-mib.obj `if test -f 'eaton-ups-pwnm2-mib.c'; then $(CYGPATH_W) 'eaton-ups-pwnm2-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ups-pwnm2-mib.c'; fi` snmp_ups-eaton-ups-pxg-mib.o: eaton-ups-pxg-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ups-pxg-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Tpo -c -o snmp_ups-eaton-ups-pxg-mib.o `test -f 'eaton-ups-pxg-mib.c' || echo '$(srcdir)/'`eaton-ups-pxg-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ups-pxg-mib.c' object='snmp_ups-eaton-ups-pxg-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ups-pxg-mib.o `test -f 'eaton-ups-pxg-mib.c' || echo '$(srcdir)/'`eaton-ups-pxg-mib.c snmp_ups-eaton-ups-pxg-mib.obj: eaton-ups-pxg-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-eaton-ups-pxg-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Tpo -c -o snmp_ups-eaton-ups-pxg-mib.obj `if test -f 'eaton-ups-pxg-mib.c'; then $(CYGPATH_W) 'eaton-ups-pxg-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ups-pxg-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Tpo $(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='eaton-ups-pxg-mib.c' object='snmp_ups-eaton-ups-pxg-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-eaton-ups-pxg-mib.obj `if test -f 'eaton-ups-pxg-mib.c'; then $(CYGPATH_W) 'eaton-ups-pxg-mib.c'; else $(CYGPATH_W) '$(srcdir)/eaton-ups-pxg-mib.c'; fi` snmp_ups-emerson-avocent-pdu-mib.o: emerson-avocent-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-emerson-avocent-pdu-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Tpo -c -o snmp_ups-emerson-avocent-pdu-mib.o `test -f 'emerson-avocent-pdu-mib.c' || echo '$(srcdir)/'`emerson-avocent-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Tpo $(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='emerson-avocent-pdu-mib.c' object='snmp_ups-emerson-avocent-pdu-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-emerson-avocent-pdu-mib.o `test -f 'emerson-avocent-pdu-mib.c' || echo '$(srcdir)/'`emerson-avocent-pdu-mib.c snmp_ups-emerson-avocent-pdu-mib.obj: emerson-avocent-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-emerson-avocent-pdu-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Tpo -c -o snmp_ups-emerson-avocent-pdu-mib.obj `if test -f 'emerson-avocent-pdu-mib.c'; then $(CYGPATH_W) 'emerson-avocent-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/emerson-avocent-pdu-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Tpo $(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='emerson-avocent-pdu-mib.c' object='snmp_ups-emerson-avocent-pdu-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-emerson-avocent-pdu-mib.obj `if test -f 'emerson-avocent-pdu-mib.c'; then $(CYGPATH_W) 'emerson-avocent-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/emerson-avocent-pdu-mib.c'; fi` snmp_ups-hpe-pdu-mib.o: hpe-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-hpe-pdu-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-hpe-pdu-mib.Tpo -c -o snmp_ups-hpe-pdu-mib.o `test -f 'hpe-pdu-mib.c' || echo '$(srcdir)/'`hpe-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-hpe-pdu-mib.Tpo $(DEPDIR)/snmp_ups-hpe-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hpe-pdu-mib.c' object='snmp_ups-hpe-pdu-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-hpe-pdu-mib.o `test -f 'hpe-pdu-mib.c' || echo '$(srcdir)/'`hpe-pdu-mib.c snmp_ups-hpe-pdu-mib.obj: hpe-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-hpe-pdu-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-hpe-pdu-mib.Tpo -c -o snmp_ups-hpe-pdu-mib.obj `if test -f 'hpe-pdu-mib.c'; then $(CYGPATH_W) 'hpe-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/hpe-pdu-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-hpe-pdu-mib.Tpo $(DEPDIR)/snmp_ups-hpe-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hpe-pdu-mib.c' object='snmp_ups-hpe-pdu-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-hpe-pdu-mib.obj `if test -f 'hpe-pdu-mib.c'; then $(CYGPATH_W) 'hpe-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/hpe-pdu-mib.c'; fi` snmp_ups-hpe-pdu3-cis-mib.o: hpe-pdu3-cis-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-hpe-pdu3-cis-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Tpo -c -o snmp_ups-hpe-pdu3-cis-mib.o `test -f 'hpe-pdu3-cis-mib.c' || echo '$(srcdir)/'`hpe-pdu3-cis-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Tpo $(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hpe-pdu3-cis-mib.c' object='snmp_ups-hpe-pdu3-cis-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-hpe-pdu3-cis-mib.o `test -f 'hpe-pdu3-cis-mib.c' || echo '$(srcdir)/'`hpe-pdu3-cis-mib.c snmp_ups-hpe-pdu3-cis-mib.obj: hpe-pdu3-cis-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-hpe-pdu3-cis-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Tpo -c -o snmp_ups-hpe-pdu3-cis-mib.obj `if test -f 'hpe-pdu3-cis-mib.c'; then $(CYGPATH_W) 'hpe-pdu3-cis-mib.c'; else $(CYGPATH_W) '$(srcdir)/hpe-pdu3-cis-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Tpo $(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='hpe-pdu3-cis-mib.c' object='snmp_ups-hpe-pdu3-cis-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-hpe-pdu3-cis-mib.obj `if test -f 'hpe-pdu3-cis-mib.c'; then $(CYGPATH_W) 'hpe-pdu3-cis-mib.c'; else $(CYGPATH_W) '$(srcdir)/hpe-pdu3-cis-mib.c'; fi` snmp_ups-huawei-mib.o: huawei-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-huawei-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-huawei-mib.Tpo -c -o snmp_ups-huawei-mib.o `test -f 'huawei-mib.c' || echo '$(srcdir)/'`huawei-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-huawei-mib.Tpo $(DEPDIR)/snmp_ups-huawei-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='huawei-mib.c' object='snmp_ups-huawei-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-huawei-mib.o `test -f 'huawei-mib.c' || echo '$(srcdir)/'`huawei-mib.c snmp_ups-huawei-mib.obj: huawei-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-huawei-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-huawei-mib.Tpo -c -o snmp_ups-huawei-mib.obj `if test -f 'huawei-mib.c'; then $(CYGPATH_W) 'huawei-mib.c'; else $(CYGPATH_W) '$(srcdir)/huawei-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-huawei-mib.Tpo $(DEPDIR)/snmp_ups-huawei-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='huawei-mib.c' object='snmp_ups-huawei-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-huawei-mib.obj `if test -f 'huawei-mib.c'; then $(CYGPATH_W) 'huawei-mib.c'; else $(CYGPATH_W) '$(srcdir)/huawei-mib.c'; fi` snmp_ups-ietf-mib.o: ietf-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-ietf-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-ietf-mib.Tpo -c -o snmp_ups-ietf-mib.o `test -f 'ietf-mib.c' || echo '$(srcdir)/'`ietf-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-ietf-mib.Tpo $(DEPDIR)/snmp_ups-ietf-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ietf-mib.c' object='snmp_ups-ietf-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-ietf-mib.o `test -f 'ietf-mib.c' || echo '$(srcdir)/'`ietf-mib.c snmp_ups-ietf-mib.obj: ietf-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-ietf-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-ietf-mib.Tpo -c -o snmp_ups-ietf-mib.obj `if test -f 'ietf-mib.c'; then $(CYGPATH_W) 'ietf-mib.c'; else $(CYGPATH_W) '$(srcdir)/ietf-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-ietf-mib.Tpo $(DEPDIR)/snmp_ups-ietf-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ietf-mib.c' object='snmp_ups-ietf-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-ietf-mib.obj `if test -f 'ietf-mib.c'; then $(CYGPATH_W) 'ietf-mib.c'; else $(CYGPATH_W) '$(srcdir)/ietf-mib.c'; fi` snmp_ups-mge-mib.o: mge-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-mge-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-mge-mib.Tpo -c -o snmp_ups-mge-mib.o `test -f 'mge-mib.c' || echo '$(srcdir)/'`mge-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-mge-mib.Tpo $(DEPDIR)/snmp_ups-mge-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mge-mib.c' object='snmp_ups-mge-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-mge-mib.o `test -f 'mge-mib.c' || echo '$(srcdir)/'`mge-mib.c snmp_ups-mge-mib.obj: mge-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-mge-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-mge-mib.Tpo -c -o snmp_ups-mge-mib.obj `if test -f 'mge-mib.c'; then $(CYGPATH_W) 'mge-mib.c'; else $(CYGPATH_W) '$(srcdir)/mge-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-mge-mib.Tpo $(DEPDIR)/snmp_ups-mge-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mge-mib.c' object='snmp_ups-mge-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-mge-mib.obj `if test -f 'mge-mib.c'; then $(CYGPATH_W) 'mge-mib.c'; else $(CYGPATH_W) '$(srcdir)/mge-mib.c'; fi` snmp_ups-netvision-mib.o: netvision-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-netvision-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-netvision-mib.Tpo -c -o snmp_ups-netvision-mib.o `test -f 'netvision-mib.c' || echo '$(srcdir)/'`netvision-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-netvision-mib.Tpo $(DEPDIR)/snmp_ups-netvision-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='netvision-mib.c' object='snmp_ups-netvision-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-netvision-mib.o `test -f 'netvision-mib.c' || echo '$(srcdir)/'`netvision-mib.c snmp_ups-netvision-mib.obj: netvision-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-netvision-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-netvision-mib.Tpo -c -o snmp_ups-netvision-mib.obj `if test -f 'netvision-mib.c'; then $(CYGPATH_W) 'netvision-mib.c'; else $(CYGPATH_W) '$(srcdir)/netvision-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-netvision-mib.Tpo $(DEPDIR)/snmp_ups-netvision-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='netvision-mib.c' object='snmp_ups-netvision-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-netvision-mib.obj `if test -f 'netvision-mib.c'; then $(CYGPATH_W) 'netvision-mib.c'; else $(CYGPATH_W) '$(srcdir)/netvision-mib.c'; fi` snmp_ups-raritan-pdu-mib.o: raritan-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-raritan-pdu-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-raritan-pdu-mib.Tpo -c -o snmp_ups-raritan-pdu-mib.o `test -f 'raritan-pdu-mib.c' || echo '$(srcdir)/'`raritan-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-raritan-pdu-mib.Tpo $(DEPDIR)/snmp_ups-raritan-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='raritan-pdu-mib.c' object='snmp_ups-raritan-pdu-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-raritan-pdu-mib.o `test -f 'raritan-pdu-mib.c' || echo '$(srcdir)/'`raritan-pdu-mib.c snmp_ups-raritan-pdu-mib.obj: raritan-pdu-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-raritan-pdu-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-raritan-pdu-mib.Tpo -c -o snmp_ups-raritan-pdu-mib.obj `if test -f 'raritan-pdu-mib.c'; then $(CYGPATH_W) 'raritan-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/raritan-pdu-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-raritan-pdu-mib.Tpo $(DEPDIR)/snmp_ups-raritan-pdu-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='raritan-pdu-mib.c' object='snmp_ups-raritan-pdu-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-raritan-pdu-mib.obj `if test -f 'raritan-pdu-mib.c'; then $(CYGPATH_W) 'raritan-pdu-mib.c'; else $(CYGPATH_W) '$(srcdir)/raritan-pdu-mib.c'; fi` snmp_ups-raritan-px2-mib.o: raritan-px2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-raritan-px2-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-raritan-px2-mib.Tpo -c -o snmp_ups-raritan-px2-mib.o `test -f 'raritan-px2-mib.c' || echo '$(srcdir)/'`raritan-px2-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-raritan-px2-mib.Tpo $(DEPDIR)/snmp_ups-raritan-px2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='raritan-px2-mib.c' object='snmp_ups-raritan-px2-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-raritan-px2-mib.o `test -f 'raritan-px2-mib.c' || echo '$(srcdir)/'`raritan-px2-mib.c snmp_ups-raritan-px2-mib.obj: raritan-px2-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-raritan-px2-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-raritan-px2-mib.Tpo -c -o snmp_ups-raritan-px2-mib.obj `if test -f 'raritan-px2-mib.c'; then $(CYGPATH_W) 'raritan-px2-mib.c'; else $(CYGPATH_W) '$(srcdir)/raritan-px2-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-raritan-px2-mib.Tpo $(DEPDIR)/snmp_ups-raritan-px2-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='raritan-px2-mib.c' object='snmp_ups-raritan-px2-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-raritan-px2-mib.obj `if test -f 'raritan-px2-mib.c'; then $(CYGPATH_W) 'raritan-px2-mib.c'; else $(CYGPATH_W) '$(srcdir)/raritan-px2-mib.c'; fi` snmp_ups-xppc-mib.o: xppc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-xppc-mib.o -MD -MP -MF $(DEPDIR)/snmp_ups-xppc-mib.Tpo -c -o snmp_ups-xppc-mib.o `test -f 'xppc-mib.c' || echo '$(srcdir)/'`xppc-mib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-xppc-mib.Tpo $(DEPDIR)/snmp_ups-xppc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xppc-mib.c' object='snmp_ups-xppc-mib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-xppc-mib.o `test -f 'xppc-mib.c' || echo '$(srcdir)/'`xppc-mib.c snmp_ups-xppc-mib.obj: xppc-mib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -MT snmp_ups-xppc-mib.obj -MD -MP -MF $(DEPDIR)/snmp_ups-xppc-mib.Tpo -c -o snmp_ups-xppc-mib.obj `if test -f 'xppc-mib.c'; then $(CYGPATH_W) 'xppc-mib.c'; else $(CYGPATH_W) '$(srcdir)/xppc-mib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/snmp_ups-xppc-mib.Tpo $(DEPDIR)/snmp_ups-xppc-mib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xppc-mib.c' object='snmp_ups-xppc-mib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(snmp_ups_CFLAGS) $(CFLAGS) -c -o snmp_ups-xppc-mib.obj `if test -f 'xppc-mib.c'; then $(CYGPATH_W) 'xppc-mib.c'; else $(CYGPATH_W) '$(srcdir)/xppc-mib.c'; fi` mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(HEADERS) installdirs: for dir in "$(DESTDIR)$(driverexecdir)" "$(DESTDIR)$(sbindir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) clean: clean-am clean-am: clean-driverexecPROGRAMS clean-generic clean-libtool \ clean-noinstLTLIBRARIES clean-sbinPROGRAMS mostlyclean-am distclean: distclean-am -rm -f ./$(DEPDIR)/adelsystem_cbi.Po -rm -f ./$(DEPDIR)/al175.Po -rm -f ./$(DEPDIR)/apc-hid.Po -rm -f ./$(DEPDIR)/apc_modbus.Po -rm -f ./$(DEPDIR)/apcsmart-old.Po -rm -f ./$(DEPDIR)/apcsmart.Po -rm -f ./$(DEPDIR)/apcsmart_tabs.Po -rm -f ./$(DEPDIR)/apcupsd_ups-apcupsd-ups.Po -rm -f ./$(DEPDIR)/arduino-hid.Po -rm -f ./$(DEPDIR)/asem.Po -rm -f ./$(DEPDIR)/bcmxcp.Po -rm -f ./$(DEPDIR)/bcmxcp_ser.Po -rm -f ./$(DEPDIR)/bcmxcp_usb.Po -rm -f ./$(DEPDIR)/belkin-hid.Po -rm -f ./$(DEPDIR)/belkin.Po -rm -f ./$(DEPDIR)/belkinunv.Po -rm -f ./$(DEPDIR)/bestfcom.Po -rm -f ./$(DEPDIR)/bestfortress.Po -rm -f ./$(DEPDIR)/bestuferrups.Po -rm -f ./$(DEPDIR)/bestups.Po -rm -f ./$(DEPDIR)/bicker_ser.Po -rm -f ./$(DEPDIR)/blazer.Po -rm -f ./$(DEPDIR)/blazer_ser.Po -rm -f ./$(DEPDIR)/blazer_usb.Po -rm -f ./$(DEPDIR)/clone-outlet.Po -rm -f ./$(DEPDIR)/clone.Po -rm -f ./$(DEPDIR)/cps-hid.Po -rm -f ./$(DEPDIR)/delta_ups-hid.Po -rm -f ./$(DEPDIR)/dstate.Plo -rm -f ./$(DEPDIR)/dummy_ups-dummy-ups.Po -rm -f ./$(DEPDIR)/ecoflow-hid.Po -rm -f ./$(DEPDIR)/etapro.Po -rm -f ./$(DEPDIR)/ever-hid.Po -rm -f ./$(DEPDIR)/everups.Po -rm -f ./$(DEPDIR)/explore-hid.Po -rm -f ./$(DEPDIR)/failover.Po -rm -f ./$(DEPDIR)/gamatronic.Po -rm -f ./$(DEPDIR)/generic_gpio_common.Po -rm -f ./$(DEPDIR)/generic_gpio_libgpiod.Po -rm -f ./$(DEPDIR)/generic_modbus.Po -rm -f ./$(DEPDIR)/genericups.Po -rm -f ./$(DEPDIR)/hidparser.Po -rm -f ./$(DEPDIR)/huawei-ups2000.Po -rm -f ./$(DEPDIR)/hwmon_ina219.Po -rm -f ./$(DEPDIR)/idowell-hid.Po -rm -f ./$(DEPDIR)/isbmex.Po -rm -f ./$(DEPDIR)/ivtscd.Po -rm -f ./$(DEPDIR)/legrand-hid.Po -rm -f ./$(DEPDIR)/libdummy_mockdrv_la-dstate.Plo -rm -f ./$(DEPDIR)/libdummy_mockdrv_la-main.Plo -rm -f ./$(DEPDIR)/libhid.Po -rm -f ./$(DEPDIR)/libserial_nutscan_la-bcmxcp_ser.Plo -rm -f ./$(DEPDIR)/libserial_nutscan_la-serial.Plo -rm -f ./$(DEPDIR)/libusb0.Po -rm -f ./$(DEPDIR)/libusb1.Po -rm -f ./$(DEPDIR)/liebert-esp2.Po -rm -f ./$(DEPDIR)/liebert-gxe.Po -rm -f ./$(DEPDIR)/liebert-hid.Po -rm -f ./$(DEPDIR)/liebert.Po -rm -f ./$(DEPDIR)/macosx-ups.Po -rm -f ./$(DEPDIR)/main.Plo -rm -f ./$(DEPDIR)/masterguard.Po -rm -f ./$(DEPDIR)/metasys.Po -rm -f ./$(DEPDIR)/mge-hid.Po -rm -f ./$(DEPDIR)/mge-utalk.Po -rm -f ./$(DEPDIR)/mge_shut-hidparser.Po -rm -f ./$(DEPDIR)/mge_shut-libhid.Po -rm -f ./$(DEPDIR)/mge_shut-libshut.Po -rm -f ./$(DEPDIR)/mge_shut-mge-hid.Po -rm -f ./$(DEPDIR)/mge_shut-usbhid-ups.Po -rm -f ./$(DEPDIR)/microdowell.Po -rm -f ./$(DEPDIR)/microsol-apc.Po -rm -f ./$(DEPDIR)/microsol-common.Po -rm -f ./$(DEPDIR)/netxml_ups-mge-xml.Po -rm -f ./$(DEPDIR)/netxml_ups-netxml-ups.Po -rm -f ./$(DEPDIR)/nhs_ser.Po -rm -f ./$(DEPDIR)/nut-ipmipsu.Po -rm -f ./$(DEPDIR)/nut-libfreeipmi.Po -rm -f ./$(DEPDIR)/nutdrv_atcl_usb.Po -rm -f ./$(DEPDIR)/nutdrv_hashx.Po -rm -f ./$(DEPDIR)/nutdrv_qx-common_voltronic-crc.Po -rm -f ./$(DEPDIR)/nutdrv_qx-libusb0.Po -rm -f ./$(DEPDIR)/nutdrv_qx-libusb1.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Po -rm -f ./$(DEPDIR)/nutdrv_qx-usb-common.Po -rm -f ./$(DEPDIR)/nutdrv_siemens_sitop.Po -rm -f ./$(DEPDIR)/oneac.Po -rm -f ./$(DEPDIR)/openups-hid.Po -rm -f ./$(DEPDIR)/optiups.Po -rm -f ./$(DEPDIR)/phoenixcontact_modbus.Po -rm -f ./$(DEPDIR)/pijuice.Po -rm -f ./$(DEPDIR)/powercom-hid.Po -rm -f ./$(DEPDIR)/powercom.Po -rm -f ./$(DEPDIR)/powerman-pdu.Po -rm -f ./$(DEPDIR)/powerp-bin.Po -rm -f ./$(DEPDIR)/powerp-txt.Po -rm -f ./$(DEPDIR)/powerpanel.Po -rm -f ./$(DEPDIR)/powervar-hid.Po -rm -f ./$(DEPDIR)/powervar_cx_ser-powervar_cx.Po -rm -f ./$(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-libusb0.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-libusb1.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-powervar_cx.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-usb-common.Po -rm -f ./$(DEPDIR)/rhino.Po -rm -f ./$(DEPDIR)/richcomm_usb.Po -rm -f ./$(DEPDIR)/riello.Po -rm -f ./$(DEPDIR)/riello_ser.Po -rm -f ./$(DEPDIR)/riello_usb.Po -rm -f ./$(DEPDIR)/safenet.Po -rm -f ./$(DEPDIR)/salicru-hid.Po -rm -f ./$(DEPDIR)/serial.Plo -rm -f ./$(DEPDIR)/skel.Po -rm -f ./$(DEPDIR)/sms_ser.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-ats-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-epdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-baytech-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-bestpower-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-compaq-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-cyberpower-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-delta_ups-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ats30-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-hpe-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-huawei-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-ietf-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-mge-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-netvision-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-raritan-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-raritan-px2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-snmp-ups-helpers.Po -rm -f ./$(DEPDIR)/snmp_ups-snmp-ups.Po -rm -f ./$(DEPDIR)/snmp_ups-xppc-mib.Po -rm -f ./$(DEPDIR)/socomec_jbus.Po -rm -f ./$(DEPDIR)/solis.Po -rm -f ./$(DEPDIR)/tripplite-hid.Po -rm -f ./$(DEPDIR)/tripplite.Po -rm -f ./$(DEPDIR)/tripplite_usb.Po -rm -f ./$(DEPDIR)/tripplitesu.Po -rm -f ./$(DEPDIR)/upscode2.Po -rm -f ./$(DEPDIR)/upsdrvctl.Po -rm -f ./$(DEPDIR)/upsdrvquery.Plo -rm -f ./$(DEPDIR)/usb-common.Po -rm -f ./$(DEPDIR)/usbhid-ups.Po -rm -f ./$(DEPDIR)/ve-direct.Po -rm -f ./$(DEPDIR)/victronups.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-driverexecPROGRAMS install-sbinPROGRAMS install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/adelsystem_cbi.Po -rm -f ./$(DEPDIR)/al175.Po -rm -f ./$(DEPDIR)/apc-hid.Po -rm -f ./$(DEPDIR)/apc_modbus.Po -rm -f ./$(DEPDIR)/apcsmart-old.Po -rm -f ./$(DEPDIR)/apcsmart.Po -rm -f ./$(DEPDIR)/apcsmart_tabs.Po -rm -f ./$(DEPDIR)/apcupsd_ups-apcupsd-ups.Po -rm -f ./$(DEPDIR)/arduino-hid.Po -rm -f ./$(DEPDIR)/asem.Po -rm -f ./$(DEPDIR)/bcmxcp.Po -rm -f ./$(DEPDIR)/bcmxcp_ser.Po -rm -f ./$(DEPDIR)/bcmxcp_usb.Po -rm -f ./$(DEPDIR)/belkin-hid.Po -rm -f ./$(DEPDIR)/belkin.Po -rm -f ./$(DEPDIR)/belkinunv.Po -rm -f ./$(DEPDIR)/bestfcom.Po -rm -f ./$(DEPDIR)/bestfortress.Po -rm -f ./$(DEPDIR)/bestuferrups.Po -rm -f ./$(DEPDIR)/bestups.Po -rm -f ./$(DEPDIR)/bicker_ser.Po -rm -f ./$(DEPDIR)/blazer.Po -rm -f ./$(DEPDIR)/blazer_ser.Po -rm -f ./$(DEPDIR)/blazer_usb.Po -rm -f ./$(DEPDIR)/clone-outlet.Po -rm -f ./$(DEPDIR)/clone.Po -rm -f ./$(DEPDIR)/cps-hid.Po -rm -f ./$(DEPDIR)/delta_ups-hid.Po -rm -f ./$(DEPDIR)/dstate.Plo -rm -f ./$(DEPDIR)/dummy_ups-dummy-ups.Po -rm -f ./$(DEPDIR)/ecoflow-hid.Po -rm -f ./$(DEPDIR)/etapro.Po -rm -f ./$(DEPDIR)/ever-hid.Po -rm -f ./$(DEPDIR)/everups.Po -rm -f ./$(DEPDIR)/explore-hid.Po -rm -f ./$(DEPDIR)/failover.Po -rm -f ./$(DEPDIR)/gamatronic.Po -rm -f ./$(DEPDIR)/generic_gpio_common.Po -rm -f ./$(DEPDIR)/generic_gpio_libgpiod.Po -rm -f ./$(DEPDIR)/generic_modbus.Po -rm -f ./$(DEPDIR)/genericups.Po -rm -f ./$(DEPDIR)/hidparser.Po -rm -f ./$(DEPDIR)/huawei-ups2000.Po -rm -f ./$(DEPDIR)/hwmon_ina219.Po -rm -f ./$(DEPDIR)/idowell-hid.Po -rm -f ./$(DEPDIR)/isbmex.Po -rm -f ./$(DEPDIR)/ivtscd.Po -rm -f ./$(DEPDIR)/legrand-hid.Po -rm -f ./$(DEPDIR)/libdummy_mockdrv_la-dstate.Plo -rm -f ./$(DEPDIR)/libdummy_mockdrv_la-main.Plo -rm -f ./$(DEPDIR)/libhid.Po -rm -f ./$(DEPDIR)/libserial_nutscan_la-bcmxcp_ser.Plo -rm -f ./$(DEPDIR)/libserial_nutscan_la-serial.Plo -rm -f ./$(DEPDIR)/libusb0.Po -rm -f ./$(DEPDIR)/libusb1.Po -rm -f ./$(DEPDIR)/liebert-esp2.Po -rm -f ./$(DEPDIR)/liebert-gxe.Po -rm -f ./$(DEPDIR)/liebert-hid.Po -rm -f ./$(DEPDIR)/liebert.Po -rm -f ./$(DEPDIR)/macosx-ups.Po -rm -f ./$(DEPDIR)/main.Plo -rm -f ./$(DEPDIR)/masterguard.Po -rm -f ./$(DEPDIR)/metasys.Po -rm -f ./$(DEPDIR)/mge-hid.Po -rm -f ./$(DEPDIR)/mge-utalk.Po -rm -f ./$(DEPDIR)/mge_shut-hidparser.Po -rm -f ./$(DEPDIR)/mge_shut-libhid.Po -rm -f ./$(DEPDIR)/mge_shut-libshut.Po -rm -f ./$(DEPDIR)/mge_shut-mge-hid.Po -rm -f ./$(DEPDIR)/mge_shut-usbhid-ups.Po -rm -f ./$(DEPDIR)/microdowell.Po -rm -f ./$(DEPDIR)/microsol-apc.Po -rm -f ./$(DEPDIR)/microsol-common.Po -rm -f ./$(DEPDIR)/netxml_ups-mge-xml.Po -rm -f ./$(DEPDIR)/netxml_ups-netxml-ups.Po -rm -f ./$(DEPDIR)/nhs_ser.Po -rm -f ./$(DEPDIR)/nut-ipmipsu.Po -rm -f ./$(DEPDIR)/nut-libfreeipmi.Po -rm -f ./$(DEPDIR)/nutdrv_atcl_usb.Po -rm -f ./$(DEPDIR)/nutdrv_hashx.Po -rm -f ./$(DEPDIR)/nutdrv_qx-common_voltronic-crc.Po -rm -f ./$(DEPDIR)/nutdrv_qx-libusb0.Po -rm -f ./$(DEPDIR)/nutdrv_qx-libusb1.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_ablerex.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_bestups.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_blazer-common.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_gtec.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_hunnox.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart31.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_innovart33.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_masterguard.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mecer.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec-old.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_megatec.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_mustek.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q1.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q2.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_q6.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-axpert.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs-hex.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic-qs.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_voltronic.Po -rm -f ./$(DEPDIR)/nutdrv_qx-nutdrv_qx_zinto.Po -rm -f ./$(DEPDIR)/nutdrv_qx-usb-common.Po -rm -f ./$(DEPDIR)/nutdrv_siemens_sitop.Po -rm -f ./$(DEPDIR)/oneac.Po -rm -f ./$(DEPDIR)/openups-hid.Po -rm -f ./$(DEPDIR)/optiups.Po -rm -f ./$(DEPDIR)/phoenixcontact_modbus.Po -rm -f ./$(DEPDIR)/pijuice.Po -rm -f ./$(DEPDIR)/powercom-hid.Po -rm -f ./$(DEPDIR)/powercom.Po -rm -f ./$(DEPDIR)/powerman-pdu.Po -rm -f ./$(DEPDIR)/powerp-bin.Po -rm -f ./$(DEPDIR)/powerp-txt.Po -rm -f ./$(DEPDIR)/powerpanel.Po -rm -f ./$(DEPDIR)/powervar-hid.Po -rm -f ./$(DEPDIR)/powervar_cx_ser-powervar_cx.Po -rm -f ./$(DEPDIR)/powervar_cx_ser-powervar_cx_ser.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-libusb0.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-libusb1.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-powervar_cx.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-powervar_cx_usb.Po -rm -f ./$(DEPDIR)/powervar_cx_usb-usb-common.Po -rm -f ./$(DEPDIR)/rhino.Po -rm -f ./$(DEPDIR)/richcomm_usb.Po -rm -f ./$(DEPDIR)/riello.Po -rm -f ./$(DEPDIR)/riello_ser.Po -rm -f ./$(DEPDIR)/riello_usb.Po -rm -f ./$(DEPDIR)/safenet.Po -rm -f ./$(DEPDIR)/salicru-hid.Po -rm -f ./$(DEPDIR)/serial.Plo -rm -f ./$(DEPDIR)/skel.Po -rm -f ./$(DEPDIR)/sms_ser.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-ats-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-epdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-apc-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-baytech-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-baytech-rpc3nc-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-bestpower-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-compaq-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-cyberpower-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-delta_ups-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ats16-nm2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ats16-nmc-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ats30-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-genesis2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-helpers.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-marlin-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-nlogic-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-pulizzi-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-pdu-revelation-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ups-pwnm2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-eaton-ups-pxg-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-emerson-avocent-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-hpe-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-hpe-pdu3-cis-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-huawei-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-ietf-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-mge-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-netvision-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-raritan-pdu-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-raritan-px2-mib.Po -rm -f ./$(DEPDIR)/snmp_ups-snmp-ups-helpers.Po -rm -f ./$(DEPDIR)/snmp_ups-snmp-ups.Po -rm -f ./$(DEPDIR)/snmp_ups-xppc-mib.Po -rm -f ./$(DEPDIR)/socomec_jbus.Po -rm -f ./$(DEPDIR)/solis.Po -rm -f ./$(DEPDIR)/tripplite-hid.Po -rm -f ./$(DEPDIR)/tripplite.Po -rm -f ./$(DEPDIR)/tripplite_usb.Po -rm -f ./$(DEPDIR)/tripplitesu.Po -rm -f ./$(DEPDIR)/upscode2.Po -rm -f ./$(DEPDIR)/upsdrvctl.Po -rm -f ./$(DEPDIR)/upsdrvquery.Plo -rm -f ./$(DEPDIR)/usb-common.Po -rm -f ./$(DEPDIR)/usbhid-ups.Po -rm -f ./$(DEPDIR)/ve-direct.Po -rm -f ./$(DEPDIR)/victronups.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-driverexecPROGRAMS uninstall-sbinPROGRAMS .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-driverexecPROGRAMS clean-generic clean-libtool \ clean-noinstLTLIBRARIES clean-sbinPROGRAMS cscopelist-am ctags \ ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-driverexecPROGRAMS install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am install-man \ install-pdf install-pdf-am install-ps install-ps-am \ install-sbinPROGRAMS install-strip installcheck \ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am \ uninstall-driverexecPROGRAMS uninstall-sbinPROGRAMS .PRECIOUS: Makefile # Export certain values for ccache which NUT ci_build.sh can customize, # to facilitate developer iteration re-runs of "make" later. # At least GNU and BSD make implementations are okay with this syntax. @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_NAMESPACE@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_BASEDIR@export CCACHE_BASEDIR=@CCACHE_BASEDIR@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_DIR@export CCACHE_DIR=@CCACHE_DIR@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_PATH@export CCACHE_PATH=@CCACHE_PATH@ @NUT_AM_MAKE_CAN_EXPORT@@NUT_AM_EXPORT_CCACHE_PATH@export PATH=@PATH_DURING_CONFIGURE@ # Make sure out-of-dir dependencies exist (especially when dev-building parts): $(top_builddir)/common/libcommon.la \ $(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libparseconf.la \ $(top_builddir)/clients/libupsclient.la: dummy +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) # Builds from root dir arrange stuff decently. Make sure parallel builds # started from scratch right in this dir get dependencies in proper order # (sub-makes are independent as far as trying to write into same files): $(top_builddir)/common/libcommon.la: $(top_builddir)/common/libparseconf.la # Internally (clients/Makefile.am) libupsclient.la requires libcommonclient.la # and that in turn libparseconf.la: $(top_builddir)/clients/libupsclient.la: $(top_builddir)/common/libparseconf.la dummy: # NOTE: Do not clean ".deps" in SUBDIRS of the main project, # the root Makefile.am takes care of that! #clean-local: # $(AM_V_at)rm -rf $(builddir)/.deps # Helper for only the enabled libs to get built: all-libs-local: $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES) $(EXTRA_LTLIBRARIES) # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: nut-2.8.4/drivers/ever-hid.c0000664000175000017500000010000315000733176012577 00000000000000/* ever-hid.c - subdriver to monitor EVER USB/HID devices with NUT * * Copyright (C) * 2003 - 2012 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * 2013 Charles Lepple * 2017 EVER Power Systems [https://ever.eu/] * 2020 - 2022 Jim Klimov * * Note: this subdriver was initially generated as a "stub" by the * gen-usbhid-subdriver script. It must be customized. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be first */ #include "usbhid-ups.h" #include "ever-hid.h" #include "main.h" /* for getval() */ #include "usb-common.h" #define EVER_HID_VERSION "Ever HID 0.10" /* FIXME: experimental flag to be put in upsdrv_info */ /* Ever */ #define EVER_VENDORID 0x2e51 /* ST Microelectronics */ #define STMICRO_VENDORID 0x0483 /* Please note that USB vendor ID 0x0483 is from ST Microelectronics - * with actual product IDs delegated to different OEMs. * Devices handled in this driver are marketed under Ever brand. */ /* USB IDs device table */ static usb_device_id_t ever_usb_device_table[] = { { USB_DEVICE(STMICRO_VENDORID, 0xa113), NULL }, { USB_DEVICE(EVER_VENDORID, 0xffff), NULL}, { USB_DEVICE(EVER_VENDORID, 0x0000), NULL}, /* Terminating entry */ { 0, 0, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ static const char *ever_format_hardware_fun(double value) { /* TODO - add exception handling for v1.0b0B */ const char* hard_rev[27] = {"0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; static char model[10]; snprintf(model, sizeof(model), "rev.%sv%02u", (&hard_rev[ ((unsigned int)value & 0xFF00)>>8 ])[0], (unsigned int)value & 0xFF ); return model; } static const char *ever_format_version_fun(double value) { static char model[10]; /*upsdebugx(1, "UPS ups_firmware_conversion_fun VALUE: %d", (long)value);*/ snprintf(model, sizeof(model), "v%X.%Xb%02d", ((unsigned int)value & 0xF000)>>12, ((unsigned int)value & 0xF00)>>8, ((int)value & 0xFF) ); return model; } static const char *ever_mac_address_fun(double value) { int mac_adress_report_id = 210; int len = reportbuf->len[mac_adress_report_id]; int n = 0; /* number of characters currently in line */ int i; /* number of bytes output from buffer */ const void *buf = reportbuf->data[mac_adress_report_id]; static char line[100]; NUT_UNUSED_VARIABLE(value); line[0] = '\0'; /* skip first element which is a report id */ for (i = 1; i < len; i++) { n = snprintfcat(line, sizeof(line), n ? ":%02x" : "%02x", ((unsigned char *)buf)[i]); } return line; } static const char *ever_ip_address_fun(double value) { static int report_counter = 1; int report_id = 211, len; int n = 0; /* number of characters currently in line */ int i; /* number of bytes output from buffer */ const void *buf; static char line[100]; NUT_UNUSED_VARIABLE(value); if(report_counter == 1) report_id = 211; /* notification dest ip */ else if(report_counter == 2) report_id = 230; /* ip address */ else if(report_counter == 3) report_id = 231; /* network mask */ else if(report_counter == 4) report_id = 232; /* default gateway */ report_counter== 4 ? report_counter=1 : report_counter++; len = reportbuf->len[report_id]; buf = reportbuf->data[report_id]; line[0] = '\0'; /* skip first element which is a report id */ for (i = 1; i < len; i++) { n = snprintfcat(line, sizeof(line), n ? ".%d" : "%d", ((unsigned char *)buf)[i]); } return line; } static const char *ever_packets_fun(double value) { static int report_counter = 1; int report_id = 215, len, res; const unsigned char *buf; static char line[200]; NUT_UNUSED_VARIABLE(value); if(report_counter == 1 ) report_id = 215; else if(report_counter == 2 ) report_id = 216; else if(report_counter == 3 ) report_id = 217; else if(report_counter == 4 ) report_id = 218; report_counter== 4 ? report_counter=1 : report_counter++; len = reportbuf->len[report_id]; buf = reportbuf->data[report_id]; line[0] = '\0'; /* skip first element which is a report id */ if(len < 5) return ""; res = (int)buf[1]; res |= (int)buf[2] << 8; res |= (int)buf[3] << 16; res |= (int)buf[4] << 24; snprintf(line, sizeof(line), "%d", res); return line; } static const char* ever_workmode_fun(double value) { int workmode_report_id = 74; int workmode = -1; const unsigned char *buf = reportbuf->data[workmode_report_id]; static char line[200]; NUT_UNUSED_VARIABLE(value); line[0] = '\0'; /* skip first element which is a report id */ snprintfcat(line, sizeof(line), "%d", buf[1]); workmode = atoi(line); switch(workmode) { case 1: return "UNKNOWN"; case 2: return "STOP"; case 4: return "ONLINE"; case 8: return "ONBATTERY"; case 16: return "WATCH"; case 32: return "WAITING"; case 64: return "EMERGENCY"; default: return "UNKNOWN"; } } static const char* ever_messages_fun(double value) { int messages_report_id = 75, messages; int n = 0; /* number of characters currently in line */ const unsigned char *buf = reportbuf->data[messages_report_id]; static char line[200]; NUT_UNUSED_VARIABLE(value); line[0] = '\0'; /* skip first element which is a report id */ messages = (int)buf[1]; messages |= (int)buf[2] << 8; /* duplicate of ups.status: OB LB */ /* if(messages & 0x01) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "OVERLOAD"); if(messages & 0x02) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "BATTERY_LOW"); */ if(messages & 0x04) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "BOOST"); if(messages & 0x08) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "BUCK"); if(messages & 0x10) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "BOOST_BLOCKED"); if(messages & 0x20) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "BUCK_BLOCKED"); if(messages & 0x40) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "CHARGING"); if(messages & 0x80) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "FAN_ON"); if(messages & 0x100) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "EPO_BLOCKED"); if(messages & 0x200) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "NEED_REPLACMENT"); if(messages & 0x400 || messages & 0x800) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "OVERHEAT"); if(messages & 0x1000) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "WAITING_FOR_MIN_CHARGE"); if(messages & 0x2000) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "MAINS_OUT_OF_RANGE"); return line; } static const char* ever_alarms_fun(double value) { int alarms_report_id = 76, alarms; int n = 0; /* number of characters currently in line */ const unsigned char *buf = reportbuf->data[alarms_report_id]; static char line[200]; NUT_UNUSED_VARIABLE(value); line[0] = '\0'; /* skip first element which is a report id */ alarms = (int)buf[1]; alarms |= (int)buf[2] << 8; if(alarms & 0x01) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "OVERLOAD"); if(alarms & 0x02) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "SHORT-CIRCUIT"); if(alarms & 0x04 || alarms & 0x08) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "OVERHEAT"); if(alarms & 0x10) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "EPO"); if(alarms & 0x20) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "INERNAL_ERROR"); if(alarms & 0x40) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "REVERSE_POWER_SUPPLY"); if(alarms & 0x80) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "NO_INETERNAL_COMM"); if(alarms & 0x100) n = snprintfcat(line, sizeof(line), n ? " %s" : "%s", "CRITICAL_BATT_VOLTAGE"); return line; } static const char* ever_on_off_fun(double value) { int workmode_report_id = 74; int workmode = -1; const unsigned char *buf = reportbuf->data[workmode_report_id]; static char line[200]; NUT_UNUSED_VARIABLE(value); line[0] = '\0'; /* skip first element which is a report id */ snprintfcat(line, sizeof(line), "%d", buf[1]); workmode = atoi(line); if(workmode != 0x04 && workmode != 0x08) return "off"; return "!off"; } static info_lkp_t ever_format_hardware[] = { { 0, NULL, ever_format_hardware_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_format_version[] = { { 0, NULL, ever_format_version_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_mac_address[] = { { 0, NULL, ever_mac_address_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_ip_address[] = { { 0, NULL, ever_ip_address_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_packets[] = { { 0, NULL, ever_packets_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_workmode[] = { { 0, NULL, ever_workmode_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_messages[] = { { 0, NULL, ever_messages_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_alarms[] = { { 0, NULL, ever_alarms_fun, NULL }, { 0, NULL, NULL, NULL } }; static info_lkp_t ever_on_off_info[] = { { 0, NULL, ever_on_off_fun, NULL }, { 0, NULL, NULL, NULL } }; /* EVER usage table */ static usage_lkp_t ever_usage_lkp[] = { { "EVER1", 0x00000000 }, { "EVER2", 0xff000000 }, { "EVER3", 0xff000001 }, { "EVER4", 0xff000002 }, { "EVER5", 0xff000003 }, { "EVER6", 0xff000004 }, { "EVER7", 0xff000005 }, { "EVER8", 0xff000006 }, { "EVER9", 0xff000007 }, { "EVER10", 0xff000008 }, { "EVER11", 0xff000009 }, { "EVER12", 0xff000010 }, { "EVER13", 0xff000011 }, { "EVER14", 0xff000012 }, { "EVER15", 0xff000013 }, { "EVER16", 0xff000014 }, { "EVER17", 0xff000015 }, { "EVER18", 0xff000016 }, { "EVER19", 0xff000017 }, { "EVER20", 0xff000018 }, { "EVER21", 0xff000019 }, { "EVER22", 0xff00001a }, { "EVER23", 0xff00001b }, { "EVER24", 0xff00001c }, { "EVER25", 0xff00001d }, { "EVER26", 0xff00001e }, { "EVER27", 0xff00001f }, { "EVER28", 0xff000020 }, { "EVER29", 0xff000021 }, { "EVER30", 0xff000022 }, { "EVER31", 0xff000023 }, { "EVER32", 0xff000030 }, { "EVER33", 0xff000031 }, { "EVER34", 0xff000032 }, { "EVER35", 0xff000033 }, { "EVER36", 0xff000034 }, { "EVER37", 0xff000035 }, { "EVER38", 0xff000036 }, { "EVER39", 0xff000037 }, { "EVER40", 0xff000038 }, { "EVER41", 0xff000039 }, { "EVER42", 0xff000040 }, { "EVER43", 0xff000041 }, { "EVER44", 0xff000042 }, { "EVER45", 0xff000043 }, { "EVER46", 0xff000044 }, { "EVER47", 0xff000045 }, { "EVER48", 0xff000046 }, { "EVER49", 0xff000050 }, { "EVER50", 0xff000051 }, { "EVER51", 0xff000052 }, { "EVER52", 0xff000053 }, { "EVER53", 0xff000054 }, { "EVER54", 0xff000060 }, { "EVER55", 0xff000061 }, { "EVER56", 0xff000062 }, { "EVER57", 0xff000063 }, { "EVER58", 0xff000064 }, { "EVER59", 0xff000066 }, { "EVER60", 0xff000067 }, { "EVER61", 0xff000068 }, { "EVER62", 0xff000069 }, { "EVER63", 0xff00006a }, { "EVER64", 0xff00006b }, { "EVER65", 0xff00006c }, { "EVER66", 0xff00006d }, { "EVER67", 0xff00006e }, { "EVER68", 0xff00006f }, { "EVER69", 0xff000070 }, { "EVER70", 0xff000071 }, { "EVER71", 0xff000072 }, { "EVER72", 0xff000073 }, { "EVER73", 0xff000074 }, { "EVER74", 0xff000075 }, { "EVER75", 0xff000076 }, { "EVER76", 0xff000077 }, { "EVER77", 0xff000078 }, { "EVER78", 0xff000079 }, { "EVER79", 0xff00007a }, { "EVER80", 0xff00007b }, { "EVER81", 0xff00007c }, { "EVER82", 0xff00007d }, { "EVER83", 0xff00007e }, { "EVER84", 0xff00007f }, { "EVER85", 0xff000080 }, { "EVER86", 0xff000081 }, { "EVER87", 0xff000082 }, { "EVER88", 0xff000083 }, { "EVER89", 0xff000084 }, { "EVER90", 0xff000085 }, { "EVER91", 0xff000086 }, { "EVER92", 0xff000087 }, { "EVER93", 0xff000088 }, { "EVER94", 0xff000089 }, { "EVER95", 0xff00008a }, { "EVER96", 0xff00008b }, { "EVER97", 0xff000090 }, { "EVER98", 0xff000091 }, { "EVER99", 0xff000092 }, { "EVER100", 0xff000093 }, { "EVER101", 0xff000094 }, { "EVER102", 0xff000095 }, { "EVER103", 0xff000096 }, { "EVER104", 0xff000097 }, { NULL, 0 } }; static usage_tables_t ever_utab[] = { ever_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t ever_hid2nut[] = { /* Note: fields marked with "experimental." prefix were proposed without * an exact match vs. docs/nut-names.txt definitions. PRs are welcome to * analyze and map those values into standard NUT variable names, or to * raise discussion on mailing lists and define new names via consensus. * There is a lot of interesting info listed below. * * Note: mappings that were applied below (as committed 2022-02-09) may * be wrong and are based mostly on cursory reading of original names. * In particular, not sure if the skipped "id.*" fields were identifiers * or some "internal device" etc. */ /* experimental: "NUT variable names" do not currently have * any battery.*id data points: */ { "experimental.battery.batteryid", 0, 0, "UPS.BatterySystem.Battery.BatteryID", NULL, "%.0f", 0, NULL }, { "experimental.battery.systemid", 0, 0, "UPS.BatterySystem.BatterySystemID", NULL, "%.0f", 0, NULL }, { "experimental.battery.chargerid", 0, 0, "UPS.BatterySystem.Charger.ChargerID", NULL, "%.0f", 0, NULL }, { "experimental.battery.input_flowid", 0, 0, "UPS.BatterySystem.Input.FlowID", NULL, "%.0f", 0, NULL }, { "experimental.battery.input_id", 0, 0, "UPS.BatterySystem.Input.InputID", NULL, "%.0f", 0, NULL }, { "experimental.battery.output_flowid", 0, 0, "UPS.BatterySystem.Output.FlowID", NULL, "%.0f", 0, NULL }, { "experimental.battery.output_id", 0, 0, "UPS.BatterySystem.Output.OutputID", NULL, "%.0f", 0, NULL }, /* experimental: "NUT variable names" do not currently have * any id (nor version) data points for FW/HW of components: */ /* not implemented*/ /* { "experimental.id.ups_type", 0, 0, "UPS.EVER1.EVER12", NULL, "%s", 0, ever_format_model }, */ { "experimental.id.firmware_version_inverter", 0, 0, "UPS.EVER1.EVER13", NULL, "%s", 0, ever_format_version }, { "experimental.id.firmware_version_interfaces", 0, 0, "UPS.EVER1.EVER14", NULL, "%s", 0, ever_format_version }, { "experimental.id.hardware_version", 0, 0, "UPS.EVER1.EVER15", NULL, "%s", 0, ever_format_hardware }, { "experimental.id.protocol_version_inverter", 0, 0, "UPS.EVER1.EVER16", NULL, "%s", 0, ever_format_version }, { "experimental.id.protocol_version_interfaces", 0, 0, "UPS.EVER1.EVER17", NULL, "%s", 0, ever_format_version }, /* WAS: "experimental.inverter_info.heatsink_temperature" */ { "ups.temperature", 0, 0, "UPS.EVER1.EVER42", NULL, "%s", 0, kelvin_celsius_conversion }, /* WAS: "experimental.inverter_info.battery_temperature" */ { "battery.temperature", 0, 0, "UPS.EVER1.EVER43", NULL, "%s", 0, kelvin_celsius_conversion }, /* WAS: "experimental.ups_info.output_powerfactor" */ { "output.powerfactor", 0, 0, "UPS.EVER1.EVER44", NULL, "%.0f", 0, NULL }, /* experimental: Should these be HU_TYPE_CMD entries? * Or are they really settings? */ { "experimental.control.ups_on", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER45.EVER46", NULL, "%.0f", 0, NULL }, { "experimental.control.clear_fault", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER45.EVER47", NULL, "%.0f", 0, NULL }, { "experimental.control.clear_battery_fault", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER45.EVER48", NULL, "%.0f", 0, NULL }, { "experimental.control.epo_blocked", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER49.EVER50", NULL, "%.0f", 0, NULL }, { "experimental.control.green_mode", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER49.EVER51", NULL, "%.0f", 0, NULL }, { "experimental.control.button_sound", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER49.EVER52", NULL, "%.0f", 0, NULL }, { "experimental.control.audible_alarm", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER49.EVER53", NULL, "%.0f", 0, NULL }, /* WAS: "experimental.config.output_voltage" */ { "output.voltage", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.EVER1.EVER54", NULL, "%.0f", 0, NULL }, /* not implemented*/ /* { "experimental.config.min_output_voltage", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.EVER1.EVER55", NULL, "%.0f", 0, NULL }, { "experimental.config.max_output_voltage", ST_FLAG_RW | ST_FLAG_STRING, 3, "UPS.EVER1.EVER56", NULL, "%.0f", 0, NULL }, { "experimental.config.min_output_frequency", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER57", NULL, "%.1f", 0, NULL }, { "experimental.config.max_output_frequency", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.EVER1.EVER58", NULL, "%.1f", 0, NULL }, */ /* experimental: what units is this counted in? * is "ups.load.high" a suitable mapping here? or "battery.voltage.high"? */ { "experimental.config.overload_clearance_threshold", ST_FLAG_RW | ST_FLAG_STRING, 2, "UPS.EVER1.EVER59", NULL, "%.0f", 0, NULL }, { "experimental.config.stb_charge", ST_FLAG_RW | ST_FLAG_STRING, 2, "UPS.EVER1.EVER60", NULL, "%.0f", 0, NULL }, /* WAS: "experimental.config.number_of_ebms" * Should this be a string? rw? */ { "battery.packs.external", ST_FLAG_RW | ST_FLAG_STRING, 1, "UPS.EVER1.EVER61", NULL, "%.0f", 0, NULL }, { "experimental.statistics.mains_loss_counter", 0, 0, "UPS.EVER1.EVER62", NULL, "%.0f", 0, NULL }, { "experimental.statistics.lowering_AVR_trigger_counter", 0, 0, "UPS.EVER1.EVER63", NULL, "%.0f", 0, NULL }, { "experimental.statistics.rising_AVR_trigger_counter", 0, 0, "UPS.EVER1.EVER64", NULL, "%.0f", 0, NULL }, { "experimental.statistics.overload_counter", 0, 0, "UPS.EVER1.EVER65", NULL, "%.0f", 0, NULL }, { "experimental.statistics.short_circuit_counter", 0, 0, "UPS.EVER1.EVER66", NULL, "%.0f", 0, NULL }, { "experimental.statistics.discharge_counter", 0, 0, "UPS.EVER1.EVER67", NULL, "%.0f", 0, NULL }, { "experimental.statistics.overheat_counter", 0, 0, "UPS.EVER1.EVER68", NULL, "%.0f", 0, NULL }, { "experimental.statistics.mains_operation_time", 0, 0, "UPS.EVER1.EVER69", NULL, "%.0f", 0, NULL }, { "experimental.statistics.autonomous_operation_time", 0, 0, "UPS.EVER1.EVER70", NULL, "%.0f", 0, NULL }, { "experimental.statistics.overload_operation_time", 0, 0, "UPS.EVER1.EVER71", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.mac_address", 0, 0, "UPS.EVER1.EVER72", NULL, "%s", 0, ever_mac_address }, { "experimental.networkcard.notification_destination_ip", 0, 0, "UPS.EVER1.EVER73", NULL, "%s", 0, ever_ip_address }, { "experimental.networkcard.send_packets", 0, 0, "UPS.EVER1.EVER77", NULL, "%s", 0, ever_packets }, { "experimental.networkcard.received_packets", 0, 0, "UPS.EVER1.EVER78", NULL, "%s", 0, ever_packets }, { "experimental.networkcard.send_packets_err", 0, 0, "UPS.EVER1.EVER79", NULL, "%s", 0, ever_packets }, { "experimental.networkcard.received_packets_err", 0, 0, "UPS.EVER1.EVER80", NULL, "%s", 0, ever_packets }, { "experimental.networkcard.config_dhcp_enabled", 0, 0, "UPS.EVER1.EVER85.EVER86", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.config_ethernet_enabled", 0, 0, "UPS.EVER1.EVER85.EVER87", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.config_http_enabled", 0, 0, "UPS.EVER1.EVER85.EVER88", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.config_snmp_enabled", 0, 0, "UPS.EVER1.EVER85.EVER89", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.config_snmp_trap_enabled", 0, 0, "UPS.EVER1.EVER85.EVER90", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.config_readonly", 0, 0, "UPS.EVER1.EVER85.EVER91", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.config_restart_eth", 0, 0, "UPS.EVER1.EVER85.EVER96", NULL, "%.0f", 0, NULL }, { "experimental.networkcard.ip_address", 0, 0, "UPS.EVER1.EVER93", NULL, "%s", 0, ever_ip_address }, { "experimental.networkcard.network_mask", 0, 0, "UPS.EVER1.EVER94", NULL, "%s", 0, ever_ip_address }, { "experimental.networkcard.default_gateway", 0, 0, "UPS.EVER1.EVER95", NULL, "%s", 0, ever_ip_address }, /* WAS: "experimental.id.config_active_power" */ { "ups.realpower.nominal", 0, 0, "UPS.Flow.ConfigActivePower", NULL, "%.0f", 0, NULL }, /* WAS: "experimental.id.config_apparent_power" * Other HID subdrivers use "ups.power.nominal" mostly (often HU_FLAG_STATIC); * once of each: "ups.realpower.nominal", "ups.realpower". * Is this even a run-time value or a hardware property? */ { "ups.power.nominal", 0, 0, "UPS.Flow.ConfigApparentPower", NULL, "%.0f", 0, NULL }, /* WAS: "experimental.ups.config_frequency" * Here and next: is this about input or output?.. * Other drivers have "input.frequency.nominal" on numbered Flows * As a "nominal", should it be HU_FLAG_SEMI_STATIC or HU_FLAG_STATIC maybe? * Note there are non-nominal values in "powerconverter" below, * so the questions here may be somewhat irrelevant... */ { "output.frequency.nominal", 0, 0, "UPS.Flow.ConfigFrequency", NULL, "%.0f", 0, NULL }, /* WAS: "experimental.ups.config_voltage" */ { "output.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "experimental.ups.flow_id", 0, 0, "UPS.Flow.FlowID", NULL, "%.0f", 0, NULL }, /* NOTE: NUT variable names define "outlet.n.*" names for numbering all * separately manageable outlets; the numberless value (or outlet.0.*) * is reserved to represent common properties of all outlets, if there * are more than one outlet (group). * Mapping below arbitrarily assigns n=1 but really this should be tied * to actual outlet counts (see %i mappings in other drivers). */ /* WAS: experimental.outlet.outlet_id */ { "outlet.1.id", 0, 0, "UPS.OutletSystem.Outlet.OutletID", NULL, "%.0f", 0, NULL }, /* WAS: */ { "experimental.outlet.1.present", 0, 0, "UPS.OutletSystem.Outlet.PresentStatus.Present", NULL, "%.0f", 0, yes_no_info }, { "outlet.1.switchable", 0, 0, "UPS.OutletSystem.Outlet.PresentStatus.Switchable", NULL, "%.0f", 0, yes_no_info }, /* WAS: experimental.outlet.switch_on_off */ { "outlet.1.status", 0, 0, "UPS.OutletSystem.Outlet.PresentStatus.SwitchOn/Off", NULL, "%.0f", 0, NULL }, { "experimental.outlet.1.undefined", 0, 0, "UPS.OutletSystem.Outlet.PresentStatus.Undefined", NULL, "%.0f", 0, NULL }, { "experimental.outlet.1.system_id", 0, 0, "UPS.OutletSystem.OutletSystemID", NULL, "%.0f", 0, NULL }, /* experimental: Should these be HU_TYPE_CMD entries? * Or are they really settings? */ { "experimental.outlet.1.switch_off_control", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.OutletSystem.Outlet.SwitchOffControl", NULL, "%.0f", 0, NULL }, { "experimental.outlet.1.switch_on_control", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.OutletSystem.Outlet.SwitchOnControl", NULL, "%.0f", 0, NULL }, { "experimental.powerconverter.input_flow_id", 0, 0, "UPS.PowerConverter.Input.FlowID", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.input_frequency */ { "input.frequency", 0, 0, "UPS.PowerConverter.Input.Frequency", NULL, "%.0f", 0, NULL }, { "experimental.powerconverter.input_id", 0, 0, "UPS.PowerConverter.Input.InputID", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.input_voltage */ { "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.output_active_power */ { "ups.realpower", 0, 0, "UPS.PowerConverter.Output.ActivePower", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.output_apparent_power */ { "ups.power", 0, 0, "UPS.PowerConverter.Output.ApparentPower", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.output_current */ { "output.current", 0, 0, "UPS.PowerConverter.Output.Current", NULL, "%.0f", 0, NULL }, { "experimental.powerconverter.output_flowid", 0, 0, "UPS.PowerConverter.Output.FlowID", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.output_frequency */ { "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%.0f", 0, NULL }, { "experimental.powerconverter.output_id", 0, 0, "UPS.PowerConverter.Output.OutputID", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.output_percent_load * Note: several original readings map into "ups.load", first served wins */ { "ups.load", 0, 0, "UPS.PowerConverter.Output.PercentLoad", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powerconverter.output_voltage */ { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.0f", 0, NULL }, { "experimental.powerconverter.powerconverterid", 0, 0, "UPS.PowerConverter.PowerConverterID", NULL, "%.0f", 0, NULL }, { "experimental.powersummary.capacity_granularity_1", 0, 0, "UPS.PowerSummary.CapacityGranularity1", NULL, "%.0f", 0, NULL }, { "experimental.powersummary.capacity_granularity_2", 0, 0, "UPS.PowerSummary.CapacityGranularity2", NULL, "%.0f", 0, NULL }, /* WAS: */ { "experimental.powersummary.capacity_mode", 0, 0, "UPS.PowerSummary.CapacityMode", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.delay_before_shutdown */ { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL }, /* WAS: experimental.powersummary.design_capacity */ { "battery.capacity", 0, 0, "UPS.PowerSummary.DesignCapacity", NULL, "%.0f", 0, NULL }, { "experimental.powersummary.flow_id", 0, 0, "UPS.PowerSummary.FlowID", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.full_charge_capacity */ { "battery.capacity", 0, 0, "UPS.PowerSummary.FullChargeCapacity", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.idevice_chemistry */ { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.percent_load * Note: several original readings map into "ups.load", first served wins */ { "ups.load", 0, 0, "UPS.PowerSummary.PercentLoad", NULL, "%.0f", 0, NULL }, { "experimental.powersummary.rechargeable", 0, 0, "UPS.PowerSummary.Rechargeable", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.remaining_capacity */ { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.remaining_time_limit */ { "battery.runtime.low", ST_FLAG_RW | ST_FLAG_NUMBER, 0, "UPS.PowerSummary.RemainingTimeLimit", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.run_time_to_empty */ { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.voltage */ { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.0f", 0, NULL }, /* WAS: experimental.powersummary.delay_before_shutdown */ { "ups.timer.shutdown", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL }, #if WITH_UNMAPPED_DATA_POINTS /* not implemented*/ { "unmapped.ups.powersummary.powersummaryid", 0, 0, "UPS.PowerSummary.PowerSummaryID", NULL, "%.0f", 0, NULL }, #endif /* if WITH_UNMAPPED_DATA_POINTS */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.AwaitingPower", NULL, NULL, HU_FLAG_QUICK_POLL, awaitingpower_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BatteryPresent", NULL, NULL, 0, nobattery_info }, /* not implemented*/ /* { "experimental.ups.presentstatus.belowremainingcapacitylimit", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, "%.0f", 0, NULL }, */ /* { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Boost", NULL, NULL, 0, boost_info }, */ /* { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Buck", NULL, NULL, 0, trim_info }, */ /* { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.CommunicationLost", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, /* not implemented*/ /* { "experimental.ups.powersummary.presentstatus.good", 0, 0, "UPS.PowerSummary.PresentStatus.Good", NULL, "%.0f", 0, NULL }, */ /* { "experimental.ups.powersummary.presentstatus.internalfailure", 0, 0, "UPS.PowerSummary.PresentStatus.InternalFailure", NULL, "%.0f", 0, NULL }, */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, NULL, HU_FLAG_QUICK_POLL, overload_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.OverTemperature", NULL, NULL, 0, overheat_info }, /* not implemented*/ /* { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.RemainingTimeLimitExpired", NULL, NULL, 0, lowbatt_info }, */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER18.EVER19", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER18.EVER20", NULL, NULL, 0, lowbatt_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER18.EVER21", NULL, NULL, 0, boost_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER18.EVER22", NULL, NULL, 0, trim_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER18.EVER25", NULL, NULL, 0, charging_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER18.EVER28", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER32.EVER33", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER32.EVER40", NULL, "%.0f", 0, commfault_info }, { "BOOL", 0, 0, "UPS.EVER1.EVER97.EVER102", NULL, "%s", 0, ever_on_off_info }, /* ever workmodes, messages & alarms */ { "experimental.status.workmode", 0, 0, "UPS.EVER1.EVER97.EVER98", NULL, "%s", 0, ever_workmode }, { "experimental.status.messages", 0, 0, "UPS.EVER1.EVER18.EVER28", NULL, NULL, 0, ever_messages }, { "experimental.status.alarms", 0, 0, "UPS.EVER1.EVER32.EVER33", NULL, NULL, 0, ever_alarms }, /* instant commands */ /* experimental: With the same fields here, are the commands different? * Per NUT command names, should be: documented load.off stays off, like * shutdown.stayoff, but shutdown.return may return if wall power comes back! * In many drivers, similar command with "-1" instead of DEFAULT_OFFDELAY * serves as a shutdown.stop (to abort a pending shutdown). */ { "load.off.delay", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "shutdown.return", 0, 0, "UPS.PowerSummary.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *ever_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *ever_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "Ever"; } static const char *ever_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if the device is supported by this subdriver, else 0. */ static int ever_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(ever_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("Ever", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t ever_subdriver = { EVER_HID_VERSION, ever_claim, ever_utab, ever_hid2nut, ever_format_model, ever_format_mfr, ever_format_serial, fix_report_desc, }; nut-2.8.4/drivers/apcsmart.c0000644000175000017500000016131615044656702012731 00000000000000/* * apcsmart.c - driver for APC smart protocol units (originally "newapc") * * Copyright (C) 1999 Russell Kroll * (C) 2000 Nigel Metheringham * (C) 2011+ Michal Soltys * (C) 2024 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" /* Must be first, includes "config.h" */ #include #include #include #include #include /* strcasecmp() */ #include "serial.h" #include "timehead.h" #include "nut_stdint.h" #include "apcsmart.h" #include "apcsmart_tabs.h" #define DRIVER_NAME "APC Smart protocol driver" #define DRIVER_VERSION "3.36" #ifdef WIN32 # ifndef ECANCELED # define ECANCELED ERROR_CANCELLED # endif #endif /* WIN32 */ /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Russell Kroll \n" "Nigel Metheringham \n" "Michal Soltys ", DRV_STABLE, { &apc_tab_info, NULL } }; static long ups_status = 0; /* some forwards */ static int sdcmd_S(const void *); static int sdcmd_AT(const void *); static int sdcmd_K(const void *); static int sdcmd_Z(const void *); static int sdcmd_CS(const void *); /* * following table *must* match order defined in the man page, namely: * 0:: soft hibernate (*S*) * 1:: hard hibernate (*@*) * 2:: delayed poweroff (*K*) * 3:: instant poweroff (*Z*) * 4:: "force OB hack" (*CS*) */ static int (*sdlist[])(const void *) = { sdcmd_S, sdcmd_AT, sdcmd_K, sdcmd_Z, sdcmd_CS, }; #define SDIDX_AT 1 /* * note: both lookup functions MUST be used after variable detection is * completed - that is after deprecate_vars() call; the general reason for this * is 1:n and n:1 NUT <-> APC mappings, which are not determined prior to the * detection */ static apc_vartab_t *vt_lookup_char(char cmdchar) { int i; for (i = 0; apc_vartab[i].name != NULL; i++) if ((apc_vartab[i].flags & APC_PRESENT) && apc_vartab[i].cmd == cmdchar) return &apc_vartab[i]; return NULL; } static apc_vartab_t *vt_lookup_name(const char *var) { int i; for (i = 0; apc_vartab[i].name != NULL; i++) if ((apc_vartab[i].flags & APC_PRESENT) && !strcasecmp(apc_vartab[i].name, var)) return &apc_vartab[i]; return NULL; } static const char *prtchr(char x) { static size_t curr = 24; static char info[32]; curr = (curr + 8) & 0x1F; snprintf(info + curr, 8, isprint((size_t)x) ? "%c" : "0x%02x", x); return info + curr; } static int rexhlp(const char *rex, const char *val) { static const char *empty = ""; int ret; regex_t mbuf; if (!rex || !*rex) return 1; if (!val) val = empty; regcomp(&mbuf, rex, REG_EXTENDED|REG_NOSUB); ret = regexec(&mbuf, val, 0, 0, 0); regfree(&mbuf); return !ret; } /* convert APC formatting to NUT formatting */ /* TODO: handle errors better */ static const char *convert_data(apc_vartab_t *vt, const char *upsval) { static char temp[APC_LBUF]; long tval; memset(temp, '\0', sizeof(temp)); /* this should never happen */ if (strlen(upsval) >= sizeof(temp)) { upslogx(LOG_CRIT, "%s: the length of [%s] is too big", __func__, vt->name); memcpy(temp, upsval, sizeof(temp) - 1); temp[sizeof(temp) - 1] = '\0'; return temp; } switch (vt->flags & APC_F_MASK) { case APC_F_PERCENT: case APC_F_VOLT: case APC_F_AMP: case APC_F_CELSIUS: case APC_F_HEX: case APC_F_DEC: case APC_F_SECONDS: case APC_F_LEAVE: /* no conversion for any of these */ strncpy(temp, upsval, sizeof(temp) - 1); temp[sizeof(temp) - 1] = '\0'; return temp; case APC_F_HOURS: /* convert to seconds */ tval = 60 * 60 * strtol(upsval, NULL, 10); snprintf(temp, sizeof(temp), "%ld", tval); return temp; case APC_F_MINUTES: /* Convert to seconds - NUT standard time measurement */ tval = 60 * strtol(upsval, NULL, 10); /* Ignore errors - there's not much we can do */ snprintf(temp, sizeof(temp), "%ld", tval); return temp; case APC_F_REASON: switch (upsval[0]) { case 'R': return "unacceptable utility voltage rate of change"; case 'H': return "high utility voltage"; case 'L': return "low utility voltage"; case 'T': return "line voltage notch or spike"; case 'O': return "no transfers yet since turnon"; case 'S': return "simulated power failure or UPS test"; default: strncpy(temp, upsval, sizeof(temp) - 1); temp[sizeof(temp) - 1] = '\0'; return temp; } default: break; } /* this should never happen */ upslogx(LOG_CRIT, "%s: unable to convert [%s]", __func__, vt->name); strncpy(temp, upsval, sizeof(temp) - 1); temp[sizeof(temp) - 1] = '\0'; return temp; } /* report differences if tcsetattr != tcgetattr, return otherwise */ /* * AIX compatible names */ #if defined(VWERSE) && !defined(VWERASE) #define VWERASE VWERSE #endif /* VWERSE && !VWERASE */ #if defined(VDISCRD) && !defined(VDISCARD) #define VDISCARD VDISCRD #endif /* VDISCRD && !VDISCARD */ static void apc_ser_diff(struct termios *tioset, struct termios *tioget) { size_t i; const char dir[] = { 's', 'g' }; struct termios *tio[] = { tioset, tioget }; struct cchar { const char *name; unsigned int sub; }; const struct cchar cchars1[] = { #ifdef VDISCARD { "discard", VDISCARD }, #endif #ifdef VDSUSP { "dsusp", VDSUSP }, #endif { "eof", VEOF }, { "eol", VEOL }, { "eol2", VEOL2 }, { "erase", VERASE }, #ifdef VINTR { "intr", VINTR }, #endif { "kill", VKILL }, { "lnext", VLNEXT }, { "min", VMIN }, { "quit", VQUIT }, #ifdef VREPRINT { "reprint", VREPRINT }, #endif { "start", VSTART }, #ifdef VSTATUS { "status", VSTATUS }, #endif { "stop", VSTOP }, { "susp", VSUSP }, { "time", VTIME }, { "werase", VWERASE }, { NULL, 0 }, }, *cp; /* clear status flags so that they don't affect our binary compare */ #if defined(PENDIN) || defined(FLUSHO) for (i = 0; i < SIZEOF_ARRAY(tio); i++) { #ifdef PENDIN tio[i]->c_lflag &= ~(unsigned int)PENDIN; #endif #ifdef FLUSHO tio[i]->c_lflag &= ~(unsigned int)FLUSHO; #endif } #endif /* defined(PENDIN) || defined(FLUSHO) */ if (!memcmp(tio[0], tio[1], sizeof(*tio[0]))) return; upslogx(LOG_NOTICE, "%s: device reports different attributes than requested", device_path); /* * According to the manual the most common problem is mismatched * combinations of input and output baud rates. If the combination is * not supported then neither are changed. This should not be a * problem here since we set them both to the same extremely common * rate of 2400. */ for (i = 0; i < SIZEOF_ARRAY(tio); i++) { upsdebugx(1, "%s: tc%cetattr(): gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:", __func__, dir[i], (unsigned int) tio[i]->c_cflag, (unsigned int) tio[i]->c_iflag, (unsigned int) tio[i]->c_lflag, (unsigned int) tio[i]->c_oflag); for (cp = cchars1; cp->name; ++cp) upsdebugx(1, "%s: \t%s=%x:", __func__, cp->name, tio[i]->c_cc[cp->sub]); upsdebugx(1, "%s: \tispeed=%d:ospeed=%d", __func__, (int) cfgetispeed(tio[i]), (int) cfgetospeed(tio[i])); } } static void apc_ser_set(void) { struct termios tio, tio_chk; char *val; /* * this must be called before the rest, as ser_set_speed() performs * early initialization of the port, apart from changing speed */ ser_set_speed(upsfd, device_path, B2400); val = getval("cable"); if (val && !strcasecmp(val, ALT_CABLE_1)) { if (ser_set_dtr(upsfd, 1) == -1) fatalx(EXIT_FAILURE, "%s: ser_set_dtr(%s) failed", __func__, device_path); if (ser_set_rts(upsfd, 0) == -1) fatalx(EXIT_FAILURE, "%s: ser_set_rts(%s) failed", __func__, device_path); } /* * that's all if we want simple non canonical mode; this is meant as a * compatibility measure for windows systems and perhaps some * problematic serial cards/converters */ if ((val = getval("ttymode")) && !strcmp(val, "raw")) return; memset(&tio, 0, sizeof(tio)); errno = 0; if (tcgetattr(upsfd, &tio)) fatal_with_errno(EXIT_FAILURE, "%s: tcgetattr(%s)", __func__, device_path); /* set port mode: common stuff, canonical processing */ tio.c_cflag |= (CS8 | CLOCAL | CREAD); tio.c_lflag |= ICANON; #ifdef NOKERNINFO tio.c_lflag |= NOKERNINFO; #endif tio.c_lflag &= ~(unsigned int)(ISIG | IEXTEN); tio.c_iflag |= (IGNCR | IGNPAR); tio.c_iflag &= ~(unsigned int)(IXON | IXOFF); tio.c_cc[VEOL] = '*'; /* specially handled in apc_read() */ #ifdef _POSIX_VDISABLE tio.c_cc[VERASE] = _POSIX_VDISABLE; tio.c_cc[VKILL] = _POSIX_VDISABLE; tio.c_cc[VEOF] = _POSIX_VDISABLE; tio.c_cc[VEOL2] = _POSIX_VDISABLE; #endif if (tcflush(upsfd, TCIOFLUSH)) fatal_with_errno(EXIT_FAILURE, "%s: tcflush(%s)", __func__, device_path); /* * warn: * Note, that tcsetattr() returns success if /any/ of the requested * changes could be successfully carried out. Thus the more complicated * test. */ if (tcsetattr(upsfd, TCSANOW, &tio)) fatal_with_errno(EXIT_FAILURE, "%s: tcsetattr(%s)", __func__, device_path); memset(&tio_chk, 0, sizeof(tio_chk)); if (tcgetattr(upsfd, &tio_chk)) fatal_with_errno(EXIT_FAILURE, "%s: tcgetattr(%s)", __func__, device_path); apc_ser_diff(&tio, &tio_chk); } static void ups_status_set(void) { status_init(); if (ups_status & APC_STAT_CAL) status_set("CAL"); /* calibration */ if (ups_status & APC_STAT_TRIM) status_set("TRIM"); /* SmartTrim */ if (ups_status & APC_STAT_BOOST) status_set("BOOST"); /* SmartBoost */ if (ups_status & APC_STAT_OL) status_set("OL"); /* on line */ if (ups_status & APC_STAT_OB) status_set("OB"); /* on battery */ if (ups_status & APC_STAT_OVER) status_set("OVER"); /* overload */ if (ups_status & APC_STAT_LB) status_set("LB"); /* low battery */ if (ups_status & APC_STAT_RB) status_set("RB"); /* replace batt */ if (ups_status == 0) status_set("OFF"); status_commit(); } static void alert_handler(char ch) { switch (ch) { case '!': /* clear OL, set OB */ upsdebugx(1, "%s: %s", __func__, "OB"); ups_status &= ~APC_STAT_OL; ups_status |= APC_STAT_OB; break; case '$': /* clear OB, set OL */ upsdebugx(1, "%s: %s", __func__, "OL"); ups_status &= ~APC_STAT_OB; ups_status |= APC_STAT_OL; break; case '%': /* set LB */ upsdebugx(1, "%s: %s", __func__, "LB"); ups_status |= APC_STAT_LB; break; case '+': /* clear LB */ upsdebugx(1, "%s: %s", __func__, "not LB"); ups_status &= ~APC_STAT_LB; break; case '#': /* set RB */ upsdebugx(1, "%s: %s", __func__, "RB"); ups_status |= APC_STAT_RB; break; case '?': /* set OVER */ upsdebugx(1, "%s: %s", __func__, "OVER"); ups_status |= APC_STAT_OVER; break; case '=': /* clear OVER */ upsdebugx(1, "%s: %s", __func__, "not OVER"); ups_status &= ~APC_STAT_OVER; break; default: upsdebugx(1, "%s: got 0x%02x (unhandled)", __func__, ch); break; } ups_status_set(); } /* * we need a tiny bit different processing due to "*" and canonical mode; the * function is subtly different from generic ser_get_line_alert() */ #define apc_read(b, l, f) apc_read_i(b, l, f, __func__, __LINE__) static ssize_t apc_read_i(char *buf, size_t buflen, int flags, const char *fn, unsigned int ln) { const char *iset = IGN_CHARS, *aset = ""; size_t count = 0; ssize_t i, ret; int sec = 3, usec = 0; char temp[APC_LBUF]; if (buflen > (size_t)SSIZE_MAX) { fatalx (EXIT_FAILURE, "Error: apc_read_i called with buflen too large"); } if (INVALID_FD(upsfd)) return 0; if (flags & SER_D0) { sec = 0; usec = 0; } if (flags & SER_DX) { sec = 0; usec = 200000; } if (flags & SER_D1) { sec = 1; usec = 500000; } if (flags & SER_D3) { sec = 3; usec = 0; } if (flags & SER_AA) { iset = IGN_AACHARS; aset = ALERT_CHARS; } if (flags & SER_CC) { iset = IGN_CCCHARS; aset = ""; sec = 6; usec = 0; } if (flags & SER_CS) { iset = IGN_CSCHARS; aset = ""; sec = 6; usec = 0; } memset(buf, '\0', buflen); while (count < buflen - 1) { errno = 0; ret = select_read(upsfd, temp, sizeof(temp), sec, usec); /* partial timeout (non-canon only paranoid check) */ if (ret == 0 && count) { ser_comm_fail("serial port partial timeout: %u(%s)", ln, fn); return -1; } /* error or no timeout allowed */ if (ret < 0 || (ret == 0 && !(flags & SER_TO))) { if (ret) ser_comm_fail("serial port read error: %u(%s): %s", ln, fn, strerror(errno)); else ser_comm_fail("serial port read timeout: %u(%s)", ln, fn); return ret; } /* ok, timeout is acceptable... */ if (ret == 0 && (flags & SER_TO)) { /* * ...but it doesn't imply ser_comm_good * * for example we might be in comm_fail condition, * trying to "nudge" the UPS with some command * obviously expecting timeout if the comm is still * lost. This would result with filling logs with * confusing comm lost/comm re-established pairs due to * successful serial writes */ return 0; } /* parse input */ for (i = 0; i < ret; i++) { /* overflow read */ if (count == buflen - 1) { ser_comm_fail("serial port read overflow: %u(%s)", ln, fn); tcflush(upsfd, TCIFLUSH); return -1; } /* standard "line received" condition */ if (temp[i] == ENDCHAR) { ser_comm_good(); return (ssize_t)count; } /* * "*" is set as a secondary EOL; convert to "OK" only * as a reply to shutdown command in sdok(); otherwise * next select_read() will continue normally */ if ((flags & SER_HA) && temp[i] == '*') { /* * a bit paranoid, but remember that "*" is not * real EOL; there could be some firmware in * existence, which would send both string: * "OK\n" and alert: "*". * Just in case, try to flush the input with a * small 1 sec timeout. */ memset(buf, '\0', buflen); errno = 0; ret = select_read(upsfd, temp, sizeof(temp), 1, 0); if (ret < 0) { ser_comm_fail("serial port read error: %u(%s): %s", ln, fn, strerror(errno)); return ret; } buf[0] = 'O'; buf[1] = 'K'; ser_comm_good(); return 2; } /* ignore set */ if (strchr(iset, temp[i]) || temp[i] == '*') { continue; } /* alert set */ if (strchr(aset, temp[i])) { alert_handler(temp[i]); continue; } buf[count++] = temp[i]; } } ser_comm_good(); /* buflen range limited above */ return (ssize_t)count; } #define apc_write(code) apc_write_i(code, __func__, __LINE__) static ssize_t apc_write_i(unsigned char code, const char *fn, unsigned int ln) { ssize_t ret; errno = 0; if (INVALID_FD(upsfd)) return 0; ret = ser_send_char(upsfd, code); /* * Formally any write() should never return 0, if the count != 0. For * the sake of handling any obscure nonsense, we consider such return * as a failure - thus <= condition; either way, LE is a pretty hard * condition hardly ever happening; */ if (ret <= 0) ser_comm_fail("serial port write error: %u(%s): %s", ln, fn, strerror(errno)); return ret; } /* * We have to watch out for NA, here; * This is generally safe, as otherwise we will just timeout. The reason we do * it, is that under certain conditions an UPS might respond with NA for * something it would normally handle (e.g. calling @ while being in powered * off or hibernated state. If we keep sending the "arguments" after getting * NA, they will be interpreted as commands, which is quite a bug :) * Furthermore later flushes might not work properly, if the reply to those * commands are generated with some delay. * * We also set errno to something usable, so outside upslog calls don't output * confusing "success". */ #define apc_write_long(code) apc_write_long_i(code, __func__, __LINE__) static ssize_t apc_write_long_i(const char *code, const char *fn, unsigned int ln) { char temp[APC_LBUF]; ssize_t ret; ret = apc_write_i((const unsigned char)(*code), fn, ln); if (ret != 1) return ret; /* peek for the answer - anything at this point is failure */ ret = apc_read(temp, sizeof(temp), SER_DX|SER_TO); if (ret) { errno = ECANCELED; return -1; } ret = ser_send_pace(upsfd, 50000, "%s", code + 1); if (ret >= 0) ret++; /* see remark in plain apc_write() */ if (ret != (int)strlen(code)) ser_comm_fail("serial port write error: %u(%s): %s", ln, fn, strerror(errno)); return ret; } #define apc_write_rep(code) apc_write_rep_i(code, __func__, __LINE__) static ssize_t apc_write_rep_i(unsigned char code, const char *fn, unsigned int ln) { char temp[APC_LBUF]; ssize_t ret; ret = apc_write_i(code, fn, ln); if (ret != 1) return ret; /* peek for the answer - anything at this point is failure */ ret = apc_read(temp, sizeof(temp), SER_DX|SER_TO); if (ret) { errno = ECANCELED; return -1; } usleep(1300000); ret = apc_write_i(code, fn, ln); if (ret >= 0) ret++; return ret; } /* all flags other than SER_AA are ignored */ static void apc_flush(int flags) { char temp[APC_LBUF]; if (flags & SER_AA) { tcflush(upsfd, TCOFLUSH); /* TODO */ while(apc_read(temp, sizeof(temp), SER_D0|SER_TO|SER_AA) > 0); } else { tcflush(upsfd, TCIOFLUSH); /* tcflush(upsfd, TCIFLUSH); */ /* while(apc_read(temp, sizeof(temp), SER_D0|SER_TO)); */ } } /* APC specific wrappers around set/del info - to handle "packed" variables */ static void apc_dstate_delinfo(apc_vartab_t *vt, int skip) { char *name, *nidx; int c; /* standard not packed var */ if (!(vt->flags & APC_PACK)) { dstate_delinfo(vt->name); return; } if ( !(name = xmalloc(sizeof(char) * vt->nlen0)) ) { upslogx(LOG_ERR, "apc_dstate_delinfo() failed to allocate buffer"); return; } memset(name, '\0', vt->nlen0); strncpy(name, vt->name, vt->nlen0 - 1); name[vt->nlen0 - 1] = '\0'; nidx = strstr(name,".0.") + 1; for (c = skip; c < vt->cnt; c++) { *nidx = (char)('1' + c); dstate_delinfo(name); } vt->cnt = 0; free(name); } static void apc_dstate_setinfo(apc_vartab_t *vt, const char *upsval) { char *name, *nidx; char *temp, *vidx[APC_PACK_MAX], *com, *curr; size_t upsvallen = strlen(upsval); int c; /* standard not packed var */ if (!(vt->flags & APC_PACK)) { dstate_setinfo(vt->name, "%s", convert_data(vt, upsval)); return; } if ( !(name = xmalloc(sizeof(char) * vt->nlen0)) ) { upslogx(LOG_ERR, "apc_dstate_setinfo() failed to allocate buffer"); return; } if ( !(temp = xmalloc(sizeof(char) * (upsvallen + 2))) ) { /* +2 seems like an overkill, but helps hush compiler warnings */ upslogx(LOG_ERR, "apc_dstate_setinfo() failed to allocate buffer"); free(name); return; } /* we have to set proper name for dstate_setinfo() calls */ memset(name, '\0', vt->nlen0); strncpy(name, vt->name, vt->nlen0 - 1); name[vt->nlen0 - 1] = '\0'; nidx = strstr(name,".0.") + 1; /* split the value string */ memset(temp, '\0', upsvallen + 2); strncpy(temp, upsval, upsvallen + 1); temp[upsvallen] = '\0'; curr = temp; c = 0; do { vidx[c] = curr; com = strchr(curr, ','); if (com) { curr = com + 1; *com = '\0'; } } while(++c < APC_PACK_MAX && com); /* * unlikely, but keep things tidy - remove leftover values, if * subsequent read returns less */ if (vt->cnt > c) apc_dstate_delinfo(vt, c); /* unlikely - warn user if we have more than APC_PACK_MAX fields */ if (c == APC_PACK_MAX && com) upslogx(LOG_WARNING, "packed variable %s [%s] longer than %d fields,\n" "ignoring remaining fields", vt->name, prtchr(vt->cmd), c); vt->cnt = c; while (c-- > 0) { *nidx = (char)('1' + c); if (*vidx[c]) dstate_setinfo(name, "%s", convert_data(vt, vidx[c])); else dstate_setinfo(name, "N/A"); } free(name); free(temp); } static const char *preread_data(apc_vartab_t *vt) { ssize_t ret; static char temp[APC_LBUF]; upsdebugx(1, "%s: %s [%s]", __func__, vt->name, prtchr(vt->cmd)); apc_flush(0); ret = apc_write((const unsigned char)vt->cmd); if (ret != 1) return 0; ret = apc_read(temp, sizeof(temp), SER_TO); if (ret < 1 || !strcmp(temp, "NA")) { if (ret >= 0) upslogx(LOG_ERR, "%s: %s [%s] timed out or not supported", __func__, vt->name, prtchr(vt->cmd)); return 0; } return temp; } static int poll_data(apc_vartab_t *vt) { char temp[APC_LBUF]; if (!(vt->flags & APC_PRESENT)) return 1; upsdebugx(1, "%s: %s [%s]", __func__, vt->name, prtchr(vt->cmd)); apc_flush(SER_AA); if (apc_write((const unsigned char)vt->cmd) != 1) return 0; if (apc_read(temp, sizeof(temp), SER_AA) < 1) return 0; /* automagically no longer supported by the hardware somehow */ if (!strcmp(temp, "NA")) { upslogx(LOG_WARNING, "%s: verified variable %s [%s] returned NA, removing", __func__, vt->name, prtchr(vt->cmd)); vt->flags &= ~(unsigned int)APC_PRESENT; apc_dstate_delinfo(vt, 0); } else apc_dstate_setinfo(vt, temp); return 1; } static int update_status(void) { ssize_t ret; char buf[APC_LBUF]; upsdebugx(1, "%s: [%s]", __func__, prtchr(APC_STATUS)); apc_flush(SER_AA); if (apc_write(APC_STATUS) != 1) return 0; ret = apc_read(buf, sizeof(buf), SER_AA); if ((ret < 1) || (!strcmp(buf, "NA"))) { if (ret >= 0) upslogx(LOG_WARNING, "%s: %s", __func__, "failed"); return 0; } ups_status = strtol(buf, 0, 16) & 0xff; ups_status_set(); return 1; } /* * two informative functions, to not redo the same thing in few places */ static inline void confirm_cv(unsigned char cmd, const char *tag, const char *name) { upsdebugx(1, "%s [%s] - %s supported", name, prtchr((char)cmd), tag); } static inline void warn_cv(unsigned char cmd, const char *tag, const char *name) { if (tag && name) upslogx(LOG_WARNING, "%s [%s] - %s invalid", name, prtchr((char)cmd), tag); else upslogx(LOG_WARNING, "[%s] unrecognized", prtchr((char)cmd)); } static void var_string_setup(apc_vartab_t *vt) { /* * handle special data for our two strings; note - STRING variables * cannot be PACK at the same time */ if (vt->flags & APC_STRING) { dstate_setflags(vt->name, ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux(vt->name, APC_STRLEN); vt->flags |= APC_RW; } } static int var_verify(apc_vartab_t *vt) { const char *temp; if (vt->flags & APC_MULTI) { /* APC_MULTI are handled by deprecate_vars() */ vt->flags |= APC_PRESENT; return -1; } temp = preread_data(vt); /* no conversion here, validator should operate on raw values */ if (!temp || !rexhlp(vt->regex, temp)) { warn_cv((const unsigned char)vt->cmd, "variable", vt->name); return 0; } vt->flags |= APC_PRESENT; apc_dstate_setinfo(vt, temp); var_string_setup(vt); confirm_cv((const unsigned char)vt->cmd, "variable", vt->name); return 1; } /* * This function iterates over vartab, deprecating NUT<->APC 1:n and n:1 * variables. We prefer earliest present variable. All the other ones must be * marked as not present (which implies deprecation). * This pass is required after completion of all protocol_verify() and/or * legacy_verify() calls. */ static void deprecate_vars(void) { int i, j; const char *temp; apc_vartab_t *vt, *vtn; for (i = 0; apc_vartab[i].name != NULL; i++) { vt = &apc_vartab[i]; if (!(vt->flags & APC_MULTI) || !(vt->flags & APC_PRESENT)) { /* * a) not interesting, or * b) not marked as present earlier, or already handled */ continue; } /* pre-read data, we have to verify it */ temp = preread_data(vt); /* no conversion here, validator should operate on raw values */ if (!temp || !rexhlp(vt->regex, temp)) { vt->flags &= ~(unsigned int)APC_PRESENT; warn_cv((const unsigned char)vt->cmd, "variable combination", vt->name); continue; } /* multi & present, deprecate all the remaining ones */ for (j = i + 1; apc_vartab[j].name != NULL; j++) { vtn = &apc_vartab[j]; if (strcmp(vtn->name, vt->name) && vtn->cmd != vt->cmd) continue; vtn->flags &= ~(unsigned int)APC_PRESENT; } apc_dstate_setinfo(vt, temp); var_string_setup(vt); confirm_cv((const unsigned char)vt->cmd, "variable combination", vt->name); } } static void apc_getcaps(int qco) { const char *ptr, *entptr; char upsloc, temp[APC_LBUF], cmd, loc, etmp[APC_SBUF], *endtemp; int matrix, valid; size_t nument, entlen, i; ssize_t ret; apc_vartab_t *vt; /* * If we can do caps, then we need the Firmware revision which has the * locale descriptor as the last character (ugh); this is valid for * both 'V' and 'b' commands. */ ptr = dstate_getinfo("ups.firmware"); if (ptr) upsloc = ptr[strlen(ptr) - 1]; else upsloc = 0; /* get capability string */ apc_flush(0); if (apc_write(APC_CAPS) != 1) return; /* * note - apc_read() needs larger timeout grace (not a problem w.r.t. * to NUT's timing, as it's done only during setup) and different * ignore set due to certain characters like '#' being received */ ret = apc_read(temp, sizeof(temp), SER_CC|SER_TO); if ((ret < 1) || (!strcmp(temp, "NA"))) { /* * Early Smart-UPS not as smart as the later ones ... * this should never happen on properly functioning hardware - * as capability support was reported earlier */ if (ret >= 0) upslogx(LOG_WARNING, "%s", "APC cannot do capabilities but said it could !"); return; } /* recv always puts a \0 at the end, so this is safe */ /* however it assumes a zero byte cannot be embedded */ endtemp = &temp[0] + strlen(temp); if (temp[0] != '#') { upslogx(LOG_WARNING, "unknown capability start char [%c] !", temp[0]); upsdebugx(1, "%s: please report this caps string: %s", __func__, temp); return; } if (temp[1] == '#') { /* Matrix-UPS */ ptr = &temp[0]; matrix = 1; } else { ptr = &temp[1]; matrix = 0; } /* command char, location, # of entries, entry length */ while (ptr[0] != '\0') { if (matrix) ptr += 2; /* jump over repeating ## */ /* check for idiocy */ if (ptr >= endtemp) { /* if we expected this, just ignore it */ if (qco) return; fatalx(EXIT_FAILURE, "capability string has overflowed, " "please report this error with device details!"); } entptr = &ptr[4]; cmd = ptr[0]; loc = ptr[1]; if (ptr[2] < 48 || ptr[3] < 48) { upsdebugx(3, "%s: SKIP: nument (%d) or entlen (%d) " "out of range for cmd %d at loc %d", __func__, (ptr[2] - 48), (ptr[3] - 48), cmd, loc); /* just ignore it as we did for ages see e.g. v2.7.4 * (note the next loop cycle was and still would be * no-op anyway, if "nument <= 0"). */ nument = 0; entlen = 0; /* NOT a full skip: Gotta handle "vt" to act like before */ /*ptr = entptr;*/ /*continue;*/ } else { nument = (size_t)ptr[2] - 48; entlen = (size_t)ptr[3] - 48; } vt = vt_lookup_char(cmd); valid = vt && ((loc == upsloc) || (loc == '4')) && !(vt->flags & APC_PACK); /* mark this as writable */ if (valid) { upsdebugx(1, "%s: %s [%s(%c)] - capability supported", __func__, vt->name, prtchr(cmd), loc); dstate_setflags(vt->name, ST_FLAG_RW); /* make sure setvar knows what this is */ vt->flags |= APC_RW | APC_ENUM; } else if (vt && (vt->flags & APC_PACK)) /* * Currently we assume - basing on the following * feedback: * http://www.mail-archive.com/nut-upsdev@lists.alioth.debian.org/msg03398.html * - that "packed" variables are not enumerable; if at * some point in the future it turns out to be false, * the handling will have to be a bit more complex */ upslogx(LOG_WARNING, "WARN: packed APC variable %s [%s] reported as enumerable,\n" "please report it on the mailing list", vt->name, prtchr(cmd)); for (i = 0; i < nument; i++) { if (valid) { snprintf(etmp, entlen + 1, "%s", entptr); dstate_addenum(vt->name, "%s", convert_data(vt, etmp)); } entptr += entlen; } ptr = entptr; } } static void legacy_verify(const char *var) { int i; /* * note: some NUT variables map onto multiple APC ones, e.g. firmware: * V,b -> ups.firmware; that's why we keep the loop, as it's over NUT * names */ for (i = 0; apc_vartab[i].name != NULL; i++) { if (strcmp(apc_vartab[i].name, var)) continue; var_verify(&apc_vartab[i]); } } static void protocol_verify(unsigned char cmd) { int i, found; apc_vartab_t *vt; apc_cmdtab_t *ct; /* don't bother with cmd/var we don't care about */ if (strchr(APC_UNR_CMDS, cmd)) return; /* * loop necessary for APC:NUT 1:n cases (e.g. T -> device.uptime, * ambient.0.temperature) */ found = 0; for (i = 0; apc_vartab[i].name != NULL; i++) { vt = &apc_vartab[i]; if (vt->cmd != cmd) continue; var_verify(vt); found = 1; } if (found) return; /* * see if it's a command * loop necessary for APC:NUT 1:n cases (e.g. D -> calibrate.start, * calibrate.stop) */ found = 0; for (i = 0; apc_cmdtab[i].name != NULL; i++) { ct = &apc_cmdtab[i]; if (ct->cmd != cmd) continue; ct->flags |= APC_PRESENT; dstate_addcmd(ct->name); confirm_cv(cmd, "command", ct->name); found = 1; } if (found) return; /* * epilogue - unrecognized command / variable not included * in APC_UNR_CMDS */ warn_cv(cmd, NULL, NULL); } static void oldapcsetup(void) { /* * note: battery.date and ups.id make little sense here, as * that would imply writability and this is an *old* APC UPS */ legacy_verify("ups.temperature"); legacy_verify("ups.load"); legacy_verify("input.voltage"); legacy_verify("output.voltage"); legacy_verify("battery.charge"); legacy_verify("battery.voltage"); /* these will usually timeout */ legacy_verify("ups.model"); legacy_verify("ups.serial"); legacy_verify("ups.firmware"); legacy_verify("output.current"); deprecate_vars(); /* see if this might be an old Matrix-UPS instead */ if (vt_lookup_name("output.current")) dstate_setinfo("ups.model", "Matrix-UPS"); else { /* really old models don't support ups.model (APC: 0x01) */ if (!vt_lookup_name("ups.model")) /* force the model name */ dstate_setinfo("ups.model", "Smart-UPS"); } /* * If we have come down this path then we don't do capabilities and * other shiny features. */ } /* some hardware is a special case - hot-wire the list of cmdchars */ static int firmware_table_lookup(void) { ssize_t ret; unsigned int i, j; char buf[APC_LBUF]; upsdebugx(1, "%s: attempting firmware lookup using [%s]", __func__, prtchr(APC_FW_OLD)); apc_flush(0); if (apc_write(APC_FW_OLD) != 1) return 0; if ((ret = apc_read(buf, sizeof(buf), SER_TO)) < 0) return 0; /* * Some UPSes support both 'V' and 'b'. As 'b' doesn't always return * firmware version, we attempt that only if 'V' doesn't work. */ if (!ret || !strcmp(buf, "NA")) { upsdebugx(1, "%s: attempting firmware lookup using [%s]", __func__, prtchr(APC_FW_NEW)); if (apc_write(APC_FW_NEW) != 1) return 0; if (apc_read(buf, sizeof(buf), SER_TO) < 1) return 0; } upsdebugx(1, "%s: detected firmware version: %s", __func__, buf); /* this will be reworked if we get a lot of these things */ if (!strcmp(buf, "451.2.I")) { /* quirk_capability_overflow */ upsdebugx(1, "%s: WARN: quirky firmware !", __func__); return 2; } if (rexhlp("^[a-fA-F0-9]{2}$", buf)) { /* * certain old set of UPSes that return voltage above 255V * through 'b'; see: * http://article.gmane.org/gmane.comp.monitoring.nut.user/7762 */ memset(buf, '\0', sizeof(buf)); strncpy(buf, "set\1", sizeof(buf) - 1); buf[sizeof(buf) - 1] = '\0'; } for (i = 0; apc_compattab[i].firmware != NULL; i++) { if (!strcmp(apc_compattab[i].firmware, buf)) { upsdebugx(1, "%s: matched firmware: %s", __func__, apc_compattab[i].firmware); /* magic ? */ if (strspn(apc_compattab[i].firmware, "05")) { dstate_setinfo("ups.model", "Matrix-UPS"); } else { dstate_setinfo("ups.model", "Smart-UPS"); } /* matched - run the cmdchars from the table */ upsdebugx(1, "%s: parsing out supported cmds and vars", __func__); for (j = 0; j < strlen(apc_compattab[i].cmdchars); j++) protocol_verify((const unsigned char)(apc_compattab[i].cmdchars[j])); deprecate_vars(); return 1; /* matched */ } } return 0; } static int getbaseinfo(void) { unsigned int i; ssize_t ret; int qco; char *cmds, *tail, temp[APC_LBUF]; /* * try firmware lookup first; we could start with 'a', but older models * sometimes return other things than a command set */ qco = firmware_table_lookup(); if (qco == 1) /* found compat */ return 1; upsdebugx(1, "%s: attempting var/cmdset lookup using [%s]", __func__, prtchr(APC_CMDSET)); /* * Initially we ask the UPS what commands it takes. If this fails we are * going to need an alternate strategy - we can deal with that if it * happens */ apc_flush(0); if (apc_write(APC_CMDSET) != 1) return 0; if ((ret = apc_read(temp, sizeof(temp), SER_CS|SER_TO)) < 0) return 0; if (!ret || !strcmp(temp, "NA") || !rexhlp(APC_CMDSET_FMT, temp)) { /* We have an old dumb UPS - go to specific code for old stuff */ upslogx(LOG_NOTICE, "very old or unknown APC model, support will be limited"); oldapcsetup(); return 1; } upsdebugx(1, "%s: parsing out supported cmds/vars", __func__); /* * returned set is verified for validity above, so just extract * what's interesting for us * * the known format is: * ver.alerts.commands[.stuff] */ cmds = strchr(temp, '.'); cmds = strchr(cmds + 1, '.'); tail = strchr(++cmds, '.'); if (tail) *tail = 0; for (i = 0; i < strlen(cmds); i++) protocol_verify((const unsigned char)cmds[i]); deprecate_vars(); /* if capabilities are supported, add them here */ if (strchr(cmds, APC_CAPS)) { upsdebugx(1, "%s: parsing out caps", __func__); apc_getcaps(qco); } return 1; } /* check for calibration status and either start or stop */ static int do_cal(int start) { char temp[APC_LBUF]; long tval; ssize_t ret; apc_flush(SER_AA); ret = apc_write(APC_STATUS); if (ret != 1) { return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } ret = apc_read(temp, sizeof(temp), SER_AA); /* if we can't check the current calibration status, bail out */ if ((ret < 1) || (!strcmp(temp, "NA"))) { upslogx(LOG_WARNING, "%s", "runtime calibration state can not be determined"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } tval = strtol(temp, 0, 16); if (tval & APC_STAT_CAL) { /* calibration currently happening */ if (start == 1) { /* requested start while calibration still running */ upslogx(LOG_NOTICE, "%s", "runtime calibration already in progress"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } /* stop requested */ upslogx(LOG_NOTICE, "%s", "stopping runtime calibration"); ret = apc_write(APC_CMD_CALTOGGLE); if (ret != 1) { return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } ret = apc_read(temp, sizeof(temp), SER_AA); if ((ret < 1) || (!strcmp(temp, "NA")) || (!strcmp(temp, "NO"))) { upslogx(LOG_WARNING, "stop calibration failed, cmd returned: %s", temp); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } return STAT_INSTCMD_HANDLED; /* FUTURE: success */ } /* calibration not happening */ if (start == 0) { /* stop requested */ upslogx(LOG_NOTICE, "%s", "runtime calibration not occurring"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } upslogx(LOG_NOTICE, "%s", "starting runtime calibration"); ret = apc_write(APC_CMD_CALTOGGLE); if (ret != 1) { return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } ret = apc_read(temp, sizeof(temp), SER_AA); if ((ret < 1) || (!strcmp(temp, "NA")) || (!strcmp(temp, "NO"))) { upslogx(LOG_WARNING, "start calibration failed, cmd returned: %s", temp); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } return STAT_INSTCMD_HANDLED; /* FUTURE: success */ } #if 0 /* get the UPS talking to us in smart mode */ static int smartmode(void) { int ret; char temp[APC_LBUF]; apc_flush(0); ret = apc_write(APC_GOSMART); if (ret != 1) { return 0; } ret = apc_read(temp, sizeof(temp), 0); if ((ret < 1) || (!strcmp(temp, "NA")) || (!strcmp(temp, "NO"))) { upslogx(LOG_CRIT, "%s", "enabling smartmode failed !"); return 0; } return 1; } #endif /* * get the UPS talking to us in smart mode * note: this is weird overkill, but possibly excused due to some obscure * hardware/firmware combinations; simpler version commented out above, for * now let's keep minimally adjusted old one */ static int smartmode(int cnt) { ssize_t ret; int tries; char temp[APC_LBUF]; for (tries = 0; tries < cnt; tries++) { apc_flush(0); if (apc_write(APC_GOSMART) != 1) return 0; /* timeout here is intended */ ret = apc_read(temp, sizeof(temp), SER_TO|SER_D1); if (ret > 0 && !strcmp(temp, "SM")) return 1; /* success */ if (ret < 0) /* error, so we didn't timeout - wait a bit before retry */ sleep(1); if (apc_write(27) != 1) /* ESC */ return 0; /* eat the response (might be NA, might be something else) */ apc_read(temp, sizeof(temp), SER_TO|SER_D1); } return 0; /* failure */ } /* * all shutdown commands should respond with "OK" or "*" * apc_read() handles conversion to "OK" so we care only about that one * ign allows for timeout without assuming an error */ static int sdok(int ign) { ssize_t ret; char temp[APC_SBUF]; /* * older UPSes on failed commands might just timeout, we cut down * timeout grace though * furthermore, command 'Z' will not reply with anything */ ret = apc_read(temp, sizeof(temp), SER_HA|SER_D1|SER_TO); if (ret < 0) return STAT_INSTCMD_FAILED; upsdebugx(1, "%s: got \"%s\"", __func__, temp); if ((!ret && ign) || !strcmp(temp, "OK")) { upsdebugx(1, "%s: %s", __func__, "last shutdown cmd succeeded"); return STAT_INSTCMD_HANDLED; } upsdebugx(1, "%s: %s", __func__, "last shutdown cmd failed"); return STAT_INSTCMD_FAILED; } /* soft hibernate: S - working only when OB, otherwise ignored */ static int sdcmd_S(const void *foo) { apc_flush(0); if (!foo) upsdebugx(1, "%s: issuing [%s]", __func__, prtchr(APC_CMD_SOFTDOWN)); if (apc_write(APC_CMD_SOFTDOWN) != 1) return STAT_INSTCMD_FAILED; return sdok(0); } /* soft hibernate, hack version for CS 350 & co. */ static int sdcmd_CS(const void *foo) { ssize_t ret; useconds_t cshd = 3500000; char temp[APC_SBUF]; const char *val; NUT_UNUSED_VARIABLE(foo); /* TODO: Catch overflows? * Let compilers complain about (non-)casting on systems * where useconds_t is not a good target for strtod() output */ if ((val = getval("cshdelay"))) cshd = (strtod(val, NULL) * 1000000); upsdebugx(1, "%s: issuing CS 'hack' [%s+%s] with %2.1f sec delay", __func__, prtchr(APC_CMD_SIMPWF), prtchr(APC_CMD_SOFTDOWN), (double)cshd / 1000000); if (ups_status & APC_STAT_OL) { apc_flush(0); upsdebugx(1, "%s: issuing [%s]", __func__, prtchr(APC_CMD_SIMPWF)); ret = apc_write(APC_CMD_SIMPWF); if (ret != 1) { return STAT_INSTCMD_FAILED; } /* eat response, allow timeout */ ret = apc_read(temp, sizeof(temp), SER_D1|SER_TO); if (ret < 0) { return STAT_INSTCMD_FAILED; } usleep(cshd); } /* continue with regular soft hibernate */ return sdcmd_S((void *)1); } /* * hard hibernate: @nnn / @nn * note: works differently for older and new models, see manual page for * thorough explanation */ static int sdcmd_AT(const void *str) { ssize_t ret; size_t cnt, padto, i; const char *awd = str; char temp[APC_SBUF], *ptr; memset(temp, '\0', sizeof(temp)); if (!awd) awd = "000"; cnt = strlen(awd); padto = cnt == 2 ? 2 : 3; temp[0] = APC_CMD_GRACEDOWN; ptr = temp + 1; for (i = cnt; i < padto ; i++) { *ptr++ = '0'; } strncpy(ptr, awd, sizeof(temp) - (ptr - temp) - 1); temp[sizeof(temp) - 1] = '\0'; upsdebugx(1, "%s: issuing [%s] with %ld minutes of additional wake-up delay", __func__, prtchr(APC_CMD_GRACEDOWN), strtol(awd, NULL, 10)*6); apc_flush(0); ret = apc_write_long(temp); /* Range-check: padto is 2 or 3 per above */ if (ret != (ssize_t)padto + 1) { /* FIXME: ...INSTCMD_CONVERSION_FAILED ?*/ upslogx(LOG_INSTCMD_FAILED, "issuing [%s] with %" PRIuSIZE " digits failed", prtchr(APC_CMD_GRACEDOWN), padto); return STAT_INSTCMD_FAILED; } ret = sdok(0); if (ret == STAT_INSTCMD_HANDLED || padto == 3) return (int)ret; /* FIXME: ...INSTCMD_CONVERSION_FAILED ?*/ upslogx(LOG_INSTCMD_FAILED, "command [%s] with 2 digits doesn't work - try 3 digits", prtchr(APC_CMD_GRACEDOWN)); /* * "tricky" part - we tried @nn variation and it (unsurprisingly) * failed; we have to abort the sequence with something bogus to have * the clean state; newer UPSes will respond with "NO", older will be * silent (YMMV); */ apc_write(APC_GOSMART); /* eat response, allow it to timeout */ apc_read(temp, sizeof(temp), SER_D1|SER_TO); return STAT_INSTCMD_FAILED; } /* shutdown: K - delayed poweroff */ static int sdcmd_K(const void *foo) { ssize_t ret; NUT_UNUSED_VARIABLE(foo); upsdebugx(1, "%s: issuing [%s]", __func__, prtchr(APC_CMD_SHUTDOWN)); apc_flush(0); ret = apc_write_rep(APC_CMD_SHUTDOWN); if (ret != 2) return STAT_INSTCMD_FAILED; return sdok(0); } /* shutdown: Z - immediate poweroff */ static int sdcmd_Z(const void *foo) { ssize_t ret; NUT_UNUSED_VARIABLE(foo); upsdebugx(1, "%s: issuing [%s]", __func__, prtchr(APC_CMD_OFF)); apc_flush(0); ret = apc_write_rep(APC_CMD_OFF); if (ret != 2) { return STAT_INSTCMD_FAILED; } /* note: UPS will not reply anything after this command */ return sdok(1); } static void upsdrv_shutdown_simple(void) { long sdtype = 0; const char *val; if ((val = getval("sdtype"))) sdtype = strtol(val, NULL, 10); upsdebugx(1, "%s: currently: %s, sdtype: %ld", __func__, (ups_status & APC_STAT_OL) ? "on-line" : "on battery", sdtype); switch (sdtype) { case 5: /* hard hibernate */ sdcmd_AT(getval("awd")); break; case 4: /* special hack for CS 350 and similar models */ sdcmd_CS(0); break; case 3: /* delayed poweroff */ sdcmd_K(0); break; case 2: /* instant poweroff */ sdcmd_Z(0); break; case 1: /* * Send a combined set of shutdown commands which can work * better if the UPS gets power during shutdown process * Specifically it sends both the soft shutdown 'S' and the * hard hibernate '@nnn' commands */ /* S works only when OB */ if (!(ups_status & APC_STAT_OB) || sdcmd_S(0) != STAT_INSTCMD_HANDLED) sdcmd_AT(getval("awd")); break; default: /* * Send @nnn or S, depending on OB / OL status */ if (ups_status & APC_STAT_OL) /* on line */ sdcmd_AT(getval("awd")); else sdcmd_S(0); } } static void upsdrv_shutdown_advanced(void) { const void *arg; const char *val; size_t i, len; val = getval("advorder"); len = strlen(val); upsdebugx(1, "%s: currently: %s, advorder: %s", __func__, (ups_status & APC_STAT_OL) ? "on-line" : "on battery", val); /* * try each method in the list with a little bit of handling in certain * cases */ for (i = 0; i < len; i++) { switch (val[i] - '0') { case SDIDX_AT: arg = getval("awd"); break; default: arg = NULL; } if (sdlist[val[i] - '0'](arg) == STAT_INSTCMD_HANDLED) break; /* finish if command succeeded */ } } /* power down the attached load immediately */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ char temp[APC_LBUF]; if (!smartmode(1)) upslogx(LOG_WARNING, "%s: %s", __func__, "setting SmartMode failed !"); /* check the line status */ if (apc_write(APC_STATUS) == 1) { if (apc_read(temp, sizeof(temp), SER_D1) == 1) { ups_status = strtol(temp, 0, 16); } else { upslogx(LOG_WARNING, "%s: %s", __func__, "status read failed, assuming LB+OB"); ups_status = APC_STAT_LB | APC_STAT_OB; } } else { upslogx(LOG_WARNING, "%s: %s", __func__, "status write failed, assuming LB+OB"); ups_status = APC_STAT_LB | APC_STAT_OB; } if (testvar("advorder") && toupper((size_t)*getval("advorder")) != 'N') upsdrv_shutdown_advanced(); else upsdrv_shutdown_simple(); } static int update_info(int all) { int i; upsdebugx(1, "%s: starting scan%s", __func__, all ? " (all vars)" : ""); for (i = 0; apc_vartab[i].name != NULL; i++) { if (!all && (apc_vartab[i].flags & APC_POLL) == 0) continue; if (!poll_data(&apc_vartab[i])) { upsdebugx(1, "%s: %s", __func__, "aborting scan"); return 0; } } upsdebugx(1, "%s: %s", __func__, "scan completed"); return 1; } static int setvar_enum(apc_vartab_t *vt, const char *val) { int i; ssize_t ret; char orig[APC_LBUF], temp[APC_LBUF]; const char *ptr; apc_flush(SER_AA); if (apc_write((const unsigned char)vt->cmd) != 1) return STAT_SET_FAILED; ret = apc_read(orig, sizeof(orig), SER_AA); if ((ret < 1) || (!strcmp(orig, "NA"))) return STAT_SET_FAILED; ptr = convert_data(vt, orig); /* suppress redundant changes - easier on the EEPROM */ if (!strcmp(ptr, val)) { upslogx(LOG_INFO, "%s: ignoring SET %s='%s' (unchanged value)", __func__, vt->name, val); return STAT_SET_HANDLED; /* FUTURE: no change */ } for (i = 0; i < 32; i++) { if (apc_write(APC_NEXTVAL) != 1) return STAT_SET_FAILED; /* this should return either OK (if rotated) or NO (if not) */ ret = apc_read(temp, sizeof(temp), SER_AA); if ((ret < 1) || (!strcmp(temp, "NA"))) return STAT_SET_FAILED; /* sanity checks */ if (!strcmp(temp, "NO")) return STAT_SET_FAILED; if (strcmp(temp, "OK")) return STAT_SET_FAILED; /* see what it rotated onto */ if (apc_write((const unsigned char)vt->cmd) != 1) return STAT_SET_FAILED; ret = apc_read(temp, sizeof(temp), SER_AA); if ((ret < 1) || (!strcmp(temp, "NA"))) return STAT_SET_FAILED; ptr = convert_data(vt, temp); upsdebugx(1, "%s: rotate - got [%s], want [%s]", __func__, ptr, val); if (!strcmp(ptr, val)) { /* got it */ upslogx(LOG_INFO, "%s: SET %s='%s'", __func__, vt->name, val); /* refresh data from the hardware */ poll_data(vt); return STAT_SET_HANDLED; /* FUTURE: success */ } /* check for wraparound */ if (!strcmp(ptr, orig)) { upslogx(LOG_SET_FAILED, "%s: variable %s wrapped", __func__, vt->name); return STAT_SET_FAILED; } } upslogx(LOG_SET_FAILED, "%s: gave up after 6 tries for %s", __func__, vt->name); /* refresh data from the hardware */ poll_data(vt); return STAT_SET_FAILED; } static int setvar_string(apc_vartab_t *vt, const char *val) { size_t i; ssize_t ret; char temp[APC_LBUF], *ptr; /* sanitize length */ if (strlen(val) > APC_STRLEN) { upslogx(LOG_SET_FAILED, "%s: value (%s) too long", __func__, val); return STAT_SET_FAILED; } memset(temp, '\0', sizeof(temp)); apc_flush(SER_AA); if (apc_write((const unsigned char)vt->cmd) != 1) return STAT_SET_FAILED; ret = apc_read(temp, sizeof(temp), SER_AA); if ((ret < 1) || (!strcmp(temp, "NA"))) return STAT_SET_FAILED; /* suppress redundant changes - easier on the EEPROM */ if (!strcmp(temp, val)) { upslogx(LOG_INFO, "%s: ignoring SET %s='%s' (unchanged value)", __func__, vt->name, val); return STAT_SET_HANDLED; /* FUTURE: no change */ } /* length sanitized above */ temp[0] = APC_NEXTVAL; strncpy(temp + 1, val, sizeof(temp) - 1); temp[sizeof(temp) - 1] = '\0'; ptr = temp + strlen(temp); for (i = strlen(val); i < APC_STRLEN; i++) *ptr++ = '\015'; /* pad with CRs */ *ptr = 0; if (apc_write_long(temp) != APC_STRLEN + 1) return STAT_SET_FAILED; ret = apc_read(temp, sizeof(temp), SER_AA); if (ret < 1) { upslogx(LOG_SET_FAILED, "%s: %s", __func__, "short final read"); return STAT_SET_FAILED; } if (!strcmp(temp, "NO")) { upslogx(LOG_SET_FAILED, "%s: %s", __func__, "got NO at final read"); return STAT_SET_FAILED; } /* refresh data from the hardware */ poll_data(vt); upslogx(LOG_INFO, "%s: SET %s='%s'", __func__, vt->name, val); return STAT_SET_HANDLED; /* FUTURE: success */ } static int setvar(const char *varname, const char *val) { apc_vartab_t *vt; upsdebug_SET_STARTING(varname, val); vt = vt_lookup_name(varname); if (!vt) return STAT_SET_UNKNOWN; if ((vt->flags & APC_RW) == 0) { upslogx(LOG_SET_UNKNOWN, "%s: [%s] is not writable", __func__, varname); return STAT_SET_UNKNOWN; } if (vt->flags & APC_ENUM) return setvar_enum(vt, val); if (vt->flags & APC_STRING) return setvar_string(vt, val); upslogx(LOG_SET_UNKNOWN, "%s: unknown type for [%s]", __func__, varname); return STAT_SET_UNKNOWN; } /* load on */ static int do_loadon(void) { apc_flush(0); upsdebugx(1, "%s: issuing [%s]", __func__, prtchr(APC_CMD_ON)); if (apc_write_rep(APC_CMD_ON) != 2) return STAT_INSTCMD_FAILED; /* * UPS will not reply anything after this command, but might * generate brief OVER condition (which will be corrected on * the next status update) */ upsdebugx(1, "%s: [%s] completed", __func__, prtchr(APC_CMD_ON)); return STAT_INSTCMD_HANDLED; } /* actually send the instcmd's char to the UPS */ static int do_cmd(const apc_cmdtab_t *ct) { ssize_t ret; int c; char temp[APC_LBUF]; apc_flush(SER_AA); if (ct->flags & APC_REPEAT) { ret = apc_write_rep((const unsigned char)ct->cmd); c = 2; } else { ret = apc_write((const unsigned char)ct->cmd); c = 1; } if (ret != c) { return STAT_INSTCMD_FAILED; } ret = apc_read(temp, sizeof(temp), SER_AA); if (ret < 1) return STAT_INSTCMD_FAILED; if (strcmp(temp, "OK")) { upslogx(LOG_INSTCMD_FAILED, "%s: got [%s] after command [%s]", __func__, temp, ct->name); return STAT_INSTCMD_FAILED; } upslogx(LOG_INFO, "%s: %s completed", __func__, ct->name); return STAT_INSTCMD_HANDLED; } /* some commands must be repeated in a window to execute */ static int instcmd_chktime(apc_cmdtab_t *ct, const char *ext) { double elapsed; time_t now; static time_t last = 0; time(&now); elapsed = difftime(now, last); last = now; /* you have to hit this in a small window or it fails */ if ((elapsed < MINCMDTIME) || (elapsed > MAXCMDTIME)) { upsdebugx(1, "%s: outside window for [%s %s] (%2.0f)", __func__, ct->name, ext ? ext : "\b", elapsed); return 0; } return 1; } static int instcmd(const char *cmd, const char *ext) { int i; apc_cmdtab_t *ct = NULL; upsdebug_INSTCMD_STARTING(cmd, ext); for (i = 0; apc_cmdtab[i].name != NULL; i++) { /* cmd must match */ if (strcasecmp(apc_cmdtab[i].name, cmd)) continue; /* if cmd specifies regex, ext must match */ if (apc_cmdtab[i].ext) { if (!rexhlp(apc_cmdtab[i].ext, ext)) continue; /* if cmd doesn't specify regex, ext must be NULL */ } else { if (ext) continue; } ct = &apc_cmdtab[i]; break; } if (!ct) { upslog_INSTCMD_UNKNOWN(cmd, ext); return STAT_INSTCMD_UNKNOWN; } if (!(ct->flags & APC_PRESENT)) { upslogx(LOG_INSTCMD_INVALID, "%s: command [%s %s] recognized, but" " not supported by your UPS model", __func__, cmd, ext ? ext : "\b"); return STAT_INSTCMD_INVALID; } /* first verify if the command is "nasty" */ if ((ct->flags & APC_NASTY) && !instcmd_chktime(ct, ext)) return STAT_INSTCMD_HANDLED; /* future: again */ /* we're good to go, handle special stuff first, then generic cmd */ if (!strcasecmp(cmd, "calibrate.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmd, ext); return do_cal(1); } if (!strcasecmp(cmd, "calibrate.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmd, ext); return do_cal(0); } if (!strcasecmp(cmd, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmd, ext); return do_loadon(); } if (!strcasecmp(cmd, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmd, ext); return sdcmd_Z(0); } if (!strcasecmp(cmd, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmd, ext); return sdcmd_K(0); } if (!strcasecmp(cmd, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmd, ext); if (!ext || !*ext) return sdcmd_S(0); if (toupper((size_t)*ext) == 'A') return sdcmd_AT(ext + 3); if (toupper((size_t)*ext) == 'C') return sdcmd_CS(0); } /* nothing special here */ upslog_INSTCMD_POWERSTATE_CHECKED(cmd, ext); return do_cmd(ct); } /* install pointers to functions for msg handlers called from msgparse */ static void setuphandlers(void) { upsh.setvar = setvar; upsh.instcmd = instcmd; } /* ---- functions that interface with main.c ------------------------------- */ void upsdrv_makevartable(void) { addvar(VAR_VALUE, "ttymode", "tty discipline selection"); addvar(VAR_VALUE, "cable", "alternate cable (940-0095B) selection"); addvar(VAR_VALUE, "awd", "hard hibernate's additional wake-up delay"); addvar(VAR_VALUE, "sdtype", "simple shutdown method"); addvar(VAR_VALUE, "advorder", "advanced shutdown control"); addvar(VAR_VALUE, "cshdelay", "CS hack delay"); } void upsdrv_help(void) { printf( "\nFor detailed information, please refer to:\n" " - apcsmart(8)\n" " - https://www.networkupstools.org/docs/man/apcsmart.html\n" ); } void upsdrv_initups(void) { char *val; apc_vartab_t *ptr; /* sanitize awd (additional wake-up delay of '@' command) */ if ((val = getval("awd")) && !rexhlp(APC_AWDFMT, val)) { fatalx(EXIT_FAILURE, "invalid value (%s) for option 'awd'", val); } /* sanitize sdtype */ if ((val = getval("sdtype")) && !rexhlp(APC_SDFMT, val)) { fatalx(EXIT_FAILURE, "invalid value (%s) for option 'sdtype'", val); } /* sanitize advorder */ if ((val = getval("advorder")) && !rexhlp(APC_ADVFMT, val)) { fatalx(EXIT_FAILURE, "invalid value (%s) for option 'advorder'", val); } /* sanitize cshdelay */ if ((val = getval("cshdelay")) && !rexhlp(APC_CSHDFMT, val)) { fatalx(EXIT_FAILURE, "invalid value (%s) for option 'cshdelay'", val); } upsfd = extrafd = ser_open(device_path); apc_ser_set(); /* fill length values */ for (ptr = apc_vartab; ptr->name; ptr++) ptr->nlen0 = strlen(ptr->name) + 1; } void upsdrv_cleanup(void) { char temp[APC_LBUF]; if (INVALID_FD(upsfd)) return; apc_flush(0); /* try to bring the UPS out of smart mode */ apc_write(APC_GODUMB); apc_read(temp, sizeof(temp), SER_TO); ser_close(upsfd, device_path); } void upsdrv_initinfo(void) { const char *pmod, *pser; if (!smartmode(5)) { fatalx(EXIT_FAILURE, "unable to detect an APC Smart protocol UPS on port %s\n" "check the cabling, port name or model name and try again", device_path ); } if (!getbaseinfo()) { fatalx(EXIT_FAILURE, "Problems with communicating APC UPS on port %s\n", device_path ); } /* manufacturer ID - hard-coded in this particular module */ dstate_setinfo("ups.mfr", "APC"); if (!(pmod = dstate_getinfo("ups.model"))) pmod = "\"unknown model\""; if (!(pser = dstate_getinfo("ups.serial"))) pser = "unknown serial"; upsdebugx(1, "%s: detected %s [%s] on %s", __func__, pmod, pser, device_path); setuphandlers(); /* * seems to be ok so far, it must be set so initial call of * upsdrv_updateinfo() doesn't begin with stale condition */ dstate_dataok(); } void upsdrv_updateinfo(void) { static int last_worked = 0; static time_t last_full = 0; int all; time_t now; /* try to wake up a dead UPS once in awhile */ if (dstate_is_stale()) { char temp[LARGEBUF]; size_t count = 0; if (!last_worked) upsdebugx(1, "%s: %s", __func__, "comm lost"); /* reset this so a full update runs when the UPS returns */ last_full = 0; /* Flush the buffer in case it helps, * or sleep 1 sec if buffer is empty */ while (select_read(upsfd, temp, sizeof(temp), 1, 0) > 0) { count++; } errno = 0; if (!count) { /* Do not flood the device (and our logs, below) * with retry attempts */ usleep(1000000); } if (++last_worked < 10) return; /* become aggressive after a few tries */ if (!(last_worked % 60)) { upslogx(LOG_WARNING, "Trying to reconnect to the UPS"); dstate_setinfo("driver.state", "reconnect.trying"); upsdebugx(1, "%s: call upsdrv_cleanup", __func__); /* dstate_setinfo("driver.state", "cleanup.upsdrv"); */ upsdrv_cleanup(); upsdebugx(1, "%s: sleep 5 sec", __func__); usleep(5000000); upsdebugx(1, "%s: call upsdrv_initups", __func__); /* dstate_setinfo("driver.state", "init.device"); */ upsdrv_initups(); upsdebugx(1, "%s: call upsdrv_initinfo", __func__); /* dstate_setinfo("driver.state", "init.info"); */ upsdrv_initinfo(); upsdebugx(1, "%s: call upsdrv_updateinfo", __func__); dstate_setinfo("driver.state", "reconnect.updateinfo"); /* dstate_setinfo("driver.state", "init.updateinfo"); */ upsdrv_updateinfo(); dstate_setinfo("driver.state", "init.quiet"); } upsdebugx(1, "%s: nudging UPS with 'Y', iteration #%d ...", __func__, last_worked); if (!smartmode(1)) { return; } if (last_worked > 10) upslogx(LOG_WARNING, "%s: recovered the connection", __func__); upsdebugx(1, "%s: recovered the connection", __func__); last_worked = 0; } if (!update_status()) { dstate_datastale(); return; } time(&now); /* refresh all variables hourly */ /* does not catch measure-ups II insertion/removal */ if (difftime(now, last_full) > 3600) { last_full = now; all = 1; } else all = 0; if (update_info(all)) { dstate_dataok(); } else { dstate_datastale(); } } nut-2.8.4/drivers/libshut.c0000664000175000017500000012273315000733203012553 00000000000000/*! * @file libshut.c * @brief HID Library - SHUT communication sub driver * * @author Copyright (C) * 2006 - 2009 Arnaud Quette * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * -------------------------------------------------------------------------- */ /* TODO list * - cleanup, cleanup, cleanup * - manage interrupt and complete libshut_get_interrupt / shut_control_msg routing * - baudrate negotiation * - complete shut_strerror * - validate / complete commands and data table in mge-hid from mge-shut */ #include "config.h" /* must be the first header */ #include #include #include #include #include "nut_stdint.h" /* for uint8_t, uint16_t, uint32_t */ #include "serial.h" #include "libshut.h" #include "common.h" /* for xmalloc, upsdebugx prototypes */ #define SHUT_DRIVER_NAME "SHUT communication driver" #define SHUT_DRIVER_VERSION "0.89" /* communication driver description structure */ upsdrv_info_t comm_upsdrv_info = { SHUT_DRIVER_NAME, SHUT_DRIVER_VERSION, NULL, 0, { NULL } }; #define MAX_TRY 4 #define MAX_STRING_SIZE 128 /*! * HID descriptor, completed with desc{type,len} */ struct my_hid_descriptor { uint8_t bLength; uint8_t bDescriptorType; uint16_t bcdHID; uint8_t bCountryCode; uint8_t bNumDescriptors; uint8_t bReportDescriptorType; uint16_t wDescriptorLength; }; /*!******************************************************** * USB spec information, synchronised with (ripped from) libusb */ /* * Device and/or Interface Class codes */ #define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ #define USB_CLASS_AUDIO 1 #define USB_CLASS_COMM 2 #define USB_CLASS_HID 3 #define USB_CLASS_PRINTER 7 #define USB_CLASS_MASS_STORAGE 8 #define USB_CLASS_HUB 9 #define USB_CLASS_DATA 10 #define USB_CLASS_VENDOR_SPEC 0xff /* * Descriptor types */ #define USB_DT_DEVICE 0x01 #define USB_DT_CONFIG 0x02 #define USB_DT_STRING 0x03 #define USB_DT_INTERFACE 0x04 #define USB_DT_ENDPOINT 0x05 #define USB_DT_HID 0x21 #define USB_DT_REPORT 0x22 #define USB_DT_PHYSICAL 0x23 #define USB_DT_HUB 0x29 /* * Descriptor sizes per descriptor type */ #define USB_DT_DEVICE_SIZE 18 #define USB_DT_CONFIG_SIZE 9 #define USB_DT_INTERFACE_SIZE 9 #define USB_DT_ENDPOINT_SIZE 7 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ #define USB_DT_HUB_NONVAR_SIZE 7 /* * Standard requests */ #define USB_REQ_GET_STATUS 0x00 #define USB_REQ_CLEAR_FEATURE 0x01 /* 0x02 is reserved */ #define USB_REQ_SET_FEATURE 0x03 /* 0x04 is reserved */ #define USB_REQ_SET_ADDRESS 0x05 #define USB_REQ_GET_DESCRIPTOR 0x06 #define USB_REQ_SET_DESCRIPTOR 0x07 #define USB_REQ_GET_CONFIGURATION 0x08 #define USB_REQ_SET_CONFIGURATION 0x09 #define USB_REQ_GET_INTERFACE 0x0A #define USB_REQ_SET_INTERFACE 0x0B #define USB_REQ_SYNCH_FRAME 0x0C #define USB_TYPE_STANDARD (0x00 << 5) #define USB_TYPE_CLASS (0x01 << 5) #define USB_TYPE_VENDOR (0x02 << 5) #define USB_TYPE_RESERVED (0x03 << 5) #define USB_RECIP_DEVICE 0x00 #define USB_RECIP_INTERFACE 0x01 #define USB_RECIP_ENDPOINT 0x02 #define USB_RECIP_OTHER 0x03 /* * Various libusb API related stuff */ #define USB_ENDPOINT_IN 0x80 #define USB_ENDPOINT_OUT 0x00 /*! * end of USB spec information *********************************************************/ /*! * HID definitions */ #define HID_REPORT_TYPE_INPUT 0x01 #define HID_REPORT_TYPE_OUTPUT 0x02 #define HID_REPORT_TYPE_FEATURE 0x03 #define REQUEST_TYPE_USB 0x80 #define REQUEST_TYPE_HID 0x81 #define REQUEST_TYPE_GET_REPORT 0xa1 #define REQUEST_TYPE_SET_REPORT 0x21 #define MAX_REPORT_SIZE 0x1800 /*! * SHUT definitions - From Simplified SHUT spec */ #define SHUT_TYPE_REQUEST 0x01 #define SHUT_TYPE_RESPONSE 0x04 #define SHUT_TYPE_NOTIFY 0x05 #define SHUT_OK 0x06 #define SHUT_NOK 0x15 /* sync signals are also used to set the notification level */ #define SHUT_SYNC 0x16 /* complete notifications - not yet managed */ /* but needed for some early Ellipse models */ #define SHUT_SYNC_LIGHT 0x17 /* partial notifications */ #define SHUT_SYNC_OFF 0x18 /* disable notifications - only do polling */ #define SHUT_PKT_LAST 0x80 #define SHUT_TIMEOUT 3000 /*! * SHUT functions for HID marshalling */ /* Expected evaluated types for the API after typedefs: * static int shut_get_descriptor(int upsfd, unsigned char type, * unsigned char index, void *buf, int size); * static int shut_get_string_simple(int upsfd, int index, * char *buf, size_t buflen); * static int libshut_get_report(int upsfd, int ReportId, * unsigned char *raw_buf, int ReportSize ); * static int libshut_set_report(int upsfd, int id, unsigned char *pkt, * int reportlen); * static int libshut_get_interrupt(int upsfd, unsigned char *buf, * int bufsize, int timeout); * static void libshut_close(int upsfd); */ static int shut_get_descriptor( usb_dev_handle upsfd, usb_ctrl_requesttype type, usb_ctrl_descindex index, void *buf, usb_ctrl_charbufsize size); static int shut_get_string_simple( usb_dev_handle upsfd, usb_ctrl_strindex index, char *buf, usb_ctrl_charbufsize buflen); static int libshut_get_report( usb_dev_handle upsfd, usb_ctrl_repindex ReportId, usb_ctrl_charbuf raw_buf, usb_ctrl_charbufsize ReportSize); static int libshut_set_report( usb_dev_handle upsfd, usb_ctrl_repindex id, usb_ctrl_charbuf pkt, usb_ctrl_charbufsize reportlen); static int libshut_get_interrupt( usb_dev_handle upsfd, usb_ctrl_charbuf buf, usb_ctrl_charbufsize bufsize, usb_ctrl_timeout_msec timeout); static void libshut_close(usb_dev_handle upsfd); /* FIXME */ static const char * shut_strerror(void) { return ""; } /*! * From SHUT specifications * sync'ed with libusb */ typedef struct shut_ctrltransfer_s { uint8_t bRequestType; uint8_t bRequest; uint16_t wValue; uint16_t wIndex; uint16_t wLength; uint32_t timeout; /* in milliseconds */ /* pointer to data */ void *data; /* uint8_t padding[8]; for use with shut_set_report?! */ } shut_ctrltransfer_t; typedef union hid_data_t { shut_ctrltransfer_t hid_pkt; uint8_t raw_pkt[8]; /* max report lengh, was 8 */ } hid_data_t; typedef struct shut_packet_s { uint8_t bType; uint8_t bLength; hid_data_t data; uint8_t bChecksum; } shut_packet_t; typedef union shut_data_t { shut_packet_t shut_pkt; uint8_t raw_pkt[11]; } shut_data_t; typedef union hid_desc_data_t { struct my_hid_descriptor hid_desc; uint8_t raw_desc[9]; /* max report lengh, aws 9 */ } hid_desc_data_t; /* Device descriptor */ typedef struct device_descriptor_s { uint8_t bLength; uint8_t bDescriptorType; uint16_t bcdUSB; uint8_t bDeviceClass; uint8_t bDeviceSubClass; uint8_t bDeviceProtocol; uint8_t bMaxPacketSize0; uint16_t idVendor; uint16_t idProduct; uint16_t bcdDevice; uint8_t iManufacturer; uint8_t iProduct; uint8_t iSerialNumber; uint8_t bNumConfigurations; } device_descriptor_t; #if 0 typedef union device_desc_data_t { device_descriptor_t dev_desc; uint8_t raw_desc[18]; } device_desc_data_t; #endif /* Low level SHUT (Serial HID UPS Transfer) routines */ /* Expected evaluated types for the API after typedefs: static void setline(int upsfd, int set); static int shut_synchronise(int upsfd); static int shut_wait_ack(int upsfd); static int shut_interrupt_read(int upsfd, int ep, unsigned char *bytes, int size, int timeout); static int shut_control_msg(int upsfd, int requesttype, int request, int value, int index, unsigned char *bytes, int size, int timeout); */ static void setline( usb_dev_handle upsfd, int set); static int shut_synchronise(usb_dev_handle upsfd); static int shut_wait_ack(usb_dev_handle upsfd); static int shut_interrupt_read( usb_dev_handle upsfd, usb_ctrl_endpoint ep, usb_ctrl_charbuf bytes, usb_ctrl_charbufsize size, usb_ctrl_timeout_msec timeout); static int shut_control_msg( usb_dev_handle upsfd, usb_ctrl_requesttype requesttype, usb_ctrl_request request, usb_ctrl_msgvalue value, usb_ctrl_repindex index, usb_ctrl_charbuf bytes, usb_ctrl_charbufsize size, usb_ctrl_timeout_msec timeout); /* Data portability */ /* realign packet data according to Endianess */ #define BYTESWAP(in) ((((uint16_t)in & 0x00FF) << 8) + (((uint16_t)in & 0xFF00) >> 8)) static void align_request(struct shut_ctrltransfer_s *ctrl) { #if (defined (WORDS_BIGENDIAN)) && (WORDS_BIGENDIAN) /* Sparc/Mips/... are big endian, USB/SHUT little endian */ (*ctrl).wValue = BYTESWAP((*ctrl).wValue); (*ctrl).wIndex = BYTESWAP((*ctrl).wIndex); (*ctrl).wLength = BYTESWAP((*ctrl).wLength); #else NUT_UNUSED_VARIABLE(ctrl); #endif } #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtype-limits" #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif /* On success, fill in the curDevice structure and return the report * descriptor length. On failure, return -1. * Note: When callback is not NULL, the report descriptor will be * passed to this function together with the upsfd and SHUTDevice_t * information. This callback should return a value > 0 if the device * is accepted, or < 1 if not. */ /* Expected evaluated types for the API after typedefs: * static int libshut_open(int *arg_upsfd, SHUTDevice_t *curDevice, char *arg_device_path, * int (*callback)(int arg_upsfd, SHUTDevice_t *hd, * unsigned char *rdbuf, int rdlen)) */ static int libshut_open( usb_dev_handle *arg_upsfd, SHUTDevice_t *curDevice, char *arg_device_path, int (*callback)(usb_dev_handle arg_upsfd, SHUTDevice_t *hd, usb_ctrl_charbuf rdbuf, usb_ctrl_charbufsize rdlen)) { int ret, res; usb_ctrl_char buf[20] __attribute__((aligned(4))); char string[MAX_STRING_SIZE]; struct my_hid_descriptor desc_buf, *desc = &desc_buf; struct device_descriptor_s dev_descriptor_buf, *dev_descriptor = &dev_descriptor_buf; /* report descriptor */ usb_ctrl_char rdbuf[MAX_REPORT_SIZE]; usb_ctrl_charbufsize rdlen; /* All devices use HID descriptor at index 0. However, some newer * Eaton units have a light HID descriptor at index 0, and the full * version is at index 1 (in which case, bcdDevice == 0x0202) */ usb_ctrl_descindex hid_desc_index = 0; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE # pragma GCC diagnostic ignored "-Wtautological-type-limit-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE #pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif static int usb_hid_number_opts_parsed = 0; if (!usb_hid_number_opts_parsed) { const char *s; unsigned short us = 0; if ((s = getval("usb_hid_desc_index"))) { if (!str_to_ushort(s, &us, 16) || (us > USB_CTRL_DESCINDEX_MAX)) { fatalx(EXIT_FAILURE, "%s: could not parse usb_hid_desc_index", __func__); } hid_desc_index = (usb_ctrl_descindex)us; } usb_hid_number_opts_parsed = 1; } #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_TYPE_LIMIT_COMPARE) ) # pragma GCC diagnostic pop #endif if (!arg_device_path) { fatalx(EXIT_FAILURE, "%s: arg_device_path=null", __func__); } upsdebugx(2, "libshut_open: using port %s", arg_device_path); /* If device is still open, close it */ if (VALID_FD_SER(*arg_upsfd)) { ser_close(*arg_upsfd, arg_device_path); } /* initialize serial port */ /* FIXME: add variable baudrate detection */ *arg_upsfd = ser_open(arg_device_path); ser_set_speed(*arg_upsfd, arg_device_path, B2400); setline(*arg_upsfd, 1); /* initialise communication */ if (!shut_synchronise(*arg_upsfd)) { upsdebugx(2, "No communication with UPS"); return -1; } upsdebugx(2, "Communication with UPS established"); /* we can skip the rest due to serial bus specifics! */ if (!callback) { return 1; } /* Get DEVICE descriptor */ memcpy(dev_descriptor, buf, sizeof(struct device_descriptor_s)); res = shut_get_descriptor(*arg_upsfd, USB_DT_DEVICE, 0, buf, USB_DT_DEVICE_SIZE); /* res = shut_control_msg(devp, USB_ENDPOINT_IN+1, USB_REQ_GET_DESCRIPTOR, (USB_DT_DEVICE << 8) + 0, 0, buf, 0x9, SHUT_TIMEOUT); */ if (res < 0) { upsdebugx(2, "Unable to get DEVICE descriptor (%s)", shut_strerror()); return -1; } if (res < 9) { upsdebugx(2, "DEVICE descriptor too short (expected %d, got %d)", USB_DT_DEVICE_SIZE, res); return -1; } /* collect the identifying information of this device. Note that this is safe, because there's no need to claim an interface for this (and therefore we do not yet need to detach any kernel drivers). */ free(curDevice->Vendor); free(curDevice->Product); free(curDevice->Serial); free(curDevice->Bus); free(curDevice->Device); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) free(curDevice->BusPort); #endif memset(curDevice, '\0', sizeof(*curDevice)); curDevice->VendorID = dev_descriptor->idVendor; curDevice->ProductID = dev_descriptor->idProduct; curDevice->Bus = strdup("serial"); curDevice->Device = strdup(arg_device_path); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) curDevice->BusPort = (char *)malloc(4); if (curDevice->BusPort == NULL) { fatal_with_errno(EXIT_FAILURE, "Out of memory"); } upsdebugx(2, "%s: NOTE: BusPort is always zero with libshut", __func__); sprintf(curDevice->BusPort, "%03d", 0); #endif curDevice->bcdDevice = dev_descriptor->bcdDevice; curDevice->Vendor = NULL; if (dev_descriptor->iManufacturer) { ret = shut_get_string_simple(*arg_upsfd, dev_descriptor->iManufacturer, string, MAX_STRING_SIZE); if (ret > 0) { curDevice->Vendor = strdup(string); } } if (curDevice->Vendor == NULL) { curDevice->Vendor = strdup("Eaton"); } /* ensure iProduct retrieval */ if (dev_descriptor->iProduct) { ret = shut_get_string_simple(*arg_upsfd, dev_descriptor->iProduct, string, MAX_STRING_SIZE); } else { ret = 0; } if (ret > 0) { curDevice->Product = strdup(string); } else { curDevice->Product = strdup("unknown"); } if (dev_descriptor->iSerialNumber) { ret = shut_get_string_simple(*arg_upsfd, dev_descriptor->iSerialNumber, string, 0x25); } else { ret = 0; } if (ret > 0) { curDevice->Serial = strdup(string); } else { curDevice->Serial = strdup("unknown"); } upsdebugx(2, "- VendorID: %04x", curDevice->VendorID); upsdebugx(2, "- ProductID: %04x", curDevice->ProductID); upsdebugx(2, "- Manufacturer: %s", curDevice->Vendor); upsdebugx(2, "- Product: %s", curDevice->Product); upsdebugx(2, "- Serial Number: %s", curDevice->Serial); upsdebugx(2, "- Bus: %s", curDevice->Bus); #if (defined WITH_USB_BUSPORT) && (WITH_USB_BUSPORT) upsdebugx(2, "- Bus Port: %s", curDevice->BusPort ? curDevice->BusPort : "unknown"); #endif upsdebugx(2, "- Device: %s", curDevice->Device ? curDevice->Device : "unknown"); upsdebugx(2, "- Device release number: %04x", curDevice->bcdDevice); upsdebugx(2, "Device matches"); if ((curDevice->VendorID == 0x463) && (curDevice->bcdDevice == 0x0202)) { upsdebugx(1, "Eaton device v2.02. Using full report descriptor"); if (!getval("usb_hid_desc_index")) hid_desc_index = 1; } /* Get HID descriptor */ memcpy(desc, buf, sizeof(struct my_hid_descriptor)); res = shut_get_descriptor(*arg_upsfd, USB_DT_HID, hid_desc_index, buf, 0x9); /* res = shut_control_msg(devp, USB_ENDPOINT_IN+1, USB_REQ_GET_DESCRIPTOR, (USB_DT_HID << 8) + 0, 0, buf, 0x9, SHUT_TIMEOUT); */ if (res < 0) { upsdebugx(2, "Unable to get HID descriptor (%s)", shut_strerror()); return -1; } if (res < 9) { upsdebugx(2, "HID descriptor too short (expected %d, got %d)", 8, res); return -1; } /* USB_LE16_TO_CPU(desc->wDescriptorLength); */ desc->wDescriptorLength = (0x00FF & (uint8_t)buf[7]) | ((0x00FF & (uint8_t)buf[8]) << 8); upsdebugx(2, "HID descriptor retrieved (Reportlen = %u)", desc->wDescriptorLength); /* if (!dev->config) { upsdebugx(2, " Couldn't retrieve descriptors"); return -1; } */ rdlen = desc->wDescriptorLength; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if (rdlen > sizeof(rdbuf) || rdlen > INT_MAX) { #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif upsdebugx(2, "HID descriptor too long %" PRI_NUT_USB_CTRL_CHARBUFSIZE " (max %" PRIuSIZE ")", rdlen, sizeof(rdbuf)); return -1; } /* Get REPORT descriptor */ res = shut_get_descriptor(*arg_upsfd, USB_DT_REPORT, hid_desc_index, rdbuf, rdlen); /* res = shut_control_msg(devp, USB_ENDPOINT_IN+1, USB_REQ_GET_DESCRIPTOR, (USB_DT_REPORT << 8) + 0, 0, ReportDesc, desc->wDescriptorLength, SHUT_TIMEOUT); */ #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if (res >= 0 && (uintmax_t)res < (uintmax_t)SIZE_MAX && (size_t)res == rdlen) #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif { res = callback(*arg_upsfd, curDevice, rdbuf, rdlen); if (res < 1) { upsdebugx(2, "Caller doesn't like this device"); return -1; } upsdebugx(2, "Report descriptor retrieved (Reportlen = %" PRI_NUT_USB_CTRL_CHARBUFSIZE ")", rdlen); upsdebugx(2, "Found HID device"); fflush(stdout); return (int)rdlen; } if (res < 0) { upsdebugx(2, "Unable to get Report descriptor (%d)", res); } else { upsdebugx(2, "Report descriptor too short (expected %" PRI_NUT_USB_CTRL_CHARBUFSIZE ", got %d)", rdlen, res); } upsdebugx(2, "libshut: No appropriate HID device found"); fflush(stdout); return -1; } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic pop #endif /* Expected evaluated types for the API after typedefs: * static void libshut_close(int arg_upsfd) */ static void libshut_close(usb_dev_handle arg_upsfd) { if (INVALID_FD_SER(arg_upsfd)) { return; } ser_close(arg_upsfd, NULL); } /* return the report of ID=type in report * return -1 on failure, report length on success */ /* Expected evaluated types for the API after typedefs: * static int libshut_get_report(int arg_upsfd, int ReportId, * unsigned char *raw_buf, int ReportSize) */ static int libshut_get_report( usb_dev_handle arg_upsfd, usb_ctrl_repindex ReportId, usb_ctrl_charbuf raw_buf, usb_ctrl_charbufsize ReportSize) { if (INVALID_FD_SER(arg_upsfd)) { return 0; } upsdebugx(4, "Entering libshut_get_report"); return shut_control_msg(arg_upsfd, REQUEST_TYPE_GET_REPORT, /* == USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE, */ 0x01, ReportId+(0x03<<8), /* HID_REPORT_TYPE_FEATURE */ 0, raw_buf, ReportSize, SHUT_TIMEOUT); } /* return ReportSize upon success ; -1 otherwise */ /* Expected evaluated types for the API after typedefs: * static int libshut_set_report(int arg_upsfd, int ReportId, * unsigned char *raw_buf, int ReportSize) */ static int libshut_set_report( usb_dev_handle arg_upsfd, usb_ctrl_repindex ReportId, usb_ctrl_charbuf raw_buf, usb_ctrl_charbufsize ReportSize) { int ret; if (INVALID_FD_SER(arg_upsfd)) { return 0; } upsdebugx(1, "Entering libshut_set_report (report %x, " "len %" PRI_NUT_USB_CTRL_CHARBUFSIZE ")", (unsigned int)ReportId, ReportSize); if ((uintmax_t)ReportSize > (uintmax_t)INT_MAX) { upsdebugx(1, "%s: ReportSize exceeds INT_MAX", __func__); return -1; } upsdebug_hex (4, "==> Report after set", raw_buf, ReportSize); ret = shut_control_msg(arg_upsfd, REQUEST_TYPE_SET_REPORT, /* == USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, */ 0x09, ReportId+(0x03<<8), /* HID_REPORT_TYPE_FEATURE */ 0, raw_buf, ReportSize, SHUT_TIMEOUT); return ((ret == 0) ? (int)ReportSize : ret); } /* Expected evaluated types for the API after typedefs: * static int libshut_get_string(int arg_upsfd, * int StringIdx, char *buf, size_t buflen) */ static int libshut_get_string( usb_dev_handle arg_upsfd, usb_ctrl_strindex StringIdx, char *buf, usb_ctrl_charbufsize buflen) { int ret; if (INVALID_FD_SER(arg_upsfd)) { return -1; } ret = shut_get_string_simple(arg_upsfd, StringIdx, buf, buflen); if (ret > 0) upsdebugx(2, "-> String: %s (len = %i/%i)", buf, ret, (int)buflen); else upsdebugx(2, "- Unable to fetch buf"); return ret; } /* Expected evaluated types for the API after typedefs: * static int libshut_get_interrupt(int arg_upsfd, unsigned char *buf, * int bufsize, int timeout) */ static int libshut_get_interrupt( usb_dev_handle arg_upsfd, usb_ctrl_charbuf buf, usb_ctrl_charbufsize bufsize, usb_ctrl_timeout_msec timeout) { int ret; if (INVALID_FD_SER(arg_upsfd)) { return -1; } /* FIXME: hardcoded interrupt EP => need to get EP descr for IF descr */ ret = shut_interrupt_read(arg_upsfd, 0x81, buf, bufsize, timeout); if (ret > 0) upsdebugx(6, " ok"); else upsdebugx(6, " none (%i)", ret); return ret; } shut_communication_subdriver_t shut_subdriver = { SHUT_DRIVER_NAME, SHUT_DRIVER_VERSION, libshut_open, libshut_close, libshut_get_report, libshut_set_report, libshut_get_string, libshut_get_interrupt }; /***********************************************************************/ /********** Low level SHUT (Serial HID UPS Transfer) routines **********/ /***********************************************************************/ /* * set RTS to on and DTR to off * * set : 1 to set comm * set : 0 to stop commupsh. */ /* Expected evaluated types for the API after typedefs: * void setline(int arg_upsfd, int set) */ void setline(usb_dev_handle arg_upsfd, int set) { if (INVALID_FD_SER(arg_upsfd)) { return; } upsdebugx(3, "entering setline(%i)", set); if (set == 1) { ser_set_dtr(arg_upsfd, 0); ser_set_rts(arg_upsfd, 1); } else { ser_set_dtr(arg_upsfd, 1); ser_set_rts(arg_upsfd, 0); } } /***************************************************************************** * shut_synchronise () * * initiate communication with the UPS * * return TRUE on success, FALSE on failure * *****************************************************************************/ /* Expected evaluated types for the API after typedefs: * int shut_synchronise(int arg_upsfd) */ int shut_synchronise(usb_dev_handle arg_upsfd) { int retCode = 0; unsigned char c = SHUT_SYNC_OFF, reply; int try; upsdebugx (2, "entering shut_synchronise()"); reply = '\0'; /* FIXME: re enable notification support? switch (notification) { case OFF_NOTIFICATION: c = SHUT_SYNC_OFF; break; case LIGHT_NOTIFICATION: c = SHUT_SYNC_LIGHT; break; default: case COMPLETE_NOTIFICATION: c = SHUT_SYNC; break; } */ /* Sync with the UPS according to notification */ for (try = 0; try < MAX_TRY; try++) { upsdebugx (3, "Syncing communication (try %i)", try); if ((ser_send_char(arg_upsfd, c)) == -1) { upsdebugx (3, "Communication error while writing to port"); continue; } ser_get_char(arg_upsfd, &reply, 1, 0); if (reply == c) { upsdebugx (3, "Syncing and notification setting done"); return 1; } } return retCode; } /*! * Compute a SHUT checksum for the packet "buf" */ /* Expected evaluated types for the API after typedefs: * static unsigned char shut_checksum(const unsigned char *buf, int bufsize) */ static unsigned char shut_checksum( const usb_ctrl_charbuf buf, usb_ctrl_charbufsize bufsize) { usb_ctrl_charbufsize i; unsigned char chk=0; for(i=0; i0 && Retry<3) { /* if(serial_read (SHUT_TIMEOUT, &Start[0]) > 0) */ if(ser_get_char(arg_upsfd, &Start[0], SHUT_TIMEOUT/1000, 0) > 0) { /* sdata.shut_pkt.bType = Start[0]; */ if(Start[0]==SHUT_SYNC) { upsdebugx (4, "received SYNC token"); memcpy(Buf, Start, 1); return 1; } else if(Start[0]==SHUT_SYNC_OFF) { upsdebugx (4, "received SYNC_OFF token"); memcpy(Buf, Start, 1); return 1; } else { /* if((serial_read (SHUT_TIMEOUT, &Start[1]) > 0) && */ if( (ser_get_char(arg_upsfd, &Start[1], SHUT_TIMEOUT/1000, 0) > 0) && ((Start[1]>>4)==(Start[1]&0x0F))) { upsdebug_hex(4, "Receive", Start, 2); Size=Start[1]&0x0F; if( Size > 8 ) { upsdebugx (4, "shut_packet_recv: invalid frame size = %d", Size); ser_send_char(arg_upsfd, SHUT_NOK); Retry++; break; } /* sdata.shut_pkt.bLength = Size; */ for(recv=0;recv OK", Chk[0]); memcpy(Buf, Frame, Size); datalen-=Size; Buf+=Size; Pos+=Size; Retry=0; ser_send_char(arg_upsfd, SHUT_OK); /* shut_token_send(SHUT_OK); */ /* Check if there are more data to receive */ if((Start[0] & 0xf0) == SHUT_PKT_LAST) { /* Check if it's a notification */ if ((Start[0] & 0x0f) == SHUT_TYPE_NOTIFY) { /* TODO: process notification (dropped for now) */ upsdebugx (4, "=> notification"); datalen+=Pos; Pos=0; } else { return Pos; } } else upsdebugx (4, "need more data (%" PRI_NUT_USB_CTRL_CHARBUFSIZE ")!", datalen); } else { upsdebugx (4, "shut_checksum: %02x => NOK", Chk[0]); ser_send_char(arg_upsfd, SHUT_NOK); /* shut_token_send(SHUT_NOK); */ Retry++; } } else { return 0; } } } else { Retry++; } } /* while */ return 0; } /**********************************************************************/ /* Expected evaluated types for the API after typedefs: * static int shut_interrupt_read(int arg_upsfd, int ep, * unsigned char *bytes, int size, * int timeout) */ static int shut_interrupt_read( usb_dev_handle arg_upsfd, usb_ctrl_endpoint ep, usb_ctrl_charbuf bytes, usb_ctrl_charbufsize size, usb_ctrl_timeout_msec timeout) { /* usleep(timeout * 1000); */ /* FIXME: to be written */ NUT_UNUSED_VARIABLE(arg_upsfd); NUT_UNUSED_VARIABLE(ep); NUT_UNUSED_VARIABLE(bytes); NUT_UNUSED_VARIABLE(size); NUT_UNUSED_VARIABLE(timeout); return 0; } /**********************************************************************/ /* Expected evaluated types for the API after typedefs: * static int shut_get_string_simple(int arg_upsfd, int index, * char *buf, size_t buflen) */ static int shut_get_string_simple( usb_dev_handle arg_upsfd, usb_ctrl_strindex index, char *buf, usb_ctrl_charbufsize buflen) { usb_ctrl_char tbuf[255]; /* Some devices choke on size > 255 */ int ret, si, di; ret = shut_control_msg(arg_upsfd, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, 0x0, tbuf, buflen, SHUT_TIMEOUT); if (ret < 0) return ret; if (tbuf[1] != USB_DT_STRING) return -EIO; if (tbuf[0] > ret) return -EFBIG; /* skip the UTF8 zero'ed high bytes */ for (di = 0, si = 2; si < tbuf[0]; si += 2) { if (di >= (int)(buflen - 1)) break; if (tbuf[si + 1]) /* high byte */ buf[di++] = '?'; else buf[di++] = (char)tbuf[si]; } buf[di] = 0; return di; } /* * Human Interface Device (HID) functions *********************************************************************/ /********************************************************************** * shut_get_descriptor(int desctype, usb_ctrl_charbuf pkt) * * get descriptor specified by DescType and return it in Buf * * desctype - from shutdataType * pkt - where to store the report received * * return 0 on success, -1 on failure, -2 on NACK * *********************************************************************/ /* Expected evaluated types for the API after typedefs: * static int shut_get_descriptor(int arg_upsfd, unsigned char type, * unsigned char index, void *buf, int size) */ static int shut_get_descriptor( usb_dev_handle arg_upsfd, usb_ctrl_requesttype type, usb_ctrl_descindex index, void *buf, usb_ctrl_charbufsize size) { memset(buf, 0, size); upsdebugx (2, "entering shut_get_descriptor(n %02x, %" PRI_NUT_USB_CTRL_CHARBUFSIZE ")", type, size); return shut_control_msg(arg_upsfd, USB_ENDPOINT_IN+(type>=USB_DT_HID?1:0), USB_REQ_GET_DESCRIPTOR, (type << 8) + index, 0, buf, size, SHUT_TIMEOUT); } /* Take care of a SHUT transfer (sending and receiving data) */ /* Expected evaluated types for the API after typedefs: * static int shut_control_msg(int arg_upsfd, int requesttype, int request, * int value, int index, unsigned char *bytes, int size, * int timeout) */ static int shut_control_msg( usb_dev_handle arg_upsfd, usb_ctrl_requesttype requesttype, usb_ctrl_request request, usb_ctrl_msgvalue value, usb_ctrl_repindex index, usb_ctrl_charbuf bytes, usb_ctrl_charbufsize size, usb_ctrl_timeout_msec timeout) { unsigned char shut_pkt[11]; short Retry=1, set_pass = -1; usb_ctrl_charbufsize data_size, remaining_size = size; int i; struct shut_ctrltransfer_s ctrl; int ret = 0; upsdebugx (3, "entering shut_control_msg"); /* deal for set requests */ if (requesttype == REQUEST_TYPE_SET_REPORT) { set_pass = 1; /* add 8 for the first frame that declares a coming set */ remaining_size+= 8; } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif /* Note: checking against limits of protocol struct fields, * not against USB_CTRL_REQUEST_MAX et al, which are mostly int */ if (requesttype < 0 || (uintmax_t)requesttype > UINT8_MAX || request < 0 || (uintmax_t)request > UINT8_MAX || value < 0 || (uintmax_t)value > UINT16_MAX || index < 0 || (uintmax_t)index > UINT16_MAX || (uintmax_t)size > UINT16_MAX || (uintmax_t)timeout > UINT32_MAX ) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic pop #endif upsdebugx (1, "%s: input values out of range", __func__); return -1; } /* build the control request */ ctrl.bRequestType = (uint8_t)requesttype; ctrl.bRequest = (uint8_t)request; ctrl.wValue = (uint16_t)value; ctrl.wIndex = (uint16_t)index; ctrl.wLength = (uint16_t)size; ctrl.data = bytes; ctrl.timeout = (uint32_t)timeout; /* in milliseconds */ align_request(&ctrl); /* Send all data */ while(remaining_size > 0 && Retry > 0) { if (requesttype == REQUEST_TYPE_SET_REPORT) { if (set_pass == 1) { data_size = 8; set_pass++; /* prepare for the next step */ } else { data_size = size; upsdebug_hex(4, "data", bytes, data_size); } } else { /* Always 8 bytes payload for GET_REPORT with SHUT */ data_size = 8; } /* Forge the SHUT Frame */ shut_pkt[0] = SHUT_TYPE_REQUEST + ( ((requesttype == REQUEST_TYPE_SET_REPORT) && (remaining_size>8))? 0 : SHUT_PKT_LAST); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE # pragma GCC diagnostic ignored "-Wtautological-unsigned-zero-compare" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if (data_size < 0 || data_size > UCHAR_MAX) { #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_UNSIGNED_ZERO_COMPARE) ) # pragma GCC diagnostic pop #endif upsdebugx(1, "%s: ERROR: data_size %" PRI_NUT_USB_CTRL_CHARBUFSIZE " is out of range for SHUT packet", __func__, data_size); return -1; } if (data_size > 0x0F || data_size > sizeof(shut_pkt) - 2) { upsdebugx(1, "%s: WARNING: data_size %" PRI_NUT_USB_CTRL_CHARBUFSIZE " may be too large for SHUT packet?", __func__, data_size); /* Do not abort here - maybe there is intentional maths * in the protocol with overlapping/shifted-away numbers? */ } shut_pkt[1] = (unsigned char)(data_size<<4) + (unsigned char)data_size; if ( (requesttype == REQUEST_TYPE_SET_REPORT) && (remaining_size < 8) ) memcpy(&shut_pkt[2], bytes, data_size > sizeof(shut_pkt) - 2 ? sizeof(shut_pkt) - 2 : data_size); /* we need to send ctrl.data */ else memcpy(&shut_pkt[2], &ctrl, 8); shut_pkt[(data_size+3) - 1] = shut_checksum(&shut_pkt[2], (unsigned char)data_size); /* Packets need only to be sent once * NACK handling should take care of the rest */ if (Retry == 1) { ser_send_buf(arg_upsfd, shut_pkt, data_size+3); upsdebug_hex(3, "shut_control_msg", shut_pkt, data_size+3); /* serial_send (shut_pkt, data_size+3); */ } i = shut_wait_ack (arg_upsfd); switch (i) { case 0: if (requesttype == REQUEST_TYPE_SET_REPORT) remaining_size-=data_size; else remaining_size = 0; Retry=1; break; case -1: if (Retry >= MAX_TRY) { upsdebugx(2, "Max tries reached while waiting for ACK, still getting errors"); /* try to resync, and give one more try */ Retry--; shut_synchronise(arg_upsfd); return i; } else { upsdebugx(4, "Retry = %i", Retry); /* Send a NACK to get a resend from the UPS */ ser_send_char(arg_upsfd, SHUT_NOK); Retry++; } break; case -3: /* FIXME: notification caught => to be processed */ /* Send a NACK for the moment, to get a resend from the UPS */ ser_send_char(arg_upsfd, SHUT_NOK); Retry++; goto fallthrough_default; default: fallthrough_default: break; } } if (remaining_size != 0) return -1; /* now receive data, except for SET_REPORT */ if (requesttype != REQUEST_TYPE_SET_REPORT) ret = shut_packet_recv (arg_upsfd, bytes, size); return ret; } /********************************************************************** * shut_wait_ack() * * wait for an ACK packet * * returns 0 on success, -1 on error, -2 on NACK, -3 on NOTIFICATION * *********************************************************************/ /* Expected evaluated types for the API after typedefs: * int shut_wait_ack(int arg_upsfd) */ int shut_wait_ack(usb_dev_handle arg_upsfd) { int retCode = -1; unsigned char c = '\0'; ser_get_char(arg_upsfd, &c, SHUT_TIMEOUT/1000, 0); if (c == SHUT_OK) { upsdebugx (2, "shut_wait_ack(): ACK received"); retCode = 0; } else if (c == SHUT_NOK) { upsdebugx (2, "shut_wait_ack(): NACK received"); retCode = -2; } else if ((c & 0x0f) == SHUT_TYPE_NOTIFY) { upsdebugx (2, "shut_wait_ack(): NOTIFY received"); retCode = -3; } else if (c == '\0') upsdebugx (2, "shut_wait_ack(): Nothing received"); return retCode; } nut-2.8.4/drivers/tripplite.c0000644000175000017500000004303215044656702013125 00000000000000/* tripplite.c - model specific routines for Tripp Lite SmartUPS models (tested with: "SMART 700" [on back -- "SmartPro UPS" on front], "SMART700SER") tripplite.c was derived from Russell Kroll's bestups.c by Rik Faith. Copyright (C) 1999 Russell Kroll Copyright (C) 2001 Rickard E. (Rik) Faith Copyright (C) 2004,2008 Nicholas J. Kain This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* REFERENCE 1 A few magic numbers were derived from the GPL'd file opensrc_server/upscmd.cpp, formerly (but not longer) available from Tripp Lite at http://www.tripplite.com/linux/. */ /* REFERENCE 2 Other hints on commands were found on these web pages: http://www.kursknet.ru/~boa/ups/stinfo_command.html http://www.kursknet.ru/~boa/ups/rtinfo_command.html These pages confirm the information in the Tripp Lite source code referenced above and add more details. The first page tells how to derive the VA rating from w_value and l_value. It's a confusing explanation because shifts are used to mask out bits. Here is an example starting with the formula on the web page and proceeding to a formula that uses C syntax. I have a SMART 700 (700VA, 450W) w_value = 0x84 [available from upsc as REG1] l_value=- 0x60 [available from upsc as REG2] Unit Type: bit 6 of w_value is 0 so I have a Smart (vs. a Unison) VA Rating: ((([V:W Result]<<2)*8)+([V:L Result]>>3))*5 = (((w_value<<2)*8)+([l_value]>>3)) * 5 = ((w_value & 0x3f)*32 + (l_value >> 3)) * 5 = (4 * 32 + 12) * 5 = 700 */ /* Known UPS Commands: * * :N%02X -- delay the UPS for provided time (hex seconds) * :H%06X -- reboot the UPS. UPS will restart after provided time (hex s) * :A -- begins a self-test * :C -- fetches result of a self-test * :K1 -- turns on power receptacles * :K0 -- turns off power receptacles * :K3 -- turns on bank 1 receptacle(s) * :K2 -- turns off bank 1 receptacle(s) * :K5 -- turns on bank 2 receptacle(s) * :K4 -- turns off bank 2 receptacle(s) * :G -- unconfirmed: shuts down UPS until power returns * :Q1 -- enable "Remote Reboot" * :Q0 -- disable "Remote Reboot" * :W -- returns 'W' data * :L -- returns 'L' data * :V -- returns 'V' data (firmware revision) * :X -- returns 'X' data (firmware checksum) * :D -- returns general status data * :B -- returns battery voltage (hexadecimal decivolts) * :I -- returns minimum input voltage (hexadecimal hertz) * :M -- returns maximum input voltage (hexadecimal hertz) * :P -- returns power rating * :Z -- unknown * :U -- unknown * :O -- unknown * :E -- unknown * :Y -- returns mains frequency (':D' is preferred) * :T -- returns ups temperature (':D' is preferred) * :R -- returns input voltage (':D' is preferred) * :F -- returns load percentage (':D' is preferred) * :S -- enables remote reboot/remote power on */ /* Returned value from ':D' looks like: * * 0123456789abcdef01234 * ABCCDEFFGGGGHHIIIIJJJ * A 0=LB 1=OK * B 0=OVER 1=OK * CC INFO_UTILITY * D 0=normal 1=TRIM 2=BOOST 3="EXTRA BOOST" * E 0=OFF 1=OB 2=OL 3=OB (1 and 3 are the same?) * FF f(INFO_UPSTEMP) * GG ? INFO_BATTPCT (00 when OB, values don't match table we use) * HH ? (always 00) * II INFO_LOADPCT * JJJJ ? (e.g., 5B82 5B82 5982 037B 0082) * KKK INFO_ACFREQ * 10 */ #include "main.h" #include "serial.h" #include "tripplite.h" #include "nut_stdint.h" #include "nut_float.h" #include #define DRIVER_NAME "Tripp-Lite SmartUPS driver" #define DRIVER_VERSION "0.98" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Russell Kroll \n" \ "Rickard E. (Rik) Faith \n" \ "Nicholas J. Kain ", DRV_STABLE, { NULL } }; /* Time in seconds to delay before shutting down. */ static unsigned int offdelay = DEFAULT_OFFDELAY; static unsigned int startdelay = DEFAULT_STARTDELAY; static unsigned int bootdelay = DEFAULT_BOOTDELAY; static long hex2d(char *start, unsigned int len) { char buf[32]; snprintf(buf, sizeof buf, "%.*s", len, start); return strtol(buf, NULL, 16); } /* The UPS that I'm using (SMART700SER) has the bizarre characteristic * of innately echoing back commands. Therefore, we cannot use * ser_get_line and must manually discard our echoed command. * * All UPS commands are challenge-response, so this function makes things * very clean. * * return: # of chars in buf, excluding terminating \0 */ static ssize_t send_cmd(const char *str, char *buf, size_t len) { char c; ssize_t ret = 0; ssize_t i = 0; ser_flush_io(upsfd); ser_send(upsfd, "%s", str); if (!len || !buf || len > SSIZE_MAX) return -1; for (;;) { ret = ser_get_char(upsfd, &c, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 1) return -1; if (c == ENDCHAR) break; } do { ret = ser_get_char(upsfd, &c, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 1) return -1; if (c == IGNCHAR || c == ENDCHAR) continue; buf[i++] = c; } while (c != ENDCHAR && i < (int)len); buf[i] = '\0'; return i; } static void get_letter_cmd(const char *str, char *buf, size_t len) { int tries; ssize_t ret; for (tries = 0; tries < MAXTRIES; ++tries) { ret = send_cmd(str, buf, len); if ((ret > 0) && isalnum((unsigned char)buf[0])) return; } fatalx(EXIT_FAILURE, "\nFailed to find UPS - giving up..."); } static ssize_t do_reboot_now(void) { char buf[256], cmd[16]; snprintf(cmd, sizeof cmd, ":H%06X\r", startdelay); return send_cmd(cmd, buf, sizeof buf); } static void do_reboot(void) { char buf[256], cmd[16]; snprintf(cmd, sizeof cmd, ":N%02X\r", bootdelay); send_cmd(cmd, buf, sizeof buf); do_reboot_now(); } static ssize_t soft_shutdown(void) { char buf[256], cmd[16]; snprintf(cmd, sizeof cmd, ":N%02X\r", offdelay); send_cmd(cmd, buf, sizeof buf); return send_cmd(":G\r", buf, sizeof buf); } static ssize_t hard_shutdown(void) { char buf[256], cmd[16]; snprintf(cmd, sizeof cmd, ":N%02X\r", offdelay); send_cmd(cmd, buf, sizeof buf); return send_cmd(":K0\r", buf, sizeof buf); } static int instcmd(const char *cmdname, const char *extra) { char buf[256]; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); send_cmd(":A\r", buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); send_cmd(":K0\r", buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); send_cmd(":K1\r", buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "outlet.1.load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); send_cmd(":K2\r", buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "outlet.1.load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); send_cmd(":K3\r", buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "outlet.2.load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); send_cmd(":K4\r", buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "outlet.2.load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); send_cmd(":K5\r", buf, sizeof buf); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.reboot")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); do_reboot_now(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.reboot.graceful")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); do_reboot(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); soft_shutdown(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); hard_shutdown(); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } static int setvar(const char *varname, const char *val) { upsdebug_SET_STARTING(varname, val); if (!strcasecmp(varname, "ups.delay.shutdown")) { int ipv = atoi(val); if (ipv >= 0) offdelay = (unsigned int)ipv; dstate_setinfo("ups.delay.shutdown", "%u", offdelay); return STAT_SET_HANDLED; } if (!strcasecmp(varname, "ups.delay.start")) { int ipv = atoi(val); if (ipv >= 0) startdelay = (unsigned int)ipv; dstate_setinfo("ups.delay.start", "%u", startdelay); return STAT_SET_HANDLED; } if (!strcasecmp(varname, "ups.delay.reboot")) { int ipv = atoi(val); if (ipv >= 0) bootdelay = (unsigned int)ipv; dstate_setinfo("ups.delay.reboot", "%u", bootdelay); return STAT_SET_HANDLED; } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } void upsdrv_initinfo(void) { const char *model; char w_value[16], l_value[16], v_value[16], x_value[16]; int gen, plugs; long w, l, va; get_letter_cmd(":W\r", w_value, sizeof w_value); get_letter_cmd(":L\r", l_value, sizeof l_value); get_letter_cmd(":V\r", v_value, sizeof v_value); get_letter_cmd(":X\r", x_value, sizeof x_value); dstate_setinfo("ups.mfr", "%s", "Tripp Lite"); w = hex2d(w_value, 2); l = hex2d(l_value, 2); model = "Smart"; if (w & 0x40) model = "Unison"; va = ((w & 0x3f) * 32 + (l >> 3)) * 5; /* New formula */ if (!(w & 0x80)) va = l / 2; /* Old formula */ gen = 1 + (!(x_value[0] & 0x07) * !(x_value[1] & 0x07)); plugs = x_value[0] - !!(x_value[1] >> 3) * 8; dstate_setinfo("ups.model", "%s %ld", model, va); dstate_setinfo("ups.firmware", "%c%c (Gen %d)", 'A'+v_value[0]-'0', 'A'+v_value[1]-'0', gen); dstate_setinfo("ups.delay.shutdown", "%u", offdelay); dstate_setflags("ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.shutdown", 3); dstate_setinfo("ups.delay.start", "%u", startdelay); dstate_setflags("ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.start", 8); dstate_setinfo("ups.delay.reboot", "%u", bootdelay); dstate_setflags("ups.delay.reboot", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.reboot", 3); dstate_addcmd("test.battery.start"); /* Turns off automatically */ dstate_addcmd("load.off"); dstate_addcmd("load.on"); dstate_addcmd("shutdown.reboot"); dstate_addcmd("shutdown.reboot.graceful"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); if (plugs > 1) { dstate_addcmd("outlet.1.load.off"); dstate_addcmd("outlet.1.load.on"); if (plugs > 2) { dstate_addcmd("outlet.2.load.off"); dstate_addcmd("outlet.2.load.on"); } } upsh.instcmd = instcmd; upsh.setvar = setvar; printf("Detected %s %s on %s\n", dstate_getinfo("ups.mfr"), dstate_getinfo("ups.model"), device_path); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = do_loop_shutdown_commands("shutdown.return", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } void upsdrv_updateinfo(void) { static int numfails; char buf[256]; int bp, temp; ssize_t len; long volt, load, vmax, vmin, stest; int bcond, lstate, tstate, mode; float bv, freq; len = send_cmd(":D\r", buf, sizeof buf); if (len != 21) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("Data command failed: [%" PRIiSIZE "] bytes != 21 bytes.", len); dstate_datastale(); } return; } volt = hex2d(buf + 2, 2); temp = (int)(hex2d(buf + 6, 2)*0.3636 - 21.0); load = hex2d(buf + 12, 2); freq = hex2d(buf + 18, 3) / 10.0; bcond = buf[0]; lstate = buf[1]; tstate = buf[4]; mode = buf[5]; if (volt > INVOLT_MAX || volt < INVOLT_MIN || temp > TEMP_MAX || temp < TEMP_MIN || load > LOAD_MAX || load < LOAD_MIN || freq > FREQ_MAX || freq < FREQ_MIN) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("Data out of bounds: [%0ld,%3d,%3ld,%02.2f]", volt, temp, load, freq); dstate_datastale(); } return; } send_cmd(":B\r", buf, sizeof buf); bv = (float)(hex2d(buf, 2)) / 10.0; if (bv > 50.0 || bv < 0.0) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("Battery voltage out of bounds: [%02.1f]", bv); dstate_datastale(); } return; } send_cmd(":M\r", buf, sizeof buf); vmax = hex2d(buf, 2); if (vmax > INVOLT_MAX || vmax < INVOLT_MIN) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("InVoltMax out of bounds: [%ld]", vmax); dstate_datastale(); } return; } send_cmd(":I\r", buf, sizeof buf); vmin = hex2d(buf, 2); if (vmin > INVOLT_MAX || vmin < INVOLT_MIN) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("InVoltMin out of bounds: [%ld]", vmin); dstate_datastale(); } return; } send_cmd(":C\r", buf, sizeof buf); errno = 0; stest = strtol(buf, 0, 10); if (errno == ERANGE) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("Self test is out of range: [%ld]", stest); dstate_datastale(); } return; } if (errno == EINVAL) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("Self test returned non-numeric data."); dstate_datastale(); } return; } if (stest > 3 || stest < 0) { ++numfails; if (numfails > MAXTRIES) { ser_comm_fail("Self test out of bounds: [%ld]", stest); dstate_datastale(); } return; } /* We've successfully gathered all the data for an update. */ numfails = 0; dstate_setinfo("input.voltage", "%0ld", volt); dstate_setinfo("ups.temperature", "%3d", temp); dstate_setinfo("ups.load", "%3ld", load); dstate_setinfo("input.frequency", "%02.2f", freq); status_init(); /* Battery Voltage Condition */ switch (bcond) { case '0': /* Low Battery */ status_set("LB"); break; case '1': /* Normal */ break; default: /* Unknown */ upslogx(LOG_ERR, "Unknown battery state: %c", bcond); break; } /* Load State */ switch (lstate) { case '0': /* Overload */ status_set("OVER"); break; case '1': /* Normal */ break; default: /* Unknown */ upslogx(LOG_ERR, "Unknown load state: %c", lstate); break; } /* Tap State */ switch (tstate) { case '0': /* Normal */ break; case '1': /* Reducing */ status_set("TRIM"); break; case '2': /* Boost */ case '3': /* Extra Boost */ status_set("BOOST"); break; default: /* Unknown */ upslogx(LOG_ERR, "Unknown tap state: %c", tstate); break; } /* Mode */ switch (mode) { case '0': /* Off */ status_set("OFF"); break; case '1': /* On Battery */ status_set("OB"); break; case '2': /* On Line */ status_set("OL"); break; case '3': /* On Battery */ status_set("OB"); break; default: /* Unknown */ upslogx(LOG_ERR, "Unknown mode state: %c", mode); break; } status_commit(); /* dq ~= sqrt(dV) is a reasonable approximation * Results fit well against the discrete function used in the Tripp Lite * source, but give a continuous result. */ if (bv >= MAX_VOLT) bp = 100; else if (bv <= MIN_VOLT) bp = 10; else bp = (int)(100*sqrt((bv - MIN_VOLT) / (MAX_VOLT - MIN_VOLT))); dstate_setinfo("battery.voltage", "%.1f", bv); dstate_setinfo("battery.charge", "%3d", bp); dstate_setinfo("input.voltage.maximum", "%ld", vmax); dstate_setinfo("input.voltage.minimum", "%ld", vmin); switch (stest) { case 0: dstate_setinfo("ups.test.result", "%s", "OK"); break; case 1: dstate_setinfo("ups.test.result", "%s", "Battery Bad (Replace)"); break; case 2: dstate_setinfo("ups.test.result", "%s", "In Progress"); break; case 3: dstate_setinfo("ups.test.result", "%s", "Bad Inverter"); break; default: dstate_setinfo("ups.test.result", "Unknown (%s)", buf); break; } dstate_dataok(); ser_comm_good(); } void upsdrv_help(void) { } void upsdrv_makevartable(void) { char msg[256]; snprintf(msg, sizeof msg, "Set shutdown delay, in seconds (default=%d).", DEFAULT_OFFDELAY); addvar(VAR_VALUE, "offdelay", msg); snprintf(msg, sizeof msg, "Set start delay, in seconds (default=%d).", DEFAULT_STARTDELAY); addvar(VAR_VALUE, "startdelay", msg); snprintf(msg, sizeof msg, "Set reboot delay, in seconds (default=%d).", DEFAULT_BOOTDELAY); addvar(VAR_VALUE, "rebootdelay", msg); } void upsdrv_initups(void) { char *val; upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); if ((val = getval("offdelay"))) { int ipv = atoi(val); if (ipv >= 0) offdelay = (unsigned int)ipv; } if ((val = getval("startdelay"))) { int ipv = atoi(val); if (ipv >= 0) startdelay = (unsigned int)ipv; } if ((val = getval("rebootdelay"))) { int ipv = atoi(val); if (ipv >= 0) bootdelay = (unsigned int)ipv; } } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/microsol-common.h0000644000175000017500000000441014777753337014246 00000000000000/* microsol-common.h - common framework for Microsol Solis-based UPS hardware Copyright (C) 2004 Silvino B. Magalhaes 2019 Roberto Panerai Velloso 2021 Ygor A. S. Regados This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2021/03/19 - Version 0.70 - Initial release, based on solis driver */ #ifndef INCLUDED_MICROSOL_COMMON_H #define INCLUDED_MICROSOL_COMMON_H typedef unsigned int bool_t; #define PACKET_SIZE 25 /* buffers */ extern unsigned char received_packet[PACKET_SIZE]; /* Identification */ extern const char *model_name; extern unsigned int ups_model; extern bool_t input_220v, output_220v; /* logical */ extern bool_t detected; extern bool_t line_unpowered, overheat, overload; extern bool_t critical_battery, inverter_working; /*extern bool_t recharging;*/ /* microsol-apc.c has its own copy */ /* Input group */ extern double input_voltage, input_current, input_frequency; extern double input_minimum_voltage, input_maximum_voltage, input_nominal_voltage; extern double input_low_limit, input_high_limit; /* Output group */ extern double output_voltage, output_current, output_frequency; /* Battery group */ extern int battery_extension; extern double battery_voltage, battery_charge; extern double temperature; /* Power group */ extern double apparent_power, real_power, ups_load; extern int load_power_factor, nominal_power, ups_power_factor; extern void scan_received_pack_model_specific(void); extern void set_ups_model(void); extern bool_t ups_model_defined(void); #endif /* INCLUDED_MICROSOL_COMMON_H */ nut-2.8.4/drivers/powerpanel.c0000664000175000017500000001140015000733176013252 00000000000000/* * powerpanel.c - Model specific routines for CyberPower text/binary * protocol UPSes * * Copyright (C) * 2007 Doug Reynolds * 2007-2008 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "serial.h" #include "powerp-bin.h" #include "powerp-txt.h" static int mode = 0; static subdriver_t *subdriver[] = { &powpan_binary, &powpan_text, NULL }; #define DRIVER_NAME "CyberPower text/binary protocol UPS driver" #define DRIVER_VERSION "0.30" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Doug Reynolds \n" \ "Arjen de Korte \n" \ "Timothy Pearson ", DRV_EXPERIMENTAL, { NULL } }; /* FIXME: add a sub version for binary and text subdrivers? */ void upsdrv_initinfo(void) { char *s; dstate_setinfo("ups.mfr", "CyberPower"); dstate_setinfo("ups.model", "[unknown]"); dstate_setinfo("ups.serial", "[unknown]"); subdriver[mode]->initinfo(); /* * Allow to override the following parameters */ if ((s = getval("manufacturer")) != NULL) { dstate_setinfo("ups.mfr", "%s", s); } if ((s = getval("model")) != NULL) { dstate_setinfo("ups.model", "%s", s); } if ((s = getval("serial")) != NULL) { dstate_setinfo("ups.serial", "%s", s); } upsh.instcmd = subdriver[mode]->instcmd; upsh.setvar = subdriver[mode]->setvar; } void upsdrv_updateinfo(void) { static int retry = 0; if (subdriver[mode]->updateinfo() < 0) { ser_comm_fail("Status read failed!"); if (retry < 3) { retry++; } else { dstate_datastale(); } return; } retry = 0; ser_comm_good(); dstate_dataok(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int i, ret = -1; /* * Try to shutdown with delay and automatic reboot if the power * returned in the mean time (newer models support this). */ if (subdriver[mode]->instcmd("shutdown.return", NULL) == STAT_INSTCMD_HANDLED) { /* Shutdown successful */ return; } /* * Looks like an older type. Assume we're still on battery if * we can't read status or it is telling us we're on battery. */ for (i = 0; i < MAXTRIES; i++) { ret = subdriver[mode]->updateinfo(); if (ret >= 0) { break; } } if (ret > 0) { /* * When on battery, the 'shutdown.stayoff' command will make * the UPS switch back on when the power returns. */ if (subdriver[mode]->instcmd("shutdown.stayoff", NULL) == STAT_INSTCMD_HANDLED) { upslogx(LOG_INFO, "Waiting for power to return..."); return; } } else if (ret == 0) { /* * Apparently, the power came back already, so we just need to reboot. */ if (subdriver[mode]->instcmd("shutdown.reboot", NULL) == STAT_INSTCMD_HANDLED) { upslogx(LOG_INFO, "Rebooting now..."); return; } } upslogx(LOG_ERR, "Shutdown command failed!"); } void upsdrv_initups(void) { char *version; version = getval("protocol"); upsfd = ser_open(device_path); ser_set_rts(upsfd, 0); /* * Try to autodetect which UPS is connected. */ for (mode = 0; subdriver[mode] != NULL; mode++) { if ((version != NULL) && strcasecmp(version, subdriver[mode]->version)) { continue; } ser_set_dtr(upsfd, 1); usleep(10000); if (subdriver[mode]->initups() > 0) { upslogx(LOG_INFO, "CyberPower UPS with %s protocol on %s detected", subdriver[mode]->version, device_path); return; } ser_set_dtr(upsfd, 0); usleep(10000); } fatalx(EXIT_FAILURE, "CyberPower UPS not found on %s", device_path); } void upsdrv_help(void) { } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "ondelay", "Delay before UPS startup"); addvar(VAR_VALUE, "offdelay", "Delay before UPS shutdown"); addvar(VAR_VALUE, "manufacturer", "manufacturer"); addvar(VAR_VALUE, "model", "modelname"); addvar(VAR_VALUE, "serial", "serialnumber"); addvar(VAR_VALUE, "protocol", "protocol to use [text|binary] (default: autodection)"); } void upsdrv_cleanup(void) { ser_set_dtr(upsfd, 0); ser_close(upsfd, device_path); } nut-2.8.4/drivers/legrand-hid.h0000644000175000017500000000217014777753336013307 00000000000000/* legrand-hid.h - subdriver to monitor Legrand USB/HID devices with NUT * * Copyright (C) * 2003 - 2009 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef LEGRAND_HID_H #define LEGRAND_HID_H #include "usbhid-ups.h" extern subdriver_t legrand_subdriver; #endif /* LEGRAND_HID_H */ nut-2.8.4/drivers/nutdrv_qx_megatec.c0000644000175000017500000001732615044656702014637 00000000000000/* nutdrv_qx_megatec.c - Subdriver for Megatec protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_blazer-common.h" #include "nutdrv_qx_megatec.h" #define MEGATEC_VERSION "Megatec 0.08" /* qx2nut lookup table */ static item_t megatec_qx2nut[] = { /* * > [Q1\r] * < [(226.0 195.0 226.0 014 49.0 27.5 30.0 00001000\r] * 01234567890123456789012345678901234567890123456 * 0 1 2 3 4 */ { "input.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 1, 5, "%.1f", 0, NULL, NULL, NULL }, { "input.voltage.fault", 0, NULL, "Q1\r", "", 47, '(', "", 7, 11, "%.1f", 0, NULL, NULL, NULL }, { "output.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 13, 17, "%.1f", 0, NULL, NULL, NULL }, { "ups.load", 0, NULL, "Q1\r", "", 47, '(', "", 19, 21, "%.0f", 0, NULL, NULL, NULL }, { "input.frequency", 0, NULL, "Q1\r", "", 47, '(', "", 23, 26, "%.1f", 0, NULL, NULL, NULL }, { "battery.voltage", 0, NULL, "Q1\r", "", 47, '(', "", 28, 31, "%.2f", 0, NULL, NULL, qx_multiply_battvolt }, { "ups.temperature", 0, NULL, "Q1\r", "", 47, '(', "", 33, 36, "%.1f", 0, NULL, NULL, NULL }, /* Status bits */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 38, 38, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Utility Fail (Immediate) */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 39, 39, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Battery Low */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 40, 40, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Bypass/Boost or Buck Active */ { "ups.alarm", 0, NULL, "Q1\r", "", 47, '(', "", 41, 41, NULL, 0, NULL, NULL, blazer_process_status_bits }, /* UPS Failed */ { "ups.type", 0, NULL, "Q1\r", "", 47, '(', "", 42, 42, "%s", QX_FLAG_STATIC, NULL, NULL, blazer_process_status_bits }, /* UPS Type */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 43, 43, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Test in Progress */ { "ups.status", 0, NULL, "Q1\r", "", 47, '(', "", 44, 44, NULL, QX_FLAG_QUICK_POLL, NULL, NULL, blazer_process_status_bits }, /* Shutdown Active */ { "ups.beeper.status", 0, NULL, "Q1\r", "", 47, '(', "", 45, 45, "%s", 0, NULL, NULL, blazer_process_status_bits }, /* Beeper status */ /* * > [F\r] * < [#220.0 000 024.0 50.0\r] * 0123456789012345678901 * 0 1 2 */ { "input.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 1, 5, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.current.nominal", 0, NULL, "F\r", "", 22, '#', "", 7, 9, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "battery.voltage.nominal", 0, NULL, "F\r", "", 22, '#', "", 11, 15, "%.1f", QX_FLAG_STATIC, NULL, NULL, NULL }, { "input.frequency.nominal", 0, NULL, "F\r", "", 22, '#', "", 17, 20, "%.0f", QX_FLAG_STATIC, NULL, NULL, NULL }, /* * Common Qx protocols might only return ups.firmware here: * * > [I\r] * < [#------------- ------ VT12046Q \r] * 012345678901234567890123456789012345678 * 0 1 2 3 * * Megatec IC adds serial/runtime support function into the response: * * pc->ups: * > [I\r] * ups->pc: * < [#MegaTecabcedfhi k130v12345 v3.400000\r] * 01234567890123456789012345678901234567 * 0 1 2 3 * where: * device.mfr=MegaTec * ups.serial=abcedfhi * device.model=k130v * battery.runtime=12345 * ups.firmware=v3.400000 * * NOTE: Per example above, this reply is 38 bytes * long (including '\r') not 39 as in other dialects * and the mappings below; which part is wrong - the * example or code? The "answer_len" field should be * about "expected min length of answer" so 38 here * should cover both variants. */ { "device.mfr", 0, NULL, "I\r", "", 38, '#', "", 1, 7, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* Shorter field than in other dialects */ { "ups.serial", 0, NULL, "I\r", "", 38, '#', "", 8, 15, "%s", 0, NULL, NULL, NULL }, /* Megatec IC adds "ups.serial" support function */ { "device.model", 0, NULL, "I\r", "", 38, '#', "", 17, 21, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* Shorter field than in other dialects */ { "battery.runtime", 0, NULL, "I\r", "", 38, '#', "", 22, 26, "%s", 0, NULL, NULL, NULL }, /* Megatec IC adds "ups.runtime" support function */ { "ups.firmware", 0, NULL, "I\r", "", 38, '#', "", 28, 0, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, /* Note: Per example above, this should end at 36 not 37 as in other dialects; we say 0 to go to end of line, wherever that is in fact */ /* Instant commands */ { "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "load.on", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "shutdown.return", 0, NULL, "S%s\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stayoff", 0, NULL, "S%sR0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "shutdown.stop", 0, NULL, "C\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start", 0, NULL, "T%02d\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, blazer_process_command }, { "test.battery.start.deep", 0, NULL, "TL\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.start.quick", 0, NULL, "T\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, { "test.battery.stop", 0, NULL, "CT\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, /* Server-side settable vars */ { "ups.delay.start", ST_FLAG_RW, blazer_r_ondelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_ONDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, { "ups.delay.shutdown", ST_FLAG_RW, blazer_r_offdelay, NULL, "", 0, 0, "", 0, 0, DEFAULT_OFFDELAY, QX_FLAG_ABSENT | QX_FLAG_SETVAR | QX_FLAG_RANGE, NULL, NULL, blazer_process_setvar }, /* End of structure. */ { NULL, 0, NULL, NULL, "", 0, 0, "", 0, 0, NULL, 0, NULL, NULL, NULL } }; /* Testing table */ #ifdef TESTING static testing_t megatec_testing[] = { { "Q1\r", "(215.0 195.0 230.0 014 49.0 22.7 30.0 00000000\r", -1 }, { "F\r", "#230.0 000 024.0 50.0\r", -1 }, { "I\r", "#NOT_A_LIVE_UPS TESTING TESTING \r", -1 }, { "Q\r", "", -1 }, { "S03\r", "", -1 }, { "C\r", "", -1 }, { "S02R0005\r", "", -1 }, { "S.5R0000\r", "", -1 }, { "T04\r", "", -1 }, { "TL\r", "", -1 }, { "T\r", "", -1 }, { "CT\r", "", -1 }, { NULL } }; #endif /* TESTING */ /* Subdriver-specific initups */ static void megatec_initups(void) { blazer_initups(megatec_qx2nut); } /* Subdriver interface */ subdriver_t megatec_subdriver = { MEGATEC_VERSION, blazer_claim, megatec_qx2nut, megatec_initups, NULL, blazer_makevartable, "ACK", NULL, #ifdef TESTING megatec_testing, #endif /* TESTING */ }; nut-2.8.4/drivers/powercom.c0000644000175000017500000012251415044656702012747 00000000000000/* * powercom.c - model specific routines for following units: * -Trust 425/625 * -Powercom * -Advice Partner/King PR750 * See http://www.advice.co.il/product/inter/ups.html for its specifications. * This model is based on PowerCom (www.powercom.com) models. * -Socomec Sicon Egys 420 * -OptiUPS VS 575C * * Copyrights: * (C) 2015 Arnaud Quette * (C) 2013 Florian Bruhin * (C) 2002 Simon Rozman * (C) 1999 Peter Bieringer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * rev 0.7: Alexey Sidorov * - add Powercom's Black Knight Pro model support ( BNT-400/500/600/800/801/1000/1200/1500/2000AP 220-240V ) * * rev 0.8: Alexey Sidorov * - add Powercom's King Pro model support ( KIN-425/525/625/800/1000/1200/1500/1600/2200/3000/5000AP[-RM] 100-120,200-240 V) * * rev 0.9: Alexey Sidorov * - add Powercom's Imperial model support ( IMP-xxxAP, IMD-xxxAP ) * * rev 0.10: Alexey Sidorov * - fix wrong detection KIN-2200AP * - use ser_set_dtr/ser_set_rts * * rev 0.11: Alexey Sidorov * - move variables from .h to .c file (thanks Michael Tokarev for bugreport) * - fix string comparison (thanks Michael Tokarev for bugreport & Charles Lepple for patch) * - added BNT-other, for BNT 100-120V models (I havn't specs for it) * * Tested on: BNT-1200AP * * Known bugs: * - strange battery level on BNT1200AP in online mode( & may be on other models) * - i don't know how connect to IMP|IMD USB * - i havn't specs for BNT 100-120V models. Add BNT-other type for it * * rev 0.13: Keven Ates * - Modified functions to work for BNT-other 100-120V models. * - Modified BNT-other type defaults to work for the BNT 1500A 120VA model. * - Documented the type[] values purpose in a condensed format. * - BNT-other can be used to perform a complete user override of values for all PowerCom models, detected or not. * * Tested on: BNT-1500A * * rev 0.14: Florian Bruhin (The Compiler) * - Added support for OptiUPS VS 575C * This probably also works with others, but I don't have their model numbers. * * rev 0.15: VSE NN * - Fixed UPS type assignment for Powercom Imperial USB series manufactured since 2009. * * Tested on: IMP-625AP * * rev 0.16: Arnaud Quette * - Fixed the processing of input/output voltages for KIN models * (https://github.com/networkupstools/nut/issues/187) * * rev 0.18: Rouben Tchakhmakhtchian * - Added nobt flag to config that skips UPS battery check on startup/init * (https://github.com/networkupstools/nut/issues/546) * */ #include "main.h" #include "serial.h" #include "powercom.h" #include "nut_float.h" #define DRIVER_NAME "PowerCom protocol UPS driver" #define DRIVER_VERSION "0.25" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Simon Rozman \n" \ "Peter Bieringer \n" \ "Alexey Sidorov \n" \ "Florian Bruhin \n" \ "Arnaud Quette \n" \ "Rouben Tchakhmakhtchian ", DRV_STABLE, { NULL } }; #define NUM_OF_SUBTYPES (sizeof (types) / sizeof (*types)) /* general constants */ enum general { MAX_NUM_OF_BYTES_FROM_UPS = 16 }; /* variables used by module */ static unsigned char raw_data[MAX_NUM_OF_BYTES_FROM_UPS]; /* raw data reveived from UPS */ static unsigned int linevoltage = 230U; /* line voltage, can be defined via command line option */ static const char *manufacturer = "PowerCom"; static const char *modelname = "Unknown"; static const char *serialnumber = "Unknown"; static unsigned int type = 0; /* forward declaration of functions used to setup flow control */ static void dtr0rts1 (void); static void no_flow_control (void); /* struct defining types * --------------------- * See powercom.h for detailed information and functions. * * The following type defaults use this definition: * * "TypeID", * ByteCount, * { "FlowControlString", FlowControlFuncPtr }, * { { ValidationIndex, ValidationValue }, * { ValidationIndex, ValidationValue }, * { ValidationIndex, ValidationValue } }, * { { DelayShutdownMinutes, DelayShutdownSeconds }, * UseMinutesChar'y''n' }, * { FrequencyFactor, FrequencyConstant }, * { OfflineLoadFactor, OfflineLoadConstant, * OnlineLoadFactor, OnlineLoadConstant }, * { OfflineBatteryFactor, OfflineLoad%Factor, OfflineBatteryConstant, * OnlineBatteryFactor, OnlineBatteryConstant }, * { 240VoltageFactor, 240VoltageConstant, * 120VoltageFactor, 120VoltageConstant }, */ static struct type types[] = { { "Trust", 11, { "dtr0rts1", dtr0rts1 }, { { 5U, 0U }, { 7U, 0U }, { 8U, 0U } }, { { 0U, 10U }, 'n' }, { 0.00020997, 0.00020928 }, { 6.1343, -0.3808, 4.3110, 0.1811 }, { 5.0000, 0.3268, -825.00, 4.5639, -835.82 }, { 1.9216, -0.0977, 0.9545, 0.0000 }, }, { "Egys", 16, { "no_flow_control", no_flow_control }, { { 5U, 0x80U }, { 7U, 0U }, { 8U, 0U } }, { { 0U, 10U }, 'n' }, { 0.00020997, 0.00020928 }, { 6.1343, -0.3808, 1.3333, 0.6667 }, { 5.0000, 0.3268, -825.00, 2.2105, -355.37 }, { 1.9216, -0.0977, 0.9545, 0.0000 }, }, { "KP625AP", 16, { "dtr0rts1", dtr0rts1 }, { { 5U, 0x80U }, { 7U, 0U }, { 8U, 0U } }, { { 0U, 10U }, 'n' }, { 0.00020997, 0.00020928 }, { 6.1343, -0.3808, 4.3110, 0.1811 }, { 5.0000, 0.3268, -825.00, 4.5639, -835.82 }, { 1.9216, -0.0977, 0.9545, 0.0000 }, }, { "IMP", 16, { "no_flow_control", no_flow_control }, { { 5U, 0xFFU }, { 7U, 0U }, { 8U, 0U } }, { { 1U, 30U }, 'y' }, { 0.00020997, 0.00020928 }, { 6.1343, -0.3808, 4.3110, 0.1811 }, { 5.0000, 0.3268, -825.00, 4.5639, -835.82 }, { 1.9216, -0.0977, 0.9545, 0.0000 }, }, { "KIN", 16, { "no_flow_control", no_flow_control }, { { 11U, 0x4bU }, { 8U, 0U }, { 8U, 0U } }, { { 1U, 30U }, 'y' }, { 0.00020997, 0.0 }, { 6.1343, -0.3808, 1.075, 0.1811 }, { 5.0000, 0.3268, -825.00, 0.46511, 0 }, { 1.9216, -0.0977, 0.82857, 0.0000 }, }, { "BNT", 16, { "no_flow_control", no_flow_control }, { { 11U, 0x42U }, { 8U, 0U }, { 8U, 0U } }, { { 1U, 30U }, 'y' }, { 0.00020803, 0.0 }, { 1.4474, 0.0, 0.8594, 0.0 }, { 5.0000, 0.3268, -825.00, 0.46511, 0 }, { 1.9216, -0.0977, 0.82857, 0.0000 }, }, { "BNT-other", 16, { "no_flow_control", no_flow_control }, { { 8U, 0U }, { 8U, 0U }, { 8U, 0U } }, { { 1U, 30U }, 'y' }, { 0.00027778, 0.0000 }, { 1.0000, 0.0000, 1.0000, 0.0000 }, { 1.0000, 0.0000, 0.0000, 1.0000, 0.0000 }, { 2.0000, 0.0000, 2.0000, 0.0000 }, }, { "OPTI", 16, { "no_flow_control", no_flow_control }, { { 5U, 0xFFU }, { 7U, 0U }, { 8U, 0U } }, { { 1U, 30U }, 'y' }, { 0.0000, 0.0000 }, { 1.0000, 0.0000, 1.0000, 0.0000 }, { 1.0000, 0.0000, 0.0000, 1.0000, 0.0000 }, { 2.0000, 0.0000, 2.0000, 0.0000 }, }, }; /* values for sending to UPS */ enum commands { SEND_DATA = '\x01', BATTERY_TEST = '\x03', WAKEUP_TIME = '\x04', RESTART = '\xb9', SHUTDOWN = '\xba', COUNTER = '\xbc' }; /* location of data in received string */ enum data { UPS_LOAD = 0U, BATTERY_CHARGE = 1U, INPUT_VOLTAGE = 2U, OUTPUT_VOLTAGE = 3U, INPUT_FREQUENCY = 4U, UPSVERSION = 5U, OUTPUT_FREQUENCY = 6U, STATUS_A = 9U, STATUS_B = 10U, MODELNAME = 11U, MODELNUMBER = 12U }; /* status bits */ enum status { SUMMARY = 0U, MAINS_FAILURE = 1U, ONLINE = 1U, FAULT = 1U, LOW_BAT = 2U, BAD_BAT = 2U, TEST = 4U, AVR_ON = 8U, AVR_MODE = 16U, SD_COUNTER = 16U, OVERLOAD = 32U, SHED_COUNTER = 32U, DIS_NOLOAD = 64U, SD_DISPLAY = 128U, OFF = 128U }; static unsigned int voltages[] = {100,110,115,120,0,0,0,200,220,230,240,0,0,0,0,0}; static unsigned int BNTmodels[] = {0,400,500,600,800,801,1000,1200,1500,2000,0,0,0,0,0,0}; static unsigned int KINmodels[] = {0,425,500,525,625,800,1000,1200,1500,1600,2200,2200,2500,3000,5000,0}; static unsigned int IMPmodels[] = {0,425,525,625,825,1025,1200,1500,2000,0,0,0,0,0,0,0}; static unsigned int OPTImodels[] = {0,0,0,575,0,0,0,0,0,0,0,0,0,0,0,0}; /* * local used functions */ static void shutdown_halt(void) { ser_send_char (upsfd, (unsigned char)SHUTDOWN); if (types[type].shutdown_arguments.minutesShouldBeUsed != 'n') ser_send_char (upsfd, types[type].shutdown_arguments.delay[0]); ser_send_char (upsfd, types[type].shutdown_arguments.delay[1]); upslogx(LOG_INFO, "Shutdown (stayoff) initiated."); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); } static void shutdown_ret(void) { ser_send_char (upsfd, (unsigned char)RESTART); ser_send_char (upsfd, (unsigned char)COUNTER); if (types[type].shutdown_arguments.minutesShouldBeUsed != 'n') ser_send_char (upsfd, types[type].shutdown_arguments.delay[0]); ser_send_char (upsfd, types[type].shutdown_arguments.delay[1]); upslogx(LOG_INFO, "Shutdown (return) initiated."); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_SUCCESS); } /* registered instant commands */ static int instcmd (const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); ser_send_char (upsfd, BATTERY_TEST); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.return")) { /* NOTE: In this context, "return" is UPS behavior after the * wall-power gets restored. The routine exits the driver anyway. */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); shutdown_ret(); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); shutdown_halt(); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } /* set DTR and RTS lines on a serial port to supply a passive * serial interface: DTR to 0 (-V), RTS to 1 (+V) */ static void dtr0rts1 (void) { ser_set_dtr(upsfd, 0); ser_set_rts(upsfd, 1); upsdebugx(2, "DTR => 0, RTS => 1"); } /* clear any flow control */ static void no_flow_control (void) { struct termios tio; tcgetattr (upsfd, &tio); tio.c_iflag &= ~ ((tcflag_t)IXON | (tcflag_t)IXOFF); tio.c_cc[VSTART] = _POSIX_VDISABLE; tio.c_cc[VSTOP] = _POSIX_VDISABLE; upsdebugx(2, "Flow control disable"); /* disable any flow control */ tcsetattr(upsfd, TCSANOW, &tio); } /* sane check for returned buffer */ static int validate_raw_data (void) { int i = 0, num_of_tests = sizeof types[0].validation / sizeof types[0].validation[0]; for (i = 0; i < num_of_tests && raw_data[ types[type].validation[i].index_of_byte] == types[type].validation[i].required_value; i++) ; return (i < num_of_tests) ? 1 : 0; } /* get info from ups */ static int ups_getinfo(void) { size_t i; ssize_t c; /* send trigger char to UPS */ if (ser_send_char (upsfd, SEND_DATA) != 1) { upslogx(LOG_NOTICE, "writing error"); dstate_datastale(); return 0; } else { upsdebugx(5, "Num of bytes requested for reading from UPS: %d", types[type].num_of_bytes_from_ups); /* Note: num_of_bytes_from_ups is (unsigned char) so comparable * to ssize_t without more range checks */ c = ser_get_buf_len(upsfd, raw_data, types[type].num_of_bytes_from_ups, 3, 0); if (c != (ssize_t)types[type].num_of_bytes_from_ups) { upslogx(LOG_NOTICE, "data receiving error (%" PRIiSIZE " instead of %d bytes)", c, types[type].num_of_bytes_from_ups); dstate_datastale(); return 0; } else upsdebugx(5, "Num of bytes received from UPS: %" PRIiSIZE, c); } /* optional dump of raw data */ if (nut_debug_level > 4) { /* FIXME: use upsdebug_hex() ? */ printf("Raw data from UPS:\n"); for (i = 0; i < types[type].num_of_bytes_from_ups; i++) { printf("%2zu 0x%02x (%c)\n", i, raw_data[i], raw_data[i]>=0x20 ? raw_data[i] : ' '); } } /* validate raw data for correctness */ if (validate_raw_data() != 0) { upslogx(LOG_NOTICE, "data receiving error (validation check)"); dstate_datastale(); return 0; } return 1; } static float input_voltage(void) { unsigned int model; float tmp=0.0; if ( !strcmp(types[type].name, "BNT") && raw_data[MODELNUMBER]%16 > 7 ) { tmp=2.2*raw_data[INPUT_VOLTAGE]-24; } else if ( !strcmp(types[type].name, "KIN")) { model=KINmodels[raw_data[MODELNUMBER]/16]; /* Process input voltage, according to line voltage and model rating */ if (linevoltage < 200) { if (model <= 625) { tmp = 0.89 * raw_data[INPUT_VOLTAGE] + 6.18; } else if ((model >= 800) && (model < 2000)) { tmp = 1.61 * raw_data[INPUT_VOLTAGE] / 2.0; } else { tmp = 1.625 * raw_data[INPUT_VOLTAGE] / 2.0; } } if (linevoltage >= 200) { if (model <= 625) { tmp = 1.79 * raw_data[INPUT_VOLTAGE] + 3.35; } else if ((model >= 800) && (model < 2000)) { tmp = 1.61 * raw_data[INPUT_VOLTAGE]; } else { tmp = 1.625 * raw_data[INPUT_VOLTAGE]; } } } else if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) { tmp=raw_data[INPUT_VOLTAGE]*2.0; } else { tmp=linevoltage >= 220 ? types[type].voltage[0] * raw_data[INPUT_VOLTAGE] + types[type].voltage[1] : types[type].voltage[2] * raw_data[INPUT_VOLTAGE] + types[type].voltage[3]; } if (tmp<0) tmp=0.0; return tmp; } static float output_voltage(void) { float tmp,rdatax,rdatay,rdataz,boostdata; unsigned int statINV = 0,statAVR = 0,statAVRMode = 0,model,t; static float datax1[]={0,1.0,1.0,1.0,1.0,0.945,0.945,0.945,0.127,0.127,0.945,0.945,0.945,0.256}; static float datay1[]={0,0.85,0.85,0.85,0.88,0.9,0.9,0.9,6.6,6.6,0.87,0.87,0.87,3.29}; static float dataz1[]={0,1.03,0.78,0.78,0.72,0.55,0.55,0.55,0.5,0.5,0.43,0.43,0.43,0.3}; static float datax2[]={0,1.0,1.0,1.0,1.0,1.89,1.89,1.89,0.127,0.127,1.89,1.89,1.89,0.256}; static float datay2[]={0,1.73,1.74,1.74,1.77,0.9,0.9,0.9,13.204,13.204,0.88,0.88,0.88,6.645}; static float dataz2[]={0,1.15,0.9,0.9,0.75,1.1,1.1,1.1,0.8,0.8,0.86,0.86,0.86,0.7}; if ( !strcmp(types[type].name, "BNT") || !strcmp(types[type].name, "KIN")) { statINV=raw_data[STATUS_A] & ONLINE; statAVR=raw_data[STATUS_A] & AVR_ON; statAVRMode=raw_data[STATUS_A] & AVR_MODE; } if ( !strcmp(types[type].name, "BNT") && raw_data[MODELNUMBER]%16 > 7 ) { if (statINV==0) { if (statAVR==0){ tmp=2.2*raw_data[OUTPUT_VOLTAGE]-24; } else { if (statAVRMode > 0) tmp=(2.2*raw_data[OUTPUT_VOLTAGE]-24)*31/27; else tmp=(2.22*raw_data[OUTPUT_VOLTAGE]-24)*27/31; } } else { t=raw_data[OUTPUT_FREQUENCY]/2; tmp=(1.965*raw_data[15])*(1.965*raw_data[15])*(t-raw_data[OUTPUT_VOLTAGE])/t; if (tmp>0) tmp=sqrt(tmp); else tmp=0.0; } } else if ( !strcmp(types[type].name, "KIN")) { model=KINmodels[raw_data[MODELNUMBER]/16]; if (statINV == 0) { if (statAVR == 0) { /* FIXME: miss test "if (iUPS == 1) {" */ if (linevoltage >= 200) { if (model <= 625) tmp = 1.79*raw_data[OUTPUT_VOLTAGE] + 3.35; else if (model<2000) tmp = 1.61*raw_data[OUTPUT_VOLTAGE]; else tmp = 1.625*raw_data[OUTPUT_VOLTAGE]; } else { if (model <= 625) tmp = 0.89 * raw_data[OUTPUT_VOLTAGE] + 6.18; else if (model<2000) tmp = 1.61 * raw_data[OUTPUT_VOLTAGE] / 2.0; else tmp = 1.625 * raw_data[OUTPUT_VOLTAGE] / 2.0; } } else if (statAVR == 1) { /* FIXME: miss test "if ((iUPS == 1) || (iUPS == 13)) {" */ if (linevoltage >= 200) { if (model <= 525) tmp = 2.07 * raw_data[OUTPUT_VOLTAGE]; else if (model == 625) tmp = 2.07 * raw_data[OUTPUT_VOLTAGE]+5; else if (model < 2000) tmp = 1.87 * raw_data[OUTPUT_VOLTAGE]; else tmp = 1.87 * raw_data[OUTPUT_VOLTAGE]; } else { if (model <= 625) tmp = 2.158 * raw_data[OUTPUT_VOLTAGE] / 2.0; else if (model < 2000) tmp = 1.842 * raw_data[OUTPUT_VOLTAGE] / 2.0; else tmp = 1.875 * raw_data[OUTPUT_VOLTAGE] / 2.0; } } else { /* FIXME: miss test "if ((iUPS == 1) || (iUPS == 13)) {" */ if (linevoltage >= 200) { if (model == 625) tmp = 1.571 * raw_data[OUTPUT_VOLTAGE]; else if (model < 2000) tmp = 1.37 * raw_data[OUTPUT_VOLTAGE]; else tmp = 1.4 * raw_data[OUTPUT_VOLTAGE]; } else { if (model <= 625) tmp = 1.635 * raw_data[OUTPUT_VOLTAGE] / 2.0; else if (model < 2000) tmp = 1.392 * raw_data[OUTPUT_VOLTAGE] / 2.0; else tmp = 1.392 * raw_data[OUTPUT_VOLTAGE] / 2.0; } } } else { /* FIXME: miss test "if ((iUPS == 1) && (T != 0))" */ if (linevoltage < 200) { rdatax = datax1[raw_data[MODELNUMBER]/16]; rdatay = datay1[raw_data[MODELNUMBER]/16]; rdataz = dataz1[raw_data[MODELNUMBER]/16]; } else { rdatax = datax2[raw_data[MODELNUMBER]/16]; rdatay = datay2[raw_data[MODELNUMBER]/16]; rdataz = dataz2[raw_data[MODELNUMBER]/16+1]; } boostdata = 1.0 + statAVR * 20.0 / 135.0; t = raw_data[OUTPUT_FREQUENCY]/2; tmp = 0; if (model > 625){ tmp=(raw_data[BATTERY_CHARGE]*rdatax)*(raw_data[BATTERY_CHARGE]*rdatax)* (t-raw_data[OUTPUT_VOLTAGE])/t; if (tmp>0) /* Casts below try to avoid potential multiplication overflow */ tmp=(float)( (double)sqrt(tmp)*rdatay*boostdata - (double)raw_data[UPS_LOAD]*rdataz*boostdata ); } else { tmp=(raw_data[BATTERY_CHARGE]*rdatax-raw_data[UPS_LOAD]*rdataz)* (raw_data[BATTERY_CHARGE]*rdatax-raw_data[UPS_LOAD]*rdataz)* (t-raw_data[OUTPUT_VOLTAGE])/t; if (tmp>0) tmp=sqrt(tmp)*rdatay; } /* FIXME: may miss a last processing with ErrorVal = 5 | 10 */ } } else if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) { tmp=raw_data[OUTPUT_VOLTAGE]*2.0; } else { tmp= linevoltage >= 220 ? types[type].voltage[0] * raw_data[OUTPUT_VOLTAGE] + types[type].voltage[1] : types[type].voltage[2] * raw_data[OUTPUT_VOLTAGE] + types[type].voltage[3]; } if (tmp<0) tmp=0.0; return tmp; } static float input_freq(void) { if ( !strcmp(types[type].name, "BNT") || !strcmp(types[type].name, "KIN")) return 4807.0/raw_data[INPUT_FREQUENCY]; else if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) return raw_data[INPUT_FREQUENCY]; return raw_data[INPUT_FREQUENCY] ? 1.0 / (types[type].freq[0] * raw_data[INPUT_FREQUENCY] + types[type].freq[1]) : 0; } static float output_freq(void) { if ( !strcmp(types[type].name, "BNT") || !strcmp(types[type].name, "KIN")) return 4807.0/raw_data[OUTPUT_FREQUENCY]; else if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) return raw_data[OUTPUT_FREQUENCY]; return raw_data[OUTPUT_FREQUENCY] ? 1.0 / (types[type].freq[0] * raw_data[OUTPUT_FREQUENCY] + types[type].freq[1]) : 0; } static float load_level(void) { unsigned int statINV,model,voltage; int load425[]={99,88,84,80,84,84,84,86,86,81,76}; int load525[]={127,113,106,100,106,106,106,109,109,103,97}; int load625[]={131,115,107,103,107,107,107,110,110,105,99}; int load2k[] ={94,94,94,94,94,94,94,120,120,115,110}; int load425i[]={60,54,51,48,51,51,51,53,53,50,48}; int load525i[]={81,72,67,62,67,67,67,65,65,62,59}; int load625i[]={79,70,67,64,67,67,67,65,65,61,58}; int load2ki[] ={84,77,74,70,74,74,74,77,77,74,70}; int load400[]={1,1,1,1,1,1,1,1,88,83,87}; int load500[]={1,1,1,1,1,1,1,1,108,103,98}; int load600[]={1,1,1,1,1,1,1,1,128,123,118}; int load400i[]={1,1,1,1,1,1,1,1,54,52,49}; int load500i[]={1,1,1,1,1,1,1,1,66,64,61}; int load600i[]={1,1,1,1,1,1,1,1,86,84,81}; int load801i[]={1,1,1,1,1,1,1,1,44,42,40}; int load1000i[]={1,1,1,1,1,1,1,1,56,54,52}; int load1200i[]={1,1,1,1,1,1,1,1,76,74,72}; if ( !strcmp(types[type].name, "BNT") && raw_data[MODELNUMBER]%16 > 7 ) { statINV=raw_data[STATUS_A] & ONLINE; voltage=raw_data[MODELNUMBER]%16; model=BNTmodels[raw_data[MODELNUMBER]/16]; if (statINV==0){ if (model==400 || model==801) return raw_data[UPS_LOAD]*110.0/load400[voltage]; else if (model==600 || model==1200) return raw_data[UPS_LOAD]*110.0/load600[voltage]; else return raw_data[UPS_LOAD]*110.0/load500[voltage]; } else { switch (model) { case 400: return raw_data[UPS_LOAD]*110.0/load400i[voltage]; case 500: case 800: return raw_data[UPS_LOAD]*110.0/load500i[voltage]; case 600: return raw_data[UPS_LOAD]*110.0/load600i[voltage]; case 801: return raw_data[UPS_LOAD]*110.0/load801i[voltage]; case 1200: return raw_data[UPS_LOAD]*110.0/load1200i[voltage]; case 1000: case 1500: case 2000: return raw_data[UPS_LOAD]*110.0/load1000i[voltage]; default: break; } } } else if (!strcmp(types[type].name, "KIN")) { statINV=raw_data[STATUS_A] & ONLINE; voltage=raw_data[MODELNUMBER]%16; model=KINmodels[raw_data[MODELNUMBER]/16]; if (statINV==0){ if (model==425) return raw_data[UPS_LOAD]*110.0/load425[voltage]; if (model==525) return raw_data[UPS_LOAD]*110.0/load525[voltage]; if (model==625) return raw_data[UPS_LOAD]*110.0/load625[voltage]; if (model<2000) return raw_data[UPS_LOAD]*1.13; return raw_data[UPS_LOAD]*110.0/load2k[voltage]; } else { if (model==425) return raw_data[UPS_LOAD]*110.0/load425i[voltage]; if (model==525) return raw_data[UPS_LOAD]*110.0/load525i[voltage]; if (model==625) return raw_data[UPS_LOAD]*110.0/load625i[voltage]; if (model<2000) return raw_data[UPS_LOAD]*1.66; return raw_data[UPS_LOAD]*110.0/load2ki[voltage]; } } else if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) { return raw_data[UPS_LOAD]; } return (raw_data[STATUS_A] & MAINS_FAILURE) ? types[type].loadpct[0] * raw_data[UPS_LOAD] + types[type].loadpct[1] : types[type].loadpct[2] * raw_data[UPS_LOAD] + types[type].loadpct[3]; } static float batt_level(void) { int bat0,bat29,bat100; unsigned int model; float battval; if ( !strcmp(types[type].name, "BNT") ) { bat0=157; bat29=165; bat100=193; battval=(raw_data[UPS_LOAD])/4+raw_data[BATTERY_CHARGE]; if (battval<=bat0) return 0.0; if (battval<=bat29) return (battval-bat0)*30.0/(bat29-bat0); if (battval<=bat100) return 30.0+(battval-bat29)*70.0/(bat100-bat29); return 100.0; } if ( !strcmp(types[type].name, "KIN")) { model=KINmodels[raw_data[MODELNUMBER]/16]; if (model>=800 && model<=2000){ battval=(raw_data[BATTERY_CHARGE]-165.0)*2.6; if (raw_data[STATUS_A] & ONLINE) return battval+raw_data[UPS_LOAD]; if (battval>7) return battval-6; return battval; } else if (model<=625){ battval=raw_data[UPS_LOAD]/4.0+raw_data[BATTERY_CHARGE]; bat0=169; bat29=176; bat100=204; } else { battval=raw_data[UPS_LOAD]/4.0-raw_data[UPS_LOAD]/32.0+raw_data[BATTERY_CHARGE]; bat0=175; bat29=182; bat100=209; } if (battval<=bat0) return 0; if (battval>bat0 && battval<=bat29) return (battval-bat0)*30.0/(bat29-bat0); if (battval>bat29 && battval<=bat100) return 30.0+(battval-bat29)*70.0/(bat100-bat29); return 100; } if ( !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) return raw_data[BATTERY_CHARGE]; return (raw_data[STATUS_A] & ONLINE) ? /* Are we on battery power? */ /* Yes */ types[type].battpct[0] * raw_data[BATTERY_CHARGE] + types[type].battpct[1] * load_level() + types[type].battpct[2] : /* No */ types[type].battpct[3] * raw_data[BATTERY_CHARGE] + types[type].battpct[4]; } /* * global used functions */ /* update information */ void upsdrv_updateinfo(void) { char val[32]; if (!ups_getinfo()) { /* https://github.com/networkupstools/nut/issues/356 */ upsdebugx(1, "%s: failed to ups_getinfo() once, retrying for slower devices", __func__); if (!ups_getinfo()) { return; } } /* input.frequency */ upsdebugx(3, "input.frequency (raw data): [raw: %u]", raw_data[INPUT_FREQUENCY]); dstate_setinfo("input.frequency", "%02.2f", input_freq()); upsdebugx(2, "input.frequency: %s", dstate_getinfo("input.frequency")); /* output.frequency */ upsdebugx(3, "output.frequency (raw data): [raw: %u]", raw_data[OUTPUT_FREQUENCY]); dstate_setinfo("output.frequency", "%02.2f", output_freq()); upsdebugx(2, "output.frequency: %s", dstate_getinfo("output.frequency")); /* ups.load */ upsdebugx(3, "ups.load (raw data): [raw: %u]", raw_data[UPS_LOAD]); dstate_setinfo("ups.load", "%03.1f", load_level()); upsdebugx(2, "ups.load: %s", dstate_getinfo("ups.load")); /* battery.charge */ upsdebugx(3, "battery.charge (raw data): [raw: %u]", raw_data[BATTERY_CHARGE]); dstate_setinfo("battery.charge", "%03.1f", batt_level()); upsdebugx(2, "battery.charge: %s", dstate_getinfo("battery.charge")); /* input.voltage */ upsdebugx(3, "input.voltage (raw data): [raw: %u]", raw_data[INPUT_VOLTAGE]); dstate_setinfo("input.voltage", "%03.1f",input_voltage()); upsdebugx(2, "input.voltage: %s", dstate_getinfo("input.voltage")); /* output.voltage */ upsdebugx(3, "output.voltage (raw data): [raw: %u]", raw_data[OUTPUT_VOLTAGE]); dstate_setinfo("output.voltage", "%03.1f",output_voltage()); upsdebugx(2, "output.voltage: %s", dstate_getinfo("output.voltage")); status_init(); *val = 0; if (!(raw_data[STATUS_A] & MAINS_FAILURE)) { !(raw_data[STATUS_A] & OFF) ? status_set("OL") : status_set("OFF"); } else { status_set("OB"); } if (raw_data[STATUS_A] & LOW_BAT) status_set("LB"); if (raw_data[STATUS_A] & AVR_ON) { input_voltage() < linevoltage ? status_set("BOOST") : status_set("TRIM"); } if (raw_data[STATUS_A] & OVERLOAD) status_set("OVER"); if (raw_data[STATUS_B] & BAD_BAT) status_set("RB"); if (raw_data[STATUS_B] & TEST) status_set("TEST"); status_commit(); upsdebugx(2, "STATUS: %s", dstate_getinfo("ups.status")); dstate_dataok(); } /* shutdown UPS */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = -1; if (!device_sdcommands) { /* default: power down the attached load immediately */ printf("Forced UPS shutdown (and wait for power)...\n"); } ret = do_loop_shutdown_commands("shutdown.return", NULL); if (handling_upsdrv_shutdown > 0) set_exit_flag(ret == STAT_INSTCMD_HANDLED ? EF_EXIT_SUCCESS : EF_EXIT_FAILURE); } /* initialize UPS */ void upsdrv_initups(void) { int tmp; unsigned int model = 0; unsigned int i; static char buf[20]; /* check manufacturer name from arguments */ if (testvar("manufacturer")) manufacturer = getval("manufacturer"); /* check model name from arguments */ if (testvar("modelname")) modelname = getval("modelname"); /* check serial number from arguments */ if (testvar("serialnumber")) serialnumber = getval("serialnumber"); /* get and check type */ if (testvar("type")) { for (i = 0; i < NUM_OF_SUBTYPES && strcmp(types[i].name, getval("type")); i++) ; if (i >= NUM_OF_SUBTYPES) { printf("Given UPS type '%s' isn't valid!\n", getval("type")); exit (1); } type = i; } /* check line voltage from arguments */ if (testvar("linevoltage")) { tmp = atoi(getval("linevoltage")); if (! ( (tmp >= 200 && tmp <= 240) || (tmp >= 100 && tmp <= 120) ) ) { printf("Given line voltage '%d' is out of range (100-120 or 200-240 V)\n", tmp); exit (1); } linevoltage = (unsigned int) tmp; } if (testvar("numOfBytesFromUPS")) { tmp = atoi(getval("numOfBytesFromUPS")); if (! (tmp > 0 && tmp <= MAX_NUM_OF_BYTES_FROM_UPS) ) { printf("Given numOfBytesFromUPS '%d' is out of range (1 to %d)\n", tmp, MAX_NUM_OF_BYTES_FROM_UPS); exit (1); } types[type].num_of_bytes_from_ups = (unsigned char) tmp; } if (testvar("methodOfFlowControl")) { for (i = 0; i < NUM_OF_SUBTYPES && strcmp(types[i].flowControl.name, getval("methodOfFlowControl")); i++) ; if (i >= NUM_OF_SUBTYPES) { printf("Given methodOfFlowControl '%s' isn't valid!\n", getval("methodOfFlowControl")); exit (1); } types[type].flowControl = types[i].flowControl; } if (testvar("validationSequence") && sscanf(getval("validationSequence"), "{{%u,%x},{%u,%x},{%u,%x}}", &types[type].validation[0].index_of_byte, &types[type].validation[0].required_value, &types[type].validation[1].index_of_byte, &types[type].validation[1].required_value, &types[type].validation[2].index_of_byte, &types[type].validation[2].required_value ) < 6 ) { printf("Given validationSequence '%s' isn't valid!\n", getval("validationSequence")); exit (1); } /* NOTE: %hhu is not supported before C99; that would need reading * arguments into an uint as %u, checking range and casting */ if (testvar("shutdownArguments") && sscanf(getval("shutdownArguments"), "{{%hhu,%hhu},%c}", &types[type].shutdown_arguments.delay[0], &types[type].shutdown_arguments.delay[1], &types[type].shutdown_arguments.minutesShouldBeUsed ) < 3 ) { printf("Given shutdownArguments '%s' isn't valid!\n", getval("shutdownArguments")); exit (1); } if (testvar("frequency") && sscanf(getval("frequency"), "{%f,%f}", &types[type].freq[0], &types[type].freq[1] ) < 2 ) { printf("Given frequency '%s' isn't valid!\n", getval("frequency")); exit (1); } if (testvar("loadPercentage") && sscanf(getval("loadPercentage"), "{%f,%f,%f,%f}", &types[type].loadpct[0], &types[type].loadpct[1], &types[type].loadpct[2], &types[type].loadpct[3] ) < 4 ) { printf("Given loadPercentage '%s' isn't valid!\n", getval("loadPercentage")); exit (1); } if (testvar("batteryPercentage") && sscanf(getval("batteryPercentage"), "{%f,%f,%f,%f,%f}", &types[type].battpct[0], &types[type].battpct[1], &types[type].battpct[2], &types[type].battpct[3], &types[type].battpct[4] ) < 5 ) { printf("Given batteryPercentage '%s' isn't valid!\n", getval("batteryPercentage")); exit (1); } if (testvar("voltage") && sscanf(getval("voltage"), "{%f,%f,%f,%f}", &types[type].voltage[0], &types[type].voltage[1], &types[type].voltage[2], &types[type].voltage[3] ) < 4 ) { printf("Given voltage '%s' isn't valid!\n", getval("voltage")); exit (1); } /* open serial port */ upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B1200); /* setup flow control */ types[type].flowControl.setup_flow_control(); /* Setup Model and LineVoltage */ if (!strncmp(types[type].name, "BNT",3) || !strcmp(types[type].name, "KIN") || !strcmp(types[type].name, "IMP") || !strcmp(types[type].name, "OPTI")) { if (!ups_getinfo()) return; /* Give "BNT-other" a chance! */ if (raw_data[MODELNAME]==0x42 || raw_data[MODELNAME]==0x4B || raw_data[MODELNAME]==0x4F){ /* Give "IMP" a chance also! */ if (raw_data[UPSVERSION]==0xFF){ types[type].name="IMP"; model=IMPmodels[raw_data[MODELNUMBER]/16]; } else { model=BNTmodels[raw_data[MODELNUMBER]/16]; if (!strcmp(types[type].name, "BNT-other")) types[type].name="BNT-other"; else if (raw_data[MODELNAME]==0x42) types[type].name="BNT"; else if (raw_data[MODELNAME]==0x4B){ types[type].name="KIN"; model=KINmodels[raw_data[MODELNUMBER]/16]; } else if (raw_data[MODELNAME]==0x4F){ types[type].name="OPTI"; model=OPTImodels[raw_data[MODELNUMBER]/16]; } } } else if (raw_data[UPSVERSION]==0xFF){ types[type].name="IMP"; model=IMPmodels[raw_data[MODELNUMBER]/16]; } linevoltage=voltages[raw_data[MODELNUMBER]%16]; if (!strcmp(types[type].name, "OPTI")) { snprintf(buf,sizeof(buf),"%s-%u",types[type].name, model); } else { snprintf(buf,sizeof(buf),"%s-%uAP",types[type].name, model); } if (!strcmp(modelname, "Unknown")) modelname=buf; upsdebugx(1, "Detected: %s , %uV", buf, linevoltage); if (testvar("nobt") || dstate_getinfo("driver.flag.nobt")) { upslogx(LOG_NOTICE, "nobt flag set, skipping battery test as requested"); } else { upslogx(LOG_NOTICE, "nobt flag not set, performing battery test as requested"); if (ser_send_char (upsfd, BATTERY_TEST) != 1) { upslogx(LOG_NOTICE, "Write error: failed to send battery test command to UPS!"); dstate_datastale(); return; } } } upsdebugx(1, "Values of arguments:"); upsdebugx(1, " manufacturer : '%s'", manufacturer); upsdebugx(1, " model name : '%s'", modelname); upsdebugx(1, " serial number : '%s'", serialnumber); upsdebugx(1, " line voltage : '%u'", linevoltage); upsdebugx(1, " type : '%s'", types[type].name); upsdebugx(1, " number of bytes from UPS: '%u'", types[type].num_of_bytes_from_ups); upsdebugx(1, " method of flow control : '%s'", types[type].flowControl.name); upsdebugx(1, " validation sequence: '{{%u,%#x},{%u,%#x},{%u,%#x}}'", types[type].validation[0].index_of_byte, types[type].validation[0].required_value, types[type].validation[1].index_of_byte, types[type].validation[1].required_value, types[type].validation[2].index_of_byte, types[type].validation[2].required_value); upsdebugx(1, " shutdown arguments: '{{%u,%u},%c}'", types[type].shutdown_arguments.delay[0], types[type].shutdown_arguments.delay[1], types[type].shutdown_arguments.minutesShouldBeUsed); if ( strcmp(types[type].name, "KIN") && strcmp(types[type].name, "BNT") && strcmp(types[type].name, "IMP")) { upsdebugx(1, " frequency calculation coefficients: '{%f,%f}'", types[type].freq[0], types[type].freq[1]); upsdebugx(1, " load percentage calculation coefficients: " "'{%f,%f,%f,%f}'", types[type].loadpct[0], types[type].loadpct[1], types[type].loadpct[2], types[type].loadpct[3]); upsdebugx(1, " battery percentage calculation coefficients: " "'{%f,%f,%f,%f,%f}'", types[type].battpct[0], types[type].battpct[1], types[type].battpct[2], types[type].battpct[3], types[type].battpct[4]); upsdebugx(1, " voltage calculation coefficients: '{%f,%f}'", types[type].voltage[2], types[type].voltage[3]); } } /* display help */ void upsdrv_help(void) { /* 1 2 3 4 5 6 7 8 */ /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 MAX */ printf("\n"); printf("Specify UPS information in the ups.conf file.\n"); printf(" type: Type of UPS: 'Trust','Egys','KP625AP','IMP','KIN','BNT',\n"); printf(" 'BNT-other', 'OPTI' (default: 'Trust')\n"); printf(" 'BNT-other' is a special type intended for BNT 100-120V models,\n"); printf(" but can be used to override ALL models.\n"); printf("You can additional specify these variables:\n"); printf(" manufacturer: Manufacturer name (default: 'PowerCom')\n"); printf(" modelname: Model name (default: 'Unknown' or autodetected)\n"); printf(" serialnumber: Serial number (default: Unknown)\n"); printf(" shutdownArguments: 3 delay arguments for the shutdown operation:\n"); printf(" {{Minutes,Seconds},UseMinutes?}\n"); printf(" where Minutes and Seconds are integer, UseMinutes? is either\n"); printf(" 'y' or 'n'.\n"); printf("You can specify these variables if not automagically detected for types\n"); printf(" 'IMP','KIN','BNT'\n"); printf(" linevoltage: Line voltage: 110-120 or 220-240 (default: 230)\n"); printf(" numOfBytesFromUPS: Number of bytes in a UPS frame: 16 is common, 11 for 'Trust'\n"); printf(" methodOfFlowControl: Flow control method for UPS:\n"); printf(" 'dtr0rts1', 'dtr1' or 'no_flow_control'\n"); printf(" validationSequence: 3 pairs of validation values: {{I,V},{I,V},{I,V}}\n"); printf(" where I is the index into BytesFromUPS (see numOfBytesFromUPS)\n"); printf(" and V is the value for the ByteIndex to match.\n"); printf(" frequency: Input & Output Frequency conversion values: {A, B}\n"); printf(" used in function: 1/(A*x+B)\n"); printf(" If the raw value x IS the frequency, then A=1/(x^2), B=0\n"); printf(" loadPercentage: Load conversion values for Battery and Line load: {BA,BB,LA,LB}\n"); printf(" used in function: A*x+B\n"); printf(" If the raw value x IS the Load Percent, then A=1, B=0\n"); printf(" batteryPercentage: Battery conversion values for Battery and Line power:\n"); printf(" {A,B,C,D,E}\n"); printf(" used in functions: (Battery) A*x+B*y+C, (Line) D*x+E\n"); printf(" If the raw value x IS the Battery Percent, then\n"); printf(" A=1, B=0, C=0, D=1, E=0\n"); printf(" voltage: Voltage conversion values for 240 and 120 voltage:\n"); printf(" {240A,240B,120A,120B}\n"); printf(" used in function: A*x+B\n"); printf(" If the raw value x IS HALF the Voltage, then A=2, B=0\n"); printf(" nobt: Flag to skip battery check on init/startup.\n\n"); printf("Example for BNT1500AP in ups.conf:\n"); printf("[BNT1500AP]\n"); printf(" driver = powercom\n"); printf(" port = /dev/ttyS0\n"); printf(" desc = \"PowerCom BNT 1500 AP\"\n"); printf(" manufacturer = PowerCom\n"); printf(" modelname = BNT1500AP\n"); printf(" serialnumber = 13245678900\n"); printf(" type = BNT-other\n"); printf("# linevoltage = 120\n"); printf("# numOfBytesFromUPS = 16\n"); printf("# methodOfFlowControl = no_flow_control\n"); printf("# validationSequence = {{8,0},{8,0},{8,0}}\n"); printf("# shutdownArguments = {{1,30},y}\n"); printf("# frequency = {0.00027778,0.0000}\n"); printf("# loadPercentage = {1.0000,0.0,1.0000,0.0}\n"); printf("# batteryPercentage = {1.0000,0.0000,0.0000,1.0000,0.0000}\n"); printf("# voltage = {2.0000,0.0000,2.0000,0.0000}\n"); printf(" nobt\n"); return; } /* initialize information */ void upsdrv_initinfo(void) { /* write constant data for this model */ dstate_setinfo ("ups.mfr", "%s", manufacturer); dstate_setinfo ("ups.model", "%s", modelname); dstate_setinfo ("ups.serial", "%s", serialnumber); dstate_setinfo ("ups.model.type", "%s", types[type].name); dstate_setinfo ("input.voltage.nominal", "%u", linevoltage); /* now add the instant commands */ dstate_addcmd ("test.battery.start"); dstate_addcmd ("shutdown.return"); dstate_addcmd ("shutdown.stayoff"); upsh.instcmd = instcmd; } /* define possible arguments */ void upsdrv_makevartable(void) { /* 1 2 3 4 5 6 7 8 */ /*2345678901234567890123456789012345678901234567890123456789012345678901234567890 MAX */ addvar(VAR_VALUE, "type", "Type of UPS: 'Trust','Egys','KP625AP','IMP','KIN','BNT','BNT-other','OPTI'\n" " (default: 'Trust')"); addvar(VAR_VALUE, "manufacturer", "Manufacturer name (default: 'PowerCom')"); addvar(VAR_VALUE, "modelname", "Model name [cannot be detected] (default: Unknown)"); addvar(VAR_VALUE, "serialnumber", "Serial number [cannot be detected] (default: Unknown)"); addvar(VAR_VALUE, "shutdownArguments", "Delay values for shutdown: Minutes, Seconds, UseMinutes?'y'or'n'"); addvar(VAR_VALUE, "linevoltage", "Line voltage 110-120 or 220-240 V (default: 230)"); addvar(VAR_VALUE, "numOfBytesFromUPS", "The number of bytes in a UPS frame"); addvar(VAR_VALUE, "methodOfFlowControl", "Flow control method for UPS: 'dtr0rts1' or 'no_flow_control'"); addvar(VAR_VALUE, "validationSequence", "Validation values: ByteIndex, ByteValue x 3"); if ( strcmp(types[type].name, "KIN") && strcmp(types[type].name, "BNT") && strcmp(types[type].name, "IMP")) { addvar(VAR_VALUE, "frequency", "Frequency conversion values: FreqFactor, FreqConst"); addvar(VAR_VALUE, "loadPercentage", "Load conversion values: OffFactor, OffConst, OnFactor, OnConst"); addvar(VAR_VALUE, "batteryPercentage", "Battery conversion values: OffFactor, LoadFactor, OffConst, OnFactor, OnConst"); addvar(VAR_VALUE, "voltage", "Voltage conversion values: 240VFactor, 240VConst, 120VFactor, 120VConst"); addvar(VAR_FLAG, "nobt", "Disable battery test at driver init/startup"); } } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/riello.h0000644000175000017500000001241714777753337012425 00000000000000/* * riello.h: defines/macros for Riello protocol based UPSes * * Documents describing the protocol implemented by this driver can be * found online at: * * https://www.networkupstools.org/protocols/riello/PSGPSER-0104.pdf * https://www.networkupstools.org/protocols/riello/PSSENTR-0100.pdf * * Copyright (C) 2012 - Elio Parisi * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Reference of the derivative work: blazer driver */ #ifndef NUT_RIELLO_H_SEEN #define NUT_RIELLO_H_SEEN 1 #include "nut_stdint.h" #define CTRL_RETRIES 50 #define CTRL_TIMEOUT 100 #define MAX_READ_WRITE (16 * 1024) #define USB_WRITE_DELAY 200 #define MAXTRIES 3 #define COUNTLOST 10 #define DEV_RIELLOSENTRY 14 #define DEV_RIELLOGPSER 21 #define LENGTH_GI 68 #define LENGTH_GN 34 #define LENGTH_RS_MM 42 #define LENGTH_RS_TM 48 #define LENGTH_RS_TT 64 #define LENGTH_RE 70 #define LENGTH_RC 56 #define LENGTH_DEF 12 #define SENTR_EXT176 176 #define SENTR_ALSO240 240 #define SENTR_ONLY192 192 #define BUFFER_SIZE 220 typedef struct { uint16_t SWversion; uint16_t Model; uint16_t Uinp1; uint16_t Uinp2; uint16_t Uinp3; uint16_t Iinp1; uint16_t Iinp2; uint16_t Iinp3; uint16_t Finp; uint16_t Uout1; uint16_t Uout2; uint16_t Uout3; uint16_t Iout1; uint16_t Iout2; uint16_t Iout3; uint16_t Pout1; uint16_t Pout2; uint16_t Pout3; uint16_t Ipout1; uint16_t Ipout2; uint16_t Ipout3; uint16_t Fout; uint16_t BatTime; uint16_t BatCap; uint16_t Ubat; uint16_t Ibat; uint16_t Tsystem; uint16_t NomBatCap; uint16_t Ubypass1; uint16_t Ubypass2; uint16_t Ubypass3; uint16_t Fbypass; uint16_t LockUPS; uint8_t AlarmCode[4]; char AlarmCodeT[12]; uint8_t StatusCode[12]; char StatusCodeT[42]; char Identification[18]; char ModelStr[18]; char Version[14]; uint16_t NomPowerKVA; uint16_t NomPowerKW; uint16_t NomUbat; uint16_t NumBat; uint16_t UbatPerc; uint16_t NominalUout; uint16_t Boost; uint16_t Buck; uint8_t Identif_bytes[12]; uint16_t NomFout; uint32_t Pout1VA; uint32_t Pout2VA; uint32_t Pout3VA; uint32_t Pout1W; uint32_t Pout2W; uint32_t Pout3W; } TRielloData; /* CRC and Checksum functions */ uint16_t riello_calc_CRC(uint8_t type, uint8_t *buff, uint16_t size, uint8_t checksum); void riello_create_crc(uint8_t type, uint8_t *buff, uint16_t size, uint8_t checksum); uint8_t riello_test_crc(uint8_t type, uint8_t *buff, uint16_t size, uint8_t chacksum); uint8_t riello_test_bit(uint8_t *basic_address, uint8_t bit); /* send GPSER command functions */ uint8_t riello_prepare_gi(uint8_t* buffer); uint8_t riello_prepare_gn(uint8_t* buffer, uint8_t gpser_error_control); uint8_t riello_prepare_rs(uint8_t* buffer, uint8_t gpser_error_control); uint8_t riello_prepare_re(uint8_t* buffer, uint8_t gpser_error_control); uint8_t riello_prepare_rc(uint8_t* buffer, uint8_t gpser_error_control); uint8_t riello_prepare_cs(uint8_t* buffer, uint8_t gpser_error_control, uint16_t delay); uint8_t riello_prepare_cr(uint8_t* buffer, uint8_t gpser_error_control, uint16_t delay); uint8_t riello_prepare_cd(uint8_t* buffer, uint8_t gpser_error_control); uint8_t riello_prepare_tp(uint8_t* buffer, uint8_t gpser_error_control); uint8_t riello_prepare_tb(uint8_t* buffer, uint8_t gpser_error_control); /* send SENTR command functions */ uint8_t riello_prepare_shutsentr(uint8_t* buffer, uint16_t delay); uint8_t riello_prepare_cancelsentr(uint8_t* buffer); uint8_t riello_prepare_setrebsentr(uint8_t* buffer, uint16_t delay); uint8_t riello_prepare_rebsentr(uint8_t* buffer, uint16_t delay); uint8_t riello_prepare_tbsentr(uint8_t* buffer); /* parse GPSER ups responses */ void riello_parse_gi(uint8_t* buffer, TRielloData* data); void riello_parse_gn(uint8_t* buffer, TRielloData* data); void riello_parse_rs(uint8_t* buffer, TRielloData* data, uint8_t numread); void riello_parse_re(uint8_t* buffer, TRielloData* data); void riello_parse_rc(uint8_t* buffer, TRielloData* data); /* parse SENTR ups responses */ void riello_parse_sentr(uint8_t* buffer, TRielloData* data); /* communication functions */ void riello_init_serial(void); uint8_t riello_header(uint8_t type, uint8_t a, uint8_t* length); uint8_t riello_tail(uint8_t type, uint8_t length); uint8_t riello_test_nak(uint8_t type, uint8_t* buffer); void riello_parse_serialport(uint8_t typedev, uint8_t* buffer, uint8_t checksum); void riello_comm_setup(const char *port); int get_ups_statuscode(void); /* Shared global variables for driver subtypes */ /* extern uint8_t foundheader; */ extern uint16_t buf_ptr_length; extern uint8_t wait_packet; extern uint8_t foundnak; extern uint8_t foundbadcrc; extern uint8_t commbyte; extern uint8_t requestSENTR; #endif /* NUT_RIELLO_H_SEEN */ nut-2.8.4/drivers/explore-hid.c0000644000175000017500000000416414777753336013351 00000000000000/* explore-hid.c - this is a "stub" subdriver used to collect data * about HID UPS systems that are not yet supported. * * This subdriver will match any UPS, but only if the "-x explore" option * is given. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "usbhid-ups.h" #include "explore-hid.h" #define EXPLORE_HID_VERSION "EXPLORE HID 0.2" static usage_tables_t explore_utab[] = { hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* Data lookup table (HID <-> NUT) */ /* --------------------------------------------------------------- */ static hid_info_t explore_hid2nut[] = { /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *explore_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *explore_format_mfr(HIDDevice_t *hd) { return hd->Vendor; } static const char *explore_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int explore_claim(HIDDevice_t *hd) { NUT_UNUSED_VARIABLE(hd); if (testvar("explore")) { return 1; } else { return 0; } } subdriver_t explore_subdriver = { EXPLORE_HID_VERSION, explore_claim, explore_utab, explore_hid2nut, explore_format_model, explore_format_mfr, explore_format_serial, fix_report_desc, }; nut-2.8.4/drivers/nutdrv_qx_mecer.h0000644000175000017500000000175114670526611014324 00000000000000/* nutdrv_qx_mecer.h - Subdriver for Mecer/Voltronic Power P98 UPSes * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_MECER_H #define NUTDRV_QX_MECER_H #include "nutdrv_qx.h" extern subdriver_t mecer_subdriver; #endif /* NUTDRV_QX_MECER_H */ nut-2.8.4/drivers/eaton-pdu-genesis2-mib.c0000644000175000017500000001140615000601404015244 00000000000000/* eaton-pdu-genesis2-mib.c - data to monitor Eaton ePDUs branded as: * G1 Aphel based ePDUs (Basic) - GenesisII * * Copyright (C) 2008 - 2019 * Arnaud Quette * Arnaud Quette * Copyright (C) 2015 - 2017 * Jim Klimov * * Supported by Eaton * and previously MGE Office Protection Systems * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "eaton-pdu-genesis2-mib.h" #define EATON_APHEL_GENESIS2_MIB_VERSION "0.52" /* APHEL-GENESIS-II-MIB (monitored ePDU) * ************************************* * Note: There is also a basic XML interface, but not worth * implementing in netxml-ups! */ #define APHEL1_OID_MIB ".1.3.6.1.4.1.17373" #define APHEL1_SYSOID APHEL1_OID_MIB #define APHEL1_OID_MODEL_NAME ".1.3.6.1.4.1.17373.3.1.1.0" #define APHEL1_OID_FIRMREV ".1.3.6.1.4.1.17373.3.1.2.0" #define APHEL1_OID_DEVICE_NAME ".1.3.6.1.4.1.17373.3.1.3.0" #define APHEL1_OID_UNIT_MACADDR ".1.3.6.1.4.1.17373.3.1.4.0" /* needs concat ..0 */ #define APHEL1_OID_OUTLET_CURRENT ".1.3.6.1.4.1.17373.3.2" /* Snmp2NUT lookup table for GenesisII MIB */ static snmp_info_t eaton_aphel_genesisII_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "EATON | Powerware", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, APHEL1_OID_MODEL_NAME, "Eaton Powerware ePDU Monitored", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.macaddr", ST_FLAG_STRING, SU_INFOSIZE, APHEL1_OID_UNIT_MACADDR, "unknown", 0, NULL), /* UPS page */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "EATON | Powerware", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, APHEL1_OID_MODEL_NAME, "Generic SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.id", ST_FLAG_STRING, SU_INFOSIZE, APHEL1_OID_DEVICE_NAME, "unknown", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, APHEL1_OID_FIRMREV, "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /* Outlet page */ /* we can't use template since there is no counterpart to outlet.count */ snmp_info_default("outlet.1.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".1.0", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("outlet.2.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".2.0", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("outlet.3.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".3.0", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("outlet.4.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".4.0", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("outlet.5.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".5.0", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("outlet.6.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".6.0", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("outlet.7.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".7.0", NULL, SU_FLAG_NEGINVALID, NULL), snmp_info_default("outlet.8.current", 0, 0.1, APHEL1_OID_OUTLET_CURRENT ".8.0", NULL, SU_FLAG_NEGINVALID, NULL), /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t aphel_genesisII = { "aphel_genesisII", EATON_APHEL_GENESIS2_MIB_VERSION, NULL, APHEL1_OID_MODEL_NAME, eaton_aphel_genesisII_mib, APHEL1_SYSOID, NULL }; nut-2.8.4/drivers/nutdrv_qx_gtec.h0000644000175000017500000000171115000736161014136 00000000000000/* nutdrv_qx_gtec.h - Subdriver for Gtec UPSes * * Copyright (C) * 2025 Lukas Turek * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_GTEC_H #define NUTDRV_QX_GTEC_H #include "nutdrv_qx.h" extern subdriver_t gtec_subdriver; #endif /* NUTDRV_QX_GTEC_H */ nut-2.8.4/drivers/emerson-avocent-pdu-mib.c0000644000175000017500000002341215000601404015526 00000000000000/* emerson-avocent-pdu-mib.c - subdriver to monitor Emerson Avocent PDUs with NUT * * Copyright (C) * 2008-2018 Arnaud Quette * 2009 Opengear * 2017-2019 Eaton (Arnaud Quette ) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #define OPENGEAR_MULTIPLE_BANKS 1 #include "emerson-avocent-pdu-mib.h" #define EMERSON_AVOCENT_MIB_VERSION "1.30" #define EMERSON_AVOCENT_SYSOID ".1.3.6.1.4.1.10418.17.1.7" #define EMERSON_AVOCENT_OID_MODEL_NAME ".1.3.6.1.4.1.10418.17.2.1.2.0" /* FIXME: Avocent PM's seem to have 3 temperature sensors (index 1, 2, 3) * for the embedded temperature (equivalent to ups.temperature) */ #define AVOCENT_OID_UNIT_TEMPERATURE ".1.3.6.1.4.1.10418.17.2.5.3.1.17.1.1" /* Same as above for humidity... */ #define AVOCENT_OID_UNIT_HUMIDITY ".1.3.6.1.4.1.10418.17.2.5.3.1.24.1" #define AVOCENT_OID_OUTLET_COUNT ".1.3.6.1.4.1.10418.17.2.5.3.1.8.%i.%i" /* FIXME: This is actually pmPowerMgmtPDUTableCurrent1Value */ #define AVOCENT_OID_UNIT_CURRENT ".1.3.6.1.4.1.10418.17.2.5.3.1.10.1.1" /* FIXME: This is actually pmPowerMgmtPDUTableVoltage1Value */ #define AVOCENT_OID_UNIT_VOLTAGE ".1.3.6.1.4.1.10418.17.2.5.3.1.31.1.1" #define AVOCENT_OID_UNIT_MACADDR ".1.3.6.1.2.1.2.2.1.6.1" #ifdef OPENGEAR_MULTIPLE_BANKS #define AVOCENT_OID_OUTLET_ID ".1.3.6.1.4.1.10418.17.2.5.5.1.3" #define AVOCENT_OID_OUTLET_NAME ".1.3.6.1.4.1.10418.17.2.5.5.1.4" #define AVOCENT_OID_OUTLET_STATUS ".1.3.6.1.4.1.10418.17.2.5.5.1.5" /* This the actual value for the Current of the sensor. */ #define AVOCENT_OID_OUTLET_LOAD ".1.3.6.1.4.1.10418.17.2.5.5.1.50" #define AVOCENT_OID_OUTLET_CONTROL ".1.3.6.1.4.1.10418.17.2.5.5.1.6" #else #define AVOCENT_OID_OUTLET_ID ".1.3.6.1.4.1.10418.17.2.5.5.1.3.1.1" #define AVOCENT_OID_OUTLET_NAME ".1.3.6.1.4.1.10418.17.2.5.5.1.4.1.1" #define AVOCENT_OID_OUTLET_STATUS ".1.3.6.1.4.1.10418.17.2.5.5.1.5.1.1" #define AVOCENT_OID_OUTLET_LOAD ".1.3.6.1.4.1.10418.17.2.5.5.1.50.1.1" #define AVOCENT_OID_OUTLET_CONTROL ".1.3.6.1.4.1.10418.17.2.5.5.1.6.1.1" #endif static info_lkp_t avocent_outlet_status_info[] = { info_lkp_default(1, "off"), info_lkp_default(2, "on"), /* info_lkp_default(3, "offLocked"), info_lkp_default(4, "onLocked"), info_lkp_default(5, "offCycle"), info_lkp_default(6, "onPendingOff"), info_lkp_default(7, "offPendingOn"), info_lkp_default(8, "onPendingCycle"), info_lkp_default(9, "notSet"), info_lkp_default(10, "onFixed"), info_lkp_default(11, "offShutdown"), info_lkp_default(12, "tripped"), */ info_lkp_sentinel }; static snmp_info_t emerson_avocent_pdu_mib[] = { /* standard MIB items */ snmp_info_default("device.description", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.1.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.contact", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.4.0", NULL, SU_FLAG_OK, NULL), snmp_info_default("device.location", ST_FLAG_STRING | ST_FLAG_RW, SU_INFOSIZE, ".1.3.6.1.2.1.1.6.0", NULL, SU_FLAG_OK, NULL), /* Device page */ snmp_info_default("device.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Avocent", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("device.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.10418.17.2.5.3.1.5.1.%i", /* EMERSON_AVOCENT_OID_MODEL_NAME */ "Avocent SNMP PDU", SU_FLAG_ABSENT | SU_FLAG_OK | SU_FLAG_NAINVALID, NULL), snmp_info_default("device.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.10418.17.2.1.4.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("device.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), /* Daisychained devices support * Notes: this definition is used to: * - estimate the number of devices, based on the below OID iteration capabilities * - determine the base index of the SNMP OID (ie 0 or 1) */ snmp_info_default("device.count", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.2.1.4.1", "1", SU_FLAG_STATIC, NULL), /* UPS page */ snmp_info_default("ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Avocent", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.model", ST_FLAG_STRING, SU_INFOSIZE, EMERSON_AVOCENT_OID_MODEL_NAME, "Avocent SNMP PDU", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.id", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.10418.17.2.1.1.0", "unknown", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.serial", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.10418.17.2.1.4.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.firmware", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.10418.17.2.1.7.0", "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), snmp_info_default("ups.type", ST_FLAG_STRING, SU_INFOSIZE, NULL, "pdu", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("ups.macaddr", ST_FLAG_STRING, SU_INFOSIZE, AVOCENT_OID_UNIT_MACADDR, "", SU_FLAG_STATIC | SU_FLAG_OK, NULL), /* Outlet page */ snmp_info_default("outlet.id", 0, 1, NULL, "0", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.desc", ST_FLAG_RW | ST_FLAG_STRING, 20, NULL, "All outlets", SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL), snmp_info_default("outlet.count", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.3.1.8.1.%i", "0", SU_FLAG_STATIC | SU_FLAG_ZEROINVALID | SU_FLAG_OK, NULL), /* outlets */ /* NOTE: there is a bug in Avocent FW: * index '0' should not respond (and is not in subtree mode) but answers * to unitary get, since OIDs start at index '1'. *Use the status data below to test since '0' is not a supported value */ snmp_info_default("outlet.%i.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.10418.17.2.5.5.1.5.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1 | SU_FLAG_ZEROINVALID, &avocent_outlet_status_info[0]), snmp_info_default("outlet.%i.id", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.5.1.3.1.%i.%i", NULL, SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.desc", ST_FLAG_RW | ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.10418.17.2.5.5.1.4.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1 | SU_FLAG_NAINVALID, NULL), /* pmPowerMgmtOutletsTableCurrentValue.1.1.1; Value (Integer): 0 */ snmp_info_default("outlet.%i.current", 0, 0.1, ".1.3.6.1.4.1.10418.17.2.5.5.1.50.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* pmPowerMgmtOutletsTableCurrentHighCritical.1.1.1; Value (Integer): 160 */ snmp_info_default("outlet.%i.current.high.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.10418.17.2.5.5.1.100.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* pmPowerMgmtOutletsTableCurrentHighWarning.1.1.1; Value (Integer): 120 */ snmp_info_default("outlet.%i.current.high.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.10418.17.2.5.5.1.101.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* pmPowerMgmtOutletsTableCurrentLowWarning.1.1.1; Value (Integer): 0 */ snmp_info_default("outlet.%i.current.low.warning", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.10418.17.2.5.5.1.102.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* pmPowerMgmtOutletsTableCurrentLowCritical.1.1.1; Value (Integer): 0 */ snmp_info_default("outlet.%i.current.low.critical", ST_FLAG_RW, 0.1, ".1.3.6.1.4.1.10418.17.2.5.5.1.103.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* pmPowerMgmtOutletsTablePowerValue.1.1.1; Value (Integer): 0 */ snmp_info_default("outlet.%i.realpower", 0, 0.1, ".1.3.6.1.4.1.10418.17.2.5.5.1.60.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* pmPowerMgmtOutletsTableVoltageValue.1.1.1; Value (Integer): 238 */ snmp_info_default("outlet.%i.voltage", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.5.1.70.1.%i.%i", NULL, SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* TODO: handle statistics * pmPowerMgmtOutletsTableEnergyValue.1.1.1; Value (Integer): 0 (Wh) * pmPowerMgmtOutletsTableEnergyStartTime.1.1.1; Value (OctetString): 2018-02-13 10:40:09 * pmPowerMgmtOutletsTableEnergyReset.1.1.1; Value (Integer): noAction (1) */ /* Outlet groups collection */ /* pmPowerMgmtNumberOfOutletGroup.0; Value (Integer): 0 */ snmp_info_default("outlet.group.count", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.6.%i", "0", SU_FLAG_STATIC | SU_TYPE_DAISY_1, NULL), /* TODO: support for "Banks" (not sure to understand what is this?!) * pmPowerMgmtTotalNumberOfBanks.0; Value (Integer): 6 * pmPowerMgmtBanksTableName.1.1.1; Value (OctetString): 18-bf-ffP0_1_A */ /* According to MIB Power Control values are: * noAction(1), * powerOn(2), * powerOff(3), * powerCycle(4), * powerLock(5), * powerUnlock(6) */ snmp_info_default("outlet.%i.load.cycle", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.5.1.6.1.%i.%i", "4", SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.load.off", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.5.1.6.1.%i.%i", "3", SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), snmp_info_default("outlet.%i.load.on", 0, 1, ".1.3.6.1.4.1.10418.17.2.5.5.1.6.1.%i.%i", "2", SU_TYPE_CMD | SU_OUTLET | SU_TYPE_DAISY_1, NULL), /* end of structure. */ snmp_info_sentinel }; mib2nut_info_t emerson_avocent_pdu = { "emerson_avocent_pdu", EMERSON_AVOCENT_MIB_VERSION, NULL, EMERSON_AVOCENT_OID_MODEL_NAME, emerson_avocent_pdu_mib, EMERSON_AVOCENT_SYSOID, NULL }; nut-2.8.4/drivers/nutdrv_qx_hunnox.h0000644000175000017500000000202714670526611014545 00000000000000/* nutdrv_qx_hunnox.h - Subdriver for Hunnox protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * 2020 Mariano Jan https://marianojan.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_HUNNOX_H #define NUTDRV_QX_HUNNOX_H #include "nutdrv_qx.h" extern subdriver_t hunnox_subdriver; #endif /* NUTDRV_QX_HUNNOX_H */ nut-2.8.4/drivers/powervar_cx_ser.c0000644000175000017500000001222415044656702014320 00000000000000/*vim ts=4*/ /* powervar_cx_ser.c - Serial driver for Powervar UPM UPSs using CUSPP. * * Supported Powervar UPS families in this driver: * UPM (All) * * Copyright (C) * 2024, 2025 by Bill Elliot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * History: * - 2 December 2024. Bill Elliot * Started to work on common variable and function file so this driver * and the USB driver can make use of the same protocol related functions. * - 2 October 2024. Bill Elliot * Used pieces of oneac.c driver to get jump-started. * */ #include "main.h" #include "serial.h" #include "nut_stdint.h" /* Two drivers include the following. Provide some identifier for differences */ #define PVAR_SERIAL 1 /* This is the serial comm driver */ #include "powervar_cx.h" /* Common driver defines, variables, and functions */ #define DRIVER_NAME "Powervar-CUSSP UPS driver (Serial)" #define DRIVER_VERSION "1.00" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Bill Elliot ", DRV_EXPERIMENTAL, { NULL } }; /* Serial comm stuff here */ #define SECS 0 /* Serial function wait time*/ #define USEC 500000 /* Rest of serial function wait time*/ #define COMM_TRIES 3 /* Serial retries before "stale" */ /******************************************* * Serial response communication functions * *******************************************/ /* This function is called to send the request to the initialized device. */ size_t SendRequest (const char* sRequest) { ssize_t Ret; Ret = ser_send(upsfd, "%s%c", sRequest, ENDCHAR); return (size_t)Ret; } /* Since an installed network card may slightly delay responses from * the UPS allow for a repeat of the get request. */ #define RETRIES 4 ssize_t PowervarGetResponse (char* chBuff, const size_t BuffSize) { int Retries = RETRIES; /* x/2 seconds max with 500000 USEC */ ssize_t return_val; do { return_val = ser_get_line(upsfd, chBuff, BuffSize, ENDCHAR, IGNCHARS, SECS, USEC); if (return_val > 0) { break; } upsdebugx (3, "!PowervarGetResponse retry (%" PRIiSIZE ", %d)...", return_val, Retries); } while (--Retries > 0); upsdebugx (4, "PowervarGetResponse buffer: %s", chBuff); if (Retries == 0) { upsdebugx (2, "!!PowervarGetResponse timeout..."); return_val = 1; /* Comms error */ } else { if (Retries < RETRIES) { upsdebugx (2, "PowervarGetResponse recovered (%d)...", Retries); } return_val = 0; /* Good comms */ } return return_val; } /**************************************************************** * Below are the primary commands that are called by NUT main * ***************************************************************/ void upsdrv_initups(void) { uint32_t ulBaud; /* Serial comm init here */ upsfd = ser_open(device_path); /* See if there is a custom baudrate available -- generally not */ if (getval("pvbaud") == NULL) { ser_set_speed(upsfd, device_path, B9600); upsdebugx (4, "Serial baud set to 9600."); } else { /* Custom firmware is needed to allow for other baud rates */ ulBaud = atoi(getval("pvbaud")); if (ulBaud == 38400) { ser_set_speed(upsfd, device_path, B38400); upsdebugx (4, "Serial baud set to 38400."); } else if (ulBaud == 57600) { ser_set_speed(upsfd, device_path, B57600); upsdebugx (4, "Serial baud set to 57600."); } else if (ulBaud == 115200) /* The only other baud known to be available. */ { ser_set_speed(upsfd, device_path, B115200); upsdebugx (4, "Serial baud set to 115200."); } else { upsdebugx (4, "Serial baud not set!! (%" PRIu32 ").", ulBaud); } } /*get the UPS in the right frame of mind */ ser_send_pace(upsfd, 100, "%s", COMMAND_END); ser_send_pace(upsfd, 100, "%s", COMMAND_END); sleep (1); } /* This function is called on driver startup to initialize variables/commands */ void upsdrv_initinfo(void) { /* Get serial port ready */ ser_flush_in(upsfd, "", 0); PvarCommon_Initinfo (); } /* This function is called regularly for data updates. */ void upsdrv_updateinfo(void) { /* Get serial port ready */ ser_flush_in(upsfd, "", 0); PvarCommon_Updateinfo (); ser_comm_good(); } /************************************** * Handlers for NUT command calls * *************************************/ void upsdrv_help(void) { printf("\n---------\nNOTE:\n"); printf("This driver is for connecting to a Powervar UPS serial port at 9600 BPS.\n"); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } /* End of powervar_cx_ser.c file */ nut-2.8.4/drivers/powerp-txt.h0000644000175000017500000000205214670526611013243 00000000000000/* * powerp-txt.h - Model specific data/definitions for CyberPower text * protocol UPSes * * Copyright (C) * 2007 Doug Reynolds * 2007-2008 Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef POWERP_TXT_H #define POWERP_TXT_H #include "powerpanel.h" extern subdriver_t powpan_text; #endif nut-2.8.4/drivers/phoenixcontact_modbus.c0000644000175000017500000007022415044656702015513 00000000000000/* phoenixcontact_modbus.c - Driver for PhoenixContact-QUINT UPS * * Copyright (C) * 2017 Spiros Ioannou * 2024 Ricardo Rodriguez * 2025 Ulfat Hasangarayev * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include #include "nut_stdint.h" #include #if !(defined NUT_MODBUS_LINKTYPE_STR) # define NUT_MODBUS_LINKTYPE_STR "unknown" #endif #define DRIVER_NAME "NUT PhoenixContact Modbus driver (libmodbus link type: " NUT_MODBUS_LINKTYPE_STR ")" #define DRIVER_VERSION "0.09" #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) #define MODBUS_SLAVE_ID 192 #define QUINT_5A_UPS_1_3AH_BATTERY_PARTNUMBER 2320254 #define QUINT_5A_UPS_1_3AH_BATTERY_DESCRIPTION "QUINT-UPS/24DC/24DC/5/1.3AH" #define QUINT_10A_UPS_PARTNUMBER 2320225 #define QUINT_10A_UPS_DESCRIPTION "QUINT-UPS/24DC/24DC/10" #define QUINT_20A_UPS_PARTNUMBER 2320238 #define QUINT_20A_UPS_DESCRIPTION "QUINT-UPS/24DC/24DC/20" #define QUINT_40A_UPS_PARTNUMBER 2320241 #define QUINT_40A_UPS_DESCRIPTION "QUINT-UPS/24DC/24DC/40" #define QUINT4_10A_UPS_PARTNUMBER 2907067 #define QUINT4_10A_UPS_DESCRIPTION "QUINT4-UPS/24DC/24DC/10/USB" #define QUINT4_20A_UPS_PARTNUMBER 2907072 #define QUINT4_20A_UPS_DESCRIPTION "QUINT4-UPS/24DC/24DC/20/USB" #define QUINT4_40A_UPS_PARTNUMBER 2907078 #define QUINT4_40A_UPS_DESCRIPTION "QUINT4-UPS/24DC/24DC/40/USB" #define TRIO_5A_UPS_PARTNUMBER 2866611 #define TRIO_5A_UPS_DESCRIPTION "TRIO-UPS/1AC/24DC/5" #define TRIO_2G_5A_UPS_PARTNUMBER 2907160 #define TRIO_2G_5A_UPS_DESCRIPTION "TRIO-UPS-2G/1AC/24DC/5" #define TRIO_2G_10A_UPS_PARTNUMBER 2907161 #define TRIO_2G_10A_UPS_DESCRIPTION "TRIO-UPS-2G/1AC/24DC/10" #define TRIO_2G_20A_UPS_PARTNUMBER 1105556 #define TRIO_2G_20A_UPS_DESCRIPTION "TRIO-UPS-2G/1AC/24DC/20" /* --- Shutdown & Mode Configuration --- */ /* Macro for fetching a uint16_t config value with fallback */ #define GETVAL_U16(name, fallback) (dstate_getinfo(name) ? (uint16_t)atoi(dstate_getinfo(name)) : (fallback)) /* Time [s] after entering battery mode before shutdown signal (bit 15) is triggered */ #define REG_PC_SHUTDOWN_DELAY 0x105A /* default: 60s, range: 1–65535 */ /* Time [s] allowed for PC to shut down before output turns off */ #define REG_PC_SHUTDOWN_TIME 0x105D /* default: 120s, range: 1–3600 */ /* Time [s] output is off after PC shutdown before reboot */ #define REG_PC_RESET_TIME 0x105E /* default: 10s, range: 0–60 */ /* Time [s] input voltage must be above threshold to return to mains*/ #define REG_MAINS_RETURN_DELAY 0x1058 /* default: 10s */ /* Selector mode switch: PC-Mode = 9 */ #define REG_MODE_SELECTOR_SWITCH 0x1074 /* default: 0–9 */ /* --- Battery Monitoring --- */ /* SOH warning threshold [%] */ #define REG_WARNING_SOH_THRESHOLD 0x1071 /* default: 0 (disabled), range: 1–100 */ /* Switch to battery mode if below this input voltage [mV] */ #define REG_VOLTAGE_BELOW_BATTERY 0x1056 /* example: 21000 */ /* Switch to mains mode if above this voltage [mV] */ #define REG_VOLTAGE_ABOVE_MAINS 0x1057 /* example: 23000 */ typedef enum { NONE, QUINT_UPS, QUINT4_UPS, TRIO_UPS, TRIO_2G_UPS } models; /* Variables */ static modbus_t *modbus_ctx = NULL; static int errcount = 0; static int mrir(modbus_t * arg_ctx, int addr, int nb, uint16_t * dest); static models UPSModel = NONE; typedef struct { const char *nut_name; uint16_t reg_addr; } delay_param_t; static const delay_param_t delay_params[] = { { "battery.energysave.delay", REG_PC_SHUTDOWN_DELAY}, { "ups.timer.shutdown", REG_PC_SHUTDOWN_TIME}, { "ups.timer.start", REG_PC_RESET_TIME}, { "ups.delay.start", REG_MAINS_RETURN_DELAY}, { "experimental.ups.mode.selector", REG_MODE_SELECTOR_SWITCH}, { "experimental.battery.warning_soh", REG_WARNING_SOH_THRESHOLD}, { "input.voltage.low.critical", REG_VOLTAGE_BELOW_BATTERY}, { "input.voltage.high.critical", REG_VOLTAGE_ABOVE_MAINS } }; /* For the QUINT ups (first implementation of the driver) the modbus addresses are reported in dec format,for the QUINT4 ups they are reported in hex format. The difference is caused from the way they are reported in the datasheet, keeping them in the same format as the datasheet make more simple the maintenence of the driver avoiding conversions while coding. */ /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Spiros Ioannou \n" "Ricardo Rodriguez \n" "Ulfat Hasangarayev ", DRV_BETA, {NULL} }; static int write_uint32_register(modbus_t *ctx, int reg, uint32_t value) { uint16_t regs[2]; int ret; regs[0] = value >> 16; /*High word*/ regs[1] = value & 0xFFFF; /*Low word*/ ret = modbus_write_registers(ctx, reg, 2, regs); if (ret == -1) { upslogx(LOG_ERR, "Failed to write 32-bit value to reg 0x%04X: %s", (unsigned int)reg, modbus_strerror(errno)); } return ret; } static int write_uint32_reg_bit(modbus_t *ctx, int reg, int bit_index, bool bit_value) { uint16_t regs[2]; uint32_t val; if (modbus_read_registers(ctx, reg, 2, regs) != 2) { upslogx(LOG_ERR, "Failed to read 32-bit register 0x%04X: %s", (unsigned int)reg, modbus_strerror(errno)); return -1; } val = ((uint32_t)regs[0] << 16) | regs[1]; if (bit_value) val |= (1U << bit_index); else val &= ~(1U << bit_index); regs[0] = val >> 16; regs[1] = val & 0xFFFF; if (modbus_write_registers(ctx, reg, 2, regs) == -1) { upslogx(LOG_ERR, "Failed to write modified 32-bit value to 0x%04X: %s", (unsigned int)reg, modbus_strerror(errno)); return -1; } return 0; } static void phoenixcontact_apply_advanced_config(modbus_t *ctx) { upslogx(LOG_NOTICE, "Applying advanced Phoenix Contact configuration..."); write_uint32_reg_bit(ctx, 0x1040, 5, false); /* NOTE: you can configure these via override.* or default.* settings */ modbus_write_register(ctx, REG_PC_SHUTDOWN_DELAY, GETVAL_U16("battery.energysave.delay", 60)); modbus_write_register(ctx, REG_PC_SHUTDOWN_TIME, GETVAL_U16("ups.timer.shutdown", 60)); modbus_write_register(ctx, REG_PC_RESET_TIME, GETVAL_U16("ups.timer.start", 5)); modbus_write_register(ctx, REG_WARNING_SOH_THRESHOLD, GETVAL_U16("experimental.battery.warning_soh", 20)); modbus_write_register(ctx, REG_MODE_SELECTOR_SWITCH, GETVAL_U16("experimental.ups.mode.selector", 9)); modbus_write_register(ctx, REG_VOLTAGE_BELOW_BATTERY, GETVAL_U16("input.voltage.low.critical", 21000)); modbus_write_register(ctx, REG_VOLTAGE_ABOVE_MAINS, GETVAL_U16("input.voltage.high.critical", 29000)); modbus_write_register(ctx, REG_MAINS_RETURN_DELAY, GETVAL_U16("ups.delay.start", 10)); /* the value 0xFFFDFFFF sets bit 17 low so that the mode selector switch is overwritten in software */ write_uint32_register(ctx, 0x1076, 0xFFFDFFFF); } void upsdrv_initinfo(void) { uint16_t tab_reg[4]; uint64_t PartNumber = 0; size_t i; for (i = 0; i < (sizeof(tab_reg) / sizeof(tab_reg[0])); i++) { tab_reg[i] = 0; } upsdebugx(2, "upsdrv_initinfo"); dstate_setinfo("device.mfr", "Phoenix Contact"); /* upsh.instcmd = instcmd; */ /* upsh.setvar = setvar; */ mrir(modbus_ctx, 0x0005, 4, tab_reg); /* * Method provided from Phoenix Conatct to establish the UPS model: * Read registers from 0x0005 to 0x0008 and "concatenate" them with the order * 0x0008 0x0007 0x0006 0x0005 in hex form, convert the obtained number from hex to dec. * The first 7 most significant digits of the number in dec form are the part number of * the UPS. */ PartNumber = (tab_reg[3] << 16) + tab_reg[2]; PartNumber = (PartNumber << 16) + tab_reg[1]; PartNumber = (PartNumber << 16) + tab_reg[0]; while (PartNumber > 10000000) { PartNumber /= 10; } switch (PartNumber) { case QUINT_5A_UPS_1_3AH_BATTERY_PARTNUMBER: UPSModel = QUINT_UPS; dstate_setinfo("device.model", QUINT_5A_UPS_1_3AH_BATTERY_DESCRIPTION); break; case QUINT_10A_UPS_PARTNUMBER: UPSModel = QUINT_UPS; dstate_setinfo("device.model", QUINT_10A_UPS_DESCRIPTION); break; case QUINT_20A_UPS_PARTNUMBER: UPSModel = QUINT_UPS; dstate_setinfo("device.model", QUINT_20A_UPS_DESCRIPTION); break; case QUINT_40A_UPS_PARTNUMBER: UPSModel = QUINT_UPS; dstate_setinfo("device.model", QUINT_40A_UPS_DESCRIPTION); break; case QUINT4_10A_UPS_PARTNUMBER: UPSModel = QUINT4_UPS; dstate_setinfo("device.model", QUINT4_10A_UPS_DESCRIPTION); break; case QUINT4_20A_UPS_PARTNUMBER: UPSModel = QUINT4_UPS; dstate_setinfo("device.model", QUINT4_20A_UPS_DESCRIPTION); break; case QUINT4_40A_UPS_PARTNUMBER: UPSModel = QUINT4_UPS; dstate_setinfo("device.model", QUINT4_40A_UPS_DESCRIPTION); break; case TRIO_5A_UPS_PARTNUMBER: UPSModel = TRIO_UPS; dstate_setinfo("device.model", TRIO_5A_UPS_DESCRIPTION); break; case TRIO_2G_5A_UPS_PARTNUMBER: UPSModel = TRIO_2G_UPS; dstate_setinfo("device.model", TRIO_2G_5A_UPS_DESCRIPTION); break; case TRIO_2G_10A_UPS_PARTNUMBER: UPSModel = TRIO_2G_UPS; dstate_setinfo("device.model", TRIO_2G_10A_UPS_DESCRIPTION); break; case TRIO_2G_20A_UPS_PARTNUMBER: UPSModel = TRIO_2G_UPS; dstate_setinfo("device.model", TRIO_2G_20A_UPS_DESCRIPTION); break; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: fatalx(EXIT_FAILURE, "Unknown UPS part number: %" PRIu64, PartNumber); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } } void upsdrv_updateinfo(void) { uint16_t tab_reg[64]; uint16_t actual_code_functions; uint16_t actual_code_functions1; uint16_t actual_code_functions2; uint16_t actual_alarms = 0; uint16_t actual_alarms1 = 0; uint16_t actual_alarms2 = 0; uint16_t battery_voltage; uint16_t battery_temperature; uint16_t battery_runtime; uint16_t battery_capacity; uint16_t output_current; uint16_t value = 0; size_t i; errcount = 0; upsdebugx(2, "upsdrv_updateinfo"); switch (UPSModel) { case QUINT4_UPS: for (i = 0; i < sizeof(delay_params) / sizeof(delay_params[0]); i++) { if (modbus_read_registers(modbus_ctx, delay_params[i].reg_addr, 1, &value) != -1) { dstate_setinfo(delay_params[i].nut_name, "%d", value); } else { upslogx(LOG_WARNING, "Failed to read %s (0x%04X): %s", delay_params[i].nut_name, delay_params[i].reg_addr, modbus_strerror(errno)); } } mrir(modbus_ctx, 0x2000, 1, &actual_code_functions); tab_reg[0] = CHECK_BIT(actual_code_functions, 2); /* Battery mode is the 2nd bit of the register 0x2000 */ tab_reg[2] = CHECK_BIT(actual_code_functions, 5); /* Battery charging is the 6th bit of the register 0x2000 */ mrir(modbus_ctx, 0x3001, 1, &actual_alarms1); tab_reg[1] = CHECK_BIT(actual_alarms1, 2); /* Battery discharged is the 2nd bit of the register 0x3001 */ break; case TRIO_UPS: case QUINT_UPS: mrir(modbus_ctx, 29697, 3, tab_reg); /* LB is actually called "shutdown event" on this ups */ break; case TRIO_2G_UPS: mrir(modbus_ctx, 0x2000, 1, &actual_code_functions); mrir(modbus_ctx, 0x2002, 1, &actual_code_functions1); mrir(modbus_ctx, 0x3001, 1, &actual_code_functions2); tab_reg[0] = CHECK_BIT(actual_code_functions1, 2); tab_reg[2] = CHECK_BIT(actual_code_functions, 5); tab_reg[1] = CHECK_BIT(actual_code_functions2, 2); break; case NONE: fatalx(EXIT_FAILURE, "Unknown UPS model."); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: fatalx(EXIT_FAILURE, "Unknown UPS model."); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } status_init(); if (tab_reg[0]) status_set("OB"); else status_set("OL"); if (tab_reg[2]) { status_set("CHRG"); } if (tab_reg[1]) { status_set("LB"); } switch (UPSModel) { case TRIO_2G_UPS: case QUINT4_UPS: mrir(modbus_ctx, 0x2006, 1, tab_reg); break; case QUINT_UPS: mrir(modbus_ctx, 29745, 1, tab_reg); break; case TRIO_UPS: mrir(modbus_ctx, 29702, 1, tab_reg); break; case NONE: fatalx(EXIT_FAILURE, "Unknown UPS model."); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: fatalx(EXIT_FAILURE, "Unknown UPS model."); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } dstate_setinfo("output.voltage", "%d", (int) (tab_reg[0] / 1000)); switch (UPSModel) { case QUINT4_UPS: mrir(modbus_ctx, 0x200F, 1, tab_reg); break; case QUINT_UPS: mrir(modbus_ctx, 29749, 5, tab_reg); break; case TRIO_UPS: /*battery.charge is not available for TRIO and TRIO-2G models*/ break; case TRIO_2G_UPS: /*battery.charge is not available for TRIO and TRIO-2G models*/ break; case NONE: fatalx(EXIT_FAILURE, "Unknown UPS model."); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: fatalx(EXIT_FAILURE, "Unknown UPS model."); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } if (UPSModel != TRIO_2G_UPS && UPSModel != TRIO_UPS) dstate_setinfo("battery.charge", "%d", tab_reg[0]); /* dstate_setinfo("battery.runtime", tab_reg[1]*60); */ /* also reported on this address, but less accurately */ switch (UPSModel) { case QUINT4_UPS: mrir(modbus_ctx, 0x200A, 1, &battery_voltage); tab_reg[0] = battery_voltage; mrir(modbus_ctx, 0x200D, 1, &battery_temperature); tab_reg[1] = battery_temperature; mrir(modbus_ctx, 0x2010, 1, &battery_runtime); tab_reg[3] = battery_runtime; mrir(modbus_ctx, 0x4211, 1, &battery_capacity); tab_reg[8] = battery_capacity; mrir(modbus_ctx, 0x2007, 1, &output_current); tab_reg[6] = output_current; break; case QUINT_UPS: mrir(modbus_ctx, 29792, 10, tab_reg); break; case TRIO_UPS: mrir(modbus_ctx, 29700, 1, &battery_voltage); tab_reg[0] = battery_voltage; /*output.current variable is not available for TRIO model*/ break; case TRIO_2G_UPS: /*battery.voltage variable is not available for TRIO-2G model*/ /*battery.temperature variable is not available for TRIO and TRIO-2G models*/ /*battery.runtime variable is not available for TRIO and TRIO-2G models*/ /*battery.capacity variable is not available for TRIO and TRIO-2G models*/ mrir(modbus_ctx, 0x2007, 1, &output_current); tab_reg[6] = output_current; break; case NONE: fatalx(EXIT_FAILURE, "Unknown UPS model."); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: fatalx(EXIT_FAILURE, "Unknown UPS model."); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } if (UPSModel != TRIO_2G_UPS) { dstate_setinfo("battery.voltage", "%f", (double) (tab_reg[0]) / 1000.0); if (UPSModel != TRIO_UPS) { dstate_setinfo("battery.capacity", "%d", tab_reg[8] * 10); dstate_setinfo("battery.temperature", "%d", tab_reg[1] - 273); dstate_setinfo("battery.runtime", "%d", tab_reg[3]); } } if (UPSModel != TRIO_UPS) { dstate_setinfo("output.current", "%f", (double) (tab_reg[6]) / 1000.0); } /* ALARMS */ alarm_init(); switch (UPSModel) { case QUINT4_UPS: tab_reg[0] = 0; actual_alarms = 0; actual_alarms1 = 0; mrir(modbus_ctx, 0x3000, 1, &actual_alarms); mrir(modbus_ctx, 0x3001, 1, &actual_alarms1); if (CHECK_BIT(actual_alarms, 9) && CHECK_BIT(actual_alarms, 9)) alarm_set("End of life (Resistance)"); if (CHECK_BIT(actual_alarms1, 0)) alarm_set("End of life (Time)"); if (CHECK_BIT(actual_alarms, 10)) alarm_set("End of life (Voltage)"); if (CHECK_BIT(actual_alarms, 3)) alarm_set("No Battery"); if (CHECK_BIT(actual_alarms, 5)) alarm_set("Inconsistent technology"); if (CHECK_BIT(actual_alarms1, 8)) alarm_set("Overload Cutoff"); if (CHECK_BIT(actual_alarms1, 3)) alarm_set("Low Battery (Voltage)"); if (CHECK_BIT(actual_alarms1, 4)) alarm_set("Low Battery (Charge)"); if (CHECK_BIT(actual_alarms1, 5)) alarm_set("Low Battery (Time)"); if (CHECK_BIT(actual_alarms1, 14)) alarm_set("Low Battery (Service)"); break; case TRIO_2G_UPS: tab_reg[0] = 0; actual_alarms = 0; actual_alarms1 = 0; mrir(modbus_ctx, 0x3000, 1, &actual_alarms); mrir(modbus_ctx, 0x3001, 1, &actual_alarms1); mrir(modbus_ctx, 0x3012, 1, &actual_alarms2); if (CHECK_BIT(actual_alarms, 10)) alarm_set("End of life (Voltage)"); if (CHECK_BIT(actual_alarms, 3)) alarm_set("No Battery"); if (CHECK_BIT(actual_alarms1, 8)) alarm_set("Overload Cutoff"); if (CHECK_BIT(actual_alarms1, 17)) alarm_set("Low Battery (Voltage)"); if (CHECK_BIT(actual_alarms1, 14)) alarm_set("Low Battery (Service)"); break; case QUINT_UPS: mrir(modbus_ctx, 29840, 1, tab_reg); if (CHECK_BIT(tab_reg[0], 4) && CHECK_BIT(tab_reg[0], 5)) alarm_set("End of life (Resistance)"); if (CHECK_BIT(tab_reg[0], 6)) alarm_set("End of life (Time)"); if (CHECK_BIT(tab_reg[0], 7)) alarm_set("End of life (Voltage)"); if (CHECK_BIT(tab_reg[0], 9)) alarm_set("No Battery"); if (CHECK_BIT(tab_reg[0], 10)) alarm_set("Inconsistent technology"); if (CHECK_BIT(tab_reg[0], 11)) alarm_set("Overload Cutoff"); /* We don't use those low-battery indicators below. * No info or configuration exists for those alarm low-bat */ if (CHECK_BIT(tab_reg[0], 12)) alarm_set("Low Battery (Voltage)"); if (CHECK_BIT(tab_reg[0], 13)) alarm_set("Low Battery (Charge)"); if (CHECK_BIT(tab_reg[0], 14)) alarm_set("Low Battery (Time)"); if (CHECK_BIT(tab_reg[0], 16)) alarm_set("Low Battery (Service)"); break; case TRIO_UPS: mrir(modbus_ctx, 29706, 1, tab_reg); if (CHECK_BIT(tab_reg[0], 0)) alarm_set("End of life (Time)"); if (CHECK_BIT(tab_reg[0], 2)) alarm_set("End of life (Voltage)"); if (CHECK_BIT(tab_reg[0], 1)) alarm_set("No Battery"); if (CHECK_BIT(tab_reg[0], 3)) alarm_set("Low Battery (Voltage)"); break; case NONE: fatalx(EXIT_FAILURE, "Unknown UPS model."); #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif /* All enum cases defined as of the time of coding * have been covered above. Handle later definitions, * memory corruptions and buggy inputs below... */ default: fatalx(EXIT_FAILURE, "Unknown UPS model."); #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } if (errcount == 0) { alarm_commit(); status_commit(); dstate_dataok(); } else dstate_datastale(); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* * WARNING: When using RTU TCP, this driver will probably * never support shutdowns properly, except on some systems: * In order to be of any use, the driver should be called * near the end of the system halt script (or a service * management framework's equivalent, if any). By that * time we, in all likelyhood, won't have basic network * capabilities anymore, so we could never send this * command to the UPS. This is not an error, but rather * a limitation (on some platforms) of the interface/media * used for these devices. */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "active shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_help(void) { printf("\nConsider setting default.* values for the following tweaks:" "\nbattery.energysave.delay\tDelay after going on-battery before initiating PC shutdown (in seconds)" "\nups.timer.shutdown\tTime allowed for PC to shutdown (in seconds)" "\nups.timer.start\tDuration of output off before reboot (in seconds)" "\nups.delay.start\tDelay before switching back to mains (in seconds)" "\nexperimental.ups.mode.selector\tUPS operating mode (e.g. 9 = PC-Mode)" "\nexperimental.battery.warning_soh\tBattery warning SOH threshold (%%)" "\ninput.voltage.low.critical\tThreshold [V] to switch to battery mode" "\ninput.voltage.high.critical\tThreshold [V] to return to mains mode" "\n"); } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { } void upsdrv_initups(void) { int r, result; uint16_t FWVersion; upsdebugx(2, "upsdrv_initups"); modbus_ctx = modbus_new_rtu(device_path, 115200, 'E', 8, 1); if (modbus_ctx == NULL) fatalx(EXIT_FAILURE, "Unable to create the libmodbus context"); r = modbus_set_slave(modbus_ctx, MODBUS_SLAVE_ID); /* slave ID */ if (r < 0) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "Invalid modbus slave ID %d", MODBUS_SLAVE_ID); } if (modbus_connect(modbus_ctx) == -1) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "modbus_connect: unable to connect: %s", modbus_strerror(errno)); } result = mrir(modbus_ctx, 0x0004, 1, &FWVersion); if (result == -1) { modbus_close(modbus_ctx); modbus_free(modbus_ctx); modbus_ctx = modbus_new_rtu(device_path, 19200, 'E', 8, 1); if (modbus_ctx == NULL) fatalx(EXIT_FAILURE, "Unable to create the libmodbus context"); r = modbus_set_slave(modbus_ctx, MODBUS_SLAVE_ID); /* slave ID */ if (r < 0) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "Invalid modbus slave ID %d", MODBUS_SLAVE_ID); } if (modbus_connect(modbus_ctx) == -1) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "modbus_connect: unable to connect: %s", modbus_strerror(errno)); } r = mrir(modbus_ctx, 0x0004, 1, &FWVersion); if (r < 0) { fatalx(EXIT_FAILURE, "UPS does not repond to read requests."); } } phoenixcontact_apply_advanced_config(modbus_ctx); dstate_setinfo("ups.firmware", "%" PRIu16, FWVersion); } void upsdrv_cleanup(void) { if (modbus_ctx != NULL) { modbus_close(modbus_ctx); modbus_free(modbus_ctx); } } /* Modbus Read Input Registers */ static int mrir(modbus_t * arg_ctx, int addr, int nb, uint16_t * dest) { int r; r = modbus_read_input_registers(arg_ctx, addr, nb, dest); if (r == -1) { upslogx(LOG_ERR, "mrir: modbus_read_input_registers(addr:%d, count:%d): %s (%s)", addr, nb, modbus_strerror(errno), device_path); errcount++; } return r; } nut-2.8.4/drivers/apcsmart-old.c0000644000175000017500000010626015044656702013502 00000000000000/* apcsmart.c - driver for APC smart protocol units (originally "newapc") Copyright (C) 1999 Russell Kroll (C) 2000 Nigel Metheringham This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "serial.h" #include "apcsmart-old.h" #include "nut_stdint.h" #define DRIVER_NAME "APC Smart protocol driver (old)" #define DRIVER_VERSION "2.35" static upsdrv_info_t table_info = { "APC command table", APC_TABLE_VERSION, NULL, 0, { NULL } }; /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Russell Kroll \n" "Nigel Metheringham \n" "Michal Soltys ", DRV_STABLE, { &table_info, NULL } }; #define ALT_CABLE_1 "940-0095B" static int ups_status = 0, quirk_capability_overflow = 0; static apc_vartab_t *vartab_lookup_char(char cmdchar) { int i; for (i = 0; apc_vartab[i].name != NULL; i++) if (apc_vartab[i].cmd == cmdchar) return &apc_vartab[i]; return NULL; } static apc_vartab_t *vartab_lookup_name(const char *var) { int i; for (i = 0; apc_vartab[i].name != NULL; i++) if (!strcasecmp(apc_vartab[i].name, var)) return &apc_vartab[i]; return NULL; } /* FUTURE: change to use function pointers */ /* convert APC formatting to NUT formatting */ static const char *convert_data(apc_vartab_t *cmd_entry, const char *upsval) { static char tmp[128]; long tval; switch(cmd_entry->flags & APC_FORMATMASK) { case APC_F_PERCENT: case APC_F_VOLT: case APC_F_AMP: case APC_F_CELSIUS: case APC_F_HEX: case APC_F_DEC: case APC_F_SECONDS: case APC_F_LEAVE: /* no conversion for any of these */ return upsval; case APC_F_HOURS: /* convert to seconds */ tval = 60 * 60 * strtol(upsval, NULL, 10); snprintf(tmp, sizeof(tmp), "%ld", tval); return tmp; case APC_F_MINUTES: /* Convert to seconds - NUT standard time measurement */ tval = 60 * strtol(upsval, NULL, 10); /* Ignore errors - Theres not much we can do */ snprintf(tmp, sizeof(tmp), "%ld", tval); return tmp; case APC_F_REASON: switch (upsval[0]) { case 'R': return "unacceptable utility voltage rate of change"; case 'H': return "high utility voltage"; case 'L': return "low utility voltage"; case 'T': return "line voltage notch or spike"; case 'O': return "no transfers yet since turnon"; case 'S': return "simulated power failure or UPS test"; default: return upsval; } default: break; } upslogx(LOG_NOTICE, "Unable to handle conversion of %s", cmd_entry->name); return upsval; } static void ups_status_set(void) { status_init(); if (ups_status & APC_STAT_CAL) status_set("CAL"); /* calibration */ if (ups_status & APC_STAT_TRIM) status_set("TRIM"); /* SmartTrim */ if (ups_status & APC_STAT_BOOST) status_set("BOOST"); /* SmartBoost */ if (ups_status & APC_STAT_OL) status_set("OL"); /* on line */ if (ups_status & APC_STAT_OB) status_set("OB"); /* on battery */ if (ups_status & APC_STAT_OVER) status_set("OVER"); /* overload */ if (ups_status & APC_STAT_LB) status_set("LB"); /* low battery */ if (ups_status & APC_STAT_RB) status_set("RB"); /* replace batt */ if (ups_status == 0) status_set("OFF"); status_commit(); } static void alert_handler(char ch) { switch (ch) { case '!': /* clear OL, set OB */ upsdebugx(4, "alert_handler: OB"); ups_status &= ~APC_STAT_OL; ups_status |= APC_STAT_OB; break; case '$': /* clear OB, set OL */ upsdebugx(4, "alert_handler: OL"); ups_status &= ~APC_STAT_OB; ups_status |= APC_STAT_OL; break; case '%': /* set LB */ upsdebugx(4, "alert_handler: LB"); ups_status |= APC_STAT_LB; break; case '+': /* clear LB */ upsdebugx(4, "alert_handler: not LB"); ups_status &= ~APC_STAT_LB; break; case '#': /* set RB */ upsdebugx(4, "alert_handler: RB"); ups_status |= APC_STAT_RB; break; case '?': /* set OVER */ upsdebugx(4, "alert_handler: OVER"); ups_status |= APC_STAT_OVER; break; case '=': /* clear OVER */ upsdebugx(4, "alert_handler: not OVER"); ups_status &= ~APC_STAT_OVER; break; default: upsdebugx(4, "alert_handler got 0x%02x (unhandled)", ch); break; } ups_status_set(); } static ssize_t read_buf(char *buf, size_t buflen) { ssize_t ret; ret = ser_get_line_alert(upsfd, buf, buflen, ENDCHAR, POLL_IGNORE, POLL_ALERT, alert_handler, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 1) { ser_comm_fail("%s", ret ? strerror(errno) : "timeout"); return ret; } ser_comm_good(); return ret; } static ssize_t poll_data(apc_vartab_t *vt) { ssize_t ret; char tmp[SMALLBUF]; if ((vt->flags & APC_PRESENT) == 0) return 1; upsdebugx(4, "poll_data: %s", vt->name); ret = ser_send_char(upsfd, vt->cmd); if (ret != 1) { upslogx(LOG_ERR, "poll_data: ser_send_char failed"); dstate_datastale(); return 0; } if (read_buf(tmp, sizeof(tmp)) < 1) { dstate_datastale(); return 0; } /* no longer supported by the hardware somehow */ if (!strcmp(tmp, "NA")) { dstate_delinfo(vt->name); return 1; } dstate_setinfo(vt->name, "%s", convert_data(vt, tmp)); dstate_dataok(); return 1; } /* check for support or just update a named variable */ static int query_ups(const char *var, int first) { ssize_t ret; char temp[256]; const char *ptr; apc_vartab_t *vt; vt = vartab_lookup_name(var); if (!vt) { upsdebugx(1, "query_ups: unknown variable %s", var); return 0; } /* * not first run and already known to not be supported ? */ if (!first && !(vt->flags & APC_PRESENT)) return 0; /* empty the input buffer (while allowing the alert handler to run) */ ret = ser_get_line_alert(upsfd, temp, sizeof(temp), ENDCHAR, POLL_IGNORE, POLL_ALERT, alert_handler, 0, 0); ret = ser_send_char(upsfd, vt->cmd); if (ret != 1) { upslog_with_errno(LOG_ERR, "query_ups: ser_send_char failed"); return 0; } ret = ser_get_line_alert(upsfd, temp, sizeof(temp), ENDCHAR, POLL_IGNORE, POLL_ALERT, alert_handler, SER_WAIT_SEC, SER_WAIT_USEC); if ((ret < 1) && (first == 0)) { ser_comm_fail("%s", ret ? strerror(errno) : "timeout"); return 0; } ser_comm_good(); if ((ret < 1) || (!strcmp(temp, "NA"))) /* not supported */ return 0; vt->flags |= APC_PRESENT; ptr = convert_data(vt, temp); dstate_setinfo(vt->name, "%s", ptr); return 1; /* success */ } static void do_capabilities(void) { const char *ptr, *entptr; char upsloc, temp[512], cmd, loc, etmp[16], *endtemp; int matrix, valid; size_t i, nument, entlen; ssize_t ret; apc_vartab_t *vt; upsdebugx(1, "APC - About to get capabilities string"); /* If we can do caps, then we need the Firmware revision which has the locale descriptor as the last character (ugh) */ ptr = dstate_getinfo("ups.firmware"); if (ptr) upsloc = ptr[strlen(ptr) - 1]; else upsloc = 0; /* get capability string */ ret = ser_send_char(upsfd, APC_CAPABILITY); /* ^Z */ if (ret != 1) { upslog_with_errno(LOG_ERR, "do_capabilities: ser_send_char failed"); return; } /* note different IGN set since ^Z returns things like # */ ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, MINIGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); if ((ret < 1) || (!strcmp(temp, "NA"))) { /* Early Smart-UPS, not as smart as later ones */ /* This should never happen since we only call this if the REQ_CAPABILITIES command is supported */ upslogx(LOG_ERR, "ERROR: APC cannot do capabilities but said it could!"); return; } /* recv always puts a \0 at the end, so this is safe */ /* however it assumes a zero byte cannot be embedded */ endtemp = &temp[0] + strlen(temp); if (temp[0] != '#') { upsdebugx(1, "Unrecognized capability start char %c", temp[0]); upsdebugx(1, "Please report this error [%s]", temp); upslogx(LOG_ERR, "ERROR: unknown capability start char %c!", temp[0]); return; } if (temp[1] == '#') { /* Matrix-UPS */ matrix = 1; ptr = &temp[0]; } else { ptr = &temp[1]; matrix = 0; } /* command char, location, # of entries, entry length */ while (ptr[0] != '\0') { if (matrix) ptr += 2; /* jump over repeating ## */ /* check for idiocy */ if (ptr >= endtemp) { /* if we expected this, just ignore it */ if (quirk_capability_overflow) return; fatalx(EXIT_FAILURE, "Capability string has overflowed\n" "Please report this error with device details\n" "ERROR: capability overflow!" ); } entptr = &ptr[4]; cmd = ptr[0]; loc = ptr[1]; if (ptr[2] < 48 || ptr[3] < 48) { upsdebugx(3, "%s: SKIP: nument (%d) or entlen (%d) " "out of range for cmd %d at loc %d", __func__, (ptr[2] - 48), (ptr[3] - 48), cmd, loc); /* just ignore it as we did for ages see e.g. v2.7.4 * (note the next loop cycle was and still would be * no-op anyway, if "nument <= 0"). */ nument = 0; entlen = 0; /* NOT a full skip: Gotta handle "vt" to act like before */ /*ptr = entptr;*/ /*continue;*/ } else { nument = (size_t)ptr[2] - 48; entlen = (size_t)ptr[3] - 48; } vt = vartab_lookup_char(cmd); valid = vt && ((loc == upsloc) || (loc == '4')); /* mark this as writable */ if (valid) { upsdebugx(1, "Supported capability: %02x (%c) - %s", cmd, loc, vt->name); dstate_setflags(vt->name, ST_FLAG_RW); /* make sure setvar knows what this is */ vt->flags |= APC_RW | APC_ENUM; } for (i = 0; i < nument; i++) { if (valid) { snprintf(etmp, entlen + 1, "%s", entptr); dstate_addenum(vt->name, "%s", convert_data(vt, etmp)); } entptr += entlen; } ptr = entptr; } } static int update_status(void) { ssize_t ret; char buf[SMALLBUF]; upsdebugx(4, "update_status"); ser_flush_in(upsfd, IGNCHARS, nut_debug_level); ret = ser_send_char(upsfd, APC_STATUS); if (ret != 1) { upslog_with_errno(LOG_ERR, "update_status: ser_send_char failed"); dstate_datastale(); return 0; } ret = read_buf(buf, sizeof(buf)); if ((ret < 1) || (!strcmp(buf, "NA"))) { dstate_datastale(); return 0; } ups_status = strtol(buf, 0, 16) & 0xff; ups_status_set(); dstate_dataok(); return 1; } static void oldapcsetup(void) { ssize_t ret = 0; /* really old models ignore REQ_MODEL, so find them first */ ret = query_ups("ups.model", 1); if (ret != 1) { /* force the model name */ dstate_setinfo("ups.model", "Smart-UPS"); } /* see if this might be an old Matrix-UPS instead */ if (query_ups("output.current", 1)) dstate_setinfo("ups.model", "Matrix-UPS"); query_ups("ups.serial", 1); query_ups("input.voltage", 1); /* This one may fail... no problem */ update_status(); /* If we have come down this path then we dont do capabilities and other shiny features */ } static void protocol_verify(unsigned char cmd) { int i, found; /* see if it's a variable */ for (i = 0; apc_vartab[i].name != NULL; i++) { /* 1:1 here, so the first match is the only match */ if (apc_vartab[i].cmd == cmd) { upsdebugx(3, "UPS supports variable [%s]", apc_vartab[i].name); /* load initial data */ apc_vartab[i].flags |= APC_PRESENT; poll_data(&apc_vartab[i]); /* handle special data for our two strings */ if (apc_vartab[i].flags & APC_STRING) { dstate_setflags(apc_vartab[i].name, ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux(apc_vartab[i].name, APC_STRLEN); apc_vartab[i].flags |= APC_RW; } return; } } /* check the command list */ /* some cmdchars map onto multiple commands (start and stop) */ found = 0; for (i = 0; apc_cmdtab[i].name != NULL; i++) { if (apc_cmdtab[i].cmd == cmd) { upsdebugx(2, "UPS supports command [%s]", apc_cmdtab[i].name); dstate_addcmd(apc_cmdtab[i].name); apc_cmdtab[i].flags |= APC_PRESENT; found = 1; } } if (found) return; if (isprint((size_t)cmd)) upsdebugx(1, "protocol_verify: 0x%02x [%c] unrecognized", cmd, cmd); else upsdebugx(1, "protocol_verify: 0x%02x unrecognized", cmd); } /* some hardware is a special case - hotwire the list of cmdchars */ static int firmware_table_lookup(void) { ssize_t ret; unsigned int i, j; char buf[SMALLBUF]; upsdebugx(1, "Attempting firmware lookup using command 'V'"); ret = ser_send_char(upsfd, 'V'); if (ret != 1) { upslog_with_errno(LOG_ERR, "firmware_table_lookup: ser_send_char failed"); return 0; } ret = ser_get_line(upsfd, buf, sizeof(buf), ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); /* * Some UPSes support both 'V' and 'b'. As 'b' doesn't always return * firmware version, we attempt that only if 'V' doesn't work. */ if ((ret < 1) || (!strcmp(buf, "NA"))) { upsdebugx(1, "Attempting firmware lookup using command 'b'"); ret = ser_send_char(upsfd, 'b'); if (ret != 1) { upslog_with_errno(LOG_ERR, "firmware_table_lookup: ser_send_char failed"); return 0; } ret = ser_get_line(upsfd, buf, sizeof(buf), ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 1) { upslog_with_errno(LOG_ERR, "firmware_table_lookup: ser_get_line failed"); return 0; } } upsdebugx(2, "Firmware: [%s]", buf); /* this will be reworked if we get a lot of these things */ if (!strcmp(buf, "451.2.I")) { quirk_capability_overflow = 1; return 0; } for (i = 0; compat_tab[i].firmware != NULL; i++) { if (!strcmp(compat_tab[i].firmware, buf)) { upsdebugx(2, "Matched - cmdchars: %s", compat_tab[i].cmdchars); if (strspn(compat_tab[i].firmware, "05")) { dstate_setinfo("ups.model", "Matrix-UPS"); } else { dstate_setinfo("ups.model", "Smart-UPS"); } /* matched - run the cmdchars from the table */ for (j = 0; j < strlen(compat_tab[i].cmdchars); j++) protocol_verify((const unsigned char)(compat_tab[i].cmdchars[j])); return 1; /* matched */ } } upsdebugx(2, "Not found in table - trying normal method"); return 0; } static void getbaseinfo(void) { unsigned int i; ssize_t ret = 0; char *alrts, temp[512]; unsigned char *cmds; /* * try firmware lookup first; we could start with 'a', but older models * sometimes return other things than a command set */ if (firmware_table_lookup() == 1) return; upsdebugx(1, "APC - Attempting to find command set"); /* Initially we ask the UPS what commands it takes If this fails we are going to need an alternate strategy - we can deal with that if it happens */ ret = ser_send_char(upsfd, APC_CMDSET); if (ret != 1) { upslog_with_errno(LOG_ERR, "getbaseinfo: ser_send_char failed"); return; } ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); if ((ret < 1) || (!strcmp(temp, "NA"))) { /* We have an old dumb UPS - go to specific code for old stuff */ oldapcsetup(); return; } upsdebugx(1, "APC - Parsing out command set"); /* We have the version.alert.cmdchars string NB the alert chars are normally in IGNCHARS so will have been pretty much edited out. You will need to change the ser_get_line above if you want to check those out too.... */ alrts = strchr(temp, '.'); if (alrts == NULL) { fatalx(EXIT_FAILURE, "Unable to split APC version string"); } *alrts++ = 0; cmds = (unsigned char*)strchr(alrts, '.'); if (cmds == NULL) { fatalx(EXIT_FAILURE, "Unable to find APC command string"); } *cmds++ = 0; for (i = 0; i < strlen((char *)cmds); i++) protocol_verify(cmds[i]); /* if capabilities are supported, add them here */ if (strchr((char *)cmds, APC_CAPABILITY)) do_capabilities(); upsdebugx(1, "APC - UPS capabilities determined"); } /* check for calibration status and either start or stop */ static int do_cal(int start) { char temp[256]; long tval; ssize_t ret; ret = ser_send_char(upsfd, APC_STATUS); if (ret != 1) { upslog_with_errno(LOG_ERR, "do_cal: ser_send_char failed"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } ret = read_buf(temp, sizeof(temp)); /* if we can't check the current calibration status, bail out */ if ((ret < 1) || (!strcmp(temp, "NA"))) return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ tval = strtol(temp, 0, 16); if (tval & APC_STAT_CAL) { /* calibration currently happening */ if (start == 1) { /* requested start while calibration still running */ upslogx(LOG_INFO, "Runtime calibration already in progress"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } /* stop requested */ upslogx(LOG_INFO, "Stopping runtime calibration"); ret = ser_send_char(upsfd, APC_CMD_CALTOGGLE); if (ret != 1) { upslog_with_errno(LOG_ERR, "do_cal: ser_send_char failed"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } ret = read_buf(temp, sizeof(temp)); if ((ret < 1) || (!strcmp(temp, "NA")) || (!strcmp(temp, "NO"))) { upslogx(LOG_WARNING, "Stop calibration failed: %s", temp); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } return STAT_INSTCMD_HANDLED; /* FUTURE: success */ } /* calibration not happening */ if (start == 0) { /* stop requested */ upslogx(LOG_INFO, "Runtime calibration not occurring"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } upslogx(LOG_INFO, "Starting runtime calibration"); ret = ser_send_char(upsfd, APC_CMD_CALTOGGLE); if (ret != 1) { upslog_with_errno(LOG_ERR, "do_cal: ser_send_char failed"); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } ret = read_buf(temp, sizeof(temp)); if ((ret < 1) || (!strcmp(temp, "NA")) || (!strcmp(temp, "NO"))) { upslogx(LOG_WARNING, "Start calibration failed: %s", temp); return STAT_INSTCMD_HANDLED; /* FUTURE: failure */ } return STAT_INSTCMD_HANDLED; /* FUTURE: success */ } /* get the UPS talking to us in smart mode */ static int smartmode(void) { ssize_t ret; int tries; char temp[256]; for (tries = 0; tries < 5; tries++) { ret = ser_send_char(upsfd, APC_GOSMART); if (ret != 1) { upslog_with_errno(LOG_ERR, "smartmode: ser_send_char failed"); return 0; } ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); if (ret > 0) if (!strcmp(temp, "SM")) return 1; /* success */ sleep(1); /* wait before trying again */ /* it failed, so try to bail out of menus on newer units */ ret = ser_send_char(upsfd, 27); /* ESC */ if (ret != 1) { upslog_with_errno(LOG_ERR, "smartmode: ser_send_char failed"); return 0; } /* eat the response (might be NA, might be something else) */ ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); } return 0; /* failure */ } /* * all shutdown commands should respond with 'OK' or '*' */ static long sdok(void) { char temp[16]; ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); upsdebugx(4, "sdok: got \"%s\"", temp); if (!strcmp(temp, "*") || !strcmp(temp, "OK")) { upsdebugx(4, "Last issued shutdown command succeeded"); return 1; } upsdebugx(1, "Last issued shutdown command failed"); return 0; } /* soft hibernate: S - working only when OB, otherwise ignored */ static long sdcmd_S(long dummy) { NUT_UNUSED_VARIABLE(dummy); ser_flush_in(upsfd, IGNCHARS, nut_debug_level); upsdebugx(1, "Issuing soft hibernate"); ser_send_char(upsfd, APC_CMD_SOFTDOWN); return sdok(); } /* soft hibernate, hack version for CS 350 */ static long sdcmd_CS(long tval) { upsdebugx(1, "Using CS 350 'force OB' shutdown method"); if (tval & APC_STAT_OL) { upsdebugx(1, "On-line - forcing OB temporarily"); ser_send_char(upsfd, 'U'); usleep(UPSDELAY); } return sdcmd_S(tval); } /* * hard hibernate: @nnn / @nn * note: works differently for older and new models, see help function for * detailed info */ static long sdcmd_ATn(long cnt) { long n = 0; long mmax, ret; const char *strval; char timer[4]; mmax = cnt == 2 ? 99 : 999; if ((strval = getval("wugrace"))) { errno = 0; n = strtol(strval, NULL, 10); if (errno || n < 0 || n > mmax) n = 0; } if (cnt > INT_MAX || cnt < 0) { fatalx(EXIT_FAILURE, "Error: %s: cnt (%ld) is out of range", __func__, cnt); } snprintf(timer, sizeof(timer), "%.*ld", (int)cnt, n); ser_flush_in(upsfd, IGNCHARS, nut_debug_level); upsdebugx(1, "Issuing hard hibernate with %ld minutes additional wakeup delay", n*6); ser_send_char(upsfd, APC_CMD_GRACEDOWN); usleep(CMDLONGDELAY); ser_send_pace(upsfd, UPSDELAY, "%s", timer); ret = sdok(); if (ret || cnt == 3) return ret; /* * "tricky" part - we tried @nn variation and it (unsurprisingly) * failed; we have to abort the sequence with something bogus to have * the clean state; newer upses will respond with 'NO', older will be * silent (YMMV); */ ser_send_char(upsfd, APC_CMD_GRACEDOWN); usleep(UPSDELAY); ser_flush_in(upsfd, IGNCHARS, nut_debug_level); return 0; } /* shutdown: K - delayed poweroff */ static long sdcmd_K(long dummy) { NUT_UNUSED_VARIABLE(dummy); ser_flush_in(upsfd, IGNCHARS, nut_debug_level); upsdebugx(1, "Issuing delayed poweroff"); ser_send_char(upsfd, APC_CMD_SHUTDOWN); usleep(CMDLONGDELAY); ser_send_char(upsfd, APC_CMD_SHUTDOWN); return sdok(); } /* shutdown: Z - immediate poweroff */ static long sdcmd_Z(long dummy) { NUT_UNUSED_VARIABLE(dummy); ser_flush_in(upsfd, IGNCHARS, nut_debug_level); upsdebugx(1, "Issuing immediate poweroff"); ser_send_char(upsfd, APC_CMD_OFF); usleep(CMDLONGDELAY); ser_send_char(upsfd, APC_CMD_OFF); return sdok(); } static long (*sdlist[])(long) = { sdcmd_S, sdcmd_ATn, /* for @nnn version */ sdcmd_K, sdcmd_Z, sdcmd_CS, sdcmd_ATn, /* for @nn version */ }; #define SDIDX_S 0 #define SDIDX_AT3N 1 #define SDIDX_K 2 #define SDIDX_Z 3 #define SDIDX_CS 4 #define SDIDX_AT2N 5 #define SDCNT 6 static void upsdrv_shutdown_simple(long status) { long sdtype = 0; char *strval; if ((strval = getval("sdtype"))) { errno = 0; sdtype = strtol(strval, NULL, 10); if (errno || sdtype < 0 || sdtype > 6) sdtype = 0; } switch (sdtype) { case 6: /* hard hibernate */ sdcmd_ATn(3); break; case 5: /* "hack nn" hard hibernate */ sdcmd_ATn(2); break; case 4: /* special hack for CS 350 and similar models */ sdcmd_CS(status); break; case 3: /* delayed poweroff */ sdcmd_K(0); break; case 2: /* instant poweroff */ sdcmd_Z(0); break; case 1: /* * Send a combined set of shutdown commands which can work * better if the UPS gets power during shutdown process * Specifically it sends both the soft shutdown 'S' and the * hard hibernate '@nnn' commands */ upsdebugx(1, "UPS - currently %s - sending soft/hard hibernate commands", (status & APC_STAT_OL) ? "on-line" : "on battery"); /* S works only when OB */ if ((status & APC_STAT_OB) && sdcmd_S(0)) break; sdcmd_ATn(3); break; default: /* * Send @nnn or S, depending on OB / OL status */ if (status & APC_STAT_OL) /* on line */ sdcmd_ATn(3); else sdcmd_S(0); } } static void upsdrv_shutdown_advanced(long status) { const char *strval; const char deforder[] = {48 + SDIDX_S, 48 + SDIDX_AT3N, 48 + SDIDX_K, 48 + SDIDX_Z, 0}; size_t i; long n; strval = getval("advorder"); /* sanitize advorder */ if (!strval || !strlen(strval) || strlen(strval) > SDCNT) strval = deforder; for (i = 0; i < strlen(strval); i++) { if (strval[i] - 48 < 0 || strval[i] - 48 >= SDCNT) { strval = deforder; break; } } /* * try each method in the list with a little bit of handling in certain * cases */ for (i = 0; i < strlen(strval); i++) { switch (strval[i] - 48) { case SDIDX_CS: n = status; break; case SDIDX_AT3N: n = 3; break; case SDIDX_AT2N: default: n = 2; } if (sdlist[strval[i] - 48](n)) break; /* finish if command succeeded */ } } /* power down the attached load immediately */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ char temp[32]; ssize_t ret; long status; if (!smartmode()) upsdebugx(1, "SM detection failed. Trying a shutdown command anyway"); /* check the line status */ ret = ser_send_char(upsfd, APC_STATUS); if (ret == 1) { ret = ser_get_line(upsfd, temp, sizeof(temp), ENDCHAR, IGNCHARS, SER_WAIT_SEC, SER_WAIT_USEC); if (ret < 1) { upsdebugx(1, "Status read failed ! Assuming on battery state"); status = APC_STAT_LB | APC_STAT_OB; } else { status = strtol(temp, 0, 16); } } else { upsdebugx(1, "Status request failed; assuming on battery state"); status = APC_STAT_LB | APC_STAT_OB; } if (testvar("advorder") && strcasecmp(getval("advorder"), "no")) upsdrv_shutdown_advanced(status); else upsdrv_shutdown_simple(status); } /* 940-0095B support: set DTR, lower RTS */ static void init_serial_0095B(void) { ser_set_dtr(upsfd, 1); ser_set_rts(upsfd, 0); } static void update_info_normal(void) { size_t i; upsdebugx(3, "update_info_normal: starting"); for (i = 0; apc_vartab[i].name != NULL; i++) { if ((apc_vartab[i].flags & APC_POLL) == 0) continue; if (!poll_data(&apc_vartab[i])) { upsdebugx(3, "update_info_normal: poll_data (%s) failed - " "aborting scan", apc_vartab[i].name); return; } } upsdebugx(3, "update_info_normal: done"); } static void update_info_all(void) { size_t i; upsdebugx(3, "update_info_all: starting"); for (i = 0; apc_vartab[i].name != NULL; i++) { if (!poll_data(&apc_vartab[i])) { upsdebugx(3, "update_info_all: poll_data (%s) failed - " "aborting scan", apc_vartab[i].name); return; } } upsdebugx(3, "update_info_all: done"); } static int setvar_enum(apc_vartab_t *vt, const char *val) { int i; ssize_t ret; char orig[256], temp[256]; const char *ptr; ser_flush_in(upsfd, IGNCHARS, nut_debug_level); ret = ser_send_char(upsfd, vt->cmd); if (ret != 1) { upslog_with_errno(LOG_ERR, "setvar_enum: ser_send_char failed"); return STAT_SET_HANDLED; /* FUTURE: failed */ } ret = read_buf(orig, sizeof(orig)); if ((ret < 1) || (!strcmp(orig, "NA"))) return STAT_SET_HANDLED; /* FUTURE: failed */ ptr = convert_data(vt, orig); /* suppress redundant changes - easier on the eeprom */ if (!strcmp(ptr, val)) { upslogx(LOG_INFO, "Ignoring enum SET %s='%s' (unchanged value)", vt->name, val); return STAT_SET_HANDLED; /* FUTURE: no change */ } for (i = 0; i < 6; i++) { ret = ser_send_char(upsfd, APC_NEXTVAL); if (ret != 1) { upslog_with_errno(LOG_ERR, "setvar_enum: ser_send_char failed"); return STAT_SET_HANDLED; /* FUTURE: failed */ } /* this should return either OK (if rotated) or NO (if not) */ ret = read_buf(temp, sizeof(temp)); if ((ret < 1) || (!strcmp(temp, "NA"))) return STAT_SET_HANDLED; /* FUTURE: failed */ /* sanity checks */ if (!strcmp(temp, "NO")) return STAT_SET_HANDLED; /* FUTURE: failed */ if (strcmp(temp, "OK") != 0) return STAT_SET_HANDLED; /* FUTURE: failed */ /* see what it rotated onto */ ret = ser_send_char(upsfd, vt->cmd); if (ret != 1) { upslog_with_errno(LOG_ERR, "setvar_enum: ser_send_char failed"); return STAT_SET_HANDLED; /* FUTURE: failed */ } ret = read_buf(temp, sizeof(temp)); if ((ret < 1) || (!strcmp(temp, "NA"))) return STAT_SET_HANDLED; /* FUTURE: failed */ ptr = convert_data(vt, temp); upsdebugx(1, "Rotate value: got [%s], want [%s]", ptr, val); if (!strcmp(ptr, val)) { /* got it */ upslogx(LOG_INFO, "SET %s='%s'", vt->name, val); /* refresh data from the hardware */ query_ups(vt->name, 0); return STAT_SET_HANDLED; /* FUTURE: success */ } /* check for wraparound */ if (!strcmp(ptr, orig)) { upslogx(LOG_ERR, "setvar: variable %s wrapped", vt->name); return STAT_SET_HANDLED; /* FUTURE: failed */ } } upslogx(LOG_ERR, "setvar: gave up after 6 tries for %s", vt->name); /* refresh data from the hardware */ query_ups(vt->name, 0); return STAT_SET_HANDLED; } static int setvar_string(apc_vartab_t *vt, const char *val) { size_t i; ssize_t ret; char temp[256]; ser_flush_in(upsfd, IGNCHARS, nut_debug_level); ret = ser_send_char(upsfd, vt->cmd); if (ret != 1) { upslog_with_errno(LOG_ERR, "setvar_string: ser_send_char failed"); return STAT_SET_HANDLED; /* FUTURE: failed */ } ret = read_buf(temp, sizeof(temp)); if ((ret < 1) || (!strcmp(temp, "NA"))) return STAT_SET_HANDLED; /* FUTURE: failed */ /* suppress redundant changes - easier on the eeprom */ if (!strcmp(temp, val)) { upslogx(LOG_INFO, "Ignoring string SET %s='%s' (unchanged value)", vt->name, val); return STAT_SET_HANDLED; /* FUTURE: no change */ } ret = ser_send_char(upsfd, APC_NEXTVAL); if (ret != 1) { upslog_with_errno(LOG_ERR, "setvar_string: ser_send_char failed"); return STAT_SET_HANDLED; /* FUTURE: failed */ } usleep(UPSDELAY); for (i = 0; i < strlen(val); i++) { ret = ser_send_char(upsfd, (const unsigned char)(val[i])); if (ret != 1) { upslog_with_errno(LOG_ERR, "setvar_string: ser_send_char failed"); return STAT_SET_HANDLED; /* FUTURE: failed */ } usleep(UPSDELAY); } /* pad to 8 chars with CRs */ for (i = strlen(val); i < APC_STRLEN; i++) { ret = ser_send_char(upsfd, 13); if (ret != 1) { upslog_with_errno(LOG_ERR, "setvar_string: ser_send_char failed"); return STAT_SET_HANDLED; /* FUTURE: failed */ } usleep(UPSDELAY); } ret = read_buf(temp, sizeof(temp)); if (ret < 1) { upslogx(LOG_ERR, "setvar_string: short final read"); return STAT_SET_HANDLED; /* FUTURE: failed */ } if (!strcmp(temp, "NO")) { upslogx(LOG_ERR, "setvar_string: got NO at final read"); return STAT_SET_HANDLED; /* FUTURE: failed */ } /* refresh data from the hardware */ query_ups(vt->name, 0); upslogx(LOG_INFO, "SET %s='%s'", vt->name, val); return STAT_SET_HANDLED; /* FUTURE: failed */ } static int setvar(const char *varname, const char *val) { apc_vartab_t *vt; upsdebug_SET_STARTING(varname, val); vt = vartab_lookup_name(varname); if (!vt) return STAT_SET_UNKNOWN; if ((vt->flags & APC_RW) == 0) { upslogx(LOG_SET_INVALID, "setvar: [%s] is not writable", varname); return STAT_SET_INVALID; } if (vt->flags & APC_ENUM) return setvar_enum(vt, val); if (vt->flags & APC_STRING) return setvar_string(vt, val); upslogx(LOG_SET_UNKNOWN, "setvar: Unknown type for [%s]", varname); return STAT_SET_UNKNOWN; } /* actually send the instcmd's char to the ups */ static int do_cmd(apc_cmdtab_t *ct) { ssize_t ret; char buf[SMALLBUF]; ser_flush_in(upsfd, IGNCHARS, nut_debug_level); ret = ser_send_char(upsfd, ct->cmd); if (ret != 1) { upslog_with_errno(LOG_INSTCMD_FAILED, "do_cmd: ser_send_char failed"); return STAT_INSTCMD_HANDLED; /* FUTURE: failed */ } /* some commands have to be sent twice with a 1.5s gap */ if (ct->flags & APC_REPEAT) { usleep(CMDLONGDELAY); ret = ser_send_char(upsfd, ct->cmd); if (ret != 1) { upslog_with_errno(LOG_INSTCMD_FAILED, "do_cmd: ser_send_char failed"); return STAT_INSTCMD_HANDLED; /* FUTURE: failed */ } } ret = read_buf(buf, sizeof(buf)); if (ret < 1) return STAT_INSTCMD_HANDLED; /* FUTURE: failed */ if (strcmp(buf, "OK") != 0) { upslogx(LOG_INSTCMD_FAILED, "Got [%s] after command [%s]", buf, ct->name); return STAT_INSTCMD_HANDLED; /* FUTURE: failed */ } upslogx(LOG_INFO, "Command: %s", ct->name); return STAT_INSTCMD_HANDLED; /* FUTURE: success */ } /* some commands must be repeated in a window to execute */ static int instcmd_chktime(apc_cmdtab_t *ct) { double elapsed; time_t now; static time_t last = 0; time(&now); elapsed = difftime(now, last); last = now; /* you have to hit this in a small window or it fails */ if ((elapsed < MINCMDTIME) || (elapsed > MAXCMDTIME)) { upsdebugx(1, "instcmd_chktime: outside window for %s (%2.0f)", ct->name, elapsed); return STAT_INSTCMD_HANDLED; /* FUTURE: again */ } return do_cmd(ct); } static int instcmd(const char *cmdname, const char *extra) { int i; apc_cmdtab_t *ct; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); ct = NULL; for (i = 0; apc_cmdtab[i].name != NULL; i++) if (!strcasecmp(apc_cmdtab[i].name, cmdname)) ct = &apc_cmdtab[i]; if (!ct) { upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } if ((ct->flags & APC_PRESENT) == 0) { upslogx(LOG_INSTCMD_UNKNOWN, "%s: command [%s] [%s] is not supported on this device", __func__, NUT_STRARG(cmdname), NUT_STRARG(extra)); return STAT_INSTCMD_UNKNOWN; } if (!strcasecmp(cmdname, "calibrate.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); return do_cal(1); } if (!strcasecmp(cmdname, "calibrate.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); return do_cal(0); } upslog_INSTCMD_POWERSTATE_CHECKED(cmdname, extra); if (ct->flags & APC_NASTY) return instcmd_chktime(ct); /* nothing special here */ return do_cmd(ct); } /* install pointers to functions for msg handlers called from msgparse */ static void setuphandlers(void) { upsh.setvar = setvar; upsh.instcmd = instcmd; } /* functions that interface with main.c */ void upsdrv_makevartable(void) { addvar(VAR_VALUE, "cable", "Specify alternate cable (940-0095B)"); addvar(VAR_VALUE, "wugrace", "Hard hibernate's wakeup grace"); addvar(VAR_VALUE, "sdtype", "Specify simple shutdown method (0-6)"); addvar(VAR_VALUE, "advorder", "Enable advanced shutdown control"); } void upsdrv_initups(void) { char *cable; upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); cable = getval("cable"); if (cable && !strcasecmp(cable, ALT_CABLE_1)) init_serial_0095B(); /* make sure we wake up if the UPS sends alert chars to us */ extrafd = upsfd; } void upsdrv_help(void) { } void upsdrv_initinfo(void) { const char *pmod, *pser; if (!smartmode()) { fatalx(EXIT_FAILURE, "Unable to detect an APC Smart protocol UPS on port %s\n" "Check the cabling, port name or model name and try again", device_path ); } /* manufacturer ID - hardcoded in this particular module */ dstate_setinfo("ups.mfr", "APC"); getbaseinfo(); if (!(pmod = dstate_getinfo("ups.model"))) pmod = "\"unknown model\""; if (!(pser = dstate_getinfo("ups.serial"))) pser = "unknown serial"; upsdebugx(1, "Detected %s [%s] on %s", pmod, pser, device_path); setuphandlers(); } void upsdrv_updateinfo(void) { static time_t last_full = 0; time_t now; /* try to wake up a dead ups once in awhile */ if ((dstate_is_stale()) && (!smartmode())) { ser_comm_fail("Communications with UPS lost - check cabling"); /* reset this so a full update runs when the UPS returns */ last_full = 0; return; } ser_comm_good(); if (!update_status()) return; time(&now); /* refresh all variables hourly */ /* does not catch measure-ups II insertion/removal */ if (difftime(now, last_full) > 3600) { last_full = now; update_info_all(); return; } update_info_normal(); } void upsdrv_cleanup(void) { /* try to bring the UPS out of smart mode */ ser_send_char(upsfd, APC_GODUMB); ser_close(upsfd, device_path); } nut-2.8.4/drivers/sms_ser.h0000644000175000017500000000664515000601404012557 00000000000000/* * sms_ser.h: defines/macros protocol for SMS Brazil UPSes * * Copyright (C) 2023 - Alex W. Baule * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Reference of the derivative work: riello driver */ #ifndef NUT_SMS_SER_H_SEEN #define NUT_SMS_SER_H_SEEN 1 #include /* bool type */ #include "nut_stdint.h" #define DEFAULT_BOOTDELAY 64 /* seconds (max 0xFF) */ #define MAXTRIES 3 typedef struct { char model[25]; /* device.model */ char version[7]; /* ups.firmware */ char voltageRange[15]; /* garbage from sms (it's a string with some strange items) */ char currentRange[7]; /* garbage from sms (it's 000) maybe with some cleanup on string input.voltage.nominal */ uint8_t voltageBattery; /* battery.voltage.nominal (DeviceData.voltageBattery / 12 = battery.packs) */ uint8_t frequency; /* output.frequency.nominal */ bool beepon; /* ups.beeper.status */ bool shutdown; /* ups.status = FSD (the shutdown has started by another via) */ bool test; /* the UPS is testing the battery, need a status ? */ bool upsok; /* ups.status or battery.status ? (Maybe RB if is False ?) */ bool boost; /* ups.status = BOOST */ bool bypass; /* ups.status = BYPASS */ bool lowbattery; /* ups.status = LB (OL + LB or OB + LB ?) */ bool onbattery; /* ups.status = OB + battery.charger.status = discharging */ float lastinputVac; /* garbage ? always 000 */ float inputVac; /* input.voltage */ float outputVac; /* output.voltage */ float outputpower; /* ups.load */ float outputHz; /* output.frequency */ float batterylevel; /* battery.charge (batterylevel < 100 ? battery.charger.status = charging if onacpower/discharging if onbattery : resting) * battery.voltage = (voltageBattery * batterylevel) / 100) */ float temperatureC; /* ups.temperature */ } SmsData; void sms_parse_features(uint8_t *rawvalues, SmsData *results); void sms_parse_information(uint8_t *rawvalues, SmsData *results); void sms_parse_results(uint8_t* rawvalues, SmsData* results); uint8_t sms_prepare_get_status(uint8_t* buffer); uint8_t sms_prepare_get_information(uint8_t* buffer); uint8_t sms_prepare_get_features(uint8_t* buffer); uint8_t sms_prepare_set_beep(uint8_t* buffer); uint8_t sms_prepare_test_battery_low(uint8_t* buffer); uint8_t sms_prepare_test_battery_nsec(uint8_t* buffer, uint16_t delay); uint8_t sms_prepare_shutdown_nsec(uint8_t* buffer, uint16_t delay); uint8_t sms_prepare_shutdown_restore(uint8_t* buffer); uint8_t sms_prepare_cancel_test(uint8_t* buffer); uint8_t sms_prepare_cancel_shutdown(uint8_t* buffer); #endif /* NUT_SMS_SER_H_SEEN */ nut-2.8.4/drivers/eaton-ats30-mib.h0000644000175000017500000000203214670526611013713 00000000000000/* eaton_ats30-mib.h - subdriver to monitor eaton_ats30 SNMP devices with NUT * * Copyright (C) 2017 Eaton * Author: Tomas Halman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef EATON_ATS30_MIB_H #define EATON_ATS30_MIB_H #include "main.h" #include "snmp-ups.h" extern mib2nut_info_t eaton_ats30; #endif /* EATON_ATS30_MIB_H */ nut-2.8.4/drivers/salicru-hid.c0000644000175000017500000004020114777753337013326 00000000000000/* salicru-hid.c - subdriver to monitor Salicru USB/HID devices with NUT * * Copyright (C) * 2003 - 2012 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * 2013 Charles Lepple * 2021 Francois Lacroix * 2022 Abel Gomez * * Note: this subdriver was initially generated as a "stub" by the * gen-usbhid-subdriver script. It must be customized. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be first */ #include "usbhid-ups.h" #include "salicru-hid.h" #include "main.h" /* for getval() */ #include "usb-common.h" #define SALICRU_HID_VERSION "Salicru HID 0.4" /* FIXME: experimental flag to be put in upsdrv_info */ /* Salicru */ #define SALICRU_VENDORID 0x2e66 /* USB IDs device table */ static usb_device_id_t salicru_usb_device_table[] = { /* Salicru SPS 3000 ADV RT2 */ /* https://www.salicru.com/sps-3000-adv-rt2.html */ { USB_DEVICE(SALICRU_VENDORID, 0x0101), NULL }, /* TWINPRO3/TWINRT3 (SLC-1500-TWIN PRO3) per https://github.com/networkupstools/nut/issues/1142 */ /* SLC TWIN PRO2<=3KVA per https://github.com/networkupstools/nut/issues/450 */ { USB_DEVICE(SALICRU_VENDORID, 0x0201), NULL }, { USB_DEVICE(SALICRU_VENDORID, 0x0202), NULL }, { USB_DEVICE(SALICRU_VENDORID, 0x0203), NULL }, /* Salicru SPS 850 HOME per https://github.com/networkupstools/nut/pull/1199 */ /* https://www.salicru.com/sps-home.html */ { USB_DEVICE(SALICRU_VENDORID, 0x0300), NULL }, /* Salicru SPS 850 ADV T, see https://github.com/networkupstools/nut/issues/1416 */ /* https://www.salicru.com/sps-850-adv-t.html */ { USB_DEVICE(SALICRU_VENDORID, 0x0302), NULL }, /* Terminating entry */ { 0, 0, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* SALICRU usage table */ static usage_lkp_t salicru_usage_lkp[] = { { NULL, 0 } }; static usage_tables_t salicru_utab[] = { salicru_usage_lkp, hid_usage_lkp, NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ static hid_info_t salicru_hid2nut[] = { #ifdef DEBUG { "experimental.ups.powersummary.imanufacturer", 0, 0, "UPS.PowerSummary.iManufacturer", NULL, "%.0f", 0, NULL }, { "experimental.ups.powersummary.iproduct", 0, 0, "UPS.PowerSummary.CapacityMode", NULL, "%.0f", 0, NULL }, { "experimental.ups.powersummary.iserialnumber", 0, 0, "UPS.PowerSummary.iSerialNumber", NULL, "%.0f", 0, NULL }, { "experimental.ups.powersummary.capacitymode", 0, 0, "UPS.PowerSummary.CapacityMode", NULL, "%.0f", 0, NULL }, { "experimental.ups.powersummary.rechargeable", 0, 0, "UPS.PowerSummary.Rechargeable", NULL, "%.0f", 0, NULL }, { "experimental.ups.powersummary.designcapacity", 0, 0, "UPS.PowerSummary.DesignCapacity", NULL, "%.0f", 0, NULL }, { "experimental.ups.powersummary.fullchargecapacity", 0, 0, "UPS.PowerSummary.FullChargeCapacity", NULL, "%.0f", 0, NULL }, #endif /* DEBUG */ /* A few more unknown fields 0.043266 [D1] Path: UPS.ff010004.ff010024.ff0100d0, Type: Feature, ReportID: 0x19, Offset: 0, Size: 8, Value: 0.1 0.043766 [D1] Path: UPS.ff010004.ff010024.ff0100d1, Type: Feature, ReportID: 0x1a, Offset: 0, Size: 8, Value: 0 0.044308 [D1] Path: UPS.ff01001d.ff010019.ff010020, Type: Feature, ReportID: 0x25, Offset: 0, Size: 1, Value: 0 0.044762 [D1] Path: UPS.ff01001d.ff010019.ff010021, Type: Feature, ReportID: 0x2c, Offset: 0, Size: 1, Value: 0 0.044891 [D1] Path: UPS.ff01001d.ff010019.ff010021, Type: Input, ReportID: 0x2c, Offset: 0, Size: 1, Value: 0 0.045386 [D1] Path: UPS.ff01001d.ff01001a.ff010001, Type: Feature, ReportID: 0x26, Offset: 0, Size: 1, Value: 0 0.045888 [D1] Path: UPS.ff01001d.ff01001a.ff010002, Type: Feature, ReportID: 0x27, Offset: 0, Size: 8, Value: 1 0.047553 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.047659 [D1] Can't retrieve Report 28: Value too large for defined data type 0.047796 [D1] Path: UPS.ff01001d.ff01001b.ff010040, Type: Feature, ReportID: 0x28, Offset: 0, Size: 8 0.048272 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.048403 [D1] Can't retrieve Report 28: Value too large for defined data type 0.048537 [D1] Path: UPS.ff01001d.ff01001b.ff010016, Type: Input, ReportID: 0x28, Offset: 0, Size: 8 0.049017 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.049147 [D1] Can't retrieve Report 28: Value too large for defined data type 0.049280 [D1] Path: UPS.ff01001d.ff01001b.ff010018, Type: Feature, ReportID: 0x28, Offset: 8, Size: 8 0.050944 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.051124 [D1] Can't retrieve Report 28: Value too large for defined data type 0.051264 [D1] Path: UPS.ff01001d.ff01001b.ff010018, Type: Input, ReportID: 0x28, Offset: 8, Size: 8 0.052965 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.053137 [D1] Can't retrieve Report 29: Value too large for defined data type 0.053277 [D1] Path: UPS.ff01001d.ff01001b.ff010015, Type: Feature, ReportID: 0x29, Offset: 0, Size: 8 0.053804 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.053954 [D1] Can't retrieve Report 29: Value too large for defined data type 0.054091 [D1] Path: UPS.ff01001d.ff01001b.ff010015, Type: Output, ReportID: 0x29, Offset: 0, Size: 8 0.054530 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.054664 [D1] Can't retrieve Report 29: Value too large for defined data type 0.054799 [D1] Path: UPS.ff01001d.ff01001b.ff010017, Type: Feature, ReportID: 0x29, Offset: 8, Size: 8 0.055285 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.055421 [D1] Can't retrieve Report 29: Value too large for defined data type 0.055557 [D1] Path: UPS.ff01001d.ff01001b.ff010017, Type: Output, ReportID: 0x29, Offset: 8, Size: 8 0.056130 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.056273 [D1] Can't retrieve Report 2d: Value too large for defined data type 0.056409 [D1] Path: UPS.ff01001d.ff01001b.ff010010, Type: Feature, ReportID: 0x2d, Offset: 0, Size: 1 0.056927 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.057074 [D1] Can't retrieve Report 2d: Value too large for defined data type 0.057211 [D1] Path: UPS.ff01001d.ff01001b.ff01001e, Type: Feature, ReportID: 0x2d, Offset: 1, Size: 1 0.057676 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.057825 [D1] Can't retrieve Report 2d: Value too large for defined data type 0.057962 [D1] Path: UPS.ff01001d.ff01001b.ff01001f, Type: Feature, ReportID: 0x2d, Offset: 2, Size: 1 0.058416 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.058551 [D1] Can't retrieve Report 2d: Value too large for defined data type 0.058685 [D1] Path: UPS.ff01001d.ff01001b.ff010010, Type: Input, ReportID: 0x2d, Offset: 0, Size: 1 0.059156 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.059291 [D1] Can't retrieve Report 2d: Value too large for defined data type 0.059426 [D1] Path: UPS.ff01001d.ff01001b.ff01001e, Type: Input, ReportID: 0x2d, Offset: 1, Size: 1 0.059957 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.060112 [D1] Can't retrieve Report 2d: Value too large for defined data type 0.060248 [D1] Path: UPS.ff01001d.ff01001b.ff01001f, Type: Input, ReportID: 0x2d, Offset: 2, Size: 1 0.061944 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.062117 [D1] Can't retrieve Report 2a: Value too large for defined data type 0.062256 [D1] Path: UPS.ff01001d.ff01001b.ff010013, Type: Feature, ReportID: 0x2a, Offset: 0, Size: 1 0.063941 [D2] libusb_get_report: error sending control message: Value too large for defined data type 0.064104 [D1] Can't retrieve Report 2b: Value too large for defined data type 0.064242 [D1] Path: UPS.ff01001d.ff01001b.ff010014, Type: Feature, ReportID: 0x2b, Offset: 0, Size: 1 */ /* Battery page */ { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", 0, stringid_conversion }, { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", 0, NULL }, { "battery.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.runtime.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.PowerSummary.RemainingTimeLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.2f", 0, NULL }, /* UPS page */ { "ups.load", 0, 0, "UPS.Output.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.beeper.status", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "%s", 0, beeper_info }, { "ups.test.result", 0, 0, "UPS.Output.Test", NULL, "%s", 0, test_read_info }, { "ups.realpower.nominal", 0, 0, "UPS.Output.ConfigActivePower", NULL, "%.0f", 0, NULL }, /* Boolean value */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyCharged", NULL, NULL, 0, fullycharged_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.RemainingTimeLimitExpired", NULL, NULL, 0, timelimitexpired_info }, { "BOOL", 0, 0, "UPS.Output.CommunicationLost", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.Output.Boost", NULL, NULL, 0, boost_info }, { "BOOL", 0, 0, "UPS.Output.Overload", NULL, NULL, 0, overload_info }, /* Input page */ { "input.frequency", 0, 0, "UPS.Input.Frequency", NULL, "%.1f", 0, NULL }, { "input.voltage.nominal", 0, 0, "UPS.Input.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "input.voltage", 0, 0, "UPS.Input.Voltage", NULL, "%.1f", 0, NULL }, /* read-only on this model but probably R/W in other models */ /* { "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Input.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.high", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.Input.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, */ { "input.transfer.high", 0, 0, "UPS.PowerConverter.Output.HighVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.transfer.low", 0, 0, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* Output page */ { "output.frequency", 0, 0, "UPS.Output.Frequency", NULL, "%.1f", 0, NULL }, { "output.voltage", 0, 0, "UPS.Output.Voltage", NULL, "%.1f", 0, NULL }, { "output.voltage.nominal", 0, 0, "UPS.Output.ConfigVoltage", NULL, "%.0f", 0, NULL }, /* instant commands. */ /* Need testing { "test.battery.start.quick", 0, 0, "UPS.Output.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "test.battery.start.deep", 0, 0, "UPS.Output.Test", NULL, "2", HU_TYPE_CMD, NULL }, { "test.battery.stop", 0, 0, "UPS.Output.Test", NULL, "3", HU_TYPE_CMD, NULL }, { "load.off.delay", 0, 0, "UPS.Output.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.Output.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "shutdown.stop", 0, 0, "UPS.Output.DelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, { "shutdown.reboot", 0, 0, "UPS.Output.DelayBeforeReboot", NULL, "10", HU_TYPE_CMD, NULL }, { "beeper.on", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.off", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, { "beeper.enable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.mute", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, */ /* Salicru Twin Pro 2 Descriptors: Sensors */ { "ups.load", 0, 0, "UPS.PowerSummary.PercentLoad", NULL, "%.0f", 0, NULL }, { "ups.test.result", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "%s", 0, test_read_info }, { "ups.realpower.nominal", 0, 0, "UPS.Flow.[4].ConfigActivePower", NULL, "%.0f", 0, NULL }, { "ups.realpower", 0, 0, "UPS.PowerConverter.Output.ActivePower", NULL, "%.0f", 0, NULL }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Overload", NULL, NULL, 0, overload_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.OverTemperature", NULL, NULL, 0, overheat_info }, { "input.frequency", 0, 0, "UPS.PowerConverter.Input.[1].Frequency", NULL, "%.1f", 0, NULL }, { "input.voltage", 0, 0, "UPS.PowerConverter.Input.[1].Voltage", NULL, "%.1f", 0, NULL }, { "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%.1f", 0, NULL }, { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.1f", 0, NULL }, { "output.voltage.nominal", 0, 0, "UPS.PowerSummary.ConfigVoltage", NULL, "%.0f", 0, NULL }, { "ups.test.result", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "%s", 0, test_read_info }, /* Salicru Twin Pro 2 Descriptors: Instant commands */ { "test.battery.start.quick", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "1", HU_TYPE_CMD, NULL }, { "test.battery.start.deep", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "2", HU_TYPE_CMD, NULL }, { "test.battery.stop", 0, 0, "UPS.BatterySystem.Battery.Test", NULL, "3", HU_TYPE_CMD, NULL }, /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *salicru_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *salicru_format_mfr(HIDDevice_t *hd) { return hd->Vendor ? hd->Vendor : "Salicru"; } static const char *salicru_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int salicru_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(salicru_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("Salicru", hd); return 0; case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t salicru_subdriver = { SALICRU_HID_VERSION, salicru_claim, salicru_utab, salicru_hid2nut, salicru_format_model, salicru_format_mfr, salicru_format_serial, fix_report_desc, }; nut-2.8.4/drivers/metasys.c0000644000175000017500000010655415044656702012607 00000000000000/* metasys.c - driver for Meta System UPS Copyright (C) 2004 Fabio Di Niro This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Uncomment if you want to read additional Meta System UPS data */ /* #define EXTRADATA */ #include "main.h" #include "serial.h" #include "nut_float.h" #include "nut_stdint.h" #define DRIVER_NAME "Metasystem UPS driver" #define DRIVER_VERSION "0.12" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Fabio Di Niro ", DRV_STABLE, { NULL } }; /* Autorestart flag */ static int autorestart = 0; static int nominal_power = 0; /* ups commands */ #define UPS_INFO 0x00 #define UPS_OUTPUT_DATA 0x01 #define UPS_INPUT_DATA 0x02 #define UPS_STATUS 0x03 #define UPS_BATTERY_DATA 0x04 #define UPS_HISTORY_DATA 0x05 #define UPS_GET_SCHEDULING 0x06 #define UPS_EVENT_LIST 0x07 #define UPS_GET_TIMES_ON_BATTERY 0x08 #define UPS_GET_NEUTRAL_SENSE 0x09 #define UPS_SET_SCHEDULING 0x0a #define UPS_SET_NEUTRAL_SENSE 0x0b #define UPS_SET_TIMES_ON_BATTERY 0x0c #define UPS_SET_BUZZER_MUTE 0x0d #define UPS_SET_BATTERY_TEST 0x0e static int instcmd(const char *cmdname, const char *extra); /* Metasystem UPS data transfer are made with packet of the format: STX DATA_LENGTH DATA CHECKSUM where: STX is 0x02 and is the start of transmission byte DATA_LENGTH is number of data bytes + the checksum byte DATA ...... CHECKSUM is the sum modulus 256 of all DATA bytes + DATA_LENGTH The answer from the UPS have the same packet format and the first data byte is equal to the command that the ups is answering to */ static uint16_t get_word(unsigned char *buffer) { /* return an integer reading a word in the supplied buffer */ unsigned char a, b; uint16_t result; a = buffer[0]; b = buffer[1]; result = b*256 + a; return result; } static uint32_t get_long(unsigned char *buffer) { /* return a long integer reading 4 bytes in the supplied buffer */ unsigned char a, b, c, d; uint32_t result; a=buffer[0]; b=buffer[1]; c=buffer[2]; d=buffer[3]; result = (256*256*256*d) + (256*256*c) + (256*b) + a; return result; } static float get_word_float(unsigned char *buffer) { /* return a float converted after reading a word in the supplied buffer */ /* NOTE: This started as a wrapper for legacy logic that directly assigned * float_num = get_word(...) * in code below. No idea if the protocol really sends 16-bit floats. * FWIW, bcmxcp.c copied get_word() and get_long() from metasys.c but did * implement a get_float() for IEEE-754 32-bit values. */ return (float)(int16_t)get_word(buffer); } static void send_zeros(void) { /* send 100 times the value 0x00.....it seems to be used for resetting */ unsigned char buf[100]; /* the ups serial port */ memset(buf, '\0', sizeof(buf)); ser_send_buf(upsfd, buf, sizeof(buf)); return; } /* was used just for the debug process */ static void dump_buffer(unsigned char *buffer, int buf_len) { int i; for (i = 0; i < buf_len; i++) { printf("byte %d: %x\n", i, buffer[i]); } return; } /* send a read command to the UPS, it retries 5 times before give up it's a 4 byte request (STX, LENGTH, COMMAND and CHECKSUM) */ static void send_read_command(unsigned char command) { int retry; ssize_t sent; unsigned char buf[4]; retry = 0; sent = 0; while ((sent != 4) && (retry < 5)) { buf[0]=0x02; /* STX Start of Transmission */ buf[1]=0x02; /* data length(data + checksum byte) */ buf[2]=command; /* command to send */ buf[3]=buf[1] + buf[2]; /* checksum (sum modulus 256 of data bytes + length) */ if (retry == 4) send_zeros(); /* last retry is preceded by a serial reset...*/ sent = ser_send_buf(upsfd, buf, 4); retry += 1; } } /* send a write command to the UPS, the write command and the value to be written are passed with a char* buffer it retries 5 times before give up */ static void send_write_command(unsigned char *command, size_t command_length) { int retry, checksum; ssize_t sent; size_t i; unsigned char raw_buf[255]; /* prepares the raw data */ raw_buf[0] = 0x02; /* STX byte */ raw_buf[1] = (unsigned char)(command_length + 1); /* data length + checksum */ memcpy(raw_buf+2, command, command_length); command_length += 2; /* calculate checksum */ checksum = 0; for (i = 1; i < command_length; i++) checksum += raw_buf[i]; checksum = checksum % 256; raw_buf[command_length] = (unsigned char)checksum; command_length +=1; assert (command_length < INT_MAX); retry = 0; sent = 0; while ((sent != (int)(command_length)) && (retry < 5)) { if (retry == 4) send_zeros(); /* last retry is preceded by a serial reset... */ sent = ser_send_buf(upsfd, raw_buf, (command_length)); if (sent < 0) ser_comm_fail("Error sending command %d\n", raw_buf[2]); if (sent != (int)(command_length)) printf("Error sending command %d\n", raw_buf[2]); retry += 1; } } /* get the answer of a command from the ups */ static int get_answer(unsigned char *data) { unsigned char my_buf[255]; /* packet has a maximum length of 256 bytes */ unsigned char packet_length, checksum, i; ssize_t res; /* Read STX byte */ res = ser_get_char(upsfd, my_buf, 1, 0); if (res < 1) { ser_comm_fail("Receive error (STX): %" PRIiSIZE "!!!\n", res); return -1; } if (my_buf[0] != 0x02) { ser_comm_fail("Receive error (STX): packet not on start!!\n"); return -1; } /* Read data length byte */ res = ser_get_char(upsfd, my_buf, 1, 0); if (res < 1) { ser_comm_fail("Receive error (length): %" PRIiSIZE "!!!\n", res); return -1; } packet_length = my_buf[0]; if (packet_length < 2) { ser_comm_fail("Receive error (length): packet length %d!!!\n", packet_length); return -1; } /* Try to read all the remainig bytes (packet_length) */ res = ser_get_buf_len(upsfd, my_buf, packet_length, 1, 0); if (res != packet_length) { ser_comm_fail("Receive error (data): got %" PRIiSIZE " bytes instead of %d!!!\n", res, packet_length); return -1; } /* now we have the whole answer from the ups, we can checksum it checksum byte is equal to the sum modulus 256 of all the data bytes + packet_length (no STX no checksum byte itself) */ checksum = packet_length; for (i = 0; i < (packet_length - 1); i++) checksum += my_buf[i]; checksum = checksum % 256; if (my_buf[packet_length-1] != checksum) { ser_comm_fail("checksum error! got %x instead of %x, received %d bytes \n", my_buf[packet_length - 1], checksum, packet_length); dump_buffer(my_buf, packet_length); return -1; } packet_length-=1; /* get rid of the checksum byte */ memcpy(data, my_buf, packet_length); return packet_length; } /* send a read command and try get the answer, if something fails, it retries (5 times max) if it is on the 4th or 5th retry, it will flush the serial before sending commands it returns the length of the received answer or -1 in case of failure */ static int command_read_sequence(unsigned char command, unsigned char *data) { int bytes_read = 0; int retry = 0; while ((bytes_read < 1) && (retry < 5)) { send_read_command(command); bytes_read = get_answer(data); if (retry > 2) ser_flush_in(upsfd, "", 0); retry += 1; } if ((data[0] != command) || (retry == 5)) { ser_comm_fail("Error executing command %d\n", command); dstate_datastale(); return -1; } ser_comm_good(); return bytes_read; } /* send a write command and try get the answer, if something fails, it retries (5 times max) if it is on the 4th or 5th retry, it will flush the serial before sending commands it returns the length of the received answer or -1 in case of failure */ static int command_write_sequence(unsigned char *command, size_t command_length, unsigned char *answer) { int bytes_read = 0; int retry = 0; while ((bytes_read < 1) && (retry < 5)) { send_write_command(command, command_length); bytes_read = get_answer(answer); if (retry > 2) ser_flush_in(upsfd, "", 0); retry += 1; } if ((answer[0] != command[0]) || (retry == 5)) { ser_comm_fail("Error executing command N.%d\n", command[0]); dstate_datastale(); return -1; } ser_comm_good(); return bytes_read; } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic push #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtype-limits" #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif void upsdrv_initinfo(void) { unsigned char my_answer[255]; char serial[13]; int res, i; /* Initial setup of variables */ #ifdef EXTRADATA dstate_setinfo("output.power", "%d", -1); dstate_setflags("output.power", ST_FLAG_RW); #endif dstate_setinfo("output.voltage", "%d", -1); dstate_setflags("output.voltage", ST_FLAG_RW); dstate_setinfo("output.current", "%d", -1); dstate_setflags("output.current", ST_FLAG_RW); #ifdef EXTRADATA dstate_setinfo("output.current.peak", "%2.2f", -1); dstate_setflags("output.current.peak", ST_FLAG_RW); dstate_setinfo("input.power", "%d", -1); dstate_setflags("input.power", ST_FLAG_RW); #endif dstate_setinfo("input.voltage", "%d", -1); dstate_setflags("input.voltage", ST_FLAG_RW); #ifdef EXTRADATA dstate_setinfo("input.current", "%2.2f", -1); dstate_setflags("input.current", ST_FLAG_RW); dstate_setinfo("input.current.peak", "%2.2f", -1); dstate_setflags("input.current.peak", ST_FLAG_RW); #endif dstate_setinfo("battery.voltage", "%d", -1); dstate_setflags("battery.voltage", ST_FLAG_RW); #ifdef EXTRADATA dstate_setinfo("battery.voltage.low", "%2.2f", -1); dstate_setflags("battery.voltage.low", ST_FLAG_RW); dstate_setinfo("battery.voltage.exhaust", "%2.2f", -1); dstate_setflags("battery.voltage.exhaust", ST_FLAG_RW); dstate_setinfo("ups.total.runtime", "retrieving..."); dstate_setflags("ups.total.runtime", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("ups.total.runtime", 20); dstate_setinfo("ups.inverter.runtime", "retrieving..."); dstate_setflags("ups.inverter.runtime", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("ups.inverter.runtime", 20); dstate_setinfo("ups.inverter.interventions", "%d", -1); dstate_setflags("ups.inverter.interventions", ST_FLAG_RW); dstate_setinfo("battery.full.discharges", "%d", -1); dstate_setflags("battery.full.discharges", ST_FLAG_RW); dstate_setinfo("ups.bypass.interventions", "%d", -1); dstate_setflags("ups.bypass.interventions", ST_FLAG_RW); dstate_setinfo("ups.overheatings", "%d", -1); dstate_setflags("ups.overheatings", ST_FLAG_RW); #endif dstate_setinfo("ups.load", "%d", -1); dstate_setflags("ups.load", ST_FLAG_RW); dstate_setinfo("ups.delay.shutdown", "%d", -1); dstate_setflags("ups.delay.shutdown", ST_FLAG_RW); dstate_setinfo("ups.delay.start", "%d", -1); dstate_setflags("ups.delay.start", ST_FLAG_RW); dstate_setinfo("ups.temperature", "%d", -1); dstate_setflags("ups.temperature", ST_FLAG_RW); dstate_setinfo("ups.test.result", "not yet done..."); dstate_setflags("ups.test.result", ST_FLAG_STRING | ST_FLAG_RW); dstate_setaux("ups.test.result", 20); /* UPS INFO READ */ res = command_read_sequence(UPS_INFO, my_answer); if (res < 0) fatal_with_errno(EXIT_FAILURE, "Could not communicate with the ups"); /* the manufacturer is hard coded into the driver, the model type is in the second byte of the answer, the third byte identifies the model version */ dstate_setinfo("ups.mfr", "Meta System"); i = my_answer[1] * 10 + my_answer[2]; switch (i) { case 11: dstate_setinfo("ups.model", "%s", "HF Line (1 board)"); nominal_power = 630; break; case 12: dstate_setinfo("ups.model", "%s", "HF Line (2 boards)"); nominal_power = 1260; break; case 13: dstate_setinfo("ups.model", "%s", "HF Line (3 boards)"); nominal_power = 1890; break; case 14: dstate_setinfo("ups.model", "%s", "HF Line (4 boards)"); nominal_power = 2520; break; case 21: dstate_setinfo("ups.model", "%s", "ECO Network 750/1000"); nominal_power = 500; break; case 22: dstate_setinfo("ups.model", "%s", "ECO Network 1050/1500"); nominal_power = 700; break; case 23: dstate_setinfo("ups.model", "%s", "ECO Network 1500/2000"); nominal_power = 1000; break; case 24: dstate_setinfo("ups.model", "%s", "ECO Network 1800/2500"); nominal_power = 1200; break; case 25: dstate_setinfo("ups.model", "%s", "ECO Network 2100/3000"); nominal_power = 1400; break; case 31: dstate_setinfo("ups.model", "%s", "ECO 308"); nominal_power = 500; break; case 32: dstate_setinfo("ups.model", "%s", "ECO 311"); nominal_power = 700; break; case 44: dstate_setinfo("ups.model", "%s", "HF Line (4 boards)/2"); nominal_power = 2520; break; case 45: dstate_setinfo("ups.model", "%s", "HF Line (5 boards)/2"); nominal_power = 3150; break; case 46: dstate_setinfo("ups.model", "%s", "HF Line (6 boards)/2"); nominal_power = 3780; break; case 47: dstate_setinfo("ups.model", "%s", "HF Line (7 boards)/2"); nominal_power = 4410; break; case 48: dstate_setinfo("ups.model", "%s", "HF Line (8 boards)/2"); nominal_power = 5040; break; case 51: dstate_setinfo("ups.model", "%s", "HF Millennium 810"); nominal_power = 700; break; case 52: dstate_setinfo("ups.model", "%s", "HF Millennium 820"); nominal_power = 1400; break; case 61: dstate_setinfo("ups.model", "%s", "HF TOP Line 910"); nominal_power = 700; break; case 62: dstate_setinfo("ups.model", "%s", "HF TOP Line 920"); nominal_power = 1400; break; case 63: dstate_setinfo("ups.model", "%s", "HF TOP Line 930"); nominal_power = 2100; break; case 64: dstate_setinfo("ups.model", "%s", "HF TOP Line 940"); nominal_power = 2800; break; case 74: dstate_setinfo("ups.model", "%s", "HF TOP Line 940/2"); nominal_power = 2800; break; case 75: dstate_setinfo("ups.model", "%s", "HF TOP Line 950/2"); nominal_power = 3500; break; case 76: dstate_setinfo("ups.model", "%s", "HF TOP Line 960/2"); nominal_power = 4200; break; case 77: dstate_setinfo("ups.model", "%s", "HF TOP Line 970/2"); nominal_power = 4900; break; case 78: dstate_setinfo("ups.model", "%s", "HF TOP Line 980/2"); nominal_power = 5600; break; case 81: dstate_setinfo("ups.model", "%s", "ECO 508"); nominal_power = 500; break; case 82: dstate_setinfo("ups.model", "%s", "ECO 511"); nominal_power = 700; break; case 83: dstate_setinfo("ups.model", "%s", "ECO 516"); nominal_power = 1000; break; case 84: dstate_setinfo("ups.model", "%s", "ECO 519"); nominal_power = 1200; break; case 85: dstate_setinfo("ups.model", "%s", "ECO 522"); nominal_power = 1400; break; case 91: dstate_setinfo("ups.model", "%s", "ECO 305 / Harviot 530 SX"); nominal_power = 330; break; case 92: dstate_setinfo("ups.model", "%s", "ORDINATORE 2"); nominal_power = 330; break; case 93: dstate_setinfo("ups.model", "%s", "Harviot 730 SX"); nominal_power = 430; break; case 101: dstate_setinfo("ups.model", "%s", "ECO 308 SX / SX Interactive / Ordinatore"); nominal_power = 500; break; case 102: dstate_setinfo("ups.model", "%s", "ECO 311 SX / SX Interactive"); nominal_power = 700; break; case 111: dstate_setinfo("ups.model", "%s", "ally HF 800 / BI-TWICE 800"); nominal_power = 560; break; case 112: dstate_setinfo("ups.model", "%s", "ally HF 1600"); nominal_power = 1120; break; case 121: dstate_setinfo("ups.model", "%s", "ally HF 1000 / BI-TWICE 1000"); nominal_power = 700; break; case 122: dstate_setinfo("ups.model", "%s", "ally HF 2000"); nominal_power = 1400; break; case 131: dstate_setinfo("ups.model", "%s", "ally HF 1250 / BI-TWICE 1250"); nominal_power = 875; break; case 132: dstate_setinfo("ups.model", "%s", "ally HF 2500"); nominal_power = 1750; break; case 141: dstate_setinfo("ups.model", "%s", "Megaline 1250"); nominal_power = 875; break; case 142: dstate_setinfo("ups.model", "%s", "Megaline 2500"); nominal_power = 1750; break; case 143: dstate_setinfo("ups.model", "%s", "Megaline 3750"); nominal_power = 2625; break; case 144: dstate_setinfo("ups.model", "%s", "Megaline 5000"); nominal_power = 3500; break; case 154: dstate_setinfo("ups.model", "%s", "Megaline 5000 / 2"); nominal_power = 3500; break; case 155: dstate_setinfo("ups.model", "%s", "Megaline 6250 / 2"); nominal_power = 4375; break; case 156: dstate_setinfo("ups.model", "%s", "Megaline 7500 / 2"); nominal_power = 5250; break; case 157: dstate_setinfo("ups.model", "%s", "Megaline 8750 / 2"); nominal_power = 6125; break; case 158: dstate_setinfo("ups.model", "%s", "Megaline 10000 / 2"); nominal_power = 7000; break; default: fatal_with_errno(EXIT_FAILURE, "Unknown UPS"); } /* Get the serial number; res >=0 per check above */ #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) /* Note for gating macros above: unsuffixed HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP * means support of contexts both inside and outside function body, so the push * above and pop below (outside this finction) are not used. */ # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS /* Note that the individual warning pragmas for use inside function bodies * are named without a _INSIDEFUNC suffix, for simplicity and legacy reasons */ # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif if (res < 7 || (unsigned long long int)res >= SIZE_MAX) #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) # pragma GCC diagnostic pop #endif fatal_with_errno(EXIT_FAILURE, "Could not communicate with the ups"); memcpy(serial, my_answer + 7, (size_t)(res - 7)); /* serial number start from the 8th byte */ serial[12]='\0'; /* terminate string */ dstate_setinfo("ups.serial", "%s", serial); /* get the ups firmware. The major number is in the 5th byte, the minor is in the 6th */ dstate_setinfo("ups.firmware", "%u.%u", my_answer[5], my_answer[6]); printf("Detected %s [%s] v.%s on %s\n", dstate_getinfo("ups.model"), dstate_getinfo("ups.serial"), dstate_getinfo("ups.firmware"), device_path); /* Add instant commands */ dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); dstate_addcmd("shutdown.stop"); dstate_addcmd("test.failure.start"); dstate_addcmd("test.failure.stop"); dstate_addcmd("test.battery.start"); dstate_addcmd("beeper.enable"); dstate_addcmd("beeper.mute"); dstate_addcmd("beeper.on"); dstate_addcmd("beeper.off"); upsh.instcmd = instcmd; return; } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic pop #endif void upsdrv_updateinfo(void) { int res; uint16_t int_num; #ifdef EXTRADATA int day, hour, minute; #endif float float_num; uint32_t long_num; unsigned char my_answer[255]; /* GET Output data */ res = command_read_sequence(UPS_OUTPUT_DATA, my_answer); if (res < 0) { printf("Could not communicate with the ups"); dstate_datastale(); } else { /* Active power */ int_num = get_word(&my_answer[1]); if (nominal_power != 0) { float_num = (float)((int_num * 100)/nominal_power); dstate_setinfo("ups.load", "%2.1f", float_num); } else { dstate_setinfo("ups.load", "%s", "not available"); } #ifdef EXTRADATA dstate_setinfo("output.power", "%u", int_num); #endif /* voltage */ int_num = get_word(&my_answer[3]); if ((int16_t)int_num > 0) dstate_setinfo("output.voltage", "%u", int_num); if ((int16_t)int_num == -1) dstate_setinfo("output.voltage", "%s", "overrange"); if ((int16_t)int_num == -2) dstate_setinfo("output.voltage", "%s", "not available"); /* current */ float_num = get_word_float(&my_answer[5]); if (f_equal(float_num, -1.0)) dstate_setinfo("output.current", "%s", "overrange"); if (f_equal(float_num, -2.0)) dstate_setinfo("output.current", "%s", "not available"); if (float_num > 0) { float_num = (float)(float_num/10); dstate_setinfo("output.current", "%2.2f", float_num); } #ifdef EXTRADATA /* peak current */ float_num = get_word_float(&my_answer[7]); if (f_equal(float_num, -1.0)) dstate_setinfo("output.current.peak", "%s", "overrange"); if (f_equal(float_num, -2.0)) dstate_setinfo("output.current.peak", "%s", "not available"); if (float_num > 0) { float_num = (float)(float_num/10); dstate_setinfo("output.current.peak", "%2.2f", float_num); } #endif } /* GET Input data */ res = command_read_sequence(UPS_INPUT_DATA, my_answer); if (res < 0){ printf("Could not communicate with the ups"); dstate_datastale(); } else { #ifdef EXTRADATA /* Active power */ int_num = get_word(&my_answer[1]); if ((int16_t)int_num > 0) dstate_setinfo("input.power", "%u", int_num); if ((int16_t)int_num == -1) dstate_setinfo("input.power", "%s", "overrange"); if ((int16_t)int_num == -2) dstate_setinfo("input.power", "%s", "not available"); #endif /* voltage */ int_num = get_word(&my_answer[3]); if ((int16_t)int_num > 0) dstate_setinfo("input.voltage", "%u", int_num); if ((int16_t)int_num == -1) dstate_setinfo("input.voltage", "%s", "overrange"); if ((int16_t)int_num == -2) dstate_setinfo("input.voltage", "%s", "not available"); #ifdef EXTRADATA /* current */ float_num = get_word_float(&my_answer[5]); if (float_num == -1) dstate_setinfo("input.current", "%s", "overrange"); if (float_num == -2) dstate_setinfo("input.current", "%s", "not available"); if (float_num > 0) { float_num = (float)(float_num/10); dstate_setinfo("input.current", "%2.2f", float_num); } /* peak current */ float_num = get_word_float(&my_answer[7]); if (float_num == -1) dstate_setinfo("input.current.peak", "%s", "overrange"); if (float_num == -2) dstate_setinfo("input.current.peak", "%s", "not available"); if (float_num > 0) { float_num = (float)(float_num/10); dstate_setinfo("input.current.peak", "%2.2f", float_num); } #endif } /* GET Battery data */ res = command_read_sequence(UPS_BATTERY_DATA, my_answer); if (res < 0) { printf("Could not communicate with the ups"); dstate_datastale(); } else { /* Actual value */ float_num = get_word_float(&my_answer[1]); float_num = (float)(float_num/10); dstate_setinfo("battery.voltage", "%2.2f", float_num); #ifdef EXTRADATA /* reserve threshold */ float_num = get_word_float(&my_answer[3]); float_num = (float)(float_num/10); dstate_setinfo("battery.voltage.low", "%2.2f", float_num); /* exhaust threshold */ float_num = get_word_float(&my_answer[5]); float_num = (float)(float_num/10); dstate_setinfo("battery.voltage.exhaust", "%2.2f", float_num); #endif } #ifdef EXTRADATA /* GET history data */ res = command_read_sequence(UPS_HISTORY_DATA, my_answer); if (res < 0) { printf("Could not communicate with the ups"); dstate_datastale(); } else { /* ups total runtime */ long_num = get_long(&my_answer[1]); day = (int)(long_num / 86400); long_num -= (long)(day*86400); hour = (int)(long_num / 3600); long_num -= (long)(hour*3600); minute = (int)(long_num / 60); long_num -= (minute*60); dstate_setinfo("ups.total.runtime", "%d days %dh %dm %lus", day, hour, minute, long_num); /* ups inverter runtime */ long_num = get_long(&my_answer[5]); day = (int)(long_num / 86400); long_num -= (long)(day*86400); hour = (int)(long_num / 3600); long_num -= (long)(hour*3600); minute = (int)(long_num / 60); long_num -= (minute*60); dstate_setinfo("ups.inverter.runtime", "%d days %dh %dm %lus", day, hour, minute, long_num); /* ups inverter interventions */ dstate_setinfo("ups.inverter.interventions", "%u", get_word(&my_answer[9])); /* battery full discharges */ dstate_setinfo("battery.full.discharges", "%u", get_word(&my_answer[11])); /* ups bypass / stabilizer interventions */ int_num = get_word(&my_answer[13]); if ((int16_t)int_num == -2) dstate_setinfo("ups.bypass.interventions", "%s", "not avaliable"); if ((int16_t)int_num >= 0) dstate_setinfo("ups.bypass.interventions", "%u", int_num); /* ups overheatings */ int_num = get_word(&my_answer[15]); if ((int16_t)int_num == -2) dstate_setinfo("ups.overheatings", "%s", "not avalilable"); if ((int16_t)int_num >= 0) dstate_setinfo("ups.overheatings", "%u", int_num); } #endif /* GET times on battery */ res = command_read_sequence(UPS_GET_TIMES_ON_BATTERY, my_answer); if (res < 0) { printf("Could not communicate with the ups"); dstate_datastale(); } else { autorestart = my_answer[5]; } /* GET schedule */ res = command_read_sequence(UPS_GET_SCHEDULING, my_answer); if (res < 0) { printf("Could not communicate with the ups"); dstate_datastale(); } else { /* time remaining to shutdown */ long_num = get_long(&my_answer[1]); if ((int32_t)long_num == -1) { dstate_setinfo("ups.delay.shutdown", "%d", 120); } else { dstate_setinfo("ups.delay.shutdown", "%lu", (unsigned long)long_num); } /* time remaining to restart */ long_num = get_long(&my_answer[5]); if ((int32_t)long_num == -1) { dstate_setinfo("ups.delay.start", "%d", 0); } else { dstate_setinfo("ups.delay.start", "%lu", (unsigned long)long_num); } } /* GET ups status */ res = command_read_sequence(UPS_STATUS, my_answer); if (res < 0) { printf("Could not communicate with the ups"); dstate_datastale(); } else { /* ups temperature */ my_answer[3] -=128; if (my_answer[3] > 0) { dstate_setinfo("ups.temperature", "%d", my_answer[3]); } else { dstate_setinfo("ups.temperature", "%s", "not available"); } /* Status */ status_init(); switch (my_answer[1]) { /* byte 1 = STATUS */ case 0x00: status_set("OL"); /* running on mains power */ break; case 0x01: status_set("OB"); /* running on battery power */ break; case 0x02: status_set("LB"); /* battery reserve */ break; case 0x03: /* bypass engaged */ case 0x04: /* manual bypass engaged */ status_set("BY"); break; default: printf("status unknown \n"); break; } switch (my_answer[2]) { /* byte 2 = FAULTS */ case 0x00: /* all right */ break; case 0x01: /* overload */ status_set("OVER"); break; case 0x02: /* overheat */ break; case 0x03: /* hardware fault */ break; case 0x04: /* battery charger failure (overcharging) */ break; case 0x05: /* replace batteries */ status_set("RB"); break; default: printf("status unknown \n"); break; } status_commit(); dstate_dataok(); } return; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ unsigned char command[10], answer[10]; /* Ensure that the ups is configured for automatically restart after a complete battery discharge and when the power comes back after a shutdown. Similar code to "shutdown.restart" but different timeouts. */ if (! autorestart) { command[0]=UPS_SET_TIMES_ON_BATTERY; command[1]=0x00; /* max time on */ command[2]=0x00; /* battery */ command[3]=0x00; /* max time after */ command[4]=0x00; /* battery reserve */ command[5]=0x01; /* autorestart after battery depleted enabled */ command_write_sequence(command, 6, answer); } /* schedule a shutdown in 120 seconds */ command[0]=UPS_SET_SCHEDULING; command[1]=0x96; /* remaining */ command[2]=0x00; /* time */ command[3]=0x00; /* to */ command[4]=0x00; /* shutdown 150 secs */ /* restart time has been set to 1 instead of 0 for avoiding a bug in some ups firmware */ command[5]=0x01; /* programmed */ command[6]=0x00; /* time */ command[7]=0x00; /* to */ command[8]=0x00; /* restart 1 sec */ command_write_sequence(command, 9, answer); /* you may have to check the line status since the commands for toggling power are frequently different for OL vs. OB */ /* OL: this must power cycle the load if possible */ /* OB: the load must remain off until the power returns */ } static int instcmd(const char *cmdname, const char *extra) { unsigned char command[10], answer[10]; int res; if (!strcasecmp(cmdname, "beeper.off")) { /* compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.off' command has been renamed to 'beeper.mute' for this driver"); return instcmd("beeper.mute", NULL); } if (!strcasecmp(cmdname, "beeper.on")) { /* compatibility mode for old command */ upslogx(LOG_WARNING, "The 'beeper.on' command has been renamed to 'beeper.enable'"); return instcmd("beeper.enable", NULL); } /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "shutdown.return")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* Same stuff as upsdrv_shutdown() */ if (! autorestart) { command[0]=UPS_SET_TIMES_ON_BATTERY; command[1]=0x00; /* max time on */ command[2]=0x00; /* battery */ command[3]=0x00; /* max time after */ command[4]=0x00; /* battery reserve */ command[5]=0x01; /* autorestart after battery depleted enabled */ command_write_sequence(command, 6, answer); } /* schedule a shutdown in 30 seconds */ command[0]=UPS_SET_SCHEDULING; command[1]=0x1e; /* remaining */ command[2]=0x00; /* time */ command[3]=0x00; /* to */ command[4]=0x00; /* shutdown 30 secs */ command[5]=0x01; /* programmed */ command[6]=0x00; /* time */ command[7]=0x00; /* to */ command[8]=0x00; /* restart 1 sec */ command_write_sequence(command, 9, answer); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stayoff")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); /* schedule a shutdown in 30 seconds with no restart (-1) */ command[0]=UPS_SET_SCHEDULING; command[1]=0x1e; /* remaining */ command[2]=0x00; /* time */ command[3]=0x00; /* to */ command[4]=0x00; /* shutdown 150 secs */ command[5]=0xff; /* programmed */ command[6]=0xff; /* time */ command[7]=0xff; /* to */ command[8]=0xff; /* restart -1 no restart*/ command_write_sequence(command, 9, answer); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); /* set shutdown and restart time to -1 (no shutdown, no restart) */ command[0]=UPS_SET_SCHEDULING; command[1]=0xff; /* remaining */ command[2]=0xff; /* time */ command[3]=0xff; /* to */ command[4]=0xff; /* shutdown -1 (no shutdown) */ command[5]=0xff; /* programmed */ command[6]=0xff; /* time */ command[7]=0xff; /* to */ command[8]=0xff; /* restart -1 no restart */ command_write_sequence(command, 9, answer); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.failure.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); /* force ups on battery power */ command[0]=UPS_SET_BATTERY_TEST; command[1]=0x01; /* 0 = perform battery test 1 = force UPS on battery power 2 = restore standard mode (mains power) */ command_write_sequence(command, 2, answer); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.failure.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); /* restore standard mode (mains power) */ command[0]=UPS_SET_BATTERY_TEST; command[1]=0x02; /* 0 = perform battery test 1 = force UPS on battery power 2 = restore standard mode (mains power) */ command_write_sequence(command, 2, answer); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); /* launch battery test */ command[0]=UPS_SET_BATTERY_TEST; command[1]=0x00; /* 0 = perform battery test 1 = force UPS on battery power 2 = restore standard mode (mains power) */ send_write_command(command, 2); sleep(15); res = get_answer(answer); switch (answer[1]) { /* byte 1 = Test result */ case 0x00: /* all right */ dstate_setinfo("ups.test.result", "OK"); break; case 0x01: dstate_setinfo("ups.test.result", "Battery charge: 20%%"); break; case 0x02: dstate_setinfo("ups.test.result", "Battery charge: 40%%"); break; case 0x03: dstate_setinfo("ups.test.result", "Battery charge: 60%%"); break; case 0x04: dstate_setinfo("ups.test.result", "Battery charge: 80%%"); break; case 0x05: dstate_setinfo("ups.test.result", "Battery charge: 100%%"); break; case 0xfe: dstate_setinfo("ups.test.result", "Bad battery pack: replace"); break; default: dstate_setinfo("ups.test.result", "Impossible to test"); break; } dstate_dataok(); upslogx(LOG_NOTICE, "instcmd: test battery returned with %d bytes", res); upslogx(LOG_NOTICE, "test battery byte 1 = %x", answer[1]); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "beeper.enable")) { /* set buzzer to not muted */ command[0]=UPS_SET_BUZZER_MUTE; command[1]=0x00; /* 0 = not muted 1 = muted 2 = read current status */ command_write_sequence(command, 2, answer); return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "beeper.mute")) { /* set buzzer to muted */ command[0]=UPS_SET_BUZZER_MUTE; command[1]=0x01; /* 0 = not muted 1 = muted 2 = read current status */ command_write_sequence(command, 2, answer); return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { /* allow '-x xyzzy' */ /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */ /* allow '-x foo=' */ /* addvar(VAR_VALUE, "foo", "Override foo setting"); */ } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); send_zeros(); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/tripplite-hid.c0000644000175000017500000006632314777753337013715 00000000000000/* tripplite-hid.c - data to monitor Tripp Lite USB/HID devices with NUT * * Copyright (C) * 2003 - 2012 Arnaud Quette * 2005 - 2006 Peter Selinger * 2008 - 2009 Arjen de Korte * * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "usbhid-ups.h" #include "tripplite-hid.h" #include "usb-common.h" #define TRIPPLITE_HID_VERSION "TrippLite HID 0.85" /* FIXME: experimental flag to be put in upsdrv_info */ /* For some devices, the reported battery voltage is off by * factor of 10 (due to an error in the report descriptor), * so we need to apply a scale factor to it to get the actual * battery voltage. By default, the factor is 1 (no scaling). */ static double battery_scale = 1.0; static double io_voltage_scale = 1.0; static double io_frequency_scale = 1.0; static double io_current_scale = 1.0; /* Specific handlers for USB device matching */ static void *battery_scale_1dot0(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); /* FIXME: we could remove this one since it's the default! */ battery_scale = 1.0; return NULL; } static void *battery_scale_0dot1(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); battery_scale = 0.1; return NULL; } static void *smart1500lcdt_scale(USBDevice_t *device) { NUT_UNUSED_VARIABLE(device); battery_scale = 100000.0; io_voltage_scale = 100000.0; io_frequency_scale = 0.01; io_current_scale = 0.01; return NULL; } /* TrippLite */ #define TRIPPLITE_VENDORID 0x09ae /* Hewlett Packard */ #define HP_VENDORID 0x03f0 /* Delta/Minuteman */ #define DELTA_VENDORID 0x05dd /* USB IDs device table */ static usb_device_id_t tripplite_usb_device_table[] = { /* e.g. TrippLite AVR550U */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x1003), battery_scale_0dot1 }, /* e.g. TrippLite AVR750U */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x1007), battery_scale_0dot1 }, /* e.g. TrippLite ECO550UPS */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x1008), battery_scale_0dot1 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x1009), battery_scale_0dot1 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x1010), battery_scale_0dot1 }, /* e.g. TrippLite SU3000LCD2UHV */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x1330), battery_scale_1dot0 }, /* e.g. TrippLite OMNI1000LCD */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x2005), battery_scale_0dot1 }, /* e.g. TrippLite OMNI900LCD */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x2007), battery_scale_0dot1 }, /* e.g. ? */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x2008), battery_scale_0dot1 }, /* e.g. TrippLite Smart1000LCD */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x2009), battery_scale_0dot1 }, /* e.g. ? */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x2010), battery_scale_0dot1 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x2011), battery_scale_0dot1 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x2012), battery_scale_0dot1 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x2013), battery_scale_0dot1 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x2014), battery_scale_0dot1 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x3008), battery_scale_1dot0 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x3009), battery_scale_1dot0 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x3010), battery_scale_1dot0 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x3011), battery_scale_1dot0 }, /* e.g. TrippLite smart2200RMXL2U */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x3012), battery_scale_1dot0 }, /* e.g. ? */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x3013), battery_scale_1dot0 }, /* e.g. ? */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x3014), battery_scale_1dot0 }, /* e.g. ? */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x3015), battery_scale_1dot0 }, /* e.g. TrippLite Smart1500LCD (newer unit) */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x3016), smart1500lcdt_scale }, /* e.g. TrippLite AVR750U (newer unit) */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x3024), smart1500lcdt_scale }, /* e.g. TrippLite SmartOnline SU1500RTXL2UA (older unit?) */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x4001), battery_scale_1dot0 }, /* e.g. TrippLite SmartOnline SU6000RT4U? */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x4002), battery_scale_1dot0 }, /* e.g. TrippLite SmartOnline SU1500RTXL2ua */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x4003), battery_scale_1dot0 }, /* e.g. TrippLite SmartOnline SU1000XLA */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x4004), battery_scale_1dot0 }, /* e.g. ? */ { USB_DEVICE(TRIPPLITE_VENDORID, 0x4005), battery_scale_1dot0 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x4006), battery_scale_1dot0 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x4007), battery_scale_1dot0 }, { USB_DEVICE(TRIPPLITE_VENDORID, 0x4008), battery_scale_1dot0 }, /* e.g. ? */ { USB_DEVICE(HP_VENDORID, 0x0001), battery_scale_1dot0 }, /* HP R1500 G2 and G3 INTL */ { USB_DEVICE(HP_VENDORID, 0x1fe0), battery_scale_1dot0 }, /* HP T750 G2 */ { USB_DEVICE(HP_VENDORID, 0x1fe1), battery_scale_1dot0 }, /* e.g. ? */ { USB_DEVICE(HP_VENDORID, 0x1fe2), battery_scale_1dot0 }, /* HP T1500 G3 */ { USB_DEVICE(HP_VENDORID, 0x1fe3), battery_scale_1dot0 }, /* HP T750 INTL */ { USB_DEVICE(HP_VENDORID, 0x1f06), battery_scale_1dot0 }, /* HP T1000 INTL */ { USB_DEVICE(HP_VENDORID, 0x1f08), battery_scale_1dot0 }, /* HP T1500 INTL */ { USB_DEVICE(HP_VENDORID, 0x1f09), battery_scale_1dot0 }, /* HP R/T 2200 INTL (like SMART2200RMXL2U) */ { USB_DEVICE(HP_VENDORID, 0x1f0a), battery_scale_1dot0 }, /* Delta/Minuteman Enterprise Plus E1500RM2U */ { USB_DEVICE(DELTA_VENDORID, 0xa011), battery_scale_1dot0 }, /* Delta/Minuteman PRO1500RT2U */ { USB_DEVICE(DELTA_VENDORID, 0xa0a0), battery_scale_1dot0 }, /* Terminating entry */ { 0, 0, NULL } }; /* returns statically allocated string - must not use it again before done with result! */ static const char *tripplite_chemistry_fun(double value) { static char buf[20]; const char *model; model = dstate_getinfo("ups.productid"); /* Workaround for AVR 550U firmware bug */ if (!strcmp(model, "1003")) { return "unknown"; } /* Workaround for OMNI1000LCD firmware bug */ if (!strcmp(model, "2005")) { return "unknown"; } return HIDGetIndexString(udev, (int)value, buf, sizeof(buf)); } static info_lkp_t tripplite_chemistry[] = { { 0, NULL, tripplite_chemistry_fun, NULL } }; /* returns statically allocated string - must not use it again before done with result! */ static const char *tripplite_battvolt_fun(double value) { static char buf[8]; snprintf(buf, sizeof(buf), "%.1f", battery_scale * value); return buf; } static info_lkp_t tripplite_battvolt[] = { { 0, NULL, tripplite_battvolt_fun, NULL } }; static const char *tripplite_iovolt_fun(double value) { static char buf[8]; snprintf(buf, sizeof(buf), "%.1f", io_voltage_scale * value); return buf; } static info_lkp_t tripplite_iovolt[] = { { 0, NULL, tripplite_iovolt_fun, NULL } }; static const char *tripplite_iofreq_fun(double value) { static char buf[8]; snprintf(buf, sizeof(buf), "%.1f", io_frequency_scale * value); return buf; } static info_lkp_t tripplite_iofreq[] = { { 0, NULL, tripplite_iofreq_fun, NULL } }; static const char *tripplite_ioamp_fun(double value) { static char buf[8]; snprintf(buf, sizeof(buf), "%.1f", io_current_scale * value); return buf; } static info_lkp_t tripplite_ioamp[] = { { 0, NULL, tripplite_ioamp_fun, NULL } }; /* --------------------------------------------------------------- */ /* Vendor-specific usage table */ /* --------------------------------------------------------------- */ /* TRIPPLITE usage table */ static usage_lkp_t tripplite_usage_lkp[] = { /* currently unknown: 00ff0001, ffff007d, ffff00c0, ffff00c1, ffff00c2, ffff00c3, ffff00c4, ffff00c5, ffff00d2, ffff0091, ffff00c7 */ { "TLCustom", 0xffff0010 }, { "TLDelayBeforeStartup", 0xffff0056 }, /* in minutes */ { "TLLowVoltageTransferMax", 0xffff0057 }, { "TLLowVoltageTransferMin", 0xffff0058 }, { "TLHighVoltageTransferMax", 0xffff0059 }, { "TLHighVoltageTransferMin", 0xffff005a }, /* Outlet state: * 1- On/Closed * 2- Off/Open * 3- On with pending off * 4- Off with pending on * 5- Unknown * 6- Resolved/Unknown * 7- Failed and Closed * 8- Failed and Open */ { "OutletState", 0xffff007a }, { "OutletCount", 0xffff007b }, /* Number of load segments */ { "UPSFirmwareVersion", 0xffff007c }, { "CommunicationProtocolVersion", 0xffff007d }, /* HID protocol version */ { "CommunicationVersion", 0xffff007e }, /* USB firmware version */ { "iUPSPartNumber", 0xffff007f }, /* String index to Part Number */ { "AutoOnDelay", 0xffff0080 }, /* '0' (no delay) to 'n' (delay in seconds) */ { "TLWatchdog", 0xffff0092 }, { "TLOutletsAvailableMask", 0xffff0095 }, { "TLOutletsStatusMask", 0xffff0096 }, /* it looks like Tripp Lite confused pages 0x84 and 0x85 for the following 4 items, on some OMNI1000LCD devices. */ { "TLCharging", 0x00840044 }, /* conflicts with HID spec! */ /* conflicts with HID spec (and HP implementation) for TrippLite! * Refer to tripplite_discharging_info */ { "TLDischarging", 0x00840045 }, { "TLNeedReplacement", 0x0084004b }, { "TLACPresent", 0x008400d0 }, { NULL, 0 } }; static usage_tables_t tripplite_utab[] = { tripplite_usage_lkp, /* tripplite lookup table; make sure this is first */ hid_usage_lkp, /* generic lookup table */ NULL, }; /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ /* --------------------------------------------------------------- */ /* HID2NUT lookup table */ static hid_info_t tripplite_hid2nut[] = { #if WITH_UNMAPPED_DATA_POINTS || (defined USBHID_UPS_TRIPPLITE_DEBUG) /* unmapped variables - meaning unknown */ { "UPS.Flow.0xffff0097", 0, 0, "UPS.Flow.0xffff0097", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff0075", 0, 0, "UPS.TLCustom.[1].0xffff0075", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff0076", 0, 0, "UPS.TLCustom.[1].0xffff0076", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff007c", 0, 0, "UPS.TLCustom.[1].0xffff007c", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff007d", 0, 0, "UPS.TLCustom.[1].0xffff007d", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e0", 0, 0, "UPS.TLCustom.[1].0xffff00e0", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e1", 0, 0, "UPS.TLCustom.[1].0xffff00e1", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e2", 0, 0, "UPS.TLCustom.[1].0xffff00e2", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e3", 0, 0, "UPS.TLCustom.[1].0xffff00e3", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e4", 0, 0, "UPS.TLCustom.[1].0xffff00e4", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e5", 0, 0, "UPS.TLCustom.[1].0xffff00e5", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e6", 0, 0, "UPS.TLCustom.[1].0xffff00e6", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e7", 0, 0, "UPS.TLCustom.[1].0xffff00e7", NULL, "%.0f", 0, NULL }, { "UPS.TLCustom.[1].0xffff00e8", 0, 0, "UPS.TLCustom.[1].0xffff00e8", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00c0", 0, 0, "UPS.0xffff0015.[1].0xffff00c0", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00c1", 0, 0, "UPS.0xffff0015.[1].0xffff00c1", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00c2", 0, 0, "UPS.0xffff0015.[1].0xffff00c2", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00c3", 0, 0, "UPS.0xffff0015.[1].0xffff00c3", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00c4", 0, 0, "UPS.0xffff0015.[1].0xffff00c4", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00c5", 0, 0, "UPS.0xffff0015.[1].0xffff00c5", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00d2", 0, 0, "UPS.0xffff0015.[1].0xffff00d2", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00d3", 0, 0, "UPS.0xffff0015.[1].0xffff00d3", NULL, "%.0f", 0, NULL }, { "UPS.0xffff0015.[1].0xffff00d6", 0, 0, "UPS.0xffff0015.[1].0xffff00d6", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff0081", 0, 0, "UPS.OutletSystem.Outlet.0xffff0081", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff0091", 0, 0, "UPS.OutletSystem.Outlet.0xffff0091", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff0093", 0, 0, "UPS.OutletSystem.Outlet.0xffff0093", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff0095", 0, 0, "UPS.OutletSystem.Outlet.0xffff0095", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff0096", 0, 0, "UPS.OutletSystem.Outlet.0xffff0096", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff0098", 0, 0, "UPS.OutletSystem.Outlet.0xffff0098", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff00a2", 0, 0, "UPS.OutletSystem.Outlet.0xffff00a2", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff00a4", 0, 0, "UPS.OutletSystem.Outlet.0xffff00a4", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff00a7", 0, 0, "UPS.OutletSystem.Outlet.0xffff00a7", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff00a9", 0, 0, "UPS.OutletSystem.Outlet.0xffff00a9", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff00aa", 0, 0, "UPS.OutletSystem.Outlet.0xffff00aa", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff00ab", 0, 0, "UPS.OutletSystem.Outlet.0xffff00ab", NULL, "%.0f", 0, NULL }, { "UPS.OutletSystem.Outlet.0xffff00ac", 0, 0, "UPS.OutletSystem.Outlet.0xffff00ac", NULL, "%.0f", 0, NULL }, { "UPS.PowerSummary.iOEMInformation", 0, 0, "UPS.PowerSummary.iOEMInformation", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, #endif /* if WITH_UNMAPPED_DATA_POINTS || USBHID_UPS_TRIPPLITE_DEBUG */ /* Device page */ { "device.part", 0, 0, "UPS.TLCustom.[1].iUPSPartNumber", NULL, "%s", HU_FLAG_STATIC, stringid_conversion }, /* Battery page */ { "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.charge", 0, 0, "UPS.BatterySystem.Battery.RemainingCapacity", NULL, "%.0f", 0, NULL }, { "battery.charge.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL }, { "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", 0, NULL }, { "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", 0, NULL }, { "battery.voltage.nominal", 0, 0, "UPS.BatterySystem.Battery.ConfigVoltage", NULL, "%.1f", HU_FLAG_STATIC, NULL }, { "battery.voltage", 0, 0, "UPS.BatterySystem.Battery.Voltage", NULL, "%s", 0, tripplite_battvolt }, { "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", HU_FLAG_STATIC, tripplite_chemistry }, { "battery.temperature", 0, 0, "UPS.BatterySystem.Temperature", NULL, "%s", 0, kelvin_celsius_conversion }, /* UPS page */ { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.OutletSystem.Outlet.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL}, { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.OutletSystem.Outlet.TLDelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL}, /* FIXME { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 6, "UPS.TLCustom.[1].TLDelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_FLAG_ABSENT, NULL}, { "ups.timer.start", 0, 0, "UPS.TLCustom.[1].DelayBeforeStartup", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, - what's the right notion behind this one? { "ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING, 6, "UPS.TLCustom.[1].AutoOnDelay", NULL, DEFAULT_ONDELAY, 0, NULL}, */ { "ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING, 10, "UPS.OutletSystem.Outlet.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_FLAG_ABSENT, NULL}, { "ups.timer.start", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeStartup", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.start", 0, 0, "UPS.OutletSystem.Outlet.TLDelayBeforeStartup", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.shutdown", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeShutdown", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL}, { "ups.timer.reboot", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeReboot", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL }, { "ups.test.result", 0, 0, "UPS.BatterySystem.Test", NULL, "%s", 0, test_read_info }, { "ups.beeper.status", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "%s", 0, beeper_info }, { "ups.power.nominal", 0, 0, "UPS.Flow.ConfigApparentPower", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "ups.power", 0, 0, "UPS.OutletSystem.Outlet.ActivePower", NULL, "%.1f", 0, NULL }, { "ups.power", 0, 0, "UPS.PowerConverter.Output.ActivePower", NULL, "%.1f", 0, NULL }, { "ups.load", 0, 0, "UPS.OutletSystem.Outlet.PercentLoad", NULL, "%.0f", 0, NULL }, /* FIXME: what is the conversion format for this one? * Example on HP T1500 G3 * UPS.TLCustom.[1].UPSFirmwareVersion, Type: Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 262 */ { "ups.firmware", 0, 0, "UPS.TLCustom.[1].UPSFirmwareVersion", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* Number of seconds left before the watchdog reboots the UPS (0 = disabled) */ { "ups.watchdog.status", 0, 0, "UPS.OutletSystem.Outlet.TLWatchdog", NULL, "%.0f", 0, NULL }, /* Special case: ups.status */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.InternalFailure", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, 0, shutdownimm_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyCharged", NULL, NULL, HU_FLAG_QUICK_POLL, fullycharged_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.FullyDischarged", NULL, NULL, HU_FLAG_QUICK_POLL, depleted_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, /* repeat some of the above for faulty usage codes (seen on OMNI1000LCD, untested) */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.TLACPresent", NULL, NULL, HU_FLAG_QUICK_POLL, online_info }, /* "Redundant" definition to deal with the conflict between * TrippLite units, wrongly defining 0x00840045 as "TLDischarging" * and HP which uses the standard 0x00840045 (as ConfigPercentLoad). * Note that this path should not exist on HP devices. */ { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.TLDischarging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, /* Otherwise, define the version for HP devices */ { "ups.load.nominal", 0, 0, "UPS.Flow.ConfigPercentLoad", NULL, "%.0f", 0, NULL }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.TLCharging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.TLNeedReplacement", NULL, NULL, 0, replacebatt_info }, { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.VoltageOutOfRange", NULL, NULL, 0, vrange_info }, { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.Buck", NULL, NULL, 0, trim_info }, { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.Boost", NULL, NULL, 0, boost_info }, { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.Overload", NULL, NULL, 0, overload_info }, /* This is probably not the correct mapping for all models */ /* { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.Used", NULL, NULL, 0, nobattery_info }, */ { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.OverTemperature", NULL, NULL, 0, overheat_info }, { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.InternalFailure", NULL, NULL, 0, commfault_info }, { "BOOL", 0, 0, "UPS.PowerConverter.PresentStatus.AwaitingPower", NULL, NULL, 0, awaitingpower_info }, /* Duplicated values { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.BelowRemainingCapacityLimit", NULL, NULL, HU_FLAG_QUICK_POLL, lowbatt_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.FullyCharged", NULL, NULL, HU_FLAG_QUICK_POLL, fullycharged_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.Charging", NULL, NULL, HU_FLAG_QUICK_POLL, charging_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.Discharging", NULL, NULL, HU_FLAG_QUICK_POLL, discharging_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.FullyDischarged", NULL, NULL, HU_FLAG_QUICK_POLL, depleted_info }, { "BOOL", 0, 0, "UPS.BatterySystem.Battery.PresentStatus.NeedReplacement", NULL, NULL, 0, replacebatt_info }, */ /* Input page */ { "input.voltage.nominal", 0, 0, "UPS.PowerSummary.Input.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.voltage", 0, 0, "UPS.PowerSummary.Input.Voltage", NULL, "%s", 0, tripplite_iovolt }, { "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%s", 0, tripplite_iovolt }, { "input.frequency", 0, 0, "UPS.PowerConverter.Input.Frequency", NULL, "%s", 0, tripplite_iofreq }, { "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.1f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.low.max", 0, 0, "UPS.PowerConverter.Output.TLLowVoltageTransferMax", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.transfer.low.min", 0, 0, "UPS.PowerConverter.Output.TLLowVoltageTransferMin", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.transfer.high", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.HighVoltageTransfer", NULL, "%.1f", HU_FLAG_SEMI_STATIC, NULL }, { "input.transfer.high.max", 0, 0, "UPS.PowerConverter.Output.TLHighVoltageTransferMax", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "input.transfer.high.min", 0, 0, "UPS.PowerConverter.Output.TLHighVoltageTransferMin", NULL, "%.0f", HU_FLAG_STATIC, NULL }, /* Output page */ { "output.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%s", 0, tripplite_iovolt }, { "output.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, tripplite_iovolt }, { "output.current", 0, 0, "UPS.PowerConverter.Output.Current", NULL, "%s", 0, tripplite_ioamp }, { "output.frequency.nominal", 0, 0, "UPS.Flow.ConfigFrequency", NULL, "%.0f", HU_FLAG_STATIC, NULL }, { "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%s", 0, tripplite_iofreq }, /* instant commands. */ { "test.battery.start.quick", 0, 0, "UPS.BatterySystem.Test", NULL, "1", HU_TYPE_CMD, NULL }, /* reported to work on OMNI1000 */ { "test.battery.start.deep", 0, 0, "UPS.BatterySystem.Test", NULL, "2", HU_TYPE_CMD, NULL }, /* reported not to work */ { "test.battery.stop", 0, 0, "UPS.BatterySystem.Test", NULL, "3", HU_TYPE_CMD, NULL }, /* reported not to work */ { "load.off.delay", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeShutdown", NULL, DEFAULT_OFFDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "load.on.delay", 0, 0, "UPS.OutletSystem.Outlet.TLDelayBeforeStartup", NULL, DEFAULT_ONDELAY, HU_TYPE_CMD, NULL }, { "shutdown.stop", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeShutdown", NULL, "-1", HU_TYPE_CMD, NULL }, { "shutdown.reboot", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeReboot", NULL, "10", HU_TYPE_CMD, NULL }, /* NOTE: the ECO550UPS doesn't support DelayBeforeStartup, so we use the watchdog to trigger a reboot */ { "shutdown.reboot", 0, 0, "UPS.OutletSystem.Outlet.TLWatchdog", NULL, "10", HU_TYPE_CMD, NULL }, /* WARNING: if this timer expires, the UPS will reboot! Defaults to 60 seconds */ { "reset.watchdog", 0, 0, "UPS.OutletSystem.Outlet.TLWatchdog", NULL, "60", HU_TYPE_CMD, NULL }, { "beeper.on", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.off", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, { "beeper.disable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "1", HU_TYPE_CMD, NULL }, { "beeper.enable", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "2", HU_TYPE_CMD, NULL }, { "beeper.mute", 0, 0, "UPS.PowerSummary.AudibleAlarmControl", NULL, "3", HU_TYPE_CMD, NULL }, /* FIXME (to be tested): HP specific (may conflict or differ from TL implementation!) * { "outlet.count", 0, 0, "UPS.TLCustom.[1].OutletCount", NULL, "%.0f", HU_FLAG_STATIC, NULL }, * { "outlet.status", 0, 0, "UPS.TLCustom.[1].OutletState", NULL, "%.0f", HU_FLAG_STATIC, NULL }, 0.284486 Path: UPS.TLCustom.[1].ffff00ff, Type: Feature, ReportID: 0xff, Offset: 0, Size: 8, Value: 255 0.285276 Path: UPS.TLCustom.[1].OutletCount, Type: Feature, ReportID: 0x6d, Offset: 0, Size: 8, Value: 1 0.286260 Path: UPS.TLCustom.[1].OutletState, Type: Feature, ReportID: 0x70, Offset: 0, Size: 8, Value: 1 0.287248 Path: UPS.TLCustom.[1].CommunicationVersion, Type: Feature, ReportID: 0x0e, Offset: 0, Size: 16, Value: 262 0.288901 Path: UPS.TLCustom.[1].CommunicationProtocolVersion, Type: Feature, ReportID: 0x6c, Offset: 0, Size: 16, Value: 2560 0.289903 Path: UPS.TLCustom.[1].TLDelayBeforeStartup, Type: Feature, ReportID: 0x71, Offset: 0, Size: 16, Value: 65535 0.290854 Path: UPS.TLCustom.[1].AutoOnDelay, Type: Feature, ReportID: 0x72, Offset: 0, Size: 16, Value: 65535 */ /* end of structure. */ { NULL, 0, 0, NULL, NULL, NULL, 0, NULL } }; static const char *tripplite_format_model(HIDDevice_t *hd) { return hd->Product; } static const char *tripplite_format_mfr(HIDDevice_t *hd) { return hd->Vendor; } static const char *tripplite_format_serial(HIDDevice_t *hd) { return hd->Serial; } /* this function allows the subdriver to "claim" a device: return 1 if * the device is supported by this subdriver, else 0. */ static int tripplite_claim(HIDDevice_t *hd) { int status = is_usb_device_supported(tripplite_usb_device_table, hd); switch (status) { case POSSIBLY_SUPPORTED: switch (hd->VendorID) { case HP_VENDORID: /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } /* * this vendor makes lots of USB devices that are * not a UPS, so don't use possibly_supported here */ return 0; case TRIPPLITE_VENDORID: /* reject known non-HID devices */ /* not all Tripp Lite products are HID, some are "serial over USB". */ if (hd->ProductID == 0x0001) { /* e.g. SMART550USB, SMART3000RM2U */ upsdebugx(0, "This Tripp Lite device (%04x/%04x) is not supported by usbhid-ups.\n" "Please use the tripplite_usb driver instead.\n", hd->VendorID, hd->ProductID); return 0; } /* by default, reject, unless the productid option is given */ if (getval("productid")) { return 1; } possibly_supported("TrippLite", hd); return 0; /* catch all (not really needed) */ default: return 0; } case SUPPORTED: return 1; case NOT_SUPPORTED: default: return 0; } } subdriver_t tripplite_subdriver = { TRIPPLITE_HID_VERSION, tripplite_claim, tripplite_utab, tripplite_hid2nut, tripplite_format_model, tripplite_format_mfr, tripplite_format_serial, fix_report_desc, }; nut-2.8.4/drivers/solis.h0000644000175000017500000004673114777753337012276 00000000000000/* solis.h - Microsol Solis UPS hardware Copyright (C) 2004 Silvino B. Magalhaes 2019 Roberto Panerai Velloso This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2004/10/10 - Version 0.10 - Initial release 2004/10/20 - Version 0.20 - add Battery information in driver 2004/10/26 - Version 0.30 - add commands and test shutdown 2004/10/30 - Version 0.40 - add model data structs 2004/11/22 - Version 0.50 - add internal e external shutdown programming 2005/06/16 - Version 0.60 - save external shutdown programming to ups, support new cables and Solaris compilation 2015/09/19 - Version 0.63 - patch for correct reading for Microsol Back-Ups BZ1200-BR */ #ifndef INCLUDED_SOLIS_H #define INCLUDED_SOLIS_H #include "nut_stdint.h" /* General FIXMEs: * * "static" declarations belong in some one single C source; * headers should use "extern" to refer linker to look for * vars in other object files * * use a common definition of bool_t */ typedef int bool_t; /* autonomy constants */ static const int bext[5] = {14,18,28,18,1}; static const int nompow[5] = { 1000,1500,2000,3000,1200 }; static const int inds[6] = { 0,0,1,2,3,4 }; static const double InVolt_offset = 30.; #define PACKET_SIZE 25 static const size_t packet_size = PACKET_SIZE; static const struct { int maxi; /* power internals */ int minc[21]; /* power minimal index */ int maxc[21]; /* power maximus index */ int mm[21][39]; /* autonomy time [minutes] */ } auton[5] = {{ 7, { 139,139,142,141,141,141,141,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } , { 176,174,172,172,170,170,170,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } , { { 1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5,6,7,8,10,11,12,15,17,19,22,25,28,31,35,40,43,47,52,59,64,68,75,75 }, { 1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,7,8,9,10,11,12,13,15,18,20,21,24,28,30,32,33,33,34,34,34,34 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,4,4,5,5,6,7,8,9,10,11,12,13,15,17,19,21,22,23,23,23,23,23,23 }, { 1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,4,5,6,7,7,8,9,19,11,12,13,14,16,18,20,20,20,20,20,20 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,5,5,6,6,6,7,7,8,8,10,11,12,13,14,14,14,14,14,14,14,14 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,3,3,4,4,5,6,6,6,7,7,8,9,10,11,12,12,12,12,12,12,12,12,12,12 }, { 1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,4,4,5,5,6,6,6,7,7,8,9,10,10,10,10,10,10,10,10,10,10,10,10,10 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, },}, { 10, { 141,141,141,141,141,141,141,141,141,141,0,0,0,0,0,0,0,0,0,0,0 } , { 177,177,177,172,173,172,172,172,172,172,0,0,0,0,0,0,0,0,0,0,0 } , { { 1,1,1,1,1,1,1,1,1,2,2,3,3,5,6,7,9,10,12,15,16,18,22,25,27,30,36,42,45,48,55,60,64,70,78, 84,90,97,104 }, { 1,1,1,1,1,1,1,1,1,2,2,2,3,2,3,4,5,6,7,8,10,12,13,14,16,19,22,25,28,30,35,38,42,46,52,55, 58,60,62 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,4,5,7,9,10,12,13,16,20,21,23,26,28,30,34,35,37,38,39,40 ,40,40 }, { 1,1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,4,5,6,7,8,9,10,11,13,14,16,18,21,22,24,27,27,27,27,27,27 }, { 1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,4,4,4,4,4,5,6,7,8,9,10,11,12,14,15,16,19,20,22,23,23,23,23,23 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,3,3,4,4,4,4,5,6,7,8,9,10,11,12,13,14,16,17,18,18,18,18,18,18 }, { 1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,4,4,4,4,4,5,7,7,7,8,9,10,11,12,14,14,14,14,14,14,14 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,3,4,4,4,4,4,5,6,7,7,8,8,9,10,11,12,13,13,13,13,13,13,13,13 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,4,4,4,4,4,5,6,7,7,8,9,10,10,11,11,12,12,12,12,12,12 }, { 1,1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,3,4,4,4,4,5,6,6,7,7,8,8,8,9,9,10,10,10,10,10,10,10,10 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, },}, { 13, { 141,141,141,141,141,141,141,141,141,141,141,141,141,0,0,0,0,0,0,0,0 } , { 177,177,177,172,173,172,172,172,172,172,172,172,172,0,0,0,0,0,0,0,0 } , { { 1,1,1,1,1,1,2,2,2,3,4,5,5,8,10,11,13,15,18,22,24,28,34,40,43,48,56,65,70,76,85,93,100,110,122,132,141,152,162 }, { 1,1,1,1,1,1,1,2,2,2,3,3,3,4,5,6,8,9,10,12,15,18,20,22,25,30,35,40,44,48,54,60,65,73,80,85,92,94,95 }, { 1,1,1,1,1,1,1,2,2,3,3,3,4,4,4,5,5,6,8,10,14,16,18,20,24,30,32,36,40,44,48,52,54,58,59,60 ,62,62,62 }, { 1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,5,6,8,9,10,12,13,15,17,20,22,24,28,32,35,38,42,42,42,42,42,42 }, { 1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,7,8,10,11,12,14,15,17,18,21,24,26,29,32,34,36,36,36,36,36 }, { 1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5,6,7,8,9,10,12,13,15,16,18,20,22,24,26,28,28,28,28,28,28 }, { 1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,4,5,5,6,6,7,8,9,10,11,13,14,15,17,19,21,22,22,22,22,22,22 }, { 1,1,1,1,1,1,1,2,2,2,3,3,3,3,4,4,5,5,6,6,7,8,8,9,10,11,12,14,15,17,18,19,20,20,20,20,20,20,20 }, { 1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,4,4,5,6,6,7,7,8,9,10,11,12,13,15,15,16,16,16,16,16,16,16,16 }, { 1,1,1,1,1,1,1,1,2,2,2,3,3,3,4,4,4,5,5,6,7,8,9,9,10,11,12,12,12,13,13,14,14,14,14,14,14,14,14 }, { 1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,4,4,5,5,6,7,7,8,9,10,10,10,11,11,12,12,12,12,12,12,12,12 }, { 1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,8,8,9,9,10,10,10,10,10,10,10,10 }, { 1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,4,4,4,5,5,6,6,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, },}, { 21, { 141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141 } , { 177,175,173,171,169,169,168,168,167,167,166,165,164,162,160,160,160,160,159,158,157 } , { { 1,1,1,1,2,2,3,4,5,6,7,8,9,10,11,12,13,14,16,19,22,24,27,30,33,37,42,44,50,55,60,65,70,75 ,80,88,93,95,100 }, { 1,1,1,1,2,2,3,4,5,6,7,8,9,10,11,12,13,14,15,18,20,22,25,27,31,35,38,42,46,50,55,61,66,71 ,76,83,89,89,89 }, { 1,1,1,1,2,2,3,3,4,5,6,7,8,8,9,10,11,12,13,15,18,19,22,24,26,30,33,38,40,45,50,55,60,66,70,70,70,70,70 }, { 1,1,1,1,1,1,2,2,3,4,5,6,7,7,8,9,10,10,11,13,16,17,19,21,23,25,28,34,36,39,45,50,55,55,55,55,55,55,55 }, { 1,1,1,1,1,1,2,2,3,4,4,5,6,6,7,8,8,9,10,12,14,15,17,18,20,21,25,28,30,34,39,39,39,39,39,39,39,39,39 }, { 1,1,1,1,1,1,2,2,3,4,4,4,5,5,6,7,8,8,9,10,12,13,15,16,18,19,22,25,26,28,30,30,30,30,30,30,30,30,30 }, { 1,1,1,1,1,1,2,2,2,3,3,3,4,4,5,6,7,7,8,9,11,12,13,14,17,17,20,22,24,26,26,26,26,26,26,26,26,26,26 }, { 1,1,1,1,1,1,2,2,2,3,3,3,4,4,5,5,6,7,7,8,10,11,12,13,15,16,18,20,22,23,23,23,23,23,23,23,23,23,23 }, { 1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,6,7,7,9,10,11,13,14,15,16,18,19,19,19,19,19,19,19,19,19,19,19 }, { 1,1,1,1,1,1,1,1,1,2,2,2,2,3,4,4,5,6,7,7,8,10,11,13,14,15,15,16,17,17,17,17,17,17,17,17,17,17,17 }, { 1,1,1,1,1,1,1,1,1,2,2,2,2,3,4,4,5,6,7,7,8,9,10,11,13,14,13,14,14,14,14,14,14,14,14,14,14,14,14 }, { 1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,5,6,6,7,8,9,10,12,13,12,13,13,13,13,13,13,13,13,13,13,13,13 }, { 1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,5,6,6,7,8,8,9,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,5,6,6,7,7,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,5,6,6,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,5,6,6,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,5,6,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 }, { 1,1,1,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,5,6,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 }, { 1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }, { 1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6 }, { 1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5 }, },}, { 21, { 141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141 } , { 177,175,173,171,169,169,168,168,167,167,166,165,164,162,160,160,160,160,159,158,157 } , { { 1,1,1,2,5,5,8,11,14,16,19,22,36,40,44,48,52,56,64,76,88,96,145,162, 178,199,226,237,270,297,324,351,378,405,432,475,502,513,540 }, { 1,1,1,2,3,5,8,11,14,16,19,22,36,40,44,48,52,56,60,72,80,88,135,145, 167,189,205,226,248,270,297,329,356,383,410,448,480,480,480 }, { 1,1,1,2,3,5,6,8,11,14,16,19,32,32,36,40,44,48,52,60,72,76,118,129, 140,162,178,205,216,243,270,297,324,356,378,378,378,378,378 }, { 1,1,1,2,3,4,5,6,8,11,14,16,28,28,32,36,40,40,44,52,64,68,102, 113,124,135,151,183,194,210,243,270,297,297,297,297,297,297,297 }, { 1,1,1,2,3,4,5,6,8,11,11,14,24,24,28,32,32,36,40,48,56,60,91, 97,108,113,135,151,162,183,210,210,210,210,210,210,210,210,210 }, { 1,1,1,2,3,4,5,6,8,11,11,11,20,20,24,28,32,32,36,40,48,52,81, 86,97,102,118,135,140,151,162,162,162,162,162,162,162,162,162 }, { 1,1,1,2,3,4,5,6,7,8,8,8,16,16,20,24,28,28,32,36,44,48,70,75, 91,91,108,118,129,140,140,140,140,140,140,140,140,140,140 }, { 1,1,1,2,2,3,4,5,5,8,8,8,16,16,20,20,24,28,28,32,40,44,64,70, 81,86,97,108,118,124,124,124,124,124,124,124,124,124,124 }, { 1,1,1,2,2,3,3,4,4,5,5,6,12,12,16,16,20,24,28,28,36,40,59, 70,75,81,86,97,102,102,102,102,102,102,102,102,102,102,102 }, { 1,1,1,2,2,3,3,4,4,5,5,8,10,12,16,16,20,24,28,28,32,40, 59,70,75,81,81,86,91,91,91,91,91,91,91,91,91,91,91 }, { 1,1,1,2,2,3,3,4,4,5,6,8,10,12,16,16,20,24,28,28,32,36,54, 59,70,75,70,75,75,75,75,75,75,75,75,75,75,75,75 }, { 1,1,2,2,2,2,2,2,2,5,6,8,10,12,16,18,20,22,24,26,28,36,48, 54,60,65,70,70,70,70,70,70,70,70,70,70,70,70,70 }, { 1,1,1,2,2,3,3,4,4,5,6,8,10,12,15,16,18,20,22,24,28,32,43, 48,58,64,64,64,64,64,64,64,64,64,64,64,64,64,64 }, { 1,1,1,2,2,3,3,4,4,4,5,6,8,10,12,16,20,24,26,28,30,32,42, 48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48 }, { 1,1,1,2,2,3,3,4,4,4,5,6,8,10,12,15,18,20,24,28,30,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 }, { 1,1,1,2,2,3,3,4,4,4,5,6,8,10,12,16,18,22,24,28,30,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 }, { 1,1,1,2,2,3,3,4,4,4,5,6,8,10,12,16,18,20,22,24,28,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 }, { 1,1,1,2,2,3,3,4,4,4,5,6,8,10,12,16,18,20,22,24,28,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 }, { 1,1,1,2,2,3,3,4,5,5,6,8,10,12,14,16,18,20,22,24,28,28,28, 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28 }, { 1,1,1,2,2,3,3,4,4,5,5,6,8,10,12,16,18,20,22,24,24,24,24, 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24 }, { 1,1,1,2,2,3,3,3,4,5,5,6,8,10,12,15,16,18,20,20,20,20,20, 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20 } },}, }; /* ----------------------------------------------------------- * Solis constants for data ajustment * ----------------------------------------------------------- */ static const struct { double m_infreq; double m_appp_offset; double m_involt193[2]; double m_involt194[2]; double m_incurr[2]; double m_battvolt[2]; double m_outvolt_s[2][2]; double m_outvolt_i[2][2]; double m_outcurr_s[2][2]; double m_outcurr_i[2][2]; double m_utilp_s[2][2]; double m_utilp_i[2][2]; double m_appp_s[2][2]; double m_appp_i[2][2]; } ctab[6] = { { 101620.0, 25.0, { 1.141, 13.0 }, { 1.141, 13.0 }, { 22.2, 800.0 }, { 1.0/7.19, 0.0 }, { { 1.45, 13.0 },{ 1.4, 17.0 } }, { { 1.45, 13.0 },{ 1.4, 17.0 } }, { { 1.0/20.5, 0.15 }, { 1.0/20.5, 0.15 } }, { { 1.0/20.5, 0.15 }, { 1.0/20.5, 0.15 } }, { { 1.0/12.8, 16.0 }, { 1.0/12.3, 15.0 } }, { { 1.0/12.8, 16.0 }, { 1.0/12.3, 15.0 } }, { { 1.0/13.46, 16.7 }, { 1.0/12.9, 19.0 } }, { { 1.0/13.46, 16.7 }, { 1.0/12.9, 19.0 } } }, { 101715.0, 28.0, { 1.141, 12.0 }, { 2.5, -250.0 }, { 22.2, 800.0 }, { 1.0/7.19, 0.6}, { { 1.44, 13.0 }, { 1.4, 18.0 } }, { { 2.9, 13.0 }, { 3.15, 2.0 } }, { { 1.0/21.75, 0.15 }, { 1.0/21.75, 0.15 } }, { { 1.0/49.0, 0.1 }, { 1.0/49.0, 0.1 } }, { { 1.0/12.87, 15.6 }, { 1.0/12.2, 13.0 } }, { { 1.0/14.5, 20.0 }, { 1.0/14.0, 25.0 } }, { { 1.0/13.5, 16.0 }, { 1.0/12.9, 17.0 } }, { { 1.0/15.4, 22.0 }, { 1.0/14.5, 22.0 } } }, { 101620.0, 35.0, { 1.141, 13.0 }, { 2.5, -250.0 }, { 22.2, 800.0 }, { 1.0/7.0, 0.0 }, { { 1.375, 16.0 }, { 1.41, 16.0 } }, { { 2.8, 20.0 }, { 2.9, 18.0 } }, { { 1.0/16.5, 0.1 }, { 1.0/16.8, 0.0 } }, { { 1.0/32.5, 0.0 }, { 1.0/32.5, 0.0 } }, { { 1.0/10.2, 11.0 }, { 1.0/9.4, 15.0 } }, { { 1.0/10.1, 26.0 }, { 1.0/9.4, 30.0 } }, { { 1.0/10.2, 11.0 }, { 1.0/9.4, 15.0 } }, { { 1.0/10.6, 26.0 }, { 1.0/9.8, 30.0 } } }, { 101700.0, 40.0, { 1.141, 13.0 }, { 2.5, -250.0 }, { 35.0, 800.0 }, { 1.0/7.19, 1.1 }, { { 1.45, 11.8 }, { 1.65, 0.0 } }, { { 2.93, 13.0 }, { 3.0, 12.0 } }, { { 1.0/12.2, 0.32 }, { 1.0/12.2, 0.32 } }, { { 1.0/23.2, 0.2 }, { 1.0/23.2, 0.20 } }, { { 1.0/7.0, 16.5 }, { 1.0/6.85, 13.0 } }, { { 1.0/7.15, 30.0 }, { 1.0/6.87, 23.0 } }, { { 1.0/7.45, 28.0 }, { 1.0/7.25, 18.2 } }, { { 1.0/7.55, 37.0 }, { 1.0/7.25, 29.0 } } }, { 101800.0, 56.0, { 1.127, 12.0 }, { 2.5, -250.0 }, { 35.0, 1000.0 }, { 1.0/3.52, 0.0 }, { { 1.41, 13.0 }, { 1.4, 17.0 } }, { { 2.73, 25.0 }, { 2.73, 30.0 } }, { { 1.0/8.15, 0.25 }, { 1.0/8.15, 0.25 } }, { { 1.0/16.0, 0.4 }, { 1.0/15.0, 0.4 } }, { { 1.0/4.87, 19.0 }, { 1.0/4.55, 17.0 } }, { { 1.0/4.78, 52.0 }, { 1.0/4.55, 55.0 } }, { { 1.0/5.15, 29.0 }, { 1.0/4.8, 26.0 } }, { { 1.0/4.78, 52.0 }, { 1.0/4.55, 55.0 } } }, /*STAY1200_USB double m_infreq; double m_appp_offset; double m_involt193[2]; double m_involt194[2]; double m_incurr[2]; double m_battvolt[2]; double m_outvolt_s[2][2]; double m_outvolt_i[2][2]; double m_outcurr_s[2][2]; double m_outcurr_i[2][2]; double m_utilp_s[2][2]; double m_utilp_i[2][2]; double m_appp_s[2][2]; double m_appp_i[2][2]; */ { 101800.0, /* m_infreq */ 56.0, /* m_appp_offset */ { 1.64, 9.34 }, /* m_involt193 - ok */ { 2.5, -250.0 }, /* m_involt194 */ { 35.0, 1000.0 }, /* m_incurr */ { 0.1551, 0.2525 }, /* m_battvolt */ { { 1.41, 13.0 }, { 1.4, 17.0 } }, /* m_outvolt_s */ { { 2.73, 25.0 }, { 2.73, 30.0 } }, /* m_outvolt_i */ { { 1.0/8.15, 0.25 }, { 1.0/8.15, 0.25 } }, /* m_outcurr_s */ { { 1.0/16.0, 0.4 }, { 1.0/15.0, 0.4 } }, /* m_outcurr_i */ { { 1.0/4.87, 19.0 }, { 1.0/4.55, 17.0 } }, /* m_utilp_s */ { { 1.0/4.78, 52.0 }, { 1.0/4.55, 55.0 } }, /* m_utilp_i */ { { 1.0/5.15, 29.0 }, { 1.0/4.8, 26.0 } }, /* m__app_s */ { { 1.0/4.78, 52.0 }, { 1.0/4.55, 55.0 } } /* m_app_i */ } }; /* Date, time and programming group */ static int const BASE_YEAR = 1998; /* Note: code below uses relative "unsigned char" years */ static int Day, Month, Year; static int isprogram = 0, progshut = 0, prgups = 0; static int dian=0, mesn=0, anon=0, weekn=0; static int dhour, dmin, lhour, lmin, ihour,imin, isec, hourshut, minshut; static uint8_t DaysOnWeek=0, DaysOffWeek=0, DaysStd = 0; static char seman[4]; /* buffers */ static unsigned char RecPack[PACKET_SIZE]; static unsigned char ConfigPack[12]; /* unsigned char MibData[161]; unsigned char DumpPack[242]; */ /* Identification */ static const char *Model; static int SolisModel, imodel; static int InputValue, Out220; /* Status group */ static unsigned char InputStatus,OutputStatus, BattStatus; /* Events group */ static unsigned char SourceEvents, OutputEvents, BattEvents; /* logical */ static bool_t detected = 0; static bool_t SourceFail, SourceLast, FailureFlag, SourceReturn, SuperHeat; static bool_t SuperHeatLast, OverCharge, OverChargeLast, LowBatt; static bool_t CriticBatt, CriticBattLast, Flag_inversor, InversorOn, InversorOnLast; /* Input group */ static double InVoltage, InCurrent, InFreq; static double InDownLim, InUpLim, NomInVolt; /* Output group */ static double OutVoltage, OutCurrent, OutFreq, OutDownLim, OutUpLim, NomOutVolt; /* Battery group */ static int Autonomy, BattExtension, maxauto; static double BattVoltage, Temperature, batcharge; /* Power group */ static double AppPower, UtilPower, upscharge; static int ChargePowerFactor, NominalPower, UpsPowerFactor; static void print_info(void); static int is_today( unsigned char, int ); static void autonomy_calc( int ); static void scan_received_pack(void); static void comm_receive(const unsigned char*, size_t); static void get_base_info(void); static void get_update_info(void); #endif /* INCLUDED_SOLIS_H */ nut-2.8.4/drivers/apc-hid.h0000644000175000017500000000221714670526611012422 00000000000000/* apc-hid.h - data to monitor APC USB/HID devices with NUT * * Copyright (C) * 2003 - 2005 Arnaud Quette * 2005 John Stamp * 2005 Peter Selinger * * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef APC_HID_H #define APC_HID_H #include "usbhid-ups.h" extern subdriver_t apc_subdriver; #endif /* APC_HID_H */ nut-2.8.4/drivers/solis.c0000644000175000017500000006565415044656702012260 00000000000000/* solis.c - driver for Microsol Solis UPS hardware Copyright (C) 2004 Silvino B. Magalhães 2019 Roberto Panerai Velloso This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2004/10/10 - Version 0.10 - Initial release 2004/10/20 - Version 0.20 - add Battery information in driver 2004/10/26 - Version 0.30 - add commands and test shutdown 2004/10/30 - Version 0.40 - add model data structs 2005/06/30 - Version 0.41 - patch for solaris compability 2005/07/01 - Version 0.50 - add internal e external shutdown programming 2005/08/18 - Version 0.60 - save external shutdown programming to ups, and support new cables for solis 3 2015/09/19 - Version 0.65 - patch for correct reading for Microsol Back-Ups BZ1200-BR 2017/12/21 - Version 0.66 - remove memory leaks (unfreed strdup()s); remove ser_flush_in calls that were causing desync issues; other minor improvements in source code. (see the version control logs for more recent updates) Microsol contributed with UPS Solis 1.5 HS 1.5 KVA for my tests. http://www.microsol.com.br */ #include "main.h" /* Includes "config.h", must be first */ #include #include #include "nut_stdint.h" #include "serial.h" #include "nut_float.h" #include "solis.h" #include "timehead.h" #define DRIVER_NAME "Microsol Solis UPS driver" #define DRIVER_VERSION "0.72" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Silvino B. Magalhães " \ "Roberto Panerai Velloso ", DRV_STABLE, { NULL } }; #define false 0 #define true 1 #define RESP_END 0xFE #define ENDCHAR 13 /* replies end with CR */ /* solis commands */ #define CMD_UPSCONT 0xCC #define CMD_SHUT 0xDD #define CMD_SHUTRET 0xDE #define CMD_EVENT 0xCE #define CMD_DUMP 0xCD /* comment on english language */ /* #define PORTUGUESE */ /* The following Portuguese strings are in UTF-8. */ #ifdef PORTUGUESE #define M_UNKN "Modêlo solis desconhecido\n" #define NO_SOLIS "Solis não detectado! abortando ...\n" #define UPS_DATE "Data no UPS %4d/%02d/%02d\n" #define SYS_DATE "Data do Sistema %4d/%02d/%02d dia da semana %s\n" #define ERR_PACK "Pacote errado\n" #define NO_EVENT "Não há eventos\n" #define UPS_TIME "Hora interna UPS %0d:%02d:%02d\n" #define PRG_DAYS "Shutdown Programavel Dom Seg Ter Qua Qui Sex Sab\n" #define PRG_ONON "Programação shutdown ativa externa\n" #define PRG_ONOU "Programação shutdown ativa interna\n" #define TIME_OFF "UPS Hora desligar %02d:%02d\n" #define TIME_ON "UPS Hora ligar %02d:%02d\n" #define PRG_ONOF "Programação shutdown desativada\n" #define TODAY_DD "Desligamento hoje as %02d:%02d\n" #define SHUT_NOW "Shutdown iminente!\n" #else #define M_UNKN "Unknown solis model\n" #define NO_SOLIS "Solis not detected! aborting ...\n" #define UPS_DATE "UPS Date %4d/%02d/%02d\n" #define SYS_DATE "System Date %4d/%02d/%02d day of week %s\n" #define ERR_PACK "Wrong package\n" #define NO_EVENT "No events\n" #define UPS_TIME "UPS internal Time %0d:%02d:%02d\n" #define PRG_DAYS "Programming Shutdown Sun Mon Tue Wed Thu Fri Sat\n" #define PRG_ONON "External shutdown programming active\n" #define PRG_ONOU "Internal shutdown programming atcive\n" #define TIME_OFF "UPS Time power off %02d:%02d\n" #define TIME_ON "UPS Time power on %02d:%02d\n" #define PRG_ONOF "Shutdown programming not activated\n" #define TODAY_DD "Shutdown today at %02d:%02d\n" #define SHUT_NOW "Shutdown now!\n" #endif #define FMT_DAYS " %d %d %d %d %d %d %d\n" /* convert standard days string to firmware format */ static char* convert_days(char *cop) { static char alt[8]; int ish, fim; if (weekn >= 6 || weekn < 0) ish = 0; else ish = 1 + weekn; fim = 7 - ish; /* rotate left only 7 bits */ memcpy(alt, &cop[ish], (size_t)fim); if (ish > 0) memcpy(&alt[fim], cop, (size_t)ish); alt[7] = 0; /* string terminator */ return alt; } inline static int is_binary(char ch ) { return ( ch == '1' || ch == '0' ); } /* convert string to binary */ static uint8_t str2bin( char *binStr ) { uint8_t result = 0; int i; for (i = 0; i < 7; ++i) { char ch = binStr[i]; if (is_binary(ch)) result += ( (ch - '0') << (6 - i) ); else return 0; } return result; } /* revert firmware format to standard string binary days */ static uint8_t revert_days(unsigned char dweek) { char alt[8]; int i; for (i = 0; i < (6 - weekn); ++i) alt[i] = (dweek >> (5 - weekn - i)) & 0x01; for (i = 0; i < weekn+1; ++i) alt[i+(6-weekn)] = (dweek >> (6 - i)) & 0x01; for (i=0; i < 7; i++) alt[i] += '0'; alt[7] = 0; /* string terminator */ return str2bin(alt); } static int is_hour(char *hour, int qual) { int hora, min; if ((strlen(hour) != 5) || (sscanf(hour, "%d:%d", &hora, &min) != 2)) return -1; if (qual) { dhour = hora; dmin = min; } else { lhour = hora; lmin = min; } return 1; } static void send_shutdown( void ) { int i; for (i = 0; i < 10; i++) ser_send_char(upsfd, CMD_SHUT ); upslogx(LOG_NOTICE, "Ups shutdown command sent"); printf("Ups shutdown command sent\n"); } /* save config ups */ static void save_ups_config( void ) { int i, chks = 0; /* FIXME? Check for overflows with int => char truncations? * See also microsol-common.c for very similar code */ ConfigPack[0] = (unsigned char)0xCF; ConfigPack[1] = (unsigned char)ihour; ConfigPack[2] = (unsigned char)imin; ConfigPack[3] = (unsigned char)isec; ConfigPack[4] = (unsigned char)lhour; ConfigPack[5] = (unsigned char)lmin; ConfigPack[6] = (unsigned char)dhour; ConfigPack[7] = (unsigned char)dmin; ConfigPack[8] = (unsigned char)(weekn << 5); ConfigPack[8] = (unsigned char)ConfigPack[8] | (unsigned char)dian; ConfigPack[9] = (unsigned char)(mesn << 4); ConfigPack[9] = (unsigned char)ConfigPack[9] | (unsigned char)( anon - BASE_YEAR ); ConfigPack[10] = (unsigned char)DaysOffWeek; /* MSB zero */ ConfigPack[10] = ConfigPack[10] & (~(0x80)); for (i=0; i < 11; i++) chks += ConfigPack[i]; /* FIXME? Does truncation to char have same effect as %256 ? */ ConfigPack[11] = (unsigned char)(chks % 256); for (i=0; i < 12; i++) ser_send_char(upsfd, ConfigPack[i]); } /* print UPS internal variables */ static void print_info( void ) { printf(UPS_DATE, Year, Month, Day); printf(SYS_DATE, anon, mesn, dian, seman); printf(UPS_TIME, ihour, imin, isec); if (prgups > 0) { /*sunday, monday, tuesday, wednesday, thursday, friday, saturday*/ int week_days[7] = {0, 0, 0, 0, 0, 0, 0}; int i; /* this is the string to binary standard */ for (i = 0; i < 7; ++i) week_days[i] = (DaysStd >> (6 - i)) & 0x01; if (prgups == 3) printf(PRG_ONOU); else printf(PRG_ONON); printf(TIME_ON, lhour, lmin); printf(TIME_OFF, dhour, dmin); printf(PRG_DAYS); printf(FMT_DAYS, week_days[0], week_days[1], week_days[2], week_days[3], week_days[4], week_days[5], week_days[6]); } else printf(PRG_ONOF); } /* is today shutdown day ? */ inline static int is_today( unsigned char dweek, int nweek) { return (dweek >> (6 - nweek)) & 0x01; } /* all models */ static void autonomy_calc( int iauto ) { int indice, indd, lim, min, max, inf, sup, indc, bx, ipo = 0; bx = bext[iauto]; indice = RecPack[3]; indd = indice - 139; if (UtilPower > 20) ipo = (UtilPower - 51) / 100; indc = auton[iauto].maxi; if( ipo > indc ) return; min = auton[iauto].minc[ipo]; inf = min - 1; max = auton[iauto].maxc[ipo]; lim = max - 139; sup = max + 1; if (UtilPower <= 20) { Autonomy = 170; maxauto = 170; } else { maxauto = auton[iauto].mm[ipo][lim]; if( indice > inf && indice < sup ) Autonomy = auton[iauto].mm[ipo][indd]; else { if (indice > max) Autonomy = maxauto; if (indice < min) Autonomy = 0; } } if (BattExtension > 0 && iauto < 4) Autonomy = ( Autonomy * ( BattExtension + bx ) * 1.0 / bx ); } static void scan_received_pack(void) { int aux, im, ov; /* model independent data */ Year = (RecPack[ 19 ] & 0x0F) + BASE_YEAR; Month = (RecPack[ 19 ] & 0xF0) >> 4; Day = (RecPack[ 18 ] & 0x1F); DaysOnWeek = RecPack[17]; /* Days of week if in UPS shutdown programming mode */ if (prgups == 3) { DaysStd = revert_days( DaysOnWeek ); /* time for programming UPS off */ dhour = RecPack[15]; dmin = RecPack[16]; /* time for programming UPS on */ lhour = RecPack[13]; lmin = RecPack[14]; } /* UPS internal time */ ihour = RecPack[11]; imin = RecPack[10]; isec = RecPack[9]; if ((0x01 & RecPack[20]) == 0x01) Out220 = 1; CriticBatt = (0x04 & RecPack[20]) == 0x04; InversorOn = (0x08 & RecPack[20]) == 0x08; SuperHeat = (0x10 & RecPack[20]) == 0x10; SourceFail = (0x20 & RecPack[20]) == 0x20; OverCharge = (0x80 & RecPack[20]) == 0x80; if ((0x40 & RecPack[20]) == 0x40) InputValue = 1; else InputValue = 0; Temperature = 0x7F & RecPack[4]; if (0x80 & RecPack[4]) Temperature -= 128; /* model dependent data */ im = inds[imodel]; ov = Out220; if (SolisModel != 16) { if (RecPack[6] >= 194) InVoltage = RecPack[6] * ctab[imodel].m_involt194[0] + ctab[imodel].m_involt194[1]; else InVoltage = RecPack[6] * ctab[imodel].m_involt193[0] + ctab[imodel].m_involt193[1]; } else { /* Code InVoltage for STAY1200_USB */ if ((RecPack[20] & 0x1) == 0) /* IsOutVoltage 220 */ InVoltage = RecPack[2] * ctab[imodel].m_involt193[0] + ctab[imodel].m_involt193[1]; else InVoltage = RecPack[2] * ctab[imodel].m_involt193[0] + ctab[imodel].m_involt193[1] - 3.0; } BattVoltage = RecPack[ 3 ] * ctab[imodel].m_battvolt[0] + ctab[imodel].m_battvolt[1]; NominalPower = nompow[im]; if (SourceFail) { OutVoltage = RecPack[ 1 ] * ctab[imodel].m_outvolt_i[ov][0] + ctab[imodel].m_outvolt_i[ov][1]; OutCurrent = RecPack[ 5 ] * ctab[imodel].m_outcurr_i[ov][0] + ctab[imodel].m_outcurr_i[ov][1]; AppPower = ( RecPack[ 5 ] * RecPack[ 1 ] ) * ctab[imodel].m_appp_i[ov][0] + ctab[imodel].m_appp_i[ov][1]; UtilPower = ( RecPack[ 7 ] + RecPack[ 8 ] * 256 ) * ctab[imodel].m_utilp_i[ov][0] + ctab[imodel].m_utilp_i[ov][1]; InCurrent = 0; } else { OutVoltage = RecPack[ 1 ] * ctab[imodel].m_outvolt_s[ov][0] + ctab[imodel].m_outvolt_s[ov][1]; OutCurrent = RecPack[ 5 ] * ctab[imodel].m_outcurr_s[ov][0] + ctab[imodel].m_outcurr_s[ov][1]; AppPower = ( RecPack[ 5 ] * RecPack[ 1 ] ) * ctab[imodel].m_appp_s[ov][0] + ctab[imodel].m_appp_s[ov][1]; UtilPower = ( RecPack[ 7 ] + RecPack[ 8 ] * 256 ) * ctab[imodel].m_utilp_s[ov][0] + ctab[imodel].m_utilp_s[ov][1]; InCurrent = ( ctab[imodel].m_incurr[0] * 1.0 / BattVoltage ) - ( AppPower * 1.0 / ctab[imodel].m_incurr[1] ) + OutCurrent *( OutVoltage * 1.0 / InVoltage ); } if (SolisModel == 16) { int configRelay = (RecPack[6] & 0x38) >> 3; double TENSAO_SAIDA_F1_MR[8] = { 1.1549, 1.0925, 0.0, 0.0, 1.0929, 1.0885, 0.0, 0.8654262224145391 }; double TENSAO_SAIDA_F2_MR[8] = { -6.9157, 11.026, 10.43, 0.0, -0.6109, 12.18, 0.0, 13.677}; const double TENSAO_SAIDA_F2_MI[8] ={ 5.59, 9.47, 13.7, 0.0, 0.0, 0.0, 0.0, 0.0 }; const double TENSAO_SAIDA_F1_MI[8] = { 7.9, 9.1, 17.6, 0.0, 0.0, 0.0, 0.0, 0.0 }; const double corrente_saida_F1_MR = 0.12970000389100012; const double corrente_saida_F2_MR = 0.5387060281204546; /* double corrente_saida_F1_MI = 0.1372; double corrente_saida_F2_MI = 0.3456; */ if (SourceFail) { if (RecPack[20] == 0) { double a = RecPack[1] * 2; a /= 128.0; /* a = double sqrt(a); */ OutVoltage = RecPack[1] * a * TENSAO_SAIDA_F1_MI[configRelay] + TENSAO_SAIDA_F2_MI[configRelay]; } } else { double RealPower, potVA1, potVA2, potLin, potRe; OutCurrent = (float)(corrente_saida_F1_MR * RecPack[5] + corrente_saida_F2_MR); OutVoltage = RecPack[1] * TENSAO_SAIDA_F1_MR[configRelay] + TENSAO_SAIDA_F2_MR[configRelay]; AppPower = OutCurrent * OutVoltage; RealPower = (RecPack[7] + RecPack[8] * 256); potVA1 = 5.968 * AppPower - 284.36; potVA2 = 7.149 * AppPower - 567.18; potLin = 0.1664 * RealPower + 49.182; potRe = 0.1519 * RealPower + 32.644; if (fabs(potVA1 - RealPower) < fabs(potVA2 - RealPower)) RealPower = potLin; else RealPower = potRe; if (OutCurrent < 0.7) RealPower = AppPower; if (AppPower < RealPower) { double f = AppPower; AppPower = RealPower; RealPower = f; } } } aux = (RecPack[ 21 ] + RecPack[ 22 ] * 256); if (aux > 0) InFreq = ctab[imodel].m_infreq * 1.0 / aux; /* Specific for STAY1200_USB */ if (SolisModel == 16) { InFreq = ((float)(0.37 * (257 - (aux >> 8)))); } else InFreq = 0; /* input voltage offset */ if (InVoltage < InVolt_offset) { /* all is equal 30 */ InFreq = 0; InVoltage = 0; InCurrent = 0; } /* app power offset */ if (AppPower < ctab[imodel].m_appp_offset) { AppPower = 0; UtilPower = 0; ChargePowerFactor = 0; OutCurrent = 0; } if (im < 3) autonomy_calc(im); else { if (BattExtension == 80 && im == 3) autonomy_calc(im + 1); else autonomy_calc(im); } /* model independent data */ batcharge = ( Autonomy / maxauto ) * 100.0; upscharge = ( AppPower / NominalPower ) * 100.0; if (batcharge > 100.0) batcharge = 100.0; OutFreq = 60; if (!InversorOn) { OutVoltage = 0; OutFreq = 0; } if (!SourceFail && InversorOn) OutFreq = InFreq; if (AppPower < 0) /* charge pf */ ChargePowerFactor = 0; else { if( d_equal(AppPower, 0) ) ChargePowerFactor = 100; else ChargePowerFactor = (( UtilPower / AppPower) * 100); if(ChargePowerFactor > 100) ChargePowerFactor = 100; } if (SourceFail && SourceLast) /* first time failure */ FailureFlag = true; /* source return */ if (!SourceFail && !SourceLast) { SourceReturn = true; /* clean port: */ /* ser_flush_in(upsfd,"",0); */ } if((!SourceFail) == SourceLast) { SourceReturn = false; FailureFlag = false; } SourceLast = !SourceFail; /* Autonomy */ if (Autonomy < 5) LowBatt = true; else LowBatt = false; UpsPowerFactor = 700; /* input 110V or 220v */ if (InputValue == 0) { InDownLim = 75; InUpLim = 150; NomInVolt = 110; } else { InDownLim = 150; InUpLim = 300; NomInVolt = 220; } /* output volage 220V or 110V */ if (Out220) { OutDownLim = 190; OutUpLim = 250; NomOutVolt = 220; } else { OutDownLim = 100; OutUpLim = 140; NomOutVolt = 110; } if (SourceFail) /* source status */ InputStatus = 2; else InputStatus = 1; if (InversorOn) /* output status */ OutputStatus = 1; else OutputStatus = 2; if (OverCharge) OutputStatus = 3; if (CriticBatt) /* battery status */ BattStatus = 4; else BattStatus = 1; SourceEvents = 0; if (FailureFlag) SourceEvents = 1; if (SourceReturn) SourceEvents = 2; /* verify Inversor */ if (Flag_inversor) { InversorOnLast = InversorOn; Flag_inversor = false; } OutputEvents = 0; if (InversorOn && !InversorOnLast) OutputEvents = 26; if (InversorOnLast && !InversorOn) OutputEvents = 27; InversorOnLast = InversorOn; if (SuperHeat && !SuperHeatLast) OutputEvents = 12; if (SuperHeatLast && !SuperHeat) OutputEvents = 13; SuperHeatLast = SuperHeat; if (OverCharge && !OverChargeLast) OutputEvents = 10; if (OverChargeLast && !OverCharge) OutputEvents = 11; OverChargeLast = OverCharge; BattEvents = 0; CriticBattLast = CriticBatt; } static void comm_receive(const unsigned char *bufptr, size_t size) { if (size == packet_size) { int CheckSum = 0; size_t i; memcpy(RecPack, bufptr, packet_size); if (nut_debug_level >= 3) upsdebug_hex(3, "comm_receive: RecPack", RecPack, size); /* CheckSum verify */ for (i = 0 ; i < packet_size-2 ; ++i ) CheckSum += RecPack[i]; CheckSum = CheckSum % 256; upsdebugx(4, "%s: calculated checksum = 0x%02x, RecPack[23] = 0x%02x", __func__, (unsigned int)CheckSum, RecPack[23]); /* clean port: */ /* ser_flush_in(upsfd,"",0); */ /* RecPack[0] == model number below: * SOLIS = 1; * RHINO = 2; * STAY = 3; * SOLIS_LI_700 = 169; * SOLIS_M11 = 171; * SOLIS_M15 = 175; * SOLIS_M14 = 174; * SOLIS_M13 = 173; * SOLISDC_M14 = 201; * SOLISDC_M13 = 206; * SOLISDC_M15 = 207; * CABECALHO_RHINO = 194; * PS800 = 185; * STAY1200_USB = 186; * PS350_CII = 184; * PS2200 = 187; * PS2200_22 = 188; * STAY700_USB = 189; * BZ1500 = 190; */ if ((((RecPack[0] & 0xF0) == 0xA0 ) || (RecPack[0] & 0xF0) == 0xB0) && (RecPack[24] == 254) && (RecPack[23] == CheckSum)) { if (!detected) { if (RecPack[0] == 186) SolisModel = 16; else SolisModel = (int) (RecPack[0] & 0x0F); if (SolisModel < 13) imodel = SolisModel - 10; /* 10 = 0, 11 = 1 */ else imodel = SolisModel - 11; /* 13 = 2, 14 = 3, 15 = 4 */ detected = true; } switch (SolisModel) { case 10: case 11: case 12: case 13: case 14: case 15: scan_received_pack(); break; case 16: /* STAY1200_USB model */ scan_received_pack(); break; default: printf(M_UNKN); scan_received_pack(); /* Scan anyway. */ break; } } } } static void get_base_info(void) { #ifdef PORTUGUESE const char DaysOfWeek[7][4]={"Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"}; #else const char DaysOfWeek[7][4]={"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; #endif unsigned char packet[PACKET_SIZE], syncEOR = '\0', syncEOR_was_read = 0; int i1=0, i2=0; size_t i; ssize_t tam; time_t tmt; struct tm *now; struct tm tmbuf; time(&tmt); now = localtime_r(&tmt, &tmbuf); dian = now->tm_mday; mesn = now->tm_mon+1; anon = now->tm_year+1900; ihour = now->tm_hour; imin = now->tm_min; isec = now->tm_sec; weekn = now->tm_wday; strcpy(seman, DaysOfWeek[weekn]); if (testvar("battext")) BattExtension = atoi(getval("battext")); if (testvar("prgshut")) prgups = atoi(getval("prgshut")); if (prgups > 0 && prgups < 3) { if (testvar("daysweek")) DaysOnWeek = str2bin(convert_days(getval("daysweek"))); if (testvar("daysoff")) { char *doff = getval("daysoff"); DaysStd = str2bin(doff); DaysOffWeek = str2bin( convert_days(doff)); } if (testvar("houron")) i1 = is_hour(getval("houron"), 0); if (testvar("houroff")) i2 = is_hour(getval("houroff"), 1); if (i1 == 1 && i2 == 1 && (DaysOnWeek > 0)) { isprogram = 1; /* prgups == 1 ou 2 */ if (prgups == 2) save_ups_config(); /* save ups config */ } else { if (i2 == 1 && DaysOffWeek > 0) { isprogram = 1; DaysOnWeek = DaysOffWeek; } } } /* end prgups 1 - 2 */ /* dummy read attempt to sync - throw it out */ upsdebugx(3, "%s: sending CMD_UPSCONT and ENDCHAR to sync", __func__); ser_send(upsfd, "%c%c", CMD_UPSCONT, ENDCHAR); /* * - Read until end-of-response character (0xFE): * read up to 3 packets in size before giving up * synchronizing with the device. */ for (i = 0; i < packet_size*3; i++) { ser_get_char(upsfd, &syncEOR, 3, 0); syncEOR_was_read = 1; if(syncEOR == RESP_END) break; } if (!syncEOR_was_read || syncEOR != RESP_END) { /* synchronization failed */ fatalx(EXIT_FAILURE, NO_SOLIS); } else { upsdebugx(4, "%s: requesting %" PRIuSIZE " bytes from ser_get_buf_len()", __func__, packet_size); tam = ser_get_buf_len(upsfd, packet, packet_size, 3, 0); if (tam < 0) { upsdebugx(0, "%s: Error (%" PRIiSIZE ") reading from ser_get_buf_len()", __func__, tam); fatalx(EXIT_FAILURE, NO_SOLIS); } upsdebugx(2, "%s: received %" PRIiSIZE " bytes from ser_get_buf_len()", __func__, tam); if (tam > 0 && nut_debug_level >= 4) { upsdebug_hex(4, "received from ser_get_buf_len()", packet, (size_t)tam); } comm_receive(packet, (size_t)tam); } if (!detected) fatalx(EXIT_FAILURE, NO_SOLIS ); switch (SolisModel) { case 10: case 11: case 12: Model = "Solis 1.0"; break; case 13: Model = "Solis 1.5"; break; case 14: Model = "Solis 2.0"; break; case 15: Model = "Solis 3.0"; break; case 16: Model = "Microsol Back-Ups BZ1200-BR"; break; default: break; } /* if( isprogram ) */ if (prgups == 1) { hourshut = dhour; minshut = dmin; } else { if (prgups == 2 || prgups == 3) { /* broadcast before firmware shutdown */ if (dmin < 5) { if (dhour > 1) hourshut = dhour - 1; else hourshut = 23; minshut = 60 - ( 5 - dmin ); } else { hourshut = dhour; minshut = dmin - 5; } } } /* manufacturer */ dstate_setinfo("ups.mfr", "%s", "Microsol"); dstate_setinfo("ups.model", "%s", Model); dstate_setinfo("input.transfer.low", "%03.1f", InDownLim); dstate_setinfo("input.transfer.high", "%03.1f", InUpLim); dstate_addcmd("shutdown.return"); /* CMD_SHUTRET */ dstate_addcmd("shutdown.stayoff"); /* CMD_SHUT */ printf("Detected %s on %s\n", dstate_getinfo("ups.model"), device_path); print_info(); } static void get_update_info(void) { unsigned char temp[256]; int isday, hourn, minn; ssize_t tam; /* time update and programable shutdown block */ time_t tmt; struct tm *now; struct tm tmbuf; time(&tmt); now = localtime_r(&tmt, &tmbuf); hourn = now->tm_hour; minn = now->tm_min; weekn = now->tm_wday; if (isprogram || prgups == 3) { if (isprogram) isday = is_today(DaysStd, weekn); else isday = is_today( DaysStd, weekn); if (isday) printf(TODAY_DD, hourshut, minshut); if ( (hourn == hourshut) && (minn >= minshut) && isday) { printf( SHUT_NOW ); progshut = 1; } } /* programable shutdown end block */ /* get update package */ temp[0] = 0; /* flush temp buffer */ upsdebugx(3, "%s: requesting %" PRIuSIZE " bytes from ser_get_buf_len()", __func__, packet_size); tam = ser_get_buf_len(upsfd, temp, packet_size, 3, 0); if (tam < 0) { upsdebugx(0, "%s: Error (%" PRIiSIZE ") reading from ser_get_buf_len()", __func__, tam); fatalx(EXIT_FAILURE, NO_SOLIS); } upsdebugx(2, "%s: received %" PRIiSIZE " bytes from ser_get_buf_len()", __func__, tam); if(tam > 0 && nut_debug_level >= 4) upsdebug_hex(4, "received from ser_get_buf_len()", temp, (size_t)tam); comm_receive(temp, (size_t)tam); } static int instcmd(const char *cmdname, const char *extra) { /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "shutdown.return")) { /* shutdown and restart */ /* FIXME: check with HW if this is not * a "shutdown.reboot" instead (or also)? */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ser_send_char(upsfd, CMD_SHUTRET); /* 0xDE */ /* ser_send_char(upsfd, ENDCHAR); */ return STAT_INSTCMD_HANDLED; } if (!strcasecmp(cmdname, "shutdown.stayoff")) { /* shutdown now (one way) */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); ser_send_char(upsfd, CMD_SHUT); /* 0xDD */ /* ser_send_char(upsfd, ENDCHAR); */ return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } void upsdrv_initinfo(void) { get_base_info(); upsh.instcmd = instcmd; } void upsdrv_updateinfo(void) { get_update_info(); /* new package for updates */ dstate_setinfo("output.voltage", "%03.1f", OutVoltage); dstate_setinfo("input.voltage", "%03.1f", InVoltage); dstate_setinfo("battery.voltage", "%02.1f", BattVoltage); dstate_setinfo("battery.charge", "%03.1f", batcharge); dstate_setinfo("output.current", "%03.1f", OutCurrent); status_init(); if (!SourceFail) status_set("OL"); /* on line */ else status_set("OB"); /* on battery */ if (Autonomy < 5) status_set("LB"); /* low battery */ if (progshut) { /* software programable shutdown immediately */ if( prgups == 2 ) send_shutdown(); /* Ups shutdown in 4-5 minutes -- redundant Ups shutdown */ status_set("LB"); /* no low battery but is a force shutdown */ } status_commit(); dstate_setinfo("ups.temperature", "%2.2f", Temperature); dstate_setinfo("input.frequency", "%2.1f", InFreq); dstate_setinfo("ups.load", "%03.1f", upscharge); dstate_dataok(); } /*! @brief Power down the attached load immediately. * Basic idea: find out line status and send appropriate command. * - on battery: send normal shutdown, UPS will return by itself on utility * - on line: send shutdown+return, UPS will cycle and return soon. */ void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ if (!SourceFail) { /* on line */ upslog_INSTCMD_POWERSTATE_CHANGE("shutdown.return", (char *)NULL); upslogx(LOG_NOTICE, "On line, sending shutdown+return command...\n"); ser_send_char(upsfd, CMD_SHUTRET ); /* Seems AKA: instcmd("shutdown.return", NULL); */ } else { upslog_INSTCMD_POWERSTATE_CHANGE("shutdown.stayoff", (char *)NULL); upslogx(LOG_NOTICE, "On battery, sending normal shutdown command...\n"); ser_send_char(upsfd, CMD_SHUT); /* Seems AKA: instcmd("shutdown.stayoff", NULL); */ } } void upsdrv_help(void) { printf("\nSolis options\n"); printf(" Battery Extension in AH\n"); printf(" battext = 80\n"); printf(" Programable UPS power on/off\n"); printf(" prgshut = 0 (default, no software programable shutdown)\n"); printf(" prgshut = 1 (software programable shutdown without UPS power off)\n"); printf(" prgshut = 2 (software programable shutdown with UPS power off)\n"); printf(" prgshut = 3 (activate UPS programable power on/off)\n"); printf(" Otherwise uses:\n"); printf(" daysweek = 1010101 ( power on days )\n"); printf(" daysoff = 1010101 ( power off days )\n"); printf(" where each digit is a day from sun...sat with 0 = off and 1 = on\n"); printf(" houron = hh:mm hh = hour 0-23 mm = minute 0-59 separated with :\n"); printf(" houroff = hh:mm hh = hour 0-23 mm = minute 0-59 separated with :\n"); printf(" where houron is power-on hour and houroff is shutdown and power-off hour\n"); printf(" Uses daysweek and houron to programming and save UPS power on/off\n"); printf(" These are valid only if prgshut = 2 or 3\n"); } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "battext", "Battery Extension (0-80)min"); addvar(VAR_VALUE, "prgshut", "Programable power off (0-3)"); addvar(VAR_VALUE, "daysweek", "Days of week UPS power of/off"); addvar(VAR_VALUE, "daysoff", "Days of week Driver shutdown"); addvar(VAR_VALUE, "houron", "Power on hour (hh:mm)"); addvar(VAR_VALUE, "houroff", "Power off hour (hh:mm)"); } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B9600); ser_set_dtr(upsfd, 1); ser_set_rts(upsfd, 0); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/nutdrv_qx_megatec-old.h0000644000175000017500000000201114670526611015400 00000000000000/* nutdrv_qx_megatec-old.h - Subdriver for Megatec/old protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef NUTDRV_QX_MEGATEC_OLD_H #define NUTDRV_QX_MEGATEC_OLD_H #include "nutdrv_qx.h" extern subdriver_t megatec_old_subdriver; #endif /* NUTDRV_QX_MEGATECH_OLD_H */ nut-2.8.4/drivers/hidtypes.h0000664000175000017500000003050215000733203012727 00000000000000/* * types.h: HID Parser types definitions * * This file is part of the MGE UPS SYSTEMS HID Parser * * Copyright (C) * 1998-2003 MGE UPS SYSTEMS, Luc Descotils * 2015 Eaton, Arnaud Quette (Update MAX_REPORT) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * -------------------------------------------------------------------------- */ #ifndef HIDTYPES_H #define HIDTYPES_H #ifdef __cplusplus /* *INDENT-OFF* */ extern "C" { /* *INDENT-ON* */ #endif /* __cplusplus */ #include #include "nut_stdint.h" #include "nut_bool.h" /* * Constants * -------------------------------------------------------------------------- */ #define PATH_SIZE 10 /* Deep max for Path */ #define USAGE_TAB_SIZE 50 /* Size of usage stack */ #define MAX_REPORT 500 /* Including FEATURE, INPUT and OUTPUT */ #define REPORT_DSC_SIZE 6144 /* Size max of Report Descriptor */ #define MAX_REPORT_TS 3 /* Max time validity of a report */ /* * Items * -------------------------------------------------------------------------- */ #define SIZE_0 0x00 #define SIZE_1 0x01 #define SIZE_2 0x02 #define SIZE_4 0x03 #define SIZE_MASK 0x03 #define TYPE_MAIN 0x00 #define TYPE_GLOBAL 0x04 #define TYPE_LOCAL 0x08 #define TYPE_MASK 0x0C /* Main items */ #define ITEM_COLLECTION 0xA0 #define ITEM_END_COLLECTION 0xC0 #define ITEM_FEATURE 0xB0 #define ITEM_INPUT 0x80 #define ITEM_OUTPUT 0x90 /* Global items */ #define ITEM_UPAGE 0x04 #define ITEM_LOG_MIN 0x14 #define ITEM_LOG_MAX 0x24 #define ITEM_PHY_MIN 0x34 #define ITEM_PHY_MAX 0x44 #define ITEM_UNIT_EXP 0x54 #define ITEM_UNIT 0x64 #define ITEM_REP_SIZE 0x74 #define ITEM_REP_ID 0x84 #define ITEM_REP_COUNT 0x94 /* Local items */ #define ITEM_USAGE 0x08 #define ITEM_STRING 0x78 /* Long item */ #define ITEM_LONG 0xFC #define ITEM_MASK 0xFC /* Attribute Flags */ #define ATTR_DATA_CST 0x01 #define ATTR_NVOL_VOL 0x80 /* Usage Pages */ /* For more details, please see docs/hid-subdrivers.txt */ #define PAGE_POWER_DEVICE 0x84 #define PAGE_BATTERY_SYSTEM 0x85 /* Usage within Power Device page */ #define USAGE_POW_UNDEFINED 0x00840000 #define USAGE_POW_I_NAME 0x00840001 #define USAGE_POW_PRESENT_STATUS 0x00840002 #define USAGE_POW_CHANGED_STATUS 0x00840003 #define USAGE_POW_UPS 0x00840004 #define USAGE_POW_POWER_SUPPLY 0x00840005 #define USAGE_POW_PERIPHERAL_DEVICE 0x00840006 #define USAGE_POW_BATTERY_SYSTEM 0x00840010 #define USAGE_POW_BATTERY_SYSTEM_ID 0x00840011 #define USAGE_POW_BATTERY 0x00840012 #define USAGE_POW_BATTERY_ID 0x00840013 #define USAGE_POW_CHARGER 0x00840014 #define USAGE_POW_CHARGER_ID 0x00840015 #define USAGE_POW_POWER_CONVERTER 0x00840016 #define USAGE_POW_POWER_CONVERTER_ID 0x00840017 #define USAGE_POW_OUTLET_SYSTEM 0x00840018 #define USAGE_POW_OUTLET_SYSTEM_ID 0x00840019 #define USAGE_POW_INPUT 0x0084001A #define USAGE_POW_INPUT_ID 0x0084001B #define USAGE_POW_OUTPUT 0x0084001C #define USAGE_POW_OUTPUT_ID 0x0084001D #define USAGE_POW_FLOW 0x0084001E #define USAGE_POW_FLOW_ID 0x0084001F #define USAGE_POW_OUTLET 0x00840020 #define USAGE_POW_OUTLET_ID 0x00840021 #define USAGE_POW_GANG 0x00840022 #define USAGE_POW_GANG_ID 0x00840023 #define USAGE_POW_POWER_SUMMARY 0x00840024 #define USAGE_POW_POWER_SUMMARY_ID 0x00840025 #define USAGE_POW_VOLTAGE 0x00840030 #define USAGE_POW_CURRENT 0x00840031 #define USAGE_POW_FREQUENCY 0x00840032 #define USAGE_POW_APPARENT_POWER 0x00840033 #define USAGE_POW_ACTIVE_POWER 0x00840034 #define USAGE_POW_PERCENT_LOAD 0x00840035 #define USAGE_POW_TEMPERATURE 0x00840036 #define USAGE_POW_HUMIDITY 0x00840037 #define USAGE_POW_BAD_COUNT 0x00840038 #define USAGE_POW_CONFIG_VOLTAGE 0x00840040 #define USAGE_POW_CONFIG_CURRENT 0x00840041 #define USAGE_POW_CONFIG_FREQUENCY 0x00840042 #define USAGE_POW_CONFIG_APPARENT_POWER 0x00840043 #define USAGE_POW_CONFIG_ACTIVE_POWER 0x00840044 #define USAGE_POW_CONFIG_PERCENT_LOAD 0x00840045 #define USAGE_POW_CONFIG_TEMPERATURE 0x00840046 #define USAGE_POW_CONFIG_HUMIDITY 0x00840047 #define USAGE_POW_SWITCH_ON_CONTROL 0x00840050 #define USAGE_POW_SWITCH_OFF_CONTROL 0x00840051 #define USAGE_POW_TOGGLE_CONTROL 0x00840052 #define USAGE_POW_LOW_VOLTAGE_TRANSFER 0x00840053 #define USAGE_POW_HIGH_VOLTAGE_TRANSFER 0x00840054 #define USAGE_POW_DELAY_BEFORE_REBOOT 0x00840055 #define USAGE_POW_DELAY_BEFORE_STARTUP 0x00840056 #define USAGE_POW_DELAY_BEFORE_SHUTDOWN 0x00840057 #define USAGE_POW_TEST 0x00840058 #define USAGE_POW_MODULE_RESET 0x00840059 #define USAGE_POW_AUDIBLE_ALARM_CONTROL 0x0084005A #define USAGE_POW_PRESENT 0x00840060 #define USAGE_POW_GOOD 0x00840061 #define USAGE_POW_INTERNAL_FAILURE 0x00840062 #define USAGE_POW_VOLTAGE_OUT_OF_RANGE 0x00840063 #define USAGE_POW_FREQUENCY_OUT_OF_RANGE 0x00840064 #define USAGE_POW_OVERLOAD 0x00840065 #define USAGE_POW_OVER_CHARGED 0x00840066 #define USAGE_POW_OVER_TEMPERATURE 0x00840067 #define USAGE_POW_SHUTDOWN_REQUESTED 0x00840068 #define USAGE_POW_SHUTDOWN_IMMINENT 0x00840069 #define USAGE_POW_SWITCH_ON_OFF 0x0084006B #define USAGE_POW_SWITCHABLE 0x0084006C #define USAGE_POW_USED 0x0084006D #define USAGE_POW_BOOST 0x0084006E #define USAGE_POW_BUCK 0x0084006F #define USAGE_POW_INITIALIZED 0x00840070 #define USAGE_POW_TESTED 0x00840071 #define USAGE_POW_AWAITING_POWER 0x00840072 #define USAGE_POW_COMMUNICATION_LOST 0x00840073 #define USAGE_POW_I_MANUFACTURER 0x008400FD #define USAGE_POW_I_PRODUCT 0x008400FE #define USAGE_POW_I_SERIAL_NUMBER 0x008400FF /* Usage within Battery System page */ #define USAGE_BAT_UNDEFINED 0x00850000 #define USAGE_BAT_SMB_BATTERY_MODE 0x00850001 #define USAGE_BAT_SMB_BATTERY_STATUS 0x00850002 #define USAGE_BAT_SMB_ALARM_WARNING 0x00850003 #define USAGE_BAT_SMB_CHARGER_MODE 0x00850004 #define USAGE_BAT_SMB_CHARGER_STATUS 0x00850005 #define USAGE_BAT_SMB_CHARGER_SPEC_INFO 0x00850006 #define USAGE_BAT_SMB_SELECTOR_STATE 0x00850007 #define USAGE_BAT_SMB_SELECTOR_PRESETS 0x00850008 #define USAGE_BAT_SMB_SELECTOR_INFO 0x00850009 #define USAGE_BAT_OPTIONAL_MFG_FUNCTION_1 0x00850010 #define USAGE_BAT_OPTIONAL_MFG_FUNCTION_2 0x00850011 #define USAGE_BAT_OPTIONAL_MFG_FUNCTION_3 0x00850012 #define USAGE_BAT_OPTIONAL_MFG_FUNCTION_4 0x00850013 #define USAGE_BAT_OPTIONAL_MFG_FUNCTION_5 0x00850014 #define USAGE_BAT_CONNECTION_TO_SMBUS 0x00850015 #define USAGE_BAT_OUTPUT_CONNECTION 0x00850016 #define USAGE_BAT_CHARGER_CONNECTION 0x00850017 #define USAGE_BAT_BATTERY_INSERTION 0x00850018 #define USAGE_BAT_USE_NEXT 0x00850019 #define USAGE_BAT_OK_TO_USE 0x0085001A #define USAGE_BAT_BATTERY_SUPPORTED 0x0085001B #define USAGE_BAT_SELECTOR_REVISION 0x0085001C #define USAGE_BAT_CHARGING_INDICATOR 0x0085001D #define USAGE_BAT_MANUFACTURER_ACCESS 0x00850028 #define USAGE_BAT_REMAINING_CAPACITY_LIMIT 0x00850029 #define USAGE_BAT_REMAINING_TIME_LIMIT 0x0085002A #define USAGE_BAT_AT_RATE 0x0085002B #define USAGE_BAT_CAPACITY_MODE 0x0085002C #define USAGE_BAT_BROADCAST_TO_CHARGER 0x0085002D #define USAGE_BAT_PRIMARY_BATTERY 0x0085002E #define USAGE_BAT_CHARGE_CONTROLLER 0x0085002F #define USAGE_BAT_TERMINATE_CHARGE 0x00850040 #define USAGE_BAT_TERMINATE_DISCHARGE 0x00850041 #define USAGE_BAT_BELOW_REMAINING_CAPACITY_LIMIT 0x00850042 #define USAGE_BAT_REMAINING_TIME_LIMIT_EXPIRED 0x00850043 #define USAGE_BAT_CHARGING 0x00850044 #define USAGE_BAT_DISCHARGING 0x00850045 #define USAGE_BAT_FULLY_CHARGED 0x00850046 #define USAGE_BAT_FULLY_DISCHARGED 0x00850047 #define USAGE_BAT_CONDITIONING_FLAG 0x00850048 #define USAGE_BAT_AT_RATE_OK 0x00850049 #define USAGE_BAT_SMB_ERROR_CODE 0x0085004A #define USAGE_BAT_NEED_REPLACEMENT 0x0085004B #define USAGE_BAT_AT_RATE_TIME_TO_FULL 0x00850060 #define USAGE_BAT_AT_RATE_TIME_TO_EMPTY 0x00850061 #define USAGE_BAT_AVERAGE_CURRENT 0x00850062 #define USAGE_BAT_MAX_ERROR 0x00850063 #define USAGE_BAT_RELATIVE_STATE_OF_CHARGE 0x00850064 #define USAGE_BAT_ABSOLUTE_STATE_OF_CHARGE 0x00850065 #define USAGE_BAT_REMAINING_CAPACITY 0x00850066 #define USAGE_BAT_FULL_CHARGE_CAPACITY 0x00850067 #define USAGE_BAT_RUN_TIME_TO_EMPTY 0x00850068 #define USAGE_BAT_AVERAGE_TIME_TO_EMPTY 0x00850069 #define USAGE_BAT_AVERAGE_TIME_TO_FULL 0x0085006A #define USAGE_BAT_CYCLE_COUNT 0x0085006B #define USAGE_BAT_BATT_PACK_MODEL_LEVEL 0x00850080 #define USAGE_BAT_INTERNAL_CHARGE_CONTROLLER 0x00850081 #define USAGE_BAT_PRIMARY_BATTERY_SUPPORT 0x00850082 #define USAGE_BAT_DESIGN_CAPACITY 0x00850083 #define USAGE_BAT_SPECIFICATION_INFO 0x00850084 #define USAGE_BAT_MANUFACTURER_DATE 0x00850085 #define USAGE_BAT_SERIAL_NUMBER 0x00850086 #define USAGE_BAT_I_MANUFACTURER_NAME 0x00850087 #define USAGE_BAT_I_DEVICE_NAME 0x00850088 #define USAGE_BAT_I_DEVICE_CHEMISTRY 0x00850089 #define USAGE_BAT_MANUFACTURER_DATA 0x0085008A #define USAGE_BAT_RECHARGEABLE 0x0085008B #define USAGE_BAT_WARNING_CAPACITY_LIMIT 0x0085008C #define USAGE_BAT_CAPACITY_GRANULARITY_1 0x0085008D #define USAGE_BAT_CAPACITY_GRANULARITY_2 0x0085008E #define USAGE_BAT_I_OEMINFORMATION 0x0085008F #define USAGE_BAT_INHIBIT_CHARGE 0x008500C0 #define USAGE_BAT_ENABLE_POLLING 0x008500C1 #define USAGE_BAT_RESET_TO_ZERO 0x008500C2 #define USAGE_BAT_AC_PRESENT 0x008500D0 #define USAGE_BAT_BATTERY_PRESENT 0x008500D1 #define USAGE_BAT_POWER_FAIL 0x008500D2 #define USAGE_BAT_ALARM_INHIBITED 0x008500D3 #define USAGE_BAT_THERMISTOR_UNDER_RANGE 0x008500D4 #define USAGE_BAT_THERMISTOR_HOT 0x008500D5 #define USAGE_BAT_THERMISTOR_COLD 0x008500D6 #define USAGE_BAT_THERMISTOR_OVER_RANGE 0x008500D7 #define USAGE_BAT_VOLTAGE_OUT_OF_RANGE 0x008500D8 #define USAGE_BAT_CURRENT_OUT_OF_RANGE 0x008500D9 #define USAGE_BAT_CURRENT_NOT_REGULATED 0x008500DA #define USAGE_BAT_VOLTAGE_NOT_REGULATED 0x008500DB #define USAGE_BAT_MASTER_MODE 0x008500DC #define USAGE_BAT_CHARGER_SELECTOR_SUPPORT 0x008500F0 #define USAGE_BAT_CHARGER_SPEC 0x008500F1 #define USAGE_BAT_LEVEL_2 0x008500F2 #define USAGE_BAT_LEVEL_3 0x008500F3 /* * HIDNode_t struct * * Describe a HID Path point: Usage = bits 0..15, UPage = bits 16..31 * -------------------------------------------------------------------------- */ typedef uint32_t HIDNode_t; /* * HIDPath struct * * Describe a HID Path * -------------------------------------------------------------------------- */ typedef struct { uint8_t Size; /* HID Path size */ HIDNode_t Node[PATH_SIZE]; /* HID Path */ } HIDPath_t; /* * HIDData struct * * Describe a HID Data with its location in report * -------------------------------------------------------------------------- */ typedef struct { HIDPath_t Path; /* HID Path */ uint8_t ReportID; /* Report ID */ uint8_t Offset; /* Offset of data in report */ uint8_t Size; /* Size of data in bit */ uint8_t Type; /* Type : FEATURE / INPUT / OUTPUT */ uint8_t Attribute; /* Report field attribute */ long Unit; /* HID Unit */ int8_t UnitExp; /* Unit exponent */ long LogMin; /* Logical Min */ long LogMax; /* Logical Max */ bool assumed_LogMax; /* Logical Max assumed (e.g. "-1" initially)? */ long PhyMin; /* Physical Min */ long PhyMax; /* Physical Max */ int8_t have_PhyMin; /* Physical Min defined? */ int8_t have_PhyMax; /* Physical Max defined? */ } HIDData_t; /* * HIDDesc struct * * Holds a parsed report descriptor * -------------------------------------------------------------------------- */ typedef struct { size_t nitems; /* number of items in descriptor */ HIDData_t *item; /* list of items */ size_t replen[256]; /* list of report lengths, in byte */ } HIDDesc_t; #ifdef __cplusplus /* *INDENT-OFF* */ } /* extern "C" */ /* *INDENT-ON* */ #endif /* __cplusplus */ #endif /* HIDTYPES_H */ nut-2.8.4/drivers/blazer_ser.c0000644000175000017500000001171715044656702013246 00000000000000/* * blazer_ser.c: support for Megatec/Q1 serial protocol based UPSes * * OBSOLETION WARNING: Please to not base new development on this * codebase, instead create a new subdriver for nutdrv_qx which * generally covers all Megatec/Qx protocol family and aggregates * device support from such legacy drivers over time. * * A document describing the protocol implemented by this driver can be * found online at "https://www.networkupstools.org/protocols/megatec.html". * * Copyright (C) 2008 - Arjen de Korte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "main.h" #include "serial.h" #include "blazer.h" #define DRIVER_NAME "Megatec/Q1 protocol serial driver" #define DRIVER_VERSION "1.64" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Arjen de Korte ", DRV_BETA, { NULL } }; #define SER_WAIT_SEC 1 /* 3 seconds for Best UPS */ /* * Generic command processing function. Send a command and read a reply. * Returns < 0 on error, 0 on timeout and the number of bytes read on * success. */ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen) { #ifndef TESTING ssize_t ret; ser_flush_io(upsfd); ret = ser_send(upsfd, "%s", cmd); if (ret <= 0) { upsdebugx(3, "send: %s", ret ? strerror(errno) : "timeout"); return ret; } upsdebugx(3, "send: '%.*s'", (int)strcspn(cmd, "\r"), cmd); ret = ser_get_buf(upsfd, buf, buflen, SER_WAIT_SEC, 0); if (ret <= 0) { upsdebugx(3, "read: %s", ret ? strerror(errno) : "timeout"); return ret; } upsdebugx(3, "read: '%.*s'", (int)strcspn(buf, "\r"), buf); return ret; #else const struct { const char *cmd; const char *answer; } testing[] = { { "Q1\r", "(215.0 195.0 230.0 014 49.0 2.27 30.0 00101000\r" }, { "F\r", "#230.0 000 024.0 50.0\r" }, { "I\r", "#NOT_A_LIVE_UPS TESTING TESTING \r" }, { NULL } }; int i; memset(buf, 0, buflen); for (i = 0; cmd && testing[i].cmd; i++) { if (strcasecmp(cmd, testing[i].cmd)) { continue; } /* TODO: Range-check int vs. ssize_t values */ return (ssize_t)snprintf(buf, buflen, "%s", testing[i].answer); } return (ssize_t)snprintf(buf, buflen, "%s", testing[i].cmd); #endif } void upsdrv_help(void) { } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "cablepower", "Set cable power for serial interface"); blazer_makevartable(); } void upsdrv_initups(void) { #ifndef TESTING # ifndef WIN32 const struct { const char *val; const int dtr; const int rts; } cablepower[] = { { "normal", 1, 0 }, /* default */ { "reverse", 0, 1 }, { "both", 1, 1 }, { "none", 0, 0 }, { NULL, 0, 0 } }; int i; const char *val; struct termios tio; /* * Open and lock the serial port and set the speed to 2400 baud. */ upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B2400); if (tcgetattr(upsfd, &tio)) { fatal_with_errno(EXIT_FAILURE, "tcgetattr"); } /* * Use canonical mode input processing (to read reply line) */ tio.c_lflag |= ICANON; /* Canonical input (erase and kill processing) */ tio.c_cc[VEOF] = _POSIX_VDISABLE; tio.c_cc[VEOL] = '\r'; tio.c_cc[VERASE] = _POSIX_VDISABLE; tio.c_cc[VINTR] = _POSIX_VDISABLE; tio.c_cc[VKILL] = _POSIX_VDISABLE; tio.c_cc[VQUIT] = _POSIX_VDISABLE; tio.c_cc[VSUSP] = _POSIX_VDISABLE; tio.c_cc[VSTART] = _POSIX_VDISABLE; tio.c_cc[VSTOP] = _POSIX_VDISABLE; if (tcsetattr(upsfd, TCSANOW, &tio)) { fatal_with_errno(EXIT_FAILURE, "tcsetattr"); } val = getval("cablepower"); for (i = 0; val && cablepower[i].val; i++) { if (!strcasecmp(val, cablepower[i].val)) { break; } } if (!cablepower[i].val) { fatalx(EXIT_FAILURE, "Value '%s' not valid for 'cablepower'", val); } ser_set_dtr(upsfd, cablepower[i].dtr); ser_set_rts(upsfd, cablepower[i].rts); /* * Allow some time to settle for the cablepower */ usleep(100000); # else /* WIN32 */ /* TODO : Correctly set the port parameters for WIN32 */ NUT_WIN32_INCOMPLETE_LOGWARN(); /* upsdebugx(0, "blazer_ser: upsdrv_init(): serial port setup for WIN32 currently has not been ported (TODO)"); */ # endif /* WIN32 */ #endif /* !TESTING */ blazer_initups(); } void upsdrv_initinfo(void) { blazer_initinfo(); } void upsdrv_cleanup(void) { #ifndef TESTING ser_set_dtr(upsfd, 0); ser_close(upsfd, device_path); #endif } nut-2.8.4/drivers/nutdrv_qx_q1.h0000644000175000017500000000340614670526611013551 00000000000000/* nutdrv_qx_q1.h - Subdriver for Q1 protocol based UPSes * * Copyright (C) * 2013 Daniele Pezzini * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * NOTE: * This subdriver implements the same protocol as the one used by the 'megatec' subdriver minus the vendor (I) and ratings (F) queries. * In the claim function: * - it doesn't even try to get 'vendor' information (I) * - it checks only status (Q1), through 'input.voltage' variable * Therefore it should be able to work even if the UPS doesn't support vendor/ratings *and* the user doesn't use the 'novendor'/'norating' flags, as long as: * - the UPS replies a Q1-compliant answer (i.e. not necessary filled with all of the Q1-required data, but at least of the right length and with not available data filled with some replacement character) * - the UPS reports a valid input.voltage (used in the claim function) * - the UPS reports valid status bits (1st, 2nd, 3rd, 6th, 7th are the mandatory ones) * */ #ifndef NUTDRV_QX_Q1_H #define NUTDRV_QX_Q1_H #include "nutdrv_qx.h" extern subdriver_t q1_subdriver; #endif /* NUTDRV_QX_Q1_H */ nut-2.8.4/drivers/microsol-apc.c0000664000175000017500000001513115000733176013473 00000000000000/* microsol-apc.c - APC Back-UPS BR series UPS driver Copyright (C) 2004 Silvino B. Magalhães 2019 Roberto Panerai Velloso 2021 Ygor A. S. Regados This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2021/03/19 - Version 0.70 - Initial release, based on solis driver */ #include "config.h" /* must be first */ #include #include #include "main.h" #include "serial.h" #include "nut_float.h" #include "timehead.h" #include "microsol-common.h" #include "microsol-apc.h" #define DRIVER_NAME "APC Back-UPS BR series UPS driver" #define DRIVER_VERSION "0.72" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Silvino B. Magalhães " "Roberto Panerai Velloso " "Ygor A. S. Regados ", DRV_STABLE, { NULL } }; #define false 0 #define true 1 #define RESP_END 0xFE #define ENDCHAR 13 /* replies end with CR */ /* solis commands */ #define CMD_UPSCONT 0xCC #define CMD_SHUT 0xDD #define CMD_SHUTRET 0xDE #define CMD_EVENT 0xCE #define CMD_DUMP 0xCD /** Check if UPS model is available here. */ bool_t ups_model_defined(void) { unsigned int model_index; for (model_index = 0; MODELS[model_index] != ups_model; model_index++); if (model_index == MODEL_COUNT) { return 0; } else { return 1; } } /** Set UPS model name. */ void set_ups_model(void) { switch (ups_model) { case 183: model_name = "BZ2200I-BR"; break; case 190: model_name = "BZ1500-BR"; break; case 191: model_name = "BZ2200BI-BR"; break; default: model_name = "Unknown UPS"; } } /** * Parse received packet with UPS instantaneous data. * This function parses model-specific values, such as voltage and battery times. */ void scan_received_pack_model_specific(void) { unsigned int relay_state; unsigned int model_index; float real_power_curve_1, real_power_curve_2, real_power_curve_3; float power_difference_1, power_difference_2, power_difference_3; bool_t recharging; /* Extract unprocessed data from packet */ input_voltage = received_packet[2]; output_voltage = received_packet[1]; output_current = received_packet[5]; battery_voltage = received_packet[3]; relay_state = (received_packet[6] & 0x28) >> 3; /* Find array indexes for detected UPS model */ for (model_index = 0; MODELS[model_index] != ups_model && model_index < MODEL_COUNT - 1; model_index++); if (MODELS[model_index] != ups_model) { upslogx(LOG_NOTICE, "UPS model not found, using fallback option."); } /* Start processing according to model */ nominal_power = NOMINAL_POWER[model_index]; input_voltage = INPUT_VOLTAGE_MULTIPLIER_A[model_index][output_220v] * input_voltage + INPUT_VOLTAGE_MULTIPLIER_B[model_index][output_220v]; battery_voltage = BATTERY_VOLTAGE_MULTIPLIER_A[model_index] * battery_voltage + BATTERY_VOLTAGE_MULTIPLIER_B[model_index]; output_current = OUTPUT_CURRENT_MULTIPLIER_A[model_index][line_unpowered] * output_current + OUTPUT_CURRENT_MULTIPLIER_B[model_index][line_unpowered]; if (ups_model == 190 && line_unpowered) { /* Special calculation for BZ1500 on battery */ output_voltage = battery_voltage * sqrt(output_voltage / 64.0) * OUTPUT_VOLTAGE_MULTIPLIER_A[model_index][line_unpowered][relay_state] - output_current * OUTPUT_VOLTAGE_MULTIPLIER_B[model_index][line_unpowered][relay_state]; output_voltage = 1.5091 * output_voltage + 1.5823; if (output_current > 4.0) output_voltage += output_current * 4.0; if (output_current > 3.0) output_voltage += output_current * 2.0; else if (output_voltage > 0.9) output_voltage += output_current / 3.0; else output_voltage -= 5.0; if (output_voltage < 100.0) output_voltage = 100; } else { output_voltage = OUTPUT_VOLTAGE_MULTIPLIER_A[model_index][line_unpowered][relay_state] * output_voltage + OUTPUT_VOLTAGE_MULTIPLIER_B[model_index][line_unpowered][relay_state]; } if (line_unpowered) { input_frequency = 0; output_frequency = 60; } else { input_frequency = 0.37 * (257 - ((received_packet[21] + received_packet[22] * 256) >> 8)); output_frequency = input_frequency; } apparent_power = output_current * output_voltage; real_power = received_packet[7] + 256 * received_packet[8]; real_power_curve_1 = REAL_POWER_CURVE_SELECTOR_A1[model_index][relay_state] * real_power + REAL_POWER_CURVE_SELECTOR_B1[model_index][relay_state]; real_power_curve_2 = REAL_POWER_CURVE_SELECTOR_A2[model_index][relay_state] * real_power + REAL_POWER_CURVE_SELECTOR_B2[model_index][relay_state]; real_power_curve_3 = REAL_POWER_CURVE_SELECTOR_A3[model_index][relay_state] * real_power + REAL_POWER_CURVE_SELECTOR_B3[model_index][relay_state]; power_difference_1 = fabs(real_power_curve_1 - apparent_power); power_difference_2 = fabs(real_power_curve_2 - apparent_power); power_difference_3 = fabs(real_power_curve_3 - apparent_power); if (power_difference_1 < power_difference_2 && power_difference_1 < power_difference_3) { real_power = REAL_POWER_MULTIPLIER_A1[model_index][relay_state] * real_power + REAL_POWER_MULTIPLIER_B1[model_index][relay_state]; } else if (power_difference_2 < power_difference_3) { real_power = REAL_POWER_MULTIPLIER_A2[model_index][relay_state] * real_power + REAL_POWER_MULTIPLIER_B2[model_index][relay_state]; } else { real_power = REAL_POWER_MULTIPLIER_A3[model_index][relay_state] * real_power + REAL_POWER_MULTIPLIER_B3[model_index][relay_state]; } /* If real power is greater than apparent power, invert values */ if (apparent_power < real_power) { apparent_power = apparent_power + real_power; real_power = apparent_power - real_power; apparent_power = apparent_power - real_power; } input_current = 1.1 * apparent_power / input_voltage; recharging = (0x02 & received_packet[20]) == 0x02; battery_charge = (100.0 * (battery_voltage - MIN_BATTERY_VOLTAGE[model_index])) / (MAX_BATTERY_VOLTAGE[model_index][recharging] - MIN_BATTERY_VOLTAGE[model_index]); } nut-2.8.4/drivers/mge-hid.h0000644000175000017500000000206114670526611012424 00000000000000/* mge-hid.h - data to monitor MGE UPS SYSTEMS HID (USB and serial) devices * * Copyright (C) 2003 - 2005 * Arnaud Quette * * Sponsored by MGE UPS SYSTEMS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef MGE_HID_H #define MGE_HID_H #include "usbhid-ups.h" extern subdriver_t mge_subdriver; #endif /* MGE_HID_H */ nut-2.8.4/drivers/socomec_jbus.c0000644000175000017500000003412215044656702013564 00000000000000/* socomec_jbus.c - Driver for Socomec JBUS UPS * * Copyright (C) * 2021 Thanos Chatziathanassiou * * Based on documentation found freely on * https://www.socomec.com/files/live/sites/systemsite/files/GB-JBUS-MODBUS-for-Delphys-MP-and-Delphys-MX-operating-manual.pdf * but with dubious legal license. The document itself states: * ``CAUTION : “This is a product for restricted sales distribution to informed partners. * Installation restrictions or additional measures may be needed to prevent disturbances'' * YMMV * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include #if !(defined NUT_MODBUS_LINKTYPE_STR) # define NUT_MODBUS_LINKTYPE_STR "unknown" #endif #define DRIVER_NAME "Socomec jbus driver (libmodbus link type: " NUT_MODBUS_LINKTYPE_STR ")" #define DRIVER_VERSION "0.09" #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) #define MODBUS_SLAVE_ID 1 #define BATTERY_RUNTIME_CRITICAL 15 /* Variables */ static modbus_t *modbus_ctx = NULL; static int mrir(modbus_t * arg_ctx, int addr, int nb, uint16_t * dest); /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Thanos Chatziathanassiou \n", DRV_BETA, {NULL} }; void upsdrv_initinfo(void) { uint16_t tab_reg[12]; int r; upsdebugx(2, "upsdrv_initinfo"); dstate_setinfo("device.mfr", "socomec jbus"); dstate_setinfo("device.model", "Socomec Generic"); upsdebugx(2, "initial read"); /* this is a neat trick, but not really helpful right now https://stackoverflow.com/questions/25811662/spliting-an-hex-into-2-hex-values/41733170#41733170 uint8_t *lowbyte; uint8_t *hibyte; */ r = mrir(modbus_ctx, 0x1000, 12, tab_reg); if (r == -1) { fatalx(EXIT_FAILURE, "failed to read UPS code from JBUS. r is %d error %s", r, modbus_strerror(errno)); } upsdebugx(2, "read UPS Code %d", tab_reg[0]); if (tab_reg[1]) { upsdebugx(2, "read UPS Power %d (kVA * 10)", tab_reg[1]); dstate_setinfo("ups.power", "%u", (unsigned int)(tab_reg[1]*100) ); } /* known Socomec Models */ switch (tab_reg[0]) { case 130: dstate_setinfo("ups.model", "%s", "DIGYS"); break; case 515: dstate_setinfo("ups.model", "%s", "DELPHYS MX"); break; case 516: dstate_setinfo("ups.model", "%s", "DELPHYS MX elite"); break; default: dstate_setinfo("ups.model", "Unknown Socomec JBUS. Send id %u and specify the model", tab_reg[0]); } if (tab_reg[3] && tab_reg[4] && tab_reg[5] && tab_reg[6] && tab_reg[7]) { dstate_setinfo("ups.serial", "%c%c%c%c%c%c%c%c%c%c", (tab_reg[3]&0xFF), (tab_reg[3]>>8), (tab_reg[4]&0xFF), (tab_reg[4]>>8), (tab_reg[5]&0xFF), (tab_reg[5]>>8), (tab_reg[6]&0xFF), (tab_reg[6]>>8), (tab_reg[7]&0xFF), (tab_reg[7]>>8) ); } /* upsh.instcmd = instcmd; */ /* upsh.setvar = setvar; */ } void upsdrv_updateinfo(void) { uint16_t tab_reg[64]; int r; upsdebugx(2, "upsdrv_updateinfo"); status_init(); /* ups configuration */ r = mrir(modbus_ctx, 0x10E0, 32, tab_reg); if (r == -1 || !tab_reg[0]) { upsdebugx(2, "Did not receive any data from the UPS at 0x10E0 ! Going stale r is %d error %s", r, modbus_strerror(errno)); dstate_datastale(); return; } dstate_setinfo("input.voltage", "%u", tab_reg[0]); dstate_setinfo("output.voltage", "%u", tab_reg[1]); dstate_setinfo("input.frequency", "%u", tab_reg[2]); dstate_setinfo("output.frequency", "%u", tab_reg[3]); upsdebugx(2, "battery capacity (Ah * 10) %u", tab_reg[8]); upsdebugx(2, "battery elements %u", tab_reg[9]); /* time and date */ r = mrir(modbus_ctx, 0x1360, 4, tab_reg); if (r == -1) { upsdebugx(2, "Did not receive any data from the UPS at 0x1360 ! Ignoring ? r is %d error %s", r, modbus_strerror(errno)); } dstate_setinfo("ups.time", "%02d:%02d:%02d", (tab_reg[1]&0xFF), (tab_reg[0]>>8), (tab_reg[0]&0xFF) ); dstate_setinfo("ups.date", "%04d/%02d/%02d", (tab_reg[3]+2000), (tab_reg[2]>>8), (tab_reg[1]>>8) ); /* ups status */ r = mrir(modbus_ctx, 0x1020, 6, tab_reg); if (r == -1) { upsdebugx(2, "Did not receive any data from the UPS at 0x1020 ! Ignoring ? r is %d error %s", r, modbus_strerror(errno)); /* dstate_datastale(); return; */ } if (CHECK_BIT(tab_reg[0], 0)) upsdebugx(2, "Rectifier Input supply present"); if (CHECK_BIT(tab_reg[0], 1)) upsdebugx(2, "Inverter ON "); if (CHECK_BIT(tab_reg[0], 2)) upsdebugx(2, "Rectifier ON"); if (CHECK_BIT(tab_reg[0], 3)) upsdebugx(2, "Load protected by inverter"); if (CHECK_BIT(tab_reg[0], 4)) upsdebugx(2, "Load on automatic bypass"); if (CHECK_BIT(tab_reg[0], 5)) upsdebugx(2, "Load on battery"); if (CHECK_BIT(tab_reg[0], 6)) upsdebugx(2, "Remote controls disable"); if (CHECK_BIT(tab_reg[0], 7)) upsdebugx(2, "Eco-mode ON"); if (CHECK_BIT(tab_reg[0], 14)) upsdebugx(2, "Battery Test failed"); if (CHECK_BIT(tab_reg[0], 15)) upsdebugx(2, "Battery near end of backup time"); if (CHECK_BIT(tab_reg[0], 16)) upsdebugx(2, "Battery disacharged"); if (CHECK_BIT(tab_reg[1], 0)) upsdebugx(2, "Battery OK"); if (CHECK_BIT(tab_reg[1], 10)) upsdebugx(2, "Bypass input supply present"); if (CHECK_BIT(tab_reg[1], 11)) upsdebugx(2, "Battery charging"); if (CHECK_BIT(tab_reg[1], 12)) upsdebugx(2, "Bypass input frequency out of tolerance"); if (CHECK_BIT(tab_reg[2], 0)) upsdebugx(2, "Unit operating"); if (CHECK_BIT(tab_reg[3], 0)) upsdebugx(2, "Maintenance mode active"); if (CHECK_BIT(tab_reg[4], 0)) upsdebugx(2, "Boost charge ON"); if (CHECK_BIT(tab_reg[4], 2)) upsdebugx(2, "Inverter switch closed"); if (CHECK_BIT(tab_reg[4], 3)) upsdebugx(2, "Bypass breaker closed"); if (CHECK_BIT(tab_reg[4], 4)) upsdebugx(2, "Maintenance bypass breaker closed"); if (CHECK_BIT(tab_reg[4], 5)) upsdebugx(2, "Remote maintenance bypass breaker closed"); if (CHECK_BIT(tab_reg[4], 6)) upsdebugx(2, "Output breaker closed (Q3)"); if (CHECK_BIT(tab_reg[4], 9)) upsdebugx(2, "Unit working"); if (CHECK_BIT(tab_reg[4], 12)) upsdebugx(2, "normal mode active"); /* alarms */ r = mrir(modbus_ctx, 0x1040, 4, tab_reg); alarm_init(); if (r == -1) { upsdebugx(2, "Did not receive any data from the UPS at 0x1040 ! Ignoring ? r is %d error %s", r, modbus_strerror(errno)); /* dstate_datastale(); return; */ } if (CHECK_BIT(tab_reg[0], 0)) { upsdebugx(2, "General Alarm"); alarm_set("General Alarm present."); } if (CHECK_BIT(tab_reg[0], 1)) { upsdebugx(2, "Battery failure"); alarm_set("Battery failure."); } if (CHECK_BIT(tab_reg[0], 2)) { upsdebugx(2, "UPS overload"); alarm_set("Overload fault."); } if (CHECK_BIT(tab_reg[0], 4)) { upsdebugx(2, "Control failure (com, internal supply...)"); alarm_set("Control failure (com, internal supply...)"); } if (CHECK_BIT(tab_reg[0], 5)) { upsdebugx(2, "Rectifier input supply out of tolerance "); alarm_set("Rectifier input supply out of tolerance."); } if (CHECK_BIT(tab_reg[0], 6)) { upsdebugx(2, "Bypass input supply out of tolerance "); alarm_set("Bypass input supply out of tolerance."); } if (CHECK_BIT(tab_reg[0], 7)) { upsdebugx(2, "Over temperature alarm "); alarm_set("Over temperature fault."); } if (CHECK_BIT(tab_reg[0], 8)) { upsdebugx(2, "Maintenance bypass closed"); alarm_set("Maintenance bypass closed."); } if (CHECK_BIT(tab_reg[0], 10)) { upsdebugx(2, "Battery charger fault"); alarm_set("Battery charger fault."); } if (CHECK_BIT(tab_reg[1], 1)) upsdebugx(2, "Improper condition of use"); if (CHECK_BIT(tab_reg[1], 2)) upsdebugx(2, "Inverter stopped for overload (or bypass transfer)"); if (CHECK_BIT(tab_reg[1], 3)) upsdebugx(2, "Microprocessor control system"); if (CHECK_BIT(tab_reg[1], 5)) upsdebugx(2, "Synchronisation fault (PLL fault)"); if (CHECK_BIT(tab_reg[1], 6)) upsdebugx(2, "Rectifier input supply fault"); if (CHECK_BIT(tab_reg[1], 7)) upsdebugx(2, "Rectifier preventive alarm"); if (CHECK_BIT(tab_reg[1], 9)) upsdebugx(2, "Inverter preventive alarm"); if (CHECK_BIT(tab_reg[1], 10)) upsdebugx(2, "Charger general alarm"); if (CHECK_BIT(tab_reg[1], 13)) upsdebugx(2, "Bypass preventive alarm"); if (CHECK_BIT(tab_reg[1], 15)) { upsdebugx(2, "Imminent STOP"); alarm_set("Imminent STOP."); } if (CHECK_BIT(tab_reg[2], 12)) { upsdebugx(2, "Servicing alarm"); alarm_set("Servicing alarm."); } if (CHECK_BIT(tab_reg[2], 15)) upsdebugx(2, "Battery room alarm"); if (CHECK_BIT(tab_reg[3], 0)) { upsdebugx(2, "Maintenance bypass alarm"); alarm_set("Maintenance bypass."); } if (CHECK_BIT(tab_reg[3], 1)) { upsdebugx(2, "Battery discharged"); alarm_set("Battery discharged."); } if (CHECK_BIT(tab_reg[3], 3)) upsdebugx(2, "Synoptic alarm"); if (CHECK_BIT(tab_reg[3], 4)) { upsdebugx(2, "Critical Rectifier fault"); alarm_set("Critical Rectifier fault."); } if (CHECK_BIT(tab_reg[3], 6)) { upsdebugx(2, "Critical Inverter fault"); alarm_set("Critical Inverter fault."); } if (CHECK_BIT(tab_reg[3], 10)) upsdebugx(2, "ESD activated"); if (CHECK_BIT(tab_reg[3], 11)) { upsdebugx(2, "Battery circuit open"); alarm_set("Battery circuit open."); } if (CHECK_BIT(tab_reg[3], 14)) { upsdebugx(2, "Bypass critical alarm"); alarm_set("Bypass critical alarm."); } /* measurements */ r = mrir(modbus_ctx, 0x1060, 48, tab_reg); if (r == -1) { upsdebugx(2, "Did not receive any data from the UPS at 0x1060 ! Ignoring ? r is %d error %s", r, modbus_strerror(errno)); /* dstate_datastale(); return; */ } if (tab_reg[1] == 0xFFFF && tab_reg[2] == 0xFFFF) { /* this a 1-phase model */ dstate_setinfo("input.phases", "1" ); dstate_setinfo("ups.load", "%u", tab_reg[0] ); dstate_setinfo("input.bypass.voltage", "%u", tab_reg[6] ); dstate_setinfo("output.voltage", "%u", tab_reg[9] ); if (tab_reg[15] != 0xFFFF) dstate_setinfo("output.current", "%u", tab_reg[15] ); } else { /* this a 3-phase model */ dstate_setinfo("input.phases", "3" ); dstate_setinfo("ups.load", "%u", tab_reg[3] ); dstate_setinfo("ups.L1.load", "%u", tab_reg[0] ); dstate_setinfo("ups.L2.load", "%u", tab_reg[1] ); dstate_setinfo("ups.L3.load", "%u", tab_reg[2] ); dstate_setinfo("input.bypass.L1-N.voltage", "%u", tab_reg[6] ); dstate_setinfo("input.bypass.L2-N.voltage", "%u", tab_reg[7] ); dstate_setinfo("input.bypass.L3-N.voltage", "%u", tab_reg[8] ); dstate_setinfo("output.L1-N.voltage", "%u", tab_reg[9] ); dstate_setinfo("output.L2-N.voltage", "%u", tab_reg[10] ); dstate_setinfo("output.L3-N.voltage", "%u", tab_reg[11] ); if (tab_reg[15] != 0xFFFF) dstate_setinfo("output.L1.current", "%u", tab_reg[15] ); if (tab_reg[16] != 0xFFFF) dstate_setinfo("output.L2.current", "%u", tab_reg[16] ); if (tab_reg[17] != 0xFFFF) dstate_setinfo("output.L3.current", "%u", tab_reg[17] ); } dstate_setinfo("battery.charge", "%u", tab_reg[4] ); dstate_setinfo("battery.capacity", "%u", (unsigned int)(tab_reg[5]/10) ); dstate_setinfo("battery.voltage", "%.2f", (double) (tab_reg[20]) / 10); dstate_setinfo("battery.current", "%.2f", (double) (tab_reg[24]) / 10 ); dstate_setinfo("battery.runtime", "%u", tab_reg[23] ); dstate_setinfo("input.bypass.frequency", "%u", (unsigned int)(tab_reg[18]/10) ); dstate_setinfo("output.frequency", "%u", (unsigned int)(tab_reg[19]/10) ); if (tab_reg[22] != 0xFFFF) { dstate_setinfo("ambient.1.present", "yes"); dstate_setinfo("ambient.1.temperature", "%u", tab_reg[22] ); } if (tab_reg[23] == 0xFFFF) { /* battery.runtime == 0xFFFF means we're on mains */ status_set("OL"); } else if (tab_reg[23] > BATTERY_RUNTIME_CRITICAL) { /* we still have mora than BATTERY_RUNTIME_CRITICAL min left ? */ status_set("OB"); } else { status_set("LB"); } /*TODO: --essential ups.status TRIM/BOOST/OVER ups.alarm --dangerous ups.shutdown shutdown.return shutdown.stop shutdown.reboot shutdown.reboot.graceful bypass.start beeper.enable beeper.disable */ alarm_commit(); status_commit(); dstate_dataok(); return; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { } void upsdrv_initups(void) { int r; upsdebugx(2, "upsdrv_initups"); modbus_ctx = modbus_new_rtu(device_path, 9600, 'N', 8, 1); if (modbus_ctx == NULL) fatalx(EXIT_FAILURE, "Unable to create the libmodbus context"); r = modbus_set_slave(modbus_ctx, MODBUS_SLAVE_ID); /* slave ID */ if (r < 0) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "Invalid modbus slave ID %d",MODBUS_SLAVE_ID); } if (modbus_connect(modbus_ctx) == -1) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "modbus_connect: unable to connect: %s", modbus_strerror(errno)); } } void upsdrv_cleanup(void) { if (modbus_ctx != NULL) { modbus_close(modbus_ctx); modbus_free(modbus_ctx); } } /* Modbus Read Input Registers */ static int mrir(modbus_t * arg_ctx, int addr, int nb, uint16_t * dest) { int r, i; /* zero out the thing, because we might have reused it */ for (i=0; i * Author: Kirill Smelkov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * - NOTE the following document is referenced in this driver: * * TE-36862-B4 "COMLI COMMUNICATION PROTOCOL IMPLEMENTED IN PRS SYSTEMS", * by Eltek A/S * * * - AL175 debug levels: * * 1 user-level trace (status, instcmd, etc...) * 2 status decode errors * 3 COMLI proto handling errors * 4 raw IO trace * */ #include "main.h" #include "serial.h" #include "timehead.h" #include #include #include #include #include #include "nut_stdint.h" typedef uint8_t byte_t; #define DRIVER_NAME "Eltek AL175/COMLI driver" #define DRIVER_VERSION "0.17" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Kirill Smelkov \n" \ "Marine & Bridge Navigation Systems ", DRV_EXPERIMENTAL, { NULL } }; #define STX 0x02 #define ETX 0x03 #define ACK 0x06 /************ * RAW DATA * ************/ /** * raw_data buffer representation */ typedef struct { byte_t *buf; /*!< the whole buffer address */ size_t buf_size; /*!< the whole buffer size */ byte_t *begin; /*!< begin of content */ byte_t *end; /*!< one-past-end of content */ } raw_data_t; /** * pseudo-alloca raw_data buffer (alloca is not in POSIX) * @param varp ptr-to local raw_data_t variable to which to alloca * @param buf_array array allocated on stack which will be used as storage * (must be auto-variable) * @return alloca'ed memory as raw_data * * Example: * * raw_data_t ack; * byte_t ack_buf[8]; * * raw_alloc_onstack(&ack, ack_buf); */ #define raw_alloc_onstack(varp, buf_array) do { \ (varp)->buf = &(buf_array)[0]; \ (varp)->buf_size = sizeof(buf_array); \ \ (varp)->begin = (varp)->buf; \ (varp)->end = (varp)->buf; \ } while (0) /** * xmalloc raw buffer * @param size size in bytes * @return xmalloc'ed memory as raw_data */ static raw_data_t raw_xmalloc(size_t size) { raw_data_t data; data.buf = xmalloc(size); data.buf_size = size; data.begin = data.buf; data.end = data.buf; return data; } /** * free raw_data buffer * @param buf raw_data buffer to free */ static void raw_free(raw_data_t *buf) { free(buf->buf); buf->buf = NULL; buf->buf_size = 0; buf->begin = NULL; buf->end = NULL; } /***************************************************************************/ /*************** * COMLI types * ***************/ /** * COMLI message header info * @see 1. INTRODUCTION */ typedef struct { int id; /*!< Id[1:2] */ int stamp; /*!< Stamp[3] */ int type; /*!< Mess Type[4] */ } msg_head_t; /** * COMLI IO header info * @see 1. INTRODUCTION */ typedef struct { size_t addr; /*!< Addr[5:8] */ size_t len; /*!< NOB[9:10] */ } io_head_t; /** * maximum allowed io.len value */ #define IO_LEN_MAX 0xff /** * COMLI header info * @see 1. INTRODUCTION */ typedef struct { msg_head_t msg; /*!< message header [1:4] */ io_head_t io; /*!< io header [5:10] */ } comli_head_t; /****************** * MISC UTILITIES * ******************/ /** * convert hex string to int * @param head input string * @param len string length * @return parsed value (>=0) if success, -1 on error */ static long from_hex(const byte_t *head, unsigned len) { long val=0; while (len-- != 0) { int ch = *head; if (!isxdigit(ch)) return -1; /* wrong character */ val *= 0x10; if (isdigit(ch)) { val += (ch-'0'); } else { /* ch = toupper(ch) without locale-related problems */ if (ch < 'A') ch += 'A' - 'a'; val += 0x0A + (ch-'A'); } ++head; } return val; } /** * compute checksum of a buffer * @see 10. CHECKSUM BCC * @param buf buffer address * @param count no. of bytes in the buffer * @return computed checksum */ static byte_t compute_bcc(const byte_t *buf, size_t count) { byte_t bcc=0; size_t i; for (i=0; i> 7 ) | (byte_t)( (x & 0x40) >> 5 ) | (byte_t)( (x & 0x20) >> 3 ) | (byte_t)( (x & 0x10) >> 1 ) | (byte_t)( (x & 0x08) << 1 ) | (byte_t)( (x & 0x04) << 3 ) | (byte_t)( (x & 0x02) << 5 ) | (byte_t)( (x & 0x01) << 7 ); *buf = x; ++buf; --count; } } /********************************************************************/ /* * communication basics * * ME (Monitor Equipment) * PRS (Power Rectifier System) /think of it as of UPS in common speak/ * * there are 2 types of transactions: * * 'ACTIVATE COMMAND' * ME -> PRS (al_prep_activate) * ME <- PRS [ack] (al_check_ack) * * * 'READ REGISTER' * ME -> PRS (al_prep_read_req) * ME <- PRS [data] (al_parse_reply) * */ /******************** * COMLI primitives * ********************/ /************************ * COMLI: OUTPUT FRAMES * ************************/ /** * prepare COMLI sentence * @see 1. INTRODUCTION * @param dest [out] where to put the result * @param h COMLI header info * @param buf data part of the sentence * @param count amount of data bytes in the sentence * * @note: the data are copied into the sentence "as-is", there is no conversion is done. * if the caller wants to reverse bits it is necessary to call reverse_bits(...) prior * to comli_prepare. */ static void comli_prepare(raw_data_t *dest, const comli_head_t *h, const void *buf, size_t count) { /* * 0 1 2 3 4 5 6 7 8 9 10 11 - - - N-1 N * +-----+---------+-------+------+-------------------------+-----------+------------+-----+-----+ * | STX | IDh IDl | Stamp | type | addr1 addr2 addr3 addr4 | NOBh NOBl | ...data... | ETX | BCC | * +-----+---------+-------+------+-------------------------+-----------+------------+-----+-----+ * * ^ ^ * | | *begin end */ byte_t *out = dest->begin; /* it's caller responsibility to allocate enough space. else it is a bug in the program */ if ( (out+11+count+2) > (dest->buf + dest->buf_size) ) fatalx(EXIT_FAILURE, "too small dest in comli_prepare\n"); out[0] = STX; snprintf((char *)out+1, 10+1, "%02X%1i%1i%04zX%02zX", (unsigned int)h->msg.id, h->msg.stamp, h->msg.type, h->io.addr, h->io.len); memcpy(out+11, buf, count); reverse_bits(out+11, count); out[11+count] = ETX; out[12+count] = compute_bcc(out+1, 10+count+1); dest->end = dest->begin + (11+count+2); } /** * prepare AL175 read data request * @see 2. MESSAGE TYPE 2 (COMMAND SENT FROM MONITORING EQUIPMENT) * @param dest [out] where to put the result * @param addr start address of requested area * @param count no. of requested bytes */ static void al_prep_read_req(raw_data_t *dest, size_t addr, size_t count) { comli_head_t h; h.msg.id = 0x14; h.msg.stamp = 1; h.msg.type = 2; h.io.addr = addr; h.io.len = count; comli_prepare(dest, &h, NULL, 0); } /** * prepare AL175 activate command * @see 4. MESSAGE TYPE 0 (ACTIVATE COMMAND) * @param dest [out] where to put the result * @param cmd command type [11] * @param subcmd command subtype [12] * @param pr1 first parameter [13:14] * @param pr2 second parameter [15:16] * @param pr3 third parameter [17:18] */ static void al_prep_activate(raw_data_t *dest, byte_t cmd, byte_t subcmd, uint16_t pr1, uint16_t pr2, uint16_t pr3) { comli_head_t h; char data[8+1]; h.msg.id = 0x14; h.msg.stamp = 1; h.msg.type = 0; h.io.addr = 0x4500; h.io.len = 8; /* NOTE: doc says we should use ASCII coding here, but the actual * values are > 0x80, so we use binary coding. And have to * make this "fit" into the char array required by snprintf */ data[0] = (char)cmd; data[1] = (char)subcmd; /* FIXME? One CI testcase builder claims here that * warning: '%2X' directive output may be truncated writing * between 2 and 4 bytes into a region of size between 3 and 5 * [-Wformat-truncation=] * but none others do, and I can't figure out how it thinks so :/ * * Per https://stackoverflow.com/questions/51534284/how-to-circumvent-format-truncation-warning-in-gcc * https://www.mail-archive.com/gcc-bugs@gcc.gnu.org/msg521037.html * and simlar googlable sources, this seems to be a bug-or-feature * linked to non-zero optimization level and/or not checking for the * return value (conveys runtime errors if any do happen). */ assert (pr1 <= UINT8_MAX); assert (pr2 <= UINT8_MAX); assert (pr3 <= UINT8_MAX); if (0 > snprintf(data+2, 6+1, "%2X%2X%2X", pr1, pr2, pr3)) { data[8] = '\0'; } comli_prepare(dest, &h, data, 8); } /*********************** * COMLI: INPUT FRAMES * ***********************/ /** * check COMLI frame for correct layout and bcc * @param f frame to check * * @return 0 (ok) -1 (error) */ static int comli_check_frame(/*const*/ raw_data_t f) { int bcc; byte_t *tail; if ( (f.end - f.begin) < 2 ) return -1; if (*f.begin!=STX) return -1; tail = f.end - 2; if (tail <= f.begin) return -1; if (tail[0]!=ETX) return -1; bcc = compute_bcc(f.begin+1, (size_t)(f.end - f.begin) - 2 /*STX & BCC*/); if (bcc!= tail[1]) return -1; return 0; } /** * parse reply header from PRS * @see 3. MESSAGE TYPE 0 (REPLY FROM PRS ON MESSAGE TYPE 2) * * @param io [out] parsed io_header * @param raw_reply_head [in] raw reply header from PRS * @return 0 (ok), -1 (error) * * @see al_parse_reply */ static int al_parse_reply_head(io_head_t *io, const raw_data_t raw_reply_head) { /* * 0 1 2 3 4 5 6 7 8 9 10 * +-----+---------+-------+------+-------------------------+-----------+-----------+ * | STX | IDh IDl | Stamp | type | addr1 addr2 addr3 addr4 | NOBh NOBl | ......... | * +-----+---------+-------+------+-------------------------+-----------+-----------+ * * ^ ^ * | | * begin end */ size_t io_addr, io_len; const byte_t *reply_head = raw_reply_head.begin - 1; if ( (raw_reply_head.end - raw_reply_head.begin) != 10) { upsdebugx(3, "%s: wrong size\t(%i != 10)", __func__, (int)(raw_reply_head.end - raw_reply_head.begin)); return -1; /* wrong size */ } if (reply_head[1]!='0' || reply_head[2]!='0') { upsdebugx(3, "%s: wrong id\t('%c%c' != '00')", __func__, reply_head[1], reply_head[2]); return -1; /* wrong id */ } if (reply_head[3]!='1') { upsdebugx(3, "%s: wrong stamp\t('%c' != '1')", __func__, reply_head[3]); return -1; /* wrong stamp */ } if (reply_head[4]!='0') { upsdebugx(3, "%s: wrong type\t('%c' != '0')", __func__, reply_head[4]); return -1; /* wrong type */ } /* Avoid signed/unsigned implicit conversion warnings * At least, when shuffling a signed long into unsigned long, * don't have to worry about overflows */ io_addr = (size_t)from_hex(&reply_head[5], 4); if (io_addr == -1UL) { upsdebugx(3, "%s: invalid addr\t('%c%c%c%c')", __func__, reply_head[5], reply_head[6], reply_head[7], reply_head[8]); return -1; /* wrong addr */ } io_len = (size_t)from_hex(&reply_head[9], 2); if (io_len == -1UL) { upsdebugx(3, "%s: invalid nob\t('%c%c')", __func__, reply_head[9], reply_head[10]); return -1; /* wrong NOB */ } if (io_len > IO_LEN_MAX) { upsdebugx(3, "nob too big\t(%" PRIuSIZE " > %i)", io_len, IO_LEN_MAX); return -1; /* too much data claimed */ } io->addr = io_addr; io->len = io_len; return 0; } /** * parse reply from PRS * @see 3. MESSAGE TYPE 0 (REPLY FROM PRS ON MESSAGE TYPE 2) * @param io_head [out] parsed io_header * @param io_buf [in] [out] raw_data where to place incoming data (see ...data... below) * @param raw_reply raw reply from PRS to check * @return 0 (ok), -1 (error) * * @see al_parse_reply_head */ static int al_parse_reply(io_head_t *io_head, raw_data_t *io_buf, /*const*/ raw_data_t raw_reply) { /* * 0 1 2 3 4 5 6 7 8 9 10 11 - - - N-1 N * +-----+---------+-------+------+-------------------------+-----------+------------+-----+-----+ * | STX | IDh IDl | Stamp | type | addr1 addr2 addr3 addr4 | NOBh NOBl | ...data... | ETX | BCC | * +-----+---------+-------+------+-------------------------+-----------+------------+-----+-----+ * * ^ ^ * | | * begin end */ int err; size_t i, io_buf_len; const byte_t *reply = NULL; /* 1: extract header and parse it */ /*const*/ raw_data_t raw_reply_head = raw_reply; if (raw_reply_head.begin + 10 <= raw_reply_head.end) raw_reply_head.end = raw_reply_head.begin + 10; err = al_parse_reply_head(io_head, raw_reply_head); if (err==-1) return -1; /* 2: process data */ reply = raw_reply.begin - 1; if ( (raw_reply.end - raw_reply.begin) != (ptrdiff_t)(10 + io_head->len)) { upsdebugx(3, "%s: corrupt sentence\t(%i != %" PRIuSIZE ")", __func__, (int)(raw_reply.end - raw_reply.begin), 10 + io_head->len); return -1; /* corrupt sentence */ } /* 3: extract the data */ if (io_buf->buf_size < io_head->len) { upsdebugx(3, "%s: too much data to fit in io_buf\t(%" PRIuSIZE " > %" PRIuSIZE ")", __func__, io_head->len, io_buf->buf_size); return -1; /* too much data to fit in io_buf */ } io_buf->begin = io_buf->buf; io_buf->end = io_buf->begin; for (i=0; ilen; ++i) *(io_buf->end++) = reply[11+i]; assert(io_buf->end - io_buf->begin >= 0); io_buf_len = (size_t)(io_buf->end - io_buf->begin); reverse_bits(io_buf->begin, io_buf_len ); upsdebug_hex(3, "\t\t--> payload", io_buf->begin, io_buf_len); return 0; /* all ok */ } /** * check acknowledge from PRS * @see 5. ACKNOWLEDGE FROM PRS * @param raw_ack raw acknowledge from PRS to check * @return 0 on success, -1 on error */ static int al_check_ack(/*const*/ raw_data_t raw_ack) { /* * 0 1 2 3 4 5 6 7 * +-----+---------+-------+------+-----+-----+-----+ * | STX | IDh IDl | Stamp | type | ACK | ETX | BCC | * +-----+---------+-------+------+-----+-----+-----+ * * ^ ^ * | | * begin end */ const byte_t *ack = raw_ack.begin - 1; if ( (raw_ack.end - raw_ack.begin) !=5) { upsdebugx(3, "%s: wrong size\t(%i != 5)", __func__, (int)(raw_ack.end - raw_ack.begin)); return -1; /* wrong size */ } if (ack[1]!='0' || ack[2]!='0') { upsdebugx(3, "%s: wrong id\t('%c%c' != '00')", __func__, ack[1], ack[2]); return -1; /* wrong id */ } /* the following in not mandated. it is just said it will be * "same as one received". but we always send '1' (0x31) as stamp * (see 4. MESSAGE TYPE 0 (ACTIVATE COMMAND). Hence, stamp checking * is hardcoded here. */ if (ack[3]!='1') { upsdebugx(3, "%s: wrong stamp\t('%c' != '1')", __func__, ack[3]); return -1; /* wrong stamp */ } if (ack[4]!='1') { upsdebugx(3, "%s: wrong type\t('%c' != '1')", __func__, ack[4]); return -1; /* wrong type */ } if (ack[5]!=ACK) { upsdebugx(3, "%s: wrong ack\t(0x%02X != 0x%02X)", __func__, ack[5], (unsigned int)ACK); return -1; /* wrong ack */ } return 0; } /******************************************************************/ /********** * SERIAL * **********/ /* clear any flow control (copy from powercom.c) */ static void ser_disable_flow_control (void) { struct termios tio; tcflag_t x; tcgetattr (upsfd, &tio); /* Clumsy rewrite of a one-liner * tio.c_iflag &= ~ (IXON | IXOFF); * to avoid type conversion warnings */ x = (IXON | IXOFF); tio.c_iflag &= ~ x; tio.c_cc[VSTART] = _POSIX_VDISABLE; tio.c_cc[VSTOP] = _POSIX_VDISABLE; upsdebugx(4, "Flow control disable"); /* disable any flow control */ tcsetattr(upsfd, TCSANOW, &tio); } static void flush_rx_queue(void) { ser_flush_in(upsfd, "", /*verbose=*/nut_debug_level); } /** * transmit frame to PRS * * @param dmsg debug message prefix * @param frame the frame to tansmit * @return 0 (ok) -1 (error) */ static int tx(const char *dmsg, /*const*/ raw_data_t frame) { ssize_t err; size_t frame_len; assert(frame.end - frame.begin >= 0); frame_len = (size_t)(frame.end - frame.begin); upsdebug_ascii(3, dmsg, frame.begin, frame_len); err = ser_send_buf(upsfd, frame.begin, frame_len ); if (err==-1) { upslog_with_errno(LOG_ERR, "failed to send frame to PRS"); return -1; } if (err != (ssize_t)frame_len) { upslogx(LOG_ERR, "sent incomplete frame to PRS"); return -1; } return 0; } /*********** * CHATTER * ***********/ static time_t T_io_begin; /* start of current I/O transaction */ static int T_io_timeout; /* in seconds */ /* start new I/O transaction with maximum time limit */ static void io_new_transaction(int timeout) { T_io_begin = time(NULL); T_io_timeout = timeout; } /** * get next character from input stream * * @param ch ptr-to where store result * * @return -1 (error) 0 (timeout) >0 (got it) * */ static ssize_t get_char(char *ch) { time_t now = time(NULL); long rx_timeout; rx_timeout = T_io_timeout - (now - T_io_begin); /* negative rx_timeout -> time already out */ if (rx_timeout < 0) return 0; return ser_get_char(upsfd, ch, rx_timeout, 0); } /** * get next characters from input stream * * @param buf ptr-to output buffer * @param len buffer length * * @return -1 (error) 0 (timeout) >0 (no. of characters actually read) * */ static ssize_t get_buf(byte_t *buf, size_t len) { time_t now = time(NULL); long rx_timeout; rx_timeout = T_io_timeout - (now - T_io_begin); /* negative rx_timeout -> time already out */ if (rx_timeout < 0) return 0; return ser_get_buf_len(upsfd, buf, len, rx_timeout, 0); } /** * scan incoming bytes for specific character * * @return 0 (got it) -1 (error) */ static int scan_for(char c) { char in; ssize_t err; while (1) { err = get_char(&in); if (err==-1 || err==0 /*timeout*/) return -1; if (in==c) break; } return 0; } /** * receive 'activate command' ACK from PRS * * @return 0 (ok) -1 (error) */ static int recv_command_ack(void) { ssize_t err; raw_data_t ack; byte_t ack_buf[8]; /* 1: STX */ err = scan_for(STX); if (err==-1) return -1; raw_alloc_onstack(&ack, ack_buf); *(ack.end++) = STX; /* 2: ID1 ID2 STAMP MSG_TYPE ACK ETX BCC */ err = get_buf(ack.end, 7); if (err!=7) return -1; ack.end += 7; /* frame constructed - let's verify it */ assert (ack.end - ack.begin >= 0); upsdebug_ascii(3, "rx (ack):\t\t", ack.begin, (size_t)(ack.end - ack.begin)); /* generic layout */ err = comli_check_frame(ack); if (err==-1) return -1; /* shrink frame */ ack.begin += 1; ack.end -= 2; return al_check_ack(ack); } /** * receive 'read register' data from PRS * @param io [out] io header of received data * @param io_buf [in] [out] where to place incoming data * * @return 0 (ok) -1 (error) */ static int recv_register_data(io_head_t *io, raw_data_t *io_buf) { ssize_t err; int ret; size_t reply_head_len; raw_data_t reply_head; raw_data_t reply; byte_t reply_head_buf[11]; /* 1: STX */ err = scan_for(STX); if (err==-1) return -1; raw_alloc_onstack(&reply_head, reply_head_buf); *(reply_head.end++) = STX; /* 2: ID1 ID2 STAMP MSG_TYPE ADDR1 ADDR2 ADDR3 ADDR4 LEN1 LEN2 */ err = get_buf(reply_head.end, 10); if (err!=10) return -1; reply_head.end += 10; assert (reply_head.end - reply_head.begin >= 0); upsdebug_ascii(3, "rx (head):\t", reply_head.begin, (size_t)(reply_head.end - reply_head.begin)); /* 3: check header, extract IO info */ reply_head.begin += 1; /* temporarily strip STX */ err = al_parse_reply_head(io, reply_head); if (err==-1) return -1; reply_head.begin -= 1; /* restore STX */ upsdebugx(4, "\t\t--> addr: 0x%" PRIxSIZE " len: 0x%" PRIxSIZE, io->addr, io->len); /* 4: allocate space for full reply and copy header there */ reply = raw_xmalloc(11/*head*/ + io->len/*data*/ + 2/*ETX BCC*/); assert (reply_head.end - reply_head.begin >= 0); reply_head_len = (size_t)(reply_head.end - reply_head.begin); memcpy(reply.end, reply_head.begin, reply_head_len); reply.end += reply_head_len; /* 5: receive tail of the frame */ err = get_buf(reply.end, io->len + 2); if (err!=(int)(io->len+2)) { upsdebugx(4, "rx_tail failed, err=%" PRIiSIZE " (!= %" PRIuSIZE ")", err, io->len+2); ret = -1; goto out; } reply.end += io->len + 2; /* frame constructed, let's verify it */ assert (reply.end - reply.begin >= 0); upsdebug_ascii(3, "rx (head+data):\t", reply.begin, (size_t)(reply.end - reply.begin)); /* generic layout */ err = comli_check_frame(reply); if (err==-1) { upsdebugx(3, "%s: corrupt frame", __func__); ret = -1; goto out; } /* shrink frame */ reply.begin += 1; reply.end -= 2; /* XXX: a bit of processing duplication here */ ret = al_parse_reply(io, io_buf, reply); out: raw_free(&reply); return ret; } /*****************************************************************/ /********************* * AL175: DO COMMAND * *********************/ /** * do 'ACTIVATE COMMAND' * * @return 0 (ok) -1 (error) */ static int al175_do(byte_t cmd, byte_t subcmd, uint16_t pr1, uint16_t pr2, uint16_t pr3) { int err; raw_data_t CTRL_frame; byte_t CTRL_frame_buf[512]; raw_alloc_onstack(&CTRL_frame, CTRL_frame_buf); al_prep_activate(&CTRL_frame, cmd, subcmd, pr1, pr2, pr3); flush_rx_queue(); /* DROP */ err = tx("tx (ctrl):\t", CTRL_frame); /* TX */ if (err==-1) return -1; return recv_command_ack(); /* RX */ } /** * 'READ REGISTER' * */ static int al175_read(byte_t *dst, size_t addr, size_t count) { int err; raw_data_t REQ_frame; raw_data_t rx_data; io_head_t io; byte_t REQ_frame_buf[512]; raw_alloc_onstack(&REQ_frame, REQ_frame_buf); al_prep_read_req(&REQ_frame, addr, count); flush_rx_queue(); /* DROP */ err = tx("tx (req):\t", REQ_frame); /* TX */ if (err==-1) return -1; rx_data.buf = dst; rx_data.buf_size = count; rx_data.begin = dst; rx_data.end = dst; err = recv_register_data(&io, &rx_data); if (err==-1) return -1; if ((rx_data.end - rx_data.begin) < 0 || (size_t)(rx_data.end - rx_data.begin) != count) return -1; if ( (io.addr != addr) || (io.len != count) ) { upsdebugx(3, "%s: io_head mismatch\t(%" PRIxSIZE ",%" PRIxSIZE " != %" PRIxSIZE ",%" PRIxSIZE ")", __func__, io.addr, io.len, addr, count); return -1; } return 0; } /************* * NUT STUFF * *************/ /**************************** * ACTIVATE COMMANDS table * * see 8. ACTIVATE COMMANDS */ typedef uint16_t mm_t; /* minutes */ typedef uint16_t VV_t; /* voltage */ #define Z1 , 0 #define Z2 , 0, 0 #define Z3 , 0, 0, 0 #define ACT int /* Declare to keep compiler happy even if some routines below are not used currently */ ACT TOGGLE_PRS_ONOFF (void); ACT CANCEL_BOOST (void); ACT STOP_BATTERY_TEST (void); ACT START_BATTERY_TEST (VV_t EndVolt, mm_t Minutes); ACT SET_FLOAT_VOLTAGE (VV_t v); ACT SET_BOOST_VOLTAGE (VV_t v); ACT SET_HIGH_BATTERY_LIMIT (VV_t Vhigh); ACT SET_LOW_BATTERY_LIMIT (VV_t Vlow); ACT SET_DISCONNECT_LEVEL_AND_DELAY (VV_t level, mm_t delay); ACT RESET_ALARMS (void); ACT CHANGE_COMM_PROTOCOL (void); ACT SET_VOLTAGE_AT_ZERO_T (VV_t v); ACT SET_SLOPE_AT_ZERO_T (VV_t mv_per_degree); ACT SET_MAX_TCOMP_VOLTAGE (VV_t v); ACT SET_MIN_TCOMP_VOLTAGE (VV_t v); ACT SWITCH_TEMP_COMP (uint16_t on); ACT SWITCH_SYM_ALARM (void); /* Implement */ ACT TOGGLE_PRS_ONOFF (void) { return al175_do(0x81, 0x80 Z3); } ACT CANCEL_BOOST (void) { return al175_do(0x82, 0x80 Z3); } ACT STOP_BATTERY_TEST (void) { return al175_do(0x83, 0x80 Z3); } ACT START_BATTERY_TEST (VV_t EndVolt, mm_t Minutes) { return al175_do(0x83, 0x81, EndVolt, Minutes Z1); } ACT SET_FLOAT_VOLTAGE (VV_t v) { return al175_do(0x87, 0x80, v Z2); } ACT SET_BOOST_VOLTAGE (VV_t v) { return al175_do(0x87, 0x81, v Z2); } ACT SET_HIGH_BATTERY_LIMIT (VV_t Vhigh) { return al175_do(0x87, 0x82, Vhigh Z2); } ACT SET_LOW_BATTERY_LIMIT (VV_t Vlow) { return al175_do(0x87, 0x83, Vlow Z2); } ACT SET_DISCONNECT_LEVEL_AND_DELAY (VV_t level, mm_t delay) { return al175_do(0x87, 0x84, level, delay Z1); } ACT RESET_ALARMS (void) { return al175_do(0x88, 0x80 Z3); } ACT CHANGE_COMM_PROTOCOL (void) { return al175_do(0x89, 0x80 Z3); } ACT SET_VOLTAGE_AT_ZERO_T (VV_t v) { return al175_do(0x8a, 0x80, v Z2); } ACT SET_SLOPE_AT_ZERO_T (VV_t mv_per_degree) { return al175_do(0x8a, 0x81, mv_per_degree Z2); } ACT SET_MAX_TCOMP_VOLTAGE (VV_t v) { return al175_do(0x8a, 0x82, v Z2); } ACT SET_MIN_TCOMP_VOLTAGE (VV_t v) { return al175_do(0x8a, 0x83, v Z2); } ACT SWITCH_TEMP_COMP (uint16_t on) { return al175_do(0x8b, 0x80, on Z2); } ACT SWITCH_SYM_ALARM (void) { return al175_do(0x8c, 0x80 Z3); } /** * extract double value from a word */ static double d16(byte_t data[2]) { return (data[1] + 0x100*data[0]) / 100.0; } void upsdrv_updateinfo(void) { /* int flags; */ byte_t x4000[9]; /* registers from 0x4000 to 0x4040 inclusive */ byte_t x4048[2]; /* 0x4048 - 0x4050 */ byte_t x4100[8]; /* 0x4100 - 0x4138 */ byte_t x4180[8]; /* 0x4180 - 0x41b8 */ byte_t x4300[2]; /* 0x4300 - 0x4308 */ int err; double batt_current = 0.0; upsdebugx(4, " "); upsdebugx(4, "UPDATEINFO"); upsdebugx(4, "----------"); io_new_transaction(/*timeout=*/3); #define RECV(reg) do { \ err = al175_read(x ## reg, 0x ## reg, sizeof(x ## reg)); \ if (err==-1) { \ dstate_datastale(); \ return; \ } \ } while (0) RECV(4000); RECV(4048); RECV(4100); RECV(4180); RECV(4300); status_init(); /* XXX non conformant with NUT naming & not well understood what they mean */ #if 0 /* 0x4000 DIGITAL INPUT 1-8 */ dstate_setinfo("load.fuse", (x4000[0] & 0x80) ? "OK" : "BLOWN"); dstate_setinfo("battery.fuse", (x4000[0] & 0x40) ? "OK" : "BLOWN"); dstate_setinfo("symalarm.fuse", (x4000[0] & 0x20) ? "OK" : "BLOWN"); /* 0x4008 BATTERY INFORMATION */ dstate_setinfo("battery.contactor", (x4000[1] & 0x80) ? "XX" : "YY"); /* FIXME */ dstate_setinfo("load.contactor", (x4000[1] & 0x40) ? "XX" : "YY"); /* FIXME */ dstate_setinfo("lvd.contactor", (x4000[1] & 0x20) ? "XX" : "YY"); /* FIXME */ #endif if (x4000[0] & 0x40){ dstate_setinfo("battery.fuse", "FAIL"); status_set("RB"); }else{ dstate_setinfo("battery.fuse", "OK"); } if (x4000[0] & 0x20){ dstate_setinfo("battery.symmetry", "FAIL"); status_set("RB"); }else{ dstate_setinfo("battery.symmetry", "OK"); } if (x4000[1] & 0x01) /* battery test running */ status_set("TEST"); /* TODO: others from 0x4008 */ /* 0x4010 NOT USED */ /* 0x4018 NOT USED */ switch (x4000[4]) { /* 0x4020 MAINS VOLTAGE STATUS */ case 0: status_set("OL"); break; case 1: status_set("OB"); break; case 2: /* doc: "not applicable" */ default: upsdebugx(2, "%s: invalid mains voltage status\t(%i)", __func__, x4000[4]); } /* 0x4028 SYSTEM ON OFF STATUS */ switch (x4000[5]) { case 0: /* system on */ break; case 1: status_set("OFF"); break; default: upsdebugx(2, "%s: invalid system on/off status\t(%i)", __func__, x4000[5]); } switch (x4000[6]) { /* 0x4030 BATTERY TEST FAIL */ case 0: dstate_setinfo("ups.test.result", "OK"); break; case 1: status_set("RB"); dstate_setinfo("ups.test.result", "FAIL"); break; default: upsdebugx(2, "%s: invalid battery test fail\t(%i)", __func__, x4000[6]); } switch (x4000[7]) { /* 0x4038 BATTERY VOLTAGE STATUS */ case 0: /* normal */ break; case 1: status_set("LB"); break; case 2: status_set("HB"); break; default: upsdebugx(2, "%s: invalid battery voltage status\t(%i)", __func__, x4000[7]); } switch (x4000[8]) { /* 0x4040 POS./NEG. BATT. CURRENT */ case 0: batt_current = +1.0; break; /* positive */ case 1: batt_current = -1.0; break; /* negative */ default: upsdebugx(2, "%s: invalid pos/neg battery current\t(%i)", __func__, x4000[8]); } switch (x4048[0]) { /* 0x4048 BOOST STATUS */ case 0: /* no boost */; break; case 1: status_set("BOOST"); break; default: upsdebugx(2, "%s: invalid boost status\t(%i)", __func__, x4048[0]); } { const char *v=NULL; switch (x4048[1]) { /* 0x4050 SYSTEM VOLTAGE STAT. */ case 0: v = "48"; break; case 1: v = "24"; break; case 2: v = "12"; break; case 3: v = "26"; break; case 4: v = "60"; break; default: upsdebugx(2, "%s: invalid system voltage status\t(%i)", __func__, x4048[1]); } if (v) dstate_setinfo("output.voltage.nominal", "%s", v); } /* 0x4100 BATTERY VOLTAGE REF */ dstate_setinfo("battery.voltage.nominal", "%.2f", d16(x4100+0)); /* 0x4110 BOOST VOLTAGE REF */ dstate_setinfo("input.transfer.boost.low", "%.2f", d16(x4100+2)); /* XXX: boost.high ? */ /* 0x4120 HIGH BATT VOLT REF XXX */ /* 0x4130 LOW BATT VOLT REF XXX */ /* 0x4180 FLOAT VOLTAGE XXX */ /* 0x4190 BATT CURRENT */ batt_current *= d16(x4180+2); dstate_setinfo("battery.current", "%.2f", batt_current); /* 0x41b0 LOAD CURRENT (output.current in NUT) */ dstate_setinfo("output.current", "%.2f", d16(x4180+6)); /* 0x4300 BATTERY TEMPERATURE */ dstate_setinfo("battery.temperature", "%.2f", d16(x4300+0)); status_commit(); upsdebugx(1, "STATUS: %s", dstate_getinfo("ups.status")); dstate_dataok(); /* out: */ return; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* TODO use TOGGLE_PRS_ONOFF for shutdown */ /* tell the UPS to shut down, then return - DO NOT SLEEP HERE */ /* maybe try to detect the UPS here, but try a shutdown even if it doesn't respond at first if possible */ /* replace with a proper shutdown function */ upslogx(LOG_ERR, "shutdown not supported"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); /* you may have to check the line status since the commands for toggling power are frequently different for OL vs. OB */ /* OL: this must power cycle the load if possible */ /* OB: the load must remain off until the power returns */ } static int instcmd(const char *cmdname, const char *extra) { int err; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); io_new_transaction(/*timeout=*/5); /* * test.battery.start * test.battery.stop */ if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); err = START_BATTERY_TEST(24, 1); return (!err ? STAT_INSTCMD_HANDLED : STAT_INSTCMD_FAILED); } if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); err = STOP_BATTERY_TEST(); return (!err ? STAT_INSTCMD_HANDLED : STAT_INSTCMD_FAILED); } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } /* no help */ void upsdrv_help(void) { } /* no -x flags */ void upsdrv_makevartable(void) { } void upsdrv_initups(void) { upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B9600); ser_disable_flow_control(); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } void upsdrv_initinfo(void) { /* TODO issue short io with UPS to detect it's presence */ /* try to detect the UPS here - call fatal_with_errno(EXIT_FAILURE, ) if it fails */ dstate_setinfo("ups.mfr", "Eltek"); dstate_setinfo("ups.model", "AL175"); /* ... */ /* instant commands */ dstate_addcmd ("test.battery.start"); dstate_addcmd ("test.battery.stop"); /* TODO rest instcmd(s) */ upsh.instcmd = instcmd; } nut-2.8.4/drivers/huawei-ups2000.c0000644000175000017500000017651615044656702013520 00000000000000/* * huawei-ups2000.c - Driver for Huawei UPS2000 (1kVA-3kVA) * * Note: If you're trying to debug the driver because it doesn't work, * please BE SURE to read the manual in "docs/man/huawei-ups2000.txt" * first! Otherwise you are guaranteed to waste your time! * * Long story short, Huawei UPS2000 (1kVA-3kVA) can be accessed via * RS-232, USB, or an optional RMS-MODBUS01B (RS-485) adapter. Only * RS-232 and USB are supported, RS-485 is not. Also, for most UPS * units, their USB ports are implemented via the MaxLinear RX21V1410 * USB-to-serial converter, and they DO NOT WORK without a special * "xr_serial" driver, only available on Linux 5.12+ (not BSD or Solaris). * Without this driver, the USB can still be recognized as a generic * USB ACM device, but it DOES NOT WORK. Alternatively, some newer UPS * units use the WCH CH341 chip, which should have better compatibility. * Detailed information will not be repeated here, please read * "docs/man/huawei-ups2000.txt". * * A document describing the protocol implemented by this driver can * be found online at: * * https://support.huawei.com/enterprise/en/doc/EDOC1000110696 * * Huawei UPS2000 driver implemented by * Copyright (C) 2020, 2021 Yifeng Li * The author is not affiliated with Huawei or other manufacturers. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" /* must be the first header */ #include #include #include "main.h" #include "serial.h" #include "nut_stdint.h" #include "timehead.h" /* fallback gmtime_r() variants if needed (e.g. some WIN32) */ #if !(defined NUT_MODBUS_LINKTYPE_STR) # define NUT_MODBUS_LINKTYPE_STR "unknown" #endif #define DRIVER_NAME "NUT Huawei UPS2000 (1kVA-3kVA) RS-232 Modbus driver (libmodbus link type: " NUT_MODBUS_LINKTYPE_STR ")" #define DRIVER_VERSION "0.10" #define CHECK_BIT(var,pos) ((var) & (1<<(pos))) #define MODBUS_SLAVE_ID 1 /* * Known UPS models. We only attempt to load the driver if * the initial communication indicates the UPS is a known * model of the UPS2000 series. */ static const char *supported_model[] = { "UPS2000", "UPS2000A", "UPS2000G", NULL }; /* * UPS2000 device identification. The information is obtained during * initial communication using Modbus command 0x2B (read device identi- * fication) to read the object 0x87 (device list). The object contains * a list of fields, each with a type, length, and value. The object is * parsed by ups2000_device_identification() and filled into the array * of struct ups2000_ident. * * Fields of interest are: * * 0x87, int32 (Device Count): Only one UPS unit is supported, * the driver aborts if more than one device is detected. * * 0x88, string (Device Description of the 1st unit): This is a * ASCII string that contains information about the 1st UPS unit. * This string, again, contains a list of fields. They are parsed * further into the array ups2000_desc. * */ #define UPS2000_IDENT_MAX_FIELDS 9 #define UPS2000_IDENT_MAX_LEN 128 #define UPS2000_IDENT_OFFSET static struct { uint8_t type; uint8_t len; uint8_t val[UPS2000_IDENT_MAX_LEN]; } ups2000_ident[UPS2000_IDENT_MAX_FIELDS]; /* * UPS2000 device description. The information is initially obtained * as field 0x88 in the UPS2000 device identification. This field is * a semicolon seperated ASCII string that contains multiple fields. * It is parsed again by ups2000_device_identification() and filled * into the ups2000_desc[] 2D array. The first dimension is used as * a key to select the wanted field (defined in the following enmu, * the second dimension is a NULL-terminated ASCII string. * * Note that ups2000_desc[0] is deliberately unused, the array begins * at one, allowing mapping from UPS2000_DESC_* to ups2000_desc[] * directly without using offsets. */ #define UPS2000_DESC_MAX_FIELDS 9 #define UPS2000_DESC_MAX_LEN 128 enum { UPS2000_DESC_MODEL = 1, UPS2000_DESC_FIRMWARE_REV, UPS2000_DESC_PROTOCOL_REV, UPS2000_DESC_ESN, UPS2000_DESC_DEVICE_ID, /* currently unused */ UPS2000_DESC_PARALLEL_ID /* currently unused */ }; static char ups2000_desc[UPS2000_DESC_MAX_FIELDS][UPS2000_DESC_MAX_LEN] = { { 0 } }; /* global variable for modbus communication */ static modbus_t *modbus_ctx = NULL; /* * How many seconds to wait before switching off/on/reboot the UPS? * * This can be set at startup time via a command-line argument, * or at runtime by writing to RW variables "ups.delay.shutdown" * and "ups.delay.start". See ups2000_delay_get/set. */ #define UPS2000_DELAY_INVALID 0xFFFF static uint16_t ups2000_offdelay = UPS2000_DELAY_INVALID; static uint16_t ups2000_ondelay = UPS2000_DELAY_INVALID; static uint16_t ups2000_rebootdelay = UPS2000_DELAY_INVALID; /* * Time when the current shutdown/reboot request is expected * to complete. This is used to calculate the ETA, See * ups2000_update_timers(). */ static time_t shutdown_at = 0; static time_t reboot_at = 0; static time_t start_at = 0; /* * Is it safe to enter bypass mode? It's checked by ups2000_update_alarm() * and used by ups2000_instcmd_bypass_start(). */ static bool bypass_available = 0; /* function prototypes */ static int ups2000_update_info(void); static int ups2000_update_status(void); static int ups2000_update_alarm(void); static int ups2000_update_timers(void); static void ups2000_device_identification(void); static size_t ups2000_read_serial(uint8_t *buf, size_t buf_len); static int ups2000_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest); static int ups2000_write_register(modbus_t *ctx, int addr, uint16_t val); static int ups2000_write_registers(modbus_t *ctx, int addr, int nb, uint16_t *src); static uint16_t crc16(uint8_t *buffer, size_t buffer_length); static time_t time_seek(time_t t, int seconds); /* rw variables function prototypes */ static int ups2000_update_rw_var(void); static int setvar(const char *name, const char *val); static int ups2000_autostart_set(const uint16_t reg, const char *string); static int ups2000_autostart_get(const uint16_t reg); static int ups2000_beeper_set(const uint16_t reg, const char *string); static int ups2000_beeper_get(const uint16_t reg); static void ups2000_delay_get(void); static int ups2000_delay_set(const char *var, const char *string); /* instant command function prototypes */ static void ups2000_init_instcmd(void); static int instcmd(const char *cmd, const char *extra); static int ups2000_instcmd_load_on(const uint16_t reg); static int ups2000_instcmd_bypass_start(const uint16_t reg); static int ups2000_instcmd_beeper_toggle(const uint16_t reg); static int ups2000_instcmd_shutdown_stayoff(const uint16_t reg); static int ups2000_instcmd_shutdown_return(const uint16_t reg); static int ups2000_instcmd_shutdown_reboot(const uint16_t reg); static int ups2000_instcmd_shutdown_reboot_graceful(const uint16_t reg); /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Yifeng Li \n", DRV_EXPERIMENTAL, { NULL } }; void upsdrv_initups(void) { int r; upsdebugx(2, "upsdrv_initups"); /* * This is an ugly workaround to a serious problem: libmodbus doesn't * support device identification. Although there's a function called * modbus_send_raw_request() for custom commands, but modbus_receive_ * confirmation() assumes a message length in the header, which is * incompatible with device identification - It simply stops reading * in the middle of the message and cannot receive our message. Worse, * there's no public API to receive a raw response. * * See: https://github.com/stephane/libmodbus/issues/231 * * Thus, the only thing we could do is opening it as a serial device * for device identification, and reopen it via libmodbus for other * commands as usual. We also have to copy the CRC-16 function from * the libmodbus source code since there's no public API to use that... */ upsfd = ser_open(device_path); ser_set_speed(upsfd, device_path, B9600); ser_set_rts(upsfd, 0); ser_set_dtr(upsfd, 0); modbus_ctx = modbus_new_rtu(device_path, 9600, 'N', 8, 1); if (modbus_ctx == NULL) fatalx(EXIT_FAILURE, "Unable to create the libmodbus context"); #if LIBMODBUS_VERSION_CHECK(3, 1, 2) /* * Although it rarely occurs, it can take as slow as 2 sec. for the * UPS to respond a read and finish transmitting the message. */ modbus_set_response_timeout(modbus_ctx, 2, 0); #else { struct timeval timeout; timeout.tv_sec = 2; timeout.tv_usec = 0; modbus_set_response_timeout(modbus_ctx, &timeout); } #endif r = modbus_set_slave(modbus_ctx, MODBUS_SLAVE_ID); if (r < 0) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "Invalid slave ID %d", MODBUS_SLAVE_ID); } if (modbus_connect(modbus_ctx) == -1) { modbus_free(modbus_ctx); fatalx(EXIT_FAILURE, "modbus_connect: unable to connect: %s", modbus_strerror(errno)); } } #define IDENT_REQUEST_LEN 7 #define IDENT_RESPONSE_MAX_LEN 128 #define IDENT_RESPONSE_HEADER_LEN 8 #define IDENT_RESPONSE_CRC_LEN 2 #define IDENT_FIELD_HEADER_LEN 2 static void ups2000_device_identification(void) { static const uint8_t ident_req[IDENT_REQUEST_LEN] = { MODBUS_SLAVE_ID, /* addr */ 0x2B, /* command: device identification */ 0x0E, /* MEI type */ 0x03, /* ReadDevID: extended identification */ 0x87, /* Object ID: device list */ 0x31, 0x75 /* CRC-16 */ }; /* * Response header: * 0x01, 0x2B, 0x0E, 0x03, 0x03, 0x00, 0x00, 0x02 * * Response fields: * header: 0x87, 0x04 // type (device counts), length * data: uint32_t * (e.g. 0x00, 0x00, 0x00, 0x01) * * header: 0x88, 0x?? // type (1st dev desc), length * data: ASCII string * (e.g. 1=UPS2000;2=V100R001C01SPC120;3=...) * * header: 0x89, 0x?? // type (2nd dev desc), length * data: ASCII string * * ... * header: 0xFF, 0x?? // type (120th dev desc), length * data: ASCII string * * CRC-16: * 0x??, 0x?? */ static const uint8_t expected_header[IDENT_RESPONSE_HEADER_LEN] = { MODBUS_SLAVE_ID, 0x2B, 0x0E, 0x03, 0x03, 0x00, 0x00, 0x02, }; bool serial_fail = 0; /* unable to read from serial */ uint16_t crc16_recv, crc16_calc; /* resp CRC */ bool crc16_fail = 0; /* resp CRC failure */ uint32_t ups_count = 0; /* number of UPS in the resp list */ uint8_t ident_response[IDENT_RESPONSE_MAX_LEN]; /* resp buf */ size_t ident_response_len; /* buf len */ uint8_t *ident_response_end = NULL; /* buf end marker (excluding CRC) */ uint8_t *ptr = NULL; /* buf iteratior */ /* a desc string copied from ups2000_ident[] */ char *ups2000_ident_desc = NULL; int i; ssize_t r; /* attempt to obtain a response header with valid CRC. */ for (i = 0; i < 3; i++) { /* step 1: record response length and initialize ptr */ upsdebugx(2, "ser_send_buf"); ser_flush_in(upsfd, "", nut_debug_level); r = ser_send_buf(upsfd, ident_req, IDENT_REQUEST_LEN); if (r != IDENT_REQUEST_LEN) { fatalx(EXIT_FAILURE, "unable to send request!"); } ident_response_len = ups2000_read_serial(ident_response, IDENT_RESPONSE_MAX_LEN); ptr = ident_response; ident_response_end = ptr + ident_response_len - IDENT_RESPONSE_CRC_LEN; /* step 2: check response length */ if (ident_response_len == 0) { upslogx(LOG_ERR, "unable to read from serial port %s, retry...", device_path); serial_fail = 1; continue; } else serial_fail = 0; upsdebug_hex(2, "ups2000_read_serial() received", ptr, ident_response_len); if (ptr + IDENT_RESPONSE_HEADER_LEN > ident_response_end) { fatalx(EXIT_FAILURE, "response header too short! " "expected %d, received %" PRIuSIZE ".", IDENT_RESPONSE_HEADER_LEN, ident_response_len); } /* step 3: check response CRC-16 */ crc16_recv = (uint16_t) ident_response_end[0] << 8 | ident_response_end[1]; crc16_calc = crc16(ident_response, ident_response_len - IDENT_RESPONSE_CRC_LEN); if (crc16_recv == crc16_calc) { crc16_fail = 0; break; } crc16_fail = 1; } /* step 4: check serial & CRC-16 verification status */ if (serial_fail) fatalx(EXIT_FAILURE, "unable to read from serial port %s!", device_path); if (crc16_fail) fatalx(EXIT_FAILURE, "response CRC verification failed!"); /* step 5: check response header */ if (memcmp(expected_header, ident_response, IDENT_RESPONSE_HEADER_LEN)) fatalx(EXIT_FAILURE, "unexpected response header!"); ptr += IDENT_RESPONSE_HEADER_LEN; /* step 6: extract ident fields */ memset(ups2000_ident, 0x00, sizeof(ups2000_ident)); for (i = 0; i < UPS2000_IDENT_MAX_FIELDS; i++) { uint8_t type, len; if (ptr + 2 > ident_response_end) break; type = *ptr++; len = *ptr++; if (len + 1 > UPS2000_IDENT_MAX_LEN) fatalx(EXIT_FAILURE, "response field too long!"); ups2000_ident[i].type = type; ups2000_ident[i].len = len; /* * Always zero-terminate the bytes, in case the data * is an ASCII string (i.e. device desc string), libc * string functions can be used. */ ups2000_ident[i].val[len] = '\0'; if (ptr + len > ident_response_end) fatalx(EXIT_FAILURE, "response field too short!"); memcpy(ups2000_ident[i].val, ptr, len); ptr += len; } /* step 7: validate device identification field 0x87 and 0x88 */ for (i = 0; i < UPS2000_IDENT_MAX_FIELDS; i++) { /* only one device is supported */ if (ups2000_ident[i].type == 0x87) { /* so we assume 0x87 must be 1 */ ups_count = (uint32_t)(ups2000_ident[i].val[0]) << 24 | (uint32_t)(ups2000_ident[i].val[1]) << 16 | (uint32_t)(ups2000_ident[i].val[2]) << 8 | (uint32_t)(ups2000_ident[i].val[3]); } if (ups2000_ident[i].type == 0x88) { /* * And only check 0x88, not 0x89, etc. Also copy the * string for later parsing via strtok(). */ ups2000_ident_desc = strdup((char *) ups2000_ident[i].val); break; } } if (ups_count != 1) fatalx(EXIT_FAILURE, "only 1 UPS is supported, %u found", ups_count); if (!ups2000_ident_desc) fatalx(EXIT_FAILURE, "device desc string not found"); /* * step 8: extract fields from the desc string. * (1=UPS2000;2=V100R001C01SPC120;3=...) */ for (i = 0; i < UPS2000_DESC_MAX_FIELDS; i++) { char *key; /* "1", "2", "3", ... */ char *val; /* "UPS2000", "V100R001C01SPC120", ... */ unsigned int idx = 0; if (i == 0) key = strtok(ups2000_ident_desc, "="); else key = strtok(NULL, "="); if (!key) break; val = strtok(NULL, ";"); if (!val) break; r = str_to_uint_strict(key, &idx, 10); if (!r || idx + 1 > UPS2000_DESC_MAX_FIELDS || idx < 1) fatalx(EXIT_FAILURE, "desc index %u is invalid!", idx); if (strlen(val) + 1 > UPS2000_DESC_MAX_LEN) fatalx(EXIT_FAILURE, "desc field %u too long!", idx); memcpy(ups2000_desc[idx], val, strlen(val) + 1); } free(ups2000_ident_desc); /* * step 9: Validate desc fields that we are going to use are valid. * * Note: UPS2000_DESC_DEVICE_ID and UPS2000_DESC_PARALLEL_ID are * currently unused and unchecked. */ for (i = UPS2000_DESC_MODEL; i <= UPS2000_DESC_ESN; i++) { if (strlen(ups2000_desc[i]) == 0) fatalx(EXIT_FAILURE, "desc field %d is missing!", i); } } void upsdrv_initinfo(void) { bool in_list = 0; int i = 0; upsdebugx(2, "upsdrv_initinfo"); ups2000_device_identification(); /* check whether the UPS is a known model */ for (i = 0; supported_model[i] != NULL; i++) { if (!strcmp(supported_model[i], ups2000_desc[UPS2000_DESC_MODEL]) ) { in_list = 1; } } if (!in_list) { fatalx(EXIT_FAILURE, "Unknown UPS model %s", ups2000_desc[UPS2000_DESC_MODEL]); } dstate_setinfo("device.mfr", "Huawei"); dstate_setinfo("device.type", "ups"); dstate_setinfo("device.model", "%s", ups2000_desc[UPS2000_DESC_MODEL]); dstate_setinfo("device.serial", "%s", ups2000_desc[UPS2000_DESC_ESN]); dstate_setinfo("ups.mfr", "Huawei"); dstate_setinfo("ups.model", "%s", ups2000_desc[UPS2000_DESC_MODEL]); dstate_setinfo("ups.firmware", "%s", ups2000_desc[UPS2000_DESC_FIRMWARE_REV]); dstate_setinfo("ups.firmware.aux", "%s", ups2000_desc[UPS2000_DESC_PROTOCOL_REV]); dstate_setinfo("ups.serial", "%s", ups2000_desc[UPS2000_DESC_ESN]); dstate_setinfo("ups.type", "online"); /* RW variables */ upsh.setvar = setvar; /* instant commands */ ups2000_init_instcmd(); upsh.instcmd = instcmd; } /* * All registers are uint16_t. But the data they represent can * be either an integer or a float. This information is used for * error checking (int and float have different invalid values). */ enum { REG_UINT16, REG_UINT32, /* occupies two registers */ REG_FLOAT, /* actually a misnomer, it should really be called * fixed-point number, but we follow the datasheet */ }; #define REG_UINT16_INVALID 0xFFFFU #define REG_UINT32_INVALID 0xFFFFFFFFU #define REG_FLOAT_INVALID 0x7FFFU /* * Declare UPS attribute variables, format strings, registers, * and their scaling factors in a lookup table to avoid spaghetti * code. */ static struct { const char *name; const char *fmt; const uint16_t reg; const int datatype; /* only UINT32 occupies 2 regs */ const float scaling; /* scale it down to get the original */ } ups2000_var[] = { { "input.voltage", "%03.1f", 1000, REG_FLOAT, 10.0 }, { "input.frequency", "%02.1f", 1003, REG_FLOAT, 10.0 }, { "input.bypass.voltage", "%03.1f", 1004, REG_FLOAT, 10.0 }, { "input.bypass.frequency", "%03.1f", 1007, REG_FLOAT, 10.0 }, { "output.voltage", "%03.1f", 1008, REG_FLOAT, 10.0 }, { "output.current", "%03.1f", 1011, REG_FLOAT, 10.0 }, { "output.frequency", "%03.1f", 1014, REG_FLOAT, 10.0 }, { "output.realpower", "%02.1f", 1015, REG_FLOAT, 0.01 }, /* 10 / 1 kW */ { "output.power", "%03.1f", 1018, REG_FLOAT, 0.01 }, /* 10 / 1 kVA */ { "ups.load", "%02.1f", 1021, REG_FLOAT, 10.0 }, { "ups.temperature", "%02.1f", 1027, REG_FLOAT, 10.0 }, { "battery.voltage", "%02.1f", 2000, REG_FLOAT, 10.0 }, { "battery.charge", "%02.1f", 2003, REG_UINT16, 1.0 }, { "battery.runtime", "%.0f", 2004, REG_UINT32, 1.0 }, { "battery.packs", "%.0f", 2007, REG_UINT16, 1.0 }, { "battery.capacity", "%.0f", 2033, REG_UINT16, 1.0 }, { "ups.power.nominal", "%.0f", 9009, REG_FLOAT, 0.01 }, /* 10 / 1 kVA */ { NULL, NULL, 0, 0, 0 }, }; static int ups2000_update_info(void) { uint16_t reg[3][34]; int i; int r; upsdebugx(2, "ups2000_update_info"); /* * All status registers have an offset of 10000 * ups_number. * We only support 1 UPS, thus it's always 10000. Register * 1000 becomes 11000. */ r = ups2000_read_registers(modbus_ctx, 11000, 28, reg[0]); if (r != 28) return 1; r = ups2000_read_registers(modbus_ctx, 12000, 34, reg[1]); if (r != 34) return 1; r = ups2000_read_registers(modbus_ctx, 19009, 1, ®[2][9]); if (r != 1) return 1; for (i = 0; ups2000_var[i].name != NULL; i++) { uint16_t reg_id = ups2000_var[i].reg; uint8_t page = (uint8_t)(reg_id / 1000 - 1); uint8_t idx = (uint8_t)(reg_id % 1000); uint32_t val; bool invalid = 0; if (page == 8) /* hack for the lonely register 9009 */ page = 2; if (page > 2 || idx > 33) /* also suppress compiler warn */ fatalx(EXIT_FAILURE, "register calculation overflow!"); switch (ups2000_var[i].datatype) { case REG_FLOAT: val = reg[page][idx]; if (val == REG_FLOAT_INVALID) invalid = 1; break; case REG_UINT16: val = reg[page][idx]; if (val == REG_UINT16_INVALID) invalid = 1; break; case REG_UINT32: val = (uint32_t)(reg[page][idx]) << 16; val |= (uint32_t)(reg[page][idx + 1]); if (val == REG_UINT32_INVALID) invalid = 1; break; default: fatalx(EXIT_FAILURE, "invalid data type in register table!"); } if (invalid) { upslogx(LOG_ERR, "register %04d has invalid value %04x,", reg_id, val); return 1; } dstate_setinfo_dynamic(ups2000_var[i].name, ups2000_var[i].fmt, "%f", (float) val / ups2000_var[i].scaling); } return 0; } /* * A lookup table of all the status registers and the list of * corresponding flags they represent. A register may set multiple * status flags, represented by an array of flags_t. * * There are two types of flags. If the flag is a "status flag" * for status_set(), for example, "OL" or "OB", the field * "status_name" is used. If the flag is a "data variable" for * dstate_setinfo(), the variable name and value is written in * "var_name" and "var_val" fields. * * For each flag, if it's indicated by a specific value in a * register, the "val" field is used. If a flag is indicated by * a bit, the "bit" field should be used. Fields "val" and "bit" * cannot be used at the same time, at least one must be "-1". * * Also, some important registers indicate basic system status * (e.g. whether the UPS is on line power or battery), this info * must always be available, and they are always expected to set * at least one flag. If the important register does not set any * flag, it means we've received an invalid or unknown value, * and we must report an error. The "must_set_flag" field is used * for this purpose. */ static struct { const uint16_t reg; bool must_set_flag; struct flags_t { const char *status_name; const int16_t val; const int bit; const char *var_name, *var_val; } flags[10]; } ups2000_status_reg[] = { { 1024, 1, { { "OFF", 0, -1, NULL, NULL }, { "BYPASS", 1, -1, NULL, NULL }, { "OL", 2, -1, NULL, NULL }, { "OB", 3, -1, NULL, NULL }, { "OL ECO", 5, -1, NULL, NULL }, { NULL, -1, -1, NULL, NULL }, }}, { 1043, 0, { { "CAL", -1, 2, NULL, NULL }, /* battery self-test */ { "LB", -1, 6, NULL, NULL }, { NULL, -1, -1, NULL, NULL }, }}, /* * Note: 3 = float charging, 4 = equalization charging, but * both of them are reported as "charging", not "floating". * The definition of "floating" in NUT is: "battery has * completed its charge cycle, and waiting to go to resting * mode", which is not true for UPS2000. */ { 2002, 1, { { "", 2, -1, "battery.charger.status", "resting" }, { "CHRG", 3, -1, "battery.charger.status", "charging" }, { "CHRG", 4, -1, "battery.charger.status", "charging" }, { "DISCHRG", 5, -1, "battery.charger.status", "discharging" }, { NULL, -1, -1, NULL, NULL }, }}, { 0, 0, { { NULL, -1, -1, NULL, NULL } } } }; static int ups2000_update_status(void) { int i, j; int r; upsdebugx(2, "ups2000_update_status"); for (i = 0; ups2000_status_reg[i].reg != 0; i++) { uint16_t reg, val; struct flags_t *flag; int flag_count = 0; reg = ups2000_status_reg[i].reg; r = ups2000_read_registers(modbus_ctx, reg + 10000, 1, &val); if (r != 1) return 1; if (val == REG_UINT16_INVALID) { upslogx(LOG_ERR, "register %04d has invalid value %04x,", reg, val); return 1; } flag = ups2000_status_reg[i].flags; for (j = 0; flag[j].status_name != NULL; j++) { /* * if the register is equal to the "val" we are looking * for, or if register has its n-th "bit" set... */ if ((flag[j].val != -1 && flag[j].val == val) || (flag[j].bit != -1 && CHECK_BIT(val, flag[j].bit)) ) { /* if it has a corresponding status flag */ if (strlen(flag[j].status_name) != 0) status_set(flag[j].status_name); /* or if it has a corresponding dstate variable (or both) */ if (flag[j].var_name && flag[j].var_val) dstate_setinfo(flag[j].var_name, "%s", flag[j].var_val); flag_count++; } } if (ups2000_status_reg[i].must_set_flag && flag_count == 0) { upslogx(LOG_ERR, "register %04d has invalid value %04x,", reg, val); return 1; } } return 0; } /* * A lookup table of all the alarm registers and the list of * corresponding alarms they represent. Each alarm condition is * listed by its register base address "reg" and its "bit" * position. * * Each alarm condition has an "alarm_id", "alarm_cause_id", * and "alarm_name". In addition, a few alarms conditions also * indicates conditions related to batteries that is needed to * be set via status_set(), those are listed in "status_name". * Unused "status_name" is set to NULL. * * After an alarm is reported/cleared by the UPS, the "active" * flag is changed to reflect its status. The error logging * code uses this variable to issue warnings only when needed * (i.e. only after a change, avoid issuing the same warning * repeatedly). */ #define ALARM_CLEAR_AUTO 1 #define ALARM_CLEAR_MANUAL 2 #define ALARM_CLEAR_DEPENDING 3 static struct { bool active; /* runtime: is this alarm currently active? */ const uint16_t reg; /* alarm register to check */ const int bit; /* alarm bit to check */ const int alarm_clear; /* auto or manual clear */ const int loglevel; /* warning or error */ const int alarm_id, alarm_cause_id; const char *status_name; /* corresponding NUT status word */ const char *alarm_name; /* alarm string */ const char *alarm_desc; /* brief explanation */ } ups2000_alarm[] = { { false, 40156, 3, ALARM_CLEAR_AUTO, LOG_ALERT, 30, 1, NULL, "UPS internal overtemperature", "The ambient temperature is over 50-degree C. " "Startup from standby mode is prohibited.", }, { false, 40161, 1, ALARM_CLEAR_AUTO, LOG_WARNING, 10, 1, NULL, "Abnormal bypass voltage", "Bypass input is unavailable or out-of-range. Wait for " "bypass input to recover, or change acceptable bypass " "range via front panel.", }, { false, 40161, 2, ALARM_CLEAR_AUTO, LOG_WARNING, 10, 2, NULL, "Abnormal bypass frequency", "Bypass input is unavailable or out-of-range. Wait for " "bypass input to recover, or change acceptable bypass " "range via front panel.", }, { false, 40163, 3, ALARM_CLEAR_DEPENDING, LOG_WARNING, 25, 1, NULL, "Battery overvoltage", "When the UPS is started, voltage of each battery exceeds 15 V. " "Or: current battery voltage exceeds 14.7 V.", }, { false, 40164, 1, ALARM_CLEAR_AUTO, LOG_WARNING, 29, 1, "RB", "Battery needs maintenance", "During the last battery self-check, the battery voltage " "was lower than the replacement threshold (11 V).", }, { false, 40164, 3, ALARM_CLEAR_AUTO, LOG_WARNING, 26, 1, NULL, "Battery undervoltage", NULL, }, { false, 40170, 4, ALARM_CLEAR_AUTO, LOG_ALERT, 22, 1, NULL, "Battery disconnected", "Battery is not connected, has loose connection, or faulty.", }, { false, 40173, 5, ALARM_CLEAR_AUTO, LOG_ALERT, 66, 1, "OVER", "Output overload (105%-110%)", "UPS will shut down or transfer to bypass mode in 5-10 minutes.", }, { false, 40173, 3, ALARM_CLEAR_AUTO, LOG_ALERT, 66, 2, "OVER", "Output overload (110%-130%)", "UPS will shut down or transfer to bypass mode in 30-60 seconds.", }, { false, 40174, 0, ALARM_CLEAR_DEPENDING, LOG_ALERT, 14, 1, NULL, "UPS startup timeout", "The inverter output voltage is not within +/- 2 V of the " "rated output. Or: battery is overdischarged.", }, { false, 40179, 14, ALARM_CLEAR_MANUAL, LOG_ALERT, 42, 15, NULL, "Rectifier fault (internal fault)", "Bus voltage is lower than 320 V.", }, { false, 40179, 15, ALARM_CLEAR_MANUAL, LOG_ALERT, 42, 17, NULL, "Rectifier fault (internal fault)", "Bus voltage is higher than 450 V.", }, { false, 40180, 1, ALARM_CLEAR_MANUAL, LOG_ALERT, 42, 18, NULL, "Rectifier fault (internal fault)", "Bus voltage is lower than 260 V.", }, { false, 40180, 5, ALARM_CLEAR_AUTO, LOG_ALERT, 42, 24, NULL, "EEPROM fault (internal fault)", "Faulty EEPROM. All settings are restored to " "factory default and cannot be saved.", }, { false, 40180, 6, ALARM_CLEAR_MANUAL, LOG_ALERT, 42, 27, NULL, "Inverter fault (internal fault)", "Inverter output overvoltage, undervoltage or " "undercurrent.", }, { false, 40180, 7, ALARM_CLEAR_DEPENDING, LOG_ALERT, 42, 28, NULL, "Inverter fault (internal fault)", "The inverter output voltage is lower than 100 V.", }, { false, 40180, 10, ALARM_CLEAR_MANUAL, LOG_ALERT, 42, 31, NULL, "Inverter fault (internal fault)", "The difference between the absolute value of the positive bus " "voltage and that of the negative bus voltage is 100 V.", }, { false, 40180, 11, ALARM_CLEAR_DEPENDING, LOG_ALERT, 42, 32, NULL, "UPS internal overtemperature", "The ambient temperature is over 50 degree C, " "switching to bypass mode.", }, { false, 40180, 13, ALARM_CLEAR_MANUAL, LOG_ALERT, 42, 36, NULL, "Charger fault (internal fault)", "The charger has no output. Faulty internal connections.", }, { false, 40182, 4, ALARM_CLEAR_MANUAL, LOG_ALERT, 42, 42, NULL, "Charger fault (internal fault)", "The charger has no output while the inverter is on, " "battery undervoltage. Faulty switching transistor.", }, { false, 40182, 13, ALARM_CLEAR_MANUAL, LOG_ALERT, 66, 3, "OVER", "Output overload shutdown", "UPS has shutdown or transferred to bypass mode.", }, { false, 40182, 14, ALARM_CLEAR_MANUAL, LOG_ALERT, 66, 4, "OVER", "Bypass output overload shutdown", "UPS has shutdown, bypass output was overload and exceeded " "time limit.", }, { false, 0, -1, -1, -1, -1, -1, NULL, NULL, NULL } }; /* don't spam the syslog */ static time_t alarm_logged_since = 0; #define UPS2000_LOG_INTERVAL 600 /* 10 minutes */ static int ups2000_update_alarm(void) { uint16_t val[27]; int i; int r; char alarm_buf[128]; size_t all_alarms_len = 0; int alarm_count = 0; bool alarm_logged = 0; bool alarm_rtfm = 0; time_t now = time(NULL); upsdebugx(2, "ups2000_update_alarm"); /* * All alarm registers have an offset of 1024 * ups_number. * We only support 1 UPS, it's always 1024. */ r = ups2000_read_registers(modbus_ctx, ups2000_alarm[0].reg + 1024, 27, val); if (r != 27) return 1; bypass_available = 1; /* register 40161 hack, see comments below */ for (i = 0; ups2000_alarm[i].alarm_id != -1; i++) { int idx = ups2000_alarm[i].reg - ups2000_alarm[0].reg; if (idx > 26 || idx < 0) fatalx(EXIT_FAILURE, "register calculation overflow!"); if (CHECK_BIT(val[idx], ups2000_alarm[i].bit)) { int gotlen; if (ups2000_alarm[i].reg == 40161) /* * HACK: special treatment for register 40161. If this * register indicates an alarm, we need to lock the * "bypass.on" command as a software foolproof mechanism. * It's written to the global "bypass_available" flag. */ bypass_available = 0; alarm_count++; gotlen = snprintf(alarm_buf, 128, "(ID %02d/%02d): %s!", ups2000_alarm[i].alarm_id, ups2000_alarm[i].alarm_cause_id, ups2000_alarm[i].alarm_name); if (gotlen < 0 || (uintmax_t)gotlen > SIZE_MAX) { fatalx(EXIT_FAILURE, "alarm_buf preparation over/under-flow!"); } all_alarms_len += (size_t)gotlen; alarm_set(alarm_buf); if (ups2000_alarm[i].status_name) status_set(ups2000_alarm[i].status_name); /* * Log the warning only if it's a new alarm, or if a long time * has paseed since we first warned it. */ if (!ups2000_alarm[i].active || difftime(now, alarm_logged_since) >= UPS2000_LOG_INTERVAL ) { int loglevel; const char *alarm_word; /* * Most text editors have syntax highlighting, adding an * alarm word makes the log more readable */ loglevel = ups2000_alarm[i].loglevel; if (loglevel <= LOG_ERR) { alarm_word = "ERROR"; /* * If at least one error is serious, suggest reading * manual. */ alarm_rtfm = 1; } else { alarm_word = "WARNING"; } upslogx(loglevel, "%s: alarm %02d, Cause %02d: %s!", alarm_word, ups2000_alarm[i].alarm_id, ups2000_alarm[i].alarm_cause_id, ups2000_alarm[i].alarm_name); if (ups2000_alarm[i].alarm_desc) upslogx(loglevel, "%s", ups2000_alarm[i].alarm_desc); switch (ups2000_alarm[i].alarm_clear) { case ALARM_CLEAR_AUTO: upslogx(loglevel, "This alarm can be auto cleared."); break; case ALARM_CLEAR_MANUAL: upslogx(loglevel, "This alarm can only be manually cleared " "via front panel."); break; case ALARM_CLEAR_DEPENDING: upslogx(loglevel, "This alarm is auto or manually cleared " "depending on the specific problem."); break; default: break; } ups2000_alarm[i].active = 1; alarm_logged = 1; } } else { if (ups2000_alarm[i].active) { upslogx(LOG_WARNING, "Cleared alarm %02d, Cause %02d: %s", ups2000_alarm[i].alarm_id, ups2000_alarm[i].alarm_cause_id, ups2000_alarm[i].alarm_name); ups2000_alarm[i].active = 0; alarm_logged = 1; } } } if (alarm_count > 0) { /* append this to the alarm string as a friendly reminder */ int gotlen = snprintf(alarm_buf, 128, "Check log for details!"); if (gotlen < 0 || (uintmax_t)gotlen > SIZE_MAX) { fatalx(EXIT_FAILURE, "alarm_buf preparation over/under-flow!"); } all_alarms_len += (size_t)gotlen; alarm_set(alarm_buf); /* if the alarm string is too long, replace it with this */ if (all_alarms_len + 1 > ST_MAX_VALUE_LEN) { alarm_init(); /* discard all original alarms */ snprintf(alarm_buf, 128, "UPS has %d alarms in effect, " "check log for details!", alarm_count); alarm_set(alarm_buf); } /* * If we are doing a syslog, write the final message and refresh the * do-not-spam-the-log timer "alarm_logged_since". */ if (alarm_logged) { upslogx(LOG_WARNING, "UPS has %d alarms in effect.", alarm_count); if (alarm_rtfm) upslogx(LOG_WARNING, "Read Huawei User Manual for " "troubleshooting information."); alarm_logged_since = time(NULL); } } else { upsdebugx(2, "UPS has 0 alarms in effect."); if (alarm_logged) { upslogx(LOG_WARNING, "UPS has cleared all alarms."); alarm_logged_since = time(NULL); } } return 0; } void upsdrv_updateinfo(void) { int err = 0; upsdebugx(2, "upsdrv_updateinfo"); status_init(); alarm_init(); err += ups2000_update_timers(); err += ups2000_update_alarm(); err += ups2000_update_info(); err += ups2000_update_status(); err += ups2000_update_rw_var(); if (err > 0) { upsdebugx(2, "upsdrv_updateinfo failed, data stale."); dstate_datastale(); return; } alarm_commit(); status_commit(); dstate_dataok(); upsdebugx(2, "upsdrv_updateinfo done"); } /* * A lookup table of simple RW (configurable) variable "name", and their * "getter" and "setter". A "getter" function reads the variable from * the UPS, and a "setter" overwrites it. * * This struct only handles simple variables, delays are handled in another * table. */ static struct { const char *name; const uint16_t reg; int (*const getter)(const uint16_t); int (*const setter)(const uint16_t, const char *); } ups2000_rw_var[] = { { "ups.start.auto", 1044, ups2000_autostart_get, ups2000_autostart_set }, { "ups.beeper.status", 1046, ups2000_beeper_get, ups2000_beeper_set }, { NULL, 0, NULL, NULL }, }; /* * A specialized lookup table of startup, reboot and shutdown delays, * represented by RW variables. */ static struct ups2000_delay_t { const char *name; /* RW variable name */ uint16_t *const global_var; /* its corresponding global variable */ const char *varname_cmdline; /* cmdline argument passed to us */ const uint16_t min; /* minimum value allowed (seconds) */ const uint16_t max; /* maximum value allowed (seconds) */ const uint8_t step; /* can only be set in discrete steps */ const uint16_t dfault; /* default value */ } ups2000_rw_delay[] = { /* 5940 = 99 min. */ { "ups.delay.shutdown", &ups2000_offdelay, "offdelay", 6, 5940, 6, 60 }, { "ups.delay.reboot", &ups2000_rebootdelay, "rebootdelay", 6, 5940, 6, 60 }, { "ups.delay.start", &ups2000_ondelay, "ondelay", 60, 5940, 60, 60 }, { NULL, NULL, NULL, 0, 0, 0, 0 }, }; enum { SHUTDOWN, REBOOT, START }; static int ups2000_update_rw_var(void) { int i; int r; upsdebugx(2, "ups2000_update_rw_var"); for (i = 0; ups2000_rw_var[i].name != NULL; i++) { r = ups2000_rw_var[i].getter(ups2000_rw_var[i].reg); if (r != 0) return 1; } ups2000_delay_get(); return 0; } static int setvar(const char *name, const char *val) { int i; int r; upsdebug_SET_STARTING(name, val); for (i = 0; ups2000_rw_var[i].name != NULL; i++) { if (!strcasecmp(ups2000_rw_var[i].name, name)) { r = ups2000_rw_var[i].setter(ups2000_rw_var[i].reg, val); goto found; } } for (i = 0; ups2000_rw_delay[i].name != NULL; i++) { if (!strcasecmp(ups2000_rw_delay[i].name, name)) { r = ups2000_rw_var[i].setter(ups2000_rw_var[i].reg, val); goto found; } } upslog_SET_UNKNOWN(name, val); return STAT_SET_UNKNOWN; found: if (r == STAT_SET_FAILED) upslog_SET_FAILED(name, val); else if (r == STAT_SET_INVALID) upslog_SET_INVALID(name, val); return r; } static int ups2000_autostart_get(const uint16_t reg) { /* * "ups.start.auto" is not supported because it overcomplicates * the logic. The driver changes "ups.start.auto" internally to * allow shutdown and reboot commands to do their jobs. If we make * "ups.start.auto" an user configuration, it means we must (1) * watch for UPS front panel updates and apply the user setting to * the driver, and (2) save the restart setting temporally before * restarting, track the UPS restart process, and program the value * back later. * * Not supporting it greatly simplifies the logic - upsdrv_shutdown * always put the UPS in a restartable mode, following the standard * NUT behavior. Worse is better. (To prevent user confusion, we * don't even report this variable, otherwise the user may attempt * to change it using the front panel. */ NUT_UNUSED_VARIABLE(reg); return 0; } /* * Currently for internal use only, see comments above. */ static int ups2000_autostart_set(const uint16_t reg, const char *string) { uint16_t val; int r; if (!strcasecmp(string, "yes")) val = 1; else if (!strcasecmp(string, "no")) val = 0; else return STAT_SET_INVALID; r = ups2000_write_register(modbus_ctx, reg + 10000, val); if (r != 1) return STAT_SET_FAILED; return STAT_SET_HANDLED; } static int ups2000_beeper_get(const uint16_t reg) { uint16_t val; int r; r = ups2000_read_registers(modbus_ctx, reg + 10000, 1, &val); if (r != 1) return -1; if (val != 0 && val != 1) return -1; /* * The register is "beeper disable", but we need to report whether it's * enabled, thus we invert the boolean. */ if (val == 0) dstate_setinfo("ups.beeper.status", "enabled"); else dstate_setinfo("ups.beeper.status", "disabled"); dstate_setflags("ups.beeper.status", ST_FLAG_RW); dstate_addenum("ups.beeper.status", "enabled"); dstate_addenum("ups.beeper.status", "disabled"); return 0; } static int ups2000_beeper_set(const uint16_t reg, const char *string) { uint16_t val; int r; if (!strcasecmp(string, "disabled") || !strcasecmp(string, "muted")) { /* * Temporary "muted" is not supported. Only permanent "disabled" * is. This is why we only support "beeper.disable" as an instant * command, not "beeper.muted". But when setting it as a variable, * we try to be robust here and treat both as synonyms. */ val = 1; } else if (!strcasecmp(string, "enabled")) val = 0; else return STAT_SET_INVALID; r = ups2000_write_register(modbus_ctx, reg + 10000, val); if (r != 1) return STAT_SET_FAILED; return STAT_SET_HANDLED; } /* * Note: variables "ups.delay.{shutdown,start,reboot}" are software- * only variables. We only get the user settings, validate its value * and store them as global variables. The actual hardware register * are only programmed when a shutdown/reboot is issued. */ static void ups2000_delay_get(void) { char *cmdline; int i; int r; for (i = 0; ups2000_rw_delay[i].name != NULL; i++) { struct ups2000_delay_t *delay; delay = &ups2000_rw_delay[i]; if (*delay->global_var == UPS2000_DELAY_INVALID) { cmdline = getval(delay->varname_cmdline); if (cmdline) { r = ups2000_delay_set(delay->name, cmdline); if (r != STAT_SET_HANDLED) { upslogx(LOG_ERR, "servar: %s is invalid. " "Reverting to default %s %d seconds", delay->varname_cmdline, delay->varname_cmdline, delay->dfault); *delay->global_var = delay->dfault; } } else { *delay->global_var = delay->dfault; upslogx(LOG_INFO, "setvar: use default %s %d seconds", delay->varname_cmdline, delay->dfault); } } dstate_setinfo(delay->name, "%d", *delay->global_var); dstate_setflags(delay->name, ST_FLAG_RW); dstate_addrange(delay->name, delay->min, delay->max); } } static int ups2000_delay_set(const char *var, const char *string) { struct ups2000_delay_t *delay_schema = NULL; uint16_t delay, delay_rounded; int i; int r; r = str_to_ushort_strict(string, &delay, 10); if (!r) return STAT_SET_INVALID; for (i = 0; ups2000_rw_delay[i].name != NULL; i++) { if (!strcmp(ups2000_rw_delay[i].name, var)) { delay_schema = &ups2000_rw_delay[i]; break; } } if (!delay_schema) return STAT_SET_UNKNOWN; if (delay > delay_schema->max) return STAT_SET_INVALID; if (delay < delay_schema->min) { upslogx(LOG_NOTICE, "setvar: %s [%u] is too low, " "it has been set to %u seconds", delay_schema->varname_cmdline, delay, delay_schema->min); delay = delay_schema->min; } if (delay % delay_schema->step != 0) { delay_rounded = delay + delay_schema->step - delay % delay_schema->step; upslogx(LOG_NOTICE, "setvar: %s [%u] is not a multiple of %d, " "it has been rounded up to %u seconds", delay_schema->varname_cmdline, delay, delay_schema->step, delay_rounded); delay = delay_rounded; } *delay_schema->global_var = delay; return STAT_SET_HANDLED; } /* * A lookup table of all instant commands "cmd" and their * corresponding registers "reg". For each instant command, * it's handled by... * * 1. One register write, by writing "val1" to "reg1", the * simplest case. * * 2. Two register writes, by writing "val1" to "reg1", and * writing "val2" to "reg2". One after another. * * 3. Calling "*handler_func" and passing "reg1". This is * used to handle commands that needs additional processing. * If "reg1" is not necessary or unsuitable, "-1" is used. */ #define REG_NULL -1, -1 #define FUNC_NULL NULL static struct ups2000_cmd_t { const char *cmd; const int16_t reg1, val1, reg2, val2; int (*const handler_func)(const uint16_t); } ups2000_cmd[] = { { "test.battery.start.quick", 2028, 1, REG_NULL, FUNC_NULL }, { "test.battery.start.deep", 2021, 1, REG_NULL, FUNC_NULL }, { "test.battery.stop", 2023, 1, REG_NULL, FUNC_NULL }, { "beeper.enable", 1046, 0, REG_NULL, FUNC_NULL }, { "beeper.disable", 1046, 1, REG_NULL, FUNC_NULL }, { "load.off", 1045, 0, 1030, 1, FUNC_NULL }, { "bypass.stop", 1029, 1, 1045, 0, FUNC_NULL }, { "load.on", 1029, -1, REG_NULL, ups2000_instcmd_load_on }, { "bypass.start", REG_NULL, REG_NULL, ups2000_instcmd_bypass_start }, { "beeper.toggle", 1046, -1, REG_NULL, ups2000_instcmd_beeper_toggle }, { "shutdown.stayoff", 1049, -1, REG_NULL, ups2000_instcmd_shutdown_stayoff }, { "shutdown.return", REG_NULL, REG_NULL, ups2000_instcmd_shutdown_return }, { "shutdown.reboot", REG_NULL, REG_NULL, ups2000_instcmd_shutdown_reboot }, { "shutdown.reboot.graceful", REG_NULL, REG_NULL, ups2000_instcmd_shutdown_reboot_graceful }, { NULL, -1, -1, -1, -1, NULL }, }; static void ups2000_init_instcmd(void) { int i; for (i = 0; ups2000_cmd[i].cmd != NULL; i++) { dstate_addcmd(ups2000_cmd[i].cmd); } } static int instcmd(const char *cmd, const char *extra) { int i; int status; struct ups2000_cmd_t *cmd_action = NULL; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmd, extra); for (i = 0; ups2000_cmd[i].cmd != NULL; i++) { if (!strcasecmp(cmd, ups2000_cmd[i].cmd)) { cmd_action = &ups2000_cmd[i]; } } if (!cmd_action) { upslog_INSTCMD_UNKNOWN(cmd, extra); return STAT_INSTCMD_UNKNOWN; } upslog_INSTCMD_POWERSTATE_CHECKED(cmd, extra); if (cmd_action->handler_func) { /* handled by a function */ if (cmd_action->reg1 < 0) { /* FIXME: ...INSTCMD_CONVERSION_FAILED ? */ upslogx(LOG_INSTCMD_UNKNOWN, "instcmd: command [%s] reg1 is negative", cmd); return STAT_INSTCMD_UNKNOWN; } else { status = cmd_action->handler_func((uint16_t)cmd_action->reg1); } } else if (cmd_action->reg1 >= 0 && cmd_action->val1 >= 0) { /* handled by a register write */ int r = ups2000_write_register(modbus_ctx, 10000 + cmd_action->reg1, (uint16_t)cmd_action->val1); if (r == 1) status = STAT_INSTCMD_HANDLED; else status = STAT_INSTCMD_FAILED; /* * if the previous write succeeds and there is an additional * register to write. */ if (r == 1 && cmd_action->reg2 >= 0 && cmd_action->val2 >= 0) { r = ups2000_write_register(modbus_ctx, 10000 + cmd_action->reg2, (uint16_t)cmd_action->val2); if (r == 1) status = STAT_INSTCMD_HANDLED; else status = STAT_INSTCMD_FAILED; } } else { fatalx(EXIT_FAILURE, "invalid ups2000_cmd table!"); } if (status == STAT_INSTCMD_FAILED) upslog_INSTCMD_FAILED(cmd, extra); else if (status == STAT_INSTCMD_HANDLED) upslogx(LOG_INFO, "instcmd: command [%s] handled", cmd); return status; } static int ups2000_instcmd_load_on(const uint16_t reg) { int r; const char *status; /* force refresh UPS status */ status_init(); r = ups2000_update_status(); if (r != 0) { /* * When the UPS status is updated, the code must set either OL, OB, OL ECO, * BYPASS, or OFF. These five options are mutually exclusive. If the register * value is invalid and set none of these flags, failure code 1 is returned. */ dstate_datastale(); return STAT_INSTCMD_FAILED; } status_commit(); status = dstate_getinfo("ups.status"); if (strstr(status, "OFF")) { /* no warning needed, continue at ups2000_write_register() below */ } else if (strstr(status, "OL") || strstr(status, "OB")) { /* * "Turning it on" has no effect if it's already on. Log a warning * while still accepting and executing the command. */ upslogx(LOG_WARNING, "load.on: UPS is already on."); upslogx(LOG_WARNING, "load.on: still executing command anyway."); } else if (strstr(status, "BYPASS")) { /* * If it's in bypass mode, reject this command. The UPS would otherwise * enter normal mode, but "load.on" is not supposed to affect the * normal/bypass status. Also log an error and suggest "bypass.stop". */ /* FIXME: ..._INVALID ? */ upslogx(LOG_INSTCMD_FAILED, "load.on error: UPS is already on, and is in bypass mode. " "To enter normal mode, use bypass.stop"); return STAT_INSTCMD_FAILED; } else { /* unreachable, see comments for r != 0 at the beginning */ /* FIXME: ..._INVALID ? */ upslogx(LOG_INSTCMD_FAILED, "load.on error: invalid ups.status (%s) detected. " "Please file a bug report!", status); return STAT_INSTCMD_FAILED; } r = ups2000_write_register(modbus_ctx, 10000 + reg, 1); if (r != 1) return STAT_INSTCMD_FAILED; return STAT_INSTCMD_HANDLED; } static int ups2000_instcmd_bypass_start(const uint16_t reg) { int r; NUT_UNUSED_VARIABLE(reg); /* force update alarms */ alarm_init(); r = ups2000_update_alarm(); if (r != 0) return STAT_INSTCMD_FAILED; alarm_commit(); /* bypass input has a power failure, refuse to bypass */ if (!bypass_available) { upslogx(LOG_INSTCMD_FAILED, "bypass input is abnormal, refuse to enter bypass mode."); return STAT_INSTCMD_FAILED; } /* enable "bypass on shutdown" */ r = ups2000_write_register(modbus_ctx, 10000 + 1045, 1); if (r != 1) return STAT_INSTCMD_FAILED; /* shutdown */ r = ups2000_write_register(modbus_ctx, 10000 + 1030, 1); if (r != 1) return STAT_INSTCMD_FAILED; return STAT_INSTCMD_HANDLED; } static int ups2000_instcmd_beeper_toggle(const uint16_t reg) { int r; const char *string; r = ups2000_beeper_get(reg); if (r != 0) return STAT_INSTCMD_FAILED; string = dstate_getinfo("ups.beeper.status"); if (!strcasecmp(string, "enabled")) r = ups2000_beeper_set(reg, "disabled"); else if (!strcasecmp(string, "disabled")) r = ups2000_beeper_set(reg, "enabled"); else return STAT_INSTCMD_FAILED; if (r != STAT_SET_HANDLED) return STAT_INSTCMD_FAILED; return STAT_INSTCMD_HANDLED; } /* * "ups.shutdown.stayoff": wait an optional offdelay and shutdown. * When the grid power returns, stay off. */ static int ups2000_instcmd_shutdown_stayoff(const uint16_t reg) { uint16_t val; int r; r = setvar("ups.start.auto", "no"); if (r != STAT_SET_HANDLED) return STAT_INSTCMD_FAILED; val = ups2000_offdelay * 10; /* scaling factor */ val /= 60; /* convert to minutes */ r = ups2000_write_register(modbus_ctx, 10000 + reg, val); if (r != 1) return STAT_INSTCMD_FAILED; return STAT_INSTCMD_HANDLED; } /* * Wait for "offdelay" second, turn off the load. Then, wait * for "ondelay" seconds. If the grid power still exists or * has returned after the timer, turn on the load. Otherwise, * shutdown the UPS. When combined with "ups.start.auto", it * guarantees the server can always be restarted even if there * is a power race. * * "shutdown.return", "shutdown.reboot" and "shutdown.reboot. * graceful" all rely on this function. */ static int ups2000_shutdown_guaranteed_return(uint16_t offdelay, uint16_t ondelay) { int r; uint16_t val[2]; r = setvar("ups.start.auto", "yes"); if (r != STAT_SET_HANDLED) return STAT_INSTCMD_FAILED; val[0] = (offdelay * 10) / 60; val[1] = ondelay / 60; r = ups2000_write_registers(modbus_ctx, 1047 + 10000, 2, val); if (r != 2) return STAT_INSTCMD_FAILED; return STAT_INSTCMD_HANDLED; } /* * "ups.shutdown.return": wait an optional "offdelay" and shutdown. * When the grid power returns, power on the load. */ static int ups2000_instcmd_shutdown_return(const uint16_t reg) { int r; NUT_UNUSED_VARIABLE(reg); r = ups2000_shutdown_guaranteed_return( ups2000_offdelay, ups2000_ondelay); if (r == STAT_INSTCMD_HANDLED) { shutdown_at = time_seek(time(NULL), ups2000_offdelay); } return r; } /* * "ups.shutdown.reboot": shutdown as soon as possible using the * smallest "rebootdelay" (inside the UPS, it's the same "ondelay" * timer), restart after an "ondelay". * * In our implementation, it's like "ups.shutdown.return", just * with a minimal "ondelay". */ static int ups2000_instcmd_shutdown_reboot(const uint16_t reg) { int r; NUT_UNUSED_VARIABLE(reg); r = ups2000_shutdown_guaranteed_return( ups2000_rw_delay[REBOOT].min, ups2000_ondelay); if (r == STAT_INSTCMD_HANDLED) { reboot_at = time_seek(time(NULL), ups2000_rw_delay[REBOOT].min); start_at = time_seek(reboot_at, ups2000_ondelay); } return r; } /* * "ups.shutdown.reboot.graceful": shutdown after a "rebootdelay" * (inside the UPS, it's the same "ondelay" timer), restart after * an "ondelay". * * In our implementation, it's like "ups.shutdown.return", just * with a "rebootdelay" instead of an "ondelay". */ static int ups2000_instcmd_shutdown_reboot_graceful(const uint16_t reg) { int r; NUT_UNUSED_VARIABLE(reg); r = ups2000_shutdown_guaranteed_return( ups2000_rebootdelay, ups2000_ondelay); if (r == STAT_INSTCMD_HANDLED) { reboot_at = time_seek(time(NULL), ups2000_rebootdelay); start_at = time_seek(reboot_at, ups2000_ondelay); } return r; } /* * List of countdown timers and pointers to their corresponding * global variables "at_time". They record estimated timestamps * when the actions are supposed to be performed. */ static struct { const char *name; time_t *const at_time; } ups2000_timers[] = { { "ups.timer.reboot", &reboot_at }, { "ups.timer.shutdown", &shutdown_at }, { "ups.timer.start", &start_at }, { NULL, NULL }, }; static int ups2000_update_timers(void) { time_t now; int eta; int i; now = time(NULL); for (i = 0; ups2000_timers[i].name != NULL; i++) { if (*ups2000_timers[i].at_time) { eta = difftime(*ups2000_timers[i].at_time, now); if (eta < 0) eta = 0; dstate_setinfo(ups2000_timers[i].name, "%d", eta); } else { dstate_setinfo(ups2000_timers[i].name, "%d", -1); } } return 0; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ int ret = do_loop_shutdown_commands("shutdown.reboot", NULL); if (ret != STAT_INSTCMD_HANDLED) { upslogx(LOG_ERR, "upsdrv_shutdown failed!"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { char msg[64]; snprintf(msg, 64, "Set shutdown delay, in seconds, 6-second step" " (default=%d)", ups2000_rw_delay[SHUTDOWN].dfault); addvar(VAR_VALUE, "offdelay", msg); snprintf(msg, 64, "Set reboot delay, in seconds, 6-second step" " (default=%d).", ups2000_rw_delay[REBOOT].dfault); addvar(VAR_VALUE, "rebootdelay", msg); snprintf(msg, 64, "Set start delay, in seconds, 60-second step" " (default=%d).", ups2000_rw_delay[START].dfault); addvar(VAR_VALUE, "ondelay", msg); } void upsdrv_cleanup(void) { if (modbus_ctx != NULL) { modbus_close(modbus_ctx); modbus_free(modbus_ctx); } ser_close(upsfd, device_path); } /* * Seek time "t" forward or backward by n "seconds" without assuming * the underlying type and format of "time_t". This ensures maximum * portability. Although on POSIX and many other systems, "time_t" * is guaranteed to be in seconds. * * On error, abort the program. */ static time_t time_seek(time_t t, int seconds) { struct tm time_tm; time_t time_output; if (!t) fatalx(EXIT_FAILURE, "time_seek() failed!"); if (gmtime_r(&t, &time_tm) == NULL) fatalx(EXIT_FAILURE, "time_seek() failed!"); time_tm.tm_sec += seconds; time_output = mktime(&time_tm); if (time_output == (time_t) -1) fatalx(EXIT_FAILURE, "time_seek() failed!"); return time_output; } /* * Read bytes from the UPS2000 serial port, until the buffer has * nothing left to read (after ser_get_buf() times out). The buffer * size is limited to buf_len (inclusive). * * On error, return 0. * * In the serial library, ser_get_buf() can be a short read, and * ser_get_buf_let() requires a precalculated length, necessiates * our own read function. */ static size_t ups2000_read_serial(uint8_t *buf, size_t buf_len) { ssize_t bytes = 0; size_t total = 0; /* wait 400 ms for the device to process our command */ usleep(400 * 1000); while (buf_len > 0) { bytes = ser_get_buf(upsfd, buf, buf_len, 1, 0); if (bytes < 0) return 0; /* read failure */ else if (bytes == 0) return total; /* nothing to read */ if ((size_t) bytes > buf_len) { /* * Assertion: This should never happen. bytes is always less or equal * to buf_len, and buf_len will never underflow under any circumstances. */ fatalx(EXIT_FAILURE, "ups2000_read_serial() reads too much!"); } total += (size_t)bytes; /* increment byte counter */ buf += bytes; /* advance buffer position */ buf_len -= (size_t)bytes; /* decrement limiter */ } return 0; /* buffer exhaustion */ } /* * Retry control. By default, we are in RETRY_ENABLE mode. For each * register read, we retry three times (1 sec. between each attempt), * before raising a fatal error and giving up. So far so good, but, * if the link went down, all operation would fail and the program * would become unresponsive due to excessive retrys. * * To prevent this problem, after the first fatal error, we stop all * retry attempts by entering RETRY_DISABLE_TEMPORARY mode, allowing * subsequent operation to fail without retry. Later, after the first * success is encountered, we move back to RETRY_ENABLE mode. */ enum { RETRY_ENABLE, RETRY_DISABLE_TEMPORARY }; static int retry_status = RETRY_ENABLE; /* * Read one or more registers using libmodbus. * * This is simply a wrapper for libmodbus's modbus_read_registers() with * retry and workaround logic. When an error has occured, we retry 3 times * before giving up, allowing us to recover from non-fatal failures without * triggering a data stale. */ static int ups2000_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest) { int i; int r = -1; if (addr < 10000) upslogx(LOG_ERR, "Invalid register read from %04d detected. " "Please file a bug report!", addr); for (i = 0; i < 3; i++) { /* * If the previous read failed with a timeout, often there * are still unprocessed bytes in the serial buffer and they * would be mixed with the new data, creating invalid messages, * making all subsequent reads to fail as well. * * Flush read buffer first to avoid it. */ modbus_flush(ctx); r = modbus_read_registers(ctx, addr, nb, dest); /* generic retry for modbus read failures. */ if (retry_status == RETRY_ENABLE && r != nb) { upslogx(LOG_WARNING, "modbus_read_registers() failed (%d, errno %d): %s", r, errno, modbus_strerror(errno)); upslogx(LOG_WARNING, "Register %04d has a read failure. Retrying...", addr); sleep(1); continue; } else if (r == nb) retry_status = RETRY_ENABLE; /* * Workaround for buggy register 2002 (battery status). Sometimes * this register returns invalid values. This is a known problem * and it's not fatal, so we use LOG_INFO. */ if (retry_status == RETRY_ENABLE && addr == 12002 && (dest[0] < 2 || dest[0] > 5) ) { upslogx(LOG_INFO, "Battery status has a non-fatal read failure, it's usually harmless. Retrying... "); sleep(1); continue; } else if (addr == 12002 && dest[0] >= 2 && dest[0] <= 5) retry_status = RETRY_ENABLE; return r; } /* Give up */ upslogx(LOG_ERR, "modbus_read_registers() failed (%d, errno %d): %s", r, errno, modbus_strerror(errno)); upslogx(LOG_ERR, "Register %04d has a fatal read failure.", addr); retry_status = RETRY_DISABLE_TEMPORARY; return r; } static int ups2000_write_registers(modbus_t *ctx, int addr, int nb, uint16_t *src) { int i; int r = -1; if (addr < 10000) upslogx(LOG_ERR, "Invalid register write to %04d detected. " "Please file a bug report!", addr); for (i = 0; i < 3; i++) { r = modbus_write_registers(ctx, addr, nb, src); /* generic retry for modbus write failures. */ if (retry_status == RETRY_ENABLE && r != nb) { upslogx(LOG_WARNING, "modbus_write_registers() failed (%d, errno %d): %s", r, errno, modbus_strerror(errno)); upslogx(LOG_WARNING, "Register %04d has a write failure. Retrying...", addr); sleep(1); continue; } else if (r == nb) retry_status = RETRY_ENABLE; return r; } /* Give up */ upslogx(LOG_ERR, "modbus_write_registers() failed (%d, errno %d): %s", r, errno, modbus_strerror(errno)); upslogx(LOG_ERR, "Register %04d has a fatal write failure.", addr); retry_status = RETRY_DISABLE_TEMPORARY; return r; } static int ups2000_write_register(modbus_t *ctx, int addr, uint16_t val) { return ups2000_write_registers(ctx, addr, 1, &val); } /* * The following CRC-16 code was copied from libmodbus. * * Copyright (C) 2001-2011 Stéphane Raimbault * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ /* Table of CRC values for high-order byte */ static const uint8_t table_crc_hi[] = { 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 }; /* Table of CRC values for low-order byte */ static const uint8_t table_crc_lo[] = { 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 }; static uint16_t crc16(uint8_t * buffer, size_t buffer_length) { uint8_t crc_hi = 0xFF; /* high CRC byte initialized */ uint8_t crc_lo = 0xFF; /* low CRC byte initialized */ unsigned int i; /* will index into CRC lookup */ /* pass through message buffer */ while (buffer_length--) { i = crc_hi ^ *buffer++; /* calculate the CRC */ crc_hi = crc_lo ^ table_crc_hi[i]; crc_lo = table_crc_lo[i]; } return (uint16_t) crc_hi << 8 | crc_lo; } nut-2.8.4/drivers/belkin.h0000644000175000017500000000371715000736161012356 00000000000000/* belkin.h - serial commands for Belkin smart protocol units Copyright (C) 2000 Marcus Müller This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef WIN32 #include #endif /* !WIN32 */ #include "serial.h" #include "timehead.h" #define STATUS 'P' #define CONTROL 'S' #define MANUFACTURER "MNU" #define MODEL "MOD" #define VERSION_CMD "VER" #define RATING "RAT" #define STAT_INPUT "STI" #define STAT_OUTPUT "STO" #define STAT_BATTERY "STB" #define STAT_STATUS "STA" #define TEST_RESULT "TSR" #define POWER_ON "RON" #define POWER_OFF "ROF" #define POWER_SDTYPE "SDT" /* shutdown type? */ #define POWER_CYCLE "SDA" /* shutdown, then restore */ #define BUZZER "BUZ" #define BUZZER_ON "1" #define BUZZER_OFF0 "0" /* Switching the buzzer off can be either 0 or 2 */ #define BUZZER_OFF2 "2" /* Seems to be used for F6c1400 */ #define TEST "TST" #define TEST_10SEC "3" #define TEST_DEEP "4" #define TEST_CANCEL "0" /* The UPS Status "low battery" comes up 10s before the UPS actually stops. Therefore a shutdown is done at this battery % */ #define LOW_BAT 20 /* the maximum allowed number of missed replies */ #define MAXTRIES 3 /* dangerous instant commands must be reconfirmed within a 12 second window */ #define CONFIRM_DANGEROUS_COMMANDS 1 #define MINCMDTIME 3 #define MAXCMDTIME 15 nut-2.8.4/drivers/microdowell.c0000644000175000017500000010521215044656702013430 00000000000000/* * * microdowell.c: support for Microdowell Enterprise Nxx/Bxx serial protocol based UPSes * * Copyright (C) Elio Corbolante * * microdowell.c created on 27/09/2007 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* anything commented is optional anything else is mandatory */ #include "main.h" #include "serial.h" #ifndef WIN32 #include #endif #include "timehead.h" #include "nut_stdint.h" #define ENTERPRISE_PROTOCOL #include "microdowell.h" #define MAX_START_DELAY 999999 #define MAX_SHUTDOWN_DELAY 32767 /* Maximum length of a string representing these values */ #define MAX_START_DELAY_LEN 6 #define MAX_SHUTDOWN_DELAY_LEN 5 #define DRIVER_NAME "MICRODOWELL UPS driver" #define DRIVER_VERSION "0.06" /* driver description structure */ upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Elio Corbolante ", DRV_STABLE, { NULL } }; static ENT_STRUCT ups ; /* common driver routines */ int instcmd(const char *cmdname, const char *extra); int setvar(const char *varname, const char *val); /* he knew... macros should evaluate their arguments only once */ #define CLAMP(x, min, max) (((x) < (min)) ? (min) : (((x) > (max)) ? (max) : (x))) static int CheckDataChecksum(unsigned char *Buff, size_t Len) { size_t i, Idx ; unsigned char Xor ; ups.FramePointer = Xor = 0 ; for (Idx=0 ; Idx < Len ; Idx++) if (Buff[Idx] == STX_CHAR) break ; ups.FramePointer = Idx ; /* Memorise start point. */ /* Check that the message is not to short... */ if ( (Idx > (Len-4)) || (Idx+Buff[Idx+1]+2 > Len) ) return(ERR_MSG_TOO_SHORT) ; /* Too short a message! */ /* Calculate checksum */ for (i=Idx+1 ; i < Idx+Buff[Idx+1]+2 ; i++) Xor ^= Buff[i] ; /* if Xor != then checksum error */ if (Xor != Buff[i]) return(ERR_MSG_CHECKSUM) ; /* error in checksum */ /* If checksum OK: return */ return(0) ; } static const char *ErrMessages[] = { /* 0 */ "errorcode NOT DEFINED", /* default error message */ /* 1 */ "I2C bus busy (e2prom)", /* 2 */ "Command received: checksum not valid", /* 3 */ "Command received: unrecognized command", /* 4 */ "WRITE: eeprom address not multiple of 8", /* 5 */ "READ: eeprom address (added with size) out of bound ", /* 6 */ "error writing e2prom address", /* 7 */ "error writing e2prom subaddress", /* 8 */ "error reading e2prom data", /* 9 */ "error writing e2prom address", /* 10 */ "error reading e2prom subaddress", /* 11 */ "error writing e2prom data", /* 12 */ "error writing e2prom address during data verification", /* 13 */ "error verification e2prom data", /* 14 */ "e2prom data are different from those in the write buffer", /* 15 */ "e2prom checksum error", /* 16 */ "NO CHARS FROM PORT", /* 17 */ "TOO FEW DATA RECEIVED: [STX] near end of message", /* 18 */ "CHECKSUM ERROR IN MESSAGE", /* 19 */ "OK", /* */ "" } ; static const char *PrintErr(int ErrCode) { int msgIndex = 0 ; /* The default 'msgIndex' is 0 (error code not defined) */ switch (ErrCode) { case ERR_NO_ERROR : msgIndex = 19 ; break ; case ERR_I2C_BUSY : msgIndex = 1 ; break ; case ERR_CMD_CHECKSUM : msgIndex = 2 ; break ; case ERR_CMD_UNRECOG : msgIndex = 3 ; break ; case ERR_EEP_NOBLOCK : msgIndex = 4 ; break ; case ERR_EEP_OOBOUND : msgIndex = 5 ; break ; case ERR_EEP_WADDR1 : msgIndex = 6 ; break ; case ERR_EEP_WSADDR1 : msgIndex = 7 ; break ; case ERR_EEP_RDATA : msgIndex = 8 ; break ; case ERR_EEP_WADDR2 : msgIndex = 9 ; break ; case ERR_EEP_WSADDR2 : msgIndex = 10 ; break ; case ERR_EEP_WDATA : msgIndex = 11 ; break ; case ERR_EEP_WADDRVER : msgIndex = 12 ; break ; case ERR_EEP_WDATAVER : msgIndex = 13 ; break ; case ERR_EEP_VERIFY : msgIndex = 14 ; break ; case ERR_EEP_CHECKSUM : msgIndex = 15 ; break ; case ERR_COM_NO_CHARS : msgIndex = 16 ; break ; case ERR_MSG_TOO_SHORT : msgIndex = 17 ; break ; case ERR_MSG_CHECKSUM : msgIndex = 18 ; break ; default : msgIndex = 0 ; break ; } return(ErrMessages[msgIndex]) ; } static int CheckErrCode(unsigned char * Buff) { auto int Ret ; switch (Buff[2]) { /* I have found an error */ case CMD_NACK : Ret = Buff[3] ; break ; case CMD_ACK : case CMD_GET_STATUS : case CMD_GET_MEASURES : case CMD_GET_CONFIG : case CMD_GET_BATT_STAT : case CMD_GET_MASK : case CMD_SET_TIMER : case CMD_BATT_TEST : case CMD_GET_BATT_TEST : case CMD_SD_ONESHOT : case CMD_GET_SD_ONESHOT: case CMD_SET_SCHEDULE : case CMD_GET_SCHEDULE : case CMD_GET_EEP_BLOCK : case CMD_SET_EEP_BLOCK : case CMD_GET_EEP_SEED : case CMD_INIT : Ret = 0 ; break ; /* command not recognized */ default: Ret = ERR_CMD_UNRECOG ; break ; } return(Ret) ; } static void SendCmdToSerial(unsigned char *Buff, size_t Len) { int i; unsigned char Tmp[20], Xor ; Tmp[0] = STX_CHAR ; Xor = Tmp[1] = (unsigned char) (Len & 0x1f) ; for (i=0 ; i < Tmp[1] ; i++) { Tmp[i+2] = Buff[i] ; Xor ^= Buff[i] ; } Tmp[Len+2] = Xor ; upsdebug_hex(4, "->UPS", Tmp, Len+3) ; /* flush serial port */ ser_flush_in(upsfd, "", 0) ; /* empty input buffer */ ser_send_buf(upsfd, Tmp, Len+3) ; /* send data to the UPS */ } static unsigned char * CmdSerial(unsigned char *OutBuffer, size_t Len, unsigned char *RetBuffer) { # define TMP_BUFF_LEN 1024 unsigned char InpBuff[TMP_BUFF_LEN+1] ; unsigned char TmpBuff[3] ; int i, ErrCode ; unsigned char *p ; size_t BuffLen ; /* The default error code (no received character) */ ErrCode = ERR_COM_NO_CHARS ; SendCmdToSerial(OutBuffer, Len) ; usleep(10000) ; /* small delay (1/100 s) */ /* get chars until timeout */ BuffLen = 0 ; while (ser_get_char(upsfd, TmpBuff, 0, 10000) == 1) { InpBuff[BuffLen++] = TmpBuff[0] ; if (BuffLen > TMP_BUFF_LEN) break ; } upsdebug_hex(4, "UPS->", InpBuff, BuffLen) ; if (BuffLen > 0) { ErrCode = CheckDataChecksum(InpBuff, BuffLen) ; /* upsdebugx(4, "ErrCode = %d / Len = %d", ErrCode, BuffLen); */ if (!ErrCode) { /* FramePointer to valid data! */ p = InpBuff + ups.FramePointer ; /* p now point to valid data. check if it is a error code. */ ErrCode = CheckErrCode(p) ; if (!ErrCode) { /* I copy the data read in the buffer */ for(i=0 ; i<(int) (p[1])+3 ; i++) RetBuffer[i] = p[i] ; ups.ErrCode = ups.ErrCount = ups.CommStatus = 0 ; return(RetBuffer) ; } } } /* if they have arrived here, wants to say that I have found an error.... */ ups.ErrCode = ErrCode ; ups.ErrCount++ ; if (ups.ErrCount > 3) { ups.CommStatus &= 0x80 ; ups.CommStatus |= (unsigned char) (ups.ErrCount & 0x7F) ; if (ups.ErrCount > 100) ups.ErrCount = 100 ; } return(NULL) ; /* There have been errors in the reading of the data */ } static int detect_hardware(void) { unsigned char OutBuff[20] ; unsigned char InpBuff[260] ; unsigned char *p ; int i, retries ; struct tm *Time ; struct tm tmbuf; time_t lTime ; ups.ge_2kVA = 0 ; for (retries=0 ; retries <= 4 ; retries++) { /* Identify UPS model */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_UPS_MODEL ; /* UPS model */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got UPS model */ for (i=0 ; i<8 ; i++) ups.UpsModel[i] = (char)p[i+5] ; ups.UpsModel[8] = '\0' ; upsdebugx(2, "get 'UPS model': %s", PrintErr(ups.ErrCode)); break ; /* UPS identified: exit from ' for' LOOP */ } else { upsdebugx(1, "[%d] get 'UPS model': %s", retries, PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "[%d] Unable to identify UPS model [%s]", retries, PrintErr(ups.ErrCode)); usleep(100000) ; /* small delay (1/10 s) for next retry */ } } /* check if I was unable to find the UPS */ if (retries == 4) /* UPS not found! */ return -1; /* UPS serial number */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_SERIAL_NUM ; /* UPS serial # */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got UPS serial # */ for (i=0 ; i<8 ; i++) ups.SerialNumber[i] = (char)p[i+5] ; ups.SerialNumber[8] = '\0' ; upsdebugx(2, "get 'UPS Serial #': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'UPS Serial #': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to identify UPS serial # [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get Production date & FW info */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_PROD_DATE ; /* Production date + HW version */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got Production date & FW info */ p += 5 ; /* 'p' points to eeprom data */ ups.YearOfProd = 2000 + p[0] ; /* Production year of the UPS */ ups.MonthOfProd = p[1] ; /* Production month of the UPS */ ups.DayOfProd = p[2] ; /* Production day of the UPS */ ups.HW_MajorVersion = (p[3]>>4) & 0x0F ; /* Hardware: Major version */ ups.HW_MinorVersion = (p[3] & 0x0F) ; /* Hardware: Minor version */ ups.BR_MajorVersion = (p[4]>>4) & 0x0F ; /* BoardHardware: Major version */ ups.BR_MinorVersion = (p[4] & 0x0F) ; /* BoardHardware: Minor version */ ups.FW_MajorVersion = (p[5]>>4) & 0x0F ; /* Firmware: Major version */ ups.FW_MinorVersion = (p[5] & 0x0F) ; /* Firmware: Minor version */ ups.FW_SubVersion = p[6] ; /* Firmware: SUBVERSION (special releases */ ups.BatteryNumber = p[7] ; /* number of batteries in UPS */ upsdebugx(2, "get 'Production date': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Production date': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read Production date [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get Battery substitution date */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_BATT_SUBST ; /* Battery substitution dates */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got Battery substitution date */ p += 5 ; /* 'p' points to eeprom data */ upsdebugx(2, "get 'Battery Subst. Dates': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Battery Subst. Dates': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read Battery Subst. Dates [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get working time (battery+normal)) */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_MIN_VBATT ; /* working time */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got working time (battery+normal)) */ p += 5 ; /* 'p' points to eeprom data */ upsdebugx(2, "get 'UPS life info': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'UPS life info': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read UPS life info [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get the THRESHOLD table (0) */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_THRESHOLD_0 ; /* Thresholds table 0 */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got the THRESHOLD table (0) */ p += 5 ; /* 'p' points to eeprom data */ upsdebugx(2, "get 'Thresholds table 0': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Thresholds table 0': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read Thresholds table 0 [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get the THRESHOLD table (1) */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_THRESHOLD_1 ; /* Thresholds table 0 */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got the THRESHOLD table (1) */ p += 5 ; /* 'p' points to eeprom data */ upsdebugx(2, "get 'Thresholds table 1': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Thresholds table 1': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read Thresholds table 1 [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get the THRESHOLD table (2) */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_THRESHOLD_2 ; /* Thresholds table 0 */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got the THRESHOLD table (2) */ p += 5 ; /* 'p' points to eeprom data */ upsdebugx(2, "get 'Thresholds table 2': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Thresholds table 2': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read Thresholds table 2 [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get Option Bytes */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_OPT_BYTE_BLK ; /* Option Bytes */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got Option Bytes */ p += 5 ; /* 'p' points to eeprom data */ dstate_setinfo("input.voltage.nominal", "%s", (p[EEP_OPT_BYTE_1] & 0x02) ? "110": "230") ; dstate_setinfo("input.frequency", "%s", (p[EEP_OPT_BYTE_1] & 0x01) ? "60.0": "50.0") ; upsdebugx(2, "get 'Option Bytes': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Option Bytes': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read Option Bytes [%s]", PrintErr(ups.ErrCode)); return -1; } /* Get UPS sensitivity (fault points) */ OutBuff[0] = CMD_GET_EEP_BLOCK ; /* get EEPROM data */ OutBuff[1] = EEP_FAULT_POINTS ; /* Number of fault points (sensitivity)) */ OutBuff[2] = 8 ; /* number of bytes */ if ((p = CmdSerial(OutBuff, LEN_GET_EEP_BLOCK, InpBuff)) != NULL) { /* got UPS sensitivity (fault points) */ p += 5 ; /* 'p' points to eeprom data */ switch (p[0]) { case 1 : dstate_setinfo("input.sensitivity", "H") ; break ; case 2 : dstate_setinfo("input.sensitivity", "M") ; break ; case 3 : dstate_setinfo("input.sensitivity", "L") ; break ; default : dstate_setinfo("input.sensitivity", "L") ; break ; } upsdebugx(2, "get 'Input Sensitivity': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Input Sensitivity': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to read Input Sensitivity [%s]", PrintErr(ups.ErrCode)); return -1; } /* Set internal UPS clock */ time(&lTime) ; Time = localtime_r(&lTime, &tmbuf); OutBuff[0] = CMD_SET_TIMER ; /* set UPS internal timer */ OutBuff[1] = (Time->tm_wday+6) % 7 ; /* week day (0=monday) */ OutBuff[2] = (unsigned char)Time->tm_hour ; /* hours */ OutBuff[3] = (unsigned char)Time->tm_min ; /* minutes */ OutBuff[4] = (unsigned char)Time->tm_sec ; /* seconds */ if ((p = CmdSerial(OutBuff, LEN_SET_TIMER, InpBuff)) != NULL) { upsdebugx(2, "set 'UPS internal clock': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "set 'UPS internal clock': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Unable to set UPS internal clock [%s]", PrintErr(ups.ErrCode)); return -1; } return 0; /* everything was OK */ } /* ========================= */ void upsdrv_updateinfo(void) { unsigned char OutBuff[20] ; unsigned char InpBuff[260] ; unsigned char *p ; /* int i ; */ OutBuff[0] = CMD_GET_STATUS ; /* get UPS status */ if ((p = CmdSerial(OutBuff, LEN_GET_STATUS, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ status_init(); /* reset status flags */ /* store last UPS status */ ups.StatusUPS = (uint32_t)p[0] ; ups.StatusUPS |= ((uint32_t)p[1]<<8) ; ups.StatusUPS |= ((uint32_t)p[2]<<16) ; ups.StatusUPS |= ((uint32_t)p[3]<<24) ; ups.ShortStatus = (uint16_t)p[0]; ups.ShortStatus |= ((uint16_t)p[1]<<8) ; upsdebugx(1, "ups.StatusUPS: %08" PRIX32, ups.StatusUPS); upsdebugx(1, "ups.ShortStatus: %04" PRIX16, ups.ShortStatus); /* on battery? */ if (p[0] & 0x01) status_set("OB"); /* YES */ /* LOW battery? */ if (p[0] & 0x02) status_set("LB"); /* YES */ /* online? */ if (p[0] & 0x08) status_set("OL"); /* YES */ /* Overload? */ if (p[1] & 0xC0) status_set("OVER"); /* YES */ /* Offline/Init/Stanby/Waiting for mains? */ if (p[0] & 0xE0) status_set("OFF"); /* YES */ /* AVR on (boost)? */ if (p[4] & 0x04) status_set("BOOST"); /* YES */ /* AVR on (buck)? */ if (p[4] & 0x08) status_set("TRIM"); /* YES */ dstate_setinfo("ups.time", "%02d:%02d:%02d", p[6], p[7], p[8]) ; upsdebugx(3, "get 'Get Status': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Get Status': %s", PrintErr(ups.ErrCode)); /* upslogx(LOG_ERR, "get 'Get Status': %s", PrintErr(ups.ErrCode)); */ dstate_datastale(); return; } /* ========================= */ OutBuff[0] = CMD_GET_MEASURES ; /* get UPS values */ if ((p = CmdSerial(OutBuff, LEN_GET_MEASURES, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ dstate_setinfo("input.voltage", "%d", (int)((float)(p[2]*256 + p[3]) / 36.4)) ; if (ups.ge_2kVA) { dstate_setinfo("output.voltage", "%d", (int)((float)(p[6]*256 + p[7]) / 63.8)) ; dstate_setinfo("output.current", "%1.f", ((float)(p[8]*256 + p[9]) / 635.0)) ; dstate_setinfo("battery.voltage", "%.1f", ((float) (p[4]*256 + p[5])) / 329.0) ; } else { dstate_setinfo("output.voltage", "%d", (int)((float)(p[6]*256 + p[7]) / 36.4)) ; dstate_setinfo("output.current", "%1.f", ((float)(p[8]*256 + p[9]) / 1350.0)) ; dstate_setinfo("battery.voltage", "%.1f", ((float) (p[4]*256 + p[5])) / 585.0) ; } dstate_setinfo("ups.temperature", "%d", (int)(((float)(p[10]*256 + p[11])-202.97) / 1.424051)) ; upsdebugx(3, "get 'Get Measures': %s", PrintErr(ups.ErrCode)); } else { /* upsdebugx(1, "get 'Get Measures': %s", PrintErr(ups.ErrCode)); */ upslogx(LOG_ERR, "get 'Get Measures': %s", PrintErr(ups.ErrCode)); dstate_datastale(); return; } /* ========================= */ OutBuff[0] = CMD_GET_BAT_LD ; /* get UPS Battery and Load values */ if ((p = CmdSerial(OutBuff, LEN_GET_BAT_LD, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ dstate_setinfo("ups.power", "%d", (p[4]*256 + p[5])) ; /* dstate_setinfo("ups.realpower", "%d", (int)((float)(p[4]*256 + p[5]) * 0.6)) ; */ dstate_setinfo("battery.charge", "%d", (int)p[0]) ; dstate_setinfo("ups.load", "%d", (int)p[6]) ; upsdebugx(3, "get 'Get Batt+Load Status': %s", PrintErr(ups.ErrCode)); } else { /* upsdebugx(1, "get 'Get Batt+Load Status': %s", PrintErr(ups.ErrCode)); */ upslogx(LOG_ERR, "get 'Get Batt+Load Status': %s", PrintErr(ups.ErrCode)); dstate_datastale(); return; } status_commit(); dstate_dataok(); poll_interval = 2; } /* ========================= */ int instcmd(const char *cmdname, const char *extra) { unsigned char OutBuff[20] ; unsigned char InpBuff[260] ; unsigned char *p ; /* int i ; */ /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (strcasecmp(cmdname, "load.on") == 0) { OutBuff[0] = CMD_SD_ONESHOT ; /* turn ON the outputs */ OutBuff[1] = 0xFF ; /* ALL outputs */ OutBuff[2] = 0x08 ; /* Enable outputs (immediately) */ OutBuff[3] = 0 ; OutBuff[4] = 0 ; OutBuff[5] = 0 ; OutBuff[6] = 0 ; OutBuff[7] = 0 ; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if ((p = CmdSerial(OutBuff, LEN_SD_ONESHOT, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ upslogx(LOG_INFO, "Turning load on."); upsdebugx(1, "'SdOneshot(turn_ON)': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "'SdOneshot(turn_ON)': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "'SdOneshot(turn_ON)': %s", PrintErr(ups.ErrCode)); } return STAT_INSTCMD_HANDLED; } if (strcasecmp(cmdname, "load.off") == 0) { OutBuff[0] = CMD_SD_ONESHOT ; /* turn ON the outputs */ OutBuff[1] = 0xFF ; /* ALL outputs */ OutBuff[2] = 0x04 ; /* Disable outputs (immediately) */ OutBuff[3] = 0 ; OutBuff[4] = 0 ; OutBuff[5] = 0 ; OutBuff[6] = 0 ; OutBuff[7] = 0 ; upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if ((p = CmdSerial(OutBuff, LEN_SD_ONESHOT, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ upslogx(LOG_INFO, "Turning load on."); upsdebugx(1, "'SdOneshot(turn_OFF)': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "'SdOneshot(turn_OFF)': %s", PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "'SdOneshot(turn_OFF)': %s", PrintErr(ups.ErrCode)); } return STAT_INSTCMD_HANDLED; } if (strcasecmp(cmdname, "shutdown.return") == 0) { OutBuff[0] = CMD_SD_ONESHOT ; /* turn ON the outputs */ OutBuff[1] = 0xFF ; /* ALL outputs */ if (ups.StatusUPS & 0x01) OutBuff[2] = 0x02 ; /* Battery shutdown */ else OutBuff[2] = 0x01 ; /* Online shutdown */ if (ups.ShutdownDelay < 6) ups.ShutdownDelay = 6 ; OutBuff[3] = (ups.ShutdownDelay >> 8) & 0xFF ; /* SDDELAY (MSB) Shutdown value (seconds) */ OutBuff[4] = (ups.ShutdownDelay & 0xFF) ; /* SDDELAY (LSB) */ OutBuff[5] = (ups.WakeUpDelay >> 16) & 0xFF ; /* WUDELAY (MSB) Wakeup value (seconds) */ OutBuff[6] = (ups.WakeUpDelay >> 8) & 0xFF ; /* WUDELAY (...) */ OutBuff[7] = (ups.WakeUpDelay & 0xFF ) ; /* WUDELAY (LSB) */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if ((p = CmdSerial(OutBuff, LEN_SD_ONESHOT, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ upslogx(LOG_INFO, "Shutdown command(TYPE=%02x, SD=%u, WU=%u)", OutBuff[2], ups.ShutdownDelay, ups.WakeUpDelay) ; upsdebugx(3, "Shutdown command(TYPE=%02x, SD=%u, WU=%u): %s", OutBuff[2], ups.ShutdownDelay, ups.WakeUpDelay, PrintErr(ups.ErrCode)); } else { upsdebugx(1, "Shutdown command(TYPE=%02x, SD=%u, WU=%u): %s", OutBuff[2], ups.ShutdownDelay, ups.WakeUpDelay, PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Shutdown command(SD=%u, WU=%u): %s", ups.ShutdownDelay, ups.WakeUpDelay, PrintErr(ups.ErrCode)); } return STAT_INSTCMD_HANDLED; } if (strcasecmp(cmdname, "shutdown.stayoff") == 0) { OutBuff[0] = CMD_SD_ONESHOT ; /* turn ON the outputs */ OutBuff[1] = 0xFF ; /* ALL outputs */ if (ups.StatusUPS & 0x01) OutBuff[2] = 0x02 ; /* Battery shutdown */ else OutBuff[2] = 0x01 ; /* Online shutdown */ if (ups.ShutdownDelay < 6) ups.ShutdownDelay = 6 ; OutBuff[3] = (ups.ShutdownDelay >> 8) & 0xFF ; /* SDDELAY (MSB) Shutdown value (seconds) */ OutBuff[4] = (ups.ShutdownDelay & 0xFF) ; /* SDDELAY (LSB) */ OutBuff[5] = 0 ; /* WUDELAY (MSB) Wakeup value (seconds) */ OutBuff[6] = 0 ; /* WUDELAY (...) */ OutBuff[7] = 0 ; /* WUDELAY (LSB) */ upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); if ((p = CmdSerial(OutBuff, LEN_SD_ONESHOT, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ upslogx(LOG_INFO, "shutdown.stayoff - (TYPE=%02x, SD=%u, WU=%d)", OutBuff[2], ups.ShutdownDelay, 0) ; upsdebugx(3, "shutdown.stayoff - (TYPE=%02x, SD=%u, WU=%d): %s", OutBuff[2], ups.ShutdownDelay, 0, PrintErr(ups.ErrCode)); } else { upsdebugx(1, "shutdown.stayoff - (TYPE=%02x, SD=%u, WU=%d): %s", OutBuff[2], ups.ShutdownDelay, 0, PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "shutdown.stayoff - (TYPE=%02x, SD=%u, WU=%d)", OutBuff[2], ups.ShutdownDelay, 0) ; } return STAT_INSTCMD_HANDLED; } upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) || defined (HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic push #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtype-limits" #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #if (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE_BESIDEFUNC) # pragma GCC diagnostic ignored "-Wtautological-compare" #endif int setvar(const char *varname, const char *val) { unsigned int delay; upsdebug_SET_STARTING(varname, val); if (sscanf(val, "%u", &delay) != 1) { /* FIXME: ..._CONVERSION_FAILED? log it? */ return STAT_SET_UNKNOWN; } if (strcasecmp(varname, "ups.delay.start") == 0) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || defined (HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE # pragma GCC diagnostic ignored "-Wtautological-compare" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif delay = CLAMP(delay, 0, MAX_START_DELAY); #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || defined (HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE) ) # pragma GCC diagnostic pop #endif upsdebugx(1, "set 'WUDELAY': %u/%u", delay, ups.WakeUpDelay); ups.WakeUpDelay = delay ; dstate_setinfo("ups.delay.start", "%u", ups.WakeUpDelay); dstate_dataok(); return STAT_SET_HANDLED; } if (strcasecmp(varname, "ups.delay.shutdown") == 0) { #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || defined (HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS # pragma GCC diagnostic ignored "-Wtype-limits" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE # pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE # pragma GCC diagnostic ignored "-Wtautological-compare" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wtautological-compare" #pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif delay = CLAMP(delay, 0, MAX_SHUTDOWN_DELAY); #ifdef __clang__ #pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) || defined (HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE) ) # pragma GCC diagnostic pop #endif upsdebugx(1, "set 'SDDELAY': %u/%u", delay, ups.ShutdownDelay); ups.ShutdownDelay = delay; dstate_setinfo("ups.delay.shutdown", "%u", ups.ShutdownDelay); dstate_dataok(); return STAT_SET_HANDLED; } upslog_SET_UNKNOWN(varname, val); return STAT_SET_UNKNOWN; } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) || defined (HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_COMPARE_BESIDEFUNC) ) # pragma GCC diagnostic pop #endif void upsdrv_initinfo(void) { /* Get vars from ups.conf */ if (getval("ups.delay.shutdown")) { int ipv = atoi(getval("ups.delay.shutdown")); ups.ShutdownDelay = (unsigned int) CLAMP(ipv, 0, MAX_SHUTDOWN_DELAY); } else { ups.ShutdownDelay = 120; /* Shutdown delay in seconds */ } if (getval("ups.delay.start")) { int ipv = atoi(getval("ups.delay.start")); ups.WakeUpDelay = (unsigned int) CLAMP(ipv, 0, MAX_START_DELAY); } else { ups.WakeUpDelay = 10; /* WakeUp delay in seconds */ } if (detect_hardware() == -1) { fatalx(EXIT_FAILURE, "Unable to detect a Microdowell's Enterprise UPS on port %s\nCheck the cable, port name and try again", device_path); } /* I set the correspondig UPS variables They were read in 'detect_hardware()' some other variables were set in 'detect_hardware()' */ dstate_setinfo("ups.model", "Enterprise N%s", ups.UpsModel+3) ; dstate_setinfo("ups.power.nominal", "%d", atoi(ups.UpsModel+3) * 100) ; dstate_setinfo("ups.realpower.nominal", "%d", atoi(ups.UpsModel+3) * 60) ; ups.ge_2kVA = 0 ; /* differentiate between 2 type of UPSs */ if (atoi(ups.UpsModel+3) >= 20) ups.ge_2kVA = 1 ; dstate_setinfo("ups.type", "online-interactive") ; dstate_setinfo("ups.serial", "%s", ups.SerialNumber) ; dstate_setinfo("ups.firmware", "%d.%d (%d)", ups.FW_MajorVersion, ups.FW_MinorVersion, ups.FW_SubVersion) ; dstate_setinfo("ups.firmware.aux", "%d.%d %d.%d", ups.HW_MajorVersion, ups.HW_MinorVersion, ups.BR_MajorVersion, ups.BR_MinorVersion) ; dstate_setinfo("ups.mfr", "Microdowell") ; dstate_setinfo("ups.mfr.date", "%04d/%02d/%02d", ups.YearOfProd, ups.MonthOfProd, ups.DayOfProd) ; dstate_setinfo("battery.packs", "%d", ups.BatteryNumber) ; /* Register the available variables. */ dstate_setinfo("ups.delay.start", "%u", ups.WakeUpDelay); dstate_setflags("ups.delay.start", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.start", MAX_START_DELAY_LEN); dstate_setinfo("ups.delay.shutdown", "%u", ups.ShutdownDelay); dstate_setflags("ups.delay.shutdown", ST_FLAG_RW | ST_FLAG_STRING); dstate_setaux("ups.delay.shutdown", MAX_SHUTDOWN_DELAY_LEN); dstate_addcmd("load.on"); dstate_addcmd("load.off"); dstate_addcmd("shutdown.return"); dstate_addcmd("shutdown.stayoff"); /* Register the available instant commands. */ /* dstate_addcmd("test.battery.start"); dstate_addcmd("test.battery.stop"); dstate_addcmd("shutdown.stop"); dstate_addcmd("beeper.toggle"); */ /* set handlers */ upsh.instcmd = instcmd ; upsh.setvar = setvar; } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ unsigned char OutBuff[20]; unsigned char InpBuff[260]; unsigned char *p; unsigned char BatteryFlag = 0; OutBuff[0] = CMD_GET_STATUS ; /* get UPS status */ if ((p = CmdSerial(OutBuff, LEN_GET_STATUS, InpBuff)) != NULL) { p += 3 ; /* 'p' points to received data */ status_init(); /* reset status flags */ /* store last UPS status */ ups.StatusUPS = (uint32_t)p[0] ; ups.StatusUPS |= ((uint32_t)p[1]<<8) ; ups.StatusUPS |= ((uint32_t)p[2]<<16) ; ups.StatusUPS |= ((uint32_t)p[3]<<24) ; ups.ShortStatus = (uint16_t)p[0] ; ups.ShortStatus |= ((uint16_t)p[1]<<8) ; upsdebugx(1, "ups.StatusUPS: %08" PRIX32, ups.StatusUPS); upsdebugx(1, "ups.ShortStatus: %04" PRIX16, ups.ShortStatus); /* on battery? */ if (p[0] & 0x01) BatteryFlag = 1 ; /* YES */ upsdebugx(3, "get 'Get Status': %s", PrintErr(ups.ErrCode)); } else { upsdebugx(1, "get 'Get Status': %s", PrintErr(ups.ErrCode)); /* upslogx(LOG_ERR, "get 'Get Status': %s", PrintErr(ups.ErrCode)); */ } /* Send SHUTDOWN command */ OutBuff[0] = CMD_SD_ONESHOT ; /* Send SHUTDOWN command */ OutBuff[1] = 0xFF ; /* shutdown on ALL ports */ /* is the UPS on battery? */ if (BatteryFlag) OutBuff[2] = 0x02 ; /* Type of shutdown (BATTERY MODE) */ else OutBuff[2] = 0x01 ; /* Type of shutdown (ONLINE) */ if (ups.ShutdownDelay < 6) ups.ShutdownDelay = 6 ; OutBuff[3] = (ups.ShutdownDelay >> 8) & 0xFF ; /* SDDELAY (MSB) Shutdown value (seconds) */ OutBuff[4] = (ups.ShutdownDelay & 0xFF) ; /* SDDELAY (LSB) */ OutBuff[5] = (ups.WakeUpDelay >> 16) & 0xFF ; /* WUDELAY (MSB) Wakeup value (seconds) */ OutBuff[6] = (ups.WakeUpDelay >> 8) & 0xFF ; /* WUDELAY (...) */ OutBuff[7] = (ups.WakeUpDelay & 0xFF ) ; /* WUDELAY (LSB) */ if ((p = CmdSerial(OutBuff, LEN_SD_ONESHOT, InpBuff)) != NULL) { upsdebugx(2, "Shutdown command(TYPE=%02x, SD=%u, WU=%u): %s", OutBuff[2], ups.ShutdownDelay, ups.WakeUpDelay, PrintErr(ups.ErrCode)); } else { /* command not sent: print error code */ upsdebugx(1, "Shutdown command(TYPE=%02x, SD=%u, WU=%u): %s", OutBuff[2], ups.ShutdownDelay, ups.WakeUpDelay, PrintErr(ups.ErrCode)); upslogx(LOG_ERR, "Shutdown command(SD=%u, WU=%u): %s", ups.ShutdownDelay, ups.WakeUpDelay, PrintErr(ups.ErrCode)); } } void upsdrv_help(void) { } /* list flags and values that you want to receive via -x */ void upsdrv_makevartable(void) { /* allow '-x xyzzy' */ /* addvar(VAR_FLAG, "xyzzy", "Enable xyzzy mode"); */ /* allow '-x foo=' */ addvar(VAR_VALUE, "ups.delay.shutdown", "Override shutdown delay (120s)"); addvar(VAR_VALUE, "ups.delay.start", "Override restart delay (10s)"); } void upsdrv_initups(void) { upsfd = ser_open(device_path) ; ser_set_speed(upsfd, device_path, B19200) ; /* need to clear RTS and DTR: otherwise with default cable, communication will be problematic It is the same as removing pin7 from cable (pin 7 is needed for Plug&Play compatibility) */ ser_set_dtr(upsfd, 0); ser_set_rts(upsfd, 0); usleep(10000) ; /* small delay (1/100 s)) */ } void upsdrv_cleanup(void) { /* free(dynamic_mem); */ ser_close(upsfd, device_path) ; } nut-2.8.4/drivers/liebert-gxe.c0000644000175000017500000003410015044656702013314 00000000000000/* liebert-gxe.c - support for Liebert GXE Series UPS models via serial. Copyright (C) 2024 Gong Zhile This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "main.h" #include "attribute.h" #include "serial.h" #include "ydn23.h" #define DRIVER_NAME "Liebert GXE Series UPS driver" #define DRIVER_VERSION "0.04" #define PROBE_RETRIES 3 #define DEFAULT_STALE_RETRIES 3 #define DATAFLAG_WARN_MASK (1) #define DATAFLAG_ONOFF_MASK (1 << 4) /* Populated in upsdrv_initups() to default or user setting */ static char *devaddr = NULL; static int stale_retries = DEFAULT_STALE_RETRIES; static int stale_retry = DEFAULT_STALE_RETRIES; #define TRY_STALE() \ if ((stale_retry--) > 0) \ dstate_dataok(); \ else \ dstate_datastale(); \ #define ARRAY_SIZE(x) ((sizeof x) / (sizeof *x)) static const char *gxe_warns[] = { NULL, /* DATAFLAG */ "Inverter Out-of-Sync", "Unhealthy Main Circuit", "Rectifier Failure", "Inverter Failure", "Unhealthy Bypass", "Unhealthy Battery Voltage", NULL, /* USER_DEFINED */ NULL, /* USER_DEFINED */ "Power Module Overheated", "Unhealthy Fan", "Netural Input Missing", "Master Line Abnormally Turned-off", "Charger Failure", "Battery Discharge Declined", "Backup Power Supply Failure", "Ouput Overloaded", "Ouput Shorted", "Overload Timed-out", "Unhealthy Parallel Machine Current", "Parallel Machine Connection Failure", "Parallel Machine Address Error", "Unhealthy Internal Communication", "System Overloaded", "Battery Installed Backwards", "Battery Not Found", }; /* Instcmd & Driver Init: SYSPARAM -OK-> WARNING -OK-> ONOFF -OK-> ANALOG */ /* If the dataflag set for WARNING/ONOFF, set next state respectively. */ static enum gxe_poll_state { GXE_ONOFF, GXE_ANALOG, GXE_WARNING, /* Scheduled System Parameters, Trigged by Instcmd */ GXE_SYSPARAM, } poll_state; upsdrv_info_t upsdrv_info = { DRIVER_NAME, DRIVER_VERSION, "Gong Zhile ", DRV_EXPERIMENTAL, { NULL } }; static int instcmd(const char *cmdname, const char *extra) { enum YDN23_COMMAND_ID cmd = YDN23_REMOTE_COMMAND; struct ydn23_frame sendframe, recvframe; int retry, ret, len = 4; char *data = NULL; /* May be used in logging below, but not as a command argument */ NUT_UNUSED_VARIABLE(extra); upsdebug_INSTCMD_STARTING(cmdname, extra); if (!strcasecmp(cmdname, "test.battery.start")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); data = "1002"; } else if (!strcasecmp(cmdname, "test.battery.stop")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); data = "1003"; } else if (!strcasecmp(cmdname, "load.on")) { upslog_INSTCMD_POWERSTATE_MAYBE(cmdname, extra); data = "2001"; } else if (!strcasecmp(cmdname, "load.off")) { upslog_INSTCMD_POWERSTATE_CHANGE(cmdname, extra); data = "2003"; } else { upslog_INSTCMD_UNKNOWN(cmdname, extra); return STAT_INSTCMD_UNKNOWN; } ydn23_frame_init(&sendframe, cmd, devaddr, "21", data, len); for (retry = 0; retry < PROBE_RETRIES; retry++) { ret = ydn23_frame_send(upsfd, &sendframe); if (ret <= 0) continue; ret = ydn23_frame_read(upsfd, &recvframe, 2, 0); if (ret > 0) { poll_state = GXE_SYSPARAM; return STAT_INSTCMD_HANDLED; } } upslogx(LOG_INSTCMD_FAILED, "instcmd: remote failed response, try again"); return STAT_INSTCMD_FAILED; } static void upsdrv_updateinfo_onoff(void) { int retry, ret = -1, dflag, pwrval, rectval; struct ydn23_frame sendframe, frame; ydn23_frame_init(&sendframe, YDN23_GET_ONOFF_DATA, "21", devaddr, NULL, 0); for (retry = 0; retry < PROBE_RETRIES; retry++) { ret = ydn23_frame_send(upsfd, &sendframe); if (ret <= 0) continue; ret = ydn23_frame_read(upsfd, &frame, 2, 0); if (ret > 0) break; } if (ret <= 0) { upslogx(LOG_WARNING, "failed reading ONOFF data, retry"); TRY_STALE() return; } stale_retry = stale_retries; poll_state = GXE_ANALOG; /* DATAFLAG */ dflag = ydn23_val_from_hex(YDN23_FRAME_REG(frame, 0), 2); if (dflag & DATAFLAG_ONOFF_MASK) poll_state = GXE_ONOFF; if (dflag & DATAFLAG_WARN_MASK) poll_state = GXE_WARNING; status_init(); /* Field 1, Power Supply (01=UPS, 02=Bypass) */ pwrval = ydn23_val_from_hex(YDN23_FRAME_REG(frame, 1), 2); /* Field 3, Rectifier Power Supply (E0=None, E1=CITYPWR, E2=BAT) */ rectval = ydn23_val_from_hex(YDN23_FRAME_REG(frame, 3), 2); if (pwrval == 0x01 && rectval == 0xe2) status_set("OB"); else if (pwrval == 0x01) status_set("OL"); else if (pwrval == 0x02) { status_set("OL"); status_set("BYPASS"); } else upslogx(LOG_WARNING, "unknown ups state: %x %x", (unsigned int)pwrval, (unsigned int)rectval); status_commit(); /* Field 4, Battery Status */ switch(ydn23_val_from_hex(YDN23_FRAME_REG(frame, 4), 2)) { case 0xe0: dstate_setinfo("battery.charger.status", "resting"); break; case 0xe1: case 0xe2: dstate_setinfo("battery.charger.status", "charging"); break; case 0xe3: dstate_setinfo("battery.charger.status", "discharging"); break; default: upslogx(LOG_WARNING, "unknown battery status, ignored"); break; } /* Field 5, Battery Test State */ switch(ydn23_val_from_hex(YDN23_FRAME_REG(frame, 5), 2)) { case 0xe0: dstate_setinfo("ups.test.result", "In progress"); break; case 0xe1: dstate_setinfo("ups.test.result", "Idle"); break; default: upslogx(LOG_WARNING, "unknown battery test state, ignored"); break; } dstate_dataok(); } static void upsdrv_updateinfo_analog(void) { struct ydn23_frame sendframe, frame; int retry, ret = -1, dflag, volt; ydn23_frame_init(&sendframe, YDN23_GET_ANALOG_DATA_D, "21", devaddr, NULL, 0); for (retry = 0; retry < PROBE_RETRIES; retry++) { ret = ydn23_frame_send(upsfd, &sendframe); if (ret <= 0) continue; ret = ydn23_frame_read(upsfd, &frame, 2, 0); if (ret > 0) break; } if (ret <= 0) { upslogx(LOG_WARNING, "failed reading ANALOG data, retry"); TRY_STALE() return; } stale_retry = stale_retries; /* DATAFLAG, NOT RELIABLE SOMEHOW */ dflag = ydn23_val_from_hex(frame.INFO, 2); if (dflag & DATAFLAG_ONOFF_MASK) poll_state = GXE_ONOFF; if (dflag & DATAFLAG_WARN_MASK) poll_state = GXE_WARNING; /* Field 1, AC_IN VOLTAGE */ volt = ydn23_val_from_hex(YDN23_FRAME_REG(frame, 1), 4)/100; if (volt == 0 && status_get("OL")) { /* Oh no, power failed still online? */ status_init(); status_set("OB"); status_commit(); poll_state = GXE_WARNING; } if (volt > 0 && status_get("OB")) { /* Hum, power recovered still on battery? */ status_init(); status_set("OL"); status_commit(); poll_state = GXE_WARNING; } dstate_setinfo("input.voltage", "%.02f", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 1), 4)/100.0f); /* Field 4, AC_OUT VOLTAGE */ dstate_setinfo("output.voltage", "%.02f", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 7), 4)/100.0f); /* Field 7, AC_OUT CURRENT */ dstate_setinfo("output.current", "%.02f", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 13), 4)/100.0f); /* Field 10, DC VOLTAGE */ dstate_setinfo("battery.voltage", "%.02f", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 19), 4)/100.0f); /* Field 11, AC_OUT FREQUENCY */ dstate_setinfo("output.frequency", "%.02f", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 21), 4)/100.0f); /* Field 15, AC_IN FREQUENCY */ dstate_setinfo("input.frequency", "%.02f", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 27), 4)/100.0f); /* Field 18, AC_OUT REALPOWER, kW */ dstate_setinfo("ups.realpower", "%d", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 33), 4)*10); /* Field 19, AC_OUT POWER, kVA */ dstate_setinfo("ups.power", "%d", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 35), 4)*10); /* Field 22, BATTERY BACKUP TIME, Minutes */ dstate_setinfo("battery.runtime", "%d", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 41), 4)*60); dstate_dataok(); } static void upsdrv_updateinfo_sysparam(void) { struct ydn23_frame sendframe, frame; int retry, ret = -1; ydn23_frame_init(&sendframe, YDN23_GET_SYS_PARAM_D, "21", devaddr, NULL, 0); for (retry = 0; retry < PROBE_RETRIES; retry++) { ret = ydn23_frame_send(upsfd, &sendframe); if (ret <= 0) continue; ret = ydn23_frame_read(upsfd, &frame, 2, 0); if (ret > 0) break; } if (ret <= 0) { upslogx(LOG_WARNING, "failed reading SYSPARAM data, retry"); TRY_STALE() return; } stale_retry = stale_retries; poll_state = GXE_WARNING; /* Field 6, Nominal Voltage */ dstate_setinfo("output.voltage.nominal", "%d", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 9), 4)); /* Field 7, Nominal Frequency */ dstate_setinfo("output.frequency.nominal", "%d", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 11), 4)); /* Field 10, Bypass Working Voltage Max, ALWAYS 115% */ if (ydn23_val_from_hex(YDN23_FRAME_REG(frame, 17), 4) == 1) dstate_setinfo("input.transfer.bypass.high", "%f", ydn23_val_from_hex(YDN23_FRAME_REG(frame, 9), 4)*1.15f); /* Field 11, Bypass Working Voltage Min, Volt */ if (ydn23_val_from_hex(YDN23_FRAME_REG(frame, 19), 4) == 1) dstate_setinfo("input.transfer.bypass.low", "%d", 120); /* Field 21, Battery Test Interval, per 3 mons */ dstate_setinfo("ups.test.interval", "%ld", (long) ydn23_val_from_hex(YDN23_FRAME_REG(frame, 39), 4)*3*108000); dstate_dataok(); } static void upsdrv_updateinfo_warning(void) { struct ydn23_frame sendframe, frame; int retry, ret = -1, val; size_t i; ydn23_frame_init(&sendframe, YDN23_GET_WARNING_DATA, "21", devaddr, NULL, 0); for (retry = 0; retry < PROBE_RETRIES; retry++) { ret = ydn23_frame_send(upsfd, &sendframe); if (ret <= 0) continue; ret = ydn23_frame_read(upsfd, &frame, 2, 0); if (ret > 0) break; } if (ret <= 0) { upslogx(LOG_WARNING, "failed reading WARNING data, retry"); TRY_STALE() return; } stale_retry = stale_retries; poll_state = GXE_ONOFF; alarm_init(); for (i = 0; i < ARRAY_SIZE(gxe_warns); i++) { if (!gxe_warns[i]) continue; val = ydn23_val_from_hex(YDN23_FRAME_REG(frame, 1+i), 2); switch(val) { case 0x00: case 0x0e: case 0xe0: break; case 0x01: case 0x02: case 0x03: case 0xf0: alarm_set(gxe_warns[i]); break; default: upslogx(LOG_WARNING, "unexpected warning val %x", (unsigned int)val); break; } } alarm_commit(); dstate_dataok(); } void upsdrv_updateinfo(void) { switch(poll_state) { case GXE_ANALOG: upslogx(LOG_DEBUG, "Polling ANALOG data"); upsdrv_updateinfo_analog(); break; case GXE_ONOFF: upslogx(LOG_DEBUG, "Polling ONOFF data"); upsdrv_updateinfo_onoff(); break; case GXE_WARNING: upslogx(LOG_DEBUG, "Polling WARNING data"); upsdrv_updateinfo_warning(); break; case GXE_SYSPARAM: upslogx(LOG_DEBUG, "Polling SYSPARAM data"); upsdrv_updateinfo_sysparam(); break; #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic push #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT # pragma GCC diagnostic ignored "-Wcovered-switch-default" #endif #ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE # pragma GCC diagnostic ignored "-Wunreachable-code" #endif /* Older CLANG (e.g. clang-3.4) seems to not support the GCC pragmas above */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunreachable-code" # pragma clang diagnostic ignored "-Wcovered-switch-default" #endif default: /* Must not occur. */ upslogx(LOG_WARNING, "Unknown State Reached, " "Fallback to ANALOG data"); poll_state = GXE_ANALOG; upsdrv_updateinfo(); break; #ifdef __clang__ # pragma clang diagnostic pop #endif #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_COVERED_SWITCH_DEFAULT) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE) ) # pragma GCC diagnostic pop #endif } } void upsdrv_initinfo(void) { struct ydn23_frame sendframe, recvframe; char databuf[11]; int retry, ret = -1; ydn23_frame_init(&sendframe, YDN23_GET_VENDOR_INFO, "21", devaddr, NULL, 0); for (retry = 0; retry < PROBE_RETRIES; retry++) { ret = ydn23_frame_send(upsfd, &sendframe); if (ret <= 0) continue; ret = ydn23_frame_read(upsfd, &recvframe, 2, 0); if (ret > 0) break; } if (ret <= 0) fatal_with_errno(EXIT_FAILURE, "liebert-gxe: failed reading response"); /* UPS Name, 10 bytes */ ydn23_substr_from_hex(databuf, 11, YDN23_FRAME_REG(recvframe, 0), 20); dstate_setinfo("ups.mfr", "EmersonNetworkPower"); dstate_setinfo("ups.model", "%s", databuf); dstate_setinfo("ups.id", "%s", devaddr); dstate_addcmd("test.battery.start"); dstate_addcmd("test.battery.stop"); dstate_addcmd("load.off"); dstate_addcmd("load.on"); upsh.instcmd = instcmd; poll_state = GXE_SYSPARAM; } void upsdrv_help(void) { } void upsdrv_makevartable(void) { addvar(VAR_VALUE, "addr", "Override default UPS address"); addvar(VAR_VALUE, "retry", "Override default retry"); } void upsdrv_initups(void) { upsfd = ser_open(device_path); devaddr = "01"; /* Default Address is 0x01 */ if (testvar("addr")) devaddr = getval("addr"); if (testvar("retry")) stale_retries = atoi(getval("retry")); stale_retry = stale_retries; poll_interval = 5; usleep(100000); } void upsdrv_shutdown(void) { /* Only implement "shutdown.default"; do not invoke * general handling of other `sdcommands` here */ /* FIXME: There seems to be instcmd(load.off), why not that? */ upslogx(LOG_INFO, "Liebert GXE UPS can't fully shutdown, NOOP"); if (handling_upsdrv_shutdown > 0) set_exit_flag(EF_EXIT_FAILURE); } void upsdrv_cleanup(void) { ser_close(upsfd, device_path); } nut-2.8.4/drivers/nutdrv_qx_voltronic-axpert.c0000644000175000017500000063624115044656702016555 00000000000000/* nutdrv_qx_voltronic-axpert.c - Subdriver for Voltronic Power Axpert * * Copyright (C) * 2014 Daniele Pezzini * 2022 Graham Leggett * 2025 Jim Klimov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "main.h" #include "nutdrv_qx.h" #include "nutdrv_qx_voltronic-axpert.h" #include "common_voltronic-crc.h" #include "nut_float.h" #define VOLTRONIC_AXPERT_VERSION "Voltronic-Axpert 0.01" /* For dev-testing: known ways to get data points, need mapping into NUT variables */ #if WITH_UNMAPPED_DATA_POINTS # define TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT 1 #else # define TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT 0 #endif /* NOTE for dev-testing: you can enable single or combo code paths * with macros below, to enable visibility of certain data point * or command/setting groups. It suffices to e.g. add `+ 1` to the * line you want to activate in the custom build of NUT for testing. */ #define TESTING_AXPERT_CAPS_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_CAPS_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_OPERATIONAL_OPTIONS_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_PFC_CURVE_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_GENERATOR_AS_AC_SOURCE_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_OUTPUT_REALPOWER_NOMINAL_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_RATINGS_QUERY_3 TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_ACCEPTABLE_LIMITS_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_PF_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_DATETIME_QUERY_CHANGE TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_BATTERY_INFO_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_FAULT_TYPE_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_SELFTEST_RESULT_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_ENERGY_STATS_QUERY TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT #define TESTING_AXPERT_INSTCMD TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT /* Warning: unlocks a method not used in any code path: */ #define TESTING_AXPERT_FUNC_PROCESS_SIGN 0 // TESTING_AXPERT_UNMAPPED_MAPPINGS_DEFAULT /* Support functions */ static int voltronic_sunny_claim(void); static void voltronic_axpert_initinfo(void); static void voltronic_sunny_makevartable(void); static int voltronic_axpert_clear_flags(const char *varname, const unsigned long flag, const unsigned long noflag, const unsigned long clearflag); #if TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE static int voltronic_axpert_add_flags(const char *varname, const unsigned long flag, const unsigned long noflag, const unsigned long addflag); #endif /* TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE */ #if TESTING_AXPERT_ENERGY_STATS_QUERY static int voltronic_sunny_checksum(const char *string); #endif /* TESTING_AXPERT_ENERGY_STATS_QUERY */ #if TESTING_AXPERT_OUTPUT_REALPOWER_NOMINAL_QUERY || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE static void voltronic_sunny_update_related_vars_limits(item_t *item, const char *value); #endif /* TESTING_AXPERT_OUTPUT_REALPOWER_NOMINAL_QUERY || TESTING_AXPERT_FUNC_PROCESS_SIGN || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE || TESTING_AXPERT_FAULT_TYPE_QUERY || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE */ #if TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE static int voltronic_sunny_OEEPB(void); #endif /* TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE */ /* Range/enum functions */ #if TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE static int voltronic_sunny_pv_priority_enum(char *value, const size_t len); #endif /* TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE */ #if TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY static int voltronic_sunny_grid_inout_freq_max(char *value, const size_t len); static int voltronic_sunny_grid_inout_freq_min(char *value, const size_t len); #endif /* TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY */ #if TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE static int voltronic_sunny_bc_v_bulk(char *value, const size_t len); #endif /* TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE */ #if TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE static int voltronic_sunny_pv_input_volt_max(char *value, const size_t len); #endif /* TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE */ /* Answer preprocess functions */ static int voltronic_axpert_checkcrc(item_t *item, const int len); /* Command preprocess functions */ static int voltronic_axpert_crc(item_t *item, char *command, const size_t commandlen); #if TESTING_AXPERT_FAULT_TYPE_QUERY static int voltronic_sunny_fault_query(item_t *item, char *command, const size_t commandlen); #endif /* TESTING_AXPERT_FAULT_TYPE_QUERY */ #if TESTING_AXPERT_ENERGY_STATS_QUERY static int voltronic_sunny_energy_hour(item_t *item, char *command, const size_t commandlen); static int voltronic_sunny_energy_day(item_t *item, char *command, const size_t commandlen); static int voltronic_sunny_energy_month(item_t *item, char *command, const size_t commandlen); static int voltronic_sunny_energy_year(item_t *item, char *command, const size_t commandlen); #endif /* TESTING_AXPERT_ENERGY_STATS_QUERY */ /* Preprocess functions */ static int voltronic_axpert_hex_preprocess(item_t *item, char *value, const size_t valuelen); #if TESTING_AXPERT_OUTPUT_REALPOWER_NOMINAL_QUERY || TESTING_AXPERT_FUNC_PROCESS_SIGN || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE || TESTING_AXPERT_FAULT_TYPE_QUERY static int voltronic_sunny_basic_preprocess(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_OUTPUT_REALPOWER_NOMINAL_QUERY || TESTING_AXPERT_FUNC_PROCESS_SIGN || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE || TESTING_AXPERT_FAULT_TYPE_QUERY */ static int voltronic_axpert_protocol(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_fw(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_serial_numb(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_capability(item_t *item, char *value, const size_t valuelen); #if TESTING_AXPERT_CAPS_CHANGE static int voltronic_axpert_capability_set(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_capability_reset(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_capability_set_nonut(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_CAPS_CHANGE */ #if TESTING_AXPERT_OPERATIONAL_OPTIONS_QUERY_CHANGE || TESTING_AXPERT_PFC_CURVE_QUERY_CHANGE || TESTING_AXPERT_GENERATOR_AS_AC_SOURCE_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE static int voltronic_sunny_01(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_01_set(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_OPERATIONAL_OPTIONS_QUERY_CHANGE || TESTING_AXPERT_PFC_CURVE_QUERY_CHANGE || TESTING_AXPERT_GENERATOR_AS_AC_SOURCE_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE */ #if TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE static int voltronic_sunny_pv_priority(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_pv_priority_set(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE */ #if TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE static int voltronic_sunny_unskip_setvar(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE */ static int voltronic_axpert_qpiri_battery_type(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_qpiri_model_type(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_transformer(item_t *item, char *value, const size_t valuelen); #if TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE static int voltronic_sunny_volt_nom_set(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE */ #if TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE static int voltronic_sunny_process_setvar(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE || TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY || TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE || TESTING_AXPERT_PF_QUERY_CHANGE */ #if TESTING_AXPERT_OUTPUT_REALPOWER_NOMINAL_QUERY static int voltronic_sunny_basic_preprocess_and_update_related_vars_limits(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_OUTPUT_REALPOWER_NOMINAL_QUERY */ #if TESTING_AXPERT_RATINGS_QUERY_3 static int voltronic_sunny_yymmdd(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_hh_mm(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_RATINGS_QUERY_3 */ #if TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE static int voltronic_sunny_lst(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE */ #if TESTING_AXPERT_ACCEPTABLE_LIMITS_QUERY static int voltronic_sunny_set_limits(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_ACCEPTABLE_LIMITS_QUERY */ #if TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE static int voltronic_sunny_unskip_setvar_and_update_related_vars_limits(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE || TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE */ #if TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE static int voltronic_sunny_charger_limits_set(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_discharging_limits_set(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE */ #if TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE static int voltronic_sunny_hhmm(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_hhmm_set(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_hhmm_x2_set(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE */ #if TESTING_AXPERT_PF_QUERY_CHANGE static int voltronic_sunny_pf(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_pfc_set(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_PF_QUERY_CHANGE */ #if TESTING_AXPERT_DATETIME_QUERY_CHANGE || TESTING_AXPERT_ENERGY_STATS_QUERY || TESTING_AXPERT_RATINGS_QUERY_3 || TESTING_AXPERT_FAULT_TYPE_QUERY static int voltronic_sunny_date(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_DATETIME_QUERY_CHANGE || TESTING_AXPERT_ENERGY_STATS_QUERY || TESTING_AXPERT_RATINGS_QUERY_3 || TESTING_AXPERT_FAULT_TYPE_QUERY */ #if TESTING_AXPERT_DATETIME_QUERY_CHANGE || TESTING_AXPERT_FAULT_TYPE_QUERY static int voltronic_sunny_time(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_DATETIME_QUERY_CHANGE || TESTING_AXPERT_FAULT_TYPE_QUERY */ #if TESTING_AXPERT_DATETIME_QUERY_CHANGE static int voltronic_sunny_date_set(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_time_set(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_DATETIME_QUERY_CHANGE */ #if TESTING_AXPERT_FUNC_PROCESS_SIGN /* WARNING: Currently unused in any code path! */ static int voltronic_sunny_process_sign(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_FUNC_PROCESS_SIGN */ static int voltronic_axpert_status(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_warning(item_t *item, char *value, const size_t valuelen); static int voltronic_axpert_mode(item_t *item, char *value, const size_t valuelen); #if TESTING_AXPERT_BATTERY_INFO_QUERY static int voltronic_sunny_batt_runtime(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_BATTERY_INFO_QUERY */ #if TESTING_AXPERT_FAULT_TYPE_QUERY static int voltronic_sunny_fault(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_date_skip_me(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_time_skip_me(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_skip_me(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_fault_status(item_t *item, char *value, const size_t valuelen); static int voltronic_sunny_fault_id(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_FAULT_TYPE_QUERY */ #if TESTING_AXPERT_SELFTEST_RESULT_QUERY static int voltronic_sunny_self_test_result(item_t *item, char *value, const size_t valuelen); #endif /* TESTING_AXPERT_SELFTEST_RESULT_QUERY */ /* == Global vars == */ #if TESTING_AXPERT_CAPS_CHANGE /* Capability vars ("enabled"/"disabled") */ static char *bypass_alarm, *battery_alarm; #endif /* TESTING_AXPERT_CAPS_CHANGE */ /* Global flags */ static int crc = 1, /* Whether device puts CRC in its replies or not */ line_loss = 0, /* Whether device has lost connection to the grid or not */ pv_loss = 0; /* Whether devoce has lost connection to PV or not */ static double fw = 0; /* Firmware version */ static int protocol = 0, /* Protocol used by device */ #if TESTING_AXPERT_FAULT_TYPE_QUERY fault_id, /* Fault ID */ #endif /* TESTING_AXPERT_FAULT_TYPE_QUERY */ #if TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE model_id = 0, /* Model ID */ #endif /* TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE */ model_type = 0; /* Model type */ /* == Ranges/enums/lengths == */ /* Enumlist for battery type */ static info_rw_t voltronic_axpert_e_battery_type[] = { { "AGM", 0 }, /* Type: 0 */ { "Flooded", 0 }, /* Type: 1 */ { "User", 0 }, /* Type: 2 */ { "", 0 } }; /* Enumlist for device model type */ static info_rw_t voltronic_axpert_e_model_type[] = { { "Grid-tie", 0 }, /* Type: 0 */ { "Off-grid", 0 }, /* Type: 1 */ { "Hybrid", 0 }, /* Type: 10 */ { "Off Grid with 2 Trackers", 0 }, /* Type: 11 */ { "Off Grid with 3 Trackers", 0 }, /* Type: 20 */ { "", 0 } }; /* Enumlist for device capabilities that have a NUT var */ static info_rw_t voltronic_axpert_e_cap[] = { { "no", 0 }, { "yes", 0 }, { "", 0 } }; #if TESTING_AXPERT_CAPS_CHANGE || TESTING_AXPERT_OPERATIONAL_OPTIONS_QUERY_CHANGE || TESTING_AXPERT_PFC_CURVE_QUERY_CHANGE || TESTING_AXPERT_GENERATOR_AS_AC_SOURCE_QUERY_CHANGE /* Enumlist for NONUT capabilities */ static info_rw_t voltronic_axpert_e_cap_nonut[] = { { "disabled", 0 }, { "enabled", 0 }, { "", 0 } }; #endif /* TESTING_AXPERT_CAPS_CHANGE */ #if TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE /* Enumlist for PV energy supply priority */ static info_rw_t voltronic_sunny_e_pv_priority[] = { { "Battery-Load", voltronic_sunny_pv_priority_enum }, /* Priority: 01; Type: Off-grid (01) */ { "Load-Battery", voltronic_sunny_pv_priority_enum }, /* Priority: 02; Type: Off-grid (01); Model: 150 */ { "Load-Battery (grid relay disconnected)", voltronic_sunny_pv_priority_enum }, /* Priority: 02; Type: Off-grid (01); Model: 151 */ { "Battery-Load-Grid", voltronic_sunny_pv_priority_enum }, /* Priority: 01; Type: Grid-tie with backup (10) */ { "Load-Battery-Grid", voltronic_sunny_pv_priority_enum }, /* Priority: 02; Type: Grid-tie with backup (10) */ { "Load-Grid-Battery", voltronic_sunny_pv_priority_enum }, /* Priority: 03; Type: Grid-tie with backup (10) */ { "", 0 } }; /* Preprocess enum value for PV energy supply priority */ static int voltronic_sunny_pv_priority_enum(char *value, const size_t len) { NUT_UNUSED_VARIABLE(len); /* FIXME? strncasecmp(value, expected, len) but make sure we check the whole fixed argument or it is not equal */ switch (model_type) { case 1: /* Off-grid */ if ( !strcasecmp(value, "Battery-Load") || /* Priority: 01 */ !strcasecmp(value, "Load-Battery") || /* Priority: 02; Model: 150 */ !strcasecmp(value, "Load-Battery (grid relay disconnected)") /* Priority: 02; Model: 151 */ ) return 0; break; case 10: /* Grid-tie with backup */ if ( !strcasecmp(value, "Battery-Load-Grid") || /* Priority: 01 */ !strcasecmp(value, "Load-Battery-Grid") || /* Priority: 02 */ !strcasecmp(value, "Load-Grid-Battery") /* Priority: 03 */ ) return 0; break; case 0: /* Grid-tie */ case 11: /* Self-use */ default: break; } return -1; } #endif /* TESTING_AXPERT_PV_SUPPLY_PRIORITY_QUERY_CHANGE */ /* Enumlist for nominal voltage */ static info_rw_t voltronic_axpert_e_volt_nom[] = { { "101", 0 }, /* Low voltage models */ { "110", 0 }, /* Low voltage models */ { "120", 0 }, /* Low voltage models */ { "127", 0 }, /* Low voltage models */ { "202", 0 }, /* High voltage models */ { "208", 0 }, /* High voltage models */ { "220", 0 }, /* High voltage models */ { "230", 0 }, /* High voltage models */ { "240", 0 }, /* High voltage models */ { "", 0 } }; #if TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE /* Enumlist for nominal frequency */ static info_rw_t voltronic_sunny_e_freq_nom[] = { { "50", 0 }, { "60", 0 }, { "", 0 } }; /* Range for number of MPP trackers in use */ static info_rw_t voltronic_sunny_r_mpp_number[] = { { "01", 0 }, { "99", 0 }, { "", 0 } }; #endif /* TESTING_AXPERT_NOMINAL_VOLTAGE_CHANGE */ #if TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY /* Range for maximum grid output voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #1, #2) */ static info_rw_t voltronic_sunny_r_grid_output_volt_max[] = { { "240", 0 }, { "276", 0 }, { "", 0 } }; /* Range for maximum grid input voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #1, #2) */ static info_rw_t voltronic_sunny_r_grid_input_volt_max[] = { { "240", 0 }, { "280", 0 }, { "", 0 } }; /* Range for minimum grid output voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #3, #4) */ static info_rw_t voltronic_sunny_r_grid_output_volt_min[] = { { "176", 0 }, { "220", 0 }, { "", 0 } }; /* Range for minimum grid input voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #3, #4) */ static info_rw_t voltronic_sunny_r_grid_input_volt_min[] = { { "175", 0 }, { "220", 0 }, { "", 0 } }; /* Range for maximum grid input/output frequency: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #5, #6) */ static info_rw_t voltronic_sunny_r_grid_inout_freq_max[] = { /* FIXME: ranges only support ints */ { "50.2", voltronic_sunny_grid_inout_freq_max }, /* Nominal frequency (QPIRI #2) == 50.0 */ { "54.8", voltronic_sunny_grid_inout_freq_max }, /* Nominal frequency (QPIRI #2) == 50.0 */ { "60.2", voltronic_sunny_grid_inout_freq_max }, /* Nominal frequency (QPIRI #2) == 60.0 */ { "64.8", voltronic_sunny_grid_inout_freq_max }, /* Nominal frequency (QPIRI #2) == 60.0 */ { "", 0 } }; /* Preprocess range value for (not overwritten) maximum grid input/output frequency */ static int voltronic_sunny_grid_inout_freq_max(char *value, const size_t len) { char *ptr; const int val = strtol(value, &ptr, 10) * 10 + (*ptr == '.' ? strtol(++ptr, NULL, 10) : 0); double gfn; const char *gridfreqnom = dstate_getinfo("grid.frequency.nominal"); NUT_UNUSED_VARIABLE(len); /* FIXME? */ if (!gridfreqnom) { upsdebugx(2, "%s: unable to get grid.frequency.nominal", __func__); return -1; } gfn = strtod(gridfreqnom, NULL); switch (val) { case 502: case 548: /* Nominal frequency (QPIRI #2) == 50.0 */ if (gfn == 50.0) return 0; break; case 602: case 648: /* Nominal frequency (QPIRI #2) == 60.0 */ if (gfn == 60.0) return 0; break; default: upsdebugx(2, "%s: unknown value (%s)", __func__, value); break; } return -1; } /* Range for minimum grid input/output frequency: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #7, #8) */ static info_rw_t voltronic_sunny_r_grid_inout_freq_min[] = { /* FIXME: ranges only support ints */ { "45.0", voltronic_sunny_grid_inout_freq_min }, /* Nominal frequency (QPIRI #2) == 50.0 */ { "49.8", voltronic_sunny_grid_inout_freq_min }, /* Nominal frequency (QPIRI #2) == 50.0 */ { "55.0", voltronic_sunny_grid_inout_freq_min }, /* Nominal frequency (QPIRI #2) == 60.0 */ { "59.8", voltronic_sunny_grid_inout_freq_min }, /* Nominal frequency (QPIRI #2) == 60.0 */ { "", 0 } }; /* Preprocess range value for (not overwritten) minimum grid input/output frequency */ static int voltronic_sunny_grid_inout_freq_min(char *value, const size_t len) { char *ptr; const int val = strtol(value, &ptr, 10) * 10 + (*ptr == '.' ? strtol(++ptr, NULL, 10) : 0); double gfn; const char *gridfreqnom = dstate_getinfo("grid.frequency.nominal"); NUT_UNUSED_VARIABLE(len); /* FIXME? */ if (!gridfreqnom) { upsdebugx(2, "%s: unable to get grid.frequency.nominal", __func__); return -1; } gfn = strtod(gridfreqnom, NULL); switch (val) { case 450: case 498: /* Nominal frequency (QPIRI #2) == 50.0 */ if (gfn == 50.0) return 0; break; case 550: case 598: /* Nominal frequency (QPIRI #2) == 60.0 */ if (gfn == 60.0) return 0; break; default: upsdebugx(2, "%s: unknown value (%s)", __func__, value); break; } return -1; } #endif /* TESTING_AXPERT_GRID_OUTPUT_VOLTAGE_LIMITS_QUERY */ #if TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE /* Range for waiting time before grid connection: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #9, #10) */ static info_rw_t voltronic_sunny_r_grid_waiting_time[] = { { "5", 0 }, { "999", 0 }, { "", 0 } }; #endif /* TESTING_AXPERT_WAITING_TIME_BEFORE_GRID_CONNECTION_QUERY_CHANGE */ #if TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE /* Range for maximum battery-charging current: filled at runtime by voltronic_sunny_set_limits() (QVFTR #11, #12), overwritten (if appropriate) by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bc_v_floating[] = { { "", 0 }, { "", 0 }, { "", 0 } }; /* Range for maximum battery-charging current: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #13, #14) and voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bc_c_max[] = { /* FIXME: ranges only support ints */ { "0.5", 0 }, { "25.0", 0 }, { "", 0 } }; /* Range for bulk battery-charging voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #25, #26) and voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bc_v_bulk[] = { { "47", 0 }, { "50", voltronic_sunny_bc_v_bulk }, /* IFF FW version (QSVFW2) >= 0.3 */ { "57", voltronic_sunny_bc_v_bulk }, /* IFF FW version (QSVFW2) < 0.3 */ { "", 0 } }; /* Preprocess range value for (not overwritten) bulk battery-charging voltage */ static int voltronic_sunny_bc_v_bulk(char *value, const size_t len) { const int val = strtol(value, NULL, 10); NUT_UNUSED_VARIABLE(len); /* FIXME? */ switch (val) { case 50: /* FW version (QSVFW2) >= 0.3 */ if (fw >= 0.3) return 0; break; case 57: /* FW version (QSVFW2) < 0.3 */ if (fw < 0.3) return 0; break; default: upsdebugx(2, "%s: unknown value (%s)", __func__, value); break; } return -1; } #endif /* TESTING_AXPERT_BATTERY_CHARGING_DATA_QUERY || TESTING_AXPERT_BATTERY_CHARGING_LIMITS_CHANGE */ #if TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE /* Range for minimum floating battery-charging current: filled at runtime by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bc_c_floating_low[] = { { "0", 0 }, { "", 0 }, { "", 0 } }; /* Range for restart battery-charging voltage: filled at runtime by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bc_v_restart[] = { { "0", 0 }, { "", 0 }, { "", 0 } }; /* Range for floating battery-charging current time thershold */ static info_rw_t voltronic_sunny_r_bc_time_threshold[] = { { "0", 0 }, { "900", 0 }, { "", 0 } }; /* Range for cut-off battery-discharging voltage when grid is not available: overwritten (if appropriate) at runtime by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bd_v_cutoff_gridoff[] = { { "40", 0 }, { "48", 0 }, { "", 0 } }; /* Range for cut-off battery-discharging voltage when grid is available: overwritten (if appropriate) at runtime by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bd_v_cutoff_gridon[] = { { "40", 0 }, { "48", 0 }, { "", 0 } }; /* Range for restart battery-discharging voltage when grid is unavailable: filled at runtime by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bd_v_restart_gridoff[] = { { "", 0 }, { "", 0 }, { "", 0 } }; /* Range for restart battery-discharging voltage when grid is available: filled at runtime by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_bd_v_restart_gridon[] = { { "", 0 }, { "", 0 }, { "", 0 } }; /* Range for maximum PV input voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #15, #16) */ static info_rw_t voltronic_sunny_r_pv_input_volt_max[] = { { "450", 0 }, { "510", voltronic_sunny_pv_input_volt_max }, /* P16 */ { "550", voltronic_sunny_pv_input_volt_max }, /* P15 */ { "", 0 } }; /* Preprocess range value for (not overwritten) maximum PV input voltage */ static int voltronic_sunny_pv_input_volt_max(char *value, const size_t len) { const int val = strtol(value, NULL, 10); NUT_UNUSED_VARIABLE(len); /* FIXME? */ switch (val) { case 510: /* P16 */ if (protocol == 16) return 0; break; case 550: /* P15 */ if (protocol == 15) return 0; break; default: upsdebugx(2, "%s: unknown value (%s)", __func__, value); break; } return -1; } /* Range for minimum PV input voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #17, #18) */ static info_rw_t voltronic_sunny_r_pv_input_volt_min[] = { { "90", 0 }, { "200", 0 }, { "", 0 } }; /* Range for maximum MPP voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #19, #20) */ static info_rw_t voltronic_sunny_r_mpp_input_volt_max[] = { { "400", 0 }, { "450", 0 }, { "", 0 } }; /* Range for minimum MPP voltage: overwritten (if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #21, #22) */ static info_rw_t voltronic_sunny_r_mpp_input_volt_min[] = { { "110", 0 }, { "200", 0 }, { "", 0 } }; #endif /* TESTING_AXPERT_BATTERY_CHARGING_LIMITS_QUERY_CHANGE */ #if TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE /* Range for maximum output power: filled(/overwritten, if appropriate) at runtime by voltronic_sunny_set_limits() (QVFTR #23, #24) and voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_output_realpower_max[] = { { "0", 0 }, { "", 0 }, { "", 0 } }; /* Range for maximum power feeding grid: max value filled at runtime by voltronic_sunny_update_related_vars_limits() */ static info_rw_t voltronic_sunny_r_grid_realpower_max[] = { { "0", 0 }, { "", 0 }, { "", 0 } }; /* Range for LCD sleep time (time after which LCD screen-saver starts) */ static info_rw_t voltronic_sunny_r_lcd_sleep_time[] = { { "0", 0 }, /* 00 */ { "2970", 0 }, /* 99 */ { "", 0 } }; /* Time (hh:mm) length */ static info_rw_t voltronic_sunny_l_hhmm[] = { { "5", 0 }, { "", 0 } }; /* Range for maximum grid input average voltage */ static info_rw_t voltronic_sunny_r_grid_in_avg_volt_max[] = { { "235", 0 }, { "265", 0 }, { "", 0 } }; /* Range for grid power deviation */ static info_rw_t voltronic_sunny_r_grid_power_deviation[] = { { "0", 0 }, { "999", 0 }, { "", 0 } }; #endif /* TESTING_AXPERT_MAX_OUTPUT_POWER_QUERY_CHANGE */ #if TESTING_AXPERT_PF_QUERY_CHANGE /* Range for power factor */ static info_rw_t voltronic_sunny_r_output_powerfactor[] = { /* FIXME: 1. nutdrv_qx setvar+RANGE doesn't support negative values; 2. values should be divided by 100 */ { "-99", 0 }, { "-90", 0 }, { "90", 0 }, { "100", 0 }, { "", 0 } }; /* Range for power percent setting */ static info_rw_t voltronic_sunny_r_powerpercent_setting[] = { { "10", 0 }, { "100", 0 }, { "", 0 } }; /* Range for power factor_percent */ static info_rw_t voltronic_sunny_r_powerfactor_percent[] = { { "50", 0 }, { "100", 0 }, { "", 0 } }; /* Range for power factor curve */ static info_rw_t voltronic_sunny_r_powerfactor_curve[] = { /* FIXME: nutdrv_qx setvar+RANGE doesn't support negative values */ { "-99", 0 }, { "-90", 0 }, { "", 0 } }; #endif /* TESTING_AXPERT_PF_QUERY_CHANGE */ #if TESTING_AXPERT_DATETIME_QUERY_CHANGE /* Date (YYYY/MM/DD) length */ static info_rw_t voltronic_sunny_l_date[] = { { "10", 0 }, { "", 0 } }; /* Time (hh:mm:ss) length */ static info_rw_t voltronic_sunny_l_time[] = { { "8", 0 }, { "", 0 } }; #endif /* TESTING_AXPERT_DATETIME_QUERY_CHANGE */ /* == qx2nut lookup table == */ static item_t voltronic_axpert_qx2nut[] = { /*#######################################################################################################################################################################################################################################################################################################################################################################################################* *# info_type |info_flags |info_rw |command |answer |answer |leading|value |from |to |dfl |qxflags |preprocess_command |preprocess_answer |preprocess #* *# | | | |_len | | | | | | | | | | #* *#######################################################################################################################################################################################################################################################################################################################################################################################################*/ /* Query device for protocol * > [QPI\r] * < [(PI30\r] * 012345 * 0 */ { "device.firmware.aux", 0, NULL, "QPI\r", "", 6, '(', "", 1, 4, "%s", QX_FLAG_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_protocol }, /* Query device for firmware version * > [QVFW\r] * < [(VERFW:00074.50\r] * 0123456789012345 * 0 1 */ { "device.firmware", 0, NULL, "QVFW\r", "", 16, '(', "", 7, 14, "0X%s", QX_FLAG_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_fw }, /* Query device for main CPU processor version * > [QVFW\r] * < [(VERFW:00074.50\r] * 0123456789012345 * 0 1 */ { "device.firmware.main", 0, NULL, "QVFW\r", "", 16, '(', "", 7, 14, "0X%s", QX_FLAG_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_hex_preprocess }, /* Query device for SCC1 CPU Firmware version * > [QVFW2\r] * < [(VERFW2:00000.31\r] * 01234567890123456 * 0 1 */ { "device.firmware.scc1", 0, NULL, "QVFW2\r", "", 17, '(', "", 8, 15, "0X%s", QX_FLAG_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_hex_preprocess }, /* Query device for SCC2 CPU Firmware version * > [QVFW3\r] * < [(VERFW3:00000.31\r] * 01234567890123456 * 0 1 */ { "device.firmware.scc2", 0, NULL, "QVFW3\r", "", 17, '(', "", 8, 15, "0X%s", QX_FLAG_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_hex_preprocess }, /* Query device for SCC3 CPU Firmware version * > [QVFW4\r] * < [(VERFW4:00000.31\r] * 01234567890123456 * 0 1 */ { "device.firmware.scc3", 0, NULL, "QVFW4\r", "", 17, '(', "", 8, 15, "0X%s", QX_FLAG_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_hex_preprocess }, /* Query device for serial number * > [QID\r] * < [(12345679012345\r] <- As far as I know it hasn't a fixed length -> min length = ( + \r = 2 * 0123456789012345 * 0 1 */ { "device.serial", 0, NULL, "QID\r", "", 2, '(', "", 1, 0, "%s", QX_FLAG_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_serial_numb }, /*#######################################################################################################################################################################################################################################################################################################################################################################################################################################*/ /* Query device for capability; only those capabilities whom the device is capable of are reported as Enabled or Disabled * > [QFLAG\r] * < [(EakxyDbjuvz\r] * 01234567890123 * 0 * min length = ( + E + D + \r = 4 * * A Enable/disable silence buzzer or open buzzer * B Enable/Disable overload bypass function * J Enable/Disable power saving * K Enable/Disable LCD display escape to default page after 1min timeout * U Enable/Disable overload restart * V Enable/Disable over temperature restart * X Enable/Disable backlight on * Y Enable/Disable alarm on when primary source interrupt * Z Enable/Disable fault code record * L Enable/Disable data log pop-up */ { "battery.energysave", ST_FLAG_RW, voltronic_axpert_e_cap, "QFLAG\r", "", 4, '(', "", 1, 0, "%s", QX_FLAG_ENUM | QX_FLAG_SEMI_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability }, { "ups.beeper.status", 0, NULL, "QFLAG\r", "", 4, '(', "", 1, 0, "%s", QX_FLAG_SEMI_STATIC, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability }, #if TESTING_AXPERT_CAPS_QUERY /* Not available in NUT */ /* FIXME: ups_status BYPASS and RB(?) */ { "experimental.bypass_alarm", 0, NULL, "QFLAG\r", "", 4, '(', "", 1, 0, "%s", QX_FLAG_SEMI_STATIC | QX_FLAG_NONUT, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability }, { "experimental.battery_alarm", 0, NULL, "QFLAG\r", "", 4, '(', "", 1, 0, "%s", QX_FLAG_SEMI_STATIC | QX_FLAG_NONUT, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability }, #endif /* TESTING_AXPERT_CAPS_QUERY */ #if TESTING_AXPERT_CAPS_CHANGE /* Enable or Disable or Reset to safe default values capability options * > [PEX\r] > [PDX\r] > [PF\r] * < [(ACK\r] < [(ACK\r] < [(ACK\r] * 01234 01234 01234 * 0 0 0 */ { "battery.energysave", 0, voltronic_axpert_e_cap, "P%sJ\r", "", 5, '(', "", 1, 3, NULL, QX_FLAG_SETVAR | QX_FLAG_ENUM | QX_FLAG_SKIP, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability_set }, /* Not available in NUT */ { "experimental.reset_to_default", 0, NULL, "PF\r", "", 5, '(', "", 1, 3, NULL, QX_FLAG_SETVAR | QX_FLAG_NONUT, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability_reset }, /* FIXME: ups_status BYPASS and RB(?) */ { "experimental.bypass_alarm", 0, voltronic_axpert_e_cap_nonut, "P%sP\r", "", 5, '(', "", 1, 3, NULL, QX_FLAG_SETVAR | QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SKIP, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability_set_nonut }, { "experimental.battery_alarm", 0, voltronic_axpert_e_cap_nonut, "P%sB\r", "", 5, '(', "", 1, 3, NULL, QX_FLAG_SETVAR | QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SKIP, voltronic_axpert_crc, voltronic_axpert_checkcrc, voltronic_axpert_capability_set_nonut }, #endif /* TESTING_AXPERT_CAPS_CHANGE */ #if TESTING_AXPERT_OPERATIONAL_OPTIONS_QUERY_CHANGE /* Query device for operational options flag (P16 only) * > [QENF\r] * < [(A1B1C1D1E1F0G1\r] <- required options (length: 16) * < [(A1B0C1D0E1F0G0H0I_J_\r] <- known available options * 0123456789012345678901 * 0 1 2 */ { "experimental.charge_battery", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 16, '(', "", 2, 2, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, /* A */ { "experimental.charge_battery_from_ac", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 16, '(', "", 4, 4, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, /* B */ { "experimental.feed_grid", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 16, '(', "", 6, 6, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, /* C */ { "experimental.discharge_battery_when_pv_on", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 16, '(', "", 8, 8, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, /* D */ { "experimental.discharge_battery_when_pv_off", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 16, '(', "", 10, 10, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, /* E */ { "experimental.feed_grid_from_battery_when_pv_on", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 16, '(', "", 12, 12, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, /* F */ { "experimental.feed_grid_from_battery_when_pv_off", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 16, '(', "", 14, 14, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, /* G */ /* { "unknown.?", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 18, '(', "", 16, 16, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, *//* H */ /* { "unknown.?", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 20, '(', "", 18, 18, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, *//* I */ /* { "unknown.?", ST_FLAG_RW, voltronic_axpert_e_cap_nonut, "QENF\r", "", 22, '(', "", 20, 20, "%s", QX_FLAG_ENUM | QX_FLAG_NONUT | QX_FLAG_SEMI_STATIC, NULL, voltronic_axpert_checkcrc, voltronic_sunny_01 }, *//* J */ /* Enable (: 1) or disable (: 0) operational option