DIOS.Dev.Generator.SINO.cpp 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618
  1. // CCOS.Dev.GEN.SINO.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include <assert.h>
  5. #include <functional>
  6. using namespace std::placeholders;
  7. //#include "logger.temp.h"
  8. #include "CCOS.Dev.Generator.SINO.h"
  9. #include "Helper.JSON.hpp"
  10. using namespace CCOS::Dev::Detail::Generator;
  11. namespace nsGEN = CCOS::Dev::Detail::Generator;
  12. //关闭无关警告
  13. #pragma warning (disable:4244) // warning C4244: “初始化”: 从“double”转换到“float”,可能丢失数据
  14. #pragma warning (disable:4305) // warning C4305: “参数”: 从“double”到“float”截断
  15. #pragma warning (disable:4267) // warning C4267 : “初始化”: 从“size_t”转换到“int”,可能丢失数据
  16. #pragma warning (disable:4805) // warning C4805: “!=”: 在操作中将类型“bool”与类型“int”混合不安全
  17. //设置对应通信接口库
  18. #ifdef _WIN64
  19. #ifdef _DEBUG
  20. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
  21. #else
  22. static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
  23. #endif
  24. #endif
  25. #ifdef _WIN64
  26. #ifdef _DEBUG
  27. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
  28. #else
  29. static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
  30. #endif
  31. #endif
  32. /*
  33. #数据命令格式
  34. 字节编号 数据 数据含义 备注
  35. 1 STX 帧头 WS(程序)的帧头为:0xA5,MU(设备)的帧头为:0xCF
  36. 2 TYPE 数据类型 0x00: 主动发出的数据,0x01: 反馈数据,表示收到命令并反馈数据
  37. 3 ID 命令ID(CMD)
  38. 4 LEN 数据总长度(LEN)
  39. 5~n DATA… 参数数据
  40. n+1 CRC 异或取反校验(CRC)
  41. n+2 ETX 帧尾 WS的帧尾为:0x5A,MU的帧尾为:0xFC
  42. #应答命令格式
  43. 字节编号 数据 数据含义 备注
  44. 1 STX 帧头 WS的帧头为:0xA5,MU的帧头为:0xCF
  45. 2 TYPE 数据类型 0x02: 应答命令
  46. 3 ID 命令ID(CMD)
  47. 4 LEN 数据总长度(LEN)
  48. 5 Stauts 状态 0x00: 数据成功接收并设置, 0x01: 数据不正确,未成功设置
  49. 6 CRC 异或取反校验(CRC)
  50. 7 ETX 帧尾 WS的帧尾为:0x5A, MU的帧尾为:0xFC
  51. */
  52. //设置相关常量
  53. static const int msTimeOut_Lock = 500;
  54. Log4CPP::Logger* mLog::gLogger = nullptr;
  55. //指令操作关联结构
  56. struct tFrameMapping
  57. {
  58. static const int MaxLen = 5; //前缀不能超超过5个字符
  59. using cbFun = std::function <void(char*, int)>;
  60. char strHead[MaxLen];
  61. int NbOfCharOfHead;
  62. cbFun fun;
  63. tFrameMapping(char* str, int len, cbFun f)
  64. {
  65. assert(len < MaxLen); //len最大只能是4
  66. for (int i = 0; i < len; i++) //给strHead赋值
  67. strHead[i] = str[i];
  68. NbOfCharOfHead = len + 1;
  69. fun = f;
  70. }
  71. tFrameMapping(char str, cbFun f)
  72. {
  73. strHead[0] = str;
  74. NbOfCharOfHead = 1;
  75. fun = f;
  76. }
  77. };
  78. //响应操作对照表
  79. static std::list <tFrameMapping> arFrame;
  80. //生成命令校验和:异或取反校验为除帧尾外前面所有数据的异或取反校验
  81. char ComputeCheckSum(char* cmdData, int size)
  82. {
  83. UINT8 Checksum = 0x00;
  84. for (int i = 0; i < size-2; i++)
  85. {
  86. Checksum ^= cmdData[i]; //异或
  87. }
  88. Checksum = (~Checksum) & 0xff;; //取非
  89. return Checksum;
  90. }
  91. //查找响应操作对照表执行对应操作
  92. static bool DecodeFrame(const char* strFrame, int length)
  93. {
  94. auto pr = [strFrame, length](const tFrameMapping& Item)
  95. {
  96. //mLog::Debug("DecodeFrame[{$}][{$}]", (UINT8)strFrame[2], (UINT8)Item.strHead[0]);
  97. for (int i = 0; i < Item.NbOfCharOfHead; i++)
  98. {
  99. if ((UINT8)strFrame[i+2] != (UINT8)Item.strHead[i])
  100. {
  101. return false;
  102. }
  103. }
  104. return true;
  105. };
  106. auto found = std::find_if(arFrame.begin(), arFrame.end(), pr);//此处pr用来在arFrame中找到对于的包头
  107. if (found == arFrame.end())
  108. {
  109. return false;
  110. }
  111. const auto& Item = *found;
  112. auto pc = strFrame;
  113. char data[SINO_Com_NormalLen] = { 0 };
  114. //memcpy(data, strFrame + Item.NbOfCharOfHead + 3, length - Item.NbOfCharOfHead - 3);
  115. memcpy(data, strFrame, length);
  116. data[3] = length;
  117. Item.fun(data, length - Item.NbOfCharOfHead);//第二个参数 不重要
  118. if ((UINT8)strFrame[1] != (UINT8)SINO_TYPE_CONFIRM)
  119. {
  120. arFrame.begin()->fun(data, length - Item.NbOfCharOfHead);//统一响应操作
  121. }
  122. return true;
  123. }
  124. //-----------------------------------------------------------------------------
  125. // SINODevice
  126. //-----------------------------------------------------------------------------
  127. //暂无取固定值的使用要求
  128. 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 };
  129. 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 };
  130. 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 };
  131. int g_AECFIELD_List[] = { 1, 10, 100, 11, 101, 111 };
  132. int nsGEN::SINODevice::m_iLoopTime = 1000;
  133. nsGEN::SINODevice::SINODevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
  134. {
  135. assert(EventCenter);
  136. //其余属性初始化
  137. ResDataObject temp;
  138. temp.loadFile(configfile.c_str());
  139. m_GenConfig = temp["CONFIGURATION"];
  140. TransJsonText(m_GenConfig);
  141. m_pHardwareStatusThread = NULL;
  142. m_bExpEnable = false;
  143. m_iHeartBeats = 0;
  144. m_bConnectFlag = true;
  145. m_pMechDev = nullptr;
  146. m_pCollDev = nullptr;
  147. string version;
  148. if(GetVersion(version,m_GenConfig))
  149. mLog::Info("\n===============log begin : version:{$} ===================\n", version.c_str());
  150. else
  151. mLog::Info("\n===============log begin : version:0.0.0.0 ===================\n");
  152. //设置发生器属性集合各个值的范围及精度
  153. m_DoseUnit.m_KV.reset(new KVMould(10.0, 10.0, 35.0, 1.0));
  154. m_DoseUnit.m_MA.reset(new MAMould(1.0, 0.0, 200.0, 0.1));
  155. m_DoseUnit.m_MS.reset(new MSMould(20.0, 20.0, 12000.0, 0.01));
  156. m_DoseUnit.m_MAS.reset(new MASMould(10.0, 10.0, 600.0, 1.0));
  157. m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_AEC_2P, 1));
  158. m_DoseUnit.m_WS.reset(new WORKSTATIONMould(1, 0, 5, 1));
  159. m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_TYPE::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
  160. m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
  161. m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 2, 1));
  162. m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
  163. m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
  164. m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
  165. m_DoseUnit.m_GenState.reset(new GENSTATEMould(0, SINO_STATUS_PowerOn, SINO_STATUS_Error, 1));
  166. m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
  167. m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
  168. m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
  169. m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
  170. m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
  171. m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
  172. m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 16, 1));
  173. m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
  174. m_DoseUnit.m_BatteryChargeState.reset(new BATTERYCHARGSTATEMould(0, 0, 1, 1));
  175. //m_DoseUnit.m_EXAMMode.reset(new EXAMMODEMould(EXAMMODE_TYPE::MANUAL));
  176. //实际曝光参数值
  177. m_DoseUnit.m_PostKV.reset(new POSTKVMould(0.0, 0.0, 40.0, 1.0));
  178. m_DoseUnit.m_PostMA.reset(new POSTMAMould(0.0, 0.0, 200.0, 0.1));
  179. m_DoseUnit.m_PostMS.reset(new POSTMSMould(0.0, 20.0, 12000.0, 0.01));
  180. m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.0, 0.0, 600.0, 0.01));
  181. //发生器告警及错误消息
  182. m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
  183. //配置响应操作对照表 供发生器回传的数据触发相应的操作
  184. OnCallBack();
  185. //将发生器可以对外提供的指令注册集进行补充
  186. Register();
  187. //重置发生器
  188. Reset();
  189. Sleep(500);
  190. //以下进行默认设置,需要注意默认值是否正确
  191. //刷新数据
  192. RefreshData();
  193. //启动硬件转状态查询进程
  194. StartHardwareStatusThread();
  195. }
  196. nsGEN::SINODevice::~SINODevice()
  197. {
  198. mLog::Info("\n===============log end ===================\n");
  199. //ReleaseLogger();
  200. if (m_pHardwareStatusThread != NULL)
  201. {
  202. DWORD dwExitCode = 0;
  203. GetExitCodeThread(m_pHardwareStatusThread, &dwExitCode);
  204. if (STILL_ACTIVE != dwExitCode)
  205. {
  206. TerminateThread(m_pHardwareStatusThread, 0);
  207. }
  208. m_pHardwareStatusThread = NULL;
  209. }
  210. //m_pMechDev.reset();
  211. }
  212. std::string nsGEN::SINODevice::GetGUID() const
  213. {
  214. mLog::Info("===============GetGUID : {$} ===================\n", GeneratorUnitType);
  215. return GeneratorUnitType;
  216. }
  217. void nsGEN::SINODevice::Register()
  218. {
  219. auto Disp = &Dispatch;
  220. superGen::Register(Disp);
  221. superGen::RegisterRAD(Disp);
  222. superGen::RegisterAEC(Disp);
  223. superGen::RegisterExpEnable(Disp);
  224. superGen::RegisterGeneratortoSyncStatus(Disp);
  225. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  226. auto fun_Clear_DAP = [this](auto a, auto&)
  227. {
  228. return Clear_DAP();
  229. };
  230. Disp->Action.Push("Clear_DAP", fun_Clear_DAP);
  231. auto fun_GetValue_DAP = [this](auto a, auto& b)
  232. {
  233. float value = 0;
  234. RET_STATUS ret = GetValue_DAP(value);
  235. b = ToJSON(value);
  236. return ret;
  237. };
  238. Disp->Action.Push("GetValue_DAP", fun_GetValue_DAP);
  239. #if 0
  240. auto fun_StartMove = [this](auto a,auto& b)
  241. {
  242. return StartMove();
  243. };
  244. Disp->Action.Push("StartMove", fun_StartMove);
  245. auto fun_EndMove = [this](auto a, auto& b)
  246. {
  247. return EndMove();
  248. };
  249. Disp->Action.Push("EndMove", fun_EndMove);
  250. #endif // 0
  251. }
  252. RET_STATUS nsGEN::SINODevice::SetAPRMaMmo(int nKV, float fMAS, int nFO, int nET)
  253. {
  254. mLog::Debug("SetAPRMaMmo:nKV[{$}],MAS[{$}],FO[{$}],ET[{$}] ", nKV, fMAS, nFO, nET);
  255. SINOCommand strCmd(SINO_ExpoParam, SINO_TYPE_SEND,11);
  256. strCmd.SetAt(5, nKV);
  257. int nmAs = (int)fMAS;
  258. char nmAs_Low = nmAs & (0xFF);
  259. strCmd.SetAt(6, nmAs_Low);
  260. char nmAs_High = nmAs >> 8;
  261. strCmd.SetAt(7, nmAs_High);
  262. if(1)
  263. strCmd.SetAt(8, EM_Focus_Large);
  264. else
  265. strCmd.SetAt(8, EM_Focus_Small);
  266. if (nET == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_1P ||
  267. nET == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  268. nET == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P)
  269. {
  270. mLog::Error("SetAPRMaMmo:can not set TECHMODE[{$}] \n", nET);
  271. }
  272. else
  273. {
  274. if (nET == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  275. {
  276. strCmd.SetAt(9, EM_EXPMode_MAN);
  277. }
  278. if (nET == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  279. {
  280. strCmd.SetAt(9, EM_EXPMode_AEC);
  281. }
  282. }
  283. return HWSend(strCmd);
  284. }
  285. RET_STATUS nsGEN::SINODevice::IncKV()
  286. {
  287. if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
  288. float oldKV= m_DoseUnit.m_KV->Get();
  289. oldKV++;
  290. return SetAPRMaMmo(oldKV, m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get());
  291. }
  292. RET_STATUS nsGEN::SINODevice::DecKV()
  293. {
  294. if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
  295. float oldKV = m_DoseUnit.m_KV->Get();
  296. oldKV--;
  297. return SetAPRMaMmo(oldKV, m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get());
  298. }
  299. RET_STATUS nsGEN::SINODevice::SetKV(float value)
  300. {
  301. if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
  302. return SetAPRMaMmo(value, m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get());
  303. }
  304. RET_STATUS nsGEN::SINODevice::IncMAS()
  305. {
  306. if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
  307. float oldMAS = m_DoseUnit.m_MAS->Get();
  308. oldMAS++;
  309. return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), oldMAS, m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get());
  310. }
  311. RET_STATUS nsGEN::SINODevice::DecMAS()
  312. {
  313. if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
  314. float oldMAS = m_DoseUnit.m_MAS->Get();
  315. oldMAS--;
  316. return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), oldMAS, m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get());
  317. }
  318. RET_STATUS nsGEN::SINODevice::SetMAS(float value)
  319. {
  320. if (!m_DoseUnit.m_MAS->Verify(value)) return RET_STATUS::RET_SUCCEED;
  321. return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), value, m_DoseUnit.m_Focus->Get(), m_DoseUnit.m_Techmode->Get());
  322. }
  323. RET_STATUS nsGEN::SINODevice::SetTechmode(int value)
  324. {
  325. if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
  326. mLog::Info("SetTechmode [{$}] \n", value);
  327. if (value == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P ||
  328. value == AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  329. {
  330. return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MAS->Get(), m_DoseUnit.m_Focus->Get(), value);
  331. }
  332. else
  333. {
  334. mLog::Error("SetTechmode:unknown mode[{$}] \n", value);
  335. }
  336. return RET_STATUS::RET_SUCCEED;
  337. }
  338. RET_STATUS nsGEN::SINODevice::SetEXAMMode(std::string value)
  339. {
  340. //上层给我设置exam mode。(manual semi atuo)对应(NoAEC2Point AEC2Point AEC2Point)
  341. mLog::Info("Enter setexammode func value = {$}\n", value);
  342. if (value == AttrKey::EXAMMODE_TYPE::MANUAL)
  343. {
  344. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  345. {
  346. SetTechmode(1);
  347. }
  348. }
  349. else if (value == AttrKey::EXAMMODE_TYPE::SEMIAUTO)
  350. {
  351. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  352. {
  353. SetTechmode(3);
  354. }
  355. }
  356. else if (value == AttrKey::EXAMMODE_TYPE::AUTOMATIC)
  357. {
  358. if (m_DoseUnit.m_Techmode->Get() != AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P)
  359. {
  360. SetTechmode(3);
  361. }
  362. }
  363. return RET_STATUS::RET_SUCCEED;
  364. }
  365. RET_STATUS nsGEN::SINODevice::SetFocus(int value)
  366. {
  367. if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
  368. return SetAPRMaMmo(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MAS->Get(), value, m_DoseUnit.m_Techmode->Get());
  369. }
  370. RET_STATUS nsGEN::SINODevice::SetAECDensity(int value) //发生器无此设置
  371. {
  372. if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
  373. #if 0
  374. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  375. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  376. {
  377. mLog::Info("Techmode is not AEC, Cannot set Density \n");
  378. return RET_STATUS::RET_FAILED;
  379. }
  380. #endif // 0
  381. m_DoseUnit.m_AECDensity->Update(value);
  382. return RET_STATUS::RET_SUCCEED;
  383. }
  384. RET_STATUS nsGEN::SINODevice::SetAECField(int value) //发生器无此设置
  385. {
  386. if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
  387. #if 0
  388. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  389. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  390. {
  391. mLog::Info("Techmode is not AEC, Cannot set Field \n");
  392. return RET_STATUS::RET_FAILED;
  393. }
  394. #endif // 0
  395. m_DoseUnit.m_AECField->Update(value);
  396. return RET_STATUS::RET_SUCCEED;
  397. }
  398. RET_STATUS nsGEN::SINODevice::SetAECFilm(int value) //发生器无此设置
  399. {
  400. if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
  401. #if 0
  402. if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_3P ||
  403. m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P)
  404. {
  405. mLog::Info("Techmode is not AEC, Cannot set Film \n");
  406. return RET_STATUS::RET_FAILED;
  407. }
  408. #endif // 0
  409. m_DoseUnit.m_AECFilm->Update(value);
  410. return RET_STATUS::RET_SUCCEED;
  411. }
  412. RET_STATUS nsGEN::SINODevice::SetWS(const string value) //发生器无此设置
  413. {
  414. mLog::Info("Enter SetWS {$}", value);
  415. int tempws = 0;
  416. if (value == "Table") tempws = (int)m_GenConfig["WSTable"];
  417. else if (value == "Wall") tempws = (int)m_GenConfig["WSWall"];
  418. else if (value == "Direct") tempws = (int)m_GenConfig["WSConventional"];
  419. else if (value == "Free") tempws = (int)m_GenConfig["WSFree"];
  420. else if (value == "Tomo") tempws = (int)m_GenConfig["WSTomo"];
  421. m_DoseUnit.m_WS->Update(tempws);
  422. return RET_STATUS::RET_SUCCEED;
  423. }
  424. RET_STATUS nsGEN::SINODevice::SetAPR(const _tAPRArgs& t)
  425. {
  426. mLog::Info("APR:KV={$},MA={$},MS={$},MAS={$},Focus={$},Techmode={$},WS={$},AECDensity={$},AECField={$},AECFilm={$}",t.fKV, t.fMA, t.fMS, t.fMAS, t.nFocus, t.nTechmode, t.nWS, t.nAECDensity, t.nAECField, t.nAECFilm);
  427. if (!m_DoseUnit.m_KV->Verify(t.fKV))
  428. {
  429. mLog::Error("SetAPR:KV Out of bounds[{$}] \n", t.fKV);
  430. }
  431. else if (!m_DoseUnit.m_MA->Verify(t.fMA))
  432. {
  433. mLog::Error("SetAPR:MA Out of bounds[{$}] \n", t.fMA);
  434. }
  435. else if (!m_DoseUnit.m_MS->Verify(t.fMS))
  436. {
  437. mLog::Error("SetAPR:MS Out of bounds[{$}] \n", t.fMS);
  438. }
  439. else if (!m_DoseUnit.m_MAS->Verify(t.fMAS))
  440. {
  441. mLog::Error("SetAPR:MAS Out of bounds[{$}] \n", t.fMAS);
  442. }
  443. else if (!m_DoseUnit.m_Focus->Verify(t.nFocus))
  444. {
  445. mLog::Error("SetAPR:Focus Out of bounds[{$}] \n", t.nFocus);
  446. }
  447. else
  448. {
  449. SetAPRMaMmo(t.fKV, t.fMAS, t.nFocus, t.nTechmode);
  450. }
  451. m_DoseUnit.m_WS->Update(t.nWS);
  452. SetAECDensity(t.nAECDensity);
  453. SetAECField(t.nAECField);
  454. SetAECFilm(t.nAECFilm);
  455. return RET_STATUS::RET_SUCCEED;
  456. }
  457. RET_STATUS nsGEN::SINODevice::QueryHE(int& value) //实际为主动上报
  458. {
  459. //value = m_DoseUnit.m_HE->Get();
  460. return RET_STATUS::RET_SUCCEED;
  461. }
  462. RET_STATUS nsGEN::SINODevice::RefreshData() //发生器无此设置
  463. {
  464. mLog::Debug("RefreshData: get System power on status \n");
  465. SINOCommand strCmd(SINO_ComInquiry, SINO_TYPE_SEND, 7);
  466. strCmd.SetAt(5, EM_ComInquiry_PowerOn);
  467. return HWSend(strCmd);
  468. }
  469. RET_STATUS nsGEN::SINODevice::SetExpEnable()
  470. {
  471. SINOCommand strCmd(SINO_DataQuery, SINO_TYPE_SEND, 7);
  472. strCmd.SetAt(5, EM_Query_READY);
  473. return HWSend(strCmd);
  474. }
  475. RET_STATUS nsGEN::SINODevice::SetExpDisable()
  476. {
  477. SINOCommand strCmd(SINO_DataQuery, SINO_TYPE_SEND, 7);
  478. strCmd.SetAt(5, EM_Query_NOREADY);
  479. return HWSend(strCmd);
  480. }
  481. RET_STATUS nsGEN::SINODevice::QueryPostKV(float& value) //实际为主动上报
  482. {
  483. if (m_DoseUnit.m_PostKV->Get() > 0)
  484. {
  485. value = m_DoseUnit.m_PostKV->Get();
  486. }
  487. return RET_STATUS::RET_SUCCEED;
  488. }
  489. RET_STATUS nsGEN::SINODevice::QueryPostMA(float& value) //实际为主动上报
  490. {
  491. if (m_DoseUnit.m_PostMA->Get() > 0)
  492. {
  493. value = m_DoseUnit.m_PostMA->Get();
  494. }
  495. return RET_STATUS::RET_SUCCEED;
  496. }
  497. RET_STATUS nsGEN::SINODevice::QueryPostMS(float& value) //实际为主动上报
  498. {
  499. if (m_DoseUnit.m_PostMS->Get() > 0)
  500. {
  501. value = m_DoseUnit.m_PostMS->Get();
  502. }
  503. return RET_STATUS::RET_SUCCEED;
  504. }
  505. RET_STATUS nsGEN::SINODevice::QueryPostMAS(float& value) //实际为主动上报
  506. {
  507. if (m_DoseUnit.m_PostMAS->Get() > 0)
  508. {
  509. value = m_DoseUnit.m_PostMAS->Get();
  510. }
  511. return RET_STATUS::RET_SUCCEED;
  512. }
  513. RET_STATUS nsGEN::SINODevice::IncMA()
  514. {
  515. return RET_STATUS::RET_SUCCEED;
  516. }
  517. RET_STATUS nsGEN::SINODevice::DecMA()
  518. {
  519. return RET_STATUS::RET_SUCCEED;
  520. }
  521. RET_STATUS nsGEN::SINODevice::SetMA(float value)
  522. {
  523. return RET_STATUS::RET_SUCCEED;
  524. }
  525. RET_STATUS nsGEN::SINODevice::IncMS()
  526. {
  527. return RET_STATUS::RET_SUCCEED;
  528. }
  529. RET_STATUS nsGEN::SINODevice::DecMS()
  530. {
  531. return RET_STATUS::RET_SUCCEED;
  532. }
  533. RET_STATUS nsGEN::SINODevice::SetMS(float value)
  534. {
  535. return RET_STATUS::RET_SUCCEED;
  536. }
  537. RET_STATUS nsGEN::SINODevice::Clear_DAP() //发生器无此设置
  538. {
  539. return RET_STATUS::RET_SUCCEED;
  540. }
  541. RET_STATUS nsGEN::SINODevice::GetValue_DAP(float& value) //发生器无此设置
  542. {
  543. //value = m_DAP->Get();
  544. return RET_STATUS::RET_SUCCEED;
  545. }
  546. RET_STATUS nsGEN::SINODevice::StartMove() //发生器无此设置
  547. {
  548. return RET_STATUS::RET_SUCCEED;
  549. }
  550. RET_STATUS nsGEN::SINODevice::EndMove() //发生器无此设置
  551. {
  552. return RET_STATUS::RET_SUCCEED;
  553. }
  554. RET_STATUS nsGEN::SINODevice::SetGenSynState(int value) //仅供Demo测试
  555. {
  556. m_DoseUnit.m_GenSynState->Update(value);
  557. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  558. return RET_STATUS::RET_SUCCEED; //发生器的所有状态只能主动查询,设备不会主动上报,所以可能无法软同步
  559. }
  560. RET_STATUS nsGEN::SINODevice::SetGenState(int value) //发生器无此设置
  561. {
  562. return RET_STATUS::RET_SUCCEED;
  563. }
  564. RET_STATUS nsGEN::SINODevice::SetExpMode(std::string value) //发生器无此设置
  565. {
  566. mLog::Info("Enter SetExpMode...{$} \n",value);
  567. m_DoseUnit.m_ExpMode->Update(value);
  568. return RET_STATUS::RET_SUCCEED;
  569. }
  570. RET_STATUS nsGEN::SINODevice::SetFLFMode(std::string value) //发生器无此设置
  571. {
  572. return RET_STATUS::RET_SUCCEED;
  573. }
  574. RET_STATUS nsGEN::SINODevice::SetFrameRate(FLOAT frameRate) //发生器无此设置
  575. {
  576. m_DoseUnit.m_FrameRate->Update(frameRate);
  577. return RET_STATUS::RET_SUCCEED;
  578. }
  579. RET_STATUS nsGEN::SINODevice::SetRPS(int rps) //发生器无此设置
  580. {
  581. return RET_STATUS::RET_SUCCEED;
  582. }
  583. //为了将gen和其他设备关联,能相互调用接口
  584. RET_STATUS nsGEN::SINODevice::SetGrid(int nGridType)
  585. {
  586. mLog::Debug("Enter SetGrid[{$}]", nGridType);
  587. if (m_pMechDev)
  588. m_pMechDev->UpdateGrid(0);
  589. return RET_STATUS::RET_SUCCEED;
  590. }
  591. RET_STATUS nsGEN::SINODevice::SetFilter(int nFilterType)
  592. {
  593. if (m_pMechDev)
  594. {
  595. m_pMechDev->UpdateMammo_FT(nFilterType);
  596. }
  597. if (m_pCollDev)
  598. {
  599. m_pCollDev->UpdateCollimatorFilter(nFilterType);
  600. }
  601. SINOCommand strCmd(SINO_DataQuery, SINO_TYPE_SEND, 7);
  602. strCmd.SetAt(5, EM_Query_STATUS);
  603. return HWSend(strCmd);
  604. }
  605. RET_STATUS nsGEN::SINODevice::SetAutoTracking(int nAutoTracking)
  606. {
  607. mLog::Debug("Enter SetAutoTracking[{$}]", nAutoTracking);
  608. if (m_pMechDev)
  609. m_pMechDev->UpdateMammo_Depress(nAutoTracking);
  610. SINOCommand strCmd(SINO_Compressor, SINO_TYPE_SEND, 11);
  611. strCmd.SetAt(9, nAutoTracking);
  612. return HWSend(strCmd);
  613. }
  614. RET_STATUS nsGEN::SINODevice::GetTomoResults(ResDataObject& resultAngle, ResDataObject& resultHeight)
  615. {
  616. mLog::Debug("Enter GetTomoResults");
  617. return RET_STATUS::RET_SUCCEED;
  618. }
  619. RET_STATUS nsGEN::SINODevice::SetMechDev(OemMechanical* dev)
  620. {
  621. if (dev)
  622. m_pMechDev.reset(dev);
  623. return RET_STATUS::RET_SUCCEED;
  624. }
  625. RET_STATUS nsGEN::SINODevice::SetCollimatorDev(OemCollimator* dev)
  626. {
  627. if (dev)
  628. m_pCollDev.reset(dev);
  629. return RET_STATUS::RET_SUCCEED;
  630. }
  631. RET_STATUS nsGEN::SINODevice::SetCollimatorSize(int xsize, int ysize)
  632. {
  633. if (m_pCollDev)
  634. {
  635. m_pCollDev->UpdateCollimatorXSize(xsize);
  636. m_pCollDev->UpdateCollimatorYSize(ysize);
  637. }
  638. return RET_STATUS::RET_SUCCEED;
  639. }
  640. RET_STATUS nsGEN::SINODevice::SetCollimatorLight(WORD pParams)
  641. {
  642. //此处应该发送指令给GEN,并且该指令可以控制 coll 的LED
  643. return RET_STATUS::RET_SUCCEED;
  644. }
  645. RET_STATUS nsGEN::SINODevice::Reset()
  646. {
  647. mLog::Debug("clear all errors \n");
  648. int level = 0;
  649. m_MSGUnit->DelErrorMessage("0", level, "clear all errors");
  650. SINOCommand strCmd(SINO_SystemWarning, SINO_TYPE_SEND, 7);
  651. strCmd.SetAt(5, EM_SysWarn018);
  652. return HWSend(strCmd);
  653. }
  654. RET_STATUS nsGEN::SINODevice::HWSend(SINOCommand& strCommand, int nTimeOut)
  655. {
  656. std::unique_lock<std::mutex> uqeConnectFlag(mtxConnectFlag);
  657. if (!m_bConnectFlag)
  658. {
  659. mLog::Error("==OUT==: not Connect,[{$}] send failed \n", strCommand.Get_Hex_Log());
  660. //uqeConnectFlag.unlock();
  661. return RET_STATUS::RET_FAILED;
  662. }
  663. uqeConnectFlag.unlock();
  664. if (!m_SCF) return RET_STATUS::RET_FAILED;
  665. strCommand.SetCRC(ComputeCheckSum);
  666. mLog::Info("==OUT==: [{$}] \n", strCommand.Get_Hex_Log());
  667. int retLength;
  668. m_SCF.Lock(msTimeOut_Lock)
  669. .SendPacket(strCommand, strCommand[3], nTimeOut, retLength);
  670. Sleep(nTimeOut);
  671. return RET_STATUS::RET_SUCCEED;
  672. }
  673. //-----------------------------------------------------------------------------
  674. // ProcessCmd
  675. //-----------------------------------------------------------------------------
  676. void nsGEN::SINODevice::FireNotify(std::string key, std::string content)
  677. {
  678. EventCenter->OnNotify(1, key, content);
  679. }
  680. void nsGEN::SINODevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  681. {
  682. char ErrorCode[20] = {0};
  683. sprintf_s(ErrorCode, "SINO_ERR_%03d", Code);
  684. int level = SINO_REGULATION_LEVEL::REG_ERRO;
  685. if (Act)
  686. {
  687. mLog::Error("add {$}:{$}", ErrorCode, ResInfo);
  688. m_MSGUnit->AddErrorMessage(ErrorCode, level, ResInfo);
  689. }
  690. else
  691. {
  692. mLog::Error("del {$}:{$}", ErrorCode, ResInfo);
  693. m_MSGUnit->DelErrorMessage(ErrorCode, level, ResInfo);
  694. }
  695. }
  696. void nsGEN::SINODevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
  697. {
  698. char ErrorCode[20] = { 0 };
  699. sprintf_s(ErrorCode, "SINO_WAR_%03d", Code);
  700. int level = SINO_REGULATION_LEVEL::REG_WARN;
  701. if (Act)
  702. {
  703. mLog::Error("add {$}:{$}", ErrorCode, ResInfo);
  704. m_MSGUnit->AddWarnMessage(ErrorCode, level, ResInfo);
  705. }
  706. else
  707. {
  708. mLog::Error("del {$}:{$}", ErrorCode, ResInfo);
  709. m_MSGUnit->DelWarnMessage(ErrorCode, level, ResInfo);
  710. }
  711. }
  712. void nsGEN::SINODevice::OnCallBack()
  713. {
  714. //无 操作
  715. auto HWNotProcess = [this](const char* value, int length) -> void
  716. {
  717. mLog::Info("\n This commands didn't need to process!");
  718. };
  719. //响应操作
  720. auto CallbackACK = [this](const char* value, int length) -> void
  721. {
  722. if (value[2] == SINO_SystemStatus)
  723. {
  724. SINOCommand strCmd(value[2], SINO_TYPE_CONFIRM, 6);
  725. HWSend(strCmd);
  726. }
  727. else
  728. {
  729. SINOCommand strCmd(value[2], SINO_TYPE_CONFIRM, 7);
  730. strCmd.SetAt(5, SINO_CONFIRM_OK);
  731. HWSend(strCmd);
  732. }
  733. };
  734. //命令模式:用于正常操作
  735. auto CallbackExpoParam = [this](const char* value, int length) -> void
  736. {
  737. #if 0
  738. SINOCommand ExposureParam(value);
  739. //KV
  740. int nKV = ExposureParam.GetAt(5);
  741. mLog::Debug("get CurrtSetKV [{$}]", nKV);
  742. m_DoseUnit.m_KV->Update(nKV);
  743. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  744. //MAS
  745. float fMAS = 0;
  746. if (ExposureParam.GetAt(7) == 0xFF)
  747. {
  748. fMAS = ExposureParam.GetAt(6);
  749. }
  750. else
  751. {
  752. fMAS = (ExposureParam.GetAt(7) << 8) + ExposureParam.GetAt(6);
  753. }
  754. mLog::Debug("get CurrtSetMS [{$}]", fMAS);
  755. m_DoseUnit.m_MAS->Update(fMAS);
  756. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  757. //Focus
  758. int nFO = 0;
  759. switch (ExposureParam.GetAt(8))
  760. {
  761. case EM_Focus_Large:
  762. mLog::Debug("get CurrtFocus [Small]");
  763. nFO = AttrKey::FOCUS_TYPE::FOCUS_LARGE;
  764. break;
  765. case EM_Focus_Small:
  766. mLog::Debug("get CurrtFocus [Large]");
  767. nFO = AttrKey::FOCUS_TYPE::FOCUS_SMALL;
  768. break;
  769. default:
  770. mLog::Debug("==CallbackExposureParam==: Get other Focus value!");
  771. break;
  772. }
  773. if (m_DoseUnit.m_Focus->Update(nFO))
  774. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  775. //Techmode
  776. int nET = 0;
  777. switch (ExposureParam.GetAt(9))
  778. {
  779. case EM_EXPMode_MAN:
  780. nET = AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P;
  781. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  782. break;
  783. case EM_EXPMode_AEC:
  784. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  785. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  786. break;
  787. case EM_EXPMode_Opdose:
  788. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  789. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  790. break;
  791. default:
  792. mLog::Debug("==CallbackExposureParam==: Get other Techmode value!");
  793. break;
  794. }
  795. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  796. mLog::Debug("==CallbackExposureParam==: KV: [{$}], MAS:[{$}], Focus: [{$}], TechMode: [{$}]", nKV, fMAS, nFO, nET);
  797. #else
  798. SINOCommand strCmd(SINO_DataQuery, SINO_TYPE_SEND, 7);
  799. strCmd.SetAt(5, EM_Query_STATUS);
  800. HWSend(strCmd);
  801. #endif
  802. };
  803. auto CallbackPosition = [this](const char* value, int length) -> void
  804. {
  805. SINOCommand Position(value);
  806. float fAngle = 0, fHeight = 0;
  807. //Angle
  808. if (Position.GetAt(6) == 0xFF)
  809. {
  810. fAngle = (float)(Position.GetAt(5)) / 10.0f;
  811. }
  812. else
  813. {
  814. fAngle = (float)((Position.GetAt(6) << 8) + Position.GetAt(5)) / 10.0f;
  815. }
  816. fAngle = 180 - fAngle;
  817. if (m_pMechDev)
  818. m_pMechDev->UpdateMammo_MechAngle(fAngle);
  819. //Height
  820. if (Position.GetAt(8) == 0xFF)
  821. {
  822. fHeight = Position.GetAt(7);
  823. }
  824. else
  825. {
  826. fHeight = (Position.GetAt(8) << 8) + Position.GetAt(7);
  827. }
  828. if (m_pMechDev)
  829. m_pMechDev->UpdateMammo_MechHeight(fHeight);
  830. mLog::Debug("==CallbackPosition==: Angle:[{$}], Height:[{$}]", fAngle, fHeight);
  831. };
  832. auto CallbackCompressor = [this](const char* value, int length) -> void
  833. {
  834. SINOCommand Compressor(value);
  835. float fPressure = 0;
  836. int nBreastThickness = 0, nPaddle_Type = 0, nDe_comp = 0;
  837. //BreastThickness
  838. if (Compressor.GetAt(6) == 0xFF)
  839. {
  840. nBreastThickness = Compressor.GetAt(5);
  841. }
  842. else
  843. {
  844. nBreastThickness = (Compressor.GetAt(6) << 8) + Compressor.GetAt(5);
  845. }
  846. if (m_pMechDev)
  847. m_pMechDev->UpdateMammo_PressureState(nBreastThickness);
  848. //pressure
  849. if (Compressor.GetAt(7) == 0xFF)
  850. {
  851. fPressure = 0;
  852. }
  853. else
  854. {
  855. fPressure = Compressor.GetAt(7);
  856. }
  857. if (m_pMechDev)
  858. m_pMechDev->UpdateMammo_PressureValue(fPressure);
  859. //Paddle Type
  860. if (Compressor.GetAt(8) == 0xFF)
  861. {
  862. nPaddle_Type = 0;
  863. }
  864. else
  865. {
  866. nPaddle_Type = Compressor.GetAt(8);
  867. }
  868. //De-comp
  869. if (Compressor.GetAt(9) == 0xFF)
  870. {
  871. nDe_comp = 0;
  872. }
  873. else
  874. {
  875. nDe_comp = Compressor.GetAt(9);
  876. }
  877. if (m_pMechDev)
  878. m_pMechDev->UpdateMammo_Depress(nDe_comp);
  879. mLog::Debug("==CallbackCompressor==: BreastThickness: [{$}], Pressure:[{$}] N,Paddle_Type:[{$}],De_comp:[{$}]", nBreastThickness, fPressure, nPaddle_Type, nDe_comp);
  880. };
  881. auto CallbackCollimator = [this](const char* value, int length) -> void
  882. {
  883. SINOCommand Collimator(value);
  884. //Filter
  885. int nFilter = 0;
  886. if (Collimator.GetAt(5) == 0xFF)
  887. {
  888. nFilter = EM_Mo_Filtration;
  889. }
  890. else
  891. {
  892. nFilter = Collimator.GetAt(5);
  893. }
  894. if(m_pMechDev)
  895. m_pMechDev->UpdateMammo_FT(nFilter);
  896. mLog::Debug("==CallbackCollimator==: filter: [{$}]", nFilter);
  897. };
  898. auto CallbackExposureParam = [this](const char* value, int length) -> void
  899. {
  900. SINOCommand ExposureParam(value);
  901. //KV
  902. int nKV = ExposureParam.GetAt(5);
  903. mLog::Debug("get CurrtSetKV [{$}]", nKV);
  904. m_DoseUnit.m_KV->Update(nKV);
  905. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  906. //MAS
  907. float fMAS = 0;
  908. if (ExposureParam.GetAt(7) == 0xFF)
  909. {
  910. fMAS = ExposureParam.GetAt(6);
  911. }
  912. else
  913. {
  914. fMAS = (ExposureParam.GetAt(7) << 8) + ExposureParam.GetAt(6);
  915. }
  916. mLog::Debug("get CurrtSetMS [{$}]", fMAS);
  917. m_DoseUnit.m_MAS->Update(fMAS);
  918. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  919. //Focus
  920. int nFO = 0;
  921. switch (ExposureParam.GetAt(8))
  922. {
  923. case EM_Focus_Large:
  924. mLog::Debug("get CurrtFocus [Small]");
  925. nFO = AttrKey::FOCUS_TYPE::FOCUS_LARGE;
  926. break;
  927. case EM_Focus_Small:
  928. mLog::Debug("get CurrtFocus [Large]");
  929. nFO = AttrKey::FOCUS_TYPE::FOCUS_SMALL;
  930. break;
  931. default:
  932. mLog::Debug("==CallbackExposureParam==: Get other Focus value!");
  933. break;
  934. }
  935. if (m_DoseUnit.m_Focus->Update(nFO))
  936. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  937. //Techmode
  938. int nET = 0;
  939. switch (ExposureParam.GetAt(9))
  940. {
  941. case EM_EXPMode_MAN:
  942. nET = AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P;
  943. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  944. break;
  945. case EM_EXPMode_AEC:
  946. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  947. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  948. break;
  949. case EM_EXPMode_Opdose:
  950. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  951. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  952. break;
  953. default:
  954. mLog::Debug("==CallbackExposureParam==: Get other Techmode value!");
  955. break;
  956. }
  957. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  958. mLog::Debug("==CallbackExposureParam==: KV: [{$}], MAS:[{$}], Focus: [{$}], TechMode: [{$}]", nKV, fMAS, nFO, nET);
  959. };
  960. auto CallbackHu = [this](const char* value, int length) -> void
  961. {
  962. SINOCommand HU(value);
  963. //TubeHeat status
  964. int nHUStatus = HU.GetAt(5);
  965. string HUCode("SINO_HU_");
  966. HUCode += std::to_string(nHUStatus);
  967. //TubeHeat percent value
  968. int nTubeHeat = 0;
  969. if (HU.GetAt(6) == 0xFF)
  970. {
  971. nTubeHeat = 0;
  972. }
  973. else
  974. {
  975. nTubeHeat = HU.GetAt(6);
  976. }
  977. m_DoseUnit.m_HE->Update(nTubeHeat);
  978. FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
  979. mLog::Debug("==CallbackHu==: HUStatus: [{$}],HU: [{$}]", HUCode, nTubeHeat);
  980. };
  981. auto CallbackQueryStatus = [this](const char* value, int length) -> void
  982. {
  983. #if 1
  984. SINOCommand QueryStatus(value);
  985. //KV
  986. int nKV = QueryStatus.GetAt(5);
  987. mLog::Debug("get CurrtSetKV [{$}]", nKV);
  988. m_DoseUnit.m_KV->Update(nKV);
  989. FireNotify(AttrKey::KV, m_DoseUnit.m_KV->JSGet());
  990. //MAS
  991. float fMAS = 0;
  992. if (QueryStatus.GetAt(7) == 0xFF)
  993. {
  994. fMAS = QueryStatus.GetAt(6);
  995. }
  996. else
  997. {
  998. fMAS = (QueryStatus.GetAt(7) << 8) + QueryStatus.GetAt(6);
  999. }
  1000. mLog::Debug("get CurrtSetMS [{$}]", fMAS);
  1001. m_DoseUnit.m_MAS->Update(fMAS);
  1002. FireNotify(AttrKey::MAS, m_DoseUnit.m_MAS->JSGet());
  1003. //Focus
  1004. int nFO = 0;
  1005. switch (QueryStatus.GetAt(8))
  1006. {
  1007. case EM_Focus_Large:
  1008. mLog::Debug("get CurrtFocus [Small]");
  1009. nFO = AttrKey::FOCUS_TYPE::FOCUS_LARGE;
  1010. break;
  1011. case EM_Focus_Small:
  1012. mLog::Debug("get CurrtFocus [Large]");
  1013. nFO = AttrKey::FOCUS_TYPE::FOCUS_SMALL;
  1014. break;
  1015. default:
  1016. mLog::Debug("==CallbackQueryStatus==: Get other Focus value!");
  1017. break;
  1018. }
  1019. if (m_DoseUnit.m_Focus->Update(nFO))
  1020. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1021. //Techmode
  1022. int nET = 0;
  1023. switch (QueryStatus.GetAt(9))
  1024. {
  1025. case EM_EXPMode_MAN:
  1026. nET = AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P;
  1027. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  1028. break;
  1029. case EM_EXPMode_AEC:
  1030. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  1031. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  1032. break;
  1033. case EM_EXPMode_Opdose:
  1034. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  1035. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  1036. break;
  1037. default:
  1038. mLog::Debug("==CallbackQueryStatus==: Get other Techmode value!");
  1039. break;
  1040. }
  1041. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1042. //AGD
  1043. float fAGD = 0;
  1044. if (QueryStatus.GetAt(11) == 0xFF)
  1045. {
  1046. fAGD = QueryStatus.GetAt(10);
  1047. }
  1048. else
  1049. {
  1050. fAGD = (QueryStatus.GetAt(11) << 8) + QueryStatus.GetAt(10);
  1051. }
  1052. if (m_pMechDev)
  1053. {
  1054. m_pMechDev->UpdateMammo_AGD(fAGD);
  1055. }
  1056. //Filter
  1057. int nFilter = 0;
  1058. if (QueryStatus.GetAt(12) == 0xFF)
  1059. {
  1060. nFilter = EM_Mo_Filtration;
  1061. }
  1062. else
  1063. {
  1064. nFilter = QueryStatus.GetAt(12);
  1065. }
  1066. if (m_pMechDev)
  1067. m_pMechDev->UpdateMammo_FT(nFilter);
  1068. //BreastThickness
  1069. int nBreastThickness = 0;
  1070. if (QueryStatus.GetAt(14) == 0xFF)
  1071. {
  1072. nBreastThickness = QueryStatus.GetAt(13);
  1073. }
  1074. else
  1075. {
  1076. nBreastThickness = (QueryStatus.GetAt(14) << 8) + QueryStatus.GetAt(13);
  1077. }
  1078. if (m_pMechDev)
  1079. m_pMechDev->UpdateMammo_PressureState(nBreastThickness);
  1080. //pressure
  1081. float fPressure = 0;
  1082. if (QueryStatus.GetAt(15) == 0xFF)
  1083. {
  1084. fPressure = 0;
  1085. }
  1086. else
  1087. {
  1088. fPressure = QueryStatus.GetAt(15);
  1089. }
  1090. if (m_pMechDev)
  1091. m_pMechDev->UpdateMammo_PressureValue(fPressure);
  1092. //Paddle Type
  1093. int nPaddle_Type = 0;
  1094. if (QueryStatus.GetAt(16) == 0xFF)
  1095. {
  1096. nPaddle_Type = 0;
  1097. }
  1098. else
  1099. {
  1100. nPaddle_Type = QueryStatus.GetAt(16);
  1101. }
  1102. //Angle
  1103. float fAngle = 0;
  1104. if (QueryStatus.GetAt(18) == 0xFF)
  1105. {
  1106. fAngle = (float)(QueryStatus.GetAt(17)) / 10.0f;
  1107. }
  1108. else
  1109. {
  1110. fAngle = (float)((QueryStatus.GetAt(18) << 8) + QueryStatus.GetAt(17)) / 10.0f;
  1111. }
  1112. fAngle = 180 - fAngle;
  1113. if (m_pMechDev)
  1114. m_pMechDev->UpdateMammo_MechAngle(fAngle);
  1115. //Height
  1116. float fHeight = 0;
  1117. if (QueryStatus.GetAt(20) == 0xFF)
  1118. {
  1119. fHeight = QueryStatus.GetAt(7);
  1120. }
  1121. else
  1122. {
  1123. fHeight = (QueryStatus.GetAt(20) << 8) + QueryStatus.GetAt(19);
  1124. }
  1125. if (m_pMechDev)
  1126. m_pMechDev->UpdateMammo_MechHeight(fHeight);
  1127. mLog::Debug("==CallbackQueryStatus==: KV: [{$}],MAS: [{$}],Techmode:[{$}],AGD:[{$}],Filter:[{$}],Thickness:[{$}],Pressure:[{$}],Paddle_Type:[{$}],Angle:[{$}],Height:[{$}]",
  1128. nKV, fMAS, nET, fAGD, nFilter, nBreastThickness, fPressure, nPaddle_Type, fAngle, fHeight);
  1129. #endif
  1130. };
  1131. auto CallbackPostExposure = [this](const char* value, int length) -> void
  1132. {
  1133. SINOCommand PostExposure(value);
  1134. //KV
  1135. int nKV = PostExposure.GetAt(5);
  1136. mLog::Debug("get CurrtSetKV [{$}]", nKV);
  1137. m_DoseUnit.m_PostKV->Update(nKV);
  1138. FireNotify(AttrKey::POSTKV, m_DoseUnit.m_PostKV->JSGet());
  1139. //MAS
  1140. float fMAS = 0;
  1141. if (PostExposure.GetAt(7) == 0xFF)
  1142. {
  1143. fMAS = PostExposure.GetAt(6);
  1144. }
  1145. else
  1146. {
  1147. fMAS = (PostExposure.GetAt(7) << 8) + PostExposure.GetAt(6);
  1148. }
  1149. mLog::Debug("get CurrtSetMS [{$}]", fMAS);
  1150. m_DoseUnit.m_PostMAS->Update(fMAS);
  1151. FireNotify(AttrKey::POSTMAS, m_DoseUnit.m_PostMAS->JSGet());
  1152. //Focus
  1153. int nFO = 0;
  1154. switch (PostExposure.GetAt(8))
  1155. {
  1156. case EM_Focus_Large:
  1157. mLog::Debug("get CurrtFocus [Small]");
  1158. nFO = AttrKey::FOCUS_TYPE::FOCUS_LARGE;
  1159. break;
  1160. case EM_Focus_Small:
  1161. mLog::Debug("get CurrtFocus [Large]");
  1162. nFO = AttrKey::FOCUS_TYPE::FOCUS_SMALL;
  1163. break;
  1164. default:
  1165. mLog::Debug("==CallbackPostExposure==: Get other Focus value!");
  1166. break;
  1167. }
  1168. if (m_DoseUnit.m_Focus->Update(nFO))
  1169. FireNotify(AttrKey::FOCUS, m_DoseUnit.m_Focus->JSGet());
  1170. //Techmode
  1171. int nET = 0;
  1172. switch (PostExposure.GetAt(9))
  1173. {
  1174. case EM_EXPMode_MAN:
  1175. nET = AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P;
  1176. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_NOAEC_2P);
  1177. break;
  1178. case EM_EXPMode_AEC:
  1179. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  1180. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  1181. break;
  1182. case EM_EXPMode_Opdose:
  1183. nET = AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P;
  1184. m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_2P);
  1185. break;
  1186. default:
  1187. mLog::Debug("==CallbackPostExposure==: Get other Techmode value!");
  1188. break;
  1189. }
  1190. FireNotify(AttrKey::TECHMODE, m_DoseUnit.m_Techmode->JSGet());
  1191. //AGD
  1192. float fAGD = 0;
  1193. if (PostExposure.GetAt(11) == 0xFF)
  1194. {
  1195. fAGD = PostExposure.GetAt(10);
  1196. }
  1197. else
  1198. {
  1199. fAGD = (PostExposure.GetAt(11) << 8) + PostExposure.GetAt(10);
  1200. }
  1201. if (m_pMechDev)
  1202. {
  1203. m_pMechDev->UpdateMammo_AGD(fAGD);
  1204. }
  1205. //Filter
  1206. int nFilter = 0;
  1207. if (PostExposure.GetAt(12) == 0xFF)
  1208. {
  1209. nFilter = EM_Mo_Filtration;
  1210. }
  1211. else
  1212. {
  1213. nFilter = PostExposure.GetAt(12);
  1214. }
  1215. if (m_pMechDev)
  1216. m_pMechDev->UpdateMammo_FT(nFilter);
  1217. //BreastThickness
  1218. int nBreastThickness = 0;
  1219. if (PostExposure.GetAt(14) == 0xFF)
  1220. {
  1221. nBreastThickness = PostExposure.GetAt(13);
  1222. }
  1223. else
  1224. {
  1225. nBreastThickness = (PostExposure.GetAt(14) << 8) + PostExposure.GetAt(13);
  1226. }
  1227. if (m_pMechDev)
  1228. m_pMechDev->UpdateMammo_PressureState(nBreastThickness);
  1229. //pressure
  1230. float fPressure = 0;
  1231. if (PostExposure.GetAt(15) == 0xFF)
  1232. {
  1233. fPressure = 0;
  1234. }
  1235. else
  1236. {
  1237. fPressure = PostExposure.GetAt(15);
  1238. }
  1239. if (m_pMechDev)
  1240. m_pMechDev->UpdateMammo_PressureValue(fPressure);
  1241. //Paddle Type
  1242. int nPaddle_Type = 0;
  1243. if (PostExposure.GetAt(16) == 0xFF)
  1244. {
  1245. nPaddle_Type = 0;
  1246. }
  1247. else
  1248. {
  1249. nPaddle_Type = PostExposure.GetAt(16);
  1250. }
  1251. //Angle
  1252. float fAngle = 0;
  1253. if (PostExposure.GetAt(18) == 0xFF)
  1254. {
  1255. fAngle = (float)(PostExposure.GetAt(17)) / 10.0f;
  1256. }
  1257. else
  1258. {
  1259. fAngle = (float)((PostExposure.GetAt(18) << 8) + PostExposure.GetAt(17)) / 10.0f;
  1260. }
  1261. fAngle = 180 - fAngle;
  1262. if (m_pMechDev)
  1263. m_pMechDev->UpdateMammo_MechAngle(fAngle);
  1264. //Height
  1265. float fHeight = 0;
  1266. if (PostExposure.GetAt(20) == 0xFF)
  1267. {
  1268. fHeight = PostExposure.GetAt(7);
  1269. }
  1270. else
  1271. {
  1272. fHeight = (PostExposure.GetAt(20) << 8) + PostExposure.GetAt(19);
  1273. }
  1274. if (m_pMechDev)
  1275. m_pMechDev->UpdateMammo_MechHeight(fHeight);
  1276. mLog::Debug("==CallbackPostExposure==: KV: [{$}],MAS: [{$}],Techmode:[{$}],AGD:[{$}],Filter:[{$}],Thickness:[{$}],Pressure:[{$}],Paddle_Type:[{$}],Angle:[{$}],Height:[{$}]",
  1277. nKV, fMAS,nET, fAGD, nFilter, nBreastThickness, fPressure, nPaddle_Type, fAngle, fHeight);
  1278. };
  1279. auto CallbackSystemStatus = [this](const char* value, int length) -> void
  1280. {
  1281. SINOCommand SystemStatus(value);
  1282. int nStatus = SystemStatus.GetAt(5);
  1283. mLog::Debug("==CallbackSystemStatus==: MU system Status: [{$}]", nStatus);
  1284. switch ((UINT8)nStatus)
  1285. {
  1286. case (UINT8)EM_SysStatus001: //C臂正在做旋转运动
  1287. mLog::Debug("C-arm is undergoing rotational motion");
  1288. break;
  1289. case (UINT8)EM_SysStatus002: //C臂旋转运动停止
  1290. mLog::Debug("C-arm rotation stop");
  1291. break;
  1292. case (UINT8)EM_SysStatus003: //C臂正在做升降运动
  1293. mLog::Debug("C-arm is in lifting motion");
  1294. break;
  1295. case (UINT8)EM_SysStatus004: //C臂升降运动停止
  1296. mLog::Debug("C-arm lifting movement stops");
  1297. break;
  1298. case (UINT8)EM_SysStatus005: //急停开关按下
  1299. mLog::Debug("Emergency stop switch pressed");
  1300. break;
  1301. case (UINT8)EM_SysStatus006: //急停开关弹起
  1302. mLog::Debug("Emergency stop switch pops up");
  1303. break;
  1304. case (UINT8)EM_SysStatus016: //压迫器正在做升降运动
  1305. mLog::Debug("Compressor is in lifting motion");
  1306. break;
  1307. case (UINT8)EM_SysStatus017: //压迫器升降运动停止
  1308. mLog::Debug("Compressor lifting movement stopped");
  1309. break;
  1310. case (UINT8)EM_SysStatus018: //达到最佳压力停止
  1311. mLog::Debug("Reaching optimal pressure stop");
  1312. break;
  1313. case (UINT8)EM_SysStatus019: //解除达到最佳压力停止
  1314. mLog::Debug("Release to reach optimal pressure stop");
  1315. break;
  1316. case (UINT8)EM_SysStatus020: //压迫器上升
  1317. mLog::Debug("Compressor ascending");
  1318. break;
  1319. case (UINT8)EM_SysStatus021: //压迫器下降
  1320. mLog::Debug("Compressor descent");
  1321. break;
  1322. case (UINT8)EM_SysStatus022: //压迫器停止
  1323. mLog::Debug("Compressor stop");
  1324. break;
  1325. case (UINT8)EM_SysStatus032: //准直器滤过正在切换
  1326. mLog::Debug("Collimator filter is switching");
  1327. break;
  1328. case (UINT8)EM_SysStatus033: //准直器滤过切换完毕
  1329. mLog::Debug("Collimator filter switching completed");
  1330. break;
  1331. case (UINT8)EM_SysStatus034: //准直器摄野范围正在调整
  1332. mLog::Debug("Collimator field range is being adjusted");
  1333. break;
  1334. case (UINT8)EM_SysStatus035: //准直器摄野范围调整完毕
  1335. mLog::Debug("Collimator field range adjustment completed");
  1336. break;
  1337. case (UINT8)EM_SysStatus036: //摄野灯点亮
  1338. mLog::Debug("Camera light on");
  1339. break;
  1340. case (UINT8)EM_SysStatus037: //摄野灯熄灭
  1341. mLog::Debug("Camera light off");
  1342. break;
  1343. case (UINT8)EM_SysStatus064: //允许曝光板开启曝光功能
  1344. mLog::Debug("Allow exposure board to activate exposure function");
  1345. break;
  1346. case (UINT8)EM_SysStatus065: //禁止曝光板开启曝光功能
  1347. mLog::Debug("Prohibit exposure board to activate exposure function");
  1348. break;
  1349. case (UINT8)EM_SysStatus066: //采集工作站启动曝光按钮
  1350. mLog::Debug("Start exposure button on the collection workstation");
  1351. break;
  1352. case (UINT8)EM_SysStatus067: //曝光手闸按下
  1353. mLog::Debug("PR1 : Exposure handbrake pressed");
  1354. //mLog::Debug("Request Status_4:RAD_OFF(PR0) -> RAD_PREPARE(PR1)");
  1355. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_PREPARE))
  1356. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1357. break;
  1358. case (UINT8)EM_SysStatus068: //系统曝光预热状态
  1359. mLog::Debug("PR2 : System exposure preheating status");
  1360. //mLog::Debug("Request Status_13:PREPARE or XRAYOFF(PR1 or XR0) -> RAD_READY(PR2)");
  1361. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_READY))
  1362. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1363. break;
  1364. case (UINT8)EM_SysStatus070: //滤线栅同步命令(预留)
  1365. mLog::Debug("Filter grid synchronization command");
  1366. break;
  1367. case (UINT8)EM_SysStatus071: //AEC/Opdose模式开启高压预曝光
  1368. mLog::Debug("Pre - XR1 : AEC/Opdose mode high-pressure pre exposure begin");
  1369. //mLog::Debug("Request Status_1:RAD_READY(PR2) -> X-Ray On(XR1)");
  1370. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
  1371. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1372. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_EXP", m_DoseUnit.m_GenState->JSGet());
  1373. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
  1374. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1375. break;
  1376. case (UINT8)EM_SysStatus073: //AEC/Opdose模式高压预曝光结束
  1377. mLog::Debug("Pre - XR0 : AEC/Opdose mode enables high-pressure pre exposure end");
  1378. //mLog::Debug("Request Status_1:X-Ray On(XR1) -> Off(XR0)");
  1379. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
  1380. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1381. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1382. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1383. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1384. break;
  1385. case (UINT8)EM_SysStatus075: //开启高压,系统开始正常曝光
  1386. mLog::Debug("XR1 : the system starts normal exposure");
  1387. //mLog::Debug("Request Status_1:RAD_READY(PR2) -> X-Ray On(XR1)");
  1388. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYON))
  1389. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1390. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_EXP", m_DoseUnit.m_GenState->JSGet());
  1391. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_EXP);
  1392. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1393. break;
  1394. case (UINT8)EM_SysStatus077: //曝光进程中断
  1395. mLog::Debug("XR0 : Exposure process interrupted");
  1396. //mLog::Debug("Request Status_1:X-Ray On(XR1) -> Off(XR0)");
  1397. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_XRAYOFF))
  1398. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1399. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1400. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1401. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1402. break;
  1403. case (UINT8)EM_SysStatus078: //曝光完成开始冷却
  1404. mLog::Debug("PR0 : Start cooling after exposure is completed");
  1405. //mLog::Debug("Request Status_4:GEN is not in Prep state(PR0)");
  1406. if (m_DoseUnit.m_GenSynState->Update(nsGEN::AttrKey::GENERATOR_RAD_OFF))
  1407. FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
  1408. mLog::Debug("Request Fault Status:GENSTATE {$} -> STATUS_SLEEP", m_DoseUnit.m_GenState->JSGet());
  1409. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_SLEEP);
  1410. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1411. break;
  1412. case (UINT8)EM_SysStatus079: //系统冷却完成
  1413. mLog::Debug("System cooling completed");
  1414. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1415. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1416. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1417. break;
  1418. case (UINT8)EM_SysStatus080: //屏蔽房间门处于闭合状态
  1419. mLog::Debug("The shielded room door is in a closed state");
  1420. break;
  1421. case (UINT8)EM_SysStatus081: //屏蔽房间门处于敞开状态
  1422. mLog::Debug("The shielded room door is in a opened state");
  1423. break;
  1424. case (UINT8)EM_SysStatus160: //MU初始化中
  1425. mLog::Debug("MU initialization in progress");
  1426. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_INIT", m_DoseUnit.m_GenState->JSGet());
  1427. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_INIT);
  1428. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1429. break;
  1430. case (UINT8)EM_SysStatus161: //MU初始化完成
  1431. mLog::Debug("MU initialization completed");
  1432. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1433. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1434. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1435. break;
  1436. case (UINT8)EM_SysStatus162: //MU各个状态 READY,可以进行曝光
  1437. mLog::Debug("MU in various states READY, can be exposed");
  1438. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1439. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1440. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1441. break;
  1442. case (UINT8)EM_SysStatus163: //MU 各状态NOT READY,不可以进行曝光
  1443. mLog::Debug("MU in various states not READY, can not be exposed");
  1444. mLog::Debug("Request Fault Status:GENSTATE {$} -> STATUS_ERROR", m_DoseUnit.m_GenState->JSGet());
  1445. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_ERROR);
  1446. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1447. break;
  1448. default:
  1449. mLog::Error("==CallbackSystemStatus==: unKnown status: [{$}]", nStatus);
  1450. }
  1451. };
  1452. auto CallbackSystemWarn = [this](const char* value, int length) -> void
  1453. {
  1454. SINOCommand SystemWarn(value);
  1455. int nCode = SystemWarn.GetAt(5);
  1456. mLog::Debug("==CallbackSystemWarn==: MU system Wraning: [{$}]", nCode);
  1457. switch ((UINT8)nCode)
  1458. {
  1459. case (UINT8)EM_SysWarn001: //球管温度过高报警
  1460. case (UINT8)EM_SysWarn002: //高压发生器高压输出未允许报警
  1461. case (UINT8)EM_SysWarn003: //球管高速启动故障报警
  1462. case (UINT8)EM_SysWarn004: //高压发生器产生高压电弧故障报警
  1463. case (UINT8)EM_SysWarn005: //无效曝光参数设置导致高压输出大于5KW报警
  1464. case (UINT8)EM_SysWarn006: //AEC曝光控制超时报警
  1465. case (UINT8)EM_SysWarn007: //高压发生器反馈的mAs超出设置值报警
  1466. case (UINT8)EM_SysWarn008: //曝光周期中间歇时间未完成就进行曝光报警
  1467. case (UINT8)EM_SysWarn009: //高压发生器输出KV大于42765V且时间超过1ms报警
  1468. case (UINT8)EM_SysWarn010: //高压发生器输出mA大于213.828 mA且时间超过100ms报警
  1469. case (UINT8)EM_SysWarn011: //高压发生器输出KV或mA大于设置值的%25导致报警
  1470. case (UINT8)EM_SysWarn012: //高压发生器反馈球管灯丝开路报警
  1471. case (UINT8)EM_SysWarn013: //高压发生器反馈球管过流报警
  1472. case (UINT8)EM_SysWarn014: //高压发生器AD/DC输入电压过低报警
  1473. FireErrorMessage(true, nCode, "SINO using error");
  1474. break;
  1475. case (UINT8)EM_SysWarn015: //高压发生器强制超出曝光任务周期报警
  1476. case (UINT8)EM_SysWarn016: //高压发生器管电压、管电流检测报警
  1477. case (UINT8)EM_SysWarn017: //高压发生器强制恢复过压异常报警
  1478. case (UINT8)EM_SysWarn018: //解除高压发生器报警
  1479. FireErrorMessage(false, 0, "SINO using warn");
  1480. break;
  1481. case (UINT8)EM_SysWarn019: //曝光按钮短路或者未释放报警
  1482. FireErrorMessage(true, nCode, "SINO handswitch short circuit error");
  1483. break;
  1484. case (UINT8)EM_SysWarn020: //解除手闸短路报警命令
  1485. FireErrorMessage(false, EM_SysWarn019, "SINO handswitch short circuit error");
  1486. break;
  1487. case (UINT8)EM_SysWarn021: //曝光没有到设定时间提前松开手闸报警
  1488. FireErrorMessage(true, nCode, "SINO handswitch early release error");
  1489. break;
  1490. case (UINT8)EM_SysWarn022: //消除提前松开手闸报警
  1491. FireErrorMessage(false, EM_SysWarn021, "SINO handswitch early release error");
  1492. break;
  1493. case (UINT8)EM_SysWarn023: //自动测试模式时,检测到没有短接跳线报警
  1494. FireErrorMessage(true, nCode, "SINO automatic testing short circuit error");
  1495. break;
  1496. case (UINT8)EM_SysWarn024: //解除自动测试跳线帽未短接报警
  1497. FireErrorMessage(false, EM_SysWarn023, "SINO automatic testing short circuit error");
  1498. break;
  1499. case (UINT8)EM_SysWarn025: //曝光时,未收到运动板发来的滤线栅抖动信号
  1500. case (UINT8)EM_SysWarn032: //高压通信超时
  1501. case (UINT8)EM_SysWarn048: //运动控制板自检不通过报警
  1502. FireErrorMessage(true, nCode, "SINO Sports board error");
  1503. break;
  1504. case (UINT8)EM_SysWarn049: //解除运动控制板自检不通过报警
  1505. FireErrorMessage(false, EM_SysWarn048, "SINO Sports board error");
  1506. break;
  1507. case (UINT8)EM_SysWarn052: //运动控制板存储器读写数据失败报警
  1508. FireErrorMessage(true, nCode, "SINO Sports board Memory read/write data failure error");
  1509. break;
  1510. case (UINT8)EM_SysWarn054: //解除运动控制板存储器读写数据失败报警
  1511. FireErrorMessage(false, EM_SysWarn052, "SINO Sports board Memory read/write data failure error");
  1512. break;
  1513. case (UINT8)EM_SysWarn055: //急停开关按下时,运动控制键被按下报警
  1514. FireErrorMessage(true, nCode, "SINO Sports board Key pressed error");
  1515. break;
  1516. case (UINT8)EM_SysWarn056: //解除急停开关按下时,运动控制键被按下错误
  1517. FireErrorMessage(false, EM_SysWarn055, "SINO Sports board Key pressed error");
  1518. break;
  1519. case (UINT8)EM_SysWarn057: //脚踏开关自检未完成时被踩下报警
  1520. FireErrorMessage(true, nCode, "SINO footwitch Stepped down error");
  1521. break;
  1522. case (UINT8)EM_SysWarn058: //解除脚踏开关自检未完成时被踩下报警
  1523. FireErrorMessage(false, EM_SysWarn057, "SINO footwitch Stepped down error");
  1524. break;
  1525. case (UINT8)EM_SysWarn059: //旋转运动二次限位保护开关触发报警
  1526. FireErrorMessage(true, nCode, "SINO Rotational board second limit Trigger touch off error");
  1527. break;
  1528. case (UINT8)EM_SysWarn060: //旋转运动二次限位保护开关触发报警解除
  1529. FireErrorMessage(false, EM_SysWarn059, "SINO Rotational board second limit Trigger touch off error");
  1530. break;
  1531. case (UINT8)EM_SysWarn061: //C臂旋转方向控制引脚失效报警
  1532. FireErrorMessage(true, nCode, "SINO C-arm rotation direction control pin failure error");
  1533. break;
  1534. case (UINT8)EM_SysWarn062: //解除C臂旋转方向控制引脚失效报警
  1535. FireErrorMessage(false, EM_SysWarn061, "SINO C-arm rotation direction control pin failure error");
  1536. break;
  1537. case (UINT8)EM_SysWarn063: //C臂旋转或者升降按键在自检未完成时按下报警
  1538. FireErrorMessage(true, nCode, "SINO C-arm rotation button pressed error");
  1539. break;
  1540. case (UINT8)EM_SysWarn064: //解除C臂旋转或者升降按键在自检未完成时按下报警
  1541. FireErrorMessage(false, EM_SysWarn063, "SINO C-arm rotation button pressed error");
  1542. break;
  1543. case (UINT8)EM_SysWarn065: //C臂旋转电机驱动器报警
  1544. FireErrorMessage(true, nCode, "SINO C-arm rotation motor driver error");
  1545. break;
  1546. case (UINT8)EM_SysWarn066: //解除C臂旋转电机驱动器报警
  1547. FireErrorMessage(false, EM_SysWarn065, "SINO C-arm rotation motor driver error");
  1548. break;
  1549. case (UINT8)EM_SysWarn067: //C臂电机位置超差报警
  1550. FireErrorMessage(true, nCode, "SINO C-arm motor position out of tolerance error");
  1551. break;
  1552. case (UINT8)EM_SysWarn068: //解除C臂电机位置超差报警
  1553. FireErrorMessage(false, EM_SysWarn067, "SINO C-arm motor position out of tolerance error");
  1554. break;
  1555. case (UINT8)EM_SysWarn069: //升降运动二次限位保护开关触发报警
  1556. FireErrorMessage(true, nCode, "SINO lifting board second limit Trigger touch off error");
  1557. break;
  1558. case (UINT8)EM_SysWarn070: //升降运动二次限位保护开关触发报警解除
  1559. FireErrorMessage(false, EM_SysWarn069, "SINO lifting board second limitTrigger touch off error");
  1560. break;
  1561. case (UINT8)EM_SysWarn071: //升降电机方向控制引脚失效报警
  1562. FireErrorMessage(true, nCode, "SINO Lift motor direction control pin failure error");
  1563. break;
  1564. case (UINT8)EM_SysWarn072: //解除升降电机方向控制引脚失效报警
  1565. FireErrorMessage(false, EM_SysWarn071, "SINO Lift motor direction control pin failure error");
  1566. break;
  1567. case (UINT8)EM_SysWarn073: //机架升降电机驱动器报警
  1568. FireErrorMessage(true, nCode, "SINO Rack lifting motor driver error");
  1569. break;
  1570. case (UINT8)EM_SysWarn074: //解除机架升降电机驱动器报警
  1571. FireErrorMessage(false, EM_SysWarn073, "SINO Rack lifting motor driver error");
  1572. break;
  1573. case (UINT8)EM_SysWarn075: //升降电机位置超差报警
  1574. FireErrorMessage(true, nCode, "SINO Lift motor position out of tolerance error");
  1575. break;
  1576. case (UINT8)EM_SysWarn076: //解除升降电机位置超差报警
  1577. FireErrorMessage(false, EM_SysWarn075, "SINO Lift motor position out of tolerance error");
  1578. break;
  1579. case (UINT8)EM_SysWarn077: //角度校准板失效报警
  1580. FireErrorMessage(true, nCode, "SINO Angle calibration board failure error");
  1581. break;
  1582. case (UINT8)EM_SysWarn078: //解除角度校准板失效报警
  1583. FireErrorMessage(false, EM_SysWarn077, "SINO Angle calibration board failure error");
  1584. break;
  1585. case (UINT8)EM_SysWarn096: //压迫器运动二次限位保护开关触发
  1586. FireErrorMessage(true, nCode, "SINO Compressor board second limit Trigger touch off error");
  1587. break;
  1588. case (UINT8)EM_SysWarn097: //压迫器运动二次限位保护开关触发解除
  1589. FireErrorMessage(false, EM_SysWarn096, "SINO Compressor board second limit Trigger touch off error");
  1590. break;
  1591. case (UINT8)EM_SysWarn098: //压迫器方向控制引脚失效
  1592. FireErrorMessage(true, nCode, "SINO Compressor direction control pin failure error");
  1593. break;
  1594. case (UINT8)EM_SysWarn099: //解除压迫器方向控制引脚失效
  1595. FireErrorMessage(false, EM_SysWarn098, "SINO Compressor direction control pin failure error");
  1596. break;
  1597. case (UINT8)EM_SysWarn100: //压迫器升降电机驱动器报警
  1598. FireErrorMessage(true, nCode, "SINO Compressor lifting motor driver error");
  1599. break;
  1600. case (UINT8)EM_SysWarn101: //解除压迫器升降电机驱动器报警
  1601. FireErrorMessage(false, EM_SysWarn100, "SINO Compressor lifting motor driver error");
  1602. break;
  1603. case (UINT8)EM_SysWarn102: //开机检测到压力报错
  1604. FireErrorMessage(true, nCode, "SINO Pressure detected during startup error");
  1605. break;
  1606. case (UINT8)EM_SysWarn103: //解除开机检测到压力报错
  1607. FireErrorMessage(false, EM_SysWarn102, "SINO Pressure detected during startup error");
  1608. break;
  1609. case (UINT8)EM_SysWarn104: //压力传感器故障报警Pressure Sensor ERROR
  1610. FireErrorMessage(true, nCode, "SINO pressure sensor failure error");
  1611. break;
  1612. case (UINT8)EM_SysWarn105: //解除压力传感器故障报警
  1613. FireErrorMessage(false, EM_SysWarn104, "SINO pressure sensor failure error");
  1614. break;
  1615. case (UINT8)EM_SysWarn106: //压迫器电机位置超差报警
  1616. FireErrorMessage(true, nCode, "SINO Compressor motor position out of tolerance error");
  1617. break;
  1618. case (UINT8)EM_SysWarn107: //解除压迫器电机位置超差报警
  1619. FireErrorMessage(false, EM_SysWarn106, "SINO Compressor motor position out of tolerance error");
  1620. break;
  1621. case (UINT8)EM_SysWarn108: //压迫器高度过低时插入放大架报警
  1622. FireErrorMessage(true, nCode, "SINO Insert amplifier when compressor is too low error");
  1623. break;
  1624. case (UINT8)EM_SysWarn109: //解除压迫器高度过低时插入放大架报警
  1625. FireErrorMessage(false, EM_SysWarn108, "SINO Insert amplifier when compressor is too low error");
  1626. break;
  1627. case (UINT8)EM_SysWarn110: //远端压迫器自动释放按钮被开机时按下报警
  1628. FireErrorMessage(true, nCode, "SINO Press remote compressor automatic release button when turned on error");
  1629. break;
  1630. case (UINT8)EM_SysWarn111: //解除远端压迫器自动释放按钮被开机时按下报警
  1631. FireErrorMessage(false, EM_SysWarn110, "SINO Press remote compressor automatic release button when turned on error");
  1632. break;
  1633. case (UINT8)EM_SysWarn112: //压力超限报警
  1634. FireErrorMessage(true, nCode, "SINO Pressure exceeding limit error");
  1635. break;
  1636. case (UINT8)EM_SysWarn113: //解除压力超限报警
  1637. FireErrorMessage(false, EM_SysWarn112, "SINO Pressure exceeding limit error");
  1638. break;
  1639. case (UINT8)EM_SysWarn128: //滤线栅控制电路错误
  1640. FireErrorMessage(true, nCode, "SINO Filter grid control circuit error");
  1641. break;
  1642. case (UINT8)EM_SysWarn129: //解除滤线栅电路错误
  1643. FireErrorMessage(false, EM_SysWarn128, "SINO Filter grid control circuit error");
  1644. break;
  1645. case (UINT8)EM_SysWarn152: //准直器滤片切换超时报警
  1646. FireErrorMessage(true, nCode, "SINO Collimator filter switching timeout error");
  1647. break;
  1648. case (UINT8)EM_SysWarn153: //解除准直器滤片切换超时报警
  1649. FireErrorMessage(false, EM_SysWarn152, "SINO Collimator filter switching timeout error");
  1650. break;
  1651. case (UINT8)EM_SysWarn154: //准直器摄野调节超时报警
  1652. FireErrorMessage(true, nCode, "SINO Collimator field adjustment timeout error");
  1653. break;
  1654. case (UINT8)EM_SysWarn155: //解除准直器摄野调节超时报警
  1655. FireErrorMessage(false, EM_SysWarn154, "SINO Collimator field adjustment timeout error");
  1656. break;
  1657. case (UINT8)EM_SysWarn156: //准直器存储器读数据错误报警
  1658. FireErrorMessage(true, nCode, "SINO Collimator memory read data error error");
  1659. break;
  1660. case (UINT8)EM_SysWarn157: //解除准直器存储器读数据错误报警
  1661. FireErrorMessage(false, EM_SysWarn156, "SINO Collimator memory read data error error");
  1662. break;
  1663. case (UINT8)EM_SysWarn161: //曝光控制板通信异常
  1664. case (UINT8)EM_SysWarn162: //压迫器控制板通信异常
  1665. case (UINT8)EM_SysWarn163: //准直器控制板通信异常
  1666. case (UINT8)EM_SysWarn165: //底座显示板通信异常
  1667. case (UINT8)EM_SysWarn166: //远端控制盒通信异常
  1668. FireErrorMessage(true, nCode, "SINO Abnormal communication error");
  1669. break;
  1670. case (UINT8)EM_SysWarn168: //解除通信报警
  1671. FireErrorMessage(false, 0, "SINO Abnormal communication error");
  1672. break;
  1673. default:
  1674. mLog::Error("==CallbackSystemWarn==: unKnown Wraning: [{$}]", nCode);
  1675. }
  1676. };
  1677. auto CommunicationInquiry = [this](const char* value, int length) -> void
  1678. {
  1679. SINOCommand ComInquiry(value);
  1680. int nStatus = ComInquiry.GetAt(5);
  1681. if (nStatus == EM_ComInquiry_PowerOn)
  1682. {
  1683. mLog::Debug("Request Status_1:GENSTATE {$} -> STATUS_STANDBY", m_DoseUnit.m_GenState->JSGet());
  1684. m_DoseUnit.m_GenState->Update(nsGEN::AttrKey::GENERATOR_STATUS_STANDBY);
  1685. FireNotify(AttrKey::GENSTATE, m_DoseUnit.m_GenState->JSGet());
  1686. }
  1687. else if(nStatus == EM_ComInquiry_handshake)
  1688. {
  1689. std::unique_lock<std::mutex> uqeHeartBeat(mtxHeartBeats); //心跳包统计清空
  1690. m_iHeartBeats = 0;
  1691. uqeHeartBeat.unlock();
  1692. }
  1693. mLog::Debug("==CommunicationInquiry==: status[{$}]", nStatus);
  1694. };
  1695. //服务模式:用于修改并读取非通用值, 不是正常操作的一部分.仅用于系统测试和设备维修
  1696. //暂不使用
  1697. arFrame.clear();
  1698. //命令模式:用于正常操作
  1699. arFrame.push_back(tFrameMapping("ACK",3, CallbackACK));
  1700. arFrame.push_back(tFrameMapping(SINO_ExpoParam, CallbackExpoParam));
  1701. arFrame.push_back(tFrameMapping(SINO_RackPosition,CallbackPosition));
  1702. arFrame.push_back(tFrameMapping(SINO_Compressor, CallbackCompressor));
  1703. arFrame.push_back(tFrameMapping(SINO_Collimator, CallbackCollimator));
  1704. arFrame.push_back(tFrameMapping(SINO_ExpoParam, CallbackExposureParam));
  1705. arFrame.push_back(tFrameMapping(SINO_TubeHeat, CallbackHu));
  1706. arFrame.push_back(tFrameMapping(SINO_DataFeedback, CallbackQueryStatus));
  1707. arFrame.push_back(tFrameMapping(SINO_PostFeedback, CallbackPostExposure));
  1708. arFrame.push_back(tFrameMapping(SINO_SystemStatus, CallbackSystemStatus));
  1709. arFrame.push_back(tFrameMapping(SINO_SystemWarning, CallbackSystemWarn));
  1710. arFrame.push_back(tFrameMapping(SINO_ComInquiry, CommunicationInquiry));
  1711. //服务模式:用于修改并读取非通用值, 不是正常操作的一部分.仅用于系统测试和设备维修,暂不添加
  1712. }
  1713. void nsGEN::SINODevice::ReConnect()
  1714. {
  1715. mLog::Info("enter reconnect");
  1716. m_SCF.Disconnect();
  1717. ResDataObject Connection = m_GenConfig["connections"][0];
  1718. mLog::Info("Reconnections:{$} \n", Connection.encode());
  1719. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::SINODriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1720. if (erCode == SCF_ERR::SCF_SUCCEED)
  1721. {
  1722. FireErrorMessage(false, 1, "lost Connect");
  1723. std::unique_lock<std::mutex> uqeConnectFlag(mtxConnectFlag);
  1724. m_bConnectFlag = true;
  1725. uqeConnectFlag.unlock();
  1726. mLog::Info("reconnect success");
  1727. }
  1728. else
  1729. {
  1730. mLog::Info("reconnect failed");
  1731. }
  1732. }
  1733. bool nsGEN::SINODevice::StartHardwareStatusThread()
  1734. {
  1735. mLog::Info("enter Start HardwareStatus Thread ");
  1736. if (m_pHardwareStatusThread == NULL)
  1737. {
  1738. DWORD m_HardwareStatusID;
  1739. m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  1740. if (m_pHardwareStatusThread == NULL)
  1741. {
  1742. mLog::Error("Start HardwareStatus Thread Failed");
  1743. return false;
  1744. }
  1745. }
  1746. return true;
  1747. }
  1748. DWORD nsGEN::SINODevice::HardwareStatusThread(LPVOID pParam)
  1749. {
  1750. SINODevice* pCurGen = (SINODevice*)pParam;
  1751. if (pCurGen == NULL)
  1752. {
  1753. return false;
  1754. }
  1755. mLog::Info("HardwareStatusThread start");
  1756. int iloopingFlag = 0;
  1757. if ((int)pCurGen->m_GenConfig["loopEnable"] >= 1)
  1758. {
  1759. iloopingFlag = (int)pCurGen->m_GenConfig["loopEnable"];
  1760. }
  1761. if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
  1762. {
  1763. pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
  1764. }
  1765. mLog::Info("loopEnable = {$},loopTime = {$}", iloopingFlag, pCurGen->m_iLoopTime);
  1766. int currtTime = pCurGen->m_iLoopTime;
  1767. SINOCommand strHBCmd(SINO_ComInquiry, SINO_TYPE_SEND, 7);
  1768. strHBCmd.SetAt(5, EM_ComInquiry_handshake);
  1769. pCurGen->HWSend(strHBCmd);
  1770. Sleep(currtTime);
  1771. while (iloopingFlag == 1)
  1772. {
  1773. std::unique_lock<std::mutex> uqeConnectFlag(pCurGen->mtxConnectFlag); //判断是否断连
  1774. if (!(pCurGen->m_bConnectFlag))
  1775. {
  1776. uqeConnectFlag.unlock();
  1777. mLog::Info("SINOGEN: not Connect,try to reconnect \n");
  1778. pCurGen->FireErrorMessage(true, 1, "lost Connect");
  1779. pCurGen->ReConnect();
  1780. Sleep(20000);
  1781. continue;
  1782. }
  1783. uqeConnectFlag.unlock();
  1784. std::unique_lock<std::mutex> uqeTime(pCurGen->mtxTime); //读取循环时间
  1785. mLog::Debug("currtloopTime = {$}", pCurGen->m_iLoopTime);
  1786. currtTime = pCurGen->m_iLoopTime;
  1787. uqeTime.unlock();
  1788. Sleep(currtTime);
  1789. pCurGen->HWSend(strHBCmd); //轮询发生器相关数据信息
  1790. std::unique_lock<std::mutex> uqeHeartBeat(pCurGen->mtxHeartBeats); //心跳包统计加1
  1791. pCurGen->m_iHeartBeats++;
  1792. int tempHeartBeat = pCurGen->m_iHeartBeats;
  1793. uqeHeartBeat.unlock();
  1794. if (tempHeartBeat > 10) //无返回信息认为连接断开
  1795. {
  1796. uqeHeartBeat.lock();
  1797. pCurGen->m_iHeartBeats = 0;
  1798. uqeHeartBeat.unlock();
  1799. mLog::Info("SINOGEN: lost Connect \n");
  1800. uqeConnectFlag.lock();
  1801. pCurGen->m_bConnectFlag = false;
  1802. uqeConnectFlag.unlock();
  1803. }
  1804. }
  1805. mLog::Info("HardwareStatusThread stop");
  1806. return true;
  1807. }
  1808. //-----------------------------------------------------------------------------
  1809. // SINODriver
  1810. //-----------------------------------------------------------------------------
  1811. nsGEN::SINODriver::SINODriver()
  1812. {
  1813. m_pAttribute.reset(new ResDataObject());
  1814. m_pDescription.reset(new ResDataObject());
  1815. m_pDriGenDev = nullptr;
  1816. m_pDriMechDev = nullptr;
  1817. m_pDriCollDev = nullptr;
  1818. }
  1819. nsGEN::SINODriver::~SINODriver()
  1820. {
  1821. mLog::Close();
  1822. mLog::gLogger = nullptr;
  1823. if (m_pDriGenDev)
  1824. {
  1825. delete m_pDriGenDev;
  1826. m_pDriGenDev = nullptr;
  1827. }
  1828. if (m_pDriMechDev)
  1829. {
  1830. delete m_pDriMechDev;
  1831. m_pDriMechDev = nullptr;
  1832. }
  1833. if (m_pDriCollDev)
  1834. {
  1835. delete m_pDriCollDev;
  1836. m_pDriCollDev = nullptr;
  1837. }
  1838. }
  1839. void nsGEN::SINODriver::Prepare()
  1840. {
  1841. ResDataObject r_config;
  1842. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1843. {
  1844. if ((int)r_config["CONFIGURATION"]["logEnable"] == 1)
  1845. {
  1846. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
  1847. //Log4CPP::ThreadContext::Map::Set("LogFileName", "GEN.SINO");
  1848. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.SINO");
  1849. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  1850. mLog::gLogger = Log4CPP::LogManager::GetLogger("GEN.SINO");
  1851. }
  1852. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  1853. }
  1854. super::Prepare();
  1855. }
  1856. std::string nsGEN::SINODriver::DriverProbe()
  1857. {
  1858. ResDataObject r_config, HardwareInfo;
  1859. if (r_config.loadFile(m_ConfigFileName.c_str()))
  1860. {
  1861. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  1862. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  1863. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  1864. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  1865. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  1866. }
  1867. else
  1868. {
  1869. HardwareInfo.add("MajorID", "Generator");
  1870. HardwareInfo.add("MinorID", "Dr");
  1871. HardwareInfo.add("VendorID", "SINO");
  1872. HardwareInfo.add("ProductID", "HF");
  1873. HardwareInfo.add("SerialID", "Drv");
  1874. }
  1875. string ret = HardwareInfo.encode();
  1876. return ret;
  1877. }
  1878. bool DATA_ACTION nsGEN::SINODriver::Connect()
  1879. {
  1880. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  1881. mLog::Info("connections:{$} \n", Connection.encode());
  1882. auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::SINODriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  1883. if (erCode != SCF_ERR::SCF_SUCCEED)
  1884. return false;
  1885. auto rc = super::Connect();
  1886. if (!rc)
  1887. return false;
  1888. //return (erCode == SCF_ERR::SCF_SUCCEED);
  1889. return true;
  1890. }
  1891. auto nsGEN::SINODriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
  1892. {
  1893. mLog::Info("Enter CreateDevice, index={$}", index);
  1894. if (!m_SCF.isConnected())
  1895. {
  1896. mLog::Warn("CreateDevice:not Connected");
  1897. return nullptr;
  1898. }
  1899. if (index == 0)
  1900. {
  1901. m_pDriGenDev = new SINODevice(EventCenter, m_SCF, m_ConfigFileName);
  1902. auto dev = std::unique_ptr<IODevice>(new IODevice(m_pDriGenDev));
  1903. return dev;
  1904. }
  1905. else if (index == 1)
  1906. {
  1907. mLog::Info("Enter CreateDevice Mechanical");
  1908. m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()), 0, 1, 2, 31, 32, 33, 34, 35, 36, 4, 5);
  1909. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
  1910. m_pDriMechDev->SetCtrlDev(m_pDriGenDev);
  1911. m_pDriGenDev->SetMechDev(m_pDriMechDev);
  1912. mLog::Info("Leave CreateDevice Mechanical");
  1913. return dev;
  1914. }
  1915. else if (index == 2)
  1916. {
  1917. mLog::Info("Enter CreateDevice Collimator");
  1918. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()), 40, 50, 6, 7, 8, 1);
  1919. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
  1920. m_pDriCollDev->SetCtrlDev(m_pDriGenDev);
  1921. m_pDriGenDev->SetCollimatorDev(m_pDriCollDev);
  1922. mLog::Info("Leave CreateDevice Collimator");
  1923. return dev;
  1924. }
  1925. }
  1926. void nsGEN::SINODriver::FireNotify(int code, std::string key, std::string content)
  1927. {
  1928. EventCenter->OnNotify(code, key, content);
  1929. }
  1930. bool nsGEN::SINODriver::isConnected() const
  1931. {
  1932. return super::isConnected();
  1933. }
  1934. std::string nsGEN::SINODriver::GetResource()
  1935. {
  1936. ResDataObject r_config, temp;
  1937. if (!temp.loadFile(m_ConfigFileName.c_str()))
  1938. {
  1939. return "";
  1940. }
  1941. m_ConfigAll = temp;
  1942. r_config = temp["CONFIGURATION"];
  1943. m_Configurations = r_config;
  1944. ResDataObject DescriptionTemp;
  1945. ResDataObject DescriptionSend;
  1946. ResDataObject m_DescriptionSend;
  1947. ResDataObject ListTemp;
  1948. string strTemp = ""; //用于读取字符串配置信息
  1949. string strIndex = ""; //用于读取配置信息中的List项
  1950. int nTemp = -1; //用于读取整型配置信息
  1951. char sstream[10] = { 0 }; //用于转换值
  1952. string strValue = ""; //用于存储配置的值
  1953. string strType = ""; //用于存储配置的类型 int/float/string...
  1954. /***
  1955. * 1. 通过循环,将所有配置项写到pDeviceConfig
  1956. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  1957. ***/
  1958. try
  1959. {
  1960. //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
  1961. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  1962. m_pAttribute->clear();
  1963. m_pDescription->clear();
  1964. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  1965. {
  1966. DescriptionTemp.clear();
  1967. DescriptionSend.clear();
  1968. ListTemp.clear();
  1969. //AttributeType
  1970. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  1971. DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1972. DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
  1973. strType = strTemp; //记录配置项的类型
  1974. //AttributeKey
  1975. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  1976. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  1977. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  1978. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
  1979. //printf("********************************innerkey=%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1980. //2. 赋值
  1981. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  1982. if ("int" == strType)
  1983. {
  1984. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1985. }
  1986. else if ("float" == strType)
  1987. {
  1988. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  1989. }
  1990. else //其它先按string类型处理
  1991. {
  1992. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  1993. }
  1994. //printf("********************************outkey =%s --strValue = %s\n", strTemp.c_str(), strValue.c_str());
  1995. //AttributeAccess
  1996. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  1997. DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
  1998. DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
  1999. /*
  2000. //AttributeRangeMin
  2001. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  2002. if (strTemp != "") //不需要的配置项为空
  2003. {
  2004. DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
  2005. }
  2006. //AttributeRangeMax
  2007. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  2008. if (strTemp != "") //不需要的配置项为空
  2009. {
  2010. DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
  2011. }
  2012. */
  2013. //AttributeList
  2014. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  2015. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  2016. {
  2017. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  2018. {
  2019. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  2020. auto temKey = std::to_string(nListIndex);
  2021. ListTemp.add(temKey.c_str(), strTemp.c_str());
  2022. }
  2023. DescriptionTemp.add(ConfKey::CcosList, ListTemp);
  2024. DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
  2025. }
  2026. //AttributeRequired
  2027. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  2028. DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
  2029. DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
  2030. //AttributeDefaultValue
  2031. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  2032. if (strTemp != "") //不需要的配置项为空
  2033. {
  2034. DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2035. DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
  2036. }
  2037. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2038. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  2039. m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
  2040. }
  2041. }
  2042. catch (ResDataObjectExption& e)
  2043. {
  2044. mLog::Error("Get config error: {$}", e.what());
  2045. return "";
  2046. }
  2047. ResDataObject resDeviceResource;
  2048. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2049. resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
  2050. ResDataObject DescriptionTempEx;
  2051. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2052. m_DeviceConfig.clear();
  2053. m_DeviceConfig = DescriptionTempEx;
  2054. //mLog::Debug("local ************* get resource over {$}", DescriptionTempEx.encode());
  2055. //printf("local ************* get resource over %s \n", DescriptionTempEx.encode());
  2056. resDeviceResource.clear();
  2057. resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
  2058. resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
  2059. DescriptionTempEx.clear();
  2060. DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
  2061. m_DeviceConfigSend.clear();
  2062. m_DeviceConfigSend = DescriptionTempEx;
  2063. string res = m_DeviceConfigSend.encode();
  2064. //printf("%s", res.c_str());
  2065. //mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  2066. //printf("************* get resource over %s \n", DescriptionTempEx.encode());
  2067. return res;
  2068. }
  2069. std::string nsGEN::SINODriver::DeviceProbe()
  2070. {
  2071. ResDataObject r_config, HardwareInfo;
  2072. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2073. {
  2074. HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
  2075. HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
  2076. HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
  2077. HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
  2078. HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
  2079. }
  2080. else
  2081. {
  2082. HardwareInfo.add("MajorID", "Generator");
  2083. HardwareInfo.add("MinorID", "Dr");
  2084. HardwareInfo.add("VendorID", "SINO");
  2085. HardwareInfo.add("ProductID", "HF");
  2086. HardwareInfo.add("SerialID", "Dev");
  2087. }
  2088. string ret = HardwareInfo.encode();
  2089. return ret;
  2090. }
  2091. void nsGEN::SINODriver::Disconnect()
  2092. {
  2093. super::Disconnect();
  2094. m_SCF.Disconnect();
  2095. mLog::Close();
  2096. mLog::gLogger = nullptr;
  2097. }
  2098. void nsGEN::SINODriver::Dequeue(const char* Packet, DWORD Length)
  2099. {
  2100. DecodeFrame(Packet, Length);
  2101. }
  2102. PACKET_RET nsGEN::SINODriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
  2103. {
  2104. #if 0
  2105. if (nLength > 1)
  2106. {
  2107. mLog::Error("receive data_len[{$}]", nLength);
  2108. for (int i = 0; i < nLength; i++)
  2109. {
  2110. mLog::Debug("receive data[{$}][{$:x2}]", i, RecData[i]);
  2111. }
  2112. }
  2113. #endif
  2114. bool bHasHead = false;
  2115. int iComdLengh = 7;
  2116. if (nLength < 7)
  2117. {
  2118. PacketLength = 0;
  2119. //printf("nLength too small, nLength==%d \n", nLength);
  2120. mLog::Error("nLength too small, nLength=={$}", nLength);
  2121. return PACKET_USELESS;
  2122. }
  2123. for (DWORD i = 0; i < nLength; i++)
  2124. {
  2125. //寻找包头
  2126. if ((UINT8)RecData[i]== SINO_WS_STX || (UINT8)RecData[i] == SINO_MU_STX)
  2127. {
  2128. if (i!=0) //包头之前的数据格式不对,全部扔掉
  2129. {
  2130. SINOCommand strtemp(RecData);
  2131. if (bHasHead)
  2132. {
  2133. if (i >= iComdLengh - 1) //正常指令
  2134. {
  2135. mLog::Warn("==IN two head data ==:[{$}],UselessDataLength={$},TotalLength={$} \n", strtemp.Get_Hex_Log(), PacketLength, nLength);
  2136. PacketLength = i + 1;
  2137. return PACKET_ISPACKET;
  2138. }
  2139. }
  2140. else
  2141. {
  2142. PacketLength = i;
  2143. //char strtemp[SINO_Com_NormalLen] = { 0 };
  2144. //memcpy(strtemp, RecData, SINO_Com_NormalLen - 1);
  2145. mLog::Error("==IN unknown format data ==:[{$}],UselessDataLength={$},TotalLength={$} \n", strtemp.Get_Hex_Log(), PacketLength, nLength);
  2146. return PACKET_USELESS;
  2147. }
  2148. }
  2149. else
  2150. {
  2151. bHasHead = true;
  2152. }
  2153. }
  2154. if (bHasHead && i == 3)
  2155. {
  2156. iComdLengh = RecData[i];
  2157. }
  2158. //寻找包尾
  2159. if ((UINT8)RecData[i] == SINO_WS_ETX || (UINT8)RecData[i] == SINO_MU_ETX)
  2160. {
  2161. if(bHasHead)
  2162. {
  2163. if (i >= iComdLengh-1) //正常指令
  2164. {
  2165. PacketLength = i + 1; //+1 because ETX
  2166. SINOCommand strtemp(RecData, i + 1); //全部数据
  2167. mLog::Info("==IN==:[{$}] \n", strtemp.Get_Hex_Log());
  2168. return PACKET_ISPACKET;
  2169. }
  2170. }
  2171. else //有包尾但无包头
  2172. {
  2173. PacketLength = i + 1;
  2174. //char strtemp[SINO_Com_NormalLen] = { 0 };
  2175. //memcpy(strtemp, RecData, SINO_Com_NormalLen - 1);
  2176. SINOCommand strtemp(RecData);
  2177. mLog::Error("==IN no head data ==:[{$}],NoHeadDataLength={$},TotalLength={$} \n", strtemp.Get_Hex_Log(), PacketLength, nLength);
  2178. return PACKET_USELESS;
  2179. }
  2180. }
  2181. }
  2182. if (bHasHead && nLength < SINO_Com_NormalLen)
  2183. {
  2184. PacketLength = 0;
  2185. }
  2186. if (nLength > SINO_Com_NormalLen)
  2187. {
  2188. PacketLength = nLength;
  2189. mLog::Error("nLength too big, nLength=={$}", nLength);
  2190. return PACKET_USELESS;
  2191. }
  2192. return PACKET_NOPACKET;
  2193. }
  2194. bool nsGEN::SINODriver::GetDeviceConfig(std::string& Cfg)
  2195. {
  2196. Cfg = m_DeviceConfigSend.encode();
  2197. printf("GetDeviceConfig over , %s", Cfg.c_str());
  2198. return true;
  2199. }
  2200. bool nsGEN::SINODriver::SetDeviceConfig(std::string Cfg)
  2201. {
  2202. mLog::Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  2203. printf("\n--Func-- SetDeviceConfig %s\n", Cfg.c_str());
  2204. ResDataObject DeviceConfig;
  2205. DeviceConfig.decode(Cfg.c_str());
  2206. ResDataObject DescriptionTempEx;
  2207. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  2208. mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  2209. bool bSaveFile = false; //true:重新保存配置文件
  2210. string strAccess = "";
  2211. for (int i = 0; i < DescriptionTempEx.size(); i++)
  2212. {
  2213. string strKey = DescriptionTempEx.GetKey(i);
  2214. mLog::Info("{$}", strKey.c_str());
  2215. printf("%s\n", strKey.c_str());
  2216. try
  2217. {
  2218. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  2219. {
  2220. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  2221. if ("RW" == strAccess)
  2222. {
  2223. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  2224. //1. 修改内存中的值,用于给上层发消息
  2225. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  2226. //2. 拿到Innerkey
  2227. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2228. mLog::Info("nConfigInfoCount {$}", nConfigInfoCount);
  2229. string strTemp = ""; //存储AttributeKey
  2230. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2231. {
  2232. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2233. if (strTemp == strKey)
  2234. {
  2235. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2236. break;
  2237. }
  2238. }
  2239. //3. 修改配置文件中的值
  2240. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  2241. {
  2242. mLog::Debug("SetDeviceConfigValue over");
  2243. bSaveFile = true;
  2244. }
  2245. }
  2246. else
  2247. {
  2248. mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  2249. }
  2250. }
  2251. else
  2252. {
  2253. mLog::Info("without this attribute {$}", strKey.c_str());
  2254. }
  2255. }
  2256. catch (ResDataObjectExption& e)
  2257. {
  2258. printf("\nSetDriverConfig crashed: %s\n", e.what());
  2259. mLog::Error("SetDriverConfig crashed: {$}", e.what());
  2260. return false;
  2261. }
  2262. }
  2263. if (bSaveFile)
  2264. {
  2265. //3. 重新保存配置文件
  2266. SaveConfigFile(true);
  2267. }
  2268. return true;
  2269. }
  2270. bool nsGEN::SINODriver::SaveConfigFile(bool bSendNotify)
  2271. {
  2272. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  2273. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2274. mLog::Info("SaveConfigFile over {$}", bRt);
  2275. return true;
  2276. }
  2277. bool nsGEN::SINODriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  2278. {
  2279. strValue = "";
  2280. //return true;//暂时不需要
  2281. string strTemp = pInnerKey;
  2282. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2283. {
  2284. int pos = 0;
  2285. ResDataObject resTemp = config;
  2286. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2287. {
  2288. string Key = strTemp.substr(0, pos);
  2289. string TempValue = resTemp[Key.c_str()].encode();
  2290. // printf("-TempValue=== %s", TempValue.c_str());
  2291. resTemp.clear();
  2292. resTemp.decode(TempValue.c_str());
  2293. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2294. //printf("-************--%s", strTemp.c_str());
  2295. }
  2296. if (strTemp != "")
  2297. {
  2298. strValue = (string)resTemp[strTemp.c_str()];
  2299. }
  2300. else
  2301. {
  2302. strValue = (string)resTemp;
  2303. }
  2304. }
  2305. //printf("------------%s", strValue.c_str());
  2306. return true;
  2307. }
  2308. bool nsGEN::SINODriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  2309. {
  2310. //return true;//暂时不需要
  2311. string strTemp = pInnerKey;
  2312. mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  2313. printf("\nbbbbbbbbbbbbbbBegin to change {%s} item value to {%s}\n", pInnerKey, szValue);
  2314. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2315. {
  2316. try {
  2317. int pos = 0;
  2318. ResDataObject* resTemp = &config;
  2319. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2320. {
  2321. string Key = strTemp.substr(0, pos);
  2322. resTemp = &(*resTemp)[Key.c_str()];
  2323. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2324. }
  2325. if (strTemp != "")
  2326. {
  2327. //if ((strTemp.compare("WSTable") == 0) ||
  2328. // (strTemp.compare("WSWall") == 0) ||
  2329. // (strTemp.compare("WSFree") == 0) ||
  2330. // (strTemp.compare("WSTomo") == 0) ||
  2331. // (strTemp.compare("WSConventional") == 0)
  2332. // )
  2333. //{
  2334. // int sum = (*szValue) + 1;
  2335. // (*resTemp)[strTemp.c_str()] = (char*)(&sum);
  2336. //}
  2337. //else
  2338. // (*resTemp)[strTemp.c_str()] = szValue;
  2339. (*resTemp)[strTemp.c_str()] = szValue;
  2340. }
  2341. else
  2342. {
  2343. *resTemp = szValue;
  2344. }
  2345. }
  2346. catch (ResDataObjectExption& e)
  2347. {
  2348. mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  2349. return false;
  2350. }
  2351. }
  2352. return true;
  2353. }
  2354. //-----------------------------------------------------------------------------
  2355. // GetIODriver & CreateIODriver
  2356. //-----------------------------------------------------------------------------
  2357. static nsGEN::SINODriver gIODriver;
  2358. extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
  2359. {
  2360. return &gIODriver;
  2361. }
  2362. extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
  2363. {
  2364. return new nsGEN::SINODriver();
  2365. }