PanelSerialXMLControl.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #include "stdafx.h"
  2. #include "PanelSerialXMLControl.h"
  3. PanelSerialXMLControl::PanelSerialXMLControl()
  4. {
  5. m_ResData.add(CcosPSLPanelType, "");
  6. m_ResData.add(CcosPSLPanelSerial, "");
  7. m_ResData.add(CcosPSLActive, "");
  8. m_ResData.add(CcosPSLIPAddress, "");
  9. m_ResData.add(CcosPSLCalibrationTime, "");
  10. m_ResData.add(CcosPSLPanelSize, "");
  11. m_strPanelXMLPath = "";
  12. }
  13. PanelSerialXMLControl::~PanelSerialXMLControl()
  14. {
  15. }
  16. bool PanelSerialXMLControl::SetPanelXMLPath(const char* strPanelXMLPath)
  17. {
  18. Thread_Lock();
  19. string strTem = strPanelXMLPath;
  20. if (m_strPanelXMLPath == strTem)
  21. {
  22. Thread_UnLock();
  23. return true;
  24. }
  25. m_strPanelXMLPath = strPanelXMLPath;
  26. if (!PathFileExists(strPanelXMLPath))
  27. {
  28. m_ResPanelSerialList.add("Document", "");
  29. m_ResPanelSerialList.SaveFile(m_strPanelXMLPath.c_str());
  30. Thread_UnLock();
  31. return true;
  32. }
  33. if (m_ResPanelSerialList.loadFile(strPanelXMLPath))
  34. {
  35. Thread_UnLock();
  36. return true;
  37. }
  38. Thread_UnLock();
  39. return false;
  40. }
  41. bool PanelSerialXMLControl::AddNewPanelSerial(PanelSerialList PSL)
  42. {
  43. Thread_Lock();
  44. try{
  45. int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey);
  46. int nIdx = (int)m_ResPanelSerialList["Document"].GetFirstOf(CcosPSLPanelKey);
  47. int i = 0;
  48. for (; i < nDPCCount; i++)
  49. {
  50. string strSN = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial];
  51. if (strSN == PSL.strPanelSN)
  52. {
  53. break;
  54. }
  55. nIdx = m_ResPanelSerialList["Document"].GetNextOf(CcosPSLPanelKey, nIdx);
  56. }
  57. if (i == nDPCCount)
  58. {
  59. //save 2 the config
  60. m_ResData[CcosPSLPanelType] = PSL.strPanelType.c_str();
  61. m_ResData[CcosPSLPanelSerial] = PSL.strPanelSN.c_str();
  62. m_ResData[CcosPSLActive] = PSL.strActive.c_str();
  63. m_ResData[CcosPSLIPAddress] = PSL.strIPAddress.c_str();
  64. m_ResData[CcosPSLCalibrationTime] = PSL.strCalibDate.c_str();
  65. m_ResData[CcosPSLPanelSize] = PSL.strPanelSize.c_str();
  66. m_ResPanelSerialList["Document"].add(CcosPSLPanelKey, m_ResData);
  67. }
  68. else if (i < nDPCCount)
  69. {
  70. m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelType] = PSL.strPanelType.c_str();
  71. m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial] = PSL.strPanelSN.c_str();
  72. m_ResPanelSerialList["Document"][nIdx][CcosPSLActive] = PSL.strActive.c_str();
  73. m_ResPanelSerialList["Document"][nIdx][CcosPSLIPAddress] = PSL.strIPAddress.c_str();
  74. m_ResPanelSerialList["Document"][nIdx][CcosPSLCalibrationTime] = PSL.strCalibDate.c_str();
  75. m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSize] = PSL.strPanelSize.c_str();
  76. }
  77. m_ResPanelSerialList.SaveFile(m_strPanelXMLPath.c_str());
  78. }
  79. catch (...)
  80. {
  81. Thread_UnLock();
  82. //printf("Add new panelserial failed, %s\r\n", e.what());
  83. return false;
  84. }
  85. Thread_UnLock();
  86. return true;
  87. }
  88. bool PanelSerialXMLControl::GetPanelSerialList(list<PanelSerialList> &listPanelSerial)
  89. {
  90. Thread_Lock();
  91. //重新加载一遍,避免多平板共享一个文件时,一块板修改了内容,另一个板还使用修改之前的内容
  92. if (!m_ResPanelSerialList.loadFile(m_strPanelXMLPath.c_str()))
  93. {
  94. Thread_UnLock();
  95. return false;
  96. }
  97. try{
  98. int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey);
  99. int nIdx = (int)m_ResPanelSerialList["Document"].GetFirstOf(CcosPSLPanelKey);
  100. int i = 0;
  101. for (; i < nDPCCount; i++)
  102. {
  103. PanelSerialList PSL;
  104. PSL.strActive = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLActive];
  105. PSL.strCalibDate = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLCalibrationTime];
  106. PSL.strIPAddress = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLIPAddress];
  107. PSL.strPanelSize = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSize];
  108. PSL.strPanelSN = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial];
  109. PSL.strPanelType = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelType];
  110. listPanelSerial.push_back(PSL);
  111. nIdx = m_ResPanelSerialList["Document"].GetNextOf(CcosPSLPanelKey, nIdx);
  112. }
  113. }
  114. catch (...)
  115. {
  116. Thread_UnLock();
  117. return false;
  118. }
  119. Thread_UnLock();
  120. return true;
  121. }
  122. bool PanelSerialXMLControl::ClearSNList()
  123. {
  124. Thread_Lock();
  125. try{
  126. int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey);
  127. int i = 0;
  128. for (; i < nDPCCount; i++)
  129. {
  130. m_ResPanelSerialList["Document"].eraseOneOf(CcosPSLPanelKey, i);
  131. }
  132. m_ResPanelSerialList.SaveFile(m_strPanelXMLPath.c_str());
  133. }
  134. catch (...)
  135. {
  136. Thread_UnLock();
  137. return false;
  138. }
  139. Thread_UnLock();
  140. return true;
  141. }
  142. bool PanelSerialXMLControl::GetActivedFDList(list<PanelSerialList> &listActivedFD)
  143. {
  144. Thread_Lock();
  145. try{
  146. int nDPCCount = (int)m_ResPanelSerialList["Document"].GetKeyCount(CcosPSLPanelKey);
  147. int nIdx = (int)m_ResPanelSerialList["Document"].GetFirstOf(CcosPSLPanelKey);
  148. int i = 0;
  149. for (; i < nDPCCount; i++)
  150. {
  151. string strActived = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLActive];
  152. if (strActived == "true")
  153. {
  154. PanelSerialList PSL;
  155. PSL.strActive = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLActive];
  156. PSL.strCalibDate = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLCalibrationTime];
  157. PSL.strIPAddress = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLIPAddress];
  158. PSL.strPanelSize = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSize];
  159. PSL.strPanelSN = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelSerial];
  160. PSL.strPanelType = (string)m_ResPanelSerialList["Document"][nIdx][CcosPSLPanelType];
  161. listActivedFD.push_back(PSL);
  162. }
  163. nIdx = m_ResPanelSerialList["Document"].GetNextOf(CcosPSLPanelKey, nIdx);
  164. }
  165. }
  166. catch (...)
  167. {
  168. Thread_UnLock();
  169. return false;
  170. }
  171. Thread_UnLock();
  172. return true;
  173. }