Author Topic: Insteon PLM Code RC1  (Read 6965 times)

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Insteon PLM Code RC1
« on: December 17, 2007, 09:25:29 pm »
Here it is...

#351 Process IDLE
Code: [Select]
#### Written by Dan Damron
#### #351 Process IDLE ####
############################ RECEIVE Error Trap ###########################
if  $cmdqueue.length != 0
if $cmdqueue == $savedstate
if $resetNext == 5
#Command has stalled. Reset wait flag and resend command.
log('Command Stalled!  resetting and retrying')
if $cmdqueue[0]['Command'] == 'InsStdMsg'
$cmdqueue[0]['Command'] = 'SndIns'
end
$wAIT = false
$resetNext = 0
SndIns()
else
$resetNext +=1
end
else
$resetNext = 0
$savedstate = $cmdqueue
end
end
###########################################################################

#350 Process Incoming Data
Code: [Select]
log('In----------Processing Incoming Data')
$recvbuff = ""
while(true)
buff=conn_.Recv(128,100)
if(buff.length() == 0)
break
end
$recvbuff = $recvbuff + buff
end
debugin($recvbuff)
plmparse($recvbuff)

#355 - Process Initialize
Code: [Select]
#### Written by Dan Damron
#### #355 Process Initialize ####
$log = ''
$cmdTo = ''
$cmdFrom = ''
$cmdPriority = ''
$cmdType = ''
$cmdID = ''
$cmdParams = {}
$children = {}
$recvbuff = ''
$wAIT = false
$currentCmd = {}
$flagsBroadcastMessage = 128
$flagsDirectMessage = 0
$flagsAckDirectMessage = 32
$flagsNackDirectMessage = 160
$flagsGroupBroadcaseMessage = 192
$flagsGroupCleanupDirectMessage = 64
$flagsGroupAckDirectMessage =96
$flagsGroupNackDirectMessage = 224
$cmdqueue = []
$currentcmd = 0 # to save state of command when receiving more data.
$resetNext = 0 # used in Process IDLE to trap stalled responses.
$savedstate = nil
$dcequeue = []
$X10HouseCodes = {
'6', 'A',
'E', 'B',
'2', 'C',
'A', 'D',
'1', 'E',
'9', 'F',
'5', 'G',
'D', 'H',
'7', 'I',
'F', 'J',
'3', 'K',
'B', 'L',
'0', 'M',
'8', 'N',
'4', 'O',
'C', 'P'}
$X10UnitCodes = {'6', '1', 'E', '2', '2', '3', 'A', '4',
'1', '5', '9', '6', '5', '7', 'D', '8',
'7', '9', 'F', '10', '3', '11', 'B', '12',
'0', '13', '8', '14', '4', '15', 'C', '16'}
$X10CommandCodes = {'6', 'All Lights Off', 'E', 'Status = off',
'2', 'On', 'A', 'Pre-Set Dim',
'1', 'All Lights On', '9', 'Hail Ack',
'5', 'Bright', 'D', 'Status=on',
'7', 'Extended Code','F', 'Status Request',
'3', 'Off', 'B', 'Pre-set Dim',
'0', 'All Units Off', '8', 'Hail Request',
'4', 'Dim', 'C', 'Extended Data(analog)'}
$responseString = '<' + '/' + 'Response>'
log('Finding Children..')


device_.childdevices_.each{|c| $children[device_.childdevices_[c.to_s.to_i].devdata_[12].chomp.lstrip.rstrip] = c.to_s.to_i}
$children.keys.each{|c| log(c + ' = ' + $children[c].to_s)}
#children found... get the status of each child...
$children.keys.each{|c|
if c.length > 2 #filter out X10 for now
  #pack insteon message here, and send it out!
# receive message in parsemessage and relay commands back in it.
insteonID = c.chomp.split('.')
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F', #flags
'Parameter5' => '19', #Status Request
'Parameter6' => '00'} #not used.
$cmdqueue << param
# below gets the device Cat/SubCat/Firmware (not working yet)
param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F', #flags
'Parameter5' => '10', #PING
'Parameter6' => '00'} #not used.
$cmdqueue << param

