LinuxMCE Forums

General => Developers => Topic started by: ddamron on April 19, 2008, 09:56:24 PM

Title: Sample code from the GSD/Ruby Webcast
Post by: ddamron on April 19, 2008, 09:56:24 PM

#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

Title: Re: Sample code from the GSD/Ruby Webcast
Post by: caiman 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 ?