From: Jon W. <jo...@wh...> - 2013-11-22 00:57:51
|
Kevin, Thanks. That put me on the right path. It looks like CGate used to return an address in the format //PROJECT/NETWORK/APPLICATION/GROUP, whereas now (at least for message code 342) it’s returning NETWORK/APPLICATION/GROUP. I’ve changed the regex to match against that format, and then added the project name back into the address like so - if ($cbus_data =~ /(\/\/.+\/\d+\/[a-z\d]+\/\d+)\/TagName=(.+)/) { + if ($cbus_data =~ /\d+\s+(\d+\/[a-z\d]+\/\d+)\/TagName=(.+)/) { my ($addr, $name) = ($1, $2); + $addr = "//$cbus_project_name/$addr”; That seems to have done the job. I’ve now got my CBus lights working with misterhouse. Thanks for putting me on the right track! Here’s a diff, in case you want to update the version of cbus.pl in git. Note that the changes are mostly just comments and log statements (and fixing a couple of typos.) The cbus.xml definition file that this produces includes the “dummy” group defined in the code - I had to clean that up before running “cbus builder run”. I don’t know whether or not that was a problem in the previous version. In other words, my process was: cbus builder scan cgate clean up the xml file cbus builder run reload code Cheers, Jon --- misterhouse/code/public/cbus.pl 2013-11-17 18:29:09.305099777 +1100 +++ local/code/cbus.pl 2013-11-22 11:34:52.750756230 +1100 @@ -84,6 +84,9 @@ # Changed DEV to DEBUG for commonality. # Monitor and Talker attempt to always run unless in DEBUG state. # +# V3.0.1 2013-11-22 +# Fixed to work with C-Gate Version: v2.9.7 (build 2569) +# Add logging to aid debugging cbus_builder # # How Cgate integrates with MH # @@ -153,7 +156,7 @@ ############################################################################## ############################################################################## ########### ############## -########### Globals, Startup, Menus, Voice COmmands ############## +########### Globals, Startup, Menus, Voice Commands ############## ########### ############## ############################################################################## ############################################################################## @@ -261,9 +264,9 @@ if ($data eq 'Run') { load_def_file(); if (not defined $cbus_def) { - # Their was no cbus def file to load. + # There was no cbus def file to load. # Help out a new user, by auto-building the def file. - # Otherwise, their will be nothing to build. + # Otherwise, there will be nothing to build. print_log "CBus: Builder is initiating scan of CGate"; scan_cgate(); } @@ -315,11 +318,11 @@ $cbus_def_filename = $config_parms{code_dir} . "/" . $config_parms{cbus_dat_file}; if (not -e $cbus_def_filename) { - print_log "CBus: Definition file $cbus_def_filename does not exist"; + print_log "CBus: [load_def_file] XML definition file $cbus_def_filename does not exist"; return; } - print_log "CBus: Builder - Loading CBus config from file ". + print_log "CBus: Builder - Loading CBus config from XML file ". $cbus_def_filename; $cbus_def = XMLin($cbus_def_filename, ForceArray => ['mh_group', 'note'], @@ -330,7 +333,7 @@ delete $cbus_def->{'Creation_Date'}; delete $cbus_def->{'Version'}; - # print_log Dumper($cbus_def); + #print_log Dumper($cbus_def); } @@ -355,7 +358,7 @@ sub scan_cgate { # Initiate scan of CGate data # The scan is controlled by code in the Talker mh main loop code - print_log "CBus: Scanning CGate..."; + print_log "CBus: [scan_cgate] Scanning CGate..."; # Cleanup from any previous scan and initialise flags/counters @cbus_net_list = [ ]; @@ -423,12 +426,16 @@ ); # Write the file to disk + print_log "CBus: [write_def_file] Writing XML definition to $cbus_def_filename,"; $xml_file->XMLout($cbus_def, OutputFile => $cbus_def_filename, ); } -#sub dump_cbus_data { +sub dump_cbus_data { + + print_log CBus: "Device list function disabled"; + # # Basic diagnostic routine for dumping the cbus objects hash # my $count = 0; # my $msg = "<H2>CBUS Device Listing</H2><HR>"; @@ -448,7 +455,7 @@ # # $msg .= "<HR><p>List CBus Devices: Listed $count CBus devices<p>"; # display $msg; -#} +} # @@ -1058,6 +1065,8 @@ $msg_code = $2; } +###### Message code 320: Tree information. Returned from the tree command. + if ($msg_code == 320) { if (not $cbus_got_tree_list) { if (not $cbus_units_config) { @@ -1073,6 +1082,7 @@ } else { # CGate is listing CBus "groups" if ($cbus_data =~ /end/) { + print_log "CBus: end of CBus scan data, got tree list"; $cbus_got_tree_list = 1; } elsif ($cbus_data =~ /(\/\/.+\/\d+\/\d+\/\d+).+level=(\d+)/) { print_log "CBus: scanned group=$1 at level $2"; @@ -1082,17 +1092,24 @@ } } +###### Message code 342: DBGet response (not documented in CGate Server Guide 1.0. + } elsif ($msg_code == 342) { - if ($cbus_scanning_cgate) { - if ($cbus_data =~ /(\/\/.+\/\d+\/[a-z\d]+\/\d+)\/TagName=(.+)/) { + if ($cbus_scanning_cgate) { + + print_log "CBus: Message 342 response data: $cbus_data"; + + if ($cbus_data =~ /\d+\s+(\d+\/[a-z\d]+\/\d+)\/TagName=(.+)/) { my ($addr, $name) = ($1, $2); + $addr = "//$cbus_project_name/$addr"; + print_log "CBus: Address $addr, name $name"; $cbus_scan_last_addr_seen = $addr; - # $name =~ s/ /_/g; Change spaces, depends on user usage... + # $name =~ s/ /_/g; Change spaces, depends on user usage... my $addr_type; if ($addr =~ /\/p\/(\d+)/) { # Data is for a CBus device eg. switch, relay, dimmer - $addr_type = 'unit'; + $addr_type = 'unit'; $addr = $1; } else { # Data is for a CBus "group" @@ -1124,9 +1141,12 @@ }; } } + print_log "Cbus: end message"; } - } - + } + +###### Message code 300: Object information, for example: 300 1/56/1: level=200 + } elsif ($msg_code == 300) { if ($cbus_data =~ /(sessionID=.+)/) { @@ -1181,9 +1201,13 @@ print_log "CBus: UNEXPECTED 300 msg \"$cbus_data\""; } +###### Message code 200: Completed successfully + } elsif ($msg_code == 200) { print_log "CBus: Cmd OK - $cbus_data" if $Debug{cbus}; +###### Message code 201: Service ready + } elsif ($msg_code == 201) { print_log "CBus: Comms established - $cbus_data"; @@ -1204,9 +1228,14 @@ eval_with_timer $cmd, 2; } +###### Message code 401: Bad object or device ID + } elsif ($msg_code == 401) { print_log "CBus: $cbus_data"; +###### Message code 408: Indicates that a SET, GET or other method +###### failed for a given object + } elsif ($msg_code == 408) { print_log "CBus: **** Failed Cmd - $cbus_data"; if ($msg_id =~ /\[MisterHouse(\d+)\]/) { @@ -1221,6 +1250,8 @@ } } +###### Message code unhandled + } else { print_log "CBus: Cmd port - UNHANDLED: $cbus_data"; } @@ -1251,6 +1282,7 @@ } else { # All networks scanned - set completion flag ### FIXME - RichardM test with two networks?? + print_log "Cbus: leaving scanning mode"; $cbus_scanning_cgate = 0; print_log "CBus: CBus server scan complete"; write_def_file(); @@ -1259,17 +1291,19 @@ } elsif ($cbus_got_tree_list) { if ($cbus_group_idx < @cbus_group_list) { my $group = $cbus_group_list[$cbus_group_idx++]; + print_log "Cbus: dbget group $group"; set $cbus_talker "dbget $group/TagName"; } elsif ($cbus_unit_idx < @cbus_unit_list) { my $unit = $cbus_unit_list[$cbus_unit_idx++]; + print_log "Cbus: dbget unit $unit"; set $cbus_talker "dbget $unit/TagName"; - } else { - if ($cbus_scan_last_addr_seen eq - $cbus_unit_list[$#cbus_unit_list]) { + } else { + if ($cbus_scan_last_addr_seen eq $cbus_unit_list[$#cbus_unit_list]) { # Tree Scan complete - set tree completion flag - $cbus_scanning_tree = 0; + print_log "Cbus: leaving scanning mode"; + $cbus_scanning_tree = 0; } } |