iMAPSmartLightEvent.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package kr.co.icontrols.wallpadmain.imap;
  2. import android.content.Context;
  3. import com.artncore.WallPadDataMgr.WallpadStatusData;
  4. import com.artncore.WallPadDataMgr.wallpaddbmgr.AddressSet;
  5. import com.artncore.wallpadimap.RetProci;
  6. import com.artncore.wallpadimap.WallPadiMAPClient;
  7. public class iMAPSmartLightEvent extends WallPadiMAPClient
  8. {
  9. private static final String TAG = "iMAPSmartLightEvent";
  10. String myIP = "NONE";
  11. String myDong = "NONE";
  12. String myHo = "NONE";
  13. Context ctx;
  14. RetProci Proc;
  15. String XMLHeader;
  16. WallpadStatusData DBMGR;
  17. String ServerIP = "10.0.1.1";
  18. int SvrPort = 10000;
  19. public iMAPSmartLightEvent(Context ctx)
  20. {
  21. super.setContext(ctx);
  22. DBMGR = new WallpadStatusData(ctx);
  23. AddressSet addc = DBMGR.getAddressMGR(); // DB에서 동호 정보 받아옴
  24. DBMGR.closeDB();
  25. // 동, 호, ip 정보 저장
  26. myIP = addc.IPAddress;
  27. myDong = addc.Dong;
  28. myHo = addc.Ho;
  29. // 타임아웃 설정
  30. SetSocketWaitCount(2000);
  31. // XML Header 생성
  32. XMLHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<imap ver = \"1.0\" address = \"" + myIP + "\" sender = \"" + myDong + "동 " + myHo
  33. + "호" + "\">\r\n";
  34. this.ctx = ctx;
  35. }
  36. private String GetXMLSmartLightEvent(String Type, String Device, String DeviceIndex, String CauseType, String CauseDetail)
  37. {
  38. String retXML = "";
  39. retXML = XMLHeader
  40. + " <service type = \"request\" name= \"smart_light_event\">\r\n"
  41. + " <request_info name = \"homedev\" id_high=\"" + myDong + "\" id_low=\"" + myHo + "\" type=\"" + "main" + "\" />\r\n"
  42. + " <event "
  43. + "type=\"" + Type + "\" "
  44. + "device=\"" + Device + "\" "
  45. + "device_index=\"" + DeviceIndex + "\" "
  46. + "cause_type=\"" + CauseType + "\" "
  47. + "cause_detail=\"" + CauseDetail + "\" "
  48. + " />\r\n"
  49. + " </service>\r\n</imap>";
  50. return retXML;
  51. }
  52. public void SetServerIPcfg(String IPa, int port)
  53. {
  54. ServerIP = IPa;
  55. SvrPort = port;
  56. }
  57. public void SetRetCtr(RetProci retProci)
  58. {
  59. Proc = retProci;
  60. }
  61. @Override
  62. protected void ProcComplite()
  63. {
  64. if (Proc != null)
  65. {
  66. SetItem("service");
  67. String result = GetAttributeVal(0, "result");
  68. if (result != null)
  69. {
  70. if ((result.equalsIgnoreCase("ok")) || (result.equalsIgnoreCase("none")))
  71. {
  72. String name = GetAttributeVal(0, "name");
  73. String type = GetAttributeVal(0, "type");
  74. if ((name!=null && name.equalsIgnoreCase("smart_light_event")) && (type!=null && type.equalsIgnoreCase("reply")))
  75. {
  76. Proc.ProcSuccess();
  77. return;
  78. }
  79. }
  80. }
  81. }
  82. if(Proc!=null) Proc.ProcError();
  83. }
  84. @Override
  85. protected void ProcError()
  86. {
  87. Proc.ProcError();
  88. }
  89. /**
  90. * 스마트분전반 이상상태 알림 수행
  91. * **/
  92. public void DoWork(String Type, String Device, String DeviceIndex, String CauseType, String CauseDetail)
  93. {
  94. SetServerIPConfig(ServerIP, SvrPort);
  95. String XmlData = GetXMLSmartLightEvent(Type, Device, DeviceIndex, CauseType, CauseDetail);
  96. if(XmlData != null)
  97. {
  98. SendXMLDoc(XmlData, true);
  99. }
  100. }
  101. }