#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 center, nsSCF::SCF SCF) { m_SCF = SCF; EventCenter = center; m_CollimatorUnit.m_XRatio.reset(new XRATIOMould(0.0f, 0.0f, 1.0f, 0.01)); m_CollimatorUnit.m_YRatio.reset(new YRATIOMould(0.0f, 0.0f, 1.0f, 0.01)); 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)xproportion & 0xff; nHY = ((int)yproportion >> 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(int 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(int 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(int 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(int 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); }