Posted to tcl by Napier at Wed Sep 24 15:32:00 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. }
  23.  
  24. if { [string first "~OUTPUT" $data] != -1} {
  25. LOG "Now parsing: $data"
  26. parseOutputInfo $data
  27. }
  28. if {[string first "~HVAC" $data] != -1} {
  29. LOG "Now parsing $data"
  30. parseHVACInfo $data
  31. }
  32. if {[string first "bad login" $data] != -1} {
  33. LOG "Bad login attempt."
  34. }
  35.  
  36. if { [string first "login:" $data] != -1 } {
  37. LOG "Login prompt found. Sending login..."
  38. sendLoginId
  39. }
  40.  
  41. if { [string first "password:" $data] != -1} {
  42. LOG "Password prompt found. Sending password..."
  43. sendPassword
  44. }
  45.  
  46. if { [string first "GNET>" $data] != -1 || [string first "QNET>" $data] != -1} {
  47. LOG "GNET/QNET tag found"
  48. if {$connectionFlag == "LOGIN"} {
  49. LOG "set connectionFlag CONNECTED"
  50. set connectionFlag "CONNECTED"
  51. getAllHVACs
  52. getAllOutputInfo
  53. getAllSceneInfo
  54. }
  55. }
  56.  
  57. if {[string first "~ERROR," $data] != -1} {
  58. set errorNum [string index $data 7]
  59. LOG "errorNum = $errorNum"
  60. switch $errorNum {
  61. "1" {LOG "ERROR: 1 - Parameter count mismatch."}
  62. "2" {LOG "ERROR: 2 - Object does not exist."}
  63. "3" {LOG "ERROR: 3 - Invalid action number."}
  64. "4" {LOG "ERROR: 4 - Parameter data out of range."}
  65. "5" {LOG "ERROR: 5 - Parameter data malformed."}
  66. "6" {LOG "ERROR: 6 - Unsupported command."}
  67. default {LOG "ERROR: unknown - Refer to updated Lutron protocol documentation."}
  68. }
  69. }
  70. }
  71.  
  72. LOG "parseData: END"
  73. return 1
  74. }