LinuxMCE Forums

General => Developers => Topic started by: ddamron on January 18, 2008, 05:25:43 AM

Title: NEW Threaded support for RUBY.
Post by: ddamron on January 18, 2008, 05:25:43 AM
Status Update:

Well, after much twisting of the brain, we have success.

I have successfully implemented a 'Home Automation Contoller' interface with PLCBUS.

Just what does it do?

Well, it's a set of Ruby Objects that 'encapsulate' home automation protocols.
(Actually, it can be used for ANY GSD device requiring bidirectional support)

Why is this good?

This is good for many reasons:

How do I use these routines?


Simple.  I'll include a sample class file.  Here's What you'll need to do:
How did I do it?

With a lot of patience, lots of debug output, and a little magic :)

Cool!  Can I start using it now?
no. :(
Not quite yet.

I still have to nail down some 'usage' details, I know how I want to do it.. but the code (as you can well imagine) is quite complex, and each minor change required MAJOR inspecting, to make sure it doesn't break anything else...

Stay tuned,

Dan.

P.S.
Ok, I'll give you a peek..  Here's some of my comment extracts... keep in mind, they may change...

##############################
#Class RubyCommand
##############################
class RubyCommand
  # This class is a container for a protocolObject Instance.
  # This class is responsible for the DIRECTION of communication of a specific command.

##############################
#Classe RubyCommands
##############################
#RubyCommands is an ARRAY of RubyCommand
# This class is responsible for keeping the ORDER of commands straight.
# also, for creating the RubyCommand objects.
# TODO:  Sometimes, certain commands need to be ignored.
# TODO:  Sometimes, certain commands need to INSERT a command to be sent first.
# TODO:  Sometimes, certain commands need to APPEND a command to be send right after?
#
#Actions
#we need to define actions for:
# => 0x001 Direction DCE=>GSD/GSD=>DCE
# => 0x002 Command Sent/NotSent
# => 0x004 Response (Received/Rejected)
# => 0x008 Re-send needed(true/false)
# => 0x010 Re-receive needed(true/false)
# => 0x020 IgnoreNextDCE(true/false)
# => 0x040 IgnoreNextGSD(true/false)
# => 0x080 SendThisFirst(true/false)
# => 0x100 SendThisNext(true/false)

#####################
# class ChildDevice #
#####################
# This class holds a child device.
#
# Methods:
# ChildDevice.devdata[] hash of devdata
# ChildDevice.deviceid <int> Device ID
# ChildDevice.template <int> Template ID of Child
# ChildDevice.parent <int> parent ID of Child (doesnt seem to work)
# ChildDevice.state <string> Current state of child

#################
# class Devices #
#################
# This is a HASH collecion of ChildDevice.
#
# Methods:
# Devices.append(device) <ChildDevice> adds a child device to the hash
# Devices[deviceID].<ChildDeviceMethod> this is how you get info.
# eg: d=Devices.new d.append(child102) d[102].state = "ON/100"


#####################
### PLCBUS OBJECT ###
#####################
#  This is a generic replaceable object
# This object needs the following methods:
#
# When creating this class, make sure to keep seperate variables
# to hold dce vs gsd.  This is so we can compare the variables
# later.
#
# dcein(cmd)
#   dcein is a command or event sent from dce
#   this method should take the command and prepare
#   the output into gsdout(string)
#   This command will set the direction to DCEtoGSD
#   
# dceout(cmd) cmd is dce Command Object (Command.new)
#   This method contains the command to be sent to DCE
#   
# gsdin(string)
#   gsdin is a command received from GSD
#   This method should take the string and prepare
#   the output command in dceout
#   
# gsdout(string)
#   This method contains the output string to be sent to the device
#   
# direction(DCEtoGSD|GSDtoDCE)
#   This READ ONLY property determines which direction the current command is going
#
# cmdComplete (TRUE|FALSE)
#   This is the flag you set when a response for a command is accepted.
#   This property allows the user to compare the command vs response.
#
#   It is up to the programmer to make sure what needs to be compared, is.
#   
#   When this is set to true, the command will be removed unless needMoreInput is set.
#
# neetMoreInput (TRUE|FALSE)
#   Use this flag to allow multiple response messages to come to this command. 
#
# responseNeeded(TRUE|FALSE) this is a read/write property telling the command object
#   this command requires a response.
#   this is used for bidirectional communication.  If this is set, this command will WAIT for a response from the other side.
Title: Re: NEW Threaded support for RUBY.
Post by: nlb on January 28, 2008, 05:18:14 PM
Dan,

Stupid question:
To your knowledge is possible to develop a Basic Stamp and control it via the PLCBUS controller?

cheers
Nick
Title: Re: NEW Threaded support for RUBY.
Post by: niz23 on January 28, 2008, 05:32:04 PM
nlb.

Quote from: nlb on January 28, 2008, 05:18:14 PM
Dan,

Stupid question:
To your knowledge is possible to develop a Basic Stamp and control it via the PLCBUS controller?

cheers
Nick

It should be possible.
First you need some hardware to interface plcbus<->basic stamp.
See, http://www.plcbus.com/PLCBUS-985468.html

Then you have to implement some protocol that interface lmce<->basic-stamp[application].

I believe you can extend Dans (great work so far!) plcbus implementation with custom commands that interface against your basic stamp application. Isn“t it simple. At least in theory :-)

