DIOS.Dev.Generator.SDC.cpp 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656
  1. // CCOS.Dev.GEN.DEMO.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. /*
  4. settechmode:没有专门的指令来设置。所以只要field不为零,就认为是AEC模式。
  5. */
  6. #include "stdafx.h"
  7. #include <assert.h>
  8. #include "Base64.h"
  9. #include <functional>
  10. using namespace std::placeholders;
  11. //#include "ResDataObject.h"
  12. //#include "logger.temp.h"
  13. #include "CCOS.Dev.Generator.SDC.h"
  14. #include "Helper.JSON.hpp"
  15. using namespace CCOS::Dev::Detail::Generator;
  16. namespace nsGEN = CCOS::Dev::Detail::Generator;
  17. #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
  18. #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
  19. #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
  20. static const int msTimeOut_Lock = 500;
  21. #ifdef _WIN64
  22. #ifdef _DEBUG
  23. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  24. #else
  25. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  26. #endif
  27. #endif
  28. #ifdef _WIN64
  29. #ifdef _DEBUG
  30. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  31. #else
  32. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  33. #endif
  34. #endif
  35. #define SpecialCMDAR "AR"
  36. #define SpecialCMDHU "HU"
  37. #define SpecialCMDIT "IT"
  38. #define SpecialCMDST "ST"
  39. #define SpecialCMDRX "RX"
  40. #define SpecialCMDRX1 "RX1"
  41. #define SpecialCMDRX0 "RX0"
  42. #define SpecialCMDXR1 "XR1"
  43. #define SpecialCMDXR0 "XR0"
  44. #define SpecialCMDPC "PC"
  45. #define SpecialCMDDO "DO?"
  46. #define SpecialCMDDOR "DOR"
  47. #define SpecialCMDFOS "FOS"
  48. #define SpecialCMDRF "RF"
  49. #define SpecialCMDBT "BT"
  50. #define SpecialCMDSA "SA"
  51. #define SpecialCMDDS "DS"
  52. #define SpecialCMDSX "SX"
  53. #define SpecialCMDDE "DE"
  54. #define WaitForNothing 0
  55. #define WaitForSelf 1
  56. #define WaitForACK 10
  57. #define WaitForCP 100
  58. #define WaitForCPSELF 101
  59. #define WaitForACKCP 110
  60. #define WaitForALL 111
  61. std::vector <string> g_SpecialCMD_List = { "AR","XR1","RX","ST","HU","WS","SA","SX","DS","DE"};
  62. std::vector <string> g_WaitSELF_List = { "AR","SA","SX","DS","XR1","RX0","RX1","ST","HU"};
  63. std::vector <string> g_WaitAKCMD_List = { "SA","SX","WS","MM","PH","PC","FI","FN","EC9","AR","MD","PC","TM","URSSHST",
  64. "XR1","RX0","RX1","URSSHSS","URSSHIA","URSSHIR","URSSHCA","URSSHEI","URSLK","URSSD","URSPO","URSPN","URSPR","URSRV","URSCF","URSFK","URSST","URSFI","URSOF","URSCA","URSPP","URSTI","URSYD","URSLI","URSLD","URSCL"};
  65. std::vector <string> g_WaitCPCMD_List = { "SA","SX","KV","MA","MS","MX","WS","MM","PH","PC","FI","FN","EC9","AR","MD","PC","TM","URSSHST",
  66. "XR1","RX0","RX1","HU","ST","DS","FOS","RF","BT"};
  67. //-----------------------------------------------------------------------------
  68. // ProcessCmd
  69. //-----------------------------------------------------------------------------
  70. struct tFrameMapping
  71. {
  72. static const int MaxLen = 5; // 前缀不能超超过 5 个字符 !
  73. using cbFun = std::function <void(const char*, int)>;
  74. char strHead[MaxLen]{0};
  75. int NbOfCharOfHead{0};
  76. cbFun fun{NULL};
  77. tFrameMapping(char* str, int len, cbFun f)
  78. {
  79. assert(len < MaxLen);
  80. for (int i = 0; i < len; i++)
  81. strHead[i] = str[i];
  82. NbOfCharOfHead = len;
  83. fun = f;
  84. }
  85. };
  86. static std::list <tFrameMapping> arFrame;
  87. static bool DecodeFrame(const char* strFrame, int length);
  88. //暂无取固定值的使用要求
  89. std::vector <float> g_MA_List = { 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640 };
  90. std::vector <float> g_MAS_List = { 1, 1.25, 1.6, 2, 2.5, 3.2, 4, 5, 6.4, 8, 10, 12.5, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000 };
  91. std::vector <float> g_MS_List = { 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 10000 };
  92. int g_AECFIELD_List [] = { 1, 10, 100, 11, 101, 110, 111 };
  93. bool RapidChangeValue(float& value, std::vector <float>& list,bool isIncAct)
  94. {
  95. auto item = std::find(list.begin(), list.end(), value);
  96. if (isIncAct)
  97. {
  98. if (item == list.end())
  99. value += 5;
  100. else
  101. {
  102. int index = distance(list.begin(), item)+1;
  103. if (index + 3 >= list.size())
  104. value = *(list.end() - 1);
  105. else
  106. value = *(item + 3);
  107. }
  108. }
  109. else
  110. {
  111. if (item == list.end())
  112. value -= 5;
  113. else if (item == list.end() - 1)
  114. return false;
  115. else
  116. {
  117. int index = distance(list.begin(), item);
  118. if (index - 3 <= 0)
  119. value = *(list.begin());
  120. else
  121. value = *(item - 3);
  122. }
  123. }
  124. return true;
  125. }
  126. template<typename T>
  127. int FindPositon (T *pList, int nListSize, T& value)
  128. {
  129. if (pList == NULL || nListSize == 0) return -1;
  130. if (value <= pList [0])
  131. {
  132. value = pList [0];
  133. return 0;
  134. }
  135. if (value >= pList [nListSize - 1])
  136. {
  137. value = pList [nListSize - 1];
  138. return nListSize - 1;
  139. }
  140. for (int i = 0; i < nListSize - 1; i++)
  141. {
  142. if (value >= pList [i] && value <= pList [i + 1])
  143. {
  144. int npos = 0;
  145. if (abs (value - pList [i]) >= abs (value - pList [i + 1]))
  146. {
  147. value = pList [i + 1];
  148. npos = i + 1;
  149. }
  150. else
  151. {
  152. value = pList [i];
  153. npos = i;
  154. }
  155. return npos;
  156. }
  157. }
  158. return -1;
  159. }
  160. //-----------------------------------------------------------------------------
  161. // SDCDevice
  162. //-----------------------------------------------------------------------------
  163. nsGEN::SDCDevice::SDCDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF,std::string configPath) : super(center, SCF)
  164. {
  165. assert(EventCenter);
  166. //CreateLogger("SDCSHRF");
  167. //load config XML
  168. m_strConfigPath = configPath;
  169. ResDataObject temp;
  170. temp.loadFile(m_strConfigPath.c_str());
  171. m_GenConfig = temp["CONFIGURATION"];
  172. TransJsonText(m_GenConfig);
  173. string version;
  174. if (GetVersion(version, hMyModule))
  175. FDEBUG("\n===============log begin : version:{$} ===================", version.c_str());
  176. else
  177. FDEBUG("===============log begin : version:0.0.0.0 ===================\n");
  178. m_DoseUnit.m_KV.reset(new KVMould(0.0, 40.0, 150.0, 1.0));
  179. m_DoseUnit.m_MA.reset(new MAMould(500, 8.0, 1000.0, 0.1));
  180. m_DoseUnit.m_MS.reset(new MSMould(0.0, 1.0, 10000.0, 0.01));
  181. m_DoseUnit.m_MAS.reset(new MASMould(0.0, 0.5, 1000.0, 0.01));
  182. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(0, 0, 2, 1));
  183. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 1, 8, 1));
  184. m_DoseUnit.m_Focus.reset(new FOCUSMould(1, 0, 1, 1));
  185. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  186. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  187. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  188. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  189. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 40.0, 150.0, 1.0));
  190. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 8.0, 1000.0, 0.1));
  191. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 1.0, 10000.0, 0.01));
  192. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.5, 1000.0, 0.01));
  193. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_RAD_XRAYOFF, 1));
  194. m_DoseUnit.m_GenState.reset(new GENSTATEMould(4, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
  195. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  196. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  197. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  198. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  199. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  200. m_MSGUnit.reset(new nsDetail::MSGUnit(center, GeneratorUnitType));
  201. m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
  202. m_hGenPostEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  203. m_hSendingThreadToggleEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  204. m_hGenCPEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  205. m_hGenACKEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  206. m_hGenSELFEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  207. //m_nDeviceType = (int)(m_GenConfig["GenType"]);//默认设置为2. 带有coll的。
  208. InitializeCriticalSection(&m_iCriticalSection);
  209. m_bSendingCommandsThreadExit = false;
  210. m_TimeoutReset = 0;
  211. m_bExpoEnable = false;
  212. m_bExpoFlag = false;
  213. m_sendEnable = true;
  214. m_arrWSMap.clear();
  215. //add by wxx for demand574
  216. if (m_GenConfig.GetKeyCount(ConfKey::CcosTubeInfo) > 0)
  217. {
  218. string tempValue = m_GenConfig[ConfKey::CcosTubeInfo];
  219. m_DoseUnit.m_TubeInfo.reset(new TUBEINFOMould(tempValue));
  220. }
  221. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusSmall) > 0)
  222. {
  223. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusSmall];
  224. m_DoseUnit.m_FocusSmall = tempValue;
  225. }
  226. if (m_GenConfig.GetKeyCount(ConfKey::CcosFocusLarge) > 0)
  227. {
  228. float tempValue = (float)m_GenConfig[ConfKey::CcosFocusLarge];
  229. m_DoseUnit.m_FocusLarge = tempValue;
  230. }
  231. //同步模式
  232. if (m_GenConfig.GetKeyCount("WSTable") > 0)
  233. {
  234. int WSNamber = (int)m_GenConfig["WSTable"];
  235. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTable"]);
  236. m_arrWSMap[cfgWorkStationKey("Table", AttrKey::TABLE)] = cfgWorkStationData("Table", WSNamber, WSSYN);
  237. FDEBUG("cfg Table WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  238. }
  239. if (m_GenConfig.GetKeyCount("WSWall") > 0)
  240. {
  241. int WSNamber = (int)m_GenConfig["WSWall"];
  242. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNWall"]);
  243. m_arrWSMap[cfgWorkStationKey("Wall", AttrKey::WALL)] = cfgWorkStationData("Wall", WSNamber, WSSYN);
  244. FDEBUG("cfg Wall WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  245. }
  246. if (m_GenConfig.GetKeyCount("WSFree") > 0)
  247. {
  248. int WSNamber = (int)m_GenConfig["WSFree"];
  249. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNFree"]);
  250. m_arrWSMap[cfgWorkStationKey("Free", AttrKey::MOBILE)] = cfgWorkStationData("Free", WSNamber, WSSYN);
  251. FDEBUG("cfg Free WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  252. }
  253. if (m_GenConfig.GetKeyCount("WSTomo") > 0)
  254. {
  255. int WSNamber = (int)m_GenConfig["WSTomo"];
  256. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNTomo"]);
  257. m_arrWSMap[cfgWorkStationKey("Tomo", AttrKey::TOMO)] = cfgWorkStationData("Tomo", WSNamber, WSSYN);
  258. FDEBUG("cfg Tomo WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  259. }
  260. if (m_GenConfig.GetKeyCount("WSConventional") > 0)
  261. {
  262. int WSNamber = (int)m_GenConfig["WSConventional"];
  263. EnSYNMode WSSYN = (EnSYNMode)((int)m_GenConfig["SYNConventional"]);
  264. m_arrWSMap[cfgWorkStationKey("Direct", AttrKey::CONVENTIONAL)] = cfgWorkStationData("Direct", WSNamber, WSSYN);
  265. FDEBUG("cfg Conventional WS[{$}],SYN[{$}]", WSNamber, (int)WSSYN);
  266. }
  267. OnCallBack();
  268. Register();
  269. StartSendingCommandsThread();
  270. RefreshData();
  271. }
  272. nsGEN::SDCDevice::~SDCDevice ()
  273. {
  274. CloseHandle(m_hGenPostEvent);
  275. StopSendingCommandsThread();
  276. DeleteCriticalSection(&m_iCriticalSection);
  277. }
  278. std::string nsGEN::SDCDevice::GetGUID() const
  279. {
  280. printf("\n===============GetGUID : %s ===================\n", GeneratorUnitType);
  281. return GeneratorUnitType;
  282. }
  283. void nsGEN::SDCDevice::Register()
  284. {
  285. auto Disp = &Dispatch;
  286. superGen::Register (Disp);
  287. superGen::RegisterRAD (Disp);
  288. superGen::RegisterAEC (Disp);
  289. superGen::RegisterExpEnable (Disp);
  290. superGen::RegisterGeneratortoSyncStatus(Disp);
  291. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  292. auto fun_Clear_DAP = [this](auto a, auto&)
  293. {
  294. return Clear_DAP();
  295. };
  296. Disp->Action.Push ("Clear_DAP", fun_Clear_DAP);
  297. auto fun_GetValue_DAP = [this](auto a, auto& b)
  298. {
  299. float value = 0;
  300. RET_STATUS ret = GetValue_DAP(value);
  301. b = ToJSON(value);
  302. return ret;
  303. };
  304. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  305. }
  306. RET_STATUS nsGEN::SDCDevice::IncKV ()
  307. {
  308. if (!m_DoseUnit.m_KV->CanInc ()) return RET_STATUS::RET_SUCCEED;
  309. ProcessCommand("KV+");
  310. return RET_STATUS::RET_SUCCEED;
  311. }
  312. RET_STATUS nsGEN::SDCDevice::DecKV ()
  313. {
  314. if (!m_DoseUnit.m_KV->CanDec ()) return RET_STATUS::RET_SUCCEED;
  315. ProcessCommand("KV-");
  316. return RET_STATUS::RET_SUCCEED;
  317. }
  318. RET_STATUS nsGEN::SDCDevice::SetKV (float value)
  319. {
  320. if (! m_DoseUnit.m_KV->Verify (value)) return RET_STATUS::RET_SUCCEED;
  321. char temp [50] = { 0 };
  322. sprintf_s (temp, "KV%03d", (int)value);
  323. ProcessCommand(temp);
  324. return RET_STATUS::RET_SUCCEED;
  325. }
  326. RET_STATUS nsGEN::SDCDevice::IncKVL()
  327. {
  328. float tempKV = m_DoseUnit.m_KV->Get();
  329. tempKV += 5;
  330. if (!m_DoseUnit.m_KV->Verify(tempKV)) return RET_STATUS::RET_SUCCEED;
  331. ProcessCommand("KV++");
  332. return RET_STATUS::RET_SUCCEED;
  333. }
  334. RET_STATUS nsGEN::SDCDevice::DecKVL()
  335. {
  336. float tempKV = m_DoseUnit.m_KV->Get();
  337. tempKV -= 5;
  338. if (!m_DoseUnit.m_KV->Verify(tempKV)) return RET_STATUS::RET_SUCCEED;
  339. ProcessCommand("KV--");
  340. return RET_STATUS::RET_SUCCEED;
  341. }
  342. RET_STATUS nsGEN::SDCDevice::IncMA ()
  343. {
  344. #if 0
  345. IncMAL();
  346. #else
  347. if (!m_DoseUnit.m_MA->CanInc ()) return RET_STATUS::RET_SUCCEED;
  348. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  349. {
  350. printf ("\n Techmode is MAS, can't set MA");
  351. return RET_STATUS::RET_FAILED;
  352. }
  353. ProcessCommand("MA+");
  354. #endif
  355. return RET_STATUS::RET_SUCCEED;
  356. }
  357. RET_STATUS nsGEN::SDCDevice::DecMA ()
  358. {
  359. #if 0
  360. DecMAL();
  361. #else
  362. if (!m_DoseUnit.m_MA->CanDec ()) return RET_STATUS::RET_SUCCEED;
  363. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  364. {
  365. printf ("\n Techmode is MAS, can't set MA");
  366. return RET_STATUS::RET_FAILED;
  367. }
  368. ProcessCommand("MA-");
  369. #endif
  370. return RET_STATUS::RET_SUCCEED;
  371. }
  372. RET_STATUS nsGEN::SDCDevice::SetMA (float value)
  373. {
  374. if (! m_DoseUnit.m_MA->Verify (value)) return RET_STATUS::RET_SUCCEED;
  375. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  376. {
  377. printf ("\n Techmode is MAS, can't set MA");
  378. return RET_STATUS::RET_FAILED;
  379. }
  380. char temp [50] = { 0 };
  381. sprintf_s (temp, "MA%05d", (int)(value*10));
  382. ProcessCommand(temp);
  383. return RET_STATUS::RET_SUCCEED;
  384. }
  385. RET_STATUS nsGEN::SDCDevice::IncMAL()
  386. {
  387. #if 1
  388. IncMA();
  389. #else
  390. float tempMA = m_DoseUnit.m_MA->Get();
  391. if (!RapidChangeValue(tempMA, g_MA_List, true))
  392. {
  393. return IncMA();
  394. }
  395. if (!m_DoseUnit.m_MA->Verify(tempMA)) return RET_STATUS::RET_SUCCEED;
  396. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  397. {
  398. printf("\n Techmode is MAS, can't set MA");
  399. return RET_STATUS::RET_FAILED;
  400. }
  401. char temp[50] = { 0 };
  402. sprintf_s(temp, "MA%05d", (int)(tempMA * 10));
  403. ProcessCommand(temp);
  404. #endif
  405. return RET_STATUS::RET_SUCCEED;
  406. }
  407. RET_STATUS nsGEN::SDCDevice::DecMAL()
  408. {
  409. #if 1
  410. DecMA();
  411. #else
  412. float tempMA = m_DoseUnit.m_MA->Get();
  413. if (!RapidChangeValue(tempMA, g_MA_List, false))
  414. {
  415. return DecMA();
  416. }
  417. if (!m_DoseUnit.m_MA->Verify(tempMA)) return RET_STATUS::RET_SUCCEED;
  418. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  419. {
  420. printf("\n Techmode is MAS, can't set MA");
  421. return RET_STATUS::RET_FAILED;
  422. }
  423. char temp[50] = { 0 };
  424. sprintf_s(temp, "MA%05d", (int)(tempMA * 10));
  425. ProcessCommand(temp);
  426. #endif
  427. return RET_STATUS::RET_SUCCEED;
  428. }
  429. RET_STATUS nsGEN::SDCDevice::IncMS ()
  430. {
  431. if (!m_DoseUnit.m_MS->CanInc ()) return RET_STATUS::RET_SUCCEED;
  432. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  433. {
  434. printf ("\n Techmode is MAS, can't set MS");
  435. return RET_STATUS::RET_FAILED;
  436. }
  437. ProcessCommand("MS+");
  438. return RET_STATUS::RET_SUCCEED;
  439. }
  440. RET_STATUS nsGEN::SDCDevice::DecMS ()
  441. {
  442. if (!m_DoseUnit.m_MS->CanDec ()) return RET_STATUS::RET_SUCCEED;
  443. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  444. {
  445. printf ("\n Techmode is MAS, can't set MS");
  446. return RET_STATUS::RET_FAILED;
  447. }
  448. ProcessCommand("MS-");
  449. return RET_STATUS::RET_SUCCEED;
  450. }
  451. RET_STATUS nsGEN::SDCDevice::SetMS (float value)
  452. {
  453. if (! m_DoseUnit.m_MS->Verify (value)) return RET_STATUS::RET_SUCCEED;
  454. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  455. {
  456. printf ("\n Techmode is MAS, can't set MS");
  457. return RET_STATUS::RET_FAILED;
  458. }
  459. char temp [50] = { 0 };
  460. sprintf_s (temp, "MS%05d", (int)(value));
  461. ProcessCommand(temp);
  462. return RET_STATUS::RET_SUCCEED;
  463. }
  464. RET_STATUS nsGEN::SDCDevice::IncMSL()
  465. {
  466. #if 1
  467. IncMS();
  468. #else
  469. float tempMS = m_DoseUnit.m_MS->Get();
  470. if (!RapidChangeValue(tempMS, g_MS_List, true))
  471. {
  472. return IncMS();
  473. }
  474. if (!m_DoseUnit.m_MS->Verify(tempMS)) return RET_STATUS::RET_SUCCEED;
  475. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  476. {
  477. printf("\n Techmode is MAS, can't set MS");
  478. return RET_STATUS::RET_FAILED;
  479. }
  480. char temp[50] = { 0 };
  481. sprintf_s(temp, "MS%05d", (int)(tempMS));
  482. ProcessCommand(temp);
  483. #endif
  484. return RET_STATUS::RET_SUCCEED;
  485. }
  486. RET_STATUS nsGEN::SDCDevice::DecMSL()
  487. {
  488. #if 1
  489. DecMS();
  490. #else
  491. float tempMS = m_DoseUnit.m_MS->Get();
  492. if (!RapidChangeValue(tempMS, g_MS_List, false))
  493. {
  494. return DecMS();
  495. }
  496. if (!m_DoseUnit.m_MS->Verify(tempMS)) return RET_STATUS::RET_SUCCEED;
  497. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  498. {
  499. printf("\n Techmode is MAS, can't set MS");
  500. return RET_STATUS::RET_FAILED;
  501. }
  502. char temp[50] = { 0 };
  503. sprintf_s(temp, "MS%05d", (int)(tempMS));
  504. ProcessCommand(temp);
  505. #endif
  506. return RET_STATUS::RET_SUCCEED;
  507. }
  508. RET_STATUS nsGEN::SDCDevice::IncMAS ()
  509. {
  510. if (!m_DoseUnit.m_MAS->CanInc ()) return RET_STATUS::RET_SUCCEED;
  511. if (m_DoseUnit.m_Techmode->Get () != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  512. {
  513. printf ("\n Techmode is not MAS, can't set MAS");
  514. return RET_STATUS::RET_FAILED;
  515. }
  516. ProcessCommand("MX+");
  517. return RET_STATUS::RET_SUCCEED;
  518. }
  519. RET_STATUS nsGEN::SDCDevice::DecMAS ()
  520. {
  521. if (!m_DoseUnit.m_MAS->CanDec ()) return RET_STATUS::RET_SUCCEED;
  522. if (m_DoseUnit.m_Techmode->Get () != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  523. {
  524. printf ("\n Techmode is not MAS, can't set MAS");
  525. return RET_STATUS::RET_FAILED;
  526. }
  527. ProcessCommand("MX-");
  528. return RET_STATUS::RET_SUCCEED;
  529. }
  530. RET_STATUS nsGEN::SDCDevice::SetMAS (float value)
  531. {
  532. if (! m_DoseUnit.m_MAS->Verify (value)) return RET_STATUS::RET_SUCCEED;
  533. if (m_DoseUnit.m_Techmode->Get () != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  534. {
  535. printf ("\n Techmode is not MAS, can't set MAS");
  536. return RET_STATUS::RET_FAILED;
  537. }
  538. char temp [50] = { 0 };
  539. sprintf_s (temp, "MX%06d", (int)(value * 1000));
  540. ProcessCommand(temp);
  541. return RET_STATUS::RET_SUCCEED;
  542. }
  543. RET_STATUS nsGEN::SDCDevice::IncMASL()
  544. {
  545. #if 1
  546. IncMAS();
  547. #else
  548. float tempMAS = m_DoseUnit.m_MAS->Get();
  549. if (!RapidChangeValue(tempMAS, g_MAS_List, true))
  550. {
  551. return IncMAS();
  552. }
  553. if (!m_DoseUnit.m_MAS->Verify(tempMAS)) return RET_STATUS::RET_SUCCEED;
  554. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  555. {
  556. printf("\n Techmode is not MAS, can't set MAS");
  557. return RET_STATUS::RET_FAILED;
  558. }
  559. char temp[50] = { 0 };
  560. sprintf_s(temp, "MX%06d", (int)(tempMAS * 1000));
  561. ProcessCommand(temp);
  562. #endif
  563. return RET_STATUS::RET_SUCCEED;
  564. }
  565. RET_STATUS nsGEN::SDCDevice::DecMASL()
  566. {
  567. #if 1
  568. DecMAS();
  569. #else
  570. float tempMAS = m_DoseUnit.m_MAS->Get();
  571. if (!RapidChangeValue(tempMAS, g_MAS_List, false))
  572. {
  573. return DecMAS();
  574. }
  575. if (!m_DoseUnit.m_MAS->Verify(tempMAS)) return RET_STATUS::RET_SUCCEED;
  576. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  577. {
  578. printf("\n Techmode is not MAS, can't set MAS");
  579. return RET_STATUS::RET_FAILED;
  580. }
  581. char temp[50] = { 0 };
  582. sprintf_s(temp, "MX%06d", (int)(tempMAS * 1000));
  583. ProcessCommand(temp);
  584. #endif
  585. return RET_STATUS::RET_SUCCEED;
  586. }
  587. RET_STATUS nsGEN::SDCDevice::SetTechmode (int value)
  588. {
  589. if (!m_DoseUnit.m_Techmode->Verify (value)) return RET_STATUS::RET_SUCCEED;
  590. #if 0
  591. char temp [50] = { 0 };
  592. if (value == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  593. sprintf_s(temp, "TM%01d", 2);
  594. else
  595. sprintf_s(temp, "TM%01d", 3);
  596. ProcessCommand(temp);
  597. #else
  598. //实际发送长数据
  599. char strcmd[250] = { 0 };
  600. if (value == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  601. {
  602. //SetMAS(m_sPreAPRvalue.fMAS);
  603. sprintf_s(strcmd, "SXWS%1dFO%1dFI%03dFS1FN%1dKV%03dMX%06d",m_DoseUnit.m_WS->Get(), m_DoseUnit.m_Focus->Get(), m_sPreAPRvalue.nAECField, m_sPreAPRvalue.nAECDensity + 4, (int)m_sPreAPRvalue.fKV, (int)(m_sPreAPRvalue.fMAS * 1000));
  604. //sprintf_s(strcmd, "SA2P%1d%1d%03d%06d", m_DoseUnit.m_WS->Get(), m_DoseUnit.m_Focus->Get(), (int)m_sPreAPRvalue.fKV, (int)(m_sPreAPRvalue.fMAS * 1000));
  605. }
  606. else
  607. {
  608. //SetMA(m_sPreAPRvalue.fMA);
  609. //SetMS(m_sPreAPRvalue.fMS);
  610. sprintf_s(strcmd, "SAWS%1dFO%1dET%1dFI%03dFS1FN%1dKV%03dMA%05dMS%05d",m_DoseUnit.m_WS->Get(), m_DoseUnit.m_Focus->Get(), value, m_sPreAPRvalue.nAECField, m_sPreAPRvalue.nAECDensity + 4, (int)m_sPreAPRvalue.fKV, (int)(m_sPreAPRvalue.fMA * 10), (int)m_sPreAPRvalue.fMS);
  611. //sprintf_s(strcmd, "SA3P%1d%1d%03d%05d%05d", m_DoseUnit.m_WS->Get(), m_DoseUnit.m_Focus->Get(), (int)m_sPreAPRvalue.fKV, (int)(m_sPreAPRvalue.fMA * 10), (int)m_sPreAPRvalue.fMS);
  612. }
  613. ProcessCommand(strcmd);
  614. #endif
  615. FDEBUG("Enter SetTechmode = {$}", value);
  616. assert(value);
  617. bool rc = false;
  618. int ntechmode = value;
  619. if (ntechmode == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  620. {
  621. rc = m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_V2TYPE::ET_AEC);
  622. if (m_DoseUnit.m_AECField == 0)
  623. {
  624. m_DoseUnit.m_AECField->Update(10);
  625. FireNotify(AttrKey::AECFIELD, m_DoseUnit.m_AECField->JSGet());
  626. }
  627. }
  628. else if (ntechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  629. {
  630. rc = m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_V2TYPE::ET_MAS);
  631. }
  632. else if (ntechmode == AttrKey::TECHMODE_V2TYPE::ET_TIME)
  633. {
  634. rc = m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_V2TYPE::ET_TIME);
  635. }
  636. if (rc)
  637. {
  638. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  639. }
  640. return RET_STATUS::RET_SUCCEED;
  641. }
  642. RET_STATUS nsGEN::SDCDevice::SetFocus (int value)
  643. {
  644. if (!m_DoseUnit.m_Focus->Verify (value)) return RET_STATUS::RET_SUCCEED;
  645. char temp [50] = { 0 };
  646. sprintf_s (temp, "FOS%01d", (int)value+1);
  647. ProcessCommand(temp);
  648. return RET_STATUS::RET_SUCCEED;
  649. }
  650. RET_STATUS nsGEN::SDCDevice::SetAECDensity (int value)
  651. {
  652. FDEBUG("Enter SetAECDensity = {$}", value);
  653. if (!m_DoseUnit.m_AECDensity->Verify (value)) return RET_STATUS::RET_SUCCEED;
  654. if (m_DoseUnit.m_Techmode->Get () != AttrKey::TECHMODE_V2TYPE::ET_AEC)
  655. return RET_STATUS::RET_FAILED;
  656. FDEBUG("2 Enter SetAECDensity = {$}", value);
  657. if (m_DoseUnit.m_AECDensity->Get() != value)
  658. {
  659. char temp[50] = { 0 };
  660. int realData = ((int)value + 4);
  661. sprintf_s(temp, "FN%01d", realData);
  662. ProcessCommand(temp);
  663. FDEBUG("3 Enter SetAECDensity = {$}", value);
  664. }
  665. FDEBUG("4 Enter SetAECDensity = {$}", value);
  666. return RET_STATUS::RET_SUCCEED;
  667. }
  668. RET_STATUS nsGEN::SDCDevice::SetAECField (int value)
  669. {
  670. FDEBUG("Enter SetAECField = {$}", value);
  671. if (!m_DoseUnit.m_AECField->Verify (value)) return RET_STATUS::RET_SUCCEED;
  672. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  673. return RET_STATUS::RET_FAILED;
  674. char temp [50] = { 0 };
  675. int leftValue = value / 100;
  676. int midValue = (value % 100) / 10;
  677. int rightValue = value % 10;
  678. sprintf_s (temp, "FI0%01d", leftValue);
  679. ProcessCommand(temp);
  680. sprintf_s(temp, "FI1%01d", midValue);
  681. ProcessCommand(temp);
  682. sprintf_s(temp, "FI2%01d", rightValue);
  683. ProcessCommand(temp);
  684. FDEBUG("Leave SetAECField = {$}", value);
  685. return RET_STATUS::RET_SUCCEED;
  686. }
  687. RET_STATUS nsGEN::SDCDevice::SetAECFilm (int value)
  688. {
  689. if (!m_DoseUnit.m_AECFilm->Verify (value)) return RET_STATUS::RET_SUCCEED;
  690. if (m_DoseUnit.m_Techmode->Get () == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  691. return RET_STATUS::RET_FAILED;
  692. char temp [50] = { 0 };
  693. sprintf_s (temp, "FS%01d", (int)value);
  694. ProcessCommand(temp);
  695. return RET_STATUS::RET_SUCCEED;
  696. }
  697. RET_STATUS nsGEN::SDCDevice::SetWS (const string value)
  698. {
  699. FDEBUG("Enter SetWS {$}", value);
  700. int tempws = 1;
  701. string strWS = "";
  702. cfgWorkStationKey trWS = cfgWorkStationKey(value.c_str());
  703. if (m_arrWSMap.find(trWS) != m_arrWSMap.end())
  704. {
  705. m_strCurrentWSName = trWS;
  706. tempws = m_arrWSMap[m_strCurrentWSName].nWSNamber;
  707. strWS = m_arrWSMap[m_strCurrentWSName].strWSNAme;
  708. FDEBUG("Set WS number [{$}][{$}]", strWS.c_str(), tempws);
  709. }
  710. else
  711. {
  712. FDEBUG("Set WS number default 1");
  713. m_strCurrentWSName = cfgWorkStationKey(1);
  714. }
  715. char temp[50] = { 0 };
  716. sprintf_s(temp, "WS%01d", tempws);
  717. ProcessCommand(temp);
  718. return RET_STATUS::RET_SUCCEED;
  719. }
  720. RET_STATUS nsGEN::SDCDevice::SetAPR (const _tAPRArgs& t)
  721. {
  722. char strcmd[256];
  723. FDEBUG("Enter SETAPR t.nWS={$},t.fKV={$},t.fMA={$},t.fMAS={$},t.fMS={$},t.nAECDensity={$},t.nAECField={$},t.nAECFilm={$},t.nFocus={$},t.nTechmode={$} \n",
  724. t.nWS, t.fKV, t.fMA, t.fMAS, t.fMS, t.nAECDensity, t.nAECField, t.nAECFilm, t.nFocus, t.nTechmode);
  725. FDEBUG("[SynMode:{$},SynValue:{$},WS:{$}],currentMode[{$}]",
  726. m_SyncMode.strSyncMode.c_str(), m_SyncMode.strSyncValue.c_str(), m_SyncMode.strWS.c_str(), m_DoseUnit.m_ExpMode->JSGet().c_str());
  727. int tempws = atoi(m_SyncMode.strSyncValue.c_str());
  728. //if (m_arrWSMap.find(cfgWorkStationKey(t.nWS)) != m_arrWSMap.end())
  729. //{
  730. // m_strCurrentWSName = cfgWorkStationKey(t.nWS);
  731. // tempws = m_arrWSMap[m_strCurrentWSName].nWSNamber;
  732. // FDEBUG("Set WS number {$}", tempws);
  733. //}
  734. //else
  735. //{
  736. // FDEBUG("Set WS number default 1");
  737. // m_strCurrentWSName = cfgWorkStationKey(t.nWS);
  738. // tempws = t.nWS;
  739. //}
  740. //add by wxx for bug6097 20230919
  741. FDEBUG("save APR value");
  742. m_sPreAPRvalue = t;
  743. if (m_DoseUnit.m_Techmode->Verify(t.nTechmode))
  744. m_DoseUnit.m_Techmode->Update(t.nTechmode);
  745. FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
  746. if (t.nTechmode == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  747. {
  748. sprintf_s(strcmd, "SXWS%1dFO%1dFI%03dFS1FN%1dKV%03dMX%06d", tempws, t.nFocus, t.nAECField, t.nAECDensity + 4, (int)t.fKV, (int)(t.fMAS * 1000));
  749. }
  750. else
  751. {
  752. //sprintf_s(strcmd, "SAWS%1dFO%1dE0FI%03dFS1FN%1dKV%03dMA%05dMS%05d", m_DoseUnit.m_WS->Get(), t.nFocus, t.nAECField, t.nAECDensity + 4, (int)t.fKV, (int)(t.fMA * 10), (int)t.fMS);
  753. sprintf_s(strcmd, "SAWS%1dFO%1dET%1dFI%03dFS1FN%1dKV%03dMA%05dMS%05d", tempws, t.nFocus, 0, t.nAECField, t.nAECDensity + 4, (int)t.fKV, (int)(t.fMA * 10), (int)t.fMS);
  754. }
  755. ProcessCommand(strcmd);
  756. FDEBUG("Leave SETAPR = {$}", strcmd);
  757. return RET_STATUS::RET_SUCCEED;
  758. }
  759. RET_STATUS nsGEN::SDCDevice::QueryHE(int& value)
  760. {
  761. return RET_STATUS::RET_SUCCEED;
  762. }
  763. RET_STATUS nsGEN::SDCDevice::QueryPostKV(float& value)
  764. {
  765. if (WAIT_OBJECT_0 == WaitForSingleObject(m_hGenPostEvent, 100))
  766. {
  767. value = m_DoseUnit.m_PostKV->Get();
  768. return RET_STATUS::RET_SUCCEED;
  769. }
  770. else
  771. {
  772. value = 0.0;
  773. return RET_STATUS::RET_SUCCEED;
  774. }
  775. }
  776. RET_STATUS nsGEN::SDCDevice::QueryPostMA(float& value)
  777. {
  778. if (WAIT_OBJECT_0 == WaitForSingleObject(m_hGenPostEvent, 100))
  779. {
  780. value = m_DoseUnit.m_PostMA->Get();
  781. return RET_STATUS::RET_SUCCEED;
  782. }
  783. else
  784. {
  785. value = 0.0;
  786. return RET_STATUS::RET_SUCCEED;
  787. }
  788. }
  789. RET_STATUS nsGEN::SDCDevice::QueryPostMS(float& value)
  790. {
  791. if (WAIT_OBJECT_0 == WaitForSingleObject(m_hGenPostEvent, 100))
  792. {
  793. value = m_DoseUnit.m_PostMS->Get();
  794. return RET_STATUS::RET_SUCCEED;
  795. }
  796. else
  797. {
  798. value = 0.0;
  799. return RET_STATUS::RET_SUCCEED;
  800. }
  801. }
  802. RET_STATUS nsGEN::SDCDevice::QueryPostMAS(float& value)
  803. {
  804. if (WAIT_OBJECT_0 == WaitForSingleObject(m_hGenPostEvent, 100))
  805. {
  806. value = m_DoseUnit.m_PostMAS->Get();
  807. return RET_STATUS::RET_SUCCEED;
  808. }
  809. else
  810. {
  811. value = 0.0;
  812. return RET_STATUS::RET_SUCCEED;
  813. }
  814. }
  815. RET_STATUS nsGEN::SDCDevice::Clear_DAP()
  816. {
  817. ProcessCommand("DOR", WaitForNothing);
  818. return RET_STATUS::RET_SUCCEED;
  819. }
  820. RET_STATUS nsGEN::SDCDevice::GetValue_DAP(float& value)
  821. {
  822. if (WAIT_OBJECT_0 == WaitForSingleObject(m_hGenPostEvent, 100))
  823. {
  824. value = m_DAP->Get();
  825. return RET_STATUS::RET_SUCCEED;
  826. }
  827. else
  828. {
  829. value = 0.0;
  830. return RET_STATUS::RET_SUCCEED;
  831. }
  832. }
  833. RET_STATUS nsGEN::SDCDevice::ActiveSyncMode(_tSyncModeArgs value)
  834. {
  835. FDEBUG("Enter ActiveSyncMode:[SynMode:{$},SynValue:{$},WS:{$}],currentMode[{$}]",
  836. value.strSyncMode.c_str(), value.strSyncValue.c_str(), value.strWS.c_str(), m_DoseUnit.m_ExpMode->JSGet().c_str());
  837. m_SyncMode = value;
  838. int tempSynNUm = atoi(value.strSyncValue.c_str());
  839. if (tempSynNUm == m_DoseUnit.m_WS->Get())
  840. {
  841. char temp[50] = { 0 };
  842. sprintf_s(temp, "WS%01d", tempSynNUm);
  843. if (value.strSyncMode == AttrKey::SYNC_TYPE::SYNC_HWS)
  844. {
  845. ProcessCommand(temp);
  846. }
  847. else if (value.strSyncMode == AttrKey::SYNC_TYPE::SYNC_CMD)
  848. {
  849. ProcessCommand(temp);
  850. }
  851. else if (value.strSyncMode == AttrKey::SYNC_TYPE::SYNC_FRE)
  852. {
  853. ProcessCommand(temp);
  854. }
  855. else if (value.strSyncMode == AttrKey::SYNC_TYPE::SYNC_DEMO)
  856. {
  857. }
  858. FDEBUG("ActiveSyncMode:not support [{$}:{$}] in [{$}]", value.strSyncMode.c_str(), value.strSyncValue.c_str(), m_DoseUnit.m_ExpMode->JSGet().c_str());
  859. }
  860. return RET_STATUS::RET_SUCCEED;
  861. }
  862. RET_STATUS nsGEN::SDCDevice::SetGenSynState(int value)
  863. {
  864. FDEBUG("SetGenSynState:[{$}]", value);
  865. if (value == 3 && m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY)
  866. {
  867. if (m_SyncMode.strSyncMode == AttrKey::SYNC_TYPE::SYNC_CMD)
  868. {
  869. //if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON))
  870. // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  871. FDEBUG("SetGenSynState: in softSYN,turn to RAD_XRAYON and send XR1");
  872. ProcessCommand(SpecialCMDXR1, -1, true);
  873. }
  874. else
  875. {
  876. FDEBUG("SetGenSynState:SyncMode[{$}] not CMD", m_SyncMode.strSyncMode.c_str());
  877. }
  878. }
  879. else
  880. {
  881. FDEBUG("SetGenSynState: generator is not in ready status, can't send XR1 command");
  882. }
  883. return RET_STATUS::RET_SUCCEED;
  884. }
  885. RET_STATUS nsGEN::SDCDevice::SetGenState(int value)
  886. {
  887. return RET_STATUS::RET_SUCCEED;
  888. }
  889. RET_STATUS nsGEN::SDCDevice::RefreshData ()
  890. {
  891. if(m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT))
  892. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT);
  893. FDEBUG("RefreshData:gen state is GENERATOR_STATUS_INIT");
  894. ProcessCommand(SpecialCMDAR);
  895. ProcessCommand(SpecialCMDRF);
  896. ProcessCommand(SpecialCMDST);
  897. return RET_STATUS::RET_SUCCEED;
  898. }
  899. RET_STATUS nsGEN::SDCDevice::SetExpEnable()
  900. {
  901. ProcessCommand(SpecialCMDRX1);
  902. return RET_STATUS::RET_SUCCEED;
  903. }
  904. RET_STATUS nsGEN::SDCDevice::SetExpDisable()
  905. {
  906. ProcessCommand(SpecialCMDRX0);
  907. return RET_STATUS::RET_SUCCEED;
  908. }
  909. RET_STATUS nsGEN::SDCDevice::Reset()
  910. {
  911. ProcessCommand(SpecialCMDAR);
  912. if (m_bExpoEnable.load() == false)
  913. {
  914. ProcessCommand(SpecialCMDRX1);
  915. }
  916. return RET_STATUS::RET_SUCCEED;
  917. }
  918. RET_STATUS nsGEN::SDCDevice::SetExpMode(std::string value)
  919. {
  920. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  921. return RET_STATUS::RET_SUCCEED;
  922. }
  923. RET_STATUS nsGEN::SDCDevice::SetFLFMode(std::string value)
  924. {
  925. return RET_STATUS::RET_SUCCEED;
  926. }
  927. RET_STATUS nsGEN::SDCDevice::SetEXAMMode(std::string value)
  928. {
  929. return RET_STATUS::RET_SUCCEED;
  930. }
  931. RET_STATUS nsGEN::SDCDevice::SetFrameRate(FLOAT frameRate)
  932. {
  933. return RET_STATUS::RET_SUCCEED;
  934. }
  935. RET_STATUS nsGEN::SDCDevice::HWSend (char* strCommand, int iWaitType , int nTimeOut)
  936. {
  937. int nWhileNumber = 0;
  938. if (!m_SCF)
  939. {
  940. FERROR("HWSend: m_SCF is null");
  941. return RET_STATUS::RET_FAILED;
  942. }
  943. else if (!m_sendEnable &&
  944. !(strncmp(strCommand, SpecialCMDAR,2) == 0 || strncmp(strCommand, SpecialCMDST, 2) == 0))//如果发生器处于错误状态,并且发送的不是AR或者ST命令,通通不发
  945. {
  946. FDEBUG("HWSend: Don`t Send Command: [{$}]", strCommand);
  947. StopWait();
  948. return RET_STATUS::RET_FAILED;
  949. }
  950. ResetEvent(m_hGenCPEvent);
  951. ResetEvent(m_hGenACKEvent);
  952. ResetEvent(m_hGenSELFEvent);
  953. if(!m_bExpoFlag ||
  954. (m_bExpoFlag && (strncmp(strCommand, SpecialCMDXR1, 3) == 0 ||
  955. strncmp(strCommand, SpecialCMDXR0, 3) == 0 ||
  956. strncmp(strCommand, SpecialCMDPC, 2) == 0)))
  957. {
  958. char strSendCommand[100] = { 0 };
  959. int len = strlen(strCommand);
  960. if (len < 100)
  961. {
  962. ::memcpy(strSendCommand, strCommand, len);
  963. }
  964. strSendCommand[len] = 0x0d;
  965. strSendCommand[len + 1] = 0x0a;
  966. strSendCommand[len + 2] = 0x03;
  967. //strSendCommand [len + 3] = 0x00;
  968. FDEBUG("==OUT==:[{$}]", strSendCommand);
  969. int ret = 0;
  970. m_SCF.Lock(msTimeOut_Lock)
  971. .SendPacket(strSendCommand, strlen(strSendCommand), nTimeOut, ret);
  972. //Sleep(nTimeOut);
  973. }
  974. else
  975. {
  976. StopWait();
  977. }
  978. return RET_STATUS::RET_SUCCEED;
  979. }
  980. void nsGEN::SDCDevice::WaitforSELF(const char* cmd, int lengh)
  981. {
  982. if (m_strCurrentCommand.strCommand.compare(0, lengh, cmd, 0, lengh) != 0)
  983. {
  984. return;
  985. }
  986. if (m_strCurrentCommand.nCommmandType % 10 > 0)
  987. {
  988. m_strCurrentCommand.nCommmandType -= 1;
  989. }
  990. FDEBUG("WaitforSELF:get cmd[{$}]type[{$}] self", m_strCurrentCommand.strCommand.c_str(), m_strCurrentCommand.nCommmandType.load());
  991. SetEvent(m_hGenSELFEvent);
  992. }
  993. void nsGEN::SDCDevice::WaitforACK()
  994. {
  995. if (m_strCurrentCommand.nCommmandType % 100 >= 10)
  996. {
  997. m_strCurrentCommand.nCommmandType -= 10;
  998. }
  999. FDEBUG("WaitforACK:get cmd[{$}]type[{$}] ACK", m_strCurrentCommand.strCommand.c_str(), m_strCurrentCommand.nCommmandType.load());
  1000. SetEvent(m_hGenACKEvent);
  1001. }
  1002. void nsGEN::SDCDevice::WaitforCP()
  1003. {
  1004. if (m_strCurrentCommand.nCommmandType >= 100)
  1005. {
  1006. m_strCurrentCommand.nCommmandType -= 100;
  1007. }
  1008. FDEBUG("WaitforCP:get cmd[{$}]type[{$}] cp", m_strCurrentCommand.strCommand.c_str(), m_strCurrentCommand.nCommmandType.load());
  1009. SetEvent(m_hGenCPEvent);
  1010. }
  1011. void nsGEN::SDCDevice::StopWait()
  1012. {
  1013. if (!m_strCurrentCommand.strCommand.empty())
  1014. {
  1015. FDEBUG("StopWait:cmd[{$}]type[{$}] not wait", m_strCurrentCommand.strCommand.c_str(), m_strCurrentCommand.nCommmandType.load());
  1016. m_strCurrentCommand.nCommmandType = 0;
  1017. }
  1018. }
  1019. void nsGEN::SDCDevice::FireNotify (std::string key, std::string content)
  1020. {
  1021. EventCenter->OnNotify (1, key, content);
  1022. }
  1023. bool nsGEN::SDCDevice::ProcessCommand(std::string strCommand, int nType, bool isFirstSend)
  1024. {
  1025. tagCommandStruct TempSDCCommand;
  1026. TempSDCCommand.strCommand = strCommand;
  1027. if (nType == -1)
  1028. {
  1029. TempSDCCommand.nCommmandType = 0;
  1030. if (std::find_if(g_WaitSELF_List.begin(), g_WaitSELF_List.end(), [strCommand](const string& Item)
  1031. {
  1032. if (strCommand.compare(0, Item.length(), Item, 0, Item.length()) == 0)
  1033. {
  1034. return true;
  1035. }
  1036. return false;
  1037. }) != g_WaitSELF_List.end())
  1038. {
  1039. TempSDCCommand.nCommmandType += 1;
  1040. }
  1041. if (std::find_if(g_WaitAKCMD_List.begin(), g_WaitAKCMD_List.end(), [strCommand](const string& Item)
  1042. {
  1043. if (strCommand.compare(0, Item.length(), Item, 0, Item.length()) == 0)
  1044. {
  1045. return true;
  1046. }
  1047. return false;
  1048. }) != g_WaitAKCMD_List.end())
  1049. {
  1050. TempSDCCommand.nCommmandType += 10;
  1051. }
  1052. if (std::find_if(g_WaitCPCMD_List.begin(), g_WaitCPCMD_List.end(), [strCommand](const string& Item)
  1053. {
  1054. if (strCommand.compare(0, Item.length(), Item, 0, Item.length()) == 0)
  1055. {
  1056. return true;
  1057. }
  1058. return false;
  1059. }) != g_WaitCPCMD_List.end())
  1060. {
  1061. TempSDCCommand.nCommmandType += 100;
  1062. }
  1063. }
  1064. else
  1065. TempSDCCommand.nCommmandType = nType;
  1066. bool firstOldCMD = true;
  1067. EnterCriticalSection(&m_iCriticalSection);
  1068. //当发送ST,HU,SA,SX,DS,RX命令前,清空待发送命令vector中的其他同类型命令,提高发送效率,减少发送错误
  1069. auto found = std::find_if(g_SpecialCMD_List.begin(), g_SpecialCMD_List.end(), [strCommand](const string& Item)
  1070. {
  1071. if (strCommand.compare(0, Item.length(), Item, 0, Item.length()) == 0)
  1072. {
  1073. return true;
  1074. }
  1075. return false;
  1076. });
  1077. if (found != g_SpecialCMD_List.end())
  1078. {
  1079. if ((strCommand.compare(SpecialCMDAR) == 0) || (strCommand.compare(SpecialCMDXR1) == 0))
  1080. {
  1081. //if (m_DoseUnit.m_GenState->Get() == nsGEN::AttrKey::GENERATOR_STATUS_STANDBY)
  1082. //{
  1083. m_SdcCommondvector.clear();
  1084. FDEBUG("ProcessCommand:clear the whole vector when get[{$}] ", strCommand.c_str());
  1085. //}
  1086. //else
  1087. //{
  1088. // FWARN("ProcessCommand:isn`t GENERATOR_STATUS_STANDBY not clear");
  1089. //}
  1090. }
  1091. else
  1092. {
  1093. //if (m_DoseUnit.m_GenState->Get() == nsGEN::AttrKey::GENERATOR_STATUS_STANDBY)
  1094. //{
  1095. for (int i = 0; i < m_SdcCommondvector.size(); i++)
  1096. {
  1097. if (m_SdcCommondvector[i].strCommand.compare(0, strCommand.length(),strCommand, 0, strCommand.length()) == 0)
  1098. {
  1099. if(firstOldCMD)
  1100. {
  1101. firstOldCMD = false;
  1102. m_SdcCommondvector[i] = TempSDCCommand;
  1103. FDEBUG("ProcessCommand:replace first same command[{$}] in vector ", strCommand.c_str());
  1104. }
  1105. else
  1106. {
  1107. m_SdcCommondvector.erase(m_SdcCommondvector.begin() + i);
  1108. i--;
  1109. FDEBUG("ProcessCommand:Clear other same command[{$}] in vector ", strCommand.c_str());
  1110. }
  1111. }
  1112. }
  1113. //}
  1114. //else
  1115. //{
  1116. // FWARN("ProcessCommand:isn`t GENERATOR_STATUS_STANDBY not replace");
  1117. //}
  1118. }
  1119. }
  1120. if(firstOldCMD)
  1121. {
  1122. if(TempSDCCommand.strCommand.compare(SpecialCMDRX1) == 0)
  1123. {
  1124. TempSDCCommand.nWaitTime = 10000;
  1125. }
  1126. if (isFirstSend)
  1127. {
  1128. FDEBUG("ProcessCommand:add cmd[{$}][{$}] in vector begin",
  1129. TempSDCCommand.strCommand.c_str(), TempSDCCommand.nCommmandType.load());
  1130. m_SdcCommondvector.push_front(TempSDCCommand);
  1131. }
  1132. else
  1133. {
  1134. FDEBUG("ProcessCommand:add cmd[{$}][{$}] in vector end",
  1135. TempSDCCommand.strCommand.c_str(), TempSDCCommand.nCommmandType.load());
  1136. m_SdcCommondvector.push_back(TempSDCCommand);
  1137. }
  1138. }
  1139. LeaveCriticalSection(&m_iCriticalSection);
  1140. return true;
  1141. }
  1142. bool nsGEN::SDCDevice::ReProcessCommand(std::string strCommand, int nType)
  1143. {
  1144. tagCommandStruct TempSDCCommand;
  1145. TempSDCCommand.strCommand = strCommand;
  1146. if (nType == -1)
  1147. {
  1148. TempSDCCommand.nCommmandType = 0;
  1149. if (std::find_if(g_WaitSELF_List.begin(), g_WaitSELF_List.end(), [strCommand](const string& Item)
  1150. {
  1151. if (strCommand.compare(0, Item.length(), Item, 0, Item.length()) == 0)
  1152. {
  1153. return true;
  1154. }
  1155. return false;
  1156. }) != g_WaitSELF_List.end())
  1157. {
  1158. TempSDCCommand.nCommmandType += 1;
  1159. }
  1160. if (std::find_if(g_WaitAKCMD_List.begin(), g_WaitAKCMD_List.end(), [strCommand](const string& Item)
  1161. {
  1162. if (strCommand.compare(0, Item.length(), Item, 0, Item.length()) == 0)
  1163. {
  1164. return true;
  1165. }
  1166. return false;
  1167. }) != g_WaitAKCMD_List.end())
  1168. {
  1169. TempSDCCommand.nCommmandType += 10;
  1170. }
  1171. if (std::find_if(g_WaitCPCMD_List.begin(), g_WaitCPCMD_List.end(), [strCommand](const string& Item)
  1172. {
  1173. if (strCommand.compare(0, Item.length(), Item, 0, Item.length()) == 0)
  1174. {
  1175. return true;
  1176. }
  1177. return false;
  1178. }) != g_WaitCPCMD_List.end())
  1179. {
  1180. TempSDCCommand.nCommmandType += 100;
  1181. }
  1182. }
  1183. else
  1184. TempSDCCommand.nCommmandType = nType;
  1185. EnterCriticalSection(&m_iCriticalSection);
  1186. m_SdcCommondvector.push_front(TempSDCCommand);
  1187. LeaveCriticalSection(&m_iCriticalSection);
  1188. return true;
  1189. }
  1190. DWORD SDCDevice::SedecalSendingCommandsThread(LPVOID pParam)
  1191. {
  1192. FDEBUG("Enter SedecalSendingCommandsThread");
  1193. SDCDevice* pCurrentGen = (SDCDevice*)pParam;
  1194. if (pCurrentGen == NULL)
  1195. {
  1196. FERROR("SendingCommandsThread is null");
  1197. return 0;
  1198. }
  1199. //indicating start thread success;
  1200. SetEvent(pCurrentGen->m_hSendingThreadToggleEvent);
  1201. //perform sending sedecal commands
  1202. while (!pCurrentGen->m_bSendingCommandsThreadExit)
  1203. {
  1204. //query the command from the vector
  1205. if (pCurrentGen->m_SdcCommondvector.size() > 0)
  1206. {
  1207. EnterCriticalSection(&(pCurrentGen->m_iCriticalSection));
  1208. pCurrentGen->m_strCurrentCommand = pCurrentGen->m_SdcCommondvector[0];
  1209. pCurrentGen->m_SdcCommondvector.pop_front();//erase the first command
  1210. FDEBUG("SendingCommandsThread:get cmd[{$}]type[{$}] from vector",
  1211. pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType.load());
  1212. LeaveCriticalSection(&(pCurrentGen->m_iCriticalSection));
  1213. if (pCurrentGen->m_strCurrentCommand.strCommand != "" && pCurrentGen->m_strCurrentCommand.nCommmandType.load() >= 0)// with commnad
  1214. {
  1215. //if (pCurrentGen->m_strCurrentCommand.strCommand.compare(0, 2, SpecialCMDHU) == 0 || pCurrentGen->m_strCurrentCommand.strCommand.compare(0, 2, SpecialCMDIT) == 0) //not wait command
  1216. //{
  1217. // pCurrentGen->m_strCurrentCommand.nCommmandType = 0;
  1218. // pCurrentGen->HWSend((char*)pCurrentGen->m_strCurrentCommand.strCommand.c_str(), 0);
  1219. //}else
  1220. if (pCurrentGen->m_strCurrentCommand.strCommand.compare(0, 2, SpecialCMDSA) == 0 ||
  1221. pCurrentGen->m_strCurrentCommand.strCommand.compare(0, 2, SpecialCMDSX) == 0)//APR command, dual energy command
  1222. {
  1223. pCurrentGen->HWSend((char*)pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType, 3000);
  1224. }
  1225. else if (pCurrentGen->m_strCurrentCommand.strCommand.compare(0,3, SpecialCMDFOS) == 0) //FO command
  1226. {
  1227. pCurrentGen->HWSend((char*)pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType, 1000);
  1228. }
  1229. else
  1230. {
  1231. pCurrentGen->HWSend((char*)pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType);
  1232. }
  1233. //等待
  1234. if (pCurrentGen->m_strCurrentCommand.nCommmandType > 0)
  1235. {
  1236. int waitType = pCurrentGen->m_strCurrentCommand.nCommmandType.load();
  1237. int arrayNum = 0;
  1238. bool cmdOver = false;
  1239. HANDLE hEventArray[3];
  1240. if (waitType % 10 > 0)
  1241. {
  1242. hEventArray[arrayNum] = pCurrentGen->m_hGenSELFEvent;
  1243. arrayNum++;
  1244. }
  1245. if (waitType % 100 >= 10)
  1246. {
  1247. hEventArray[arrayNum] = pCurrentGen->m_hGenACKEvent;
  1248. arrayNum++;
  1249. }
  1250. if (waitType >= 100)
  1251. {
  1252. hEventArray[arrayNum] = pCurrentGen->m_hGenCPEvent;
  1253. arrayNum++;
  1254. }
  1255. FDEBUG("SendingCommandsThread:wait cmd[{$}]type[{$}][{$}]waitTime[{$}]",
  1256. pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType.load(), arrayNum, pCurrentGen->m_strCurrentCommand.nWaitTime);
  1257. int waitTime = pCurrentGen->m_strCurrentCommand.nWaitTime;
  1258. DWORD dwResult = WaitForMultipleObjects(arrayNum, hEventArray, TRUE, waitTime);
  1259. switch (dwResult)
  1260. {
  1261. case WAIT_OBJECT_0:
  1262. FDEBUG("SendingCommandsThread:cmd[{$}]type[{$}] is over",
  1263. pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType.load());
  1264. cmdOver = true;
  1265. pCurrentGen->m_TimeoutReset = 0;
  1266. break;
  1267. case WAIT_TIMEOUT:
  1268. FDEBUG("SendingCommandsThread:cmd[{$}]type[{$}] is timeout",
  1269. pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType.load());
  1270. if (pCurrentGen->m_strCurrentCommand.nCommmandType.load() == 0)
  1271. {
  1272. cmdOver = true;
  1273. pCurrentGen->m_TimeoutReset = 0;
  1274. }
  1275. break;
  1276. case WAIT_FAILED:
  1277. FDEBUG("SendingCommandsThread:cmd[{$}]type[{$}] is failed",
  1278. pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType.load());
  1279. break;
  1280. }
  1281. if (!cmdOver)
  1282. {
  1283. if (pCurrentGen->m_TimeoutReset <= 3)
  1284. {
  1285. pCurrentGen->m_TimeoutReset++;
  1286. pCurrentGen->ReProcessCommand(pCurrentGen->m_strCurrentCommand.strCommand);
  1287. }
  1288. else
  1289. {
  1290. pCurrentGen->m_TimeoutReset = 0;
  1291. FWARN("SendingCommandsThread:cmd[{$}]type[{$}] Exceeded attempts",
  1292. pCurrentGen->m_strCurrentCommand.strCommand.c_str(), pCurrentGen->m_strCurrentCommand.nCommmandType.load());
  1293. }
  1294. }
  1295. else
  1296. {
  1297. Sleep(30);//no commnad to send, so sleep 10 ms
  1298. }
  1299. }
  1300. }
  1301. else
  1302. {
  1303. Sleep(30);//no commnad to send, so sleep 10 ms
  1304. }
  1305. }
  1306. else
  1307. {
  1308. Sleep(10);//no commnad to send, so sleep 10 ms
  1309. }
  1310. // send command
  1311. if (!(pCurrentGen->m_bExpoFlag)) //add by wxx for bug6038 20230919
  1312. {
  1313. DWORD tmNowTime = GetTickCount();
  1314. if (tmNowTime > 15000)
  1315. {
  1316. long runTime = tmNowTime - pCurrentGen->m_tmSysTime;
  1317. if (runTime > 15000)
  1318. {
  1319. pCurrentGen->m_tmSysTime = tmNowTime;
  1320. //pCurrentGen->ProcessCommand(SpecialCMDHU, WaitForCPSELF);
  1321. //pCurrentGen->ProcessCommand(SpecialCMDIT, WaitForNothing);
  1322. }
  1323. }
  1324. else
  1325. {
  1326. pCurrentGen->m_tmSysTime = GetTickCount();
  1327. }
  1328. }
  1329. }
  1330. FDEBUG("End SendingCommandsThread!!");
  1331. //indicating the end of thread;
  1332. SetEvent(pCurrentGen->m_hSendingThreadToggleEvent);
  1333. return 0;
  1334. }
  1335. //start timer to do offset calibration periodically;
  1336. bool SDCDevice::StartSendingCommandsThread()
  1337. {
  1338. //create thread;
  1339. DWORD m_HardwareStatusID;
  1340. m_SendingCommandsThread = CreateThread(0, 0, SedecalSendingCommandsThread, this, 0, &m_HardwareStatusID);
  1341. FDEBUG("Enter StartSendingCommandsThread beion");
  1342. if (NULL == m_SendingCommandsThread)
  1343. {
  1344. FDEBUG("StartSendingCommandsThread failed \n");
  1345. return false;
  1346. }
  1347. //wait till thread create successful;
  1348. if (WaitForSingleObject(m_hSendingThreadToggleEvent, 5000) == WAIT_OBJECT_0)
  1349. {
  1350. FDEBUG("detected the start of sending commands thread!");
  1351. ResetEvent(m_hSendingThreadToggleEvent);
  1352. }
  1353. FDEBUG("StartSendingCommandsThread end \n");
  1354. m_nSendingCommandsThreadId = m_HardwareStatusID;
  1355. return true;
  1356. }
  1357. bool SDCDevice::SetAcquireSatus()
  1358. {
  1359. ProcessCommand("RFW");
  1360. return true;
  1361. }
  1362. //stop sending commands thread periodically;
  1363. void SDCDevice::StopSendingCommandsThread()
  1364. {
  1365. FDEBUG("sending commands thread exiting...");
  1366. if (NULL != m_SendingCommandsThread)
  1367. {
  1368. m_bSendingCommandsThreadExit = true;
  1369. if (::WaitForSingleObject(m_hSendingThreadToggleEvent, 5000) == WAIT_OBJECT_0)
  1370. {
  1371. FDEBUG("detected the exit of sending commands thread!");
  1372. ResetEvent(m_hSendingThreadToggleEvent);
  1373. }
  1374. else
  1375. {
  1376. DWORD exitCode = 0;
  1377. //Retrieves the termination status of the specified thread;
  1378. if (!GetExitCodeThread(m_SendingCommandsThread, &exitCode))
  1379. {
  1380. DWORD nError = ::GetLastError();
  1381. FDEBUG("GetExitCodeThread() error, error No is [{$}]", nError);
  1382. }
  1383. TerminateThread(m_SendingCommandsThread, exitCode);
  1384. }
  1385. m_SendingCommandsThread = NULL;
  1386. }
  1387. }
  1388. // 收到硬件的通知, 有包到达
  1389. // 按照设计, 仅当数据有变化时, 才发通知到上层, 因此里面有大量的 if (..) FireNotify (..)
  1390. void nsGEN::SDCDevice::OnCallBack ()
  1391. {
  1392. auto HWNotProcess = [] (const char * value, int length) -> void
  1393. {
  1394. printf ("\n This commands didn't need to process!\n");
  1395. };
  1396. auto HWKV = [this] (const char * value, int length) -> void
  1397. {
  1398. assert (value);
  1399. FDEBUG("Recv KV={$}", value);
  1400. if (m_DoseUnit.m_KV->Verify(atof(value)))
  1401. {
  1402. m_DoseUnit.m_KV->Update(atof(value));
  1403. FireNotify(AttrKey::KV, value);
  1404. m_sPreAPRvalue.fKV = atof(value);
  1405. }
  1406. };
  1407. auto HWMAS = [this] (const char * value, int length)
  1408. {
  1409. assert (value);
  1410. FDEBUG("Recv MAS={$}", value);
  1411. if (m_DoseUnit.m_MAS->Verify(atof(value)))
  1412. {
  1413. m_DoseUnit.m_MAS->Update(atof(value));
  1414. FireNotify(AttrKey::MAS, value);
  1415. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_MAS)
  1416. m_sPreAPRvalue.fMAS = atof(value);
  1417. }
  1418. };
  1419. auto HWMA = [this] (const char * value, int length)
  1420. {
  1421. assert (value);
  1422. FDEBUG("Recv MA={$}", value);
  1423. if (m_DoseUnit.m_MA->Verify(atof(value)))
  1424. {
  1425. m_DoseUnit.m_MA->Update(atof(value));
  1426. FireNotify(AttrKey::MA, value);
  1427. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  1428. m_sPreAPRvalue.fMA = atof(value);
  1429. }
  1430. };
  1431. auto HWMS = [this] (const char * value, int length)
  1432. {
  1433. assert (value);
  1434. FDEBUG("Recv MS={$}", value);
  1435. if (m_DoseUnit.m_MS->Verify(atof(value)))
  1436. {
  1437. m_DoseUnit.m_MS->Update(atof(value));
  1438. FireNotify(AttrKey::MS, value);
  1439. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_V2TYPE::ET_MAS)
  1440. m_sPreAPRvalue.fMS = atof(value);
  1441. }
  1442. };
  1443. auto HWFocus = [this] (const char * value, int length)
  1444. {
  1445. assert (value);
  1446. FDEBUG("Recv FO={$}", value);
  1447. string strval = value;
  1448. if (strval.find("11") != string::npos || strval.find("20") != string::npos)
  1449. {
  1450. m_DoseUnit.m_Focus->Update(0);
  1451. }
  1452. else if (strval.find("10") != string::npos || strval.find("21") != string::npos)
  1453. {
  1454. m_DoseUnit.m_Focus->Update(1);
  1455. }
  1456. FireNotify (AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1457. if (m_DoseUnit.m_Focus->Get() == AttrKey::FOCUS_SMALL) //add by wxx for demand574
  1458. FireNotify(AttrKey::FOCUSSIZE, std::to_string(m_DoseUnit.m_FocusSmall));
  1459. else
  1460. FireNotify(AttrKey::FOCUSSIZE, std::to_string(m_DoseUnit.m_FocusLarge));
  1461. };
  1462. auto HWTechmode = [this] (const char * value, int length)
  1463. {
  1464. assert(value);
  1465. //实际发送长数据
  1466. //bool rc = false;
  1467. //int ntechmode = atoi (value);
  1468. //if (ntechmode == 2)
  1469. //{
  1470. // rc = m_DoseUnit.m_Techmode->Update(GENPARAM::ET_MAS);
  1471. //}
  1472. //else
  1473. //{
  1474. // if (m_DoseUnit.m_AECField->Get () == 0)
  1475. // rc = m_DoseUnit.m_Techmode->Update(GENPARAM::ET_TIME);
  1476. // else
  1477. // rc = m_DoseUnit.m_Techmode->Update(GENPARAM::ET_AEC);
  1478. //}
  1479. //if (rc)
  1480. // FireNotify (AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1481. // printf ("\r\n%s : %f\n", m_DoseUnit.m_Techmode->Key.c_str (), m_DoseUnit.m_Techmode->m_Val);
  1482. };
  1483. auto HWAECField = [this] (const char * value, int length)
  1484. {
  1485. int nvalue = atoi (value);
  1486. auto nToValue = m_DoseUnit.m_AECField->Get ();
  1487. switch (nvalue / 10)
  1488. {
  1489. case 0:
  1490. if (nvalue % 10 == 0)
  1491. nToValue = nToValue & 110;
  1492. else
  1493. nToValue = nToValue | 001;
  1494. break;
  1495. case 1:
  1496. if (nvalue % 10 == 0)
  1497. nToValue = nToValue & 101;
  1498. else
  1499. nToValue = nToValue | 010;
  1500. break;
  1501. case 2:
  1502. if (nvalue % 10 == 0)
  1503. nToValue = nToValue & 11;
  1504. else
  1505. nToValue = nToValue | 100;
  1506. break;
  1507. default:
  1508. break;
  1509. }
  1510. if (m_DoseUnit.m_AECField->Update (nToValue))
  1511. {
  1512. FireNotify(AttrKey::AECFIELD, value);
  1513. if(m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  1514. m_sPreAPRvalue.nAECField = nToValue;
  1515. }
  1516. };
  1517. auto HWAECFilm = [this] (const char * value, int length)
  1518. {
  1519. assert (value);
  1520. if (m_DoseUnit.m_AECFilm->Update(atoi (value)))
  1521. {
  1522. FireNotify(AttrKey::AECFILM, value);
  1523. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  1524. m_sPreAPRvalue.nAECField = atoi(value);
  1525. }
  1526. };
  1527. auto HWAECDensity = [this] (const char * value, int length)
  1528. {
  1529. assert (value);
  1530. if (atoi(value) % 10 != 0)
  1531. {
  1532. if (m_DoseUnit.m_AECDensity->Update(atoi(value) / 10 - 4))
  1533. {
  1534. FireNotify(AttrKey::AECDENSITY, m_DoseUnit.m_AECDensity->JSGet());
  1535. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_V2TYPE::ET_AEC)
  1536. m_sPreAPRvalue.nAECField = atoi(value) / 10 - 4;
  1537. }
  1538. }
  1539. };
  1540. auto HWWS = [this](const char* value, int length)
  1541. {
  1542. assert(value);
  1543. int nValue = atoi(value);
  1544. if (m_DoseUnit.m_WS->Update(nValue))
  1545. {
  1546. FireNotify(m_DoseUnit.m_WS->GetKey(), m_DoseUnit.m_WS->JSGet());
  1547. }
  1548. };
  1549. auto HWPR = [this](const char* value, int length)
  1550. {
  1551. assert(value);
  1552. int nValue = atoi(value);
  1553. if (nValue == 1)
  1554. {
  1555. m_bExpoFlag = true;
  1556. ResetEvent(m_hGenPostEvent);
  1557. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE ||
  1558. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY ||
  1559. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON)
  1560. {
  1561. FDEBUG("HWPR:GEN is already in Prep state(PR1)");
  1562. }
  1563. else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_OFF)
  1564. {
  1565. FDEBUG("HWPR:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
  1566. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1567. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1568. }
  1569. else
  1570. {
  1571. FWARN("HWPR:Wrong state change:{$} -> RAD_PREPARE(PR1)", m_DoseUnit.m_GenSynState->Get());
  1572. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1573. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1574. }
  1575. m_nSoftSynPR1Flag = true;
  1576. }
  1577. else if (nValue == 2)
  1578. {
  1579. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY ||
  1580. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON ||
  1581. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
  1582. {
  1583. FDEBUG("HWPR:GEN is already to make X-Rays(PR2)");
  1584. }
  1585. else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE)
  1586. {
  1587. FDEBUG("HWPR:PREPARE or XRAYOFF(PR1 or XR0) -> RAD_READY(PR2)");
  1588. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1589. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1590. }
  1591. else
  1592. {
  1593. FWARN("HWPR:Wrong state change:{$} -> RAD_READY(PR2)", m_DoseUnit.m_GenSynState->Get());
  1594. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1595. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1596. }
  1597. }
  1598. else
  1599. {
  1600. m_bExpoFlag = false;
  1601. FDEBUG("HWPR:GEN exit Prep state(PR0)");
  1602. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
  1603. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1604. m_nSoftSynPR1Flag = false;
  1605. }
  1606. };
  1607. auto HWXR = [this](const char* value, int length)
  1608. {
  1609. assert(value);
  1610. int nValue = atoi(value);
  1611. if (nValue == 1)
  1612. {
  1613. WaitforSELF("XR",2);
  1614. if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON)) //add by wxx for bug6079 20230915
  1615. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1616. }
  1617. else
  1618. {
  1619. m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
  1620. ProcessCommand(SpecialCMDPC); //add by wxx
  1621. //ProcessCommand("PD?",WaitForACK); //add by wxx:Not working
  1622. //ProcessCommand("PDN?",WaitForACK); //add by wxx:Not working
  1623. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1624. }
  1625. };
  1626. auto HWXS = [this](const char* value, int length)
  1627. {
  1628. assert(value);
  1629. int nValue = atoi(value);
  1630. if (nValue == 1)
  1631. {
  1632. if (m_nSoftSynPR1Flag)
  1633. {
  1634. if (m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY))
  1635. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1636. }
  1637. else
  1638. {
  1639. FWARN("HWXS:not recv PR1,need to wait PR1 to RAD_READY");
  1640. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_READY ||
  1641. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYON ||
  1642. m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF)
  1643. {
  1644. FDEBUG("HWPR:GEN is already to make X-Rays(PR2)");
  1645. }
  1646. else if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE)
  1647. {
  1648. FDEBUG("HWPR:PREPARE or XRAYOFF(PR1 or XR0) -> RAD_READY(PR2)");
  1649. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1650. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1651. }
  1652. else
  1653. {
  1654. FWARN("HWPR:Wrong state change:{$} -> RAD_READY(PR2)", m_DoseUnit.m_GenSynState->Get());
  1655. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1656. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1657. }
  1658. }
  1659. }
  1660. else
  1661. {
  1662. //if(m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF))
  1663. // FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1664. //ProcessCommand(SpecialCMDPC); //add by wxx
  1665. //ProcessCommand("PD?",WaitForACK); //add by wxx:Not working
  1666. //ProcessCommand("PDN?",WaitForACK); //add by wxx:Not working
  1667. //FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1668. }
  1669. };
  1670. auto HWRX = [this](const char* value, int length) -> void
  1671. {
  1672. assert(value);
  1673. int nValue = atoi(value);
  1674. if (nValue == 1)
  1675. {
  1676. FDEBUG("HWRX:[{$}],exp enable", nValue);
  1677. m_bExpoEnable = true;
  1678. }
  1679. else
  1680. {
  1681. FDEBUG("HWRX:[{$}],exp disable", nValue);
  1682. m_bExpoEnable = false;
  1683. }
  1684. WaitforSELF(SpecialCMDRX,2);
  1685. };
  1686. auto HWDOSE = [this](const char* value, int length) //PC:<mA> <mAs> <ms> <dose>
  1687. {
  1688. assert(value);
  1689. string strval = value;
  1690. if (length >= 13)
  1691. {
  1692. //解析Post值 aaaa bbbb ccccc aaaa postma, ccccc postms
  1693. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  1694. FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
  1695. m_DoseUnit.m_PostMA->Update(atof(strval.substr(0,4).c_str()));
  1696. FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
  1697. m_DoseUnit.m_PostMS->Update(atof(strval.substr(8, 5).c_str()));
  1698. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  1699. m_DoseUnit.m_PostMAS->Update(m_DoseUnit.m_PostMA->Get()* m_DoseUnit.m_PostMS->Get() / 1000.0);
  1700. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  1701. SetEvent(m_hGenPostEvent);
  1702. }
  1703. if (length == 19)
  1704. {
  1705. //解析DAP值 后六位ddd eff ddd*10^eff mGycm2, mGycm2/100=dGycm2
  1706. }
  1707. };
  1708. auto HWPD = [this](const char* value, int length)//add by wxx:PD:<mA> <mAs> <ms>
  1709. {
  1710. assert(value);
  1711. string strval = value;
  1712. if (length >= 13)
  1713. {
  1714. //解析Post值 aaaa bbbb ccccc aaaa postma, ccccc postms
  1715. m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
  1716. FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
  1717. m_DoseUnit.m_PostMA->Update(atof(strval.substr(0, 4).c_str()));
  1718. FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
  1719. m_DoseUnit.m_PostMS->Update(atof(strval.substr(8, 5).c_str()));
  1720. FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
  1721. m_DoseUnit.m_PostMAS->Update(m_DoseUnit.m_PostMA->Get() * m_DoseUnit.m_PostMS->Get() / 1000.0);
  1722. FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
  1723. SetEvent(m_hGenPostEvent);
  1724. }
  1725. };
  1726. auto HWERROR = [this](const char* value, int length)
  1727. {
  1728. assert(value);
  1729. int nValue = atoi(value);
  1730. if (nValue != 0)
  1731. {
  1732. if (99 == nValue)
  1733. {
  1734. char WarnCode[100]{ "" };
  1735. sprintf_s(WarnCode, "SDC_WARN_%d", nValue);
  1736. int level = 1;
  1737. m_MSGUnit->AddWarnMessage(WarnCode, level, "");
  1738. FDEBUG("HWERROR: recv ER099,try to ReSet");
  1739. ProcessCommand(SpecialCMDAR);
  1740. ProcessCommand(SpecialCMDRF);
  1741. ProcessCommand(SpecialCMDST);
  1742. ProcessCommand(SpecialCMDRX1);
  1743. }
  1744. else
  1745. {
  1746. char ErrorCode[100]{ "" };
  1747. sprintf_s(ErrorCode, "SDC_ERR_%d", nValue);
  1748. int level = 1;
  1749. m_MSGUnit->AddErrorMessage(ErrorCode, level, "");
  1750. m_sendEnable = false;//error 阶段,禁止发送指令
  1751. FDEBUG("HWERROR: [{$}] -> STATUS_ERROR", m_DoseUnit.m_GenState->Get());
  1752. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
  1753. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1754. }
  1755. }
  1756. else
  1757. {
  1758. if (99 == nValue)
  1759. {
  1760. int level = 1;
  1761. char ErrorCode[100]{ "" };
  1762. m_MSGUnit->DelWarnMessage(ErrorCode, level, "");
  1763. }
  1764. else
  1765. {
  1766. int level = 1;
  1767. char ErrorCode[100]{ "" };
  1768. m_MSGUnit->DelErrorMessage(ErrorCode, level, "");
  1769. m_sendEnable = true;
  1770. FDEBUG("HWERROR: [{$}] -> STATUS_STANDBY", m_DoseUnit.m_GenState->Get());
  1771. if (m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY))
  1772. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1773. }
  1774. }
  1775. };
  1776. auto HWAR = [this](const char* value, int length)
  1777. {
  1778. WaitforSELF(SpecialCMDAR, 2);
  1779. assert(value);
  1780. int nValue = atoi(value);
  1781. if (nValue != 0)
  1782. {
  1783. Reset();
  1784. }
  1785. };
  1786. auto HWHE = [this](const char* value, int length) -> void
  1787. {
  1788. WaitforSELF(SpecialCMDHU, 2);
  1789. assert(value);
  1790. FDEBUG("Recv HE={$}", value);
  1791. if (m_DoseUnit.m_HE->Update(atoi(value)))
  1792. FireNotify(AttrKey::TUBEHEAT, value);
  1793. };
  1794. auto HWIT = [this](const char* value, int length) -> void
  1795. {
  1796. assert(value);
  1797. FDEBUG("Recv IT={$}", value);
  1798. if (m_DoseUnit.m_KV->Update(atoi(value)))
  1799. FireNotify(AttrKey::DENHEAT, value);
  1800. };
  1801. auto HWSA = [this](const char* value, int length) -> void
  1802. {
  1803. WaitforSELF(SpecialCMDSA,2);
  1804. };
  1805. auto HWSX = [this](const char* value, int length) -> void
  1806. {
  1807. WaitforSELF(SpecialCMDSX, 2);
  1808. };
  1809. auto HWDS = [this](const char* value, int length) -> void
  1810. {
  1811. WaitforSELF(SpecialCMDDS, 2);
  1812. };
  1813. auto HWST = [this](const char* value, int length) -> void
  1814. {
  1815. FDEBUG("HWST:[{$}]", value);
  1816. WaitforSELF(SpecialCMDST, 2);
  1817. assert(value);
  1818. switch (atoi(value))
  1819. {
  1820. case 1: //1. - Initialization phase
  1821. {
  1822. FDEBUG("HWST:Initialization Phase");
  1823. if (m_DoseUnit.m_GenState->Get() < nsGEN::AttrKey::GENERATOR_STATUS_INIT)
  1824. {
  1825. FDEBUG("HWST:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
  1826. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT);
  1827. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1828. }
  1829. }
  1830. break;
  1831. case 2: //2. - Standby
  1832. {
  1833. FDEBUG("HWST:Standby");
  1834. if (m_DoseUnit.m_GenState->Get() != nsGEN::AttrKey::GENERATOR_STATUS_STANDBY)
  1835. {
  1836. FDEBUG("HWST:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1837. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1838. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1839. }
  1840. }
  1841. break;
  1842. case 3: //3. - Preparation
  1843. {
  1844. FDEBUG("HWST:Preparation");
  1845. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_OFF)
  1846. {
  1847. FDEBUG("get Gen Status_3:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
  1848. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1849. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1850. }
  1851. }
  1852. break;
  1853. case 4: //4. - Exposure
  1854. {
  1855. FDEBUG("HWST:Exposure");
  1856. //更新发生器状态并上报,否则会影响工作流 FrameEnable -> FrameReady 的转变
  1857. FDEBUG("HWST:GENSTATE {$} -> STATUS_EXP", m_DoseUnit.m_GenState->JSGet());
  1858. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
  1859. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1860. if (m_DoseUnit.m_GenSynState->Get() == nsGEN::AttrKey::GENERATOR_RAD_PREPARE)
  1861. {
  1862. FDEBUG("get Gen Status_4:PREPARE(PR1) -> RAD_READY(PR2)");
  1863. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1864. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1865. }
  1866. }
  1867. break;
  1868. case 5: //5.- Fluoro
  1869. {
  1870. FDEBUG("HWST:Fluoro");
  1871. }
  1872. break;
  1873. case 6: //6. - Filament Current Calibration
  1874. {
  1875. FDEBUG("HWST:Filament Current Calibration");
  1876. }
  1877. break;
  1878. case 7: //7. - Unrecoverable Error
  1879. {
  1880. FDEBUG("HWST:Unrecoverable Error");
  1881. FDEBUG("get Gen Status_7:GENSTATE {$} -> STATUS_ERROR", m_DoseUnit.m_GenState->JSGet());
  1882. if(m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
  1883. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1884. }
  1885. break;
  1886. case 8: //8. - Configuration
  1887. {
  1888. FDEBUG("HWST:Configuration");
  1889. }
  1890. break;
  1891. case 9: //9. - AutoCalibration
  1892. {
  1893. FDEBUG("HWST:AutoCalibration");
  1894. }
  1895. break;
  1896. case 10: //10. - Parameters Calibration
  1897. {
  1898. FDEBUG("HWST:Parameters Calibration");
  1899. }
  1900. break;
  1901. case 11: //11. - Recoverable Error
  1902. {
  1903. FDEBUG("HWST:Recoverable Error");
  1904. FDEBUG("get Gen Status_11:GENSTATE {$} -> STATUS_ERROR", m_DoseUnit.m_GenState->JSGet());
  1905. if(m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR))
  1906. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1907. }
  1908. break;
  1909. default:
  1910. FDEBUG("get Gen Status:[{$}] unknown", atoi(value));
  1911. break;
  1912. }
  1913. };
  1914. auto HWAK = [this](const char* value, int length) -> void
  1915. {
  1916. WaitforACK();
  1917. };
  1918. auto HWZCP = [this](const char* value, int length) -> void
  1919. {
  1920. WaitforCP();
  1921. };
  1922. auto HWCP = [this](const char* value, int length) -> void
  1923. {
  1924. WaitforCP();
  1925. };
  1926. // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
  1927. // 因此长的在前面, 短的在后面
  1928. // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
  1929. // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
  1930. arFrame.clear ();
  1931. arFrame.push_back (tFrameMapping ("AK", 2, HWAK));
  1932. arFrame.push_back (tFrameMapping ("ZCP", 3, HWZCP));
  1933. arFrame.push_back (tFrameMapping ("CP", 2, HWCP));
  1934. arFrame.push_back (tFrameMapping ("KV+", 3, HWNotProcess));
  1935. arFrame.push_back (tFrameMapping ("KV-", 3, HWNotProcess));
  1936. arFrame.push_back (tFrameMapping ("MA+", 3, HWNotProcess));
  1937. arFrame.push_back (tFrameMapping ("MA-", 3, HWNotProcess));
  1938. arFrame.push_back (tFrameMapping ("MS+", 3, HWNotProcess));
  1939. arFrame.push_back (tFrameMapping ("MS-", 3, HWNotProcess));
  1940. arFrame.push_back (tFrameMapping ("MX+", 3, HWNotProcess));
  1941. arFrame.push_back (tFrameMapping ("MX-", 3, HWNotProcess));
  1942. arFrame.push_back (tFrameMapping ("KVS", 3, HWKV));
  1943. arFrame.push_back (tFrameMapping ("MXS", 3, HWMAS));
  1944. arFrame.push_back (tFrameMapping ("MAS", 3, HWMA));
  1945. arFrame.push_back (tFrameMapping ("MSS", 3, HWMS));
  1946. arFrame.push_back (tFrameMapping ("KV", 2, HWKV));
  1947. arFrame.push_back (tFrameMapping ("MX", 2, HWMAS));
  1948. arFrame.push_back (tFrameMapping ("MA", 2, HWMA));
  1949. arFrame.push_back (tFrameMapping ("MS", 2, HWMS));
  1950. arFrame.push_back (tFrameMapping ("TM", 2, HWTechmode));
  1951. arFrame.push_back (tFrameMapping ("FO", 2, HWFocus));
  1952. arFrame.push_back (tFrameMapping ("FI", 2, HWAECField));
  1953. arFrame.push_back (tFrameMapping ("FS", 2, HWAECFilm));
  1954. arFrame.push_back (tFrameMapping ("FN", 2, HWAECDensity));
  1955. arFrame.push_back (tFrameMapping ("WS", 2, HWWS));
  1956. arFrame.push_back (tFrameMapping ("PR", 2, HWPR));
  1957. arFrame.push_back (tFrameMapping ("XR", 2, HWXR));
  1958. arFrame.push_back (tFrameMapping ("XS", 2, HWXS));
  1959. arFrame.push_back (tFrameMapping ("RX", 2, HWRX));
  1960. arFrame.push_back (tFrameMapping ("PC", 2, HWDOSE));
  1961. arFrame.push_back (tFrameMapping ("PD", 2, HWPD));
  1962. arFrame.push_back (tFrameMapping ("ER", 2, HWERROR));
  1963. arFrame.push_back (tFrameMapping ("AR", 2, HWAR));
  1964. arFrame.push_back (tFrameMapping ("HE", 2, HWHE));
  1965. arFrame.push_back (tFrameMapping ("IT", 2, HWIT));
  1966. arFrame.push_back (tFrameMapping ("SA", 2, HWSA));
  1967. arFrame.push_back (tFrameMapping ("SX", 2, HWSX));
  1968. arFrame.push_back (tFrameMapping ("DS", 2, HWDS));
  1969. arFrame.push_back (tFrameMapping ("ST", 2, HWST));
  1970. }
  1971. //-----------------------------------------------------------------------------
  1972. // SDCDriver
  1973. //-----------------------------------------------------------------------------
  1974. nsGEN::SDCDriver::SDCDriver ()
  1975. {
  1976. m_pAttribute.reset(new ResDataObject());
  1977. m_pDescription.reset(new ResDataObject());
  1978. }
  1979. nsGEN::SDCDriver::~SDCDriver ()
  1980. {
  1981. }
  1982. auto nsGEN::SDCDriver::CreateDevice (int index) -> std::unique_ptr <IODevice>
  1983. {
  1984. if (!m_SCF.isConnected())
  1985. return nullptr;
  1986. auto dev = std::unique_ptr <IODevice>(new IODevice(new SDCDevice(EventCenter, m_SCF,m_ConfigFileName)));
  1987. return dev;
  1988. }
  1989. void nsGEN::SDCDriver::FireNotify (int code, std::string key, std::string content)
  1990. {
  1991. EventCenter->OnNotify (code, key, content);
  1992. }
  1993. Log4CPP::Logger* gLogger = nullptr;
  1994. void nsGEN::SDCDriver::Prepare ()
  1995. {
  1996. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1997. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.SDC");
  1998. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1999. gLogger = Log4CPP::LogManager::GetLogger("GEN.SDC");
  2000. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  2001. super::Prepare ();
  2002. }
  2003. bool nsGEN::SDCDriver::Connect ()
  2004. {
  2005. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  2006. FINFO("connections:{$} \n", Connection.encode());
  2007. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::SDCDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  2008. if (erCode != SCF_ERR::SCF_SUCCEED)
  2009. return false; // erCode;
  2010. auto rc = super::Connect();
  2011. if (!rc)
  2012. return false;
  2013. //return (erCode == SCF_ERR::SCF_SUCCEED);
  2014. return true; // SCF_ERR::SCF_SUCCEED;
  2015. }
  2016. void nsGEN::SDCDriver::Disconnect()
  2017. {
  2018. super::Disconnect();
  2019. m_SCF.Disconnect();
  2020. }
  2021. bool nsGEN::SDCDriver::isConnected() const
  2022. {
  2023. return super::isConnected();
  2024. }
  2025. std::string nsGEN::SDCDriver::DriverProbe ()
  2026. {
  2027. ResDataObject r_config, HardwareInfo;
  2028. if (r_config.loadFile (m_ConfigFileName.c_str ()))
  2029. {
  2030. HardwareInfo.add ("MajorID", r_config ["CONFIGURATION"] ["MajorID"]);
  2031. HardwareInfo.add ("MinorID", r_config ["CONFIGURATION"] ["MinorID"]);
  2032. HardwareInfo.add ("VendorID", r_config ["CONFIGURATION"] ["VendorID"]);
  2033. HardwareInfo.add ("ProductID", r_config ["CONFIGURATION"] ["ProductID"]);
  2034. HardwareInfo.add ("SerialID", r_config ["CONFIGURATION"] ["SerialID"]);
  2035. }
  2036. else
  2037. {
  2038. HardwareInfo.add ("MajorID", "Generator");
  2039. HardwareInfo.add ("MinorID", "Dr");
  2040. HardwareInfo.add ("VendorID", "SDC");
  2041. HardwareInfo.add ("ProductID", "HF");
  2042. HardwareInfo.add ("SerialID", "Drv");
  2043. }
  2044. string ret = HardwareInfo.encode ();
  2045. return ret;
  2046. }
  2047. bool nsGEN::SDCDriver::GetDeviceConfig(std::string& Cfg)
  2048. {
  2049. Cfg = m_DeviceConfigSend.encode();
  2050. printf("GetDeviceConfig over , %s",Cfg.c_str());
  2051. return true;
  2052. }
  2053. bool nsGEN::SDCDriver::SetDeviceConfig(std::string Cfg)
  2054. {
  2055. FDEBUG("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  2056. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  2057. ResDataObject DeviceConfig;
  2058. DeviceConfig.decode(Cfg.c_str());
  2059. ResDataObject DescriptionTempEx;
  2060. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  2061. FDEBUG("Attribute:{$}", DescriptionTempEx.encode());
  2062. bool bSaveFile = false; //true:重新保存配置文件
  2063. string strAccess = "";
  2064. for (int i = 0; i < DescriptionTempEx.size(); i++)
  2065. {
  2066. string strKey = DescriptionTempEx.GetKey(i);
  2067. FDEBUG("{$}", strKey.c_str());
  2068. printf("%s\n", strKey.c_str());
  2069. try
  2070. {
  2071. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  2072. {
  2073. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  2074. if ("RW" == strAccess)
  2075. {
  2076. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  2077. //1. 修改内存中的值,用于给上层发消息
  2078. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  2079. //2. 拿到Innerkey
  2080. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2081. FDEBUG("nConfigInfoCount {$}", nConfigInfoCount);
  2082. string strTemp = ""; //存储AttributeKey
  2083. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2084. {
  2085. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2086. if (strTemp == strKey)
  2087. {
  2088. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2089. break;
  2090. }
  2091. }
  2092. //3. 修改配置文件中的值
  2093. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  2094. {
  2095. FDEBUG("SetDeviceConfigValue over");
  2096. bSaveFile = true;
  2097. }
  2098. }
  2099. else
  2100. {
  2101. FDEBUG("{$} is not a RW configuration item", strKey.c_str());
  2102. }
  2103. }
  2104. else
  2105. {
  2106. FDEBUG("without this attribute {$}", strKey.c_str());
  2107. }
  2108. }
  2109. catch (ResDataObjectExption& e)
  2110. {
  2111. printf("\nSetDriverConfig crashed: %s\n", e.what());
  2112. FERROR("SetDriverConfig crashed: {$}", e.what());
  2113. return false;
  2114. }
  2115. }
  2116. if (bSaveFile)
  2117. {
  2118. //3. 重新保存配置文件
  2119. SaveConfigFile(true);
  2120. }
  2121. return true;
  2122. }
  2123. bool nsGEN::SDCDriver::SaveConfigFile(bool bSendNotify)
  2124. {
  2125. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  2126. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2127. FDEBUG("SaveConfigFile over {$}", bRt);
  2128. return true;
  2129. }
  2130. bool nsGEN::SDCDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  2131. {
  2132. strValue = "";
  2133. string strTemp = pInnerKey;
  2134. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2135. {
  2136. int pos = 0;
  2137. ResDataObject resTemp = config;
  2138. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2139. {
  2140. string Key = strTemp.substr(0, pos);
  2141. string TempValue = resTemp[Key.c_str()].encode();
  2142. // printf("-TempValue=== %s", TempValue.c_str());
  2143. resTemp.clear();
  2144. resTemp.decode(TempValue.c_str());
  2145. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2146. //printf("-************--%s", strTemp.c_str());
  2147. }
  2148. if (strTemp != "")
  2149. {
  2150. strValue = (string)resTemp[strTemp.c_str()];
  2151. }
  2152. else
  2153. {
  2154. strValue = (string)resTemp;
  2155. }
  2156. }
  2157. //printf("------------%s", strValue.c_str());
  2158. return true;
  2159. }
  2160. bool nsGEN::SDCDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  2161. {
  2162. string strTemp = pInnerKey;
  2163. FDEBUG("Begin to change {$} item value to {$}", pInnerKey, szValue);
  2164. printf("bBegin to change {%s} item value to {%s}", pInnerKey, szValue);
  2165. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2166. {
  2167. try {
  2168. int pos = 0;
  2169. ResDataObject* resTemp = &config;
  2170. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2171. {
  2172. string Key = strTemp.substr(0, pos);
  2173. resTemp = &(*resTemp)[Key.c_str()];
  2174. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2175. }
  2176. if (strTemp != "")
  2177. {
  2178. //if ((strTemp.compare("WSTable") == 0) ||
  2179. // (strTemp.compare("WSWall") == 0) ||
  2180. // (strTemp.compare("WSFree") == 0) ||
  2181. // (strTemp.compare("WSTomo") == 0) ||
  2182. // (strTemp.compare("WSConventional") == 0)
  2183. // )
  2184. //{
  2185. // int sum = (*szValue) + 1;
  2186. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  2187. //}
  2188. //else
  2189. // (*resTemp)[strTemp.c_str()] = szValue;
  2190. (*resTemp)[strTemp.c_str()] = szValue;
  2191. }
  2192. else
  2193. {
  2194. *resTemp = szValue;
  2195. }
  2196. }
  2197. catch (ResDataObjectExption& e)
  2198. {
  2199. FERROR("SetDriverConfigvalue crashed: {$}", e.what());
  2200. return false;
  2201. }
  2202. }
  2203. return true;
  2204. }
  2205. std::string nsGEN::SDCDriver::GetResource()
  2206. {
  2207. ResDataObject r_config, temp;
  2208. if (!temp.loadFile(m_ConfigFileName.c_str()))
  2209. {
  2210. return "";
  2211. }
  2212. m_ConfigAll = temp;
  2213. r_config = temp["CONFIGURATION"];
  2214. m_Configurations = r_config;
  2215. ResDataObject DescriptionTemp;
  2216. ResDataObject DescriptionSend;
  2217. ResDataObject m_DescriptionSend;
  2218. ResDataObject ListTemp;
  2219. string strTemp = ""; //用于读取字符串配置信息
  2220. string strIndex = ""; //用于读取配置信息中的List项
  2221. int nTemp = -1; //用于读取整型配置信息
  2222. char sstream[10] = { 0 }; //用于转换值
  2223. string strValue = ""; //用于存储配置的值
  2224. string strType = ""; //用于存储配置的类型 int/float/string...
  2225. /***
  2226. * 1. 通过循环,将所有配置项写到pDeviceConfig
  2227. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  2228. ***/
  2229. try
  2230. {
  2231. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  2232. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2233. m_pAttribute->clear();
  2234. m_pDescription->clear();
  2235. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2236. {
  2237. DescriptionTemp.clear();
  2238. DescriptionSend.clear();
  2239. ListTemp.clear();
  2240. //AttributeType
  2241. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  2242. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2243. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  2244. strType = strTemp; //记录配置项的类型
  2245. //AttributeKey
  2246. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  2247. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2248. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  2249. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  2250. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2251. //2. 赋值
  2252. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2253. if ("int" == strType)
  2254. {
  2255. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2256. }
  2257. else if ("float" == strType)
  2258. {
  2259. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2260. }
  2261. else //其它先按string类型处理
  2262. {
  2263. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  2264. }
  2265. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  2266. //AttributeAccess
  2267. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  2268. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  2269. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  2270. /*
  2271. //AttributeRangeMin
  2272. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  2273. if (strTemp != "") //不需要的配置项为空
  2274. {
  2275. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  2276. }
  2277. //AttributeRangeMax
  2278. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  2279. if (strTemp != "") //不需要的配置项为空
  2280. {
  2281. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  2282. }
  2283. */
  2284. //AttributeList
  2285. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  2286. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  2287. {
  2288. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  2289. {
  2290. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  2291. auto temKey = std::to_string(nListIndex);
  2292. ListTemp.add(temKey.c_str(), strTemp.c_str());
  2293. }
  2294. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  2295. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  2296. }
  2297. //AttributeRequired
  2298. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  2299. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  2300. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  2301. //AttributeDefaultValue
  2302. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  2303. if (strTemp != "") //不需要的配置项为空
  2304. {
  2305. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2306. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2307. }
  2308. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2309. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  2310. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  2311. }
  2312. }
  2313. catch (ResDataObjectExption& e)
  2314. {
  2315. FERROR("Get config error: {$}", e.what());
  2316. return "";
  2317. }
  2318. ResDataObject resDeviceResource;
  2319. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2320. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  2321. ResDataObject DescriptionTempEx;
  2322. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2323. m_DeviceConfig.clear();
  2324. m_DeviceConfig = DescriptionTempEx;
  2325. FDEBUG("local ************* get resource over {$}", DescriptionTempEx.encode());
  2326. printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  2327. resDeviceResource.clear();
  2328. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2329. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  2330. DescriptionTempEx.clear();
  2331. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2332. m_DeviceConfigSend.clear();
  2333. m_DeviceConfigSend = DescriptionTempEx;
  2334. string res = m_DeviceConfigSend.encode();
  2335. //printf("%s", res.c_str());
  2336. FDEBUG("get resource over {$}", DescriptionTempEx.encode());
  2337. printf("************* get resource over %s \n", DescriptionTempEx.encode());
  2338. return res;
  2339. }
  2340. std::string nsGEN::SDCDriver::DeviceProbe ()
  2341. {
  2342. ResDataObject r_config, HardwareInfo;
  2343. if (r_config.loadFile (m_ConfigFileName.c_str ()))
  2344. {
  2345. HardwareInfo.add ("MajorID", r_config ["CONFIGURATION"] ["MajorID"]);
  2346. HardwareInfo.add ("MinorID", r_config ["CONFIGURATION"] ["MinorID"]);
  2347. HardwareInfo.add ("VendorID", r_config ["CONFIGURATION"] ["VendorID"]);
  2348. HardwareInfo.add ("ProductID", r_config ["CONFIGURATION"] ["ProductID"]);
  2349. HardwareInfo.add ("SerialID", r_config ["CONFIGURATION"] ["SerialID"]);
  2350. }
  2351. else
  2352. {
  2353. HardwareInfo.add ("MajorID", "Generator");
  2354. HardwareInfo.add ("MinorID", "Dr");
  2355. HardwareInfo.add ("VendorID", "SDC");
  2356. HardwareInfo.add ("ProductID", "HF");
  2357. HardwareInfo.add ("SerialID", "1234");
  2358. }
  2359. string ret = HardwareInfo.encode ();
  2360. return ret;
  2361. }
  2362. void nsGEN::SDCDriver::Dequeue (const char * Packet, DWORD Length)
  2363. {
  2364. FDEBUG("Dequeue:Get MSG");
  2365. DecodeFrame (Packet, Length);
  2366. }
  2367. PACKET_RET nsGEN::SDCDriver::callbackPackageProcess (const char * RecData, DWORD nLength, DWORD& PacketLength)
  2368. {
  2369. //判断是否是整包
  2370. /*
  2371. 这个是回调函数,我收到的数据会需要这个回调函数帮我判断是否是整个的包;
  2372. 如果有整个的包,返回值为true,在PacketLength处返回给我整个包的长度,我再截取后放入缓存供上层使用;
  2373. 如果缓存中的数据没有整个的数据包,那么返回false
  2374. */
  2375. if (nLength < 1)
  2376. {
  2377. printf ("nLength < 1, nLength==%d \n", nLength);
  2378. return PACKET_USELESS;
  2379. }
  2380. for (DWORD i = 0; i < nLength - 1; i++)
  2381. {
  2382. if (RecData [i] == 0x0d && RecData [i + 1] == 0x0a)
  2383. {
  2384. PacketLength = i + 2;
  2385. char strtemp [100] = { 0 };
  2386. ::memcpy(strtemp, RecData, i);
  2387. strtemp [PacketLength + 1] = 0;
  2388. //printf ("==IN ==:%s\n", strtemp);
  2389. FDEBUG("==IN==:[{$}]", strtemp);
  2390. //printf("==IN(Hex) ==:");
  2391. //for (int j = 0; j < i; j++)
  2392. //{
  2393. // printf("%02X ", RecData[j]);
  2394. //}
  2395. //printf("\n");
  2396. return PACKET_ISPACKET;
  2397. }
  2398. else if (RecData [i] == 0x03)
  2399. {
  2400. printf ("(Hex)0x03 ,len=%d \n", i);
  2401. PacketLength = i + 1;
  2402. return PACKET_USELESS;
  2403. }
  2404. }
  2405. return PACKET_NOPACKET;
  2406. }
  2407. //-----------------------------------------------------------------------------
  2408. // DecodeFrame
  2409. //-----------------------------------------------------------------------------
  2410. static bool DecodeFrame (const char* strFrame, int length)
  2411. {
  2412. auto pr = [ strFrame, length ] (const tFrameMapping& Item)
  2413. {
  2414. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  2415. {
  2416. if (strFrame [i] != Item.strHead [i])
  2417. {
  2418. return false;
  2419. }
  2420. }
  2421. return true;
  2422. };
  2423. auto found = std::find_if (arFrame.begin (), arFrame.end (), pr);
  2424. if (found == arFrame.end ())
  2425. {
  2426. return false;
  2427. }
  2428. const auto& Item = *found;
  2429. auto pc = strFrame;
  2430. pc += Item.NbOfCharOfHead;
  2431. Item.fun (pc, length - Item.NbOfCharOfHead);
  2432. return true;
  2433. }
  2434. //-----------------------------------------------------------------------------
  2435. // GetIODriver & CreateIODriver
  2436. //-----------------------------------------------------------------------------
  2437. static nsGEN::SDCDriver gIODriver;
  2438. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver () // 返回静态对象的引用, 调用者不能删除 !
  2439. {
  2440. return &gIODriver;
  2441. }
  2442. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver () // 返回新对象, 调用者必须自行删除此对象 !
  2443. {
  2444. return new nsGEN::SDCDriver ();
  2445. }