end
}
#lastly, put the PLM in monitor mode.
param = {'Command' => 'SetCfg', 'Parameter1' => '40'}
$cmdqueue << param
SndIns() #Lastly, start executing commands in order.

#384 - Process Receive Command For Child
Code: [Select]
#### Written by Dan Damron
#### #384 Process Receive Command for Child ####


log('------dce--- PRCFC:$wAIT=' + $wAIT.to_s)
#add DCE command to DCE queue




insteonID = device_.childdevices_[cmd.devidto_].devdata_[12].chomp.split('.')
###
#log('INSPECT:'+ device_.childdevices_[cmd.devidto_].devdata_[])
###
$cmdID = cmd.id_
$cmdTo = cmd.devidto_
childType = device_.childdevices_[cmd.devidto_].devtemplid_
$cmdFrom = cmd.devidfrom_
$cmdPriority = cmd.priority_
$cmdType = cmd.type_
$cmdParams = cmd.params_
log('------dce--- cmdID:' + $cmdID.to_s + ', cmdFrom:' + $cmdFrom.to_s + ', cmdTo:' + $cmdTo.to_s + ', cmdType:' + $cmdType.to_s + ', Priority:' + $cmdPriority.to_s)
$cmdParams.keys.each {|p| log('------dce--- Param_[' + p.to_s + ']=' + $cmdParams[p])}
case cmd.id_
when 192 # ON
if insteonID.length > 2 then

param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '11',
'Parameter6' => 'FF'}
$cmdqueue << param
SndIns()
else
log "------dce--- X10 DEVICE!!!"


param = {'Command' => 'SndX10',
'Parameter1' => rawX10(device_.childdevices_[cmd.devidto_].devdata_[12]),
'Parameter2' => X10Flag('On')}
$cmdqueue << param
SndIns()
end
# resp = Command.new($cmdTo, 1, $cmdPriority, $cmdType, $cmdID)
# resp.params_ = $cmdParams
# SendCommand(resp)
when 193 #OFF
if insteonID.length > 2 then

param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '13',
'Parameter6' => '00'}
$cmdqueue << param
SndIns()
else
log "------dce--- X10 DEVICE!!!"
param = {'Command' => 'SndX10',
'Parameter1' => rawX10(device_.childdevices_[cmd.devidto_].devdata_[12]),
'Parameter2' => X10Flag('Off')}
$cmdqueue << param
SndIns()

end
# resp = Command.new($cmdTo, 1, $cmdPriority, $cmdType, $cmdID)
# resp.params_ = $cmdParams
# SendCommand(resp)

when 184 #SetLevel
# convert from percent to hex
dim_level = percenttohex(cmd.params_[76])
log("------dce--- Dim Level:" + dim_level.to_s)
if insteonID.length > 2 then

param = {'Command' => 'SndIns',
'Parameter1' => insteonID[0],
'Parameter2' => insteonID[1],
'Parameter3' => insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '11',
'Parameter6' => dim_level}
$cmdqueue << param
SndIns()
else
log "X10 DEVICE!!! relative Dimming command"
# have to send 2 commands
#param = {'Command' => 'SndX10',
#'Parameter1' => rawX10(device_.childdevices_[cmd.devidto_].devdata_[12]),
#'Parameter2' => $X10CommandCodes.index['Bright'] + $X10UnitCodes.index[dim_level]
#$cmdqueue << param
#param = {'Command' => 'SndX10',
#dim_level = ((cmd.params_[76] * 16 + 1)/100).to_i.to_s
#'Parameter1' => rawX10(device_.Childdevices_[cmd.devidto_].devdata_[12]),
#'Parameter2' => $X10CommandCodes.index['Dim'] + $X10UnitCodes.index[dim_level]}

SndIns()

end
# resp = Command.new($cmdTo, 1, $cmdPriority, $cmdType, $cmdID)
# resp.params_ = $cmdParams
# SendCommand(resp)
end

