CCOS.Dev.Generator.Mould.cpp 50 KB

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