123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- #include "stdafx.h"
- #include "CommonFun.h"
- #include "CollimatorDevice.h"
- using namespace DIOS::Dev::Detail::Collimator;
- namespace nsSYN = DIOS::Dev::Detail::SYNBOX;
- //-----------------------------------------------------------------------------
- // DynBoxDevice
- //-----------------------------------------------------------------------------
- nsSYN::CollimatorDevice::CollimatorDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF)
- {
- m_SCF = SCF;
- EventCenter = center;
- m_CollimatorUnit.m_XSize.reset(new XSIZEMould(0, 0, 4300, 1));
- m_CollimatorUnit.m_YSize.reset(new YSIZEMould(0, 0, 4300, 1));
- m_CollimatorUnit.m_Filter.reset(new FILTERMould(0, 0, 5, 1));
- m_CollimatorUnit.m_SID.reset(new SIDMould(0, 0, 18000, 1));
- m_CollimatorUnit.m_Angle.reset(new ANGLEMould(0, 0, 360.0, 0.1));
- m_CollimatorUnit.m_Mode.reset(new MODEMould(0, 0, 6, 1));
- m_CollimatorUnit.m_Light.reset(new LIGHTMould(0, 0, 1, 1));
- }
- nsSYN::CollimatorDevice::~CollimatorDevice()
- {
- }
- void nsSYN::CollimatorDevice::Register(Dispatch* Dispatch)
- {
- super::Register(Dispatch);
- }
- void nsSYN::CollimatorDevice::OnCallback()
- {
-
- }
- RET_STATUS nsSYN::CollimatorDevice::SetCollimatorSize(float xproportion, float yproportion)
- {
- xproportion = xproportion * 100;
- yproportion = yproportion * 100;
- int cmdID = 0x641;
- unsigned char data[8];
- data[0] = 0x13;
- int nHX, nLX, nHY, nLY;
- nHX = ((int)xproportion >> 8) & 0xff;
- nLX = (int)yproportion & 0xff;
- nHY = ((int)xproportion >> 8) & 0xff;
- nLY = ((int)yproportion) & 0xff;
- data[1] = 0x03;
- data[2] = nLX; //X Y exchaned 20100420
- data[3] = nHX;
- data[4] = nLY;
- data[5] = nHY;
- //data[2] = 0xf1; //X Y exchaned 20100420
- //data[3] = 0x01;
- //data[4] = 0xf1;
- //data[5] = 0x01;
- data[6] = 0;//new public member
- data[7] = 0x0;
- SendCANBySCF(cmdID, &data[0], 8);
- Sleep(500);
- SendCANBySCF(cmdID, &data[0], 8);
- SetCollimatorLight(1);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsSYN::CollimatorDevice::SetCollimatorSID(unsigned short sid)
- {
- int nSID = sid * 100;
- int cmdID = 0x641;
- unsigned char data[3];
- data[0] = 0x11;
- int nHSID, nLSID;
- nHSID = ((int)nSID >> 8) & 0xff;
- nLSID = (int)nSID & 0xff;
- data[1] = nLSID; //X Y exchaned 20100420
- data[2] = nHSID;
- SendCANBySCF(cmdID, &data[0], 3);
- Sleep(500);
- SendCANBySCF(cmdID, &data[0], 3);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsSYN::CollimatorDevice::SetCollimatorFilter(unsigned short pParams)
- {
- int cmdID = 0x641;
- unsigned char data[8];
- data[0] = 0x13;
- int nHX, nLX, nHY, nLY, nFilter;
- nHX = (m_CollimatorUnit.m_XSize->Get() >> 8) & 0xff;
- nLX = m_CollimatorUnit.m_XSize->Get() & 0xff;
- nHY = (m_CollimatorUnit.m_YSize->Get() >> 8) & 0xff;
- nLY = (m_CollimatorUnit.m_YSize->Get()) & 0xff;
- nFilter = pParams;
- data[1] = 0x40;
- data[2] = nLX; //X Y exchaned 20100420
- data[3] = nHX;
- data[4] = nLY;
- data[5] = nHY;
- data[6] = nFilter;//new public member
- data[7] = 0x0;
- SendCANBySCF(cmdID, &data[0], 8);
- Sleep(500);
- SendCANBySCF(cmdID, &data[0], 8);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsSYN::CollimatorDevice::SetCollimatorAngle(float pParams)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsSYN::CollimatorDevice::SetCollimatorMode(unsigned short pParams)
- {
- int cmdID = 0x41;
- unsigned char data[8];
- data[0] = 0x1;
- data[1] = 0x0;
- data[2] = 0x6; //X Y exchaned 20100420
- SendCANBySCF(cmdID, &data[0], 3);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsSYN::CollimatorDevice::SetCollimatorLight(unsigned short pParams)
- {
- int cmdID = 0x641;
- unsigned char data[3];
- data[0] = 0x18;
- data[1] = 2; //X Y exchaned 20100420
- data[2] = 0;
- SendCANBySCF(cmdID, &data[0], 3);
- return RET_STATUS::RET_SUCCEED;
- }
- int nsSYN::CollimatorDevice::DealReceiveData(string sCmdID, const char* pData, int Datalen)
- {
- if (strtol(("0x" + sCmdID).c_str(), NULL, 16) == 0x626)
- {
- string strCmd = pData;
- if (strtol(("0x" + strCmd.substr(0, 2)).c_str(), NULL, 16) == 0x14)
- {
- bool bUpdateSize = false, bUpdateFilter = false;
- if (strtol(("0x" + strCmd.substr(3, 1)).c_str(), NULL, 16) & 0x01)
- {
- int nXSize = strtol(("0x" + strCmd.substr(4, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(6, 2)).c_str(), NULL, 16) * 256;
- bUpdateSize = true;
- nXSize = nXSize / 100;
-
- if (m_CollimatorUnit.m_XSize->Update(nXSize))
- {
- mLog::Info("m_nXSize = {$}", nXSize);
- FireNotify(m_CollimatorUnit.m_XSize->GetKey(), m_CollimatorUnit.m_XSize->JSGet());
- }
- }
- if (strtol(("0x" + strCmd.substr(3, 1)).c_str(), NULL, 16) & 0x02)
- {
- int nYSize = strtol(("0x" + strCmd.substr(8, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(10, 2)).c_str(), NULL, 16) * 256;
- nYSize = nYSize / 100;
- bUpdateSize = true;
-
- if (m_CollimatorUnit.m_YSize->Update(nYSize))
- {
- mLog::Info("m_nYSize = {$}", nYSize);
- FireNotify(m_CollimatorUnit.m_YSize->GetKey(), m_CollimatorUnit.m_YSize->JSGet());
- }
- }
- if (strtol(("0x" + strCmd.substr(2, 1)).c_str(), NULL, 16) & 0x04)
- {
- int nFilter = strtol(("0x" + strCmd.substr(12, 2)).c_str(), NULL, 16) + strtol(("0x" + strCmd.substr(14, 2)).c_str(), NULL, 16) * 256;
- bUpdateFilter = true;
- //printf("m_nFilter = %d\n", nFilter);
-
- if (m_CollimatorUnit.m_Filter->Update(nFilter))
- {
- mLog::Info("m_nFilter = {$}", nFilter);
- FireNotify(m_CollimatorUnit.m_Filter->GetKey(), m_CollimatorUnit.m_Filter->JSGet());
- }
- }
- }
- }
- return 1;
- }
- bool nsSYN::CollimatorDevice::SendCANBySCF(int cmdID, unsigned char* cmd, int cmdlen)
- {
- int nTimeout = 100;
- char cCmd[MAX_COMMAND_LEN] = "STLB";
- char str[20];
- sprintf_s(str, 3, "%02x", 10 + cmdlen * 2);
- cCmd[4] = str[0];
- cCmd[5] = str[1];
- sprintf_s(str, 10, "%08x", cmdID);
- for (int i = 0; i < 8; i++)
- {
- cCmd[6 + i] = str[i];
- }
- string CANProtocol = (string)ResDYNConfig["CANPortocol"];
- cCmd[14] = CANProtocol[0];
- sprintf_s(str, 4, "%x", cmdlen);
- cCmd[15] = str[0];
- for (int j = 0; j < cmdlen; j++)
- {
- sprintf_s(str, 4, "%02x", cmd[j]);
- cCmd[16 + (2 * j)] = str[0];
- cCmd[16 + (2 * j + 1)] = str[1];
- }
- int nCmdSize = 16 + 2 * cmdlen;
- FormatCmd(cCmd, nCmdSize);
- string strLog;
- CmdtoString(cCmd, nCmdSize, strLog);
- //PRINTA_INFO(m_pLog, "[Send:%s]", strLog.c_str());
- mLog::Info("==OUT==: {$}", cCmd);
- int ret = 0;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket(cCmd, nCmdSize, nTimeout, ret);
- Sleep(nTimeout);
- return true;
- }
- void nsSYN::CollimatorDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
|