Posted to tcl by Napier at Wed Sep 24 15:48:35 GMT 2014view raw

  1. proc parseData {buf} {
  2.  
  3. LOG "parseData: START"
  4.  
  5. global connectionFlag
  6.  
  7. global defaultPage
  8.  
  9. LOG "Incoming data buffer: $buf"
  10.  
  11. ## TO-DO: need to be fixed for a situation where two or more commands would be coming in a single string.
  12. set tempBuf $buf
  13. set rlist [split $tempBuf "\r\n"]
  14. LOG "<Tcl> List data $rlist"
  15.  
  16.  
  17. foreach data $rlist {
  18. set idx 0
  19. if {[string first "~DEVICE" $data] != -1} {
  20. LOG "Now parsing: $data"
  21. parseSceneInfo $data
  22. } elseif { [string first "~OUTPUT" $data] != -1} {
  23. LOG "Now parsing: $data"
  24. parseOutputInfo $data
  25. } elseif {[string first "~HVAC" $data] != -1} {
  26. LOG "Now parsing $data"
  27. parseHVACInfo $data
  28. } elseif {[string first "bad login" $data] != -1} {
  29. LOG "Bad login attempt."
  30. } elseif { [string first "login:" $data] != -1 } {
  31. LOG "Login prompt found. Sending login..."
  32. sendLoginId
  33. } elseif { [string first "password:" $data] != -1} {
  34. LOG "Password prompt found. Sending password..."
  35. sendPassword
  36. } elseif { [string first "GNET>" $data] != -1 || [string first "QNET>" $data] != -1} {
  37. LOG "GNET/QNET tag found"
  38. if {$connectionFlag == "LOGIN"} {
  39. LOG "set connectionFlag CONNECTED"
  40. set connectionFlag "CONNECTED"
  41. getAllHVACs
  42. getAllOutputInfo
  43. getAllSceneInfo
  44. }
  45. } elseif {[string first "~ERROR," $data] != -1} {
  46. set errorNum [string index $data 7]
  47. LOG "errorNum = $errorNum"
  48. switch $errorNum {
  49. "1" {LOG "ERROR: 1 - Parameter count mismatch."}
  50. "2" {LOG "ERROR: 2 - Object does not exist."}
  51. "3" {LOG "ERROR: 3 - Invalid action number."}
  52. "4" {LOG "ERROR: 4 - Parameter data out of range."}
  53. "5" {LOG "ERROR: 5 - Parameter data malformed."}
  54. "6" {LOG "ERROR: 6 - Unsupported command."}
  55. default {LOG "ERROR: unknown - Refer to updated Lutron protocol documentation."}
  56. }
  57. } else {puts "Unknown Data Received"
  58. }
  59.  
  60. LOG "parseData: END"
  61. return 1
  62. }