continued in next message
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.

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: Insteon PLM Code RC1
« Reply #1 on: December 17, 2007, 09:28:23 pm »
# 373 Private Method Listing
Code: [Select]
#### Written by Dan Damron
#### #373 Private Method Listing ####


def getDeviceInfo(param)
### temporary
case param['Parameter6'].hex
  when 0x0 # Generalized Controllers
case param['Parameter7'].hex
when 0x04; log('Found ControLinc [2430]')
when 0x05; log('Found RemoteLinc [2440]')
when 0x06; log('Found Icon Tabletop Controller [2830]')
when 0x09; log('Found SignaLinc RF Signal Enhancer [2442]')
when 0x0A; log('Found Balboa Instruments Poolux LCD Controller')
when 0x0B; log('Found Access Point [2443]')
when 0x0C; log('Found IES Color Touchscreen')
end
  when 0x01 # Dimmable Lighting Control
case param['Parameter7'].hex
when 0x00; log('Found LampLinc V2 [2456D3]')
when 0x01; log('Found SwitchLinc V2 Dimmer 600W [2476D]')
when 0x02; log('Found In-LineLinc Dimmer [2475D]')
when 0x03; log('Found Icon Switch Dimmer [2876D]')
when 0x04; log('Found SwitchLinc V2 Dimmer 1000W [2476DH]')
when 0x06; log('Found LampLinc 2-pin [2456D2]')
when 0x07; log('Found Icon LampLinc V2 2-pin [2456D2]')
when 0x09; log('Found KeypadLinc Dimmer [2486D]')
when 0x0A; log('Found Icon In-Wall Controller [2886D]')
when 0x0D; log('Found SocketLinc [2454D]')
when 0x13; log('Found Icon SwitchLinc Dimmer for Lixar/Bell Canada [2676D-B]')
when 0x17; log('Found ToggleLinc Dimmer [2466D]')
end
  when 0x02 # Switched Lighting Control
case param['Parameter7'].hex
when 0x09; log('Found ApplianceLinc [2456S3]')
when 0x0A; log('Found SwitchLinc Relay [2476S]')
when 0x0B; log('Found Icon On Off Switch [2876S]')
when 0x0C; log('Found Icon Appliance Adapter [2856S3]')
when 0x0D; log('Found ToggleLinc Relay [2466S]')
when 0x0E; log('Found Switchlinc Relay Countdown Timer [2476ST]')
when 0x10; log('Found In-LineLinc Relay [2475D]')
when 0x13; log('Found Icon SwitchLinc Relay for Lixar/Bell Canada [2676R-B]')
end
  when 0x03 # Network Bridges
case param['Parameter7'].hex
when 0x01; log('Found PowerLinc Serial [2414S]')
when 0x02; log('Found PowerLinc USB [2414U]')
when 0x03; log('Found Icon PowerLinc Serial [2814S]')
when 0x04; log('Found Icon PowerLinc USB [2814U]')
when 0x05; log('Found Smartlabs Power Line Modem Serial [2412S]')
end
  when 0x04 # Irrigation Control
case param['Parameter7'].hex
when 0x00; log('Found Simplehomenet EZRain1 Sprinkler Controller')
end
  when 0x05 # Climate Control
case param['Parameter7'].hex
when 0x00; log('Found Broan SMSC080 Exhaust Fan')
when 0x01; log('Found Simplehomenet EZTherm')
when 0x02; log('Found Broan SMSC110 Exhaust Fan')
when 0x03; log('Found Venstar RF Thermostat Module')
when 0x04; log('Found Simplehomenet EZStat Thermostat')
end
  when 0x06 # Pool and Spa Control
case param['Parameter7'].hex
when 0x00; log('Found Simplehomenet EZPool')
end
  when 0x07 # Sensors and Actuators
case param['Parameter7'].hex
when 0x00
end
  when 0x08 # Home Entertainment
case param['Parameter7'].hex
when 0x00
end
  when 0x09 # Energy Management
case param['Parameter7'].hex
when 0x00
end
  when 0x0A # Built-In Appliance Control
