midrange.com code scratchpad
Name:
UPSSTATUS
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
05/22/2015 05:23:03 pm
IP:
Logged
Description:
Code to get UPS and other info for IBM i V7R1.
Code:
  1.      h
  2.      hdftactgrp(*no)
  3.      d MatMAtr         pr                  extproc('_MATMATR1')
  4.      d RcvVar                         1a   options(*varsize)
  5.      d Format                         2a   const
  6.  
  7.      d MchInfo         ds                  qualified
  8.      d BytPrv                        10i 0 inz(%size(MchInfo))
  9.      d BytAvl                        10i 0
  10.      d SrlNbr                         8a
  11.  
  12.      d MchUPS          ds                  qualified
  13.      d BytPrv                        10i 0 inz(%size(MchUPS))
  14.      d BytAvl                        10i 0
  15.      d CurrIPLType                    1a
  16.      d PanelStatus1                   1a
  17.      d PanelStatus2                   1a
  18.      d Reserved5                      5a
  19.      d MostRecentIPLType...
  20.      d                                1a
  21.       /free
  22.  
  23.        MatMatr(MchInfo :x'0004');
  24.        dsply ('Serial number . . . ' + MchInfo.SrlNbr);
  25.  
  26.        MatMatr(MchUPS :x'0168');
  27.  
  28.        TestBytes(MchUPS.PanelStatus1);
  29.  
  30.        *inlr = *on;
  31.        return;
  32.       /end-free
  33.  
  34.      P TestBytes       B
  35.  
  36.      D TestBytes       PI
  37.      D  Hexval                        1    CONST
  38.  
  39.       *- Bitwise processing from bmeyers...
  40.       *--http://www.bmeyers.net/
  41.       *--  faqs/15-faqs/55-using-bitand-to-test-bits
  42.       *
  43.           // ---------------------------------------- Constants
  44.           // Bit0 = 10000000
  45.           // Bit1 = 01000000
  46.           // Bit2 = 00100000
  47.           // Bit3 = 00010000
  48.           // Bit4 = 00001000
  49.           // Bit5 = 00000100
  50.           // Bit6 = 00000010
  51.           // Bit7 = 00000001
  52.  
  53.      D Bit0            C                   X'80'
  54.      D Bit1            C                   X'40'
  55.      D Bit2            C                   X'20'
  56.      D Bit3            C                   X'10'
  57.      D Bit4            C                   X'08'
  58.      D Bit5            C                   X'04'
  59.      D Bit6            C                   X'02'
  60.      D Bit7            C                   X'01'
  61.  
  62.       /Free
  63.           // My notes...
  64.           // Bit0 = hex '80' = '1000 0000'
  65.           // Bit1 = hex '40' = '0100 0000'
  66.           // Bit2 = hex '20' = '0010 0000'
  67.           // Bit3 = hex '10' = '0001 0000'
  68.           // Bit4 = hex '08' = '0000 1000'
  69.           // Bit5 = hex '04' = '0000 0100'
  70.           // Bit6 = hex '02' = '0000 0010'
  71.           // Bit7 = hex '01' = '0000 0001'
  72.           // If %bitand(Hexval:Bit0) = Bit0 will
  73.           //  be true if the first bit of the parm coming
  74.           //  in is a '1'.  All other bits will be 0
  75.           //  in the result because Bit0 has only 0's
  76.           //  in all other bits. The only way the
  77.           // resulting bits can be '1' is if both the
  78.           // incoming field and the base field have a '1'
  79.           // in the same bit.
  80.           // So %bitand('10101010':'10000000') = '10000000' is
  81.           // true. %bitand('00010101':'10000000') = '10000000' is
  82.           // false
  83.  
  84.           // Uninterrupted power supply installed
  85.           If %Bitand(Hexval:Bit0) = Bit0;
  86.             Dsply ('Bit 0 is *On:  UPS is Attached');
  87.           Else;
  88.             Dsply ('Bit 0 is *Off: UPS is NOT Attached');
  89.           Endif;
  90.  
  91.           // Utility power failed, running on UPS
  92.           If %Bitand(Hexval:Bit1) = Bit1;
  93.             Dsply 'Bit 1 is *On:  Utility power failed, running on UPS';
  94.           Else;
  95.             Dsply 'Bit 1 is *Off: Running on Utility power';
  96.           Endif;
  97.  
  98.           // Uninterrupted power supply (UPS) bypass active
  99.           If %Bitand(Hexval:Bit2) = Bit2;
  100.             Dsply 'Bit 2 is *On:  UPS bypass active';
  101.           Else;
  102.             Dsply 'Bit 2 is *Off: UPS bypass NOT active';
  103.           Endif;
  104.  
  105.           // Uninterrupted power supply (UPS) battery low
  106.           If %Bitand(Hexval:Bit3) = Bit3;
  107.             Dsply 'Bit 3 is *On:  UPS battery low';
  108.           Else;
  109.             Dsply 'Bit 3 is *Off: UPS battery NOT low';
  110.           Endif;
  111.  
  112.           // Auto key mode
  113.           If %Bitand(Hexval:Bit4) = Bit4;
  114.             Dsply 'Bit 4 is *On:  Key mode is Auto';
  115.           Else;
  116.             Dsply 'Bit 4 is *Off: Key mode in NOT Auto';
  117.           Endif;
  118.  
  119.           // Normal key mode
  120.           If %Bitand(Hexval:Bit5) = Bit5;
  121.             Dsply 'Bit 5 is *On:  Normal key mode';
  122.           Else;
  123.             Dsply 'Bit 5 is *Off: NOT Normal key mode';
  124.           Endif;
  125.  
  126.           // Manual key mode
  127.           If %Bitand(Hexval:Bit6) = Bit6;
  128.             Dsply 'Bit 6 is *On:  Manual key mode';
  129.           Else;
  130.             Dsply 'Bit 6 is *Off: NOT Manual key mode';
  131.           Endif;
  132.  
  133.           // Secure key mode
  134.           If %Bitand(Hexval:Bit7) = Bit7;
  135.             Dsply 'Bit 7 is *On:  Secure key mode';
  136.           Else;
  137.             Dsply 'Bit 7 is *Off: NOT Secure key mode';
  138.           Endif;
  139.  
  140.           Return;
  141.       /End-free
  142.      P TestBytes       e
  143.  
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css