From the data provided on the webpage it seem like the module also provide dc power.
The biggest problem I guess will be to buy these modules. I have no idea were you may do so.


/niz23
Title: Re: NEW Threaded support for RUBY.
Post by: ddamron on January 28, 2008, 07:50:47 PM
Nick,

Anything is possible..

What did you want to do with the Stamp?

Regards,

Dan
Title: Re: NEW Threaded support for RUBY.
Post by: nlb on January 29, 2008, 11:17:28 AM
Well I would like to get into creating some controllers for my house automation myself.
I like PLCBUS but it seems that there is nothing in Belgium and the closest i found and viable is Hong Kong.  So supply is going to be a bit tough.  I figured I could start creating basic controllers and interface these with LinuxMCE through X10 (since stamp and X10 are compatible) but then reviewing x10 pros and cons, its seems that PLCBUS is more compatible for europe and hows better performances.  The only thing is how to get Stamp and plcbus to interact. Im kinda new to electronics so im kinda lost...

Any ideas / hints?
Is it even really worth it to try and control a stamp controller through plcbus?

cheers
Title: Re: NEW Threaded support for RUBY.
Post by: ddamron on January 29, 2008, 06:10:25 PM
nlb,

I think controlling your STAMP through a PLCBus device is not the way you want to go.
It requires you to buy a PLCBUS device to connect your stamp with.. then, only VERY limited commands.. ON/OFF..

What you SHOULD research, is the protocol itself.  Connect the STAMP as if it's a PLCBUS device.. (optically isolated it!) and process the protocol inside the Stamp.  That will give you MUCH more functionality.

I would recommend a few courses in Electronics first!

I'm actually a hardware guy, programming is just a requirement..

Also, if your currently playing with a STAMP, it might be worth your while to look at other microcontrollers..

STAMP's are easy to program (basic).. so it's a good starting point..  I wouldn't recommend using them in production though.

Take a look at PIC microcontrollers www.microchip.com
There is a BASIC compiler for them that is pretty powerful.. I think the url is www.oshensoft.com

HTH,

Dan

PS
(didn't mean to put a downer on your project)
Title: Re: NEW Threaded support for RUBY.
Post by: ddamron on January 30, 2008, 09:03:06 PM
I've started a wiki for Threaded Ruby.
http://wiki.linuxmce.org/index.php/Category:ThreadedRuby

Regards,

Dan
Title: Re: NEW Threaded support for RUBY.
Post by: nlb on January 31, 2008, 10:42:42 AM
Dan,
thanks for the info - cleared some things up and no worries, this is not a downer,just an obstacle.

To you knowledge, would it be possible to mix two home automation protocols, e.g. using plcbus for all the lights, etc... and zwave for motion detectors and cameras? and still be able to control them through the same MCE interface?

Nick
Title: Re: NEW Threaded support for RUBY.
Post by: bulek on January 31, 2008, 11:49:23 AM
Quote from: nlb on January 31, 2008, 10:42:42 AM
Dan,
thanks for the info - cleared some things up and no worries, this is not a downer,just an obstacle.

To you knowledge, would it be possible to mix two home automation protocols, e.g. using plcbus for all the lights, etc... and zwave for motion detectors and cameras? and still be able to control them through the same MCE interface?

Nick
AFAIK this can be easily achieved, but not with mixing on code level, but on device level. You declare one zwave controller and put all devices it controls as childern, the same for all other protocol interfaces... and you'll be able to control all devices with no problems...

Regards,

Bulek.
Title: Re: NEW Threaded support for RUBY.
Post by: ddamron on January 31, 2008, 09:20:20 PM
Bulek, nailed it.
You can mix and match anything you want.
Title: Re: NEW Threaded support for RUBY.
Post by: nlb on April 20, 2008, 09:23:46 PM
ddamron,
any updates on your workings for the plc-bus driver?
cheers

Nlb
Title: Re: NEW Threaded support for RUBY.
Post by: totallymaxed on April 20, 2008, 09:43:12 PM
Quote from: ddamron on January 31, 2008, 09:20:20 PM
Bulek, nailed it.
You can mix and match anything you want.

So does that mean that we can use your threaded Ruby code to manage Z-wave devices too? Or is it that the Z-wave devices would still use the 'old' z-wave code?

Andrew

PS nice work by the way ;-)
Title: Re: NEW Threaded support for RUBY.
Post by: tschak909 on April 20, 2008, 11:23:40 PM
currnetly, z-wave would still use the current z-wave code.

-Thom