CCOS.Dev.Generator.Mould.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  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. //注册updata
  485. Dispatch->Update.Push("CurrentSMState", [this](std::string in, std::string& out) {
  486. return SetGenCurrentSMState(in); });
  487. }
  488. void nsGEN::GeneratorMould::RegisterOther(Dispatch* Dispatch) // 子类可能希望注册更多的
  489. {
  490. //遮光器属性
  491. Dispatch->Action.Push(ActionKey::SetCollimatorLight, [this](std::string in, std::string& out) {
  492. auto value = JSONTo <float>(in);
  493. SetCollimatorLight(value);
  494. return RET_STATUS::RET_SUCCEED;
  495. });
  496. }
  497. void nsGEN::GeneratorMould::RegisterAEC(Dispatch* Dispatch)
  498. {
  499. Dispatch->Get.Push(AttrKey::AECDENSITY, [this](std::string& out) {
  500. if (m_DoseUnit.m_AECDensity)
  501. out = m_DoseUnit.m_AECDensity->JSGet();
  502. return RET_STATUS::RET_SUCCEED; });
  503. Dispatch->Set.Push(AttrKey::AECDENSITY, [this](std::string in) {
  504. auto value = JSONTo <int>(in);
  505. return SetAECDensity(value); });
  506. Dispatch->Action.Push(ActionKey::SetValue_AECDENSITY, [this](std::string in, std::string& out) {
  507. auto value = JSONTo <int>(in);
  508. return SetAECDensity(value);});
  509. Dispatch->Action.Push(ActionKey::IncParam_AECDENSITY, [this](std::string in, std::string& out) {
  510. return IncAECDensity(); });
  511. Dispatch->Action.Push(ActionKey::DecParam_AECDENSITY, [this](std::string in, std::string& out) {
  512. return DecAECDensity(); });
  513. Dispatch->Get.Push(AttrKey::AECFIELD, [this](std::string& out) {
  514. if (m_DoseUnit.m_AECField)
  515. out = m_DoseUnit.m_AECField->JSGet();
  516. return RET_STATUS::RET_SUCCEED; });
  517. Dispatch->Set.Push(AttrKey::AECFIELD, [this](std::string in) {
  518. auto value = JSONTo <int>(in);
  519. return SetAECField(value); });
  520. Dispatch->Action.Push(ActionKey::SetValue_AECFIELD, [this](std::string in, std::string& out) {
  521. auto value = JSONTo <int>(in);
  522. return SetAECField(value); });
  523. Dispatch->Get.Push(AttrKey::AECFILM, [this](std::string& out) {
  524. if (m_DoseUnit.m_AECFilm)
  525. out = m_DoseUnit.m_AECFilm->JSGet();
  526. return RET_STATUS::RET_SUCCEED; });
  527. Dispatch->Set.Push(AttrKey::AECFILM, [this](std::string in) {
  528. auto value = JSONTo <int>(in);
  529. return SetAECFilm(value); });
  530. Dispatch->Action.Push(ActionKey::SetValue_AECFILM, [this](std::string in, std::string& out) {
  531. auto value = JSONTo <int>(in);
  532. return SetAECFilm(value); });
  533. }
  534. void nsGEN::GeneratorMould::RegisterExpEnable(Dispatch* Dispatch)
  535. {
  536. Dispatch->Action.Push(ActionKey::SetExpEnable, [this](std::string in, std::string& out) {
  537. return SetExpEnable(); });
  538. Dispatch->Action.Push(ActionKey::SetExpDisable, [this](std::string in, std::string& out) {
  539. return SetExpDisable(); });
  540. }
  541. void nsGEN::GeneratorMould::RegisterGeneratortoSyncStatus(Dispatch* Dispatch)
  542. {
  543. Dispatch->Get.Push(AttrKey::GENSYNSTATE, [this](std::string& out) {
  544. if (m_DoseUnit.m_GenSynState)
  545. out = m_DoseUnit.m_GenSynState->JSGet();
  546. return RET_STATUS::RET_SUCCEED; });
  547. Dispatch->Set.Push(AttrKey::GENSYNSTATE, [this](std::string in) {
  548. auto value = JSONTo <int>(in);
  549. return SetGenSynState(value); });
  550. Dispatch->Action.Push(ActionKey::SetGeneratortoSyncStatus, [this](std::string in, std::string& out) {
  551. auto value = JSONTo <int>(in);
  552. return SetGenSynState(value); });
  553. }
  554. void nsGEN::GeneratorMould::RegisterRAD(Dispatch* Dispatch)
  555. {
  556. //KV
  557. Dispatch->Get.Push(AttrKey::KVLIST, [this](std::string& out) {
  558. if (m_DoseUnit.m_KVList)
  559. out = m_DoseUnit.m_KVList->JSGet();
  560. return RET_STATUS::RET_SUCCEED; });
  561. Dispatch->Get.Push(AttrKey::KV, [this](std::string& out) {
  562. if (m_DoseUnit.m_KV)
  563. out = m_DoseUnit.m_KV->JSGet();
  564. return RET_STATUS::RET_SUCCEED; });
  565. Dispatch->Set.Push(AttrKey::KV, [this](std::string in) {
  566. auto value = JSONTo <float>(in);
  567. return SetKV(value); });
  568. Dispatch->Action.Push(ActionKey::IncParam_KV, [this](std::string in, std::string& out) {
  569. return IncKV(); });
  570. Dispatch->Action.Push(ActionKey::DecParam_KV, [this](std::string in, std::string& out) {
  571. return DecKV(); });
  572. Dispatch->Action.Push(ActionKey::IncParam_KVL, [this](std::string in, std::string& out) {
  573. return IncKVL(); });
  574. Dispatch->Action.Push(ActionKey::DecParam_KVL, [this](std::string in, std::string& out) {
  575. return DecKVL(); });
  576. Dispatch->Action.Push(ActionKey::SetValue_KV, [this](std::string in, std::string& out) {
  577. auto value = JSONTo <float>(in);
  578. return SetKV(value); });
  579. //MA
  580. Dispatch->Get.Push(AttrKey::MA, [this](std::string& out) {
  581. if (m_DoseUnit.m_MA)
  582. out = m_DoseUnit.m_MA->JSGet();
  583. return RET_STATUS::RET_SUCCEED; });
  584. Dispatch->Set.Push(AttrKey::MA, [this](std::string in) {
  585. auto value = JSONTo <float>(in);
  586. return SetMA(value); });
  587. Dispatch->Action.Push(ActionKey::IncParam_MA, [this](std::string in, std::string& out) {
  588. return IncMA(); });
  589. Dispatch->Action.Push(ActionKey::DecParam_MA, [this](std::string in, std::string& out) {
  590. return DecMA();});
  591. Dispatch->Action.Push(ActionKey::IncParam_MAL, [this](std::string in, std::string& out) {
  592. return IncMAL(); });
  593. Dispatch->Action.Push(ActionKey::DecParam_MAL, [this](std::string in, std::string& out) {
  594. return DecMAL(); });
  595. Dispatch->Action.Push(ActionKey::SetValue_MA, [this](std::string in, std::string& out) {
  596. auto value = JSONTo <float>(in);
  597. return SetMA(value); });
  598. //MS
  599. Dispatch->Get.Push(AttrKey::MS, [this](std::string& out) {
  600. if (m_DoseUnit.m_MS)
  601. out = m_DoseUnit.m_MS->JSGet();
  602. return RET_STATUS::RET_SUCCEED; });
  603. Dispatch->Set.Push(AttrKey::MS, [this](std::string in) {
  604. auto value = JSONTo <float>(in);
  605. return SetMS(value); });
  606. Dispatch->Action.Push(ActionKey::IncParam_MS, [this](std::string in, std::string& out) {
  607. return IncMS(); });
  608. Dispatch->Action.Push(ActionKey::DecParam_MS, [this](std::string in, std::string& out) {
  609. return DecMS(); });
  610. Dispatch->Action.Push(ActionKey::IncParam_MSL, [this](std::string in, std::string& out) {
  611. return IncMSL(); });
  612. Dispatch->Action.Push(ActionKey::DecParam_MSL, [this](std::string in, std::string& out) {
  613. return DecMSL(); });
  614. Dispatch->Action.Push(ActionKey::SetValue_MS, [this](std::string in, std::string& out) {
  615. auto value = JSONTo <float>(in);
  616. return SetMS(value); });
  617. //MAS
  618. Dispatch->Get.Push(AttrKey::MASLIST, [this](std::string& out) {
  619. if (m_DoseUnit.m_mAsList)
  620. out = m_DoseUnit.m_mAsList->JSGet();
  621. return RET_STATUS::RET_SUCCEED; });
  622. Dispatch->Get.Push(AttrKey::MAS, [this](std::string& out) {
  623. if (m_DoseUnit.m_MAS)
  624. out = m_DoseUnit.m_MAS->JSGet();
  625. return RET_STATUS::RET_SUCCEED; });
  626. Dispatch->Set.Push(AttrKey::MAS, [this](std::string in) {
  627. auto value = JSONTo <float>(in);
  628. return SetMAS(value); });
  629. Dispatch->Action.Push(ActionKey::IncParam_MAS, [this](std::string in, std::string& out) {
  630. return IncMAS(); });
  631. Dispatch->Action.Push(ActionKey::DecParam_MAS, [this](std::string in, std::string& out) {
  632. return DecMAS(); });
  633. Dispatch->Action.Push(ActionKey::IncParam_MASL, [this](std::string in, std::string& out) {
  634. return IncMASL(); });
  635. Dispatch->Action.Push(ActionKey::DecParam_MASL, [this](std::string in, std::string& out) {
  636. return DecMASL(); });
  637. Dispatch->Action.Push(ActionKey::SetValue_MAS, [this](std::string in, std::string& out) {
  638. auto value = JSONTo <float>(in);
  639. return SetMAS(value); });
  640. //FOCUS
  641. Dispatch->Get.Push(AttrKey::FOCUS, [this](std::string& out) {
  642. if (m_DoseUnit.m_Focus)
  643. out = m_DoseUnit.m_Focus->JSGet();
  644. return RET_STATUS::RET_SUCCEED; });
  645. Dispatch->Set.Push(AttrKey::FOCUS, [this](std::string in) {
  646. auto value = JSONTo <int>(in);
  647. return SetFocus(value); });
  648. Dispatch->Action.Push(ActionKey::SetValue_FOCUS, [this](std::string in, std::string& out) {
  649. auto value = JSONTo <int>(in);
  650. return SetFocus(value); });
  651. //TECHMODE
  652. Dispatch->Get.Push(AttrKey::TECHMODE, [this](std::string& out) {
  653. if (m_DoseUnit.m_Techmode)
  654. out = m_DoseUnit.m_Techmode->JSGet();
  655. return RET_STATUS::RET_SUCCEED; });
  656. Dispatch->Set.Push(AttrKey::TECHMODE, [this](std::string in) {
  657. auto value = JSONTo <int>(in);
  658. return SetTechmode(value); });
  659. Dispatch->Action.Push(ActionKey::SetValue_TECHMODE, [this](std::string in, std::string& out) {
  660. auto value = JSONTo <int>(in);
  661. return SetTechmode(value); });
  662. //APR
  663. Dispatch->Action.Push(ActionKey::SetAPR, [this](std::string in, std::string& out) {
  664. ResDataObject json;
  665. json.decode(in.c_str());
  666. vector<_tAPRArgs> APRarray;
  667. try
  668. {
  669. for (int i = 0; i < json.size(); i++)
  670. {
  671. ResDataObject param = json[i];
  672. _tAPRArgs apr{ };
  673. apr.nWS = (int)param[AttrKey::WORKSTATION];
  674. apr.nFocus = (int)param[AttrKey::FOCUS];
  675. apr.nTechmode = (int)param[AttrKey::TECHMODE];
  676. apr.fKV = (float)param[AttrKey::KV];
  677. apr.fMA = (float)param[AttrKey::MA];
  678. apr.fMS = (float)param[AttrKey::MS];
  679. apr.fKV2 = (float)param[AttrKey::KV2];
  680. apr.fMA2 = (float)param[AttrKey::MA2];
  681. apr.fMS2 = (float)param[AttrKey::MS2];
  682. apr.fMAS = (float)param[AttrKey::MAS];
  683. apr.nAECDensity = (int)param[AttrKey::AECDENSITY];
  684. apr.nAECFilm = (int)param[AttrKey::AECFILM];
  685. apr.nAECField = (int)param[AttrKey::AECFIELD];
  686. APRarray.push_back(apr);
  687. }
  688. }
  689. catch (...)
  690. {
  691. printf("SetAPR Crash\n");
  692. }
  693. if (APRarray.size() > 1)
  694. {
  695. return SetAPRArray(APRarray);
  696. }
  697. else
  698. return SetAPR(APRarray[0]); });
  699. Dispatch->Action.Push(ActionKey::SetAPRArray, [this](std::string in, std::string& out) {
  700. ResDataObject json;
  701. json.decode(in.c_str());
  702. vector<_tAPRArgs> APRarray;
  703. try
  704. {
  705. for (int i = 0; i < json.size(); i++)
  706. {
  707. ResDataObject param = json[i];
  708. _tAPRArgs apr{ };
  709. apr.nWS = (int)param[AttrKey::WORKSTATION];
  710. apr.nFocus = (int)param[AttrKey::FOCUS];
  711. apr.nTechmode = (int)param[AttrKey::TECHMODE];
  712. apr.fKV = (float)param[AttrKey::KV];
  713. apr.fMA = (float)param[AttrKey::MA];
  714. apr.fMS = (float)param[AttrKey::MS];
  715. apr.fKV2 = (float)param[AttrKey::KV2];
  716. apr.fMA2 = (float)param[AttrKey::MA2];
  717. apr.fMS2 = (float)param[AttrKey::MS2];
  718. apr.fMAS = (float)param[AttrKey::MAS];
  719. apr.nAECDensity = (int)param[AttrKey::AECDENSITY];
  720. apr.nAECFilm = (int)param[AttrKey::AECFILM];
  721. apr.nAECField = (int)param[AttrKey::AECFIELD];
  722. APRarray.push_back(apr);
  723. }
  724. }
  725. catch (...)
  726. {
  727. printf("SetAPRArray Crash\n");
  728. }
  729. return SetAPRArray(APRarray); });
  730. //序列点片帧率
  731. Dispatch->Get.Push(AttrKey::FRAMERATE, [this](std::string& out) {
  732. if (m_DoseUnit.m_FrameRate)
  733. out = m_DoseUnit.m_FrameRate->JSGet();
  734. return RET_STATUS::RET_SUCCEED; });
  735. Dispatch->Set.Push(AttrKey::FRAMERATE, [this](std::string in) {
  736. auto value = JSONTo <float>(in);
  737. return SetFrameRate(value); });
  738. Dispatch->Action.Push(ActionKey::SetFrameRate, [this](std::string in, std::string& out) {
  739. auto value = JSONTo <float>(in);
  740. return SetFrameRate(value); });
  741. //曝光后的post值
  742. Dispatch->Action.Push(ActionKey::GetValue_POSTKV, [this](std::string in, std::string& out) {
  743. float value = 0;
  744. RET_STATUS ret = QueryPostKV(value);
  745. ResDataObject tempret;
  746. tempret = value;
  747. out = (const char*)tempret;
  748. return ret; });
  749. Dispatch->Get.Push(AttrKey::POSTKV, [this](std::string& out) {
  750. if (m_DoseUnit.m_PostKV)
  751. out = m_DoseUnit.m_PostKV->JSGet();
  752. return RET_STATUS::RET_SUCCEED; });
  753. Dispatch->Action.Push(ActionKey::GetValue_POSTMA, [this](std::string in, std::string& out) {
  754. float value = 0;
  755. RET_STATUS ret = QueryPostMA(value);
  756. ResDataObject tempret;
  757. tempret = value;
  758. out = (const char*)tempret;
  759. return ret; });
  760. Dispatch->Get.Push(AttrKey::POSTMA, [this](std::string& out) {
  761. if (m_DoseUnit.m_PostMA)
  762. out = m_DoseUnit.m_PostMA->JSGet();
  763. return RET_STATUS::RET_SUCCEED; });
  764. Dispatch->Action.Push(ActionKey::GetValue_POSTMS, [this](std::string in, std::string& out) {
  765. float value = 0;
  766. RET_STATUS ret = QueryPostMS(value);
  767. ResDataObject tempret;
  768. tempret = value;
  769. out = (const char*)tempret;
  770. return ret; });
  771. Dispatch->Get.Push(AttrKey::POSTMS, [this](std::string& out) {
  772. if (m_DoseUnit.m_PostMS)
  773. out = m_DoseUnit.m_PostMS->JSGet();
  774. return RET_STATUS::RET_SUCCEED; });
  775. Dispatch->Action.Push(ActionKey::GetValue_POSTMAS, [this](std::string in, std::string& out) {
  776. float value = 0;
  777. RET_STATUS ret = QueryPostMAS(value);
  778. ResDataObject tempret;
  779. tempret = value;
  780. out = (const char*)tempret;
  781. return ret; });
  782. Dispatch->Get.Push(AttrKey::POSTMAS, [this](std::string& out) {
  783. if (m_DoseUnit.m_PostMAS)
  784. out = m_DoseUnit.m_PostMAS->JSGet();
  785. return RET_STATUS::RET_SUCCEED; });
  786. }
  787. void nsGEN::GeneratorMould::RegisterFluoro(Dispatch* Dispatch)
  788. {
  789. //透视模式
  790. Dispatch->Get.Push(AttrKey::FLUMode, [this](std::string& out) {
  791. if (m_DoseUnit.m_FLMode)
  792. out = m_DoseUnit.m_FLMode->JSGet();
  793. return RET_STATUS::RET_SUCCEED; });
  794. Dispatch->Get.Push(AttrKey::FLUAccTimeUnit, [this](std::string& out) {
  795. out = m_DoseUnit.m_FLAccTimeUnit;
  796. return RET_STATUS::RET_SUCCEED; });
  797. Dispatch->Set.Push(AttrKey::FLUMode, [this](std::string in) {
  798. ResDataObject json;
  799. json.decode(in.c_str());
  800. auto value = (string)json[0];
  801. return SetFLFMode(value); });
  802. Dispatch->Action.Push(ActionKey::SetFLFMode, [this](std::string in, std::string& out) {
  803. ResDataObject json;
  804. json.decode(in.c_str());
  805. auto value = (string)json[0];
  806. return SetFLFMode(value); });
  807. //透视KV
  808. Dispatch->Get.Push(AttrKey::FLUKV, [this](std::string& out) {
  809. if (m_DoseUnit.m_FLKV)
  810. out = m_DoseUnit.m_FLKV->JSGet();
  811. return RET_STATUS::RET_SUCCEED; });
  812. Dispatch->Set.Push(AttrKey::FLUKV, [this](std::string in) {
  813. auto value = JSONTo <float>(in);
  814. return SetFluKV(value); });
  815. Dispatch->Action.Push(ActionKey::IncParam_FluKV, [this](std::string in, std::string& out) {
  816. return IncFluKV(); });
  817. Dispatch->Action.Push(ActionKey::DecParam_FluKV, [this](std::string in, std::string& out) {
  818. return DecFluKV(); });
  819. Dispatch->Action.Push(ActionKey::SetValue_FluKV, [this](std::string in, std::string& out) {
  820. auto value = JSONTo <float>(in);
  821. return SetFluKV(value); });
  822. //透视MA
  823. Dispatch->Get.Push(AttrKey::FLUMA, [this](std::string& out) {
  824. if (m_DoseUnit.m_FLMA)
  825. out = m_DoseUnit.m_FLMA->JSGet();
  826. return RET_STATUS::RET_SUCCEED; });
  827. Dispatch->Set.Push(AttrKey::FLUMA, [this](std::string in) {
  828. auto value = JSONTo <float>(in);
  829. return SetFluMA(value); });
  830. Dispatch->Action.Push(ActionKey::IncParam_FluMA, [this](std::string in, std::string& out) {
  831. return IncFluMA(); });
  832. Dispatch->Action.Push(ActionKey::DecParam_FluMA, [this](std::string in, std::string& out) {
  833. return DecFluMA(); });
  834. Dispatch->Action.Push(ActionKey::SetValue_FluMA, [this](std::string in, std::string& out) {
  835. auto value = JSONTo <float>(in);
  836. return SetFluMA(value); });
  837. //透视曝光时间
  838. Dispatch->Get.Push(AttrKey::FLUMS, [this](std::string& out) {
  839. if (m_DoseUnit.m_FLMS)
  840. out = m_DoseUnit.m_FLMS->JSGet();
  841. return RET_STATUS::RET_SUCCEED; });
  842. Dispatch->Set.Push(AttrKey::FLUMS, [this](std::string in) {
  843. auto value = JSONTo <float>(in);
  844. return SetFluMS(value); });
  845. Dispatch->Action.Push(ActionKey::IncParam_FluMS, [this](std::string in, std::string& out) {
  846. return IncFluMS(); });
  847. Dispatch->Action.Push(ActionKey::DecParam_FluMS, [this](std::string in, std::string& out) {
  848. return DecFluMS(); });
  849. Dispatch->Action.Push(ActionKey::SetValue_FluMS, [this](std::string in, std::string& out) {
  850. auto value = JSONTo <float>(in);
  851. return SetFluMS(value); });
  852. //透视帧率
  853. Dispatch->Get.Push(AttrKey::FLUPPS, [this](std::string& out) {
  854. if (m_DoseUnit.m_PPS)
  855. out = m_DoseUnit.m_PPS->JSGet();
  856. return RET_STATUS::RET_SUCCEED; });
  857. Dispatch->Set.Push(AttrKey::FLUPPS, [this](std::string in) {
  858. auto value = JSONTo <float>(in);
  859. return SetPPS(value); });
  860. Dispatch->Action.Push(ActionKey::IncParam_PPS, [this](std::string in, std::string& out) {
  861. return INCPPS(); });
  862. Dispatch->Action.Push(ActionKey::DecParam_PPS, [this](std::string in, std::string& out) {
  863. return DECPPS(); });
  864. Dispatch->Action.Push(ActionKey::SetValue_PPS, [this](std::string in, std::string& out) {
  865. auto value = JSONTo <float>(in);
  866. return SetPPS(value); });
  867. //脉冲脉宽
  868. Dispatch->Set.Push(AttrKey::FLUpulseWidth, [this](std::string in) {
  869. auto value = JSONTo <int>(in);
  870. return SetPluseWidth(value); });
  871. Dispatch->Action.Push(ActionKey::SetValue_PluseWidth, [this](std::string in, std::string& out) {
  872. auto value = JSONTo <int>(in);
  873. return SetPluseWidth(value); });
  874. //ABS模式
  875. Dispatch->Set.Push(AttrKey::FLUABSStatus, [this](std::string in) {
  876. auto value = JSONTo <int>(in);
  877. return SetABSMode(value); });
  878. Dispatch->Action.Push(ActionKey::SetValue_ABSMode, [this](std::string in, std::string& out) {
  879. auto value = JSONTo <int>(in);
  880. return SetABSMode(value); });
  881. //ABS曲线
  882. Dispatch->Set.Push(AttrKey::FLUCurve, [this](std::string in) {
  883. auto value = JSONTo <int>(in);
  884. return SetABSCurve(value); });
  885. Dispatch->Action.Push(ActionKey::IncParam_ABSCurve, [this](std::string in, std::string& out) {
  886. return IncABSCurve(); });
  887. Dispatch->Action.Push(ActionKey::DecParam_ABSCurve, [this](std::string in, std::string& out) {
  888. return DecABSCurve(); });
  889. Dispatch->Action.Push(ActionKey::SetValue_ABSCurve, [this](std::string in, std::string& out) {
  890. auto value = JSONTo <int>(in);
  891. return SetABSCurve(value); });
  892. //当前EXI
  893. //Dispatch->Set.Push(AttrKey::ABSValue, this, &GeneratorMould::JSsetABSValue);
  894. Dispatch->Action.Push(ActionKey::SetValue_ABSValue, [this](std::string in, std::string& out) {
  895. auto value = JSONTo <float>(in);
  896. return SetABSValue(value); });
  897. //目标EXI
  898. //Dispatch->Set.Push(AttrKey::ABSTargetEXI, this, &GeneratorMould::JSsetABSTargetEXI);
  899. Dispatch->Action.Push(ActionKey::SetValue_ABSTargetEXI, [this](std::string in, std::string& out) {
  900. auto value = JSONTo <float>(in);
  901. return SetABSTargetEXI(value); });
  902. //APF
  903. Dispatch->Action.Push(ActionKey::SetValue_APF, [this](std::string in, std::string& out) {
  904. _tAPFArgs t{ 0 };
  905. ResDataObject json;
  906. json.decode(in.c_str());
  907. auto& R0 = json[0];
  908. try
  909. {
  910. t.nWS = atoi(((string)R0[AttrKey::WORKSTATION]).c_str());
  911. }
  912. catch (const std::exception&)
  913. {
  914. printf("SetWS Crash\n");
  915. }
  916. catch (const ResDataObjectExption&)
  917. {
  918. printf("none matches the WORKSTATION\n");
  919. }
  920. try
  921. {
  922. t.nFluMode = atoi(((string)R0[AttrKey::FLUMode]).c_str());
  923. }
  924. catch (const std::exception&)
  925. {
  926. }
  927. catch (const ResDataObjectExption&)
  928. {
  929. }
  930. try
  931. {
  932. t.nABSMode = (int)R0[AttrKey::FLUABSStatus];
  933. }
  934. catch (const std::exception&)
  935. {
  936. }
  937. catch (const ResDataObjectExption&)
  938. {
  939. }
  940. try
  941. {
  942. t.nDoseLever = atof(((string)R0[AttrKey::FLUDoseLevel]).c_str());
  943. }
  944. catch (const std::exception&)
  945. {
  946. }
  947. catch (const ResDataObjectExption&)
  948. {
  949. }
  950. try
  951. {
  952. t.nFLKV = atof(((string)R0[AttrKey::FLUKV]).c_str());
  953. }
  954. catch (const std::exception&)
  955. {
  956. }
  957. catch (const ResDataObjectExption&)
  958. {
  959. }
  960. try
  961. {
  962. t.fFLMA = atof(((string)R0[AttrKey::FLUMA]).c_str());
  963. }
  964. catch (const std::exception&)
  965. {
  966. }
  967. catch (const ResDataObjectExption&)
  968. {
  969. }
  970. try
  971. {
  972. t.nPPS = atoi(((string)R0[AttrKey::FLUPPS]).c_str());
  973. }
  974. catch (const std::exception&)
  975. {
  976. }
  977. catch (const ResDataObjectExption&)
  978. {
  979. }
  980. return SetAPF(t); });
  981. //透视间隔时间、累计时间
  982. Dispatch->Get.Push(AttrKey::FLUIntTime, [this](std::string& out) {
  983. out = to_string(GetFluIntTimer());
  984. return RET_STATUS::RET_SUCCEED; });
  985. Dispatch->Get.Push(AttrKey::FLUAccTime, [this](std::string& out) {
  986. out = to_string(GetFluAccTimer());
  987. return RET_STATUS::RET_SUCCEED; });
  988. Dispatch->Action.Push(ActionKey::ReSetFluTimer, [this](std::string in, std::string& out) {
  989. auto value = JSONTo <int>(in);
  990. return ResetFluTimer(value); });
  991. //脚闸状态
  992. Dispatch->Action.Push(ActionKey::SetValue_FluPre, [this](std::string in, std::string& out) {
  993. auto value = JSONTo <int>(in);
  994. return SetFluPre(value); });
  995. Dispatch->Action.Push(ActionKey::SetValue_FluEXP, [this](std::string in, std::string& out) {
  996. auto value = JSONTo <int>(in);
  997. return SetFluEXP(value); });
  998. //MAG
  999. Dispatch->Action.Push(ActionKey::SetValue_FluMAG, [this](std::string in, std::string& out) {
  1000. auto value = JSONTo <int>(in);
  1001. return SetFluMAG(value); });
  1002. Dispatch->Action.Push(ActionKey::DisableMAG, [this](std::string in, std::string& out) {
  1003. return DisableMAG(); });
  1004. //Dose Level
  1005. Dispatch->Action.Push(ActionKey::SetValue_FluDoseLever, [this](std::string in, std::string& out) {
  1006. auto value = JSONTo <int>(in);
  1007. return SetFluDoseLever(value); });
  1008. //半价剂量
  1009. Dispatch->Action.Push(ActionKey::SetValue_HalfDose, [this](std::string in, std::string& out) {
  1010. auto value = JSONTo <int>(in);
  1011. return SetHalfDose(value); });
  1012. //点片曲线
  1013. Dispatch->Action.Push(ActionKey::SetValue_RadCurve, [this](std::string in, std::string& out) {
  1014. auto value = JSONTo <int>(in);
  1015. return TransferRadCurve(value); });
  1016. }
  1017. //-----------------------------------------------------------------------------
  1018. // 所有的消息响应函数
  1019. //-----------------------------------------------------------------------------
  1020. //add by wxx for task226:减少现有模块改造所以不写成纯虚
  1021. RET_STATUS nsGEN::GeneratorMould::IncKVL()
  1022. {
  1023. return RET_STATUS::RET_SUCCEED;
  1024. }
  1025. RET_STATUS nsGEN::GeneratorMould::DecKVL()
  1026. {
  1027. return RET_STATUS::RET_SUCCEED;
  1028. }
  1029. RET_STATUS nsGEN::GeneratorMould::IncMAL()
  1030. {
  1031. return RET_STATUS::RET_SUCCEED;
  1032. }
  1033. RET_STATUS nsGEN::GeneratorMould::DecMAL()
  1034. {
  1035. return RET_STATUS::RET_SUCCEED;
  1036. }
  1037. RET_STATUS nsGEN::GeneratorMould::IncMSL()
  1038. {
  1039. return RET_STATUS::RET_SUCCEED;
  1040. }
  1041. RET_STATUS nsGEN::GeneratorMould::DecMSL()
  1042. {
  1043. return RET_STATUS::RET_SUCCEED;
  1044. }
  1045. RET_STATUS nsGEN::GeneratorMould::IncMASL()
  1046. {
  1047. return RET_STATUS::RET_SUCCEED;
  1048. }
  1049. RET_STATUS nsGEN::GeneratorMould::DecMASL()
  1050. {
  1051. return RET_STATUS::RET_SUCCEED;
  1052. }
  1053. RET_STATUS nsGEN::GeneratorMould::IncAECDensity()
  1054. {
  1055. return RET_STATUS::RET_SUCCEED;
  1056. }
  1057. RET_STATUS nsGEN::GeneratorMould::DecAECDensity()
  1058. {
  1059. return RET_STATUS::RET_SUCCEED;
  1060. }
  1061. RET_STATUS nsGEN::GeneratorMould::SetAPRArray(vector<_tAPRArgs>& APRarray)
  1062. {
  1063. return RET_STATUS::RET_SUCCEED;
  1064. }
  1065. RET_STATUS nsGEN::GeneratorMould::IncFluKV()
  1066. {
  1067. return RET_STATUS::RET_SUCCEED;
  1068. }
  1069. RET_STATUS nsGEN::GeneratorMould::DecFluKV()
  1070. {
  1071. return RET_STATUS::RET_SUCCEED;
  1072. }
  1073. RET_STATUS nsGEN::GeneratorMould::SetFluKV(float value)
  1074. {
  1075. return RET_STATUS::RET_SUCCEED;
  1076. }
  1077. RET_STATUS nsGEN::GeneratorMould::IncFluMA()
  1078. {
  1079. return RET_STATUS::RET_SUCCEED;
  1080. }
  1081. RET_STATUS nsGEN::GeneratorMould::DecFluMA()
  1082. {
  1083. return RET_STATUS::RET_SUCCEED;
  1084. }
  1085. RET_STATUS nsGEN::GeneratorMould::SetFluMA(float value)
  1086. {
  1087. return RET_STATUS::RET_SUCCEED;
  1088. }
  1089. RET_STATUS nsGEN::GeneratorMould::IncFluMS()
  1090. {
  1091. return RET_STATUS::RET_SUCCEED;
  1092. }
  1093. RET_STATUS nsGEN::GeneratorMould::DecFluMS()
  1094. {
  1095. return RET_STATUS::RET_SUCCEED;
  1096. }
  1097. RET_STATUS nsGEN::GeneratorMould::SetFluMS(float value)
  1098. {
  1099. return RET_STATUS::RET_SUCCEED;
  1100. }
  1101. RET_STATUS nsGEN::GeneratorMould::SetPPS(float frameRate)
  1102. {
  1103. return RET_STATUS::RET_SUCCEED;
  1104. }
  1105. RET_STATUS nsGEN::GeneratorMould::INCPPS()
  1106. {
  1107. return RET_STATUS::RET_SUCCEED;
  1108. }
  1109. RET_STATUS nsGEN::GeneratorMould::DECPPS()
  1110. {
  1111. return RET_STATUS::RET_SUCCEED;
  1112. }
  1113. RET_STATUS nsGEN::GeneratorMould::SetPluseWidth(float fplusewidth)
  1114. {
  1115. return RET_STATUS::RET_SUCCEED;
  1116. }
  1117. RET_STATUS nsGEN::GeneratorMould::SetABSMode(int nMode)
  1118. {
  1119. return RET_STATUS::RET_SUCCEED;
  1120. }
  1121. RET_STATUS nsGEN::GeneratorMould::SetABSCurve(int curveNum)
  1122. {
  1123. return RET_STATUS::RET_SUCCEED;
  1124. }
  1125. RET_STATUS nsGEN::GeneratorMould::IncABSCurve()
  1126. {
  1127. return RET_STATUS::RET_SUCCEED;
  1128. }
  1129. RET_STATUS nsGEN::GeneratorMould::DecABSCurve()
  1130. {
  1131. return RET_STATUS::RET_SUCCEED;
  1132. }
  1133. RET_STATUS nsGEN::GeneratorMould::SetABSValue(float fABSValue)
  1134. {
  1135. return RET_STATUS::RET_SUCCEED;
  1136. }
  1137. RET_STATUS nsGEN::GeneratorMould::SetABSTargetEXI(float fEXIValue)
  1138. {
  1139. return RET_STATUS::RET_SUCCEED;
  1140. }
  1141. RET_STATUS nsGEN::GeneratorMould::SetAPF(const _tAPFArgs& t)
  1142. {
  1143. return RET_STATUS::RET_SUCCEED;
  1144. }
  1145. RET_STATUS nsGEN::GeneratorMould::ResetFluTimer(int ntype)
  1146. {
  1147. return RET_STATUS::RET_SUCCEED;
  1148. }
  1149. RET_STATUS nsGEN::GeneratorMould::SetFluPre(int bPrepare)
  1150. {
  1151. return RET_STATUS::RET_SUCCEED;
  1152. }
  1153. RET_STATUS nsGEN::GeneratorMould::SetFluEXP(int bPrepare)
  1154. {
  1155. return RET_STATUS::RET_SUCCEED;
  1156. }
  1157. RET_STATUS nsGEN::GeneratorMould::SetFLFMode(std::string value)
  1158. {
  1159. return RET_STATUS::RET_SUCCEED;
  1160. }
  1161. RET_STATUS nsGEN::GeneratorMould::SetFluMAG(int nsize)
  1162. {
  1163. return RET_STATUS::RET_SUCCEED;
  1164. }
  1165. RET_STATUS nsGEN::GeneratorMould::DisableMAG()
  1166. {
  1167. return RET_STATUS::RET_SUCCEED;
  1168. }
  1169. RET_STATUS nsGEN::GeneratorMould::SetFluDoseLever(int nlever)
  1170. {
  1171. return RET_STATUS::RET_SUCCEED;
  1172. }
  1173. RET_STATUS nsGEN::GeneratorMould::SetHalfDose(int nlever)
  1174. {
  1175. return RET_STATUS::RET_SUCCEED;
  1176. }
  1177. RET_STATUS nsGEN::GeneratorMould::TransferRadCurve(int ncurve)
  1178. {
  1179. return RET_STATUS::RET_SUCCEED;
  1180. }
  1181. //-----------------------------------------------------------------------------
  1182. // 所有的 GetXX 函数
  1183. //-----------------------------------------------------------------------------
  1184. float nsGEN::GeneratorMould::GetFluIntTimer() { if (m_DoseUnit.m_FLAccTime) return m_DoseUnit.m_FLAccTime->Get(); else return 0; }
  1185. float nsGEN::GeneratorMould::GetFluAccTimer() { if (m_DoseUnit.m_FLIntTime) return m_DoseUnit.m_FLIntTime->Get(); else return 0; }
  1186. //-----------------------------------------------------------------------------
  1187. // 所有的 SetXX 函数
  1188. //-----------------------------------------------------------------------------
  1189. RET_STATUS nsGEN::GeneratorMould::SetGenCurrentSMState(const std::string value)
  1190. {
  1191. return RET_STATUS::RET_SUCCEED;
  1192. }
  1193. //-----------------------------------------------------------------------------
  1194. // nsGEN::DriverMould
  1195. //-----------------------------------------------------------------------------
  1196. nsGEN::DriverMould::DriverMould ()
  1197. {
  1198. ConfigInfo GenVender (ConfKey::CcosGeneratorType, "string", "R", "TRUE", "");
  1199. m_ConfigInfo.push_back(GenVender);
  1200. ConfigInfo GenModel (ConfKey::CcosGeneratorModel, "string", "R", "TRUE", "");
  1201. m_ConfigInfo.push_back(GenModel);
  1202. ConfigInfo GenWSTable (ConfKey::CcosWSTable, "int", "RW", "TRUE", "");
  1203. m_ConfigInfo.push_back(GenWSTable);
  1204. ConfigInfo GenWSWall (ConfKey::CcosWSWall, "int", "RW", "TRUE", "");
  1205. m_ConfigInfo.push_back(GenWSWall);
  1206. ConfigInfo GenWSFree (ConfKey::CcosWSFree, "int", "RW", "TRUE", "");
  1207. m_ConfigInfo.push_back(GenWSFree);
  1208. ConfigInfo GenWSTomo (ConfKey::CcosWSTomo, "int", "RW", "TRUE", "");
  1209. m_ConfigInfo.push_back(GenWSTomo);
  1210. ConfigInfo GenWSConventional (ConfKey::CcosWSConventional, "int", "RW", "TRUE", "");
  1211. m_ConfigInfo.push_back(GenWSConventional);
  1212. EasyJSONEncoder synList;
  1213. synList.Set ("0", "1");
  1214. synList.Set ("1", "2");
  1215. ConfigInfo GenSynTable (ConfKey::CcosSynTable, "int", "RW", "FALSE", "");
  1216. GenSynTable.SetList (synList.ToString ().c_str ());
  1217. m_ConfigInfo.push_back(GenSynTable);
  1218. ConfigInfo GenSynWall (ConfKey::CcosSynWall, "int", "RW", "FALSE", "");
  1219. GenSynWall.SetList (synList.ToString ().c_str ());
  1220. m_ConfigInfo.push_back(GenSynWall);
  1221. ConfigInfo GenSynFree (ConfKey::CcosSynFree, "int", "RW", "FALSE", "");
  1222. GenSynFree.SetList (synList.ToString ().c_str ());
  1223. m_ConfigInfo.push_back(GenSynFree);
  1224. ConfigInfo GenSynTomo (ConfKey::CcosSynTomo, "int", "RW", "FALSE", "");
  1225. GenSynTomo.SetList (synList.ToString ().c_str ());
  1226. m_ConfigInfo.push_back(GenSynTomo);
  1227. ConfigInfo GenSynConventional (ConfKey::CcosSynConventional, "int", "RW", "FALSE", "");
  1228. GenSynConventional.SetList (synList.ToString ().c_str ());
  1229. m_ConfigInfo.push_back(GenSynConventional);
  1230. EasyJSONEncoder ConsoleRoleList;
  1231. ConsoleRoleList.Set ("0", "1");
  1232. ConsoleRoleList.Set ("1", "2");
  1233. ConsoleRoleList.Set ("2", "3");
  1234. ConfigInfo GenConsoleRole (ConfKey::CcosConsoleRole, "int", "RW", "FALSE", "");
  1235. GenConsoleRole.SetList (ConsoleRoleList.ToString ().c_str ());
  1236. m_ConfigInfo.push_back(GenConsoleRole);
  1237. ConfigInfo GenIsConnect (ConfKey::CcosIsConnect, "int", "RW", "FALSE", "");
  1238. GenIsConnect.SetList (synList.ToString ().c_str ());
  1239. m_ConfigInfo.push_back(GenIsConnect);
  1240. ConfigInfo GenSCFType (ConfKey::CcosSCFType, "string", "R", "TRUE", "");
  1241. m_ConfigInfo.push_back(GenSCFType);
  1242. EasyJSONEncoder COMList;
  1243. COMList.Set ("0", "COM1");
  1244. COMList.Set ("1", "COM2");
  1245. COMList.Set ("2", "COM3");
  1246. COMList.Set ("3", "COM4");
  1247. COMList.Set ("4", "COM5");
  1248. COMList.Set ("5", "COM6");
  1249. COMList.Set ("6", "COM7");
  1250. COMList.Set ("7", "COM8");
  1251. COMList.Set ("8", "COM9");
  1252. COMList.Set ("9", "COM10");
  1253. COMList.Set ("10", "COM11");
  1254. COMList.Set ("11", "COM12");
  1255. ConfigInfo GenSCFPort (ConfKey::CcosSCFPort, "string", "RW", "TRUE", "");
  1256. GenSCFPort.SetList (COMList.ToString ().c_str ());
  1257. m_ConfigInfo.push_back(GenSCFPort);
  1258. ConfigInfo GenSCFBaudrate (ConfKey::CcosSCFBaudrate, "int", "R", "FALSE", "");
  1259. m_ConfigInfo.push_back(GenSCFBaudrate);
  1260. ConfigInfo GenSCFBytesize (ConfKey::CcosSCFBytesize, "int", "R", "FALSE", "");
  1261. m_ConfigInfo.push_back(GenSCFBytesize);
  1262. ConfigInfo GenSCFParity (ConfKey::CcosSCFParity, "int", "R", "FALSE", "");
  1263. m_ConfigInfo.push_back(GenSCFParity);
  1264. ConfigInfo GenSCFStopbits (ConfKey::CcosSCFStopbits, "int", "R", "FALSE", "");
  1265. m_ConfigInfo.push_back(GenSCFStopbits);
  1266. }
  1267. nsGEN::DriverMould::~DriverMould ()
  1268. {
  1269. }
  1270. std::string nsGEN::DriverMould::GetGUID () const
  1271. {
  1272. return GeneratorDriverType;
  1273. }
  1274. static const auto COM_SCFDllName = "SerialSCF.so";
  1275. static const auto TCP_SCFDllName = "TcpipSCF.so";
  1276. string CCOS::Dev::Detail::Generator::DriverMould::GetConnectDLL(string& ConfigFileName)
  1277. {
  1278. string ConnectDLL = COM_SCFDllName;
  1279. ResDataObject r_config, Connection;
  1280. if (!r_config.loadFile(ConfigFileName.c_str()))
  1281. return ConnectDLL;
  1282. if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0)
  1283. {
  1284. Connection = r_config["CONFIGURATION"]["connections"]["Value"];
  1285. }
  1286. else
  1287. {
  1288. Connection = r_config["CONFIGURATION"]["connections"][0];
  1289. }
  1290. if ((string)Connection["type"] == "COM")
  1291. ConnectDLL = COM_SCFDllName;
  1292. else
  1293. ConnectDLL = TCP_SCFDllName;
  1294. return ConnectDLL;
  1295. }
  1296. ResDataObject nsGEN::DriverMould::GetConnectParam(string& ConfigFileName)
  1297. {
  1298. ResDataObject r_config, Connection;
  1299. // 检查文件是否存在
  1300. std::ifstream file(ConfigFileName);
  1301. if (!file) {
  1302. // 文件不存在,直接返回空的Connection对象
  1303. //mLog::Info("file does not exist");
  1304. return Connection;
  1305. }
  1306. if (!r_config.loadFile(ConfigFileName.c_str()))
  1307. return Connection;
  1308. if (r_config["CONFIGURATION"]["connections"].GetKeyCount("Value") > 0)
  1309. {
  1310. Connection = r_config["CONFIGURATION"]["connections"]["Value"];
  1311. }
  1312. else
  1313. {
  1314. Connection = r_config["CONFIGURATION"]["connections"][0];
  1315. }
  1316. return Connection;
  1317. }