Posted to tcl by Napier at Wed Sep 24 15:48:35 GMT 2014view raw
- proc parseData {buf} {
- LOG "parseData: START"
- global connectionFlag
- global defaultPage
- LOG "Incoming data buffer: $buf"
- ## TO-DO: need to be fixed for a situation where two or more commands would be coming in a single string.
- set tempBuf $buf
- set rlist [split $tempBuf "\r\n"]
- LOG "<Tcl> List data $rlist"
- foreach data $rlist {
- set idx 0
- if {[string first "~DEVICE" $data] != -1} {
- LOG "Now parsing: $data"
- parseSceneInfo $data
- } elseif { [string first "~OUTPUT" $data] != -1} {
- LOG "Now parsing: $data"
- parseOutputInfo $data
- } elseif {[string first "~HVAC" $data] != -1} {
- LOG "Now parsing $data"
- parseHVACInfo $data
- } elseif {[string first "bad login" $data] != -1} {
- LOG "Bad login attempt."
- } elseif { [string first "login:" $data] != -1 } {
- LOG "Login prompt found. Sending login..."
- sendLoginId
- } elseif { [string first "password:" $data] != -1} {
- LOG "Password prompt found. Sending password..."
- sendPassword
- } elseif { [string first "GNET>" $data] != -1 || [string first "QNET>" $data] != -1} {
- LOG "GNET/QNET tag found"
- if {$connectionFlag == "LOGIN"} {
- LOG "set connectionFlag CONNECTED"
- set connectionFlag "CONNECTED"
- getAllHVACs
- getAllOutputInfo
- getAllSceneInfo
- }
- } elseif {[string first "~ERROR," $data] != -1} {
- set errorNum [string index $data 7]
- LOG "errorNum = $errorNum"
- switch $errorNum {
- "1" {LOG "ERROR: 1 - Parameter count mismatch."}
- "2" {LOG "ERROR: 2 - Object does not exist."}
- "3" {LOG "ERROR: 3 - Invalid action number."}
- "4" {LOG "ERROR: 4 - Parameter data out of range."}
- "5" {LOG "ERROR: 5 - Parameter data malformed."}
- "6" {LOG "ERROR: 6 - Unsupported command."}
- default {LOG "ERROR: unknown - Refer to updated Lutron protocol documentation."}
- }
- } else {puts "Unknown Data Received"
- }
- LOG "parseData: END"
- return 1
- }