case param['Parameter7'].hex
when 0x00
end
  when 0x0B # Plumbing
case param['Parameter7'].hex
when 0x00
end
  when 0x0C # Communication
case param['Parameter7'].hex
when 0x00
end
  when 0x0D # Computer Control
case param['Parameter7'].hex
when 0x00
end
  when 0x0E # Window Coverings
case param['Parameter7'].hex
when 0x00
end
  when 0x0F # Access Control
case param['Parameter7'].hex
when 0x00
end
  when 0x10 # Security, Health, and Safety
  when 0x11 # Surveillance
  when 0x12 # Automotive
  when 0x13 # Pet care
  when 0x14 # Toys
  when 0x15 # Timekeeping
  when 0x16 # Holiday
end
### eventually, open a XML configuration script?
### or read saved data from mysql?
end

def cmdComplete
# Clears the wait flag, and removes the command from the queue.
$wAIT = false
$cmdqueue.delete_at(0)
# now that THAT command is completed, check to see if there is
# another command ready to transmit.
log ("Command Completed.  Checking queue")
if $cmdqueue.nitems > 0 then
log("Queue:" + $cmdqueue.nitems.to_s + " : executing next command")
SndIns()
else
log ('Queue Empty.')
end
end
def checkWait(param)
#Checks for response from current command.
if $cmdqueue[0] != nil
else
log('------:)----checkWait: command queue is emtpy')
if $wAIT == true #this should never happen
log('------:(XXX-CheckWait: TRUE')
else
log('------:)----CheckWait: FALSE')
end
end
end

def plmparse(value)
#THIS ROUTINE REPLACES parsestring()
#this routine will PARSE the incoming stream into valid messages
# value is the complete command
param = {}

  while value.length > 2
case value[1]
when '62'.hex # Special case, need to look at flags
if (value[5] & '10'.hex) == '10'.hex # check for extended flag
cmdlen = 23
else
cmdlen = 9
end
param['Response'] = 'SndIns'
when '50'.hex; cmdlen = 11; param['Response'] = 'InsStdMsg'
when '51'.hex; cmdlen = 25; param['Response'] = 'InsExtMsg'
when '68'.hex; cmdlen = 4 #Set Insteon ACK Message Byte
when '71'.hex; cmdlen = 5 #Set Insteon ACK Message Two Bytes
when '70'.hex; cmdlen = 4 #Set Insteon NACK Message Byte
when '63'.hex; cmdlen = 5; param['Response'] = 'SndX10'
when '52'.hex; cmdlen = 4; param['Response'] = 'X10Msg'
when '61'.hex; cmdlen = 6; param['Response'] = 'SndGrp'
when '56'.hex; cmdlen = 7; param['Response'] = 'GrpEvntRpt'
when '58'.hex; cmdlen = 3 #All-Link Cleanup Status Report
when '64'.hex; cmdlen = 5; param['Response'] = 'StLnk'
when '65'.hex; cmdlen = 3; param['Response'] = 'CancelLnk'
when '53'.hex; cmdlen = 10; param['Response'] = 'InsLnkSts'
when '69'.hex; cmdlen = 3; param['Response'] = 'GetLnk'
when '6A'.hex; cmdlen = 3; param['Response'] = 'GetNext'
when '6C'.hex; cmdlen = 3 #Get All-Link Record for Sender
when '57'.hex; cmdlen = 10; param['Response'] = 'LnkData'
when '6F'.hex; cmdlen = 12; param['Response'] = 'MngLnk'
when '67'.hex; cmdlen = 3; param['Response'] = 'RstPLM'
when '6B'.hex; cmdlen = 4; param['Response'] = 'SetCfg'
when '60'.hex; cmdlen = 9; param['Response'] = 'GetVersion'
when '66'.hex; cmdlen = 6 #Set Host Device Category
when '72'.hex; cmdlen = 3 # RF Sleep
when '54'.hex; cmdlen = 3; param['Response'] = 'BtnRpt'
when '6D'.hex; cmdlen = 3; param['Response'] = 'LEDON'
when '6E'.hex; cmdlen = 3; param['Response'] = 'LEDOFF'
end
log('cmdlen=' + cmdlen.to_s)
#Now we know the length the command should be, see if we have it.
if value.length >= cmdlen
#Yes, we have the whole command, Pack it in param
for byt in 1..cmdlen
param['Parameter' + byt.to_s] = padhex("%X" %value[byt - 1])
end
#now remove it from the string..
value = value.slice(cmdlen, value.length - cmdlen)
#Send it off for parsing
EZToDCE(param)
else
#no, we have NOT received the whole command.
return value
end
  end
