How to add your own GSD device

From LinuxMCE
Revision as of 12:04, 10 August 2007 by Nite man (Talk | contribs)

(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

How to add your own GSD device

The steps to add GSD device are following: 1. Be sure that you have installed GSD package - dpkg -l 'pluto-generic-serial-device' (it should be there).

2. Created a device template for your system and specify that it should use GSD. Add it under category lighting interfaces if you want to control lighting devices only. To control all kind of devices (security, climate etc) it's better to use Interface::Specialize. Also, you should specify a communication type - RS232, Ethernet etc.

3. After you save a new template a new interface will be added automatically. You can see it under Wizard --> Devices --> Interfaces. Also, there is a GSD page - Wizard --> Devices --> Generic Serial Devices. On that page you'll able to add/modify Ruby commands. To do that you should specify a group and tick box 'internal Ruby Command'. After you quick reload router you should see GSD process in console: # ps -elf|grep Generic_Serial_Device

5 S root     10085     1  0  76   0 -   683 -      Jul17 ?        00:00:00 SCREEN -d -m -S LinCon_8000-30 /usr/pluto/bin/Spawn_Device.sh 30 localhost Generic_Serial_Device
4 S root     10086 10085  0  75   0 -   646 wait   Jul17 pts/8    00:00:00 /bin/bash /usr/pluto/bin/Spawn_Device.sh 30 localhost Generic_Serial_Device
0 S root     31800 10086  0  79   0 - 123146 295621 Jul17 pts/8   00:00:00 ./Generic_Serial_Device -d 30 -r localhost -l /var/log/pluto/30_Generic_Serial_Device.log

Have a look into GSD log: /var/log/pluto/<GSD LinuxMCE ID>_Generic_Serial_Device.log. You can find here all Ruby errors, connection status and other useful information.

4. There are 6 base functions which you need:

  • Private Method Listing - you may place here all common functionality and use it from the others functions.
  • Process IDLE - method executed each one - two seconds, maybe useful to check a connection between your device and LinuxMCE.
  • Process Incoming Data - called when some data come from your device:
    recv = conn_.Recv(100,500);

    recv contains now the data received from the physical device (some switch is OFF). You can parse it to update a status of that switch in LinuxMCE:

    cmd = Command.new(plutoID, -1001, 1, 2, 48)
    cmd.params_[10] = 0
    SendCommand(cmd)
  • Process Receive Command For Child - called when the child device (in your case it's a dimmer of switch) gets some command: ON, OFF or SET LEVEL. Actually, those commands are routed to the parent device (your GSD interface) and it send the commands in desired format to the physical device:
    cmdId           = cmd.id_                                   # Command ID: ON, OFF, SET LEVEL
    cmdTo           = cmd.devidto_                              # Device ID in LinuxMCE
    devPort         = device_.childdevices_[cmdTo].devdata_[12] # 12 contains a port/channel
    childType       = device_.childdevices_[cmdTo].devtemplid_  # Template ID to know type of device: switch or dimmer
    
    case cmdId
          when 192 #192 is ON                     
               command = '<your ON command format>'           
          when 193 #193 is OFF                        
               command = '<your OFF command format>' 
          when 184 #184 is Level of dimmer
               command = '<your SET LEVEL command format>'                   
    end
    
    conn_.Send(command)
    
    In my case the command includes following parameters: LinuxMCE ID - to update the status in LinuxMCE, Port Number - to know where send actual command, command type - ON, OFF, SET LEVEL, level value for SET LEVEL. Plus, I generate an unique ID for each command to check its status. It might be good idea to push unsuccessful commands into array in the GSD device to run them one again.
  • Process Initialize - called when GSD device is starting. It's good point to initialize common variables and start logging for example:
    time      = Time.now
    $logFile  = File.new("/var/log/pluto/ICPDAS-" + time.strftime("%Y%m%d%H%M") + ".log", "w")
    $bFlush   = true          # flash output buffer
    $waitTime = 4000          # wait time in comunication
    

    I use that log approach just for test purpose. When you go live it's better do not use time stamp. To append your GSD device log to the one file after restart of router use that command:

    $logFile  = File.new("/var/log/pluto/ICPDAS.log", "a")
    
    Also, I use that method to get actual status real child devices and update their statuses in the LinuxMCE. Because some switch can be OFF manually during GSD device was down.
  • Process Release - called when GSD device is closing. I don't use at all.
  • Note that you should quick reload router each time when you modify your Ruby code! Because LinuxMCE caches it.

    Hope it help you to bring up your GSD device.