DIOS.Dev.Mech.WDMAMMOCAN.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
  1. #include "stdafx.h"
  2. #include <assert.h>
  3. #include "Helper.JSON.hpp"
  4. #include "DIOS.Dev.Mech.WDMAMMOCAN.hpp"
  5. using namespace DIOS::Dev;
  6. using namespace DIOS::Dev::Detail::MECH;
  7. namespace nsMech = DIOS::Dev::Detail::MECH;
  8. #pragma warning (disable:4305)
  9. //CAN ---------------------------------------------------------------
  10. #if 1
  11. //#include "stdafx.h"
  12. //#include "resource.h"
  13. //#include "CANPort.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #define new DEBUG_NEW
  18. #endif
  19. //#include "Table.h"
  20. //#include "Aqmodule.h"
  21. //#include ".\Generator\GeneratorD100.h"
  22. #include "Usbcan\SimulateCan.h"
  23. //#include "ReplaceYaoTai.h"
  24. //CTable* CCANPort::m_pTable = NULL;
  25. //CReplaceYaoTai* CCANPort::m_pReplaceYaoTai = NULL;
  26. //////////////////////////////////////////////////////////////////////
  27. // Construction/Destruction
  28. //////////////////////////////////////////////////////////////////////
  29. //-----------------------------------------------------
  30. //参数:
  31. //chr:要转换的字符
  32. //cint:储存转换过来的数据
  33. //函数功能:字符转换为数据
  34. //-----------------------------------------------------
  35. int chartoint(unsigned char chr, unsigned char* cint)//CCANPort::
  36. {
  37. unsigned char cTmp;
  38. cTmp = chr - 48; //0-9
  39. if (cTmp >= 0 && cTmp <= 9)
  40. {
  41. *cint = cTmp;
  42. return 0;
  43. }
  44. cTmp = chr - 65;//A-F
  45. if (cTmp >= 0 && cTmp <= 5)
  46. {
  47. *cint = (cTmp + 10);
  48. return 0;
  49. }
  50. cTmp = chr - 97;//a-f
  51. if (cTmp >= 0 && cTmp <= 5)
  52. {
  53. *cint = (cTmp + 10);
  54. return 0;
  55. }
  56. return 1;
  57. }
  58. //-----------------------------------------------------
  59. //参数:
  60. //str:要转换的字符串
  61. //data:储存转换过来的数据串
  62. //len:数据长度
  63. //函数功能:字符串转换为数据串
  64. //-----------------------------------------------------
  65. int strtodata(unsigned char* str, unsigned char* data, int len, int flag)//CCANPort::
  66. {
  67. unsigned char cTmp = 0;
  68. int i = 0;
  69. for (int j = 0; j < len; j++)
  70. {
  71. if (chartoint(str[i++], &cTmp))
  72. return 1;
  73. data[j] = cTmp;
  74. if (chartoint(str[i++], &cTmp))
  75. return 1;
  76. data[j] = (data[j] << 4) + cTmp;
  77. if (flag == 1)
  78. i++;
  79. }
  80. return 0;
  81. }
  82. nsMech::CCANPort::CCANPort()
  83. {
  84. //init_config
  85. m_pTableCtrl = nullptr;
  86. m_devtype = 0;
  87. m_devind = 0;
  88. //can number
  89. m_cannum = 0;
  90. //about thread
  91. m_bCANThreadActive = FALSE;
  92. m_Thread = NULL;
  93. //can start flag
  94. m_bCanStart = FALSE;
  95. m_hCANWindowHandle = NULL;
  96. m_nAngleDirection = 0;
  97. m_pCANEx = nullptr;
  98. int m_nCANType = 0;
  99. switch (m_nCANType)
  100. {
  101. case 0:
  102. m_pCANEx = new CZLG;
  103. break;
  104. case 1:
  105. m_pCANEx = new CPC;
  106. break;
  107. case 2:
  108. m_pCANEx = new CJY;
  109. case 9:
  110. m_pCANEx = new CSimulateCan;
  111. break;
  112. default:
  113. break;
  114. }
  115. }
  116. nsMech::CCANPort::~CCANPort()
  117. {
  118. if (m_Thread != NULL)
  119. {
  120. if (m_bCANThreadActive)
  121. m_bCANThreadActive = FALSE;
  122. }
  123. CAN_Close();
  124. if (m_pCANEx)
  125. {
  126. delete m_pCANEx;
  127. m_pCANEx = NULL;
  128. }
  129. }
  130. BOOL nsMech::CCANPort::CAN_Open(/*int DeviceType,*/DWORD DeviceInd, int Reserved)
  131. {
  132. // m_devtype = DeviceType;
  133. m_devind = DeviceInd;
  134. INT nFlag = 0;
  135. // while(VCI_OpenDevice(m_devtype,m_devind,Reserved) != STATUS_OK)
  136. if (!m_pCANEx->LoadDLL())
  137. {
  138. return FALSE;
  139. }
  140. while (m_pCANEx->OpenDevice(m_devind) != STATUS_OK)
  141. {
  142. if (2 == nFlag++)
  143. {
  144. return FALSE;
  145. }
  146. Sleep(1000);
  147. }
  148. return TRUE;
  149. }
  150. bool nsMech::CCANPort::CAN_Start()
  151. {
  152. //if(VCI_StartCAN(m_devtype,m_devind,m_cannum)==1)
  153. if (m_pCANEx->StartCAN(m_devind, m_cannum) == 1)
  154. {
  155. m_bCanStart = TRUE;
  156. return true;
  157. }
  158. else
  159. {
  160. return false;
  161. }
  162. }
  163. bool nsMech::CCANPort::CAN_Reset()
  164. {
  165. //2007.11.19_此函数用来复位CAN
  166. //if(VCI_ResetCAN(m_devtype,m_devind,m_cannum) == 1)
  167. if (m_pCANEx->ResetCAN(m_devind, m_cannum) == 1)
  168. {
  169. m_bCanStart = FALSE;
  170. return true;
  171. }
  172. else
  173. {
  174. //VCI_CloseDevice(m_devtype,m_devind);
  175. m_pCANEx->CloseDevice(m_devind);
  176. m_bCanStart = FALSE;
  177. return false;
  178. }
  179. }
  180. void nsMech::CCANPort::CAN_Close()
  181. {
  182. if (!m_bCanStart)
  183. return;
  184. m_bCanStart = FALSE;
  185. Sleep(100);
  186. m_pCANEx->CloseDevice(m_devind);
  187. }
  188. BOOL nsMech::CCANPort::CAN_Init(HWND hWnd, DWORD dwAccCode, DWORD dwAccMask, UCHAR ucFilter, UCHAR ucMode, UCHAR ucTiming0, UCHAR ucTiming1, int nCannum)
  189. {
  190. m_hCANWindowHandle = hWnd; //0
  191. init_config.AccCode = dwAccCode; //0 验收码
  192. init_config.AccMask = dwAccMask; //ffffffff 屏蔽码
  193. init_config.Filter = ucFilter; //1 滤波方式:单滤/双滤0/1
  194. init_config.Mode = ucMode; //0 模式:正常/只听,0/1
  195. init_config.Timing0 = ucTiming0; //TIMING0 定时器1 timing0;
  196. init_config.Timing1 = ucTiming1; //TIMING1
  197. m_cannum = nCannum; //nCannum
  198. //初始化CAN
  199. if (m_pCANEx->InitCAN(m_devind, m_cannum, &init_config) != STATUS_OK)
  200. {
  201. //VCI_CloseDevice(m_devtype,m_devind);
  202. m_pCANEx->CloseDevice(m_devind);
  203. return false;
  204. }
  205. //开启接收线程
  206. DWORD m_HardwareStatusID;
  207. m_Thread = CreateThread(0, 0, ReceiveThread, this, 0, (LPDWORD)m_HardwareStatusID);
  208. if (m_Thread == NULL)
  209. {
  210. mLog::Fatal("Start HardwareStatus Thread Failed");
  211. return false;
  212. }
  213. return TRUE;
  214. }
  215. bool nsMech::CCANPort::CAN_transmit(string strData, string strFrmID, BYTE RomoteFlag/*= 0*/, BYTE ExternFlag/*= 0*/, BYTE type/*=1*/)
  216. {
  217. VCI_CAN_OBJ frameinfo;
  218. BYTE FrameID[4] = { 0,0,0,0 };
  219. char szFrameID[9];
  220. memset(szFrameID, '0', 9);
  221. unsigned char Data[8];
  222. char szData[25];
  223. BYTE datalen = 0;
  224. //帧ID占4个字节,用16进制表示:0x21A09878,字符表示长度为8,----------------------here ,maybe not right.because as i know frameID =4.
  225. if (strFrmID.length() > 8)
  226. {
  227. return false;
  228. }
  229. //if (strFrmID.GetLength() > 8)
  230. //{
  231. // return false;
  232. //}
  233. //发送数据,16进制表示,每个数无空格, 即:"01A1098070000000",最多16个数
  234. //if (strData.GetLength() > 16)
  235. if (strData.length() > 16)
  236. {
  237. return false;
  238. }
  239. //发送帧类型:标准,扩展
  240. if (ExternFlag == 0)//标准帧
  241. {
  242. if (strData.length() % 2 == 1)//。。。?
  243. {
  244. return false;
  245. }
  246. }
  247. //copy 到低位
  248. memcpy(&szFrameID[8 - strFrmID.length()], strFrmID.c_str(), strFrmID.length());
  249. strtodata((unsigned char*)szFrameID, FrameID, 4, 0);
  250. //发送数据是16进制表示,每个数据之间有空格
  251. datalen = (strData.length()) / 2;//实际个数
  252. strcpy(szData, strData.c_str());
  253. strtodata((unsigned char*)szData, Data, datalen, 0);
  254. frameinfo.DataLen = datalen;
  255. memcpy(&frameinfo.Data, Data, datalen);
  256. frameinfo.RemoteFlag = RomoteFlag;//数据帧/远程帧
  257. frameinfo.ExternFlag = ExternFlag;
  258. frameinfo.TimeFlag = 0;
  259. frameinfo.TimeStamp = 0;
  260. //帧类型约束帧ID的实际占有位数
  261. if (frameinfo.ExternFlag == 1)
  262. {
  263. frameinfo.ID = ((DWORD)FrameID[0] << 24) + ((DWORD)FrameID[1] << 16) + ((DWORD)FrameID[2] << 8) +
  264. ((DWORD)FrameID[3]);
  265. }
  266. else
  267. {
  268. frameinfo.ID = ((DWORD)FrameID[2] << 8) + ((DWORD)FrameID[3]);
  269. }
  270. frameinfo.SendType = type;//发送格式:单发。。
  271. CCAN* p = m_pCANEx;
  272. if (m_pCANEx->Transmit(m_devind, m_cannum, &frameinfo, 1) == 1)
  273. {
  274. return true;
  275. }
  276. else
  277. {
  278. Sleep(20);
  279. if (m_pCANEx->Transmit(m_devind, m_cannum, &frameinfo, 1) == 1)
  280. return true;
  281. else
  282. {
  283. return false;
  284. }
  285. }
  286. return false;
  287. }
  288. DWORD nsMech::CCANPort::ReceiveThread(void* param)
  289. {
  290. CCANPort* port = (CCANPort*)param;
  291. VCI_CAN_OBJ frameinfo[50];
  292. VCI_ERR_INFO errinfo;
  293. string strFrmID;
  294. int nRecvDataLen = 1;
  295. string str;
  296. string strData;
  297. char recvbuf[10]{ 0,0,0,0,0,0,0,0,0,0 };
  298. port->m_bCANThreadActive = true;
  299. while (port->m_bCANThreadActive)
  300. {
  301. if (port == NULL) { return 0; }
  302. Sleep(4);
  303. nRecvDataLen = port->m_pCANEx->Receive(port->m_devind, port->m_cannum, frameinfo, 50, 200);
  304. if (nRecvDataLen == 0xffffffff)
  305. {
  306. port->m_pCANEx->ReadErrInfo(port->m_devind, port->m_cannum, &errinfo);
  307. }
  308. else
  309. {
  310. //str.Format("frameinfo->ID=%X,frameinfo->DataLen=%d, [%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X]",
  311. recvbuf[0] = frameinfo->ID;
  312. recvbuf[1] = frameinfo->DataLen;
  313. recvbuf[2] = frameinfo->Data[0];
  314. recvbuf[3] = frameinfo->Data[1];
  315. recvbuf[4] = frameinfo->Data[2];
  316. recvbuf[5] = frameinfo->Data[3];
  317. recvbuf[6] = frameinfo->Data[4];
  318. recvbuf[7] = frameinfo->Data[5];
  319. recvbuf[8] = frameinfo->Data[6];
  320. recvbuf[9] = frameinfo->Data[7];
  321. //port->m_pTableCtrl->m_pLog->WriteLog(str);
  322. mLog::Info("CAN recv data:{$}\n", recvbuf);
  323. if (frameinfo->ID == 0x405 && frameinfo->DataLen == 8)//立柱板节点
  324. {
  325. #pragma region ID405
  326. if (frameinfo->Data[1] == 1)
  327. {
  328. mLog::Info("recv Column heart beat.");
  329. }
  330. if (frameinfo->Data[1] == 2)
  331. {
  332. //配置信息回复
  333. int nPanelType = frameinfo->Data[2];//平板选择
  334. int nAngle = frameinfo->Data[3];//C臂ML0位:角度
  335. mLog::Info("recv : panel type:{$},C臂ML0位:角度={$}", nPanelType, nAngle);
  336. //port->m_pTableCtrl->m_pLog->WriteLog(str);
  337. }
  338. if (frameinfo->Data[1] == 3)
  339. {
  340. //曝光模式回复
  341. int nExpMode = frameinfo->Data[2];
  342. int nAECfield = frameinfo->Data[3];
  343. int nAECDensity = frameinfo->Data[4];
  344. mLog::Info("recv: exp mode:{$},AEC field={$},AEC density={$}", nExpMode, nAECfield, nAECDensity);
  345. }
  346. if (frameinfo->Data[1] == 4 && frameinfo->Data[2] == 0x61)
  347. {
  348. mLog::Info("recv ANRAN panel ready or not.");
  349. }
  350. if (frameinfo->Data[2] == 0x10)
  351. {
  352. mLog::Info("recv panel ready status");
  353. }
  354. if (frameinfo->Data[2] == 0x20)
  355. {
  356. mLog::Info("recv gen ready status");
  357. }
  358. if (frameinfo->Data[2] == 0x30)
  359. {
  360. mLog::Info("recv exp start");
  361. }
  362. if (frameinfo->Data[2] == 0x40)
  363. {
  364. mLog::Info("recv exp finished");
  365. }
  366. if (frameinfo->Data[2] == 0x50)
  367. {
  368. mLog::Info("recv workflow finished.");
  369. }
  370. #if 0
  371. int sid = (int)(frameinfo->Data[2] * 256 + frameinfo->Data[3]);
  372. port->m_pTableCtrl->m_nSID = sid;
  373. port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_SID, sid, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFOC);
  374. port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_SID, sid, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFHARDWARE);
  375. int _collimatorWsize = (int)(frameinfo->Data[4] * 256 + frameinfo->Data[5]);
  376. int _collimatorHsize = (int)(frameinfo->Data[6] * 256 + frameinfo->Data[7]);
  377. port->m_pTableCtrl->m_nCollRealWSize = _collimatorWsize;
  378. port->m_pTableCtrl->m_nCollRealHSize = _collimatorHsize;
  379. CString strlog;
  380. strlog.Format("feedback collimator real size: id=0x7f0, height=%d mm,width=%d mm, sid=%d cm.", _collimatorHsize, _collimatorWsize, sid);
  381. port->m_pTableCtrl->m_pLog->WriteLog(strlog, LOG_INFORMATION);
  382. int virtual_Wsize = 1;
  383. int virtual_Hsize = 1;
  384. if (port->m_pTableCtrl->m_nZoomMode == 0)//17*17
  385. {
  386. virtual_Wsize = int(_collimatorWsize / port->m_pTableCtrl->m_fHcoefficient / 10 / port->m_pTableCtrl->m_nFrontPartSID * port->m_pTableCtrl->m_nSID + 0.5);
  387. virtual_Hsize = int(_collimatorHsize / port->m_pTableCtrl->m_fVcoefficient / 10 / port->m_pTableCtrl->m_nFrontPartSID * port->m_pTableCtrl->m_nSID + 0.5);
  388. }
  389. else if (port->m_pTableCtrl->m_nZoomMode == 1)//9*9
  390. {
  391. virtual_Wsize = int(_collimatorWsize / port->m_pTableCtrl->m_fHcoefficientZoom1 / 10 / port->m_pTableCtrl->m_nFrontPartSID * port->m_pTableCtrl->m_nSID + 0.5);
  392. virtual_Hsize = int(_collimatorHsize / port->m_pTableCtrl->m_fVcoefficientZoom1 / 10 / port->m_pTableCtrl->m_nFrontPartSID * port->m_pTableCtrl->m_nSID + 0.5);
  393. }
  394. strlog.Format("feedback collimator virtual size: id=0x7f0, height=%d cm,width=%d cm", virtual_Hsize, virtual_Wsize);
  395. port->m_pTableCtrl->m_pLog->WriteLog(strlog, LOG_INFORMATION);
  396. if (port->m_pTableCtrl->m_pWnd != nullptr)
  397. {
  398. port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_COLLIMATOR, _collimatorWsize + _collimatorHsize * 100, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFOC);
  399. port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_COLLIMATOR, _collimatorWsize + _collimatorHsize * 100, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFHARDWARE);
  400. }
  401. else
  402. {
  403. port->m_pTableCtrl->m_pLog->WriteLog("port->m_pTableCtrl->m_pWnd == nullptr", LOG_INFORMATION);
  404. }
  405. #endif // 0
  406. #pragma endregion
  407. }
  408. else if (frameinfo->ID == 0x425)//C臂控制板节点
  409. {
  410. #pragma region ID425
  411. if (frameinfo->Data[0] == 0)
  412. {
  413. if (frameinfo->Data[1] == 0x18)
  414. {
  415. mLog::Info("recv 双电位器错误 or not.Data[2]决定.");
  416. }
  417. if (frameinfo->Data[1] == 0x06)
  418. {
  419. int nAngleSignal = frameinfo->Data[2];
  420. int nAngleValue = frameinfo->Data[3];
  421. if (2 == nAngleSignal)//负
  422. {
  423. nAngleValue *= -1;
  424. }
  425. mLog::Info("recv C 臂旋转角度:{$}", nAngleValue);
  426. //port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_COLL_ANGLE, nAngleValue, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFOC);
  427. //port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_COLL_ANGLE, nAngleValue, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFHARDWARE);
  428. }
  429. }
  430. if (frameinfo->Data[1] == 1)
  431. {
  432. if (frameinfo->Data[1] == 1)
  433. {
  434. mLog::Info("recv C arm heart beat.");
  435. }
  436. if (frameinfo->Data[1] == 2)
  437. {
  438. int nPrePressLimitValue = frameinfo->Data[2];
  439. int nTotalPressLimitValue = frameinfo->Data[3];
  440. mLog::Info("nPrePressLimitValue={$},nTotalPressLimitValue={$}", nPrePressLimitValue, nTotalPressLimitValue);
  441. }
  442. if (frameinfo->Data[1] == 3)
  443. {
  444. int nPressType = frameinfo->Data[2];
  445. int nReleaseType = frameinfo->Data[3];
  446. mLog::Info("recv:press type={$},release type={$}", nPressType, nReleaseType);
  447. }
  448. if (frameinfo->Data[1] == 4)
  449. {
  450. //振栅模式
  451. int nGridType = frameinfo->Data[2];
  452. mLog::Info("Grid Type={$}", nGridType);
  453. }
  454. if (frameinfo->Data[1] == 5)
  455. {
  456. int nPressThickness = frameinfo->Data[2];
  457. int nPressValue = frameinfo->Data[3];
  458. mLog::Info("recv:nPressThickness={$},nPressValue={$}", nPressThickness, nPressValue);
  459. if (port->m_pTableCtrl->m_MAMMOMECHUnit.m_Mammo_Thickness->Update(nPressThickness))
  460. {
  461. strData = frameinfo->Data[2];
  462. port->m_pTableCtrl->FireNotify(AttrKey::MAMMO_THICKNESS, strData);
  463. }
  464. if (port->m_pTableCtrl->m_MAMMOMECHUnit.m_Mammo_PressureValue->Update(nPressValue))
  465. {
  466. strData = frameinfo->Data[3];
  467. port->m_pTableCtrl->FireNotify(AttrKey::MAMMO_PRESSVAL, strData);
  468. }
  469. }
  470. if (frameinfo->Data[1] == 6)
  471. {
  472. int nCollLong = frameinfo->Data[2] * 256 + frameinfo->Data[3];
  473. int nCollCross = frameinfo->Data[4] * 256 + frameinfo->Data[5];
  474. mLog::Info("recv:nCollLong={$},nCollCross={$}", nCollLong, nCollCross);
  475. //port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_COLLIMATOR, nCollLong*100 + nCollCross, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFOC);
  476. //port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_COLLIMATOR, nCollLong*100 + nCollCross, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFHARDWARE);
  477. }
  478. if (frameinfo->Data[1] == 7)
  479. {
  480. int nFilter = frameinfo->Data[2];
  481. //port->m_pTableCtrl->m_nFilterSet = nFilter;
  482. mLog::Info("recv:Filter is {$},(1:Mo,2Rh)", nFilter);
  483. //port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_FILTER, port->m_pTableCtrl->m_nFilterSet, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFOC);
  484. //port->m_pTableCtrl->MSGControl(port->m_pTableCtrl->m_pWnd, ECOM_MSG_RFMC_PARAMOUT, ECOM_MECHCOMP_PA_FILTER, port->m_pTableCtrl->m_nFilterSet, ECOM_MSG_TYPE_SYNC_NO, ECOM_MSG_TARGETHANDLE_RFHARDWARE);
  485. }
  486. if (frameinfo->Data[1] == 12)
  487. {
  488. if (frameinfo->Data[2] == 0)
  489. {
  490. mLog::Info("recv 无错误");
  491. }
  492. if (frameinfo->Data[2] == 1)
  493. {
  494. mLog::Info("recv:压迫其初始化未到位 ");
  495. }
  496. if (frameinfo->Data[2] == 2)
  497. {
  498. mLog::Info("recv 压迫器上限位错误");
  499. }
  500. if (frameinfo->Data[2] == 3)
  501. {
  502. mLog::Info("recv 过压错误");
  503. }
  504. if (frameinfo->Data[2] == 4)
  505. {
  506. mLog::Info("recv 过流错误");
  507. }
  508. if (frameinfo->Data[2] == 5)
  509. {
  510. mLog::Info("recv 自动释放未完成");
  511. }
  512. if (frameinfo->Data[2] == 6)
  513. {
  514. mLog::Info("recv 限束器初始化成功");
  515. }
  516. if (frameinfo->Data[2] == 7)
  517. {
  518. mLog::Info("recv 压迫释放完成");
  519. }
  520. }
  521. if (frameinfo->Data[1] == 0x19)
  522. {
  523. int nPressBoardType = frameinfo->Data[2];
  524. mLog::Info("recv:nPressBoardType={$}", nPressBoardType);
  525. }
  526. }
  527. #pragma endregion
  528. }
  529. else if (frameinfo->ID == 0x485)//振动栅节点
  530. {
  531. #pragma region ID485
  532. //0x485 故障报文 4 3 故障状态:0.正确 ;1.初始化错误; 振栅板发送给图像
  533. if (frameinfo->Data[0] == 4)
  534. {
  535. if (frameinfo->Data[1] == 3)
  536. {
  537. int nStatus = frameinfo->Data[2];
  538. mLog::Info("recv:Grid Status={$}", nStatus);
  539. }
  540. }
  541. #pragma endregion
  542. }
  543. }
  544. }
  545. return 0;
  546. }
  547. #endif // 1
  548. //CAN---------------------------------------------------------------****************************************************
  549. //-----------------------------------------------------------------------------
  550. // WDMAMMOCANDevice
  551. //-----------------------------------------------------------------------------
  552. string GetProcessDirectory()
  553. {
  554. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  555. string ret = "";
  556. char szFilename[MAX_PATH] = { 0 };
  557. DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
  558. if (res == 0)
  559. {
  560. return ret;
  561. }
  562. string fullpath = szFilename;
  563. string::size_type firstHit = fullpath.find_last_of('\\');
  564. if (firstHit == string::npos || firstHit == 0)
  565. {
  566. return ret;
  567. }
  568. ret = fullpath.substr(0, firstHit);//kick last \
  569. return ret;
  570. }
  571. #if 0
  572. bool GetVersion(ResDataObject& config, string& version)
  573. {
  574. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  575. try {
  576. string procdir = "";
  577. char filename[MAX_PATH + 1] = { 0 };
  578. procdir = GetProcessDirectory();
  579. if (procdir.empty())
  580. {
  581. if (GetModuleFileName(nullptr, filename, MAX_PATH) == 0)
  582. {
  583. return false;
  584. }
  585. }
  586. else
  587. {
  588. string oemdrvpath = (const char*)config["oemdriver"];
  589. {
  590. string keystr = "%ROOT%";
  591. string::size_type pos = 0;
  592. string::size_type keylen = keystr.size();
  593. string::size_type replen = procdir.size();
  594. while ((pos = oemdrvpath.find(keystr, pos)) != string::npos)
  595. {
  596. oemdrvpath.replace(pos, keylen, procdir);
  597. pos += replen;
  598. }
  599. }
  600. strncpy_s(filename, oemdrvpath.c_str(), MAX_PATH);
  601. }
  602. ////mLog::Info("get Generator path:{$}\n", filename);
  603. DWORD dummy;
  604. DWORD size = GetFileVersionInfoSize(filename, &dummy);
  605. if (size == 0)
  606. {
  607. return false;
  608. }
  609. auto data = make_unique<BYTE[]>(size);
  610. if (!GetFileVersionInfo(filename, 0, size, &data[0]))
  611. {
  612. return false;
  613. }
  614. UINT32 len = 0;
  615. VS_FIXEDFILEINFO* fixed_file_info = 0;
  616. if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast<void**>(&fixed_file_info), &len))
  617. {
  618. return false;
  619. }
  620. // version 为版本号
  621. UINT32 vBitNumber = 0;
  622. vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS);
  623. version += to_string(vBitNumber);
  624. version += ".";
  625. vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS);
  626. version += to_string(vBitNumber);
  627. version += ".";
  628. vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS);
  629. version += to_string(vBitNumber);
  630. version += ".";
  631. vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS);
  632. version += to_string(vBitNumber);
  633. return true;
  634. }
  635. catch (...)
  636. {
  637. printf("get Generator Mould version failed");
  638. //mLog::Error("get Generator Mould version failed\n");
  639. }
  640. return false;
  641. }
  642. #endif // 0
  643. nsMech::WDMAMMOCANDevice::WDMAMMOCANDevice(std::shared_ptr <IOEventCenter> center, string configfile /*= ""*/):super(center)
  644. {
  645. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  646. ResDataObject Conftemp;
  647. //if (!configfile.empty())
  648. //{
  649. // Conftemp.loadFile(configfile.c_str());
  650. // m_GenConfig = Conftemp["CONFIGURATION"];
  651. // string version;
  652. // if (GetVersion(m_GenConfig, version))
  653. // printf("**************version:%s...\n",version.c_str());
  654. // else
  655. // printf("**************version 0 0 0 0 .");
  656. //}
  657. //else
  658. //{
  659. // printf("\n===============log begin : DEMO version:3.0.0.1 ===================\n");
  660. //}
  661. }
  662. nsMech::WDMAMMOCANDevice::~WDMAMMOCANDevice()
  663. {
  664. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  665. ////mLog::Info("\n===============log end ===================\n");
  666. }
  667. std::string WDMAMMOCANDevice::GetGUID() const
  668. {
  669. printf("\n===============GetGUID : %s ===================\n", MechanicalUnitType);
  670. return MechanicalUnitType;
  671. }
  672. void nsMech::WDMAMMOCANDevice::FireNotify(std::string key, std::string content)
  673. {
  674. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  675. EventCenter->OnNotify(1, key, content);
  676. }
  677. bool WDMAMMOCANDevice::Prepare()
  678. {
  679. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  680. Register();
  681. return true;
  682. }
  683. void WDMAMMOCANDevice::Register()
  684. {
  685. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  686. auto Disp = Dispatch.Lock().As();
  687. superMech::RegisterExamInfo(Disp);
  688. superMech::RegisterPostionNumber(Disp);
  689. superMech::RegisterGridControl(Disp);
  690. superMech::RegisterMotionControl(Disp);
  691. superMech::RegisterTOMOControl(Disp);
  692. superMech::RegisterMammoInfo(Disp);
  693. }
  694. RET_STATUS WDMAMMOCANDevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
  695. {
  696. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  697. RET_STATUS ret = RET_STATUS::RET_FAILED;
  698. return ret;
  699. }
  700. RET_STATUS WDMAMMOCANDevice::SetGrid(unsigned int GridType)
  701. {
  702. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  703. RET_STATUS ret = RET_STATUS::RET_FAILED;
  704. //ysj++v1的逻辑是首先获取,如果不同,再set,相同则不做动作。
  705. return ret;
  706. }
  707. RET_STATUS WDMAMMOCANDevice::SetAutoTracking(unsigned int nAutoTracking)
  708. {
  709. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  710. RET_STATUS ret = RET_STATUS::RET_FAILED;
  711. return ret;
  712. }
  713. //-------------------------------------------------------------------------------------------//
  714. nsMech::WDMAMMOCANDriver::WDMAMMOCANDriver()
  715. {
  716. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  717. m_bDemoMode = false;
  718. m_bDemoConnected = false;
  719. m_bDemoInitDataFlag = false;
  720. m_pDriGenDev = nullptr;
  721. m_pCAN = nullptr;
  722. m_pAttribute.reset(new ResDataObject());
  723. m_pDescription.reset(new ResDataObject());
  724. }
  725. nsMech::WDMAMMOCANDriver::~WDMAMMOCANDriver()
  726. {
  727. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  728. }
  729. auto nsMech::WDMAMMOCANDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  730. {
  731. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  732. ////mLog::Info("Enter CreateDevice, index={$}", index);
  733. printf("**************************************************enter createdevice,config=%s, index=%d************************************************************\n", m_ConfigFileName.c_str(), index);
  734. if (index == 0)
  735. {
  736. m_pDriGenDev = new WDMAMMOCANDevice(EventCenter, m_ConfigFileName);
  737. auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
  738. return dev;
  739. }
  740. //mLog::Error("unknown index");
  741. unique_ptr <IODevice> dev;
  742. return dev;
  743. }
  744. void nsMech::WDMAMMOCANDriver::FireNotify(int code, std::string key, std::string content)
  745. {
  746. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  747. EventCenter->OnNotify(code, key, content);
  748. }
  749. Log4CPP::Logger* mLog::gLogger = nullptr;
  750. void nsMech::WDMAMMOCANDriver::Prepare()
  751. {
  752. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  753. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Mechanical\Conf\Log4CPP.Config.MECH.xml)";
  754. Log4CPP::ThreadContext::Map::Set("LogFileName", "MECH.WDMAMMOCAN");
  755. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  756. mLog::gLogger = Log4CPP::LogManager::GetLogger("MECH.WDMAMMOCAN");
  757. ResDataObject r_config;
  758. if (r_config.loadFile(m_ConfigFileName.c_str()))
  759. {
  760. m_bDemoMode = (atoi)(((string)r_config["CONFIGURATION"]["IsDemo"]).c_str());
  761. ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
  762. //if ((string)Connection["type"] == "COM")
  763. //{
  764. // m_SCFDllName = COM_SCFDllName;
  765. //}
  766. //else
  767. //{
  768. // m_SCFDllName = TCP_SCFDllName;
  769. //}
  770. }
  771. }
  772. bool WDMAMMOCANDriver::ResetCommunication()
  773. {
  774. if (m_pCAN != NULL) { delete m_pCAN; m_pCAN = NULL; }
  775. m_pCAN = new CCANPort;
  776. //m_pCAN->SetTableCtrl(this);
  777. if (!m_pCAN->CAN_Open())
  778. {
  779. //this->m_pLog->WriteLog("CAN open failed.", LOG_INFORMATION, LOG_DEBUG, true);
  780. return false;
  781. }
  782. if (!m_pCAN->CAN_Init(0, 0, 0xFFFFFFFF, 1, 0, 0x04, 0x1C))
  783. {
  784. //this->m_pLog->WriteLog("CAN init failed.", LOG_INFORMATION, LOG_DEBUG, true);
  785. return false;
  786. }
  787. if (!m_pCAN->CAN_Start())//启动
  788. {
  789. //this->m_pLog->WriteLog("CAN start failed.", LOG_INFORMATION, LOG_DEBUG, true);
  790. return false;
  791. }
  792. if (!m_pCAN->m_bCanStart)
  793. {
  794. //this->m_pLog->WriteLog("CAN start failed 2.", LOG_INFORMATION, LOG_DEBUG, true);
  795. return false;
  796. }
  797. //this->m_pLog->WriteLog("CAN start success.", LOG_INFORMATION, LOG_DEBUG, true);
  798. return true;
  799. }
  800. int nsMech::WDMAMMOCANDriver::Connect()
  801. {
  802. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  803. if (m_bDemoMode)
  804. {
  805. m_bDemoConnected = true;
  806. return SCF_ERR::SCF_SUCCEED;
  807. }
  808. ResDataObject r_config;
  809. if (!r_config.loadFile(m_ConfigFileName.c_str()))
  810. return SCF_ERR::SCF_OPEN_FAILED;
  811. //ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
  812. //printf("connections:%s \n", Connection.encode());
  813. //mLog::Info("connections:{$} \n", Connection.encode());
  814. //auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::CPIDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  815. //if (erCode != SCF_ERR::SCF_SUCCEED)
  816. // return erCode;
  817. //auto rc = super::Connect();
  818. //if (!rc)
  819. // return 0;
  820. bool result = ResetCommunication();//open CAN
  821. if (result)
  822. {
  823. return SCF_ERR::SCF_SUCCEED;
  824. }
  825. return SCF_ERR::SCF_FAILED;
  826. }
  827. void nsMech::WDMAMMOCANDriver::Disconnect()
  828. {
  829. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  830. super::Disconnect();
  831. //m_SCF.Disconnect();
  832. m_bDemoConnected = false;
  833. }
  834. bool nsMech::WDMAMMOCANDriver::isConnected() const
  835. {
  836. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  837. return m_bDemoConnected;
  838. }
  839. std::string nsMech::WDMAMMOCANDriver::DriverProbe()
  840. {
  841. printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
  842. ResDataObject r_config, HardwareInfo;
  843. if (r_config.loadFile(m_ConfigFileName.c_str()))
  844. {
  845. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  846. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  847. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  848. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  849. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  850. }
  851. else
  852. {
  853. HardwareInfo.add("MajorID", "Machine");
  854. HardwareInfo.add("MinorID", "Dr");
  855. HardwareInfo.add("VendorID", "ECOM");
  856. HardwareInfo.add("ProductID", "HF");
  857. HardwareInfo.add("SerialID", "1234");
  858. }
  859. string ret = HardwareInfo.encode();
  860. printf("line= %d,%s %s\n", __LINE__, __FUNCTION__, m_ConfigFileName.c_str());
  861. return ret;
  862. }
  863. bool nsMech::WDMAMMOCANDriver::GetDeviceConfig(std::string& Cfg)
  864. {
  865. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  866. Cfg = m_DeviceConfigSend.encode();
  867. printf("GetDeviceConfig over , %s", Cfg.c_str());
  868. return true;
  869. }
  870. bool nsMech::WDMAMMOCANDriver::SetDeviceConfig(std::string Cfg)
  871. {
  872. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  873. ////mLog::Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  874. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  875. ResDataObject DeviceConfig;
  876. DeviceConfig.decode(Cfg.c_str());
  877. ResDataObject DescriptionTempEx;
  878. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  879. //mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  880. bool bSaveFile = false; //true:重新保存配置文件
  881. string strAccess = "";
  882. for (int i = 0; i < DescriptionTempEx.size(); i++)
  883. {
  884. string strKey = DescriptionTempEx.GetKey(i);
  885. ////mLog::Info("{$}", strKey.c_str());
  886. printf("%s\n", strKey.c_str());
  887. try
  888. {
  889. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  890. {
  891. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  892. if ("RW" == strAccess)
  893. {
  894. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  895. //1. 修改内存中的值,用于给上层发消息
  896. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  897. //2. 拿到Innerkey
  898. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  899. ////mLog::Info("nConfigInfoCount {$}", nConfigInfoCount);
  900. string strTemp = ""; //存储AttributeKey
  901. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  902. {
  903. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  904. if (strTemp == strKey)
  905. {
  906. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  907. break;
  908. }
  909. }
  910. //3. 修改配置文件中的值
  911. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  912. {
  913. //mLog::Debug("SetDeviceConfigValue over");
  914. bSaveFile = true;
  915. }
  916. }
  917. else
  918. {
  919. ////mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  920. }
  921. }
  922. else
  923. {
  924. ////mLog::Info("without this attribute {$}", strKey.c_str());
  925. }
  926. }
  927. catch (ResDataObjectExption& e)
  928. {
  929. printf("\nSetDriverConfig crashed: %s\n", e.what());
  930. //mLog::Error("SetDriverConfig crashed: {$}", e.what());
  931. return false;
  932. }
  933. }
  934. if (bSaveFile)
  935. {
  936. //3. 重新保存配置文件
  937. SaveConfigFile(true);
  938. }
  939. return true;
  940. }
  941. bool nsMech::WDMAMMOCANDriver::SaveConfigFile(bool bSendNotify)
  942. {
  943. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  944. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  945. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  946. ////mLog::Info("SaveConfigFile over {$}", bRt);
  947. return true;
  948. }
  949. bool nsMech::WDMAMMOCANDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  950. {
  951. printf("line= %d,%s,pInnerKey=%s,nPathID=%d\n", __LINE__, __FUNCTION__, pInnerKey, nPathID);
  952. strValue = "";
  953. string strTemp = pInnerKey;
  954. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  955. {
  956. int pos = 0;
  957. ResDataObject resTemp = config;
  958. while ((pos = strTemp.find_first_of(',')) != string::npos)
  959. {
  960. string Key = strTemp.substr(0, pos);
  961. string TempValue = resTemp[Key.c_str()].encode();
  962. //printf("-TempValue=== %s\n", TempValue.c_str());
  963. resTemp.clear();
  964. resTemp.decode(TempValue.c_str());
  965. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  966. //printf("-************--%s\n", strTemp.c_str());
  967. }
  968. if (strTemp != "")
  969. {
  970. strValue = (string)resTemp[strTemp.c_str()];
  971. }
  972. else
  973. {
  974. strValue = (string)resTemp;
  975. }
  976. }
  977. //printf("------------%s\n", strValue.c_str());
  978. return true;
  979. }
  980. bool nsMech::WDMAMMOCANDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  981. {
  982. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  983. string strTemp = pInnerKey;
  984. //mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  985. printf("\n Begin to change {%s} item value to {%s}\n", pInnerKey, szValue);
  986. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  987. {
  988. try {
  989. int pos = 0;
  990. ResDataObject* resTemp = &config;
  991. while ((pos = strTemp.find_first_of(',')) != string::npos)
  992. {
  993. string Key = strTemp.substr(0, pos);
  994. resTemp = &(*resTemp)[Key.c_str()];
  995. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  996. }
  997. if (strTemp != "")
  998. {
  999. (*resTemp)[strTemp.c_str()] = szValue;
  1000. }
  1001. else
  1002. {
  1003. *resTemp = szValue;
  1004. }
  1005. }
  1006. catch (ResDataObjectExption& e)
  1007. {
  1008. //mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  1009. return false;
  1010. }
  1011. }
  1012. return true;
  1013. }
  1014. std::string nsMech::WDMAMMOCANDriver::GetResource()
  1015. {
  1016. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  1017. ResDataObject r_config, temp;
  1018. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1019. {
  1020. return "";
  1021. }
  1022. m_ConfigAll = temp;
  1023. r_config = temp["CONFIGURATION"];
  1024. m_Configurations = r_config;
  1025. ResDataObject DescriptionTemp;
  1026. ResDataObject DescriptionSend;
  1027. ResDataObject m_DescriptionSend;
  1028. ResDataObject ListTemp;
  1029. string strTemp = ""; //用于读取字符串配置信息
  1030. string strIndex = ""; //用于读取配置信息中的List项
  1031. int nTemp = -1; //用于读取整型配置信息
  1032. char sstream[10] = { 0 }; //用于转换值
  1033. string strValue = ""; //用于存储配置的值
  1034. string strType = ""; //用于存储配置的类型 int/float/string...
  1035. try
  1036. {
  1037. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1038. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1039. m_pAttribute->clear();
  1040. m_pDescription->clear();
  1041. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1042. {
  1043. DescriptionTemp.clear();
  1044. DescriptionSend.clear();
  1045. ListTemp.clear();
  1046. //AttributeType
  1047. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1048. DescriptionTemp.add(ConfKey::DiosType, strTemp.c_str());//DiosGeneratorAttribute
  1049. DescriptionSend.add(ConfKey::DiosType, strTemp.c_str());//DiosGeneratorAttribute
  1050. strType = strTemp; //记录配置项的类型
  1051. //AttributeKey
  1052. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1053. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1054. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1055. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1056. //2. 赋值
  1057. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1058. if ("int" == strType)
  1059. {
  1060. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1061. }
  1062. else if ("float" == strType)
  1063. {
  1064. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1065. }
  1066. else //其它先按string类型处理
  1067. {
  1068. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1069. }
  1070. //AttributeAccess
  1071. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1072. DescriptionTemp.add(ConfKey::DiosAccess, strTemp.c_str());
  1073. DescriptionSend.add(ConfKey::DiosAccess, strTemp.c_str());
  1074. //AttributeRangeMin
  1075. //strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  1076. //if (strTemp != "") //不需要的配置项为空
  1077. //{
  1078. // DescriptionTemp.add(ConfKey::DiosRangeMin, strTemp.c_str());
  1079. //}
  1080. ////AttributeRangeMax
  1081. //strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  1082. //if (strTemp != "") //不需要的配置项为空
  1083. //{
  1084. // DescriptionTemp.add(ConfKey::DiosRangeMax, strTemp.c_str());
  1085. //}
  1086. //AttributeList
  1087. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  1088. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  1089. {
  1090. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  1091. {
  1092. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  1093. auto temKey = std::to_string(nListIndex);
  1094. ListTemp.add(temKey.c_str(), strTemp.c_str());
  1095. }
  1096. DescriptionTemp.add(ConfKey::DiosList, ListTemp);
  1097. DescriptionSend.add(ConfKey::DiosList, ListTemp.encode());
  1098. }
  1099. //AttributeRequired
  1100. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  1101. DescriptionTemp.add(ConfKey::DiosRequired, strTemp.c_str());
  1102. DescriptionSend.add(ConfKey::DiosRequired, strTemp.c_str());
  1103. //AttributeDefaultValue
  1104. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  1105. if (strTemp != "") //不需要的配置项为空
  1106. {
  1107. DescriptionTemp.add(ConfKey::DiosDefaultValue, strTemp.c_str());
  1108. DescriptionSend.add(ConfKey::DiosDefaultValue, strTemp.c_str());
  1109. }
  1110. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1111. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  1112. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  1113. }
  1114. }
  1115. catch (ResDataObjectExption& e)
  1116. {
  1117. //mLog::Error("Get config error: {$}", e.what());
  1118. return "";
  1119. }
  1120. ResDataObject resDeviceResource;
  1121. resDeviceResource.add(ConfKey::DiosAttribute, (*m_pAttribute));
  1122. resDeviceResource.add(ConfKey::DiosDescription, (*m_pDescription));
  1123. ResDataObject DescriptionTempEx;
  1124. DescriptionTempEx.add(ConfKey::DiosConfig, resDeviceResource);
  1125. m_DeviceConfig.clear();
  1126. m_DeviceConfig = DescriptionTempEx;
  1127. //mLog::Debug("local ************* get resource over {$}", DescriptionTempEx.encode());
  1128. printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  1129. resDeviceResource.clear();
  1130. resDeviceResource.add(ConfKey::DiosAttribute, (*m_pAttribute));
  1131. resDeviceResource.add(ConfKey::DiosDescription, m_DescriptionSend);
  1132. DescriptionTempEx.clear();
  1133. DescriptionTempEx.add(ConfKey::DiosConfig, resDeviceResource);
  1134. m_DeviceConfigSend.clear();
  1135. m_DeviceConfigSend = DescriptionTempEx;
  1136. string res = m_DeviceConfigSend.encode();
  1137. //mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  1138. printf("************* get resource over %s \n", DescriptionTempEx.encode());
  1139. return res;
  1140. }
  1141. std::string nsMech::WDMAMMOCANDriver::DeviceProbe()
  1142. {
  1143. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  1144. ResDataObject r_config, HardwareInfo;
  1145. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1146. {
  1147. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1148. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1149. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1150. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1151. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1152. }
  1153. else
  1154. {
  1155. HardwareInfo.add("MajorID", "Machine");
  1156. HardwareInfo.add("MinorID", "Dr");
  1157. HardwareInfo.add("VendorID", "ECOM");
  1158. HardwareInfo.add("ProductID", "HF");
  1159. HardwareInfo.add("SerialID", "1234");
  1160. }
  1161. string ret = HardwareInfo.encode();
  1162. return ret;
  1163. }
  1164. void nsMech::WDMAMMOCANDriver::Dequeue(const char* Packet, DWORD Length)
  1165. {
  1166. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  1167. }
  1168. PACKET_RET nsMech::WDMAMMOCANDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  1169. {
  1170. printf("line= %d,%s\n", __LINE__, __FUNCTION__);
  1171. return PACKET_NOPACKET;
  1172. }
  1173. static nsMech::WDMAMMOCANDriver gIODriver;
  1174. extern "C" DIOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  1175. {
  1176. return &gIODriver;
  1177. }
  1178. extern "C" DIOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  1179. {
  1180. return new nsMech::WDMAMMOCANDriver();
  1181. }