return value
end




def rawX10(value)

x10MSN = $X10HouseCodes.index[value[0..0]]
x10LSN = $X10UnitCodes.index[value[1..1]]
return x10MSN + x10LSN
end

def X10Flag(value)
  return + $X10CommandCodes.index[Value] + '0'
end

def SndIns
# create a new PLM command for SndIns
if $wAIT == false
param = $cmdqueue[0]
### have to figure out the command byte 2 here
work = '02'.hex.chr + plmcommand(param)
### PLM command compilation
for loop in 2..param.keys.nitems
  @dummy = param['Parameter' + (loop - 1).to_s].to_s
  work+= @dummy.hex.chr
end
conn_.Reconnect()
debug(work)
conn_.Send(work)
sleep 0.25
$wAIT = TRUE
else
log('X-----------SndIns: Waiting for response to:' +  $cmdqueue[0]['Command'].to_s)
log('X-----------SndIns: Current Queue Length:' + $cmdqueue.nitems.to_s)
end
end
def plmcommand(param)
### this returns the proper Byte2 for the command.
case param['Command']
when 'GetVersion'; return '60'.hex.chr
when 'SndIns'; return '62'.hex.chr
when 'SndGrp'; return '61'.hex.chr
when 'SndX10'; return '63'.hex.chr
when 'GetLnk'; return '69'.hex.chr
when 'GetNext'; return '6A'.hex.chr
when 'BtnRpt'; return '54'.hex.chr
when 'GetCfg'; return '73'.hex.chr
when 'StLnk'; return '64'.hex.chr
when 'CancelLnk'; return '65'.hex.chr
when 'MngLnk'; return '6F'.hex.chr
when 'RstPLM'; return '67'.hex.chr
when 'SetCfg'; return '6B'.hex.chr
when 'LEDON'; return '6D'.hex.chr
when 'LEDOFF'; return '6E'.hex.chr
end
end

def debug(text)
  work = 'OUT:'

  for c in 1..text.length
    work += padhex("%X" %text[c-1]) + ' '
  end
  log(work + "Length:" + text.length.to_s)
end

def debugin(text)
  work = 'IN:'

  for c in 1..text.length
    work += padhex("%X" %text[c-1]) + ' '
  end
  log(work + "Length:" + text.length.to_s)
end

def padhex(hex)
if hex.length==1
hex = "0" + hex
end
return hex
end

def percenttohex(level)
# convert from percent to byte
return "%X" %((level.to_i * 2.56) -1).to_i
end

def hextopercent(level)
return (level.hex.to_i / 2.55).to_i
end

def log(line)
#/var/log/pluto/121_Generic_Serial_Device.log
$log = File.open("/var/log/pluto/127_Generic_Serial_Device.log", "a")
$log.puts "(***):" + line.to_s
$log.close
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.

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: Insteon PLM Code RC1
« Reply #2 on: December 17, 2007, 09:28:54 pm »
Private Method Listing Continued

Code: [Select]
def EZToDCE(param) #Main Routine
#param contains a hash of EZBridge command structure
log('--|---------EZtoDCE')
log('Queue:' + $cmdqueue[0].inspect)
log('Param:' + param.inspect)
checkWait(param)
case param['Response']
# Standard Commands (responses to command)
when 'GetRevision' # Special Response
log('-----|---------GetRevision:' + param['Parameter1'])

