CollimatorDevice.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #include "stdafx.h"
  2. #include "CommonFun.h"
  3. #include "CollimatorDevice.h"
  4. using namespace DIOS::Dev::Detail::Collimator;
  5. namespace nsSYN = DIOS::Dev::Detail::SYNBOX;
  6. //-----------------------------------------------------------------------------
  7. // DynBoxDevice
  8. //-----------------------------------------------------------------------------
  9. nsSYN::CollimatorDevice::CollimatorDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF)
  10. {
  11. m_SCF = SCF;
  12. EventCenter = center;
  13. m_CollimatorUnit.m_XRatio.reset(new XRATIOMould(0.0f, 0.0f, 1.0f, 0.01));
  14. m_CollimatorUnit.m_YRatio.reset(new YRATIOMould(0.0f, 0.0f, 1.0f, 0.01));
  15. m_CollimatorUnit.m_XSize.reset(new XSIZEMould(0, 0, 4300, 1));
  16. m_CollimatorUnit.m_YSize.reset(new YSIZEMould(0, 0, 4300, 1));
  17. m_CollimatorUnit.m_Filter.reset(new FILTERMould(0, 0, 5, 1));
  18. m_CollimatorUnit.m_SID.reset(new SIDMould(0, 0, 18000, 1));
  19. m_CollimatorUnit.m_Angle.reset(new ANGLEMould(0, 0, 360.0, 0.1));
  20. m_CollimatorUnit.m_Mode.reset(new MODEMould(0, 0, 6, 1));
  21. m_CollimatorUnit.m_Light.reset(new LIGHTMould(0, 0, 1, 1));
  22. }
  23. nsSYN::CollimatorDevice::~CollimatorDevice()
  24. {
  25. }
  26. void nsSYN::CollimatorDevice::Register(Dispatch* Dispatch)
  27. {
  28. super::Register(Dispatch);
  29. }
  30. void nsSYN::CollimatorDevice::OnCallback()
  31. {
  32. }
  33. RET_STATUS nsSYN::CollimatorDevice::SetCollimatorSize(float xproportion, float yproportion)
  34. {
  35. xproportion = xproportion * 100;
  36. yproportion = yproportion * 100;
  37. int cmdID = 0x641;
  38. unsigned char data[8];
  39. data[0] = 0x13;
  40. int nHX, nLX, nHY, nLY;
  41. nHX = ((int)xproportion >> 8) & 0xff;
  42. nLX = (int)xproportion & 0xff;
  43. nHY = ((int)yproportion >> 8) & 0xff;
  44. nLY = ((int)yproportion) & 0xff;
  45. data[1] = 0x03;
  46. data[2] = nLX; //X Y exchaned 20100420
  47. data[3] = nHX;
  48. data[4] = nLY;
  49. data[5] = nHY;
  50. //data[2] = 0xf1; //X Y exchaned 20100420
  51. //data[3] = 0x01;
  52. //data[4] = 0xf1;
  53. //data[5] = 0x01;
  54. data[6] = 0;//new public member
  55. data[7] = 0x0;
  56. SendCANBySCF(cmdID, &data[0], 8);
  57. Sleep(500);
  58. SendCANBySCF(cmdID, &data[0], 8);
  59. SetCollimatorLight(1);
  60. return RET_STATUS::RET_SUCCEED;
  61. }
  62. RET_STATUS nsSYN::CollimatorDevice::SetCollimatorSID(int sid)
  63. {
  64. int nSID = sid * 100;
  65. int cmdID = 0x641;
  66. unsigned char data[3];
  67. data[0] = 0x11;
  68. int nHSID, nLSID;
  69. nHSID = ((int)nSID >> 8) & 0xff;
  70. nLSID = (int)nSID & 0xff;
  71. data[1] = nLSID; //X Y exchaned 20100420
  72. data[2] = nHSID;
  73. SendCANBySCF(cmdID, &data[0], 3);
  74. Sleep(500);
  75. SendCANBySCF(cmdID, &data[0], 3);
  76. return RET_STATUS::RET_SUCCEED;
  77. }
  78. RET_STATUS nsSYN::CollimatorDevice::SetCollimatorFilter(int pParams)
  79. {
  80. int cmdID = 0x641;
  81. unsigned char data[8];
  82. data[0] = 0x13;
  83. int nHX, nLX, nHY, nLY, nFilter;
  84. nHX = (m_CollimatorUnit.m_XSize->Get() >> 8) & 0xff;
  85. nLX = m_CollimatorUnit.m_XSize->Get() & 0xff;
  86. nHY = (m_CollimatorUnit.m_YSize->Get() >> 8) & 0xff;
  87. nLY = (m_CollimatorUnit.m_YSize->Get()) & 0xff;
  88. nFilter = pParams;
  89. data[1] = 0x40;
  90. data[2] = nLX; //X Y exchaned 20100420
  91. data[3] = nHX;
  92. data[4] = nLY;
  93. data[5] = nHY;
  94. data[6] = nFilter;//new public member
  95. data[7] = 0x0;
  96. SendCANBySCF(cmdID, &data[0], 8);
  97. Sleep(500);
  98. SendCANBySCF(cmdID, &data[0], 8);
  99. return RET_STATUS::RET_SUCCEED;
  100. }
  101. RET_STATUS nsSYN::CollimatorDevice::SetCollimatorAngle(float pParams)
  102. {
  103. return RET_STATUS::RET_SUCCEED;
  104. }
  105. RET_STATUS nsSYN::CollimatorDevice::SetCollimatorMode(int pParams)
  106. {
  107. int cmdID = 0x41;
  108. unsigned char data[8];
  109. data[0] = 0x1;
  110. data[1] = 0x0;
  111. data[2] = 0x6; //X Y exchaned 20100420
  112. SendCANBySCF(cmdID, &data[0], 3);
  113. return RET_STATUS::RET_SUCCEED;
  114. }
  115. RET_STATUS nsSYN::CollimatorDevice::SetCollimatorLight(int pParams)
  116. {
  117. int cmdID = 0x641;
  118. unsigned char data[3];
  119. data[0] = 0x18;
  120. data[1] = 2; //X Y exchaned 20100420
  121. data[2] = 0;
  122. SendCANBySCF(cmdID, &data[0], 3);
  123. return RET_STATUS::RET_SUCCEED;
  124. }
  125. int nsSYN::CollimatorDevice::DealReceiveData(string sCmdID, const char* pData, int Datalen)
  126. {
  127. if (strtol(("0x" + sCmdID).c_str(), NULL, 16) == 0x626)
  128. {
  129. string strCmd = pData;
  130. if (strtol(("0x" + strCmd.substr(0, 2)).c_str(), NULL, 16) == 0x14)
  131. {
  132. bool bUpdateSize = false, bUpdateFilter = false;
  133. if (strtol(("0x" + strCmd.substr(3, 1)).c_str(), NULL, 16) & 0x01)
  134. {
  135. int nXSize = strtol(("0x" + strCmd.substr(4, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(6, 2)).c_str(), NULL, 16) * 256;
  136. bUpdateSize = true;
  137. nXSize = nXSize / 100;
  138. if (m_CollimatorUnit.m_XSize->Update(nXSize))
  139. {
  140. mLog::Info("m_nXSize = {$}", nXSize);
  141. FireNotify(m_CollimatorUnit.m_XSize->GetKey(), m_CollimatorUnit.m_XSize->JSGet());
  142. }
  143. }
  144. if (strtol(("0x" + strCmd.substr(3, 1)).c_str(), NULL, 16) & 0x02)
  145. {
  146. int nYSize = strtol(("0x" + strCmd.substr(8, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(10, 2)).c_str(), NULL, 16) * 256;
  147. nYSize = nYSize / 100;
  148. bUpdateSize = true;
  149. if (m_CollimatorUnit.m_YSize->Update(nYSize))
  150. {
  151. mLog::Info("m_nYSize = {$}", nYSize);
  152. FireNotify(m_CollimatorUnit.m_YSize->GetKey(), m_CollimatorUnit.m_YSize->JSGet());
  153. }
  154. }
  155. if (strtol(("0x" + strCmd.substr(2, 1)).c_str(), NULL, 16) & 0x04)
  156. {
  157. int nFilter = strtol(("0x" + strCmd.substr(12, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(14, 2)).c_str(), NULL, 16) * 256;
  158. bUpdateFilter = true;
  159. //printf("m_nFilter = %d\n", nFilter);
  160. if (m_CollimatorUnit.m_Filter->Update(nFilter))
  161. {
  162. mLog::Info("m_nFilter = {$}", nFilter);
  163. FireNotify(m_CollimatorUnit.m_Filter->GetKey(), m_CollimatorUnit.m_Filter->JSGet());
  164. }
  165. }
  166. }
  167. }
  168. return 1;
  169. }
  170. bool nsSYN::CollimatorDevice::SendCANBySCF(int cmdID, unsigned char* cmd, int cmdlen)
  171. {
  172. int nTimeout = 100;
  173. char cCmd[MAX_COMMAND_LEN] = "STLB";
  174. char str[20];
  175. sprintf_s(str, 3, "%02x", 10 + cmdlen * 2);
  176. cCmd[4] = str[0];
  177. cCmd[5] = str[1];
  178. sprintf_s(str, 10, "%08x", cmdID);
  179. for (int i = 0; i < 8; i++)
  180. {
  181. cCmd[6 + i] = str[i];
  182. }
  183. string CANProtocol = (string)ResDYNConfig["CANPortocol"];
  184. cCmd[14] = CANProtocol[0];
  185. sprintf_s(str, 4, "%x", cmdlen);
  186. cCmd[15] = str[0];
  187. for (int j = 0; j < cmdlen; j++)
  188. {
  189. sprintf_s(str, 4, "%02x", cmd[j]);
  190. cCmd[16 + (2 * j)] = str[0];
  191. cCmd[16 + (2 * j + 1)] = str[1];
  192. }
  193. int nCmdSize = 16 + 2 * cmdlen;
  194. FormatCmd(cCmd, nCmdSize);
  195. string strLog;
  196. CmdtoString(cCmd, nCmdSize, strLog);
  197. //PRINTA_INFO(m_pLog, "[Send:%s]", strLog.c_str());
  198. mLog::Info("==OUT==: {$}", cCmd);
  199. int ret = 0;
  200. m_SCF.Lock(msTimeOut_Lock)
  201. .SendPacket(cCmd, nCmdSize, nTimeout, ret);
  202. Sleep(nTimeout);
  203. return true;
  204. }
  205. void nsSYN::CollimatorDevice::FireNotify(std::string key, std::string content)
  206. {
  207. EventCenter->OnNotify(1, key, content);
  208. }