ThreadedRuby

From LinuxMCE
Jump to: navigation, search
Version Status Date Updated Updated By
710 Unknown N/A N/A
810 Unknown N/A N/A
1004 Unknown N/A N/A
1204 Unknown N/A N/A
1404 Unknown N/A N/A
Usage Information

Here is my ThreadedRuby code. I'm trying to add notes and a bit of an explanation as to what each piece of code does. If you just want to get going, create a class Object for your protocol as per in section 5. File:ThreadedRubyObject.png

Device Object

This class is simply a holder for a Child Device with onoff and level added:

class Device
  attr_accessor  :devdata, :deviceid, :template, :parent, :onoff, :level
  def initialize()                                               
    @onoff = 'OFF'                                                #State
    @level = 0                                                    #Level
    @devdata = Hash.new                                           #to hold devdata
    @deviceid = @template = @parent = 0
  end
end

$devices hash

This hash contains all the Device Objects (child objects with state info)

This is initialized in initDevices()

Command Object

This is the PARENT class to your protocol Object. This class is responsible for determining the DIRECTION of the conversation: either DCEtoGSD (from DCERouter to your GSD Device) or GSDtoDCE (from your GSD Device to DCERouter)

The actual data is irrelevant in this object. The data is simply passed to your protocol Object.

$Commands Array

This is an Array of the Command Objects. This serves as the queue for the threading.

Once a command has been completed, it is removed from this array.

Your protocol Obect determines if the command is complete by setting the @responseAccepted = true, and @responseNeeded = false.

This will, in turn set the (command object's) state to Complete.

If a command object's state = Complete, the command is removed from the queue (array).

You can accept MULTIPLE responses for your command by keeping @responseNeeded = true.

PLCBUS OBJECT

This is a generic replaceable object This object needs the following methods:

Methods

Initialize()

  • What it does:
any Object initialization you may need.
  • When is this called:
Upon Object creation.
  • What you will get:
nothing.
  • What you will return:
nothing.

dceCommandIn(cmd)

  • What is does:
sends you a command object to allow you to create gsdOut().
  • What you will get:
cmd (Command Object)
  • What you need to return:
nothing (ignored)
  • When you will get this:
executed when a new DCE command is sent to you.

dceResponseIn(cmd)

  • What it does:
Sends you a DCE object to compare with the command.
  • What you will get:
cmd (Command Object)
  • What you need to return:
TRUE if you accept this response.
FALSE if you do NOT accept this response.
  • When you will get this:
executed when a new DCE response is ready.

gsdCommandIn(value)

  • What it does:
sends you a String to allow you to create a dceOut().
  • What you will get:
value (String Object)
  • What you need to return:
nothing (ignored)
  • When you will get this:
executed when a new GSD command is sent to you.

gsdResponseIn(value)

  • What it does:
Sends you a GSD Response to compare with the command.
  • What you will get:
cmd (Command Object)
  • What you need to return:
TRUE if you accept this response.
FALSE if you do NOT accept this response.
  • When you will get this:
executed when a new GSD response is ready.

dceout()

  • What it does:
Creates a Command Object to send to DCE.
  • What you will get:
nothing.
  • What you need to return:
a Command Object representing the previous gsdCommandIn.
  • When is this called:
After a gsdCommandIn has been sent.

gsdout()

  • What it does:
creates a String Object to send to GSD.
  • What you will get:
nothing.
  • What you will return:
a String Object representing the previous dceCommandIn.
  • When is this called:
After a dceCommandIn has been sent.

Properties:

@responseAccepted

  • What it does:
signals that the current response is accepted as valid.
  • When you should set this:
Set this to TRUE if you accept the response as a valid response for this command.
Set this to FALSE if you do NOT accept this response

@responseNeeded

  • What it does:
signals when you need a response.

@commandHolder

  • What it does:
If you need to create a new command, this is the holder for it.

Private Functions

ProtocolObject Class