CCOS.Dev.Generator.Mould.cpp 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. //
  2. #include <assert.h>
  3. #include <string>
  4. #include <limits.h> // PATH_MAX
  5. #include <unistd.h> // readlink
  6. #include <cstring>
  7. #include <dlfcn.h>
  8. #include <link.h>
  9. #include <elf.h>
  10. #include <fcntl.h>
  11. #include <sys/mman.h>
  12. #include <sys/stat.h>
  13. #include "Helper.JSON.hpp"
  14. #include "CCOS.Dev.Generator.Mould.hpp"
  15. #include "EasyJSONEncoder.hpp"
  16. #include "ResDataObject.h"
  17. #include <fstream>
  18. using namespace CCOS::Dev::Detail::Generator;
  19. namespace nsGEN = CCOS::Dev::Detail::Generator;
  20. template <>
  21. _tAPRArgs JSONTo (const std::string& in)
  22. {
  23. _tAPRArgs rc {};
  24. ResDataObject json;
  25. json.decode (in.c_str ());
  26. rc.nFocus = atoi (((string) json [0] [AttrKey::FOCUS]).c_str ());
  27. rc.nTechmode = (int) json [0] [AttrKey::TECHMODE];
  28. rc.fKV = atof (((string) json [0] [AttrKey::KV]).c_str ());
  29. rc.fMA = atof (((string) json [0] [AttrKey::MA]).c_str ());
  30. rc.fMS = atof (((string) json [0] [AttrKey::MS]).c_str ());
  31. rc.fMAS = atof (((string) json [0] [AttrKey::MAS]).c_str ());
  32. rc.nAECDensity = json [0] [AttrKey::AECDENSITY];
  33. rc.nAECFilm = json [0] [AttrKey::AECFILM];
  34. rc.nAECField = json [0] [AttrKey::AECFIELD];
  35. return rc;
  36. }
  37. template <>
  38. _tAPFArgs JSONTo(const std::string& in)
  39. {
  40. _tAPFArgs rc{};
  41. ResDataObject json;
  42. json.decode(in.c_str());
  43. auto& R0 = json[0];
  44. rc.nFluMode = atoi(((string)R0[AttrKey::FLUMode]).c_str());
  45. rc.nABSMode = (int)R0[AttrKey::FLUABSStatus];
  46. rc.nDoseLever = atof(((string)R0[AttrKey::FLUDoseLevel]).c_str());
  47. rc.nFLKV = atof(((string)R0[AttrKey::FLUKV]).c_str());
  48. rc.fFLMA = atof(((string)R0[AttrKey::FLUMA]).c_str());
  49. rc.nPPS = atoi(((string)R0[AttrKey::FLUPPS]).c_str());
  50. return rc;
  51. }
  52. //template <typename _Container, typename T>
  53. //inline _Container& operator << (_Container& ar, const T& t)
  54. //{
  55. // ar.push_back (t);
  56. // return ar;
  57. //}
  58. string nsGEN::GetProcessDirectory()
  59. {
  60. string ret = "";
  61. char szFilename[PATH_MAX] = { 0 };
  62. // Linux 获取可执行文件路径
  63. ssize_t res = readlink("/proc/self/exe", szFilename, PATH_MAX);
  64. if (res <= 0 || res >= PATH_MAX) {
  65. return ret;
  66. }
  67. szFilename[res] = '\0'; // readlink 不会添加终止符
  68. string fullpath = szFilename;
  69. string::size_type firstHit = fullpath.find_last_of('\\');
  70. if (firstHit == string::npos || firstHit == 0)
  71. {
  72. return ret;
  73. }
  74. ret = fullpath.substr(0, firstHit);//kick last \
  75. return ret;
  76. }
  77. // 获取 ELF 文件中的 .note 段信息
  78. std::string nsGEN::GetElfNoteVersion(const std::string& filename) {
  79. int fd = open(filename.c_str(), O_RDONLY);
  80. if (fd == -1) return "";
  81. struct stat st;
  82. if (fstat(fd, &st) == -1) {
  83. close(fd);
  84. return "";
  85. }
  86. void* map = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  87. if (map == MAP_FAILED) {
  88. close(fd);
  89. return "";
  90. }
  91. std::string version;
  92. ElfW(Ehdr)* ehdr = static_cast<ElfW(Ehdr)*>(map);
  93. ElfW(Shdr)* shdrs = reinterpret_cast<ElfW(Shdr)*>((uintptr_t)ehdr + ehdr->e_shoff);
  94. for (int i = 0; i < ehdr->e_shnum; ++i) {
  95. if (shdrs[i].sh_type == SHT_NOTE) {
  96. ElfW(Nhdr)* nhdr = reinterpret_cast<ElfW(Nhdr)*>((uintptr_t)map + shdrs[i].sh_offset);
  97. uintptr_t ptr = (uintptr_t)nhdr + sizeof(ElfW(Nhdr));
  98. // 跳过名称
  99. ptr += nhdr->n_namesz;
  100. if (nhdr->n_namesz % 4) ptr += 4 - (nhdr->n_namesz % 4);
  101. // 读取描述信息(版本号)
  102. if (nhdr->n_descsz > 0) {
  103. version.assign(reinterpret_cast<const char*>(ptr), nhdr->n_descsz);
  104. // 移除可能的填充字符
  105. size_t pos = version.find_first_of('\0');
  106. if (pos != std::string::npos) {
  107. version.resize(pos);
  108. }
  109. break;
  110. }
  111. }
  112. }
  113. munmap(map, st.st_size);
  114. close(fd);
  115. return version;
  116. }
  117. //获取配置文件中指定模块的版本号
  118. bool nsGEN::GetVersion(string& version, void* hMyModule)
  119. {
  120. try {
  121. std::string modulePath;
  122. if (hMyModule) {
  123. Dl_info dl_info;
  124. if (dladdr(hMyModule, &dl_info)) {
  125. modulePath = dl_info.dli_fname;
  126. }
  127. }
  128. if (modulePath.empty()) {
  129. char selfPath[PATH_MAX] = { 0 };
  130. ssize_t len = readlink("/proc/self/exe", selfPath, sizeof(selfPath) - 1);
  131. if (len <= 0) return false;
  132. selfPath[len] = '\0';
  133. modulePath = selfPath;
  134. }
  135. printf("get Generator path: %s\n", modulePath.c_str());
  136. std::string ver = GetElfNoteVersion(modulePath);
  137. if (ver.empty()) {
  138. // 备用方案:使用文件修改时间作为版本号
  139. struct stat st;
  140. if (stat(modulePath.c_str(), &st) == 0) {
  141. ver = "1.0.0." + std::to_string(st.st_mtim.tv_sec);
  142. }
  143. }
  144. if (ver.empty()) return false;
  145. version += ver;
  146. return true;
  147. }
  148. catch (...) {
  149. printf("get Generator Mould version failed\n");
  150. }
  151. return false;
  152. }
  153. bool nsGEN::GetVersion(string& version, ResDataObject& config)
  154. {
  155. try {
  156. std::string procdir = nsGEN::GetProcessDirectory();
  157. if (procdir.empty()) return false;
  158. std::string oemdrvpath = (const char*)config["oemdriver"];
  159. const std::string keystr = "%ROOT%";
  160. size_t pos = 0;
  161. while ((pos = oemdrvpath.find(keystr, pos)) != std::string::npos) {
  162. oemdrvpath.replace(pos, keystr.size(), procdir);
  163. pos += procdir.size();
  164. }
  165. printf("get Generator path: %s\n", oemdrvpath.c_str());
  166. std::string ver = GetElfNoteVersion(oemdrvpath);
  167. if (ver.empty()) {
  168. // 备用方案:使用文件修改时间作为版本号
  169. struct stat st;
  170. if (stat(oemdrvpath.c_str(), &st) == 0) {
  171. ver = "1.0.0." + std::to_string(st.st_mtim.tv_sec);
  172. }
  173. }
  174. if (ver.empty()) return false;
  175. version += ver;
  176. return true;
  177. }
  178. catch (...) {
  179. printf("get Generator Mould version failed\n");
  180. }
  181. return false;
  182. }
  183. bool nsGEN::GetVersion(string& version)
  184. {
  185. char selfPath[PATH_MAX] = { 0 };
  186. ssize_t len = readlink("/proc/self/exe", selfPath, sizeof(selfPath) - 1);
  187. if (len <= 0) return false;
  188. selfPath[len] = '\0';
  189. printf("get Generator path: %s\n", selfPath);
  190. std::string ver = GetElfNoteVersion(selfPath);
  191. if (ver.empty()) {
  192. // 备用方案:使用文件修改时间作为版本号
  193. struct stat st;
  194. if (stat(selfPath, &st) == 0) {
  195. ver = "1.0.0." + std::to_string(st.st_mtim.tv_sec);
  196. }
  197. }
  198. if (ver.empty()) return false;
  199. version += ver;
  200. return true;
  201. }
  202. void nsGEN::TransJsonText(ResDataObject& config)
  203. {
  204. for (int x = 0; x < config.size(); x++)
  205. {
  206. //如果有Value
  207. if (config[x].GetKeyCount("Value") > 0)
  208. {
  209. //mLog::FINFO("TRY COVERT [{$}] VALUE {$}", config.GetKey(x), config[x]["Value"].size() > 0 ? config[x]["Value"].encode() : (const char*)config[x]["Value"]);
  210. if (config[x]["Value"].size() <= 0)
  211. {
  212. string va = (const char*)config[x]["Value"];
  213. config[x] = va.c_str();
  214. }
  215. else
  216. {
  217. ResDataObject rest = config[x]["Value"];
  218. config[x] = rest;
  219. //mLog::FINFO("convert object [{$}], object {$}", config.GetKey(x), rest.encode());
  220. }
  221. }
  222. //mLog::FINFO("After Convert {$}", config.encode());
  223. }
  224. }
  225. //-----------------------------------------------------------------------------
  226. // nsGEN::GeneratorMould
  227. //-----------------------------------------------------------------------------
  228. //Log4CPP::Logger* mLog::gLogger = nullptr;
  229. nsGEN::GeneratorMould::GeneratorMould ()
  230. {
  231. //if (mLog::gLogger == nullptr)
  232. //{
  233. // string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  234. // //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.Mould");
  235. // Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.Mould");
  236. // auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  237. // mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.Mould");
  238. //}
  239. ////添加模型日志打印
  240. //string version;
  241. //if (GetVersion(version, hMyModule))
  242. // mLog::Info("\n===============log begin : Mould version:{$} ===================\n", version.c_str());
  243. //else
  244. // mLog::Info("\n===============log begin : Mould version:0.0.0.0 ===================\n");
  245. //不知有何用
  246. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 999999, 1));
  247. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 999999, 1));
  248. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 999999, 1));
  249. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 999999, 1));
  250. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 999999, 1));
  251. m_DoseUnit.m_Modality.reset(new MODALITYMould("DX"));
  252. //设备状态
  253. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_RAD_XRAYOFF, 1));
  254. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  255. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  256. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  257. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  258. m_DoseUnit.m_EXAMMode.reset(new EXAMMODEMould(AttrKey::EXAMMODE_TYPE::MANUAL));
  259. m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 2, 1));
  260. m_DoseUnit.m_ReferenceAirKerma.reset(new REFERENCEAIRKERMAMould(0, 0, 999999.0, 0.01));
  261. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould("null"));
  262. m_DoseUnit.m_TubeTargetMaterial.reset(new TUBETARGETMATERIALMould(AttrKey::TUBETARGETMATERIAL_TYPE::MO));
  263. m_DoseUnit.m_TubeAngle.reset(new TUBEANGLEMould(0.0, 0.0, 360.0, 1));
  264. //点片参数
  265. m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 150.0, 1.0));
  266. m_DoseUnit.m_MA.reset(new MAMould(0.0, 1.0, 5000.0, 0.1));
  267. m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 50000.0, 0.01));
  268. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.5, 5000.0, 0.01));
  269. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
  270. m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
  271. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  272. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  273. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  274. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 150.0, 1.0));
  275. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 8.0, 1000.0, 0.1));
  276. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  277. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  278. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0.0, 0.0, 30.0, 0.01));
  279. m_DoseUnit.m_KVList.reset(new KVLISTMould(""));
  280. m_DoseUnit.m_mAsList.reset(new MASLISTMould(""));
  281. //透视参数不通用暂时不初始化
  282. }
  283. nsGEN::GeneratorMould::~GeneratorMould ()
  284. {
  285. //ReleaseLogger();
  286. //delete g_GENLogger;
  287. }
  288. //-----------------------------------------------------------------------------
  289. // 所有注册应函数
  290. //-----------------------------------------------------------------------------
  291. void nsGEN::GeneratorMould::Register (Dispatch* Dispatch)
  292. {
  293. //不知有何用
  294. Dispatch->Get.Push(AttrKey::TOTALEXPSURENUMBER, [this](std::string& out) {
  295. if (m_DoseUnit.m_GenTotalExpNumber)
  296. out = m_DoseUnit.m_GenTotalExpNumber->JSGet();
  297. return RET_STATUS::RET_SUCCEED; });
  298. Dispatch->Get.Push(AttrKey::TOTALACQTIMES, [this](std::string& out) {
  299. if (m_DoseUnit.m_GenTotalAcqTimes)
  300. out = m_DoseUnit.m_GenTotalAcqTimes->JSGet();
  301. return RET_STATUS::RET_SUCCEED; });
  302. Dispatch->Get.Push(AttrKey::TUBECOOLWAITTIME, [this](std::string& out) {
  303. if (m_DoseUnit.m_GenTubeCoolWaitTimes)
  304. out = m_DoseUnit.m_GenTubeCoolWaitTimes->JSGet();
  305. return RET_STATUS::RET_SUCCEED; });
  306. Dispatch->Get.Push(AttrKey::TUBEOVERLOADNUMBER, [this](std::string& out) {
  307. if (m_DoseUnit.m_GenTubeOverLoadNumber)
  308. out = m_DoseUnit.m_GenTubeOverLoadNumber->JSGet();
  309. return RET_STATUS::RET_SUCCEED; });
  310. Dispatch->Get.Push(AttrKey::CURRENTEXPOSUREBNUMBER, [this](std::string& out) {
  311. if (m_DoseUnit.m_GenCurrentExpNumber)
  312. out = m_DoseUnit.m_GenCurrentExpNumber->JSGet();
  313. return RET_STATUS::RET_SUCCEED; });
  314. //Modality ?
  315. Dispatch->Get.Push(AttrKey::MODALITY, [this](std::string& out) {
  316. if (m_DoseUnit.m_Modality)
  317. out = m_DoseUnit.m_Modality->JSGet();
  318. return RET_STATUS::RET_SUCCEED; });
  319. Dispatch->Action.Push(ActionKey::SetModality, [this](std::string in, std::string& out) {
  320. ResDataObject json;
  321. json.decode(in.c_str());
  322. auto value = (string)json[0];
  323. if (m_DoseUnit.m_Modality != nullptr)
  324. {
  325. m_DoseUnit.m_Modality->Update(value);
  326. }
  327. return RET_STATUS::RET_SUCCEED; });
  328. //热熔
  329. Dispatch->Get.Push(AttrKey::TUBEHEAT, [this](std::string& out) {
  330. if (m_DoseUnit.m_HE)
  331. out = m_DoseUnit.m_HE->JSGet();
  332. return RET_STATUS::RET_SUCCEED; });
  333. Dispatch->Action.Push(ActionKey::Query_HE, [this](std::string in, std::string& out) {
  334. int value = 0;
  335. RET_STATUS ret = QueryHE(value);
  336. out = ToJSON(value);return ret;});
  337. //球管状态
  338. Dispatch->Get.Push(AttrKey::TUBEINFO, [this](std::string& out) {
  339. if (m_DoseUnit.m_TubeInfo)
  340. out = m_DoseUnit.m_TubeInfo->JSGet();
  341. return RET_STATUS::RET_SUCCEED; });
  342. Dispatch->Get.Push(AttrKey::TUBEANGLE, [this](std::string& out) {
  343. if (m_DoseUnit.m_TubeAngle)
  344. out = m_DoseUnit.m_TubeAngle->JSGet();
  345. return RET_STATUS::RET_SUCCEED; });
  346. Dispatch->Action.Push(ActionKey::SetTubeAngle, [this](std::string in, std::string& out) {
  347. auto value = JSONTo <float>(in);
  348. if (m_DoseUnit.m_TubeAngle != nullptr)
  349. {
  350. m_DoseUnit.m_TubeAngle->Update(value);
  351. }
  352. return RET_STATUS::RET_SUCCEED; });
  353. Dispatch->Get.Push(AttrKey::TUBETARGETMATERIAL, [this](std::string& out) {
  354. if (m_DoseUnit.m_TubeTargetMaterial)
  355. out = m_DoseUnit.m_TubeTargetMaterial->JSGet();
  356. return RET_STATUS::RET_SUCCEED; });
  357. Dispatch->Action.Push(ActionKey::SetTubeTargetMaterial, [this](std::string in, std::string& out) {
  358. ResDataObject json;
  359. json.decode(in.c_str());
  360. auto value = (string)json[0];
  361. if (m_DoseUnit.m_TubeTargetMaterial != nullptr)
  362. {
  363. m_DoseUnit.m_TubeTargetMaterial->Update(value);
  364. }
  365. return RET_STATUS::RET_SUCCEED; });
  366. //电池状态
  367. Dispatch->Get.Push(AttrKey::BATTERYCHARGESTATE, [this](std::string& out) {
  368. if (m_DoseUnit.m_BatteryChargeState)
  369. out = m_DoseUnit.m_BatteryChargeState->JSGet();
  370. return RET_STATUS::RET_SUCCEED; });
  371. Dispatch->Get.Push(AttrKey::REFERENCEAIRKERMA, [this](std::string& out) {
  372. out = m_DoseUnit.m_ReferenceAirKerma->JSGet();
  373. return RET_STATUS::RET_SUCCEED; });
  374. //设备状态
  375. Dispatch->Get.Push(AttrKey::GENSTATE, [this](std::string& out) {
  376. if (m_DoseUnit.m_GenState)
  377. out = m_DoseUnit.m_GenState->JSGet();
  378. return RET_STATUS::RET_SUCCEED; });
  379. //曝光模式
  380. Dispatch->Get.Push(AttrKey::EXPMODE, [this](std::string& out) {
  381. if (m_DoseUnit.m_ExpMode)
  382. out = m_DoseUnit.m_ExpMode->JSGet();
  383. return RET_STATUS::RET_SUCCEED; });
  384. Dispatch->Set.Push(AttrKey::EXPMODE, [this](std::string in) {
  385. ResDataObject json;
  386. json.decode(in.c_str());
  387. auto value = (string)json[0];
  388. return SetExpMode(value); });
  389. Dispatch->Action.Push(ActionKey::SetExpMode, [this](std::string in, std::string& out) {
  390. ResDataObject json;
  391. json.decode(in.c_str());
  392. auto value = (string)json[0];
  393. return SetExpMode(value); });
  394. //检查模式
  395. Dispatch->Get.Push(AttrKey::EXAMMODE, [this](std::string& out) {
  396. if (m_DoseUnit.m_EXAMMode)
  397. out = m_DoseUnit.m_EXAMMode->JSGet();
  398. return RET_STATUS::RET_SUCCEED; });
  399. Dispatch->Set.Push(AttrKey::EXAMMODE, [this](std::string in) {
  400. ResDataObject json;
  401. json.decode(in.c_str());
  402. auto value = (string)json[0];
  403. return SetEXAMMode(value); });
  404. Dispatch->Action.Push(ActionKey::SetEXAMMode, [this](std::string in, std::string& out) {
  405. ResDataObject json;
  406. json.decode(in.c_str());
  407. auto value = (string)json[0];
  408. return SetEXAMMode(value); });
  409. //工作位
  410. Dispatch->Get.Push(AttrKey::WORKSTATION, [this](std::string& out) {
  411. if (m_DoseUnit.m_WS)
  412. out = m_DoseUnit.m_WS->JSGet();
  413. return RET_STATUS::RET_SUCCEED; });
  414. Dispatch->Set.Push(AttrKey::WORKSTATION, [this](std::string in) {
  415. printf("JSSetWORKSTATION:%s\n", in.c_str());
  416. ResDataObject json;
  417. json.decode(in.c_str());
  418. string value = json[0].encode();
  419. int tempws = 0;
  420. if (value == "Table")
  421. {
  422. tempws = 0;
  423. }
  424. else if (value == "Wall")
  425. {
  426. tempws = 1;
  427. }
  428. else if (value == "Direct")
  429. {
  430. tempws = 2;
  431. }
  432. else if (value == "Free")
  433. {
  434. tempws = 3;
  435. }
  436. return SetWS(value); });
  437. Dispatch->Action.Push(ActionKey::SetValue_WORKSTATION, [this](std::string in, std::string& out) {
  438. printf("JSSetWORKSTATION:%s\n", in.c_str());
  439. ResDataObject json;
  440. json.decode(in.c_str());
  441. string value = json[0].encode();
  442. int tempws = 0;
  443. if (value == "Table")
  444. {
  445. tempws = 0;
  446. }
  447. else if (value == "Wall")
  448. {
  449. tempws = 1;
  450. }
  451. else if (value == "Direct")
  452. {
  453. tempws = 2;
  454. }
  455. else if (value == "Free")
  456. {
  457. tempws = 3;
  458. }
  459. return SetWS(value); });
  460. //重置
  461. Dispatch->Action.Push(ActionKey::Reset, [this](std::string in, std::string& out) {
  462. return Reset(); });
  463. //同步模式
  464. Dispatch->Action.Push(ActionKey::ActiveSyncMode, [this](std::string in, std::string& out) {
  465. ResDataObject json;
  466. json.decode(in.c_str());
  467. _tSyncModeArgs t{ };
  468. if (json.size() >= 3)
  469. {
  470. t.strWS = (string)json[0];
  471. t.strSyncMode = (string)json[1];
  472. t.strSyncValue = (string)json[2];
  473. return ActiveSyncMode(t);
  474. }
  475. else
  476. {
  477. return RET_STATUS::RET_FAILED;
  478. }});
  479. Dispatch->Action.Push(ActionKey::SimulateError, [this](std::string in, std::string& out) {
  480. ResDataObject json;
  481. json.decode(in.c_str());
  482. auto value = (string)json[0];
  483. return SimulateError(value); });
  484. Dispatch->Action.Push(ActionKey::SetDeviceSleepState, [this](std::string in, std::string& out) {
  485. ResDataObject json;
  486. json.decode(in.c_str());
  487. auto value = (int)json[0];
  488. return SetDeviceSleepState(value); });
  489. //注册updata
  490. Dispatch->Update.Push("CurrentSMState", [this](std::string in, std::string& out) {
  491. return SetGenCurrentSMState(in); });
  492. }
  493. void nsGEN::GeneratorMould::RegisterOther(Dispatch* Dispatch) // 子类可能希望注册更多的
  494. {
  495. //遮光器属性
  496. Dispatch->Action.Push(ActionKey::SetCollimatorLight, [this](std::string in, std::string& out) {
  497. auto value = JSONTo <float>(in);
  498. SetCollimatorLight(value);
  499. return RET_STATUS::RET_SUCCEED;
  500. });
  501. }
  502. void nsGEN::GeneratorMould::RegisterAEC(Dispatch* Dispatch)
  503. {
  504. Dispatch->Get.Push(AttrKey::AECDENSITY, [this](std::string& out) {
  505. if (m_DoseUnit.m_AECDensity)
  506. out = m_DoseUnit.m_AECDensity->JSGet();
  507. return RET_STATUS::RET_SUCCEED; });
  508. Dispatch->Set.Push(AttrKey::AECDENSITY, [this](std::string in) {
  509. auto value = JSONTo <int>(in);
  510. return SetAECDensity(value); });
  511. Dispatch->Action.Push(ActionKey::SetValue_AECDENSITY, [this](std::string in, std::string& out) {
  512. auto value = JSONTo <int>(in);
  513. return SetAECDensity(value);});
  514. Dispatch->Action.Push(ActionKey::IncParam_AECDENSITY, [this](std::string in, std::string& out) {
  515. return IncAECDensity(); });
  516. Dispatch->Action.Push(ActionKey::DecParam_AECDENSITY, [this](std::string in, std::string& out) {
  517. return DecAECDensity(); });
  518. Dispatch->Get.Push(AttrKey::AECFIELD, [this](std::string& out) {
  519. if (m_DoseUnit.m_AECField)
  520. out = m_DoseUnit.m_AECField->JSGet();
  521. return RET_STATUS::RET_SUCCEED; });
  522. Dispatch->Set.Push(AttrKey::AECFIELD, [this](std::string in) {
  523. auto value = JSONTo <int>(in);
  524. return SetAECField(value); });
  525. Dispatch->Action.Push(ActionKey::SetValue_AECFIELD, [this](std::string in, std::string& out) {
  526. auto value = JSONTo <int>(in);
  527. return SetAECField(value); });
  528. Dispatch->Get.Push(AttrKey::AECFILM, [this](std::string& out) {
  529. if (m_DoseUnit.m_AECFilm)
  530. out = m_DoseUnit.m_AECFilm->JSGet();
  531. return RET_STATUS::RET_SUCCEED; });
  532. Dispatch->Set.Push(AttrKey::AECFILM, [this](std::string in) {
  533. auto value = JSONTo <int>(in);
  534. return SetAECFilm(value); });
  535. Dispatch->Action.Push(ActionKey::SetValue_AECFILM, [this](std::string in, std::string& out) {
  536. auto value = JSONTo <int>(in);
  537. return SetAECFilm(value); });
  538. }
  539. void nsGEN::GeneratorMould::RegisterExpEnable(Dispatch* Dispatch)
  540. {
  541. Dispatch->Action.Push(ActionKey::SetExpEnable, [this](std::string in, std::string& out) {
  542. return SetExpEnable(); });
  543. Dispatch->Action.Push(ActionKey::SetExpDisable, [this](std::string in, std::string& out) {
  544. return SetExpDisable(); });
  545. }
  546. void nsGEN::GeneratorMould::RegisterGeneratortoSyncStatus(Dispatch* Dispatch)
  547. {
  548. Dispatch->Get.Push(AttrKey::GENSYNSTATE, [this](std::string& out) {
  549. if (m_DoseUnit.m_GenSynState)
  550. out = m_DoseUnit.m_GenSynState->JSGet();
  551. return RET_STATUS::RET_SUCCEED; });
  552. Dispatch->Set.Push(AttrKey::GENSYNSTATE, [this](std::string in) {
  553. auto value = JSONTo <int>(in);
  554. return SetGenSynState(value); });
  555. Dispatch->Action.Push(ActionKey::SetGeneratortoSyncStatus, [this](std::string in, std::string& out) {
  556. auto value = JSONTo <int>(in);
  557. return SetGenSynState(value); });
  558. }
  559. void nsGEN::GeneratorMould::RegisterRAD(Dispatch* Dispatch)
  560. {
  561. //KV
  562. Dispatch->Get.Push(AttrKey::KVLIST, [this](std::string& out) {
  563. if (m_DoseUnit.m_KVList)
  564. out = m_DoseUnit.m_KVList->JSGet();
  565. return RET_STATUS::RET_SUCCEED; });
  566. Dispatch->Get.Push(AttrKey::KV, [this](std::string& out) {
  567. if (m_DoseUnit.m_KV)
  568. out = m_DoseUnit.m_KV->JSGet();
  569. return RET_STATUS::RET_SUCCEED; });
  570. Dispatch->Set.Push(AttrKey::KV, [this](std::string in) {
  571. auto value = JSONTo <float>(in);
  572. return SetKV(value); });
  573. Dispatch->Action.Push(ActionKey::IncParam_KV, [this](std::string in, std::string& out) {
  574. return IncKV(); });
  575. Dispatch->Action.Push(ActionKey::DecParam_KV, [this](std::string in, std::string& out) {
  576. return DecKV(); });
  577. Dispatch->Action.Push(ActionKey::IncParam_KVL, [this](std::string in, std::string& out) {
  578. return IncKVL(); });
  579. Dispatch->Action.Push(ActionKey::DecParam_KVL, [this](std::string in, std::string& out) {
  580. return DecKVL(); });
  581. Dispatch->Action.Push(ActionKey::SetValue_KV, [this](std::string in, std::string& out) {
  582. auto value = JSONTo <float>(in);
  583. return SetKV(value); });
  584. //MA
  585. Dispatch->Get.Push(AttrKey::MA, [this](std::string& out) {
  586. if (m_DoseUnit.m_MA)
  587. out = m_DoseUnit.m_MA->JSGet();
  588. return RET_STATUS::RET_SUCCEED; });
  589. Dispatch->Set.Push(AttrKey::MA, [this](std::string in) {
  590. auto value = JSONTo <float>(in);
  591. return SetMA(value); });
  592. Dispatch->Action.Push(ActionKey::IncParam_MA, [this](std::string in, std::string& out) {
  593. return IncMA(); });
  594. Dispatch->Action.Push(ActionKey::DecParam_MA, [this](std::string in, std::string& out) {
  595. return DecMA();});
  596. Dispatch->Action.Push(ActionKey::IncParam_MAL, [this](std::string in, std::string& out) {
  597. return IncMAL(); });
  598. Dispatch->Action.Push(ActionKey::DecParam_MAL, [this](std::string in, std::string& out) {
  599. return DecMAL(); });
  600. Dispatch->Action.Push(ActionKey::SetValue_MA, [this](std::string in, std::string& out) {
  601. auto value = JSONTo <float>(in);
  602. return SetMA(value); });
  603. //MS
  604. Dispatch->Get.Push(AttrKey::MS, [this](std::string& out) {
  605. if (m_DoseUnit.m_MS)
  606. out = m_DoseUnit.m_MS->JSGet();
  607. return RET_STATUS::RET_SUCCEED; });
  608. Dispatch->Set.Push(AttrKey::MS, [this](std::string in) {
  609. auto value = JSONTo <float>(in);
  610. return SetMS(value); });
  611. Dispatch->Action.Push(ActionKey::IncParam_MS, [this](std::string in, std::string& out) {
  612. return IncMS(); });
  613. Dispatch->Action.Push(ActionKey::DecParam_MS, [this](std::string in, std::string& out) {
  614. return DecMS(); });
  615. Dispatch->Action.Push(ActionKey::IncParam_MSL, [this](std::string in, std::string& out) {
  616. return IncMSL(); });
  617. Dispatch->Action.Push(ActionKey::DecParam_MSL, [this](std::string in, std::string& out) {
  618. return DecMSL(); });
  619. Dispatch->Action.Push(ActionKey::SetValue_MS, [this](std::string in, std::string& out) {
  620. auto value = JSONTo <float>(in);
  621. return SetMS(value); });
  622. //MAS
  623. Dispatch->Get.Push(AttrKey::MASLIST, [this](std::string& out) {
  624. if (m_DoseUnit.m_mAsList)
  625. out = m_DoseUnit.m_mAsList->JSGet();
  626. return RET_STATUS::RET_SUCCEED; });
  627. Dispatch->Get.Push(AttrKey::MAS, [this](std::string& out) {
  628. if (m_DoseUnit.m_MAS)
  629. out = m_DoseUnit.m_MAS->JSGet();
  630. return RET_STATUS::RET_SUCCEED; });
  631. Dispatch->Set.Push(AttrKey::MAS, [this](std::string in) {
  632. auto value = JSONTo <float>(in);
  633. return SetMAS(value); });
  634. Dispatch->Action.Push(ActionKey::IncParam_MAS, [this](std::string in, std::string& out) {
  635. return IncMAS(); });
  636. Dispatch->Action.Push(ActionKey::DecParam_MAS, [this](std::string in, std::string& out) {
  637. return DecMAS(); });
  638. Dispatch->Action.Push(ActionKey::IncParam_MASL, [this](std::string in, std::string& out) {
  639. return IncMASL(); });
  640. Dispatch->Action.Push(ActionKey::DecParam_MASL, [this](std::string in, std::string& out) {
  641. return DecMASL(); });
  642. Dispatch->Action.Push(ActionKey::SetValue_MAS, [this](std::string in, std::string& out) {
  643. auto value = JSONTo <float>(in);
  644. return SetMAS(value); });
  645. //FOCUS
  646. Dispatch->Get.Push(AttrKey::FOCUS, [this](std::string& out) {
  647. if (m_DoseUnit.m_Focus)
  648. out = m_DoseUnit.m_Focus->JSGet();
  649. return RET_STATUS::RET_SUCCEED; });
  650. Dispatch->Set.Push(AttrKey::FOCUS, [this](std::string in) {
  651. auto value = JSONTo <int>(in);
  652. return SetFocus(value); });
  653. Dispatch->Action.Push(ActionKey::SetValue_FOCUS, [this](std::string in, std::string& out) {
  654. auto value = JSONTo <int>(in);
  655. return SetFocus(value); });
  656. //TECHMODE
  657. Dispatch->Get.Push(AttrKey::TECHMODE, [this](std::string& out) {
  658. if (m_DoseUnit.m_Techmode)
  659. out = m_DoseUnit.m_Techmode->JSGet();
  660. return RET_STATUS::RET_SUCCEED; });
  661. Dispatch->Set.Push(AttrKey::TECHMODE, [this](std::string in) {
  662. auto value = JSONTo <int>(in);
  663. return SetTechmode(value); });
  664. Dispatch->Action.Push(ActionKey::SetValue_TECHMODE, [this](std::string in, std::string& out) {
  665. auto value = JSONTo <int>(in);
  666. return SetTechmode(value); });
  667. //APR
  668. Dispatch->Action.Push(ActionKey::SetAPR, [this](std::string in, std::string& out) {
  669. ResDataObject json;
  670. if (!json.decode(in.c_str())) {
  671. printf("Failed to decode JSON input\n");
  672. out = "{\"error\":\"Invalid JSON format\"}";
  673. return RET_STATUS::RET_FAILED;
  674. }
  675. vector<_tAPRArgs> APRarray;
  676. try
  677. {
  678. for (int i = 0; i < json.size(); i++)
  679. {
  680. ResDataObject param = json[i];
  681. _tAPRArgs apr{ };
  682. try {
  683. apr.nWS = (int)param[AttrKey::WORKSTATION];
  684. }
  685. catch (...) {
  686. apr.nWS = 0;
  687. printf("Warning: Invalid WORKSTATION value, using default 0\n");
  688. }
  689. try {
  690. apr.nFocus = (int)param[AttrKey::FOCUS];
  691. }
  692. catch (...) {
  693. apr.nFocus = 0;
  694. printf("Warning: Invalid FOCUS value, using default 0\n");
  695. }
  696. try {
  697. apr.nTechmode = (int)param[AttrKey::TECHMODE];
  698. }
  699. catch (...) {
  700. apr.nTechmode = 0;
  701. printf("Warning: Invalid TECHMODE value, using default 0\n");
  702. }
  703. try {
  704. apr.fKV = (float)param[AttrKey::KV];
  705. }
  706. catch (...) {
  707. apr.fKV = 0.0f;
  708. printf("Warning: Invalid KV value, using default 0.0\n");
  709. }
  710. try {
  711. apr.fMA = (float)param[AttrKey::MA];
  712. }
  713. catch (...) {
  714. apr.fMA = 0.0f;
  715. printf("Warning: Invalid MA value, using default 0.0\n");
  716. }
  717. try {
  718. apr.fMS = (float)param[AttrKey::MS];
  719. }
  720. catch (...) {
  721. apr.fMS = 0.0f;
  722. printf("Warning: Invalid MS value, using default 0.0\n");
  723. }
  724. try {
  725. apr.fKV2 = (float)param[AttrKey::KV2];
  726. }
  727. catch (...) {
  728. apr.fKV2 = 0.0f;
  729. printf("Warning: Invalid KV2 value, using default 0.0\n");
  730. }
  731. try {
  732. apr.fMA2 = (float)param[AttrKey::MA2];
  733. }
  734. catch (...) {
  735. apr.fMA2 = 0.0f;
  736. printf("Warning: Invalid MA2 value, using default 0.0\n");
  737. }
  738. try {
  739. apr.fMS2 = (float)param[AttrKey::MS2];
  740. }
  741. catch (...) {
  742. apr.fMS2 = 0.0f;
  743. printf("Warning: Invalid MS2 value, using default 0.0\n");
  744. }
  745. try {
  746. apr.fMAS = (float)param[AttrKey::MAS];
  747. }
  748. catch (...) {
  749. apr.fMAS = 0.0f;
  750. printf("Warning: Invalid MAS value, using default 0.0\n");
  751. }
  752. try {
  753. apr.nAECDensity = (int)param[AttrKey::AECDENSITY];
  754. }
  755. catch (...) {
  756. apr.nAECDensity = 0;
  757. printf("Warning: Invalid AECDENSITY value, using default 0\n");
  758. }
  759. try {
  760. apr.nAECFilm = (int)param[AttrKey::AECFILM];
  761. }
  762. catch (...) {
  763. apr.nAECFilm = 0;
  764. printf("Warning: Invalid AECFILM value, using default 0\n");
  765. }
  766. try {
  767. apr.nAECField = (int)param[AttrKey::AECFIELD];
  768. }
  769. catch (...) {
  770. apr.nAECField = 0;
  771. printf("Warning: Invalid AECFIELD value, using default 0\n");
  772. }
  773. APRarray.push_back(apr);
  774. }
  775. }
  776. catch (const std::exception& e) {
  777. printf("SetAPR Exception: %s\n", e.what());
  778. APRarray.push_back(_tAPRArgs{});
  779. }
  780. catch (...) {
  781. printf("SetAPR Unknown Exception\n");
  782. APRarray.push_back(_tAPRArgs{});
  783. }
  784. if (APRarray.empty()) {
  785. printf("Warning: APRarray is empty, adding default parameters\n");
  786. APRarray.push_back(_tAPRArgs{});
  787. }
  788. if (APRarray.size() > 1) {
  789. return SetAPRArray(APRarray);
  790. }
  791. else {
  792. return SetAPR(APRarray[0]);
  793. } });
  794. Dispatch->Action.Push(ActionKey::SetAPRArray, [this](std::string in, std::string& out) {
  795. ResDataObject json;
  796. json.decode(in.c_str());
  797. vector<_tAPRArgs> APRarray;
  798. try
  799. {
  800. for (int i = 0; i < json.size(); i++)
  801. {
  802. ResDataObject param = json[i];
  803. _tAPRArgs apr{ };
  804. apr.nWS = (int)param[AttrKey::WORKSTATION];
  805. apr.nFocus = (int)param[AttrKey::FOCUS];
  806. apr.nTechmode = (int)param[AttrKey::TECHMODE];
  807. apr.fKV = (float)param[AttrKey::KV];
  808. apr.fMA = (float)param[AttrKey::MA];
  809. apr.fMS = (float)param[AttrKey::MS];
  810. apr.fKV2 = (float)param[AttrKey::KV2];
  811. apr.fMA2 = (float)param[AttrKey::MA2];
  812. apr.fMS2 = (float)param[AttrKey::MS2];
  813. apr.fMAS = (float)param[AttrKey::MAS];
  814. apr.nAECDensity = (int)param[AttrKey::AECDENSITY];
  815. apr.nAECFilm = (int)param[AttrKey::AECFILM];
  816. apr.nAECField = (int)param[AttrKey::AECFIELD];
  817. APRarray.push_back(apr);
  818. }
  819. }
  820. catch (...)
  821. {
  822. printf("SetAPRArray Crash\n");
  823. }
  824. return SetAPRArray(APRarray); });
  825. //序列点片帧率
  826. Dispatch->Get.Push(AttrKey::FRAMERATE, [this](std::string& out) {
  827. if (m_DoseUnit.m_FrameRate)
  828. out = m_DoseUnit.m_FrameRate->JSGet();
  829. return RET_STATUS::RET_SUCCEED; });
  830. Dispatch->Set.Push(AttrKey::FRAMERATE, [this](std::string in) {
  831. auto value = JSONTo <float>(in);
  832. return SetFrameRate(value); });
  833. Dispatch->Action.Push(ActionKey::SetFrameRate, [this](std::string in, std::string& out) {
  834. auto value = JSONTo <float>(in);
  835. return SetFrameRate(value); });
  836. //曝光后的post值
  837. Dispatch->Action.Push(ActionKey::GetValue_POSTKV, [this](std::string in, std::string& out) {
  838. float value = 0;
  839. RET_STATUS ret = QueryPostKV(value);
  840. ResDataObject tempret;
  841. tempret = value;
  842. out = (const char*)tempret;
  843. return ret; });
  844. Dispatch->Get.Push(AttrKey::POSTKV, [this](std::string& out) {
  845. if (m_DoseUnit.m_PostKV)
  846. out = m_DoseUnit.m_PostKV->JSGet();
  847. return RET_STATUS::RET_SUCCEED; });
  848. Dispatch->Action.Push(ActionKey::GetValue_POSTMA, [this](std::string in, std::string& out) {
  849. float value = 0;
  850. RET_STATUS ret = QueryPostMA(value);
  851. ResDataObject tempret;
  852. tempret = value;
  853. out = (const char*)tempret;
  854. return ret; });
  855. Dispatch->Get.Push(AttrKey::POSTMA, [this](std::string& out) {
  856. if (m_DoseUnit.m_PostMA)
  857. out = m_DoseUnit.m_PostMA->JSGet();
  858. return RET_STATUS::RET_SUCCEED; });
  859. Dispatch->Action.Push(ActionKey::GetValue_POSTMS, [this](std::string in, std::string& out) {
  860. float value = 0;
  861. RET_STATUS ret = QueryPostMS(value);
  862. ResDataObject tempret;
  863. tempret = value;
  864. out = (const char*)tempret;
  865. return ret; });
  866. Dispatch->Get.Push(AttrKey::POSTMS, [this](std::string& out) {
  867. if (m_DoseUnit.m_PostMS)
  868. out = m_DoseUnit.m_PostMS->JSGet();
  869. return RET_STATUS::RET_SUCCEED; });
  870. Dispatch->Action.Push(ActionKey::GetValue_POSTMAS, [this](std::string in, std::string& out) {
  871. float value = 0;
  872. RET_STATUS ret = QueryPostMAS(value);
  873. ResDataObject tempret;
  874. tempret = value;
  875. out = (const char*)tempret;
  876. return ret; });
  877. Dispatch->Get.Push(AttrKey::POSTMAS, [this](std::string& out) {
  878. if (m_DoseUnit.m_PostMAS)
  879. out = m_DoseUnit.m_PostMAS->JSGet();
  880. return RET_STATUS::RET_SUCCEED; });
  881. }
  882. void nsGEN::GeneratorMould::RegisterFluoro(Dispatch* Dispatch)
  883. {
  884. //透视模式
  885. Dispatch->Get.Push(AttrKey::FLUMode, [this](std::string& out) {
  886. if (m_DoseUnit.m_FLMode)
  887. out = m_DoseUnit.m_FLMode->JSGet();
  888. return RET_STATUS::RET_SUCCEED; });
  889. Dispatch->Get.Push(AttrKey::FLUAccTimeUnit, [this](std::string& out) {
  890. out = m_DoseUnit.m_FLAccTimeUnit;
  891. return RET_STATUS::RET_SUCCEED; });
  892. Dispatch->Set.Push(AttrKey::FLUMode, [this](std::string in) {
  893. ResDataObject json;
  894. json.decode(in.c_str());
  895. auto value = (string)json[0];
  896. return SetFLFMode(value); });
  897. Dispatch->Action.Push(ActionKey::SetFLFMode, [this](std::string in, std::string& out) {
  898. ResDataObject json;
  899. json.decode(in.c_str());
  900. auto value = (string)json[0];
  901. return SetFLFMode(value); });
  902. //透视KV
  903. Dispatch->Get.Push(AttrKey::FLUKV, [this](std::string& out) {
  904. if (m_DoseUnit.m_FLKV)
  905. out = m_DoseUnit.m_FLKV->JSGet();
  906. return RET_STATUS::RET_SUCCEED; });
  907. Dispatch->Set.Push(AttrKey::FLUKV, [this](std::string in) {
  908. auto value = JSONTo <float>(in);
  909. return SetFluKV(value); });
  910. Dispatch->Action.Push(ActionKey::IncParam_FluKV, [this](std::string in, std::string& out) {
  911. return IncFluKV(); });
  912. Dispatch->Action.Push(ActionKey::DecParam_FluKV, [this](std::string in, std::string& out) {
  913. return DecFluKV(); });
  914. Dispatch->Action.Push(ActionKey::SetValue_FluKV, [this](std::string in, std::string& out) {
  915. auto value = JSONTo <float>(in);
  916. return SetFluKV(value); });
  917. //透视MA
  918. Dispatch->Get.Push(AttrKey::FLUMA, [this](std::string& out) {
  919. if (m_DoseUnit.m_FLMA)
  920. out = m_DoseUnit.m_FLMA->JSGet();
  921. return RET_STATUS::RET_SUCCEED; });
  922. Dispatch->Set.Push(AttrKey::FLUMA, [this](std::string in) {
  923. auto value = JSONTo <float>(in);
  924. return SetFluMA(value); });
  925. Dispatch->Action.Push(ActionKey::IncParam_FluMA, [this](std::string in, std::string& out) {
  926. return IncFluMA(); });
  927. Dispatch->Action.Push(ActionKey::DecParam_FluMA, [this](std::string in, std::string& out) {
  928. return DecFluMA(); });
  929. Dispatch->Action.Push(ActionKey::SetValue_FluMA, [this](std::string in, std::string& out) {
  930. auto value = JSONTo <float>(in);
  931. return SetFluMA(value); });
  932. //透视曝光时间
  933. Dispatch->Get.Push(AttrKey::FLUMS, [this](std::string& out) {
  934. if (m_DoseUnit.m_FLMS)
  935. out = m_DoseUnit.m_FLMS->JSGet();
  936. return RET_STATUS::RET_SUCCEED; });
  937. Dispatch->Set.Push(AttrKey::FLUMS, [this](std::string in) {
  938. auto value = JSONTo <float>(in);
  939. return SetFluMS(value); });
  940. Dispatch->Action.Push(ActionKey::IncParam_FluMS, [this](std::string in, std::string& out) {
  941. return IncFluMS(); });
  942. Dispatch->Action.Push(ActionKey::DecParam_FluMS, [this](std::string in, std::string& out) {
  943. return DecFluMS(); });
  944. Dispatch->Action.Push(ActionKey::SetValue_FluMS, [this](std::string in, std::string& out) {
  945. auto value = JSONTo <float>(in);
  946. return SetFluMS(value); });
  947. //透视帧率
  948. Dispatch->Get.Push(AttrKey::FLUPPS, [this](std::string& out) {
  949. if (m_DoseUnit.m_PPS)
  950. out = m_DoseUnit.m_PPS->JSGet();
  951. return RET_STATUS::RET_SUCCEED; });
  952. Dispatch->Set.Push(AttrKey::FLUPPS, [this](std::string in) {
  953. auto value = JSONTo <float>(in);
  954. return SetPPS(value); });
  955. Dispatch->Action.Push(ActionKey::IncParam_PPS, [this](std::string in, std::string& out) {
  956. return INCPPS(); });
  957. Dispatch->Action.Push(ActionKey::DecParam_PPS, [this](std::string in, std::string& out) {
  958. return DECPPS(); });
  959. Dispatch->Action.Push(ActionKey::SetValue_PPS, [this](std::string in, std::string& out) {
  960. auto value = JSONTo <float>(in);
  961. return SetPPS(value); });
  962. //脉冲脉宽
  963. Dispatch->Set.Push(AttrKey::FLUpulseWidth, [this](std::string in) {
  964. auto value = JSONTo <int>(in);
  965. return SetPluseWidth(value); });
  966. Dispatch->Action.Push(ActionKey::SetValue_PluseWidth, [this](std::string in, std::string& out) {
  967. auto value = JSONTo <int>(in);
  968. return SetPluseWidth(value); });
  969. //ABS模式
  970. Dispatch->Set.Push(AttrKey::FLUABSStatus, [this](std::string in) {
  971. auto value = JSONTo <int>(in);
  972. return SetABSMode(value); });
  973. Dispatch->Action.Push(ActionKey::SetValue_ABSMode, [this](std::string in, std::string& out) {
  974. auto value = JSONTo <int>(in);
  975. return SetABSMode(value); });
  976. //ABS曲线
  977. Dispatch->Set.Push(AttrKey::FLUCurve, [this](std::string in) {
  978. auto value = JSONTo <int>(in);
  979. return SetABSCurve(value); });
  980. Dispatch->Action.Push(ActionKey::IncParam_ABSCurve, [this](std::string in, std::string& out) {
  981. return IncABSCurve(); });
  982. Dispatch->Action.Push(ActionKey::DecParam_ABSCurve, [this](std::string in, std::string& out) {
  983. return DecABSCurve(); });
  984. Dispatch->Action.Push(ActionKey::SetValue_ABSCurve, [this](std::string in, std::string& out) {
  985. auto value = JSONTo <int>(in);
  986. return SetABSCurve(value); });
  987. //当前EXI
  988. //Dispatch->Set.Push(AttrKey::ABSValue, this, &GeneratorMould::JSsetABSValue);
  989. Dispatch->Action.Push(ActionKey::SetValue_ABSValue, [this](std::string in, std::string& out) {
  990. auto value = JSONTo <float>(in);
  991. return SetABSValue(value); });
  992. //目标EXI
  993. //Dispatch->Set.Push(AttrKey::ABSTargetEXI, this, &GeneratorMould::JSsetABSTargetEXI);
  994. Dispatch->Action.Push(ActionKey::SetValue_ABSTargetEXI, [this](std::string in, std::string& out) {
  995. auto value = JSONTo <float>(in);
  996. return SetABSTargetEXI(value); });
  997. //APF
  998. Dispatch->Action.Push(ActionKey::SetValue_APF, [this](std::string in, std::string& out) {
  999. _tAPFArgs t{ 0 };
  1000. ResDataObject json;
  1001. json.decode(in.c_str());
  1002. auto& R0 = json[0];
  1003. try
  1004. {
  1005. t.nWS = atoi(((string)R0[AttrKey::WORKSTATION]).c_str());
  1006. }
  1007. catch (const std::exception&)
  1008. {
  1009. printf("SetWS Crash\n");
  1010. }
  1011. catch (const ResDataObjectExption&)
  1012. {
  1013. printf("none matches the WORKSTATION\n");
  1014. }
  1015. try
  1016. {
  1017. t.nFluMode = atoi(((string)R0[AttrKey::FLUMode]).c_str());
  1018. }
  1019. catch (const std::exception&)
  1020. {
  1021. }
  1022. catch (const ResDataObjectExption&)
  1023. {
  1024. }
  1025. try
  1026. {
  1027. t.nABSMode = (int)R0[AttrKey::FLUABSStatus];
  1028. }
  1029. catch (const std::exception&)
  1030. {
  1031. }
  1032. catch (const ResDataObjectExption&)
  1033. {
  1034. }
  1035. try
  1036. {
  1037. t.nDoseLever = atof(((string)R0[AttrKey::FLUDoseLevel]).c_str());
  1038. }
  1039. catch (const std::exception&)
  1040. {
  1041. }
  1042. catch (const ResDataObjectExption&)
  1043. {
  1044. }
  1045. try
  1046. {
  1047. t.nFLKV = atof(((string)R0[AttrKey::FLUKV]).c_str());
  1048. }
  1049. catch (const std::exception&)
  1050. {
  1051. }
  1052. catch (const ResDataObjectExption&)
  1053. {
  1054. }
  1055. try
  1056. {
  1057. t.fFLMA = atof(((string)R0[AttrKey::FLUMA]).c_str());
  1058. }
  1059. catch (const std::exception&)
  1060. {
  1061. }
  1062. catch (const ResDataObjectExption&)
  1063. {
  1064. }
  1065. try
  1066. {
  1067. t.nPPS = atoi(((string)R0[AttrKey::FLUPPS]).c_str());
  1068. }
  1069. catch (const std::exception&)
  1070. {
  1071. }
  1072. catch (const ResDataObjectExption&)
  1073. {
  1074. }
  1075. return SetAPF(t); });
  1076. //透视间隔时间、累计时间
  1077. Dispatch->Get.Push(AttrKey::FLUIntTime, [this](std::string& out) {
  1078. out = to_string(GetFluIntTimer());
  1079. return RET_STATUS::RET_SUCCEED; });
  1080. Dispatch->Get.Push(AttrKey::FLUAccTime, [this](std::string& out) {
  1081. out = to_string(GetFluAccTimer());
  1082. return RET_STATUS::RET_SUCCEED; });
  1083. Dispatch->Action.Push(ActionKey::ReSetFluTimer, [this](std::string in, std::string& out) {
  1084. auto value = JSONTo <int>(in);
  1085. return ResetFluTimer(value); });
  1086. //脚闸状态
  1087. Dispatch->Action.Push(ActionKey::SetValue_FluPre, [this](std::string in, std::string& out) {
  1088. auto value = JSONTo <int>(in);
  1089. return SetFluPre(value); });
  1090. Dispatch->Action.Push(ActionKey::SetValue_FluEXP, [this](std::string in, std::string& out) {
  1091. auto value = JSONTo <int>(in);
  1092. return SetFluEXP(value); });
  1093. //MAG
  1094. Dispatch->Action.Push(ActionKey::SetValue_FluMAG, [this](std::string in, std::string& out) {
  1095. auto value = JSONTo <int>(in);
  1096. return SetFluMAG(value); });
  1097. Dispatch->Action.Push(ActionKey::DisableMAG, [this](std::string in, std::string& out) {
  1098. return DisableMAG(); });
  1099. //Dose Level
  1100. Dispatch->Action.Push(ActionKey::SetValue_FluDoseLever, [this](std::string in, std::string& out) {
  1101. auto value = JSONTo <int>(in);
  1102. return SetFluDoseLever(value); });
  1103. //半价剂量
  1104. Dispatch->Action.Push(ActionKey::SetValue_HalfDose, [this](std::string in, std::string& out) {
  1105. auto value = JSONTo <int>(in);
  1106. return SetHalfDose(value); });
  1107. //点片曲线
  1108. Dispatch->Action.Push(ActionKey::SetValue_RadCurve, [this](std::string in, std::string& out) {
  1109. auto value = JSONTo <int>(in);
  1110. return TransferRadCurve(value); });
  1111. }
  1112. //-----------------------------------------------------------------------------
  1113. // 所有的消息响应函数
  1114. //-----------------------------------------------------------------------------
  1115. //add by wxx for task226:减少现有模块改造所以不写成纯虚
  1116. RET_STATUS nsGEN::GeneratorMould::IncKVL()
  1117. {
  1118. return RET_STATUS::RET_SUCCEED;
  1119. }
  1120. RET_STATUS nsGEN::GeneratorMould::DecKVL()
  1121. {
  1122. return RET_STATUS::RET_SUCCEED;
  1123. }
  1124. RET_STATUS nsGEN::GeneratorMould::IncMAL()
  1125. {
  1126. return RET_STATUS::RET_SUCCEED;
  1127. }
  1128. RET_STATUS nsGEN::GeneratorMould::DecMAL()
  1129. {
  1130. return RET_STATUS::RET_SUCCEED;
  1131. }
  1132. RET_STATUS nsGEN::GeneratorMould::IncMSL()
  1133. {
  1134. return RET_STATUS::RET_SUCCEED;
  1135. }
  1136. RET_STATUS nsGEN::GeneratorMould::DecMSL()
  1137. {
  1138. return RET_STATUS::RET_SUCCEED;
  1139. }
  1140. RET_STATUS nsGEN::GeneratorMould::IncMASL()
  1141. {
  1142. return RET_STATUS::RET_SUCCEED;
  1143. }
  1144. RET_STATUS nsGEN::GeneratorMould::DecMASL()
  1145. {
  1146. return RET_STATUS::RET_SUCCEED;
  1147. }
  1148. RET_STATUS nsGEN::GeneratorMould::IncAECDensity()
  1149. {
  1150. return RET_STATUS::RET_SUCCEED;
  1151. }
  1152. RET_STATUS nsGEN::GeneratorMould::DecAECDensity()
  1153. {
  1154. return RET_STATUS::RET_SUCCEED;
  1155. }
  1156. RET_STATUS nsGEN::GeneratorMould::SetAPRArray(vector<_tAPRArgs>& APRarray)
  1157. {
  1158. return RET_STATUS::RET_SUCCEED;
  1159. }
  1160. RET_STATUS nsGEN::GeneratorMould::IncFluKV()
  1161. {
  1162. return RET_STATUS::RET_SUCCEED;
  1163. }
  1164. RET_STATUS nsGEN::GeneratorMould::DecFluKV()
  1165. {
  1166. return RET_STATUS::RET_SUCCEED;
  1167. }
  1168. RET_STATUS nsGEN::GeneratorMould::SetFluKV(float value)
  1169. {
  1170. return RET_STATUS::RET_SUCCEED;
  1171. }
  1172. RET_STATUS nsGEN::GeneratorMould::IncFluMA()
  1173. {
  1174. return RET_STATUS::RET_SUCCEED;
  1175. }
  1176. RET_STATUS nsGEN::GeneratorMould::DecFluMA()
  1177. {
  1178. return RET_STATUS::RET_SUCCEED;
  1179. }
  1180. RET_STATUS nsGEN::GeneratorMould::SetFluMA(float value)
  1181. {
  1182. return RET_STATUS::RET_SUCCEED;
  1183. }
  1184. RET_STATUS nsGEN::GeneratorMould::IncFluMS()
  1185. {
  1186. return RET_STATUS::RET_SUCCEED;
  1187. }
  1188. RET_STATUS nsGEN::GeneratorMould::DecFluMS()
  1189. {
  1190. return RET_STATUS::RET_SUCCEED;
  1191. }
  1192. RET_STATUS nsGEN::GeneratorMould::SetFluMS(float value)
  1193. {
  1194. return RET_STATUS::RET_SUCCEED;
  1195. }
  1196. RET_STATUS nsGEN::GeneratorMould::SetPPS(float frameRate)
  1197. {
  1198. return RET_STATUS::RET_SUCCEED;
  1199. }
  1200. RET_STATUS nsGEN::GeneratorMould::INCPPS()
  1201. {
  1202. return RET_STATUS::RET_SUCCEED;
  1203. }
  1204. RET_STATUS nsGEN::GeneratorMould::DECPPS()
  1205. {
  1206. return RET_STATUS::RET_SUCCEED;
  1207. }
  1208. RET_STATUS nsGEN::GeneratorMould::SetPluseWidth(float fplusewidth)
  1209. {
  1210. return RET_STATUS::RET_SUCCEED;
  1211. }
  1212. RET_STATUS nsGEN::GeneratorMould::SetABSMode(int nMode)
  1213. {
  1214. return RET_STATUS::RET_SUCCEED;
  1215. }
  1216. RET_STATUS nsGEN::GeneratorMould::SetABSCurve(int curveNum)
  1217. {
  1218. return RET_STATUS::RET_SUCCEED;
  1219. }
  1220. RET_STATUS nsGEN::GeneratorMould::IncABSCurve()
  1221. {
  1222. return RET_STATUS::RET_SUCCEED;
  1223. }
  1224. RET_STATUS nsGEN::GeneratorMould::DecABSCurve()
  1225. {
  1226. return RET_STATUS::RET_SUCCEED;
  1227. }
  1228. RET_STATUS nsGEN::GeneratorMould::SetABSValue(float fABSValue)
  1229. {
  1230. return RET_STATUS::RET_SUCCEED;
  1231. }
  1232. RET_STATUS nsGEN::GeneratorMould::SetABSTargetEXI(float fEXIValue)
  1233. {
  1234. return RET_STATUS::RET_SUCCEED;
  1235. }
  1236. RET_STATUS nsGEN::GeneratorMould::SetAPF(const _tAPFArgs& t)
  1237. {
  1238. return RET_STATUS::RET_SUCCEED;
  1239. }
  1240. RET_STATUS nsGEN::GeneratorMould::ResetFluTimer(int ntype)
  1241. {
  1242. return RET_STATUS::RET_SUCCEED;
  1243. }
  1244. RET_STATUS nsGEN::GeneratorMould::SetFluPre(int bPrepare)
  1245. {
  1246. return RET_STATUS::RET_SUCCEED;
  1247. }
  1248. RET_STATUS nsGEN::GeneratorMould::SetFluEXP(int bPrepare)
  1249. {
  1250. return RET_STATUS::RET_SUCCEED;
  1251. }
  1252. RET_STATUS nsGEN::GeneratorMould::SetFLFMode(std::string value)
  1253. {
  1254. return RET_STATUS::RET_SUCCEED;
  1255. }
  1256. RET_STATUS nsGEN::GeneratorMould::SetFluMAG(int nsize)
  1257. {
  1258. return RET_STATUS::RET_SUCCEED;
  1259. }
  1260. RET_STATUS nsGEN::GeneratorMould::DisableMAG()
  1261. {
  1262. return RET_STATUS::RET_SUCCEED;
  1263. }
  1264. RET_STATUS nsGEN::GeneratorMould::SetFluDoseLever(int nlever)
  1265. {
  1266. return RET_STATUS::RET_SUCCEED;
  1267. }
  1268. RET_STATUS nsGEN::GeneratorMould::SetHalfDose(int nlever)
  1269. {
  1270. return RET_STATUS::RET_SUCCEED;
  1271. }
  1272. RET_STATUS nsGEN::GeneratorMould::TransferRadCurve(int ncurve)
  1273. {
  1274. return RET_STATUS::RET_SUCCEED;
  1275. }
  1276. //-----------------------------------------------------------------------------
  1277. // 所有的 GetXX 函数
  1278. //-----------------------------------------------------------------------------
  1279. float nsGEN::GeneratorMould::GetFluIntTimer() { if (m_DoseUnit.m_FLAccTime) return m_DoseUnit.m_FLAccTime->Get(); else return 0; }
  1280. float nsGEN::GeneratorMould::GetFluAccTimer() { if (m_DoseUnit.m_FLIntTime) return m_DoseUnit.m_FLIntTime->Get(); else return 0; }
  1281. //-----------------------------------------------------------------------------
  1282. // 所有的 SetXX 函数
  1283. //-----------------------------------------------------------------------------
  1284. RET_STATUS nsGEN::GeneratorMould::SetGenCurrentSMState(const std::string value)
  1285. {
  1286. return RET_STATUS::RET_SUCCEED;
  1287. }
  1288. //-----------------------------------------------------------------------------
  1289. // nsGEN::DriverMould
  1290. //-----------------------------------------------------------------------------
  1291. nsGEN::DriverMould::DriverMould ()
  1292. {
  1293. ConfigInfo GenVender (ConfKey::CcosGeneratorType, "string", "R", "TRUE", "");
  1294. m_ConfigInfo.push_back(GenVender);
  1295. ConfigInfo GenModel (ConfKey::CcosGeneratorModel, "string", "R", "TRUE", "");
  1296. m_ConfigInfo.push_back(GenModel);
  1297. ConfigInfo GenWSTable (ConfKey::CcosWSTable, "int", "RW", "TRUE", "");
  1298. m_ConfigInfo.push_back(GenWSTable);
  1299. ConfigInfo GenWSWall (ConfKey::CcosWSWall, "int", "RW", "TRUE", "");
  1300. m_ConfigInfo.push_back(GenWSWall);
  1301. ConfigInfo GenWSFree (ConfKey::CcosWSFree, "int", "RW", "TRUE", "");
  1302. m_ConfigInfo.push_back(GenWSFree);
  1303. ConfigInfo GenWSTomo (ConfKey::CcosWSTomo, "int", "RW", "TRUE", "");
  1304. m_ConfigInfo.push_back(GenWSTomo);
  1305. ConfigInfo GenWSConventional (ConfKey::CcosWSConventional, "int", "RW", "TRUE", "");
  1306. m_ConfigInfo.push_back(GenWSConventional);
  1307. EasyJSONEncoder synList;
  1308. synList.Set ("0", "1");
  1309. synList.Set ("1", "2");
  1310. ConfigInfo GenSynTable (ConfKey::CcosSynTable, "int", "RW", "FALSE", "");
  1311. GenSynTable.SetList (synList.ToString ().c_str ());
  1312. m_ConfigInfo.push_back(GenSynTable);
  1313. ConfigInfo GenSynWall (ConfKey::CcosSynWall, "int", "RW", "FALSE", "");
  1314. GenSynWall.SetList (synList.ToString ().c_str ());
  1315. m_ConfigInfo.push_back(GenSynWall);
  1316. ConfigInfo GenSynFree (ConfKey::CcosSynFree, "int", "RW", "FALSE", "");
  1317. GenSynFree.SetList (synList.ToString ().c_str ());
  1318. m_ConfigInfo.push_back(GenSynFree);
  1319. ConfigInfo GenSynTomo (ConfKey::CcosSynTomo, "int", "RW", "FALSE", "");
  1320. GenSynTomo.SetList (synList.ToString ().c_str ());
  1321. m_ConfigInfo.push_back(GenSynTomo);
  1322. ConfigInfo GenSynConventional (ConfKey::CcosSynConventional, "int", "RW", "FALSE", "");
  1323. GenSynConventional.SetList (synList.ToString ().c_str ());
  1324. m_ConfigInfo.push_back(GenSynConventional);
  1325. EasyJSONEncoder ConsoleRoleList;
  1326. ConsoleRoleList.Set ("0", "1");
  1327. ConsoleRoleList.Set ("1", "2");
  1328. ConsoleRoleList.Set ("2", "3");
  1329. ConfigInfo GenConsoleRole (ConfKey::CcosConsoleRole, "int", "RW", "FALSE", "");
  1330. GenConsoleRole.SetList (ConsoleRoleList.ToString ().c_str ());
  1331. m_ConfigInfo.push_back(GenConsoleRole);
  1332. ConfigInfo GenIsConnect (ConfKey::CcosIsConnect, "int", "RW", "FALSE", "");
  1333. GenIsConnect.SetList (synList.ToString ().c_str ());
  1334. m_ConfigInfo.push_back(GenIsConnect);
  1335. ConfigInfo GenSCFType (ConfKey::CcosSCFType, "string", "R", "TRUE", "");
  1336. m_ConfigInfo.push_back(GenSCFType);
  1337. EasyJSONEncoder COMList;
  1338. COMList.Set ("0", "COM1");
  1339. COMList.Set ("1", "COM2");
  1340. COMList.Set ("2", "COM3");
  1341. COMList.Set ("3", "COM4");
  1342. COMList.Set ("4", "COM5");
  1343. COMList.Set ("5", "COM6");
  1344. COMList.Set ("6", "COM7");
  1345. COMList.Set ("7", "COM8");
  1346. COMList.Set ("8", "COM9");
  1347. COMList.Set ("9", "COM10");
  1348. COMList.Set ("10", "COM11");
  1349. COMList.Set ("11", "COM12");
  1350. ConfigInfo GenSCFPort (ConfKey::CcosSCFPort, "string", "RW", "TRUE", "");
  1351. GenSCFPort.SetList (COMList.ToString ().c_str ());
  1352. m_ConfigInfo.push_back(GenSCFPort);
  1353. ConfigInfo GenSCFBaudrate (ConfKey::CcosSCFBaudrate, "int", "R", "FALSE", "");
  1354. m_ConfigInfo.push_back(GenSCFBaudrate);
  1355. ConfigInfo GenSCFBytesize (ConfKey::CcosSCFBytesize, "int", "R", "FALSE", "");
  1356. m_ConfigInfo.push_back(GenSCFBytesize);
  1357. ConfigInfo GenSCFParity (ConfKey::CcosSCFParity, "int", "R", "FALSE", "");
  1358. m_ConfigInfo.push_back(GenSCFParity);
  1359. ConfigInfo GenSCFStopbits (ConfKey::CcosSCFStopbits, "int", "R", "FALSE", "");
  1360. m_ConfigInfo.push_back(GenSCFStopbits);
  1361. }
  1362. nsGEN::DriverMould::~DriverMould ()
  1363. {
  1364. }
  1365. std::string nsGEN::DriverMould::GetGUID () const
  1366. {
  1367. return GeneratorDriverType;
  1368. }
  1369. static const auto COM_SCFDllName = "libSerialSCF.so";
  1370. static const auto TCP_SCFDllName = "libTcpipSCF.so";
  1371. string CCOS::Dev::Detail::Generator::DriverMould::GetConnectDLL(string& ConfigFileName)
  1372. {
  1373. std::cout << "DriverMould::GetConnectDLL IN " << std::endl;
  1374. std::cout << "COM_SCFDllName: " << COM_SCFDllName << " TCP_SCFDllName: " << TCP_SCFDllName << std::endl;
  1375. string ConnectDLL = COM_SCFDllName;
  1376. ResDataObject r_config, Connection;
  1377. if (!r_config.loadFile(ConfigFileName.c_str()))
  1378. return ConnectDLL;
  1379. if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0)
  1380. {
  1381. Connection = r_config["CONFIGURATION"]["connections"]["Value"];
  1382. }
  1383. else
  1384. {
  1385. Connection = r_config["CONFIGURATION"]["connections"][0];
  1386. }
  1387. if ((string)Connection["type"] == "COM")
  1388. ConnectDLL = COM_SCFDllName;
  1389. else
  1390. ConnectDLL = TCP_SCFDllName;
  1391. return ConnectDLL;
  1392. }
  1393. ResDataObject nsGEN::DriverMould::GetConnectParam(string& ConfigFileName)
  1394. {
  1395. std::cout << "DriverMould::GetConnectParam IN " << std::endl;
  1396. ResDataObject r_config, Connection;
  1397. // 检查文件是否存在
  1398. std::ifstream file(ConfigFileName);
  1399. if (!file) {
  1400. // 文件不存在,直接返回空的Connection对象
  1401. //mLog::Info("file does not exist");
  1402. return Connection;
  1403. }
  1404. if (!r_config.loadFile(ConfigFileName.c_str()))
  1405. return Connection;
  1406. if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0)
  1407. {
  1408. Connection = r_config["CONFIGURATION"]["connections"]["Value"];
  1409. }
  1410. else
  1411. {
  1412. Connection = r_config["CONFIGURATION"]["connections"][0];
  1413. }
  1414. return Connection;
  1415. }