From: Piet D. <pi...@ww...> - 2002-12-24 13:35:27
|
On Mon, 2002-12-23 at 21:59, Bruce Winter wrote: > > I checked out CPAN but don't get it. It's difficult to find the x-10 > > perl code. Could you enlighten me on the signficance of this. Is it > > similar to getting a driver into the linux kernel? > > CPAN simply has a copy of the same CM11 we have in mh. CPAN has nothing to > do with the linux kernel, it is simply a repository of perl code. I was just wondering what the significance is of the code being on CPAN. I though it might be analogous to a driver being at www.kernel.org. > You are welcome to try to patch up CM11 to make it work. It probably isn't > the best task to start learning perl on :) Rather than run it via mh, where > it may take a while to test changes, consider using something like > bin/test_x10. It is setup to run on either windows or linux, and just sends > out a few test X10 commands. I'll check that out. I've got misterhouse-2.74/code/test/test_x10.mht working with misterhouse-2.74/lib/Serial_Item.pm and misterhouse-2.74/lib/site/ControlX10/CM11.pm to monitor the x-10 events involved with the control of scenes: ------------------------------------------------------------------------------ 12/24/02 05:07:00 AM Light set to off 12/24/02 05:07:30 AM Light set to on 12/24/02 05:07:45 AM XAZ062636: test_scene1 manual 12/24/02 05:07:48 AM XAZ066636: test_scene2 manual 12/24/02 05:07:49 AM XAZ06a636: test_scene3 manual 12/24/02 05:07:50 AM XAZ06e636: test_scene4 manual 12/24/02 05:07:51 AM XAZ062e36: test_scene5 manual 12/24/02 05:07:53 AM XAZ066e36: test_scene6 manual 12/24/02 05:07:54 AM XAZ06ae36: test_scene7 manual 12/24/02 05:07:55 AM XAZ06be36: test_scene_off manual 12/24/02 05:07:56 AM XAZ06ae3c: test_scene7_dim manual 12/24/02 05:07:58 AM XAZ06be3c: test_scene7_bright manual ------------------------------------------------------------------------------ Also with the web interface I'm able to establish a scene: ------------------------------------------------------------------------------- Reading html icons from ./../web/graphics 12/24/02 05:09:40 AM XAZ06ac38: test_scene1_event manual 12/24/02 05:09:47 AM XAZ068c38: test_scene2_event manual 12/24/02 05:09:50 AM XAZ068a38: test_scene368_event manual 12/24/02 05:09:54 AM XAZ068a38: test_scene368_event manual 12/24/02 05:09:57 AM XAZ06be38: test_scene5_event manual ------------------------------------------------------------------------------- For testing the Leviton gear I've hardcoded the scene commands in test_x10.mht: -------------------------------------------------------------------------------- X10I, A1, test_light1, All_Lights|Test X10I, A2, test_light2, All_Lights|Test # X10I, AZ062636, test_scene1, All_Lights|Test X10I, AZ066636, test_scene2, All_Lights|Test X10I, AZ06a636, test_scene3, All_Lights|Test X10I, AZ06e636, test_scene4, All_Lights|Test X10I, AZ062e36, test_scene5, All_Lights|Test X10I, AZ066e36, test_scene6, All_Lights|Test X10I, AZ06ae36, test_scene7, All_Lights|Test X10I, AZ06be36, test_scene_off, All_Lights|Test # X10I, AZ06263c, test_scene1_dim, All_Lights|Test X10I, AZ06663c, test_scene2_dim, All_Lights|Test X10I, AZ06a63c, test_scene3_dim, All_Lights|Test X10I, AZ06e63c, test_scene4_dim, All_Lights|Test X10I, AZ062e3c, test_scene5_dim, All_Lights|Test X10I, AZ066e3c, test_scene6_dim, All_Lights|Test X10I, AZ06ae3c, test_scene7_dim, All_Lights|Test # X10I, AZ06363c, test_scene1_bright, All_Lights|Test X10I, AZ06763c, test_scene2_bright, All_Lights|Test X10I, AZ06b63c, test_scene3_bright, All_Lights|Test X10I, AZ06f63c, test_scene4_bright, All_Lights|Test X10I, AZ063e3c, test_scene5_bright, All_Lights|Test X10I, AZ067e3c, test_scene6_bright, All_Lights|Test X10I, AZ06be3c, test_scene7_bright, All_Lights|Test # X10I, AZ06ac38, test_scene1_event, All_Lights|Test X10I, AZ068c38, test_scene2_event, All_Lights|Test X10I, AZ068a38, test_scene368_event, All_Lights|Test X10I, AZ06be38, test_scene5_event, All_Lights|Test # X10I, AZ0ea630AZ6a, test_scene3_set, All_Lights|Test X10I, AZ0ee630AZ6e, test_scene4_set, All_Lights|Test X10I, AZ0eae30AZ6a, test_scene7_set, All_Lights|Test # --------------------------------------------------------------------------------- Change in Serial_Item.pm is very small: ---------------------------------------------------------------------------------- # diff -c Serial_Item.pm Serial_Item.pm.Orig *** Serial_Item.pm 2002-12-24 04:53:46.000000000 -0800 --- Serial_Item.pm.Orig 2002-10-12 18:08:00.000000000 -0700 *************** *** 272,279 **** $serial_data =~ /^([A-P]PRESET_DIM2)(\S*)/ or $serial_data =~ /^([A-P][1][0-6])(\S*)/ or $serial_data =~ /^([A-P][1-9A-W])(\S*)/ or $serial_data =~ /^([A-P]\&P\d+)(\S*)/ or + $serial_data =~ /^([A-P]Z\S*)/ or $serial_data =~ /^([A-P]\d+\%)(\S*)/ or $serial_data =~ /^([A-P][\+\-]?\d+)(\S*)/) { $serial_chunk = $1; --- 272,278 ---- $serial_data =~ /^([A-P]PRESET_DIM2)(\S*)/ or $serial_data =~ /^([A-P][1][0-6])(\S*)/ or $serial_data =~ /^([A-P][1-9A-W])(\S*)/ or $serial_data =~ /^([A-P]\&P\d+)(\S*)/ or $serial_data =~ /^([A-P]\d+\%)(\S*)/ or $serial_data =~ /^([A-P][\+\-]?\d+)(\S*)/) { $serial_chunk = $1; *************** ---------------------------------------------------------------------------------- The change in CM11.pm has a new block of code to parse the extended codes. Currently it's not very different than the preset code. To get scenes acting as scenes instead like lights I think will likely need a lot more change: ------------------------------------------------------------------------------------- CM11.pm CM11.pm.~2.15.~ CM11.pm.new CM11.pm.Orig CM11.pm.piet CM11.txt CM17.pm CM17.pm.old CM17.txt CVS [root@www ControlX10]# diff -c CM11.pm CM11.pm.Orig *** CM11.pm 2002-12-24 02:17:34.000000000 -0800 --- CM11.pm.Orig 2002-11-09 17:59:58.000000000 -0800 *************** *** 25,31 **** #### Package variable declarations #### ($VERSION) = q$Revision: 2.17 $ =~ /: (\S+)/; # Note: cvs version reset when we moved to sourceforge ! $DEBUG = 1; my $Last_Dcode; sub send_cm11 { --- 25,31 ---- #### Package variable declarations #### ($VERSION) = q$Revision: 2.17 $ =~ /: (\S+)/; # Note: cvs version reset when we moved to sourceforge ! $DEBUG = 0; my $Last_Dcode; sub send_cm11 { *************** *** 172,185 **** # d_xyz. for Extended code xyz for device d # xyz for Function codes, including +-## for bright/dim ! # Test for extended codes: ! # - format is: ! # Z###### for extended code 1 cmds (Ex: Z062636) ! # &P## where ## is the preset dim level (extended code 2 or 3) ! # ! my($extended_data) = $code =~ /Z(\d+)/; ! if ($extended_data) { ! $code_bits = '0111'; # Extended code $function = '1'; # Extended transmitions are a function $extended = '1'; --- 172,184 ---- # d_xyz. for Extended code xyz for device d # xyz for Function codes, including +-## for bright/dim ! # Test for extended code ! # - format is &P## where ## is the preset dim level ! if (my($extended_data) = $code =~ /&P(\d+)/) { ! unless (($extended_data >= 0) && ($extended_data < 65)) { ! print "CM11 error, invalid extended code. code=$code\n"; ! return; ! } $code_bits = '0111'; # Extended code $function = '1'; # Extended transmitions are a function $extended = '1'; *************** *** 207,274 **** $extended_data, $b3c, $b4c, $b5c, $extended_string, $extended_checksum; } ! } else { ! my($extended_data) = $code =~ /&P(\d+)/; ! if ($extended_data) { ! ! unless (($extended_data >= 0) && ($extended_data < 65)) { ! print "CM11 error, invalid extended code. code=$code\n"; ! return; ! } ! $code_bits = '0111'; # Extended code ! $function = '1'; # Extended transmitions are a function ! $extended = '1'; ! $dim_level = 0; # Dim level is not applicable to extended transmitions. ! ! # Hard codeded preset for now ... ! ! # This is not documented!! By looking at ! # ActiveHome errata, it seems the device code is required ! # - $Last_Dcode is a hack ... assume previous selected device. ! my $extended_device = '0000' . $table_dcodes{$Last_Dcode}; ! my $extended_code = '00110001'; # Type=3 => Control Modules Func=1 => Preset Receiver ! ! # Convert from bit to string ! my $b3 = pack('B8', $extended_device); ! my $b4 = pack('C1', $extended_data); ! my $b5 = pack('B8', $extended_code); ! $extended_string = $b3 . $b4 . $b5; ! my $b3c = unpack('C', $b3); ! my $b4c = unpack('C', $b4); ! my $b5c = unpack('C', $b5); ! $extended_checksum = $b3c + $b4c + $b5c; ! if ($DEBUG) { ! printf "CM11 ed=%d, b345=0x%0.2x,0x%0.2x,0x%0.2x ex=%s cs=0x%0.2x\n", ! $extended_data, $b3c, $b4c, $b5c, $extended_string, ! $extended_checksum; ! } ! } # Test for device code ! elsif ($code_bits = $table_dcodes{$code}) { ! $function = '0'; ! $extended = '0'; ! $dim_level = 0; ! $Last_Dcode = $code; # This is desperate :) } ! # Test for function code ! elsif ($code_bits = $table_fcodes{$code}) { ! $function = '1'; ! $extended = '0'; ! if ($code eq 'DIM' or $code eq 'M' or $code eq 'BRIGHT' or $code eq 'L') { ! $dim_level = 34; # Lets default to 3 bight/dims to go full swing ! } ! elsif ($code =~ /^[+-]\d\d$/) { ! $dim_level = abs($code); ! } ! else { ! $dim_level = 0; ! } } else { ! print "CM11 error, invalid cm11 x10 code: $code\n"; ! return; } } my $dim = int($dim_level * 22 / 100); # 22 levels = 100% $header = substr(unpack('B8', pack('C', $dim)), 3); --- 206,237 ---- $extended_data, $b3c, $b4c, $b5c, $extended_string, $extended_checksum; } ! } # Test for device code ! elsif ($code_bits = $table_dcodes{$code}) { ! $function = '0'; ! $extended = '0'; ! $dim_level = 0; ! $Last_Dcode = $code; # This is desperate :) ! } ! # Test for function code ! elsif ($code_bits = $table_fcodes{$code}) { ! $function = '1'; ! $extended = '0'; ! if ($code eq 'DIM' or $code eq 'M' or $code eq 'BRIGHT' or $code eq 'L') { ! $dim_level = 34; # Lets default to 3 bight/dims to go full swing } ! elsif ($code =~ /^[+-]\d\d$/) { ! $dim_level = abs($code); } else { ! $dim_level = 0; } } + else { + print "CM11 error, invalid cm11 x10 code: $code\n"; + return; + } my $dim = int($dim_level * 22 / 100); # 22 levels = 100% $header = substr(unpack('B8', pack('C', $dim)), 3); *************** ------------------------------------------------------------------------------------- It's not a bad as it looks. I indented a block of code to make it easy to see what was going on with $extended_data. I replicated the block: if (my($extended_data) = $code =~ /&P(\d+)/) { . . . } and broke the if statement into two statements so I could see extended_data with ddd. I walked thru the parsing and preparation for going to the cm11 but it's still not clear to me. I'll leave my stuff running at www.piet.net:8080 in case you feel like trying out the test function. I think the various scenes should be state changes to a single button. Whereas lights have states: on off +40 -40 5% 30% 60% 100% I suppose a scene controller might be at a specific scene and perhaps the percentage could be remembered and/or the status taken. Any thoughts? -piet -- pi...@ww... |