Author Topic: Sample code from the GSD/Ruby Webcast  (Read 3538 times)

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Sample code from the GSD/Ruby Webcast
« on: April 19, 2008, 09:56:24 pm »
Code: [Select]
#373 Private Method Listing
# Send a message out
def sndgsd(message)
  conn_.send(message)
end

#Process Response message
def response(message)
  #Message format: From, To, Priority, Type, Command [Param1 Param1Value]..

  #Our Format: To Type Command [Param Value] ...

  #split the messages up into chunks
  messages = message.split(" ")
  if messages.length < 3 then
error
  else
    to = messages[0].to_i
    type = messages[1].to_i
    cmd = messages[2].to_i

  #we now have enough information to create a command object
    cmd = Command.new(device_.devid_, to, 1, type, cmd)

  #now to populate parameters of the command
    pointer = 3

    while (messages.length > pointer)
      cmd.params_[messages[pointer].to_i] = messages[pointer + 1]
      pointer += 2
    end
    SendCommand(cmd)
  end
end

def error
  msg = 'Syntax Error'
  sndgsd(msg)
end

def prompt
  msg = 'TO TYPE CMD Param1 Param1value ...'
  sndgsd(msg)
end
#373 Private Method Listing END


#350 Process Incoming Data
while(true)
    buff=conn_.RecvDelimited(0x13.chr,50)
    if(buff.length() == 0)
        break
    end
    recv = recv + buff
    if recv[-1] == 13.chr then
      response(recv)
      recv = ''
    end
end
#350 Process Incoming Data END

The only intuitive interface is the nipple.  After that it's all learned.
My other computer is your windows box.
I'm out of my mind.  Back in 5 minutes.
Q:  What's Red and smells like blue paint?

A:  Red Paint.

caiman

  • Veteran
  • ***
  • Posts: 119
    • View Profile
Re: Sample code from the GSD/Ruby Webcast
« Reply #1 on: July 17, 2008, 09:51:05 pm »
Hi ddamron,

too bad I could not attend the webcast; I understand this sample code is for GSD, thus run from one of the lmce processes.

I would like to have a standalone ruby script (launched from command line) that connects to DCE to send messages and get events. Would you have some sample code for that ?