when 'GetLatLong'  # Special Response
log('-----|---------GetLatLong: Lat=' + param['Lat'] + ', Long=' + param['Long'])

when 'SetLatLong'
if param['Parameter1'] = 'True' then
log('-----|---------SetLatLong: Ok')
else
log('-----X---------SetLatLong: FAILED!')
end
when 'SetPasswd'

when 'SetTimeZone'

when 'GetClock' # Special Response

when 'SetClock'

when 'SetNTPServer'

when 'Upgrade'

when 'NetCfg'

when 'Reset'
#Reset Response
cmdComplete
when 'LstTimers'  # Special Response


when 'ClrTimers'

when 'AddTimer'

when 'GetTimer'    # Special Response

when 'SetTimer'

when 'DelTimer'

when 'GetVersion' # Special Response

when 'SndGrp'

when 'SndIns' # response from SndIns
### BUG FOUND ### When the EZBridge receives a command from an EXTERNAL source
### ie not from this device, cmdqueue will be nil, and the code below
### fails.  Have to check against that.
   if $cmdqueue.length > 0
#First, check the response to make sure the command made it ok.
if param['Parameter9'].to_i == 6 #Ack received
case param['Parameter7'].hex #Received an ack to THIS command
when 0x1 #Assign to Group
getDeviceInfo(param)
cmdComplete
when 0x2 #Delete from Group
when 0x10 # PING
log('Got PING ACK')
$currentcmd = 0x10
$cmdqueue[0]['Command'] = 'InsStdMsg'
when 0x11 #ON
$currentcmd = 0x11
$cmdqueue[0]['Command'] = 'InsStdMsg'
when 0x13 #OFF
$currentcmd = 0x13
$cmdqueue[0]['Command'] = 'InsStdMsg'
when 0x15 #Bright
$currentcmd = 0x15
$cmdqueue[0]['Command'] = 'InsStdMsg'
when 0x16 #DIM
$currentcmd = 0x16
$cmdqueue[0]['Command'] = 'InsStdMsg'
when 0x17 #Start Manual Change
when 0x18 #Stop Manual Change
when 0x19 #Status Request
# Status Request Acked - get ready for InsStdMsg
$currentcmd = 0x19
# change cmd to reflect InsStdMsg
$cmdqueue[0]['Command'] = 'InsStdMsg'
when 0x24
log('Caught ACK for Insteon DO EE READ')
$currentcmd = 0x24
$cmdqueue[0]['Command'] = 'InsStdMsg'
when 0x28
log('Caught ACK for Insteon SET ADDRESS MSB')
$currentcmd = 0x25
$cmdqueue[0]['Command'] = 'InsStdMsg'

when 0x29
log('Caught ACK for Insteon POKE')
$currentcmd = 0x29
$cmdqueue[0]['Command'] = 'InsStdMsg'

when 0x2A
log('Caught ACK for Insteon POKE EXTENDED')
$currentcmd = 0x2A
$cmdqueue[0]['Command'] = 'InsStdMsg'

when 0x2B
log('Caught ACK for Insteon PEEK')
$currentcmd = 0x2B
$cmdqueue[0]['Command'] = 'InsStdMsg'

when 0x2C
log('Caught ACK for Insteon PEEK INTERNAL')
$currentcmd = 0x2C
$cmdqueue[0]['Command'] = 'InsStdMsg'

when 0x2D
log('Caught ACK for Insteon POKE INTERNAL')
$currentcmd = 0x2D
$cmdqueue[0]['Command'] = 'InsStdMsg'

else
log('Unknown Insteon Cmd1')
end

else # NACK received - command failed.
end
   else
#Response received for another device.
log('Response detected for a command that was not sent by me')
   end
when 'SndX10'

when 'StLnk'

when 'CancelLnk'

when 'SetDev'

when 'RstPLM'

when 'GetLnk'

when 'GetNext'

when 'SetCfg' # response from Setcfg command
if param['Parameter4'].to_i == 6 #ack
log('SetCfg Completed')
cmdComplete
else
log('SetCfg NACKED')
end
when 'GetLnkData'

