DIOS.Dev.Mech.Demo.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. #include "stdafx.h"
  2. #include <assert.h>
  3. #include "Helper.JSON.hpp"
  4. #include "DIOS.Dev.Mech.Demo.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. #define MY_PI 3.14159265358979323846
  10. Log4CPP::Logger* mLog::gLogger = nullptr;
  11. //-----------------------------------------------------------------------------
  12. // DemoDevice
  13. //-----------------------------------------------------------------------------
  14. nsMech::DemoDevice::DemoDevice(std::shared_ptr <IOEventCenter> center, string configfile /*= ""*/):super(center)
  15. {
  16. string version;
  17. if (GetVersion(version, hMyModule))
  18. mLog::Info("\n===============log begin : version:{$} ===================\n", version.c_str());
  19. else
  20. mLog::Info("\n===============log begin : version:0.0.0.0 ===================\n");
  21. ResDataObject Conftemp;
  22. if (!configfile.empty())
  23. {
  24. Conftemp.loadFile(configfile.c_str());
  25. m_MechConfig = Conftemp["CONFIGURATION"];
  26. TransJsonText(m_MechConfig);
  27. }
  28. //normal parameter
  29. m_MECHUnit.m_MechState.reset(new MechStateMould(AttrKey::MACHINE_STATUS_STANDBY, AttrKey::MACHINE_STATUS_SHUTDOWN, AttrKey::MACHINE_STATUS_SERVICE, 1));
  30. m_MECHUnit.m_FID.reset(new FIDMould(0, 0, 10000, 1));
  31. m_MECHUnit.m_TubeAngle.reset(new TubeAngleMould(0, -180, 180, 1));
  32. m_MECHUnit.m_FPDPosition.reset(new FPDPositionMould(0, 0, 100, 1));
  33. m_MECHUnit.m_PatientSize.reset(new PATIENTSIZEMould(0, 0, 10, 1));
  34. m_MECHUnit.m_PostionNumber.reset(new POSITIONNUMBERMould(0, 0, 10000, 1));
  35. m_MECHUnit.m_SID.reset(new SIDMould(100, 0, 1000, 1));
  36. if (m_MechConfig.GetKeyCount("MechanicalAngle") > 0)
  37. {
  38. if (m_MechConfig["MechanicalAngle"].GetKeyCount("min") > 0)
  39. m_nMinAngle = m_MechConfig["MechanicalAngle"]["min"];
  40. if (m_MechConfig["MechanicalAngle"].GetKeyCount("max") > 0)
  41. m_nMaxAngle = m_MechConfig["MechanicalAngle"]["max"];
  42. mLog::Debug("config:MechanicalAngle[min:{$},max:{$}]", m_nMinAngle, m_nMaxAngle);
  43. }
  44. m_MECHUnit.m_TubeAngle.reset(new TubeAngleMould(90, m_nMinAngle, m_nMaxAngle, 1));
  45. if (m_MechConfig.GetKeyCount("MechanicalHeight") > 0)
  46. {
  47. if (m_MechConfig["MechanicalHeight"].GetKeyCount("min") > 0)
  48. m_nMinHeight = m_MechConfig["MechanicalHeight"]["min"];
  49. if (m_MechConfig["MechanicalHeight"].GetKeyCount("max") > 0)
  50. m_nMaxHeight = m_MechConfig["MechanicalHeight"]["max"];
  51. mLog::Debug("config:MechanicalHeight[min:{$},max:{$}]", m_nMinHeight, m_nMaxHeight);
  52. }
  53. m_MECHUnit.m_TubeHeight.reset(new TubeHeightMould(150, m_nMinHeight, m_nMaxHeight, 1));
  54. m_MECHUnit.m_FID.reset(new FIDMould(150, m_nMinHeight, m_nMaxHeight, 1));
  55. //拼接
  56. m_MECHUnit.m_StitchingState.reset(new StitchingStateMould(AttrKey::STITCHSTATE_INIT, AttrKey::STITCHSTATE_ERR, AttrKey::STITCHSTATE_MAX, 1));
  57. m_MECHUnit.m_StitchHeight.reset(new StitchHeightMould(0, m_nMinHeight, m_nMaxHeight, 1));
  58. m_MECHUnit.m_StitchLength.reset(new StitchLengthMould(0, 0, 1000, 1));
  59. m_MECHUnit.m_StitchOverLap.reset(new StitchOverLapMould(0, 0, 1000, 1));
  60. m_MECHUnit.m_StitchPID.reset(new StitchPIDMould(0, 0, 1000, 1));
  61. m_MECHUnit.m_StitchDirection.reset(new StitchDirectionMould(AttrKey::STITCHDIR_NULL, AttrKey::STITCHDIR_NULL, AttrKey::STITCHDIR_MAX, 1));
  62. m_MECHUnit.m_StitchType.reset(new StitchTypeMould(AttrKey::STITCHTYPE_NULL, AttrKey::STITCHTYPE_NULL, AttrKey::STITCHTYPE_MAX, 1));
  63. m_MECHUnit.m_StitchStepLength.reset(new StitchStepLengthMould(10, 0, 1000, 1));
  64. m_MECHUnit.m_FPDPosition.reset(new FPDPositionMould(0, 0, 100, 1));
  65. m_MECHUnit.m_TotalImageCount.reset(new TotalImageCountMould(0, 0, 100, 1));
  66. m_MECHUnit.m_CurrentImageNumber.reset(new CurrentImageNumberMould(100, 0, 100, 1));
  67. //遮光器
  68. m_Collimator.fHeight = 0;
  69. m_Collimator.fWidth = 0;
  70. m_MSGUnit.reset(new nsDetail::MSGUnit(center, MechUnitType));
  71. //配置响应操作对照表
  72. //OnCallBack();
  73. //将机架可以对外提供的指令注册集进行补充
  74. Register();
  75. }
  76. nsMech::DemoDevice::~DemoDevice()
  77. {
  78. mLog::Info("\n===============log end ===================\n");
  79. }
  80. std::string nsMech::DemoDevice::GetGUID() const
  81. {
  82. mLog::Info("\n===============GetGUID : {$} ===================\n", MechUnitType);
  83. return StitchMechUnitType;
  84. }
  85. void nsMech::DemoDevice::Register()
  86. {
  87. auto Disp = &Dispatch;
  88. superMech::RegisterNormalControl(Disp);
  89. superMech::RegisterStitchingControl(Disp);
  90. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  91. Disp->Get.Push("StitchPlanMinAngle", [this](std::string& out) {
  92. out = to_string(m_nMinAngle);
  93. return RET_STATUS::RET_SUCCEED; });
  94. Disp->Get.Push("StitchPlanMaxAngle", [this](std::string& out) {
  95. out = to_string(m_nMaxAngle);
  96. return RET_STATUS::RET_SUCCEED; });
  97. Disp->Get.Push("StitchPlanMinHeight", [this](std::string& out) {
  98. out = to_string(m_nMinHeight);
  99. return RET_STATUS::RET_SUCCEED; });
  100. Disp->Get.Push("StitchPlanMaxHeight", [this](std::string& out) {
  101. out = to_string(m_nMaxHeight);
  102. return RET_STATUS::RET_SUCCEED; });
  103. auto fun_SendStitchState = [this](auto in, auto& out)
  104. {
  105. FireNotify(AttrKey::STITCHINGSTATE, m_MECHUnit.m_StitchingState->Get());
  106. return RET_STATUS::RET_SUCCEED;
  107. };
  108. Disp->Action.Push("SendStitchState", fun_SendStitchState);
  109. }
  110. void nsMech::DemoDevice::FireNotify(std::string key, std::string content)
  111. {
  112. EventCenter->OnNotify(1, key, content);
  113. }
  114. void nsMech::DemoDevice::FireNotify(std::string key, int context)
  115. {
  116. char szInfo[64] = { 0 };
  117. sprintf_s(szInfo, "%d", context);
  118. EventCenter->OnNotify(1, key, szInfo);
  119. }
  120. //检查信息接口
  121. RET_STATUS nsMech::DemoDevice::SetStudyInfo(ResDataObject& pParam)
  122. {
  123. auto& P0 = pParam[0];
  124. SetPatientInfo(P0);
  125. return RET_STATUS::RET_SUCCEED;
  126. }
  127. RET_STATUS nsMech::DemoDevice::SetViewInfo(ResDataObject& pParam)
  128. {
  129. return RET_STATUS::RET_SUCCEED;
  130. }
  131. RET_STATUS nsMech::DemoDevice::SetPatientInfo(ResDataObject& pParam)
  132. {
  133. ECOM_PATIENT Info;
  134. Info.strPatientName = (string)pParam["PatientName"];
  135. Info.strSex = (string)pParam["Sex"];
  136. Info.strAge = (string)pParam["Age"];
  137. Info.strPatientID = (string)pParam["PatientID"];
  138. Info.strPatientSize = (string)pParam["PatientSize"];
  139. Info.strStudyDescription = (string)pParam["StudyDescription"];
  140. Info.strAccessionNumber = (string)pParam["AccessionNumber"];
  141. mLog::Debug("Enter SetPatientInfo:[Name:{$}],[Sex:{$}],[Age:{$}],[ID:{$}],[Size:{$}],[Description:{$}],[AccessionNumber:{$}]",
  142. Info.strPatientName.c_str(), Info.strSex.c_str(), Info.strAge.c_str(), Info.strPatientID.c_str(), Info.strPatientSize.c_str(),
  143. Info.strStudyDescription.c_str(), Info.strAccessionNumber.c_str());
  144. return RET_STATUS::RET_SUCCEED;
  145. }
  146. //基本
  147. RET_STATUS nsMech::DemoDevice::Reset()
  148. {
  149. mLog::Debug("Enter Reset");
  150. mLog::Debug("End Reset");
  151. return RET_STATUS::RET_SUCCEED;
  152. }
  153. RET_STATUS nsMech::DemoDevice::SetTechParamsInfo(ResDataObject& pParam)
  154. {
  155. return RET_STATUS::RET_SUCCEED;
  156. }
  157. RET_STATUS nsMech::DemoDevice::SetPositionNumber(int pn)
  158. {
  159. mLog::Debug("Enter SetPositionNumber:[{$}]", pn);
  160. m_MECHUnit.m_PostionNumber->Update(pn);
  161. FireNotify(AttrKey::POSITIONNUMBER, m_MECHUnit.m_PostionNumber->JSGet());
  162. return RET_STATUS::RET_SUCCEED;
  163. }
  164. RET_STATUS nsMech::DemoDevice::SetSID(float value)
  165. {
  166. mLog::Debug("Enter SetSID:[{$}]->[{$}]", m_MECHUnit.m_SID->Get(), value);
  167. if (m_MECHUnit.m_SID->Update(value))
  168. FireNotify(AttrKey::SID, m_MECHUnit.m_SID->JSGet());
  169. return RET_STATUS::RET_SUCCEED;
  170. }
  171. RET_STATUS nsMech::DemoDevice::SetSOD(float value)
  172. {
  173. return RET_STATUS::RET_SUCCEED;
  174. }
  175. RET_STATUS nsMech::DemoDevice::MoveToHome(string& value)
  176. {
  177. int PosNum = atoi(value.c_str());
  178. mLog::Debug("Enter MoveToHome:[{$}]", PosNum);
  179. return RET_STATUS::RET_FAILED;
  180. }
  181. RET_STATUS nsMech::DemoDevice::MoveMech(string& value)
  182. {
  183. return RET_STATUS::RET_SUCCEED;
  184. }
  185. RET_STATUS nsMech::DemoDevice::StopMech(string& value)
  186. {
  187. return RET_STATUS::RET_SUCCEED;
  188. }
  189. RET_STATUS nsMech::DemoDevice::SetGrid(AttrKey::MECH_GRIDSTATE GridState)
  190. {
  191. return RET_STATUS::RET_SUCCEED;
  192. }
  193. RET_STATUS nsMech::DemoDevice::SetAutoTracking(int nAutoTracking)
  194. {
  195. mLog::Debug("Enter MoveToHome:[{$}]", nAutoTracking);
  196. return RET_STATUS::RET_SUCCEED;
  197. }
  198. //拼接接口
  199. RET_STATUS nsMech::DemoDevice::BeginStitching()
  200. {
  201. if(m_MECHUnit.m_MechState->Update(AttrKey::MACHINE_STATUS_STITCH))
  202. FireNotify(AttrKey::MACHSTATE, m_MECHUnit.m_MechState->Get());
  203. mLog::Debug("Enter BeginStitching");
  204. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_START))
  205. {
  206. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_START);
  207. m_MECHUnit.m_strInfo = "Stitch Start";
  208. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  209. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  210. }
  211. InitStitching();
  212. return RET_STATUS::RET_SUCCEED;
  213. }
  214. RET_STATUS nsMech::DemoDevice::InitStitching()
  215. {
  216. mLog::Debug("Enter InitStitching");
  217. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_READY))
  218. {
  219. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_READY);
  220. m_MECHUnit.m_strInfo = "Stitch Ready";
  221. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  222. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  223. }
  224. return RET_STATUS::RET_SUCCEED;
  225. }
  226. RET_STATUS nsMech::DemoDevice::EndStitching()
  227. {
  228. mLog::Debug("Enter EndStitching");
  229. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_END))
  230. {
  231. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_END);
  232. m_MECHUnit.m_strInfo = "Stitch Finish";
  233. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  234. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  235. }
  236. return RET_STATUS::RET_SUCCEED;
  237. }
  238. RET_STATUS nsMech::DemoDevice::SetupStitching(string& value)
  239. {
  240. ResDataObject json, P0;
  241. json.decode(value.c_str());
  242. if (json.GetKeyCount("P0") > 0)
  243. {
  244. P0 = json[0];
  245. }
  246. else
  247. P0 = json;
  248. int nInitHeight = atoi(((string)P0[AttrKey::STITCHHEIGHT]).c_str());
  249. int nTargetLength = atoi(((string)P0[AttrKey::STITCHLENGTH]).c_str());
  250. int nOverlap = atoi(((string)P0[AttrKey::STITCHOVERLAP]).c_str());
  251. int nSID = atoi(((string)P0[AttrKey::STITCHSID]).c_str());
  252. int nTID = atoi(((string)P0[AttrKey::STITCHTID]).c_str());
  253. int nPID = atoi(((string)P0[AttrKey::STITCHPID]).c_str());
  254. int nDirection = atoi(((string)P0[AttrKey::STITCHDIRECTION]).c_str());
  255. int nStitchType = atoi(((string)P0[AttrKey::STITCHTYPE]).c_str());
  256. mLog::Debug("Enter SetupStitching:[InitHeight:{$},TotalLength:{$},Overlap:{$},SID:{$},TID:{$},PID:{$},Direction:{$},StitchType:{$}]",
  257. nInitHeight, nTargetLength, nOverlap, nSID, nTID, nPID, nDirection, nStitchType);
  258. m_MECHUnit.m_StitchHeight->Update(nInitHeight);
  259. m_MECHUnit.m_StitchOverLap->Update(nOverlap);
  260. m_MECHUnit.m_StitchDirection->Update(nDirection);
  261. m_MECHUnit.m_StitchType->Update(nStitchType);
  262. if (m_MECHUnit.m_CurrentImageNumber->Update(0))
  263. FireNotify(AttrKey::CURRENTIMAGENUMBER, 0);
  264. switch (m_MECHUnit.m_StitchType->Get())
  265. {
  266. case AttrKey::STITCHTYPE_AutomaticTranslation:
  267. case AttrKey::STITCHTYPE_ManualTranslation:
  268. {
  269. //总长度校验
  270. int maxLength = m_MECHUnit.m_TubeHeight->GetLimitMax() - m_MECHUnit.m_TubeHeight->GetLimitMin();
  271. if (nTargetLength > (maxLength))
  272. {
  273. mLog::Warn("StitchingLengh[{$}] too big [height min:{$},height max:{$}],need change to[{$}]",
  274. nTargetLength, m_MECHUnit.m_TubeHeight->GetLimitMax(), m_MECHUnit.m_TubeHeight->GetLimitMin(), maxLength);
  275. nTargetLength = maxLength;
  276. }
  277. m_MECHUnit.m_StitchLength->Update(nTargetLength);
  278. //总张数计算
  279. int totalImage = (float)(nTargetLength - nOverlap) / (float)(m_nFPDLengh - nOverlap);
  280. if (m_MECHUnit.m_TotalImageCount->Update(totalImage))
  281. FireNotify(AttrKey::TOTALIMAGECOUNT, totalImage);
  282. //计算步长
  283. float tempStepLength = (float)nTargetLength / (float)totalImage;
  284. if (m_MECHUnit.m_StitchStepLength->Update(tempStepLength))
  285. FireNotify(AttrKey::STITCHSTEPLENGTH, tempStepLength);
  286. mLog::Debug("compute TransStitching [total ImageCount:{$},StepLength:{$}]",
  287. totalImage, tempStepLength);
  288. }break;
  289. case AttrKey::STITCHTYPE_AutomaticAngle:
  290. case AttrKey::STITCHTYPE_ManualAngle:
  291. {
  292. //总长度校验
  293. int maxLength = m_MECHUnit.m_TubeHeight->GetLimitMax() - m_MECHUnit.m_TubeHeight->GetLimitMin();
  294. //角度范围
  295. float maxStitchAngle = 2 * atan((float)maxLength / 2.0f / m_MECHUnit.m_SID->Get()) * 180.0f / MY_PI;
  296. mLog::Debug("compute AngleStitching limit[FPDLengh:{$},OverLap:{$}, SID:{$}]->angle[min:0,max:{$}]",
  297. m_nFPDLengh, nOverlap, m_MECHUnit.m_SID->Get(), maxStitchAngle);
  298. //设置参数的总角度
  299. if (nTargetLength > maxStitchAngle)
  300. {
  301. nTargetLength = maxStitchAngle;
  302. }
  303. m_MECHUnit.m_StitchLength->Update(nTargetLength);
  304. //总张数计算
  305. int moveLengh = 2 * tan((float)nTargetLength / 2.0f / 180.0f * MY_PI) * m_MECHUnit.m_SID->Get();
  306. int totalImage = std::ceil((float)(moveLengh - nOverlap) / (float)(m_nFPDLengh - nOverlap));
  307. m_MECHUnit.m_TotalImageCount->Update(totalImage);
  308. FireNotify(AttrKey::TOTALIMAGECOUNT, totalImage);
  309. //计算步长
  310. float tempStepLength = (float)nTargetLength / (float)totalImage;
  311. if (m_MECHUnit.m_StitchStepLength->Update(tempStepLength))
  312. FireNotify(AttrKey::STITCHSTEPLENGTH, tempStepLength);
  313. mLog::Debug("compute AngleStitching [total ImageCount:{$},StepLength:{$}]",
  314. totalImage, tempStepLength);
  315. }break;
  316. default:
  317. return RET_STATUS::RET_FAILED;
  318. }
  319. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_INIT))
  320. {
  321. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_INIT);
  322. m_MECHUnit.m_strInfo = "Stitch Init";
  323. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  324. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  325. }
  326. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_REACH_INIT))
  327. {
  328. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_REACH_INIT);
  329. m_MECHUnit.m_strInfo = "Stitch Reach to the initial position";
  330. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  331. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  332. }
  333. return RET_STATUS::RET_SUCCEED;
  334. }
  335. RET_STATUS nsMech::DemoDevice::AcceptStitchingImage()
  336. {
  337. mLog::Debug("Enter AcceptStitchingImage");
  338. int Currentnum = m_MECHUnit.m_CurrentImageNumber->Get() + 1;
  339. if (m_MECHUnit.m_CurrentImageNumber->Update(Currentnum))
  340. {
  341. mLog::Debug("stitching current image[{$}:{$}]", m_MECHUnit.m_CurrentImageNumber->Get(), m_MECHUnit.m_TotalImageCount->Get());
  342. FireNotify(AttrKey::CURRENTIMAGENUMBER, Currentnum);
  343. }
  344. if (m_MECHUnit.m_CurrentImageNumber->Get() >= m_MECHUnit.m_TotalImageCount->Get())
  345. {
  346. EndStitching();
  347. }
  348. else
  349. {
  350. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_Accept_Image))
  351. {
  352. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_Accept_Image);
  353. m_MECHUnit.m_strInfo = "Stitch Accept Current image";
  354. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  355. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  356. }
  357. Sleep(2000);
  358. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_READY))
  359. {
  360. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_READY);
  361. m_MECHUnit.m_strInfo = "Stitch Ready";
  362. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  363. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  364. }
  365. }
  366. return RET_STATUS::RET_SUCCEED;
  367. }
  368. RET_STATUS nsMech::DemoDevice::RejectStitchingImage()
  369. {
  370. mLog::Debug("Enter RejectStitchingImage");
  371. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_Reject_Image))
  372. {
  373. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_Reject_Image);
  374. m_MECHUnit.m_strInfo = "Stitch Reject Current Image";
  375. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  376. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  377. }
  378. return RET_STATUS::RET_SUCCEED;
  379. }
  380. RET_STATUS nsMech::DemoDevice::CancelStitching()
  381. {
  382. mLog::Debug("Enter CancelStitching");
  383. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_CANCEL))
  384. {
  385. FireNotify(AttrKey::STITCHINGSTATE, AttrKey::STITCHSTATE_CANCEL);
  386. m_MECHUnit.m_strInfo = "Stitch Cancel";
  387. mLog::Debug("stitching:[{$}]", m_MECHUnit.m_strInfo.c_str());
  388. FireNotify(AttrKey::UNITINFO, m_MECHUnit.m_strInfo);
  389. }
  390. return RET_STATUS::RET_SUCCEED;
  391. }
  392. RET_STATUS nsMech::DemoDevice::CompleteStitching()
  393. {
  394. mLog::Debug("Enter CompleteStitching");
  395. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_END))
  396. FireNotify(AttrKey::STITCHINGSTATE, m_MECHUnit.m_StitchingState->JSGet());
  397. return RET_STATUS::RET_SUCCEED;
  398. }
  399. RET_STATUS nsMech::DemoDevice::NewExtraView()
  400. {
  401. mLog::Debug("Enter NewExtraView");
  402. return RET_STATUS::RET_SUCCEED;
  403. }
  404. RET_STATUS nsMech::DemoDevice::RepeatStitching()
  405. {
  406. mLog::Debug("Enter RepeatStitching");
  407. if (m_MECHUnit.m_StitchingState->Update(AttrKey::STITCHSTATE_RESTART))
  408. FireNotify(AttrKey::STITCHINGSTATE, m_MECHUnit.m_StitchingState->JSGet());
  409. return RET_STATUS::RET_SUCCEED;
  410. }
  411. RET_STATUS nsMech::DemoDevice::SetAutoPosiitonNo(int nPN)
  412. {
  413. mLog::Debug("Enter SetAutoPosiitonNo:[{$}]->[{$}]", m_MECHUnit.m_PostionNumber->Get(), nPN);
  414. m_MECHUnit.m_PostionNumber->Update(nPN);
  415. FireNotify(AttrKey::POSITIONNUMBER, m_MECHUnit.m_PostionNumber->JSGet());
  416. return RET_STATUS::RET_SUCCEED;
  417. }
  418. //牛头
  419. RET_STATUS nsMech::DemoDevice::SetExpEnable(bool nExpEnabled)
  420. {
  421. return RET_STATUS::RET_SUCCEED;
  422. }
  423. RET_STATUS nsMech::DemoDevice::SetWS(int nWS)
  424. {
  425. mLog::Debug("Enter SetWS:[{$}]", nWS);
  426. if (m_nWS == nWS)return RET_STATUS::RET_SUCCEED;
  427. m_nWS = nWS;
  428. return RET_STATUS::RET_SUCCEED;
  429. }
  430. RET_STATUS nsMech::DemoDevice::SetKV(int nKV)
  431. {
  432. mLog::Debug("Enter SetKV:[{$}]", nKV);
  433. if (m_nKV == nKV)return RET_STATUS::RET_SUCCEED;
  434. m_nKV = nKV;
  435. return RET_STATUS::RET_SUCCEED;
  436. }
  437. RET_STATUS nsMech::DemoDevice::SetMA(float fMA)
  438. {
  439. mLog::Debug("Enter SetMA:[{$}]", fMA);
  440. if (m_fMA == fMA)return RET_STATUS::RET_SUCCEED;
  441. m_fMA = fMA;
  442. return RET_STATUS::RET_SUCCEED;
  443. }
  444. RET_STATUS nsMech::DemoDevice::SetMS(float fMS)
  445. {
  446. mLog::Debug("Enter SetMS:[{$}]", fMS);
  447. if (m_fMS == fMS)return RET_STATUS::RET_SUCCEED;
  448. m_fMS = fMS;
  449. return RET_STATUS::RET_SUCCEED;
  450. }
  451. RET_STATUS nsMech::DemoDevice::SetMAS(float fMAS)
  452. {
  453. mLog::Debug("Enter SetMAS:[{$}]", fMAS);
  454. if (m_fMAS == fMAS)return RET_STATUS::RET_SUCCEED;
  455. m_fMAS = fMAS;
  456. return RET_STATUS::RET_SUCCEED;
  457. }
  458. RET_STATUS nsMech::DemoDevice::SetFO(int nFO)
  459. {
  460. mLog::Debug("Enter SetFO:[{$}]", nFO);
  461. if (m_nFocus == nFO)return RET_STATUS::RET_SUCCEED;
  462. m_nFocus = nFO;
  463. return RET_STATUS::RET_SUCCEED;
  464. }
  465. RET_STATUS nsMech::DemoDevice::SetTechMode(int nET)
  466. {
  467. mLog::Debug("Enter SetTechMode:[{$}]", nET);
  468. if (m_nET == nET)return RET_STATUS::RET_SUCCEED;
  469. m_nET = nET;
  470. return RET_STATUS::RET_SUCCEED;
  471. }
  472. RET_STATUS nsMech::DemoDevice::SetAECField(int nAECFieldSel)
  473. {
  474. mLog::Debug("Enter SetAECField:[{$}]", nAECFieldSel);
  475. if (m_nAECField == nAECFieldSel)return RET_STATUS::RET_SUCCEED;
  476. m_nAECField = nAECFieldSel;
  477. return RET_STATUS::RET_SUCCEED;
  478. }
  479. RET_STATUS nsMech::DemoDevice::SetDensity(float nAECDensity)
  480. {
  481. mLog::Debug("Enter SetDensity:[{$}]", nAECDensity);
  482. if (m_nAECDensity == nAECDensity)return RET_STATUS::RET_SUCCEED;
  483. m_nAECDensity = nAECDensity;
  484. return RET_STATUS::RET_SUCCEED;
  485. }
  486. RET_STATUS nsMech::DemoDevice::SetBodySize(string strSize)
  487. {
  488. mLog::Debug("Enter SetBodySize:[{$}]", strSize.c_str());
  489. char temp[50] = { 0 };
  490. int nPS = 2;
  491. if (strSize == "Small")
  492. {
  493. nPS = 1;
  494. }
  495. else if (strSize == "Middle")
  496. {
  497. nPS = 2;
  498. }
  499. else if (strSize == "Large")
  500. {
  501. nPS = 3;
  502. }
  503. else if (strSize == "Child")
  504. {
  505. nPS = 4;
  506. }
  507. if (m_nBodySize == nPS)return RET_STATUS::RET_SUCCEED;
  508. m_nBodySize = nPS;
  509. return RET_STATUS::RET_SUCCEED;
  510. }
  511. //遮光器
  512. RET_STATUS nsMech::DemoDevice::SetCollimator(ECOM_COLLIMATOR_INFO& curCollimator)
  513. {
  514. mLog::Debug("Enter SetCollimator:Height[{$}]->[{$}],Width[{$}]->[{$}]",
  515. m_Collimator.fHeight, curCollimator.fHeight, m_Collimator.fWidth, curCollimator.fWidth);
  516. m_Collimator.fHeight = curCollimator.fHeight;
  517. m_Collimator.fWidth = curCollimator.fWidth;
  518. FireNotify("XSize", m_Collimator.fHeight);
  519. FireNotify("YSize", m_Collimator.fWidth);
  520. return RET_STATUS::RET_SUCCEED;
  521. }
  522. RET_STATUS nsMech::DemoDevice::SetFilter(int nFilter)
  523. {
  524. mLog::Debug("Enter SetFilter[{$}]", nFilter);
  525. FireNotify("Filter", nFilter);
  526. return RET_STATUS::RET_SUCCEED;
  527. }
  528. //-----------------------------------------------------------------------------
  529. // DemoDriver
  530. //-----------------------------------------------------------------------------
  531. nsMech::DemoDriver::DemoDriver()
  532. {
  533. m_pAttribute.reset(new ResDataObject());
  534. m_pDescription.reset(new ResDataObject());
  535. }
  536. nsMech::DemoDriver::~DemoDriver()
  537. {
  538. }
  539. auto nsMech::DemoDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  540. {
  541. mLog::Info("Enter CreateDevice, index={$}", index);
  542. if (index == 0)
  543. {
  544. m_pDrMechDev = new DemoDevice(EventCenter, m_ConfigFileName);
  545. auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDrMechDev));
  546. return dev;
  547. }
  548. mLog::Error("unknown index[{$}]", index);
  549. unique_ptr <IODevice> dev;
  550. return dev;
  551. }
  552. void nsMech::DemoDriver::FireNotify(int code, std::string key, std::string content)
  553. {
  554. EventCenter->OnNotify(code, key, content);
  555. }
  556. void nsMech::DemoDriver::Prepare()
  557. {
  558. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Mechanical\Conf\Log4CPP.Config.MECH.xml)";
  559. //Log4CPP::ThreadContext::Map::Set("LogFileName", "MECH.Demo");
  560. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "Mech.Demo");
  561. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  562. mLog::gLogger = Log4CPP::LogManager::GetLogger("Mech.Demo");
  563. ResDataObject r_config;
  564. if (r_config.loadFile(m_ConfigFileName.c_str()))
  565. {
  566. ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
  567. }
  568. }
  569. bool nsMech::DemoDriver::Connect()
  570. {
  571. m_bDemoConnected = true;
  572. return true;
  573. }
  574. void nsMech::DemoDriver::Disconnect()
  575. {
  576. super::Disconnect();
  577. m_bDemoConnected = false;
  578. }
  579. bool nsMech::DemoDriver::isConnected() const
  580. {
  581. return m_bDemoConnected;
  582. }
  583. std::string nsMech::DemoDriver::DriverProbe()
  584. {
  585. ResDataObject r_config, HardwareInfo;
  586. if (r_config.loadFile(m_ConfigFileName.c_str()))
  587. {
  588. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  589. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  590. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  591. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  592. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  593. }
  594. else
  595. {
  596. HardwareInfo.add("MajorID", "Machine");
  597. HardwareInfo.add("MinorID", "Dr");
  598. HardwareInfo.add("VendorID", "ECOM");
  599. HardwareInfo.add("ProductID", "HF");
  600. HardwareInfo.add("SerialID", "1234");
  601. }
  602. string ret = HardwareInfo.encode();
  603. return ret;
  604. }
  605. std::string nsMech::DemoDriver::DeviceProbe()
  606. {
  607. ResDataObject r_config, HardwareInfo;
  608. if (r_config.loadFile(m_ConfigFileName.c_str()))
  609. {
  610. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  611. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  612. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  613. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  614. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  615. }
  616. else
  617. {
  618. HardwareInfo.add("MajorID", "Machine");
  619. HardwareInfo.add("MinorID", "Dr");
  620. HardwareInfo.add("VendorID", "ECOM");
  621. HardwareInfo.add("ProductID", "HF");
  622. HardwareInfo.add("SerialID", "1234");
  623. }
  624. string ret = HardwareInfo.encode();
  625. return ret;
  626. }
  627. bool nsMech::DemoDriver::GetDeviceConfig(std::string& Cfg)
  628. {
  629. Cfg = m_DeviceConfigSend.encode();
  630. return true;
  631. }
  632. bool nsMech::DemoDriver::SetDeviceConfig(std::string Cfg)
  633. {
  634. //mLog::Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  635. ResDataObject DeviceConfig;
  636. DeviceConfig.decode(Cfg.c_str());
  637. ResDataObject DescriptionTempEx;
  638. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  639. //mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  640. bool bSaveFile = false; //true:重新保存配置文件
  641. string strAccess = "";
  642. for (int i = 0; i < DescriptionTempEx.size(); i++)
  643. {
  644. string strKey = DescriptionTempEx.GetKey(i);
  645. //mLog::Info("{$}", strKey.c_str());
  646. printf("%s\n", strKey.c_str());
  647. try
  648. {
  649. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  650. {
  651. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  652. if ("RW" == strAccess)
  653. {
  654. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  655. //1. 修改内存中的值,用于给上层发消息
  656. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  657. //2. 拿到Innerkey
  658. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  659. //mLog::Info("nConfigInfoCount {$}", nConfigInfoCount);
  660. string strTemp = ""; //存储AttributeKey
  661. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  662. {
  663. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  664. if (strTemp == strKey)
  665. {
  666. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  667. break;
  668. }
  669. }
  670. //3. 修改配置文件中的值
  671. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  672. {
  673. //mLog::Debug("SetDeviceConfigValue over");
  674. bSaveFile = true;
  675. }
  676. }
  677. else
  678. {
  679. //mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  680. }
  681. }
  682. else
  683. {
  684. //mLog::Info("without this attribute {$}", strKey.c_str());
  685. }
  686. }
  687. catch (ResDataObjectExption& e)
  688. {
  689. //mLog::Error("SetDriverConfig crashed: {$}", e.what());
  690. return false;
  691. }
  692. }
  693. if (bSaveFile)
  694. {
  695. //3. 重新保存配置文件
  696. SaveConfigFile(true);
  697. }
  698. return true;
  699. }
  700. bool nsMech::DemoDriver::SaveConfigFile(bool bSendNotify)
  701. {
  702. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  703. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  704. ////mLog::Info("SaveConfigFile over {$}", bRt);
  705. return true;
  706. }
  707. bool nsMech::DemoDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  708. {
  709. strValue = "";
  710. string strTemp = pInnerKey;
  711. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  712. {
  713. int pos = 0;
  714. ResDataObject resTemp = config;
  715. while ((pos = strTemp.find_first_of(',')) != string::npos)
  716. {
  717. string Key = strTemp.substr(0, pos);
  718. string TempValue = resTemp[Key.c_str()].encode();
  719. resTemp.clear();
  720. resTemp.decode(TempValue.c_str());
  721. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  722. }
  723. if (strTemp != "")
  724. {
  725. strValue = (string)resTemp[strTemp.c_str()];
  726. }
  727. else
  728. {
  729. strValue = (string)resTemp;
  730. }
  731. }
  732. return true;
  733. }
  734. bool nsMech::DemoDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  735. {
  736. string strTemp = pInnerKey;
  737. //mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  738. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  739. {
  740. try {
  741. int pos = 0;
  742. ResDataObject* resTemp = &config;
  743. while ((pos = strTemp.find_first_of(',')) != string::npos)
  744. {
  745. string Key = strTemp.substr(0, pos);
  746. resTemp = &(*resTemp)[Key.c_str()];
  747. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  748. }
  749. if (strTemp != "")
  750. {
  751. (*resTemp)[strTemp.c_str()] = szValue;
  752. }
  753. else
  754. {
  755. *resTemp = szValue;
  756. }
  757. }
  758. catch (ResDataObjectExption& e)
  759. {
  760. mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  761. return false;
  762. }
  763. }
  764. return true;
  765. }
  766. std::string nsMech::DemoDriver::GetResource()
  767. {
  768. ResDataObject r_config, temp;
  769. if (!temp.loadFile(m_ConfigFileName.c_str()))
  770. {
  771. return "";
  772. }
  773. m_ConfigAll = temp;
  774. r_config = temp["CONFIGURATION"];
  775. m_Configurations = r_config;
  776. ResDataObject DescriptionTemp;
  777. ResDataObject DescriptionSend;
  778. ResDataObject m_DescriptionSend;
  779. ResDataObject ListTemp;
  780. string strTemp = ""; //用于读取字符串配置信息
  781. string strIndex = ""; //用于读取配置信息中的List项
  782. int nTemp = -1; //用于读取整型配置信息
  783. char sstream[10] = { 0 }; //用于转换值
  784. string strValue = ""; //用于存储配置的值
  785. string strType = ""; //用于存储配置的类型 int/float/string...
  786. try
  787. {
  788. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  789. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  790. m_pAttribute->clear();
  791. m_pDescription->clear();
  792. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  793. {
  794. DescriptionTemp.clear();
  795. DescriptionSend.clear();
  796. ListTemp.clear();
  797. //AttributeType
  798. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  799. DescriptionTemp.add(ConfKey::DiosType, strTemp.c_str());//DiosMechanicalAttribute
  800. DescriptionSend.add(ConfKey::DiosType, strTemp.c_str());//DiosMechanicalAttribute
  801. strType = strTemp; //记录配置项的类型
  802. //AttributeKey
  803. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  804. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  805. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  806. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  807. //2. 赋值
  808. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  809. if ("int" == strType)
  810. {
  811. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  812. }
  813. else if ("float" == strType)
  814. {
  815. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  816. }
  817. else //其它先按string类型处理
  818. {
  819. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  820. }
  821. //AttributeAccess
  822. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  823. DescriptionTemp.add(ConfKey::DiosAccess, strTemp.c_str());
  824. DescriptionSend.add(ConfKey::DiosAccess, strTemp.c_str());
  825. //AttributeRangeMin
  826. //strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  827. //if (strTemp != "") //不需要的配置项为空
  828. //{
  829. // DescriptionTemp.add(ConfKey::DiosRangeMin, strTemp.c_str());
  830. //}
  831. ////AttributeRangeMax
  832. //strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  833. //if (strTemp != "") //不需要的配置项为空
  834. //{
  835. // DescriptionTemp.add(ConfKey::DiosRangeMax, strTemp.c_str());
  836. //}
  837. //AttributeList
  838. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  839. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  840. {
  841. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  842. {
  843. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  844. auto temKey = std::to_string(nListIndex);
  845. ListTemp.add(temKey.c_str(), strTemp.c_str());
  846. }
  847. DescriptionTemp.add(ConfKey::DiosList, ListTemp);
  848. DescriptionSend.add(ConfKey::DiosList, ListTemp.encode());
  849. }
  850. //AttributeRequired
  851. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  852. DescriptionTemp.add(ConfKey::DiosRequired, strTemp.c_str());
  853. DescriptionSend.add(ConfKey::DiosRequired, strTemp.c_str());
  854. //AttributeDefaultValue
  855. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  856. if (strTemp != "") //不需要的配置项为空
  857. {
  858. DescriptionTemp.add(ConfKey::DiosDefaultValue, strTemp.c_str());
  859. DescriptionSend.add(ConfKey::DiosDefaultValue, strTemp.c_str());
  860. }
  861. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  862. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  863. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  864. }
  865. }
  866. catch (ResDataObjectExption& e)
  867. {
  868. mLog::Error("Get config error: {$}", e.what());
  869. return "";
  870. }
  871. ResDataObject resDeviceResource;
  872. resDeviceResource.add(ConfKey::DiosAttribute, (*m_pAttribute));
  873. resDeviceResource.add(ConfKey::DiosDescription, (*m_pDescription));
  874. ResDataObject DescriptionTempEx;
  875. DescriptionTempEx.add(ConfKey::DiosConfig, resDeviceResource);
  876. m_DeviceConfig.clear();
  877. m_DeviceConfig = DescriptionTempEx;
  878. //mLog::Debug("local ************* get resource over {$}", DescriptionTempEx.encode());
  879. resDeviceResource.clear();
  880. resDeviceResource.add(ConfKey::DiosAttribute, (*m_pAttribute));
  881. resDeviceResource.add(ConfKey::DiosDescription, m_DescriptionSend);
  882. DescriptionTempEx.clear();
  883. DescriptionTempEx.add(ConfKey::DiosConfig, resDeviceResource);
  884. m_DeviceConfigSend.clear();
  885. m_DeviceConfigSend = DescriptionTempEx;
  886. string res = m_DeviceConfigSend.encode();
  887. //mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  888. return res;
  889. }
  890. void nsMech::DemoDriver::Dequeue(const char* Packet, DWORD Length)
  891. {
  892. }
  893. PACKET_RET nsMech::DemoDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  894. {
  895. return PACKET_NOPACKET;
  896. }
  897. static nsMech::DemoDriver gIODriver;
  898. extern "C" DIOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  899. {
  900. return &gIODriver;
  901. }
  902. extern "C" DIOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  903. {
  904. return new nsMech::DemoDriver();
  905. }