home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pwrprt.zip / X10.CMD < prev   
OS/2 REXX Batch file  |  1994-12-18  |  7KB  |  245 lines

  1. /*-----------------------------------------------------------+
  2. | X10 Control Program
  3. | (C)opyright 1994, Arthur F. Tyde III
  4. |
  5. +-----------------------------------------------------------*/
  6. Signal on Syntax
  7. Signal On Novalue
  8. Signal on Halt
  9.  
  10. Version = '.01'
  11. Parse upper Arg House_Code Unit_Code Command level
  12. if house_code<>'' then do
  13.    Call Init
  14.    '@MODE' X10_Port':600,n,8,1 >NUL'
  15.    If Rc = 0 Then Do
  16.      Call X10_Direct House_Code,Unit_Code,Command,Level
  17.    End
  18.    Else
  19.      Say 'Error' rc 'from MODE.'
  20.  
  21. end
  22. else do
  23.    say
  24.    say '-> Syntax Error: X10 HC UC (ON/OFF/DIM) LEVEL'
  25. end
  26.  
  27. Bailout:
  28. call stream X10_Port,'C','CLOSE'
  29. Exit
  30.  
  31. Init:
  32.   X10_Port = 'COM2'
  33.   X10_Ack = Copies('FF'x,6)'01'x
  34.   X10_Header= Copies('FF'X,16)
  35.   Unit_code.1  = '0000000010000000'b
  36.   Unit_code.2  = '0000000001000000'b
  37.   Unit_code.3  = '0000000000100000'b
  38.   Unit_code.4  = '0000000000010000'b
  39.   Unit_code.5  = '0000000000001000'b
  40.   Unit_code.6  = '0000000000000100'b
  41.   Unit_code.7  = '0000000000000010'b
  42.   Unit_code.8  = '0000000000000001'b
  43.   Unit_code.9  = '1000000000000000'b
  44.   Unit_code.10 = '0100000000000000'b
  45.   Unit_code.11 = '0010000000000000'b
  46.   Unit_code.12 = '0001000000000000'b
  47.   Unit_code.13 = '0000100000000000'b
  48.   Unit_code.14 = '0000010000000000'b
  49.   Unit_code.15 = '0000001000000000'b
  50.   Unit_code.16 = '0000000100000000'b
  51.   X10_HouseCode.A = '60'x
  52.   X10_HouseCode.B = 'E0'x
  53.   X10_HouseCode.C = '20'x
  54.   X10_HouseCode.D = 'A0'x
  55.   X10_HouseCode.E = '10'x
  56.   X10_HouseCode.F = '90'x
  57.   X10_HouseCode.G = '50'x
  58.   X10_HouseCode.H = 'D0'x
  59.   X10_HouseCode.I = '70'x
  60.   X10_HouseCode.J = 'F0'x
  61.   X10_HouseCode.K = '30'x
  62.   X10_HouseCode.L = 'B0'x
  63.   X10_HouseCode.M = '00'x
  64.   X10_HouseCode.N = '80'x
  65.   X10_HouseCode.O = '40'x
  66.   X10_HouseCode.P = 'C0'x
  67.   X10_Function_code.ON  = '00000010'b
  68.   X10_Function_code.OFF = '00000011'b
  69.   X10_Function_code.DIM = '00000101'b
  70.   X10_Level.1  = '11110000'b
  71.   X10_Level.2  = '11100000'b
  72.   X10_Level.3  = '11010000'b
  73.   X10_Level.4  = '11000000'b
  74.   X10_Level.5  = '10110000'b
  75.   X10_Level.6  = '10100000'b
  76.   X10_Level.7  = '10010000'b
  77.   X10_Level.8  = '10000000'b
  78.   X10_Level.9  = '01110000'b
  79.   X10_Level.10 = '01100000'b
  80.   X10_Level.11 = '01010000'b
  81.   X10_Level.12 = '01000000'b
  82.   X10_Level.13 = '00110000'b
  83.   X10_Level.14 = '00100000'b
  84.   X10_Level.15 = '00010000'b
  85.   X10_Level.16 = '00000000'b
  86. Return
  87.  
  88. X10_Direct:
  89.   Parse Arg HouseCode,Unit_list,Command,Level
  90.   If Level = '' Then Level = 16
  91.   X10_Cmd = '01'x
  92.   X10_Function = X10_Function_Code.Command
  93.   X10_Level_Function = Bitor(X10_Function,X10_Level.Level)
  94.   X10_Unit_codes = X10_Units(Unit_list)
  95.  
  96.   Checksum = Right(D2C(C2D(x10_level_function),
  97.     +C2D(X10_housecode.HouseCode)+C2D(X10_unit_codes)),1)
  98.  
  99.   X10_Cmd_String = X10_Header||X10_Cmd||X10_Level_Function||,
  100.     X10_HouseCode.Housecode||X10_Unit_Codes||Checksum
  101.  
  102.   Call Charout X10_Port,X10_Cmd_String
  103.   If X10_Ack() \= X10_Ack Then Do
  104.     Say 'EEK'
  105.   End
  106. Return
  107.  
  108. /*-----------------------------------------------------------+
  109. | X10_Ack - Receive ACK from CP290
  110. +-----------------------------------------------------------*/
  111. X10_Ack:
  112.   Ack_msg = ''
  113.   Do qqx = 1 to 7
  114.     New_Char = Charin(X10_Port)
  115.     If New_Char \= '' Then
  116.       Ack_msg = Ack_msg || New_Char
  117.     Else
  118.       Leave
  119.   End
  120. Return Ack_msg
  121.  
  122. /*-----------------------------------------------------------+
  123. | X10_Units: - Construct the Unit Bitmap from a list of Units
  124. |
  125. +-----------------------------------------------------------*/
  126. X10_units:
  127.   Procedure Expose Unit_Code.
  128.   Parse Arg unit_list
  129.   Unit_bits = '0000'x
  130.   Do qqx = 1 To Words(Unit_list)
  131.     Unit = Word(Unit_list,qqx)
  132.     Unit_bits = bitor(Unit_bits,Unit_Code.unit)
  133.   End
  134. Return Unit_bits
  135.  
  136. /*-----------------------------------------------------------------+
  137. |  Exception Handlers for intercepting Rexx errors.                |
  138. +-----------------------------------------------------------------*/
  139. Failure:
  140. Novalue:
  141. Error:
  142. Syntax:
  143. Halt:
  144.   Trace 'O'
  145.   Signal Off Failure
  146.   Signal Off Novalue
  147.   Signal Off Error
  148.   Signal Off Syntax
  149.   Signal Off Halt
  150.   Rexx_err = Condition('Condition')
  151.   Rexxline = Sigl
  152.   Fault = ''
  153.   Select
  154.     When Rexx_err = 'NOVALUE' Then Do
  155.       /*------------------------------------------------------------+
  156.       |  A Rexx NOVALUE Error has been detected.
  157.       +------------------------------------------------------------*/
  158.       Fault=Condition('Description')
  159.       Call Show_error
  160.       Call Log_it 'Rexx Novalue Error for:' Fault
  161.     End
  162.     When Rexx_err = 'ERROR' | Rexx_err = 'FAILURE' Then Do
  163.       /*------------------------------------------------------------+
  164.       |  A System Error or Failure as been detected.
  165.       +------------------------------------------------------------*/
  166.       Call Show_Error
  167.       Call Log_it 'System Returned' Rc,
  168.         'Executing:' Condition('Description')
  169.     End
  170.     When Rexx_err = 'SYNTAX' Then Do
  171.       /*------------------------------------------------------------+
  172.       |  A Rexx Syntax Error has been detected.
  173.       +------------------------------------------------------------*/
  174.       Call Show_Error
  175.       Call Log_it "REXX Error Message is:" Errortext(RC)
  176.     End
  177.     When Rexx_err = 'HALT' Then Do
  178.       Call Show_Error
  179.       Call Log_it "REXX interpreter Halted."
  180.     End
  181.     Otherwise
  182.   End
  183.   If Condition('Status') = 'DELAY' Then Return
  184.   Else Signal bailout
  185.  
  186. Show_error:
  187.   lc = 'abcdefghijklmnopqrstuvwxyz'
  188.   uc = Translate(lc)
  189.   special = '.!$_0123456789'
  190.   Parse Value 0 With,
  191.     1 in_sigl,
  192.     1 Line_disp,
  193.     1 Done
  194.  
  195.   Parse Value '5 5' With Top_disp Bot_disp
  196.   Parse Source . . Prgname
  197.   Call Log_it 'Rexx' Rexx_err 'error on line' rexxline 'of' Prgname
  198.   Do Sline = Max(RexxLine-Top_disp,1) By 1 Until Done
  199.      If Sline = Rexxline | in_sigl Then Do
  200.        Prefix = '>'
  201.        In_sigl = Right(Sourceline(sline),1)=','
  202.        Line_disp = 1
  203.      End
  204.      Else Do
  205.        Prefix = ' '
  206.        If Line_disp Then Do
  207.          Vars_displayed. = 0
  208.          Line_disp = 0
  209.          Call Log_it '      ---Variable Display---'
  210.          Do Bline = rexxline By 1,
  211.            Until Right(Sourceline(Bline),1)\=','
  212.  
  213.            VLine = Translate(Sourceline(Bline), uc||lc||special,,
  214.              uc||lc||Special||Xrange('00'x,'FF'x))
  215.              Do While VLine <> ''
  216.                Parse Value VLine With VWord VLine
  217.                If Symbol(Vword) = 'VAR' Then Do
  218.                  /*------------------------------------------------+
  219.                  | Display the Variable if:
  220.                  |   a) It is not the variable that raised Novalue
  221.                  |   b) It has not already been displayed
  222.                  +------------------------------------------------*/
  223.                  If Vword\=Fault & \Vars_displayed.vword Then Do
  224.                    NLine = VWord '=' Value(VWord)
  225.                    Vars_displayed.vword = 1
  226.                    Call Log_it '      'Nline
  227.                  End
  228.                End
  229.              End
  230.           End
  231.           If Fault \= '' Then
  232.             Call Log_it '      'fault' = ** No Value **'
  233.           Call Log_it '      ----------------------'
  234.        End
  235.      End
  236.      Call Log_it Right(Sline,5)prefix Sourceline(sline)
  237.      Done = Sline > Rexxline + Bot_disp | Sline > Sourceline()
  238.   End
  239. Return
  240.  
  241. Log_it:
  242.   Parse Arg text
  243.   Say text
  244. Return
  245.