when 'LEDON'

when 'LEDOFF'

when 'MngLnk'

when 'GetCfg' # Special Response

when 'LstMacros' # Special Response

when 'ClrMacros'

when 'AddMacro'

when 'GetMacro' # Special Response

when 'SetMacro'

when 'DelMacro'

when 'LstDevices' # Special Response

when 'ClrDevices'

when 'AddDevice'

when 'GetDevice' # Special Response

when 'SetDevice'

when 'DelDevice'

when 'LstZones'

when 'ClrZones'

when 'AddZone'

when 'GetZone'

when 'SetZone'

when 'DelZone'

when 'AddDevZone'

when 'DelDevZone'

# Response Messages
when 'InsExtMsg'

when 'InsStdMsg'
case $currentcmd # if this msg is part of a response, the Insteon Cmd1 will be saved here.
when 0x0
#there is no current command
# THIS IS COMING FROM AN OUTSIDE SOURCE
#EG: Manually turning Light Switch On/Off
# process this command.
# Note, this is a standard message
# there is no ack here.  Simply Send EVENTS back to DCE
# and Complete the command.
case param['Parameter10'].hex #this is the command
when 0x01 #Assign to Group
log('Caught EXTERNAL Assign to Group')
getDeviceInfo(param)
cmdComplete
when 0x02 #Delete from Group
log('Caught EXTERNAL Delete from Group')
when 0x10 # PING
log('Caught EXTERNAL Insteon PING result')



when 0x11 #ON
log('Caught EXTERNAL Insteon ON command result')
#on level is in cmd2
insHb = param['Parameter3'] # From
insMb = param['Parameter4']
insLb = param['Parameter5']
insID = insHb + "." + insMb + "." + insLb
myDevFrom = $children[insID]
myDevTo = -1000 #DCE Router
myPriority = 1
myType = 2 #Event
#Send an EVENT
#Event #48, pipe 10, value 1=on, 2=off
cmd = Command.new(myDevFrom, myDevTo, myPriority, myType, 48) #Event
cmd.params_[10] = '1' # EVENT ON
SendCommand(cmd)
$currentcmd = 0
cmdComplete
log('EVENT SENT!!!.48:[10]=1')


when 0x13 #OFF
log('Caught EXTERNAL Insteon OFF result')
#on level is in cmd2
insHb = param['Parameter3'] # From
insMb = param['Parameter4']
insLb = param['Parameter5']
insID = insHb + "." + insMb + "." + insLb
myDevFrom = $children[insID]
myDevTo = -1000 #DCE Router
myPriority = 1
myType = 2 #Event
#Send an EVENT
#Event #48, pipe 10, value 1=on, 2=off
cmd = Command.new(myDevFrom, myDevTo, myPriority, myType, 48) #Event
cmd.params_[10] = '0' # EVENT OFF
SendCommand(cmd)
$currentcmd = 0
cmdComplete
log('EVENT SENT!!!.48:[10]=0')


when 0x15; log('Caught EXTERNAL Insteon Brighten Result')
when 0x16; log('Caught EXTERNAL Insteon DIM Result')
when 0x24; log('Caught EXTERNAL Insteon DO EE READ')
when 0x28; log('Caught EXTERNAL Insteon SET ADDRESS MSB')
when 0x29; log('Caught EXTERNAL Insteon POKE')
when 0x2A; log('Caught EXTERNAL Insteon POKE EXTENDED')
when 0x2B; log('Caught EXTERNAL Insteon PEEK')
when 0x2C; log('Caught EXTERNAL Insteon PEEK INTERNAL')
when 0x2D; log('Caught EXTERNAL Insteon POKE INTERNAL')
else
log('Unknown EXTERNAL Insteon Command.')
end
when 0x1 #Assign to Group
### This is a broadcast message sent
# from a PING command
# or from a StartLink...
getDeviceInfo(param)
$currentcmd = 0
cmdComplete
when 0x2 #Delete from Group
when 0x10 # PING
#this is where I catch the InsStdMsg for ping.
log('Caught PING Message from Device')
$currentcmd = 1

when 0x11 # ON
log('Caught Insteon ON from INTERNAL source')
insHb = param['Parameter3'] # From
insMb = param['Parameter4']
insLb = param['Parameter5']
insID = insHb + "." + insMb + "." + insLb
myDevFrom = $children[insID]
myDevTo = -1000 #DCE Router
myPriority = 1
myType = 2 #Event
#Send an EVENT
#Event #48, pipe 10, value 1=on, 2=off
cmd = Command.new(myDevFrom, myDevTo, myPriority, myType, 48) #Event
cmd.params_[10] = '1' # EVENT ON
SendCommand(cmd)
$currentcmd = 0
cmdComplete
log('EVENT SENT!!!.48:[10]=1')
when 0x13 # OFF
insHb = param['Parameter3'] # From
insMb = param['Parameter4']
insLb = param['Parameter5']
insID = insHb + "." + insMb + "." + insLb
myDevFrom = $children[insID]
myDevTo = -1000 #DCE Router
myPriority = 1
myType = 2 #Event
#Send an EVENT
#Event #48, pipe 10, value 1=on, 2=off
cmd = Command.new(myDevFrom, myDevTo, myPriority, myType, 48) #Event
cmd.params_[10] = '0' # EVENT OFF
SendCommand(cmd)
$currentcmd = 0
cmdComplete
log('EVENT SENT!!!.48:[10]=0')
when 0x19 # Status Report
insHb = param['Parameter3'] # From
insMb = param['Parameter4']
insLb = param['Parameter5']
insID = insHb + "." + insMb + "." + insLb
myDevFrom = $children[insID]
myDevTo = -1000 #DCE Router
myPriority = 1
myType = 2 #Event
#Send an EVENT
#Event #48, pipe 10, value 1=on, 2=off
cmd = Command.new(myDevFrom, myDevTo, myPriority, myType, 48) #Event
#cant send dim value, only on or off
#cmd.params_[184] = hextopercent(param['Parameter8']).to_s
if param['Parameter11'].hex.to_i == 0 #if off
cmd.params_[10] = '0' # Send Event OFF
else
cmd.params_[10] = '1' # otherwise, send EVENT ON
end
log('Parameter11 = ' + param['Parameter11'].to_s)
log('Params_[10] = ' + cmd.params_[10].to_s)
SendCommand(cmd)
log('Initial Status EVENT SENT!!!..............')
# now to clear the currentcmd and remove command from the queue
$currentcmd = 0
cmdComplete
else
end

when 'X10Msg'
log('X10 Message Received')

when 'InsLnkSts'

when 'BtnRpt'

when 'UsrRst'

when 'GrpEvntRpt'
log('Group Event Report Received')

when 'LnkData'
#Caught a LnkData Response
log('LnkData Message Received')

# Other messages
when 'PLMTimeout'
log('PLM Timeout detected.. resetting EZBridge')
resetcmd = {'Command' => 'Reset'}
$cmdqueue.insert(0, resetcmd)
sleep 15
$wAIT = false
SndIns()
when 'PLMEchoError' # Have not seen this since a1.23
# error sending command to PLM, reset command and try again
log('-----XXXXXXX' + param['Response'])
resetcmd = {'Command' => 'Reset'}
$cmdqueue.insert(0, resetcmd)
sleep 15
$wAIT = false
SndIns()
when 'LongAck'
log('-----XXXXXXX' + param['Response'])
# Error - seems to show up after PLMEchoError
resetcmd = {'Command' => 'Reset'}
$cmdqueue.insert(0, resetcmd)
sleep 15
$wAIT = false
SndIns()
else
log('-----XXXXXXX UNKNOWN Response Received:' + param['Response'])
end

end

My private method listing is getting too big to post in one message :O

The last routine EZToDCE(param) is a COMMON routine for both the PLM and the EZBridge.
Sent and returned values are exactly the same, but parsed differently depending on the device.
« Last Edit: December 17, 2007, 09:31:18 pm by ddamron »
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.