DIOS.Dev.SyncBox.V2COM.cpp 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107
  1. // DIOS.Dev.GEN.DEMO.cpp : 定义 DLL 应用程序的导出函数。
  2. //
  3. #include "stdafx.h"
  4. #include "FileVersion.hpp"
  5. #include "CommonFun.h"
  6. #include "DIOS.Dev.SyncBox.V2COM.h"
  7. #include "Helper.JSON.hpp"
  8. #include "common_api.h"
  9. using namespace DIOS::Dev::Detail::SYNBOX;
  10. namespace nsSYN = DIOS::Dev::Detail::SYNBOX;
  11. static nsSYN::DynBoxDriver * pIODriver = nullptr;
  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. #define C2COM_Com_NormalLen 45
  18. #ifdef _WIN64
  19. #ifdef _DEBUG
  20. static const auto COM_SCFDllName = "Dios.Dev.SerialSCFX64D.dll";
  21. #else
  22. static const auto COM_SCFDllName = "Dios.Dev.SerialSCFX64.dll";
  23. #endif
  24. #endif
  25. #ifdef _WIN64
  26. #ifdef _DEBUG
  27. static const auto TCP_SCFDllName = "Dios.Dev.TcpipSCFX64D.dll";
  28. #else
  29. static const auto TCP_SCFDllName = "Dios.Dev.TcpipSCFX64.dll";
  30. #endif
  31. #endif
  32. using namespace DIOS::Dev::Detail::SYNBOX;
  33. namespace nsSYN = DIOS::Dev::Detail::SYNBOX;
  34. #define TIMEOUTVALUE 100 //发送间隔
  35. atomic<int> allSendInterval = TIMEOUTVALUE; //发送间隔
  36. const char cCmd_heartbeat[5] = { 'E','C',0x0d ,0x0a ,0x00 };// "EC 回车 换行";
  37. //vector<string> m_MapChannel;
  38. ////-----------------------------------------------------------------------------
  39. //// DynBoxDevice
  40. ////-----------------------------------------------------------------------------
  41. std::unique_ptr<OemCollimator> nsSYN::SyncBoxDevice::m_pCollDev = nullptr; //遮光器逻辑实体指针
  42. std::unique_ptr<OemMechanical> nsSYN::SyncBoxDevice::m_pMechDev = nullptr; //机架逻辑实体指针
  43. bool nsSYN::SyncBoxDevice::m_bHeartBeatFlag = false;
  44. bool nsSYN::SyncBoxDevice::m_bCANHBFlag = true;
  45. nsSYN::SyncBoxDevice::SyncBoxDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
  46. {
  47. ResDataObject temp;
  48. temp.loadFile(configfile.c_str());
  49. m_SYNConfig = temp["CONFIGURATION"];
  50. TransJsonText(m_SYNConfig);
  51. m_SynBoxUnit.m_WS.reset(new WORKSTATIONMould(""));
  52. m_SynBoxUnit.m_CurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 10000, 1));
  53. m_SynBoxUnit.m_HandSwitchState.reset(new HANDSWITCHMould(0, 0, 10000, 1));
  54. m_SynBoxUnit.m_GenSynState.reset(new GENSYNSTATEMould(0, 0, 10000, 1));
  55. m_SynBoxUnit.m_TotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 10000, 1));
  56. m_SynBoxUnit.m_DetectorState.reset(new DETECTORSTATUSMould(0, 0, 10000, 1));
  57. m_SynBoxUnit.m_DetectorWindowState.reset(new XWINDOWSTATUSMould(AttrKey::XWINDOW_OFF, AttrKey::XWINDOW_OFF, AttrKey::XWINDOW_ON, 1));
  58. m_SynBoxUnit.m_ExpMode.reset(new EXPMODEMould(""));
  59. m_SynBoxUnit.m_GridStatue.reset(new GRIDSYNSTATEMould(0, 0, 20, 1));
  60. m_MSGUnit.reset(new nsDetail::MSGUnit(center, SyncConsoleUnitType));
  61. m_pHardwareThread = nullptr;
  62. m_iHeartBeats = 0;
  63. m_iConnectFlag = 3;
  64. m_bSetBaudOK = false;
  65. m_hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  66. m_hLoopBeginEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
  67. m_hLoopEndEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  68. m_hArrayEvent[0] = m_hExitEvent;
  69. m_hArrayEvent[1] = m_hLoopBeginEvent;
  70. Register();
  71. OnCallBack();
  72. #if 1 //暂不启用断线检测
  73. StartHardwareThread();
  74. #endif
  75. //CAN口日志打印标志
  76. if (m_SYNConfig.GetKeyCount("CanLogEnableFlag") > 0)
  77. {
  78. m_bCanLogEnableFlag = (int)m_SYNConfig["CanLogEnableFlag"];
  79. }
  80. //允许给图像发报文
  81. SetSendMessageEnable(2);
  82. //预压迫和全压迫设置信息
  83. int nforePressureLimit = 25, nAllPressureLimit = 55;
  84. if (m_SYNConfig.GetKeyCount("ForePressureLimit") > 0 && m_SYNConfig.GetKeyCount("AllPressureLimit") > 0)
  85. {
  86. nforePressureLimit = (int)m_SYNConfig["ForePressureLimit"];
  87. nAllPressureLimit = (int)m_SYNConfig["AllPressureLimit"];
  88. }
  89. SetPressureLimit(nforePressureLimit, nAllPressureLimit);
  90. //压迫模式
  91. if (m_SYNConfig.GetKeyCount("OppressiveMode") > 0)
  92. {
  93. m_bOppressiveMode = (int)m_SYNConfig["OppressiveMode"];
  94. }
  95. //振栅模式
  96. if (m_SYNConfig.GetKeyCount("GridMode") > 0)
  97. {
  98. m_bGridMode = (int)m_SYNConfig["GridMode"];
  99. }
  100. //与发生器通信
  101. #if Dios_V3
  102. m_pGenClient = new LogicClient("V2COM_DM", "NSQ", "", false);
  103. if (m_pGenClient->Open("diosChannel", ALL_ACCESS))
  104. {
  105. mLog::Debug("Dios_V3 Create V2COM_DM Client success");
  106. }
  107. #endif
  108. //震动栅MS余量
  109. if (m_SYNConfig.GetKeyCount("GridMSMargin") > 0)
  110. {
  111. string tempValue = m_SYNConfig["GridMSMargin"];
  112. int pos = tempValue.find(',');
  113. if (pos != string::npos)
  114. {
  115. m_iGridMSRadMargin = atoi(tempValue.substr(0, tempValue.find(',')).c_str()); //Rad GridMS
  116. m_iGridMSRadMargin = 50;
  117. m_iGridMSAECMargin = atoi(tempValue.substr(tempValue.find(',') + 1).c_str()); //AEC GridMS
  118. m_iGridMSAECMargin = 50;
  119. }
  120. }
  121. mLog::Debug("GridMSRadMargin[{$}],GridMSAECMargin[{$}]", m_iGridMSRadMargin, m_iGridMSAECMargin);
  122. //滤过数值
  123. if (m_SYNConfig.GetKeyCount("FilterMO") > 0)
  124. {
  125. m_iFilterMO = (int)m_SYNConfig["FilterMO"];
  126. }
  127. if (m_SYNConfig.GetKeyCount("FilterRH") > 0)
  128. {
  129. m_iFilterRH = (int)m_SYNConfig["FilterRH"];
  130. }
  131. mLog::Debug("FilterMO[{$}],FilterRH[{$}]", m_iFilterMO, m_iFilterRH);
  132. m_SCF.DecodePack(true);
  133. }
  134. nsSYN::SyncBoxDevice::~SyncBoxDevice()
  135. {
  136. SetCANState(false);
  137. SetEvent(m_hLoopEndEvent);
  138. SetEvent(m_hExitEvent);
  139. Sleep(2000);
  140. if (m_pHardwareThread != NULL)
  141. {
  142. TerminateThread(m_pHardwareThread, 0);
  143. m_pHardwareThread = NULL;
  144. }
  145. if (!(m_SCF.isConnected()))
  146. {
  147. mLog::Info("Call UnloadLogicDevices because Lost connect");
  148. //ReConnect(true);
  149. }
  150. #if Dios_V3
  151. if (m_pGenClient)
  152. {
  153. if (!m_pGenClient->IsClosed())
  154. {
  155. m_pGenClient->Close();
  156. }
  157. delete m_pGenClient;
  158. m_pGenClient = NULL;
  159. }
  160. #endif
  161. m_pCollDev.release();
  162. m_pCollDev = nullptr;
  163. m_pMechDev.release();
  164. m_pMechDev = nullptr;
  165. }
  166. std::string nsSYN::SyncBoxDevice::GetGUID() const
  167. {
  168. mLog::Info("===============Device GetGUID : {$} ===================", SyncConsoleUnitType);
  169. return SyncConsoleUnitType;
  170. }
  171. void nsSYN::SyncBoxDevice::Register()
  172. {
  173. auto Disp = &Dispatch;
  174. superSYN::Register(Disp);
  175. Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
  176. //手动信号调试
  177. auto fun_DebugSignal = [this](auto in, auto& out)
  178. {
  179. auto value = JSONTo <int>(in);
  180. return DebugSignal(value);
  181. };
  182. Disp->Action.Push("DebugSignal", fun_DebugSignal);
  183. auto fun_SendSignal = [this](auto in, auto& out)
  184. {
  185. ResDataObject json;
  186. json.decode(in.c_str());
  187. auto value = (string)json[0];
  188. return SendSignal(value);
  189. };
  190. Disp->Action.Push("SendSignal", fun_SendSignal);
  191. //曝光流程
  192. auto fun_SetExposureProcess = [this](auto in, auto& out)
  193. {
  194. auto value = JSONTo <int>(in);
  195. return SetExposureProcess(value);
  196. };
  197. Disp->Action.Push("SetExposureProcess", fun_SetExposureProcess);
  198. //压迫器手动释放按键
  199. auto fun_SetPressureManualRelease = [this](auto in, auto& out)
  200. {
  201. return SetPressureManualRelease();
  202. };
  203. Disp->Action.Push("SetPressureManualRelease", fun_SetPressureManualRelease);
  204. //震动栅起振
  205. auto fun_StartVibrateGrid = [this](auto in, auto& out)
  206. {
  207. return StartVibrateGrid();
  208. };
  209. Disp->Action.Push("StartVibrateGrid", fun_StartVibrateGrid);
  210. auto fun_StopVibrateGrid = [this](auto in, auto& out)
  211. {
  212. return StopVibrateGrid();
  213. };
  214. Disp->Action.Push("StopVibrateGrid", fun_StopVibrateGrid);
  215. }
  216. void nsSYN::SyncBoxDevice::FireNotify(std::string key, std::string content)
  217. {
  218. EventCenter->OnNotify(1, key, content);
  219. }
  220. void nsSYN::SyncBoxDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
  221. {
  222. string ErrorCode("SYNBOX_ERR_");
  223. ErrorCode += std::to_string(Code);
  224. int level = 0;
  225. if (Act)
  226. {
  227. mLog::Error("add {$}:{$}", ErrorCode.c_str(), ResInfo);
  228. m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
  229. }
  230. else
  231. {
  232. mLog::Error("del {$}:{$}", ErrorCode.c_str(), ResInfo);
  233. m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
  234. }
  235. }
  236. RET_STATUS nsSYN::SyncBoxDevice::HWSend(char* strCommand, int nTimeOut)
  237. {
  238. if (!m_SCF) return RET_STATUS::RET_FAILED;
  239. if (strncmp(strCommand, "CS", 2) != 0)
  240. mLog::Info("==OUT==:[{$}],len=[{$}]\n", strCommand, strlen((char*)strCommand));
  241. int retLength;
  242. m_SCF.Lock(msTimeOut_Lock)
  243. .SendPacket((char*)strCommand, strlen((char*)strCommand), nTimeOut, retLength);
  244. SetWaitAction(strCommand);
  245. return RET_STATUS::RET_SUCCEED;
  246. }
  247. RET_STATUS nsSYN::SyncBoxDevice::SendBySCF(const char* chChannelID, bool bStatus)
  248. {
  249. char cCmd[MAX_COMMAND_LEN] = { 0 };
  250. cCmd[0] = chChannelID[0];
  251. cCmd[1] = chChannelID[1];
  252. if (bStatus)
  253. cCmd[2] = '1';
  254. else
  255. cCmd[2] = '0';
  256. int nSize = 3;
  257. FormatCmd(cCmd, nSize);
  258. string strLog;
  259. CmdtoString(cCmd, nSize, strLog);
  260. mLog::Info("[Send:{$}]", cCmd);
  261. if (!m_SCF)
  262. {
  263. mLog::Error("SCF is NULL");
  264. return RET_STATUS::RET_FAILED;
  265. }
  266. mLog::Info("==OUT==:[{$}]", cCmd);
  267. int ret = 0;
  268. m_SCF.Lock(msTimeOut_Lock)
  269. .SendPacket(cCmd, nSize, TIMEOUTVALUE, ret);
  270. SetWaitAction(cCmd);
  271. return RET_STATUS::RET_SUCCEED;
  272. }
  273. void nsSYN::SyncBoxDevice::SendHeartBeat()
  274. {
  275. int nTimeout = 100;
  276. int ret = 0;
  277. if(m_bCanLogEnableFlag)
  278. mLog::Info("==OUT==: heartbeat[{$}] ", cCmd_heartbeat);
  279. m_SCF.Lock(msTimeOut_Lock)
  280. .SendPacket(cCmd_heartbeat, 4, nTimeout, ret);
  281. SetWaitAction(cCmd_heartbeat);
  282. }
  283. bool nsSYN::SyncBoxDevice::StartHardwareThread()
  284. {
  285. mLog::Info("enter Start HardwareStatus Thread ");
  286. if (m_pHardwareThread == NULL)
  287. {
  288. DWORD m_HardwareStatusID;
  289. m_pHardwareThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
  290. if (m_pHardwareThread == NULL)
  291. {
  292. mLog::Error("Start HardwareStatus Thread Failed");
  293. return false;
  294. }
  295. }
  296. return true;
  297. }
  298. DWORD nsSYN::SyncBoxDevice::HardwareStatusThread(LPVOID pParam)
  299. {
  300. SyncBoxDevice* pCurSyn = (SyncBoxDevice*)pParam;
  301. if (pCurSyn == NULL)
  302. {
  303. return false;
  304. }
  305. mLog::Info("HardwareStatusThread start");
  306. if (pCurSyn->m_SYNConfig.GetKeyCount("HeartBeatEnable") > 0)
  307. m_bHeartBeatFlag = (int)pCurSyn->m_SYNConfig["HeartBeatEnable"];
  308. if (pCurSyn->m_SYNConfig.GetKeyCount("CANHBEnable") > 0)
  309. m_bCANHBFlag = (int)pCurSyn->m_SYNConfig["CANHBEnable"];
  310. mLog::Info("m_bHeartBeatFlag[{$}], m_bCANHBFlag[{$}]", m_bHeartBeatFlag, m_bCANHBFlag);
  311. int nGetCANData = 3;
  312. DWORD event = 0;
  313. bool bExit = false;
  314. while (!bExit)
  315. {
  316. event = WaitForMultipleObjects(2, pCurSyn->m_hArrayEvent, FALSE, INFINITE);
  317. switch (event)
  318. {
  319. case WAIT_OBJECT_0:
  320. {
  321. mLog::Debug("HardwareStatusThread: exited");
  322. bExit = true;
  323. break;
  324. }break;
  325. case (WAIT_TIMEOUT):
  326. {
  327. mLog::Warn("HardwareStatusThread: Get loop EVENT timeout");
  328. }
  329. case (WAIT_OBJECT_0 + 1):
  330. {
  331. if (m_bHeartBeatFlag) //心跳检测
  332. {
  333. //判断是否断连
  334. if (pCurSyn->m_iConnectFlag == 0)
  335. {
  336. mLog::Info("V2COM: not Connect,try to reconnect \n");
  337. if (false == pCurSyn->ReConnect())
  338. Sleep(30000);
  339. continue;
  340. }
  341. int tempHeartBeat = pCurSyn->m_iHeartBeats;
  342. if (tempHeartBeat > 9) //无返回信息认为连接断开
  343. {
  344. pCurSyn->m_iHeartBeats = 0;
  345. pCurSyn->m_iConnectFlag = 0;
  346. pCurSyn->ReConnect();
  347. pCurSyn->FireErrorMessage(true, 1, "lost Connect");
  348. continue;
  349. }
  350. else
  351. {
  352. if (pCurSyn->m_iConnectFlag == 1)
  353. {
  354. mLog::Info("reconnected: try send HeartBeat");
  355. pCurSyn->m_iConnectFlag = 2;
  356. }
  357. else if (pCurSyn->m_iConnectFlag == 2)
  358. {
  359. mLog::Info("reconnected: send HeartBeat filed");
  360. pCurSyn->m_iConnectFlag = 0;
  361. continue;
  362. }
  363. if (pCurSyn->m_SynBoxUnit.m_GenSynState->Get() != AttrKey::GENERATOR_RAD_OFF ||
  364. pCurSyn->m_SynBoxUnit.m_GenSynState->Get() != AttrKey::GENERATOR_RAD_XRAYOFF)
  365. {
  366. pCurSyn->SendHeartBeat();
  367. pCurSyn->m_iHeartBeats++;
  368. }
  369. else
  370. {
  371. mLog::Debug("In Gen Expo,not Send HeartBeat");
  372. }
  373. }
  374. }
  375. else
  376. {
  377. //mLog::Debug("stop Serial HeartBeat");
  378. }
  379. //定时查询CAN信息
  380. if (m_bCANHBFlag)
  381. {
  382. if (pCurSyn->m_iConnectFlag == 3)
  383. {
  384. if (pCurSyn->m_SynBoxUnit.m_GenSynState->Get() == AttrKey::GENERATOR_RAD_OFF ||
  385. pCurSyn->m_SynBoxUnit.m_GenSynState->Get() == AttrKey::GENERATOR_RAD_XRAYOFF)
  386. {
  387. if (pCurSyn->m_pCollDev != nullptr || pCurSyn->m_pMechDev != nullptr)
  388. pCurSyn->QueryInfo();
  389. }
  390. else
  391. {
  392. mLog::Debug("HardwareStatusThread: In Gen Expo,not Query CAN Info");
  393. }
  394. }
  395. }
  396. else
  397. {
  398. if (nGetCANData && pCurSyn->m_iConnectFlag == 3)
  399. {
  400. if (pCurSyn->m_SynBoxUnit.m_GenSynState->Get() == AttrKey::GENERATOR_RAD_OFF ||
  401. pCurSyn->m_SynBoxUnit.m_GenSynState->Get() == AttrKey::GENERATOR_RAD_XRAYOFF)
  402. {
  403. if (pCurSyn->m_pCollDev != nullptr || pCurSyn->m_pMechDev != nullptr)
  404. {
  405. pCurSyn->QueryInfo();
  406. nGetCANData--;
  407. }
  408. }
  409. else
  410. {
  411. mLog::Debug("HardwareStatusThread: In Gen Expo,not Query CAN Info");
  412. }
  413. }
  414. }
  415. if (WAIT_OBJECT_0 == WaitForSingleObject(pCurSyn->m_hLoopEndEvent,5000))
  416. {
  417. mLog::Warn("HardwareStatusThread: stop wait immediately");
  418. }
  419. }break;
  420. default:
  421. {
  422. mLog::Debug("HardwareStatusThread: unknown event");
  423. }break;
  424. }
  425. }
  426. pCurSyn->m_pHardwareThread = NULL;
  427. mLog::Info("HardwareStatusThread stop");
  428. return true;
  429. }
  430. bool nsSYN::SyncBoxDevice::ReConnect()
  431. {
  432. mLog::Info("Enter V2COMBox_reConnect");
  433. //SetCANState(false);
  434. m_SCF.Disconnect();
  435. if (!pIODriver)
  436. {
  437. mLog::Info("V2COMBox_reConnect:Driver null");
  438. }
  439. else if (pIODriver->ReConnection(m_SCF))
  440. {
  441. mLog::Info("reconnected:build connect, try send HeartBeat");
  442. m_iConnectFlag = 1;
  443. return true;
  444. }
  445. else
  446. {
  447. mLog::Info("reconnect failed");
  448. }
  449. return false;
  450. }
  451. RET_STATUS nsSYN::SyncBoxDevice::DebugSignal(bool flag)
  452. {
  453. mLog::Info("DebugSignal:{$}", flag);
  454. if (m_bDebugSignal != flag)
  455. {
  456. m_bDebugSignal = flag;
  457. }
  458. return RET_STATUS::RET_SUCCEED;
  459. }
  460. RET_STATUS nsSYN::SyncBoxDevice::SendSignal(string signal)
  461. {
  462. mLog::Info("SendSignal:{$}", signal.c_str());
  463. if (m_bDebugSignal)
  464. {
  465. string strChannel = signal.substr(0, 2);
  466. bool bStatus = ChartoInt(signal[2]);
  467. SendBySCF(strChannel.c_str(), bStatus);
  468. }
  469. return RET_STATUS::RET_SUCCEED;
  470. }
  471. //SYN方法
  472. void nsSYN::SyncBoxDevice::SetCANState(bool state)
  473. {
  474. int nTimeout = 100;
  475. auto ResDYNConfig = m_SYNConfig["DeviceConfig"];
  476. char cCmd[MAX_COMMAND_LEN] = { 0 };
  477. string CANProtocol = (string)ResDYNConfig["CANPortocol"];
  478. string CANBaud = (string)ResDYNConfig["CANBaud"];
  479. int nCmdSize = 0;
  480. if (CANProtocol == "1")
  481. {
  482. cCmd[0] = 'G';
  483. }
  484. else
  485. {
  486. cCmd[0] = 'C';
  487. }
  488. if (state)
  489. {
  490. cCmd[1] = 'O';
  491. mLog::Info("OpenCAN");
  492. cCmd[2] = 4;// CANBaud[0];
  493. //string CANFilter = (string)ResDYNConfig["CANFilter"];//
  494. //if (CANFilter.length() >= 4)
  495. //{
  496. // cCmd[3] = atoi(CANFilter.substr(0,2).c_str());//
  497. // cCmd[4] = atoi(CANFilter.substr(2, 4).c_str());//
  498. //}
  499. //else
  500. //{
  501. // cCmd[3] = 0xFF;
  502. // cCmd[4] = 0x00;
  503. //}
  504. cCmd[3] = 0x00;
  505. cCmd[4] = 0xFE;
  506. nCmdSize = 5;
  507. }
  508. else
  509. {
  510. cCmd[1] = 'C';
  511. cCmd[2] = '0';
  512. mLog::Info("CloseCAN");
  513. nCmdSize = 3;
  514. }
  515. FormatCmd(cCmd, nCmdSize);
  516. string strLog;
  517. CmdtoString(cCmd, nCmdSize, strLog);
  518. mLog::Info("Send:[{$}]", strLog.c_str());
  519. //printf("[Send:%s]\n", strLog.c_str());
  520. mLog::Info("==OUT==:[{$}]", cCmd);
  521. int ret = 0;
  522. m_SCF.Lock(msTimeOut_Lock)
  523. .SendPacket(cCmd, nCmdSize, nTimeout, ret);
  524. Sleep(nTimeout);
  525. }
  526. RET_STATUS nsSYN::SyncBoxDevice::SetWS(std::string value)
  527. {
  528. if (ResDYNConfig.GetFirstOf(value.c_str()) >= 0)
  529. {
  530. m_SynBoxUnit.m_WS->Update(value);
  531. string wsSYNValue = (string)ResDYNConfig[value.c_str()];
  532. if (wsSYNValue.find("SYN") != string::npos)
  533. {
  534. m_strSYNMode = wsSYNValue;
  535. }
  536. else
  537. {
  538. m_strSYNMode = "SYN" + wsSYNValue;
  539. }
  540. }
  541. else
  542. {
  543. m_strSYNMode = "SYN0";
  544. }
  545. return RET_STATUS::RET_SUCCEED;
  546. }
  547. RET_STATUS nsSYN::SyncBoxDevice::SetExpMode(std::string value)
  548. {
  549. m_SynBoxUnit.m_ExpMode->Update(value);
  550. mLog::Info("SetExpMode {$}", value.c_str());
  551. //add for dcm img hard
  552. if (m_pCollDev != nullptr)
  553. {
  554. mLog::Info("act CollDev ReportMessageToDicom");
  555. m_pCollDev->ReportMessageToDicom();
  556. }
  557. if (m_pMechDev != nullptr)
  558. {
  559. mLog::Info("act MechDev ReportMessageToDicom");
  560. m_pMechDev->ReportMessageToDicom();
  561. }
  562. return RET_STATUS::RET_SUCCEED;
  563. }
  564. RET_STATUS nsSYN::SyncBoxDevice::Reset()
  565. {
  566. SetGenAECSignal(0);
  567. return RET_STATUS::RET_SUCCEED;
  568. }
  569. RET_STATUS nsSYN::SyncBoxDevice::SimulateFootSwitchSignal(int signal)
  570. {
  571. return RET_STATUS::RET_SUCCEED;
  572. }
  573. RET_STATUS nsSYN::SyncBoxDevice::SetValue_PPS(FLOAT fluframerate)
  574. {
  575. return RET_STATUS::RET_SUCCEED;
  576. }
  577. //串口处理
  578. int nsSYN::SyncBoxDevice::DealtheSignal(const char* channel, int state)
  579. {
  580. string strchannel = channel;
  581. int nState = -1;
  582. string strSignalName = "";
  583. if (ResDYNConfig.GetFirstOf(m_strSYNMode.c_str()) < 0)
  584. {
  585. mLog::Error("Didn't find SynMode : {$}", m_strSYNMode.c_str());
  586. return -1;
  587. }
  588. if (ResDYNConfig[m_strSYNMode.c_str()].GetFirstOf(m_SynBoxUnit.m_ExpMode->JSGet().c_str()) < 0)
  589. {
  590. mLog::Error("Didn't find CurrentExamMode : {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  591. return -1;
  592. }
  593. mLog::Info("CurrentExamMode = {$}, strchannel = {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str(), strchannel.c_str());
  594. int count = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"].size();
  595. for (int i = 0; i < count; i++)
  596. {
  597. string strKey = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"].GetKey(i);
  598. string confchannel = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strKey.c_str()]["CHANNEL"];
  599. //mLog::Info("strKey = {$}, confchannel = {$}", strKey.c_str(), confchannel.c_str());
  600. if (confchannel == strchannel)
  601. {
  602. strSignalName = strKey;
  603. nState = state;
  604. mLog::Info("Signal Name = {$}, state = {$},GenSynState = {$},AECStatus = {$},GridStatus = {$}",
  605. strSignalName.c_str(), nState, m_SynBoxUnit.m_GenSynState->Get(), m_bGenAECStatus.load(), m_iGridStatus.load());
  606. if (strSignalName == "GENPREP") //add by wxx:解决OT1信号在 配置 及 工作流中重复发送的问题
  607. {
  608. if (state == 1) //ER1
  609. {
  610. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  611. }
  612. else
  613. {
  614. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  615. SetGenAECSignal(3);
  616. }
  617. }
  618. else if (strSignalName == "GENREADY")
  619. {
  620. if (state == 1) //TB1
  621. {
  622. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  623. }
  624. else
  625. {
  626. if (m_SynBoxUnit.m_GenSynState->Get()!= AttrKey::GENERATOR_RAD_OFF)
  627. {
  628. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_PREPARE);
  629. }
  630. }
  631. }
  632. else if (strSignalName == "XWINDOWSTATUS")
  633. {
  634. if (state == 1)//PT1
  635. {
  636. if (m_bAECSecExpFlag == true)
  637. {
  638. m_bAECSecExpFlag = false;
  639. mLog::Info("send RW0 by RAD.workflows");
  640. SetSignal("GENAECCONTROL", 0); //控制AEC信号高
  641. return 1;
  642. }
  643. //主动获取发生器的ms
  644. if (m_bGenAECStatus < 2 && m_iGridStatus == 1)
  645. {
  646. #if Dios_V3
  647. if (m_pGenClient != NULL)
  648. {
  649. if (!m_pGenClient->IsClosed())
  650. {
  651. ResDataObject Request, Response;
  652. Request.add("P0", 0);
  653. m_pGenClient->Action("GetVibrationGridMS", Request, Response, 4993, "DIOS/DEVICE/Generator");
  654. string strMS = (const char*)Response;
  655. if(0 == atoi(strMS.c_str()))
  656. strMS = (const char*)Response["P0"];
  657. mLog::Debug("get[{$}] exp_time[{$}] from gen", Response.encode(), strMS.c_str());
  658. if (!strMS.empty())
  659. {
  660. int ExpTime = atoi(strMS.c_str());
  661. SetVibrateGridExpoTimes(ExpTime + GridMSMargin());
  662. }
  663. }
  664. else
  665. {
  666. mLog::Debug("V2COM_DM Client is Close");
  667. }
  668. }
  669. else
  670. {
  671. mLog::Debug("V2COM_DM Client is NULL");
  672. }
  673. #endif
  674. mLog::Info("send OW1 by RAD.workflows");
  675. SetSignal("VIBRATEGRIDSTART", 1);
  676. return 1;
  677. }
  678. //if (m_SynBoxUnit.m_GenSynState->Get() == AttrKey::GENERATOR_RAD_READY) //发送OT1收到PT1
  679. //m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  680. }
  681. else //PT0
  682. {
  683. if (m_SynBoxUnit.m_GenSynState->Get()!= AttrKey::GENERATOR_RAD_OFF)
  684. {
  685. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYOFF);
  686. }
  687. if (m_bGenAECStatus < 2 && m_iGridStatus == 1)
  688. {
  689. mLog::Info("send RW1 by RAD.workflows");
  690. SetSignal("GENAECCONTROL", 1);
  691. mLog::Info("send RT0 by RAD.workflows");
  692. SetSignal("GENEXPREQUEST", 0);
  693. mLog::Info("send OW0 by RAD.workflows");
  694. SetSignal("VIBRATEGRIDSTART", 0);
  695. return 1;
  696. }
  697. int tempAECStatus = m_bGenAECStatus;
  698. if (tempAECStatus)
  699. {
  700. mLog::Info("in AEC Mode: GenAECStatus[{$}],RT0 will send by workflows", tempAECStatus);
  701. return 1;
  702. }
  703. else
  704. {
  705. mLog::Info("in rad Mode: GenAECStatus[{$}],RT0 will send after recv PT0", tempAECStatus);
  706. }
  707. }
  708. }
  709. else if (strSignalName == "VIBRATEGRIDSTATUS")
  710. {
  711. if(state == 1) //PW1
  712. {
  713. if (m_bGenAECStatus == 1)
  714. {
  715. mLog::Info("send RW0 by RAD.workflows");
  716. SetSignal("GENAECCONTROL", 0); //控制AEC信号高
  717. return 1;
  718. }
  719. }
  720. else
  721. {
  722. mLog::Info("send RW1 by RAD.workflows");
  723. SetSignal("GENAECCONTROL", 1);
  724. }
  725. }
  726. if (strSignalName != "" && nState >= 0)
  727. {
  728. //NotifySignal(strSignalName.c_str(), nState);
  729. string strSetEnableSignal = (string)ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["SETENABLE"];
  730. string strSetDisableSignal = (string)ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["SETDISABLE"];
  731. if (nState == 1 && strSetEnableSignal != "")
  732. {
  733. if (strSetEnableSignal == "GENEXPREQUEST") //RT1
  734. {
  735. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_XRAYON);
  736. }
  737. string strRelaySignal = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["RELAY"];
  738. if (strRelaySignal != "")
  739. {
  740. mLog::Info("Set Enable Relay_Signal = {$},GenSynState = {$}", strSetEnableSignal.c_str(), m_SynBoxUnit.m_GenSynState->Get());
  741. SetMultipleSignal(strSetEnableSignal.c_str(), nState);
  742. }
  743. else
  744. {
  745. mLog::Info("Set Enable Signal = {$},GenSynState = {$}", strSetEnableSignal.c_str(), m_SynBoxUnit.m_GenSynState->Get());
  746. SetSignal(strSetEnableSignal.c_str(), nState);
  747. }
  748. }
  749. else if (nState == 0 && strSetDisableSignal != "")
  750. {
  751. if (strSetEnableSignal == "GENEXPREQUEST") //RT0
  752. {
  753. if (m_bGenAECStatus > 0 && m_SynBoxUnit.m_GenSynState->Get() != AttrKey::GENERATOR_RAD_OFF)
  754. {
  755. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  756. }
  757. }
  758. string strRelaySignal = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["INPUT"][strSignalName.c_str()]["RELAY"];
  759. if (strRelaySignal != "")
  760. {
  761. mLog::Info("Set Disable Relay_Signal = {$},GenSynState = {$}", strSetDisableSignal.c_str(), m_SynBoxUnit.m_GenSynState->Get());
  762. SetMultipleSignal(strSetEnableSignal.c_str(), nState);
  763. }
  764. else
  765. {
  766. mLog::Info("Set Disable Signal = {$},GenSynState = {$}", strSetDisableSignal.c_str(), m_SynBoxUnit.m_GenSynState->Get());
  767. SetSignal(strSetDisableSignal.c_str(), state);
  768. }
  769. }
  770. }
  771. return 1;
  772. }
  773. }
  774. mLog::Debug("finish DealtheSignal");
  775. return 0;
  776. }
  777. int nsSYN::SyncBoxDevice::NotifySignal(const char* name, int state)
  778. {
  779. string strname = name;
  780. mLog::Info("Send Notify : Name = {$}, State = {$}", name, state);
  781. if (strname == "HANDSWITCHPREP")
  782. {
  783. if (state)
  784. {
  785. m_SynBoxUnit.m_HandSwitchState->Update(1);
  786. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  787. }
  788. else
  789. {
  790. m_SynBoxUnit.m_HandSwitchState->Update(0);
  791. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  792. }
  793. }
  794. else if (strname == "HANDSWITCHREADY")
  795. {
  796. if (state)
  797. {
  798. m_SynBoxUnit.m_HandSwitchState->Update(2);
  799. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  800. }
  801. else
  802. {
  803. m_SynBoxUnit.m_HandSwitchState->Update(0);
  804. FireNotify(m_SynBoxUnit.m_HandSwitchState->GetKey(), m_SynBoxUnit.m_HandSwitchState->JSGet());
  805. }
  806. }
  807. return 2;
  808. }
  809. int nsSYN::SyncBoxDevice::SetMultipleSignal(const char* name, int state) //change by wxx:原截取字符串操作有问题
  810. {
  811. string strtemp = name;
  812. string strName = strtemp;
  813. bool lastFlag = false;
  814. std::size_t oldPos = 0;
  815. while (!strName.empty())
  816. {
  817. std::size_t findPos = strtemp.find(",", oldPos);
  818. if (findPos != string::npos)
  819. {
  820. strName = strtemp.substr(oldPos, findPos - oldPos);
  821. }
  822. else
  823. {
  824. strName = strtemp.substr(oldPos, strtemp.length() - oldPos);
  825. lastFlag = true;
  826. }
  827. if(strName.compare("GENAECCONTROL") == 0)
  828. {
  829. if (state)
  830. state = 0;
  831. else
  832. state = 1;
  833. }
  834. SetSignal(strName.c_str(), state);
  835. Sleep(10);
  836. if (lastFlag)
  837. {
  838. break;
  839. }
  840. else
  841. {
  842. oldPos = findPos + 1;
  843. }
  844. }
  845. }
  846. int nsSYN::SyncBoxDevice::SetSignal(const char* name, int state)
  847. {
  848. if (ResDYNConfig.GetFirstOf(m_strSYNMode.c_str()) < 0)
  849. {
  850. mLog::Error("Didn't find SynMode : {$}", m_strSYNMode.c_str());
  851. return -1;
  852. }
  853. if (ResDYNConfig[m_strSYNMode.c_str()].GetFirstOf(m_SynBoxUnit.m_ExpMode->JSGet().c_str()) < 0)
  854. {
  855. mLog::Error("Set Signal {$}, state {$} ", name, state);
  856. mLog::Error("Didn't find CurrentExamMode : {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  857. return -1;
  858. }
  859. string strChannel = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"][name]["CHANNEL"];
  860. if (strChannel != "")
  861. {
  862. mLog::Info("Set Signal {$}, state {$} ", name, state);
  863. SendBySCF(strChannel.c_str(), state);
  864. return 1;
  865. }
  866. return -1;
  867. }
  868. void nsSYN::SyncBoxDevice::ClearSignal()
  869. {
  870. if (ResDYNConfig.GetFirstOf(m_strSYNMode.c_str()) < 0)
  871. {
  872. mLog::Error("Didn't find SynMode : {$}", m_strSYNMode.c_str());
  873. return;
  874. }
  875. if (ResDYNConfig[m_strSYNMode.c_str()].GetFirstOf(m_SynBoxUnit.m_ExpMode->JSGet().c_str()) < 0)
  876. {
  877. mLog::Error("Didn't find CurrentExamMode : {$}", m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  878. return;
  879. }
  880. int nsize = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"].size();
  881. for (int i = 0; i < nsize; i++)
  882. {
  883. string strChannel = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"][i]["CHANNEL"];
  884. string name = ResDYNConfig[m_strSYNMode.c_str()][m_SynBoxUnit.m_ExpMode->JSGet().c_str()]["OUTPUT"].GetKey(i);
  885. mLog::Info("Clear Name :{$},CurrentExamMode ={$}", name.c_str(), m_SynBoxUnit.m_ExpMode->JSGet().c_str());
  886. if (strChannel != "" && "FRAMERATE" != name)
  887. {
  888. mLog::Info("Clear Signal {$} ", strChannel);
  889. SendBySCF(strChannel.c_str(), false);
  890. Sleep(10);
  891. }
  892. }
  893. return;
  894. }
  895. int nsSYN::SyncBoxDevice::SetPWM(float fpps)
  896. {
  897. return -1;
  898. }
  899. void nsSYN::SyncBoxDevice::DealtheHB(const char* channel, int state)
  900. {
  901. if(m_bCanLogEnableFlag)
  902. mLog::Info("==IN ==: DealtheHB[{$}] ", m_iConnectFlag.load());
  903. if (m_iConnectFlag == 2)
  904. {
  905. mLog::Info("reconnected: success");
  906. m_iConnectFlag = 3;
  907. FireErrorMessage(false, 1, "lost Connect");
  908. if (m_pCollDev != nullptr || m_pMechDev != nullptr)
  909. {
  910. mLog::Info("CANDevice ReStart");
  911. SetCANState(true);
  912. }
  913. }
  914. Sleep(1000);
  915. m_iHeartBeats = 0;
  916. }
  917. int nsSYN::SyncBoxDevice::GetConnectFlag()
  918. {
  919. return m_iConnectFlag;
  920. }
  921. //发生器方法
  922. RET_STATUS nsSYN::SyncBoxDevice::SetGeneratortoSyncStatus(int state)
  923. {
  924. string strStateName = "";
  925. int nstate = -1;
  926. mLog::Info(" SetGeneratortoSyncStatus :{$}", state);
  927. if (state == AttrKey::GENERATOR_FLU_OFF || state == AttrKey::GENERATOR_RAD_OFF)//如果是采集结束的消息,直接恢复同步盒状态
  928. {
  929. ClearSignal();
  930. }
  931. if (m_SynBoxUnit.m_GenSynState->Get() != state || state == AttrKey::GENERATOR_RAD_XRAYON || state == AttrKey::GENERATOR_RAD_XRAYOFF)
  932. {
  933. mLog::Info("switch :{$}", state);
  934. switch (state)
  935. {
  936. case AttrKey::GENERATOR_RAD_PREPARE:
  937. strStateName = "HANDSWITCHPREPREQUEST";
  938. nstate = 1;
  939. break;
  940. case AttrKey::GENERATOR_RAD_READY:
  941. strStateName = "HANDSWITCHREADYREQUEST";
  942. nstate = 1;
  943. break;
  944. case AttrKey::GENERATOR_RAD_OFF:
  945. /*strStateName = "HANDSWITCHREADYREQUEST";
  946. nstate = 0;
  947. ((DYNSyncBox*)GetDrvDPC())->SetSignal(strStateName.c_str(), state);
  948. Sleep(30);
  949. strStateName = "GENEXPREQUEST";
  950. nstate = 0;
  951. ((DYNSyncBox*)GetDrvDPC())->SetSignal(strStateName.c_str(), state);
  952. Sleep(30);
  953. strStateName = "HANDSWITCHPREPREQUEST";
  954. nstate = 0;*/
  955. break;
  956. case AttrKey::GENERATOR_FLU_READY:
  957. strStateName = "HANDSWITCHPREPREQUEST";
  958. nstate = 1;
  959. SetSignal(strStateName.c_str(), nstate);
  960. Sleep(30);
  961. strStateName = "HANDSWITCHREADYREQUEST";
  962. nstate = 1;
  963. break;
  964. case AttrKey::GENERATOR_FLU_OFF:
  965. /*strStateName = "HANDSWITCHREADYREQUEST";
  966. nstate = 0;
  967. ((DYNSyncBox*)GetDrvDPC())->SetSignal(strStateName.c_str(), nstate);
  968. Sleep(30);
  969. strStateName = "HANDSWITCHPREPREQUEST";*/
  970. break;
  971. case AttrKey::GENERATOR_RAD_XRAYON:
  972. strStateName = "GENEXPREQUEST";
  973. nstate = 1;
  974. break;
  975. case AttrKey::GENERATOR_RAD_XRAYOFF:
  976. if (m_SynBoxUnit.m_ExpMode->JSGet() != "ContinueSerial")
  977. {
  978. strStateName = "GENEXPREQUEST";
  979. nstate = 0;
  980. }
  981. break;
  982. default:
  983. strStateName = "";
  984. nstate = -1;
  985. break;
  986. }
  987. if (state == AttrKey::GENERATOR_FLU_OFF || state == AttrKey::GENERATOR_RAD_OFF)//如果是采集结束的消息,直接恢复同步盒状态
  988. {
  989. if (!m_bClear)
  990. {
  991. ClearSignal();
  992. m_bClear = true;
  993. }
  994. m_SynBoxUnit.m_GenSynState->Update(state);
  995. }
  996. else if (strStateName != "" && nstate >= 0)
  997. {
  998. m_bClear = false;
  999. SetSignal(strStateName.c_str(), nstate);
  1000. m_SynBoxUnit.m_GenSynState->Update(state);
  1001. }
  1002. }
  1003. else
  1004. {
  1005. mLog::Error("switch :{$}, PreSetGeneratortoSyncStatus=false", state);
  1006. }
  1007. return RET_STATUS::RET_SUCCEED;
  1008. }
  1009. RET_STATUS nsSYN::SyncBoxDevice::SetExpEnable()
  1010. {
  1011. return RET_STATUS::RET_SUCCEED;
  1012. }
  1013. RET_STATUS nsSYN::SyncBoxDevice::SetExpDisable()
  1014. {
  1015. return RET_STATUS::RET_SUCCEED;
  1016. }
  1017. RET_STATUS nsSYN::SyncBoxDevice::SetGenAECSignal(int signal)
  1018. {
  1019. mLog::Info("SetGenAECSignal:{$},AECMode:{$},VibrateGridMode:{$}", signal, m_bGenAECStatus.load(), m_iGridStatus.load());
  1020. switch (signal)
  1021. {
  1022. case -1://用于默认
  1023. {
  1024. m_bGenAECStatus = 0;
  1025. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
  1026. mLog::Info("do nothing by workflows");
  1027. }
  1028. break;
  1029. case 0://用于AEC预曝光初始阶段初始化
  1030. {
  1031. m_bGenAECStatus = 0;
  1032. mLog::Info("send RW1 by Preview.workflows");
  1033. SetSignal("GENAECCONTROL", 1); //控制AEC信号低
  1034. mLog::Info("send RT0 by RAD.workflows");
  1035. SetSignal("GENEXPREQUEST", 0);
  1036. mLog::Info("send OT0 by RAD.workflows");
  1037. SetSignal("DETREACQREQUEST", 0);
  1038. mLog::Info("send OW0 by RAD.workflows");
  1039. SetSignal("VIBRATEGRIDSTART", 0);
  1040. }
  1041. break;
  1042. case 1://用于VMX AEC预曝光开始
  1043. {
  1044. m_bGenAECStatus = 2;
  1045. mLog::Info("send RW0 by Preview.workflows");
  1046. SetSignal("GENAECCONTROL", 0); //Preview模式控制AEC信号高
  1047. }
  1048. break;
  1049. case 2://用于VMX AEC预曝光结束
  1050. {
  1051. if (m_bGenAECStatus)
  1052. {
  1053. m_bGenAECStatus--;
  1054. mLog::Info("send RW1 by Preview.workflows");
  1055. SetSignal("GENAECCONTROL", 1); //Preview模式控制AEC信号低
  1056. if (m_SynBoxUnit.m_GenSynState->Get() != AttrKey::GENERATOR_RAD_OFF)
  1057. {
  1058. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  1059. }
  1060. mLog::Info("send RT0 by RAD.workflows GenSynState = {$}", m_SynBoxUnit.m_GenSynState->Get());
  1061. SetSignal("GENEXPREQUEST", 0);
  1062. }
  1063. }
  1064. break;
  1065. case 3://用于VMX AEC正式曝光开始
  1066. {
  1067. if (m_bGenAECStatus)
  1068. {
  1069. mLog::Info("send RW0 by RAD.workflows");
  1070. SetSignal("GENAECCONTROL", 0); //控制AEC信号高
  1071. }
  1072. }
  1073. break;
  1074. case 4://用于VMX AEC正式曝光结束
  1075. {
  1076. if (m_bGenAECStatus)
  1077. {
  1078. m_bGenAECStatus = 0;
  1079. mLog::Info("send RW1 by RAD.workflows");
  1080. SetSignal("GENAECCONTROL", 1); //控制AEC信号低
  1081. }
  1082. mLog::Info("send RT0 by RAD.workflows");
  1083. SetSignal("GENEXPREQUEST", 0);
  1084. }
  1085. break;
  1086. case 5://用于PSG-MG5L AEC preview开启AEC
  1087. {
  1088. m_bGenAECStatus = 2;
  1089. mLog::Info("send RW0 by preview.workflows");
  1090. SetSignal("GENAECCONTROL", 0); //控制AEC信号高
  1091. }
  1092. break;
  1093. case 6://用于PSG-MG5L 尝试AEC预曝光关闭
  1094. {
  1095. if (m_bGenAECStatus)
  1096. {
  1097. m_bGenAECStatus--;
  1098. if (m_SynBoxUnit.m_GenSynState->Get()!= AttrKey::GENERATOR_RAD_OFF)
  1099. {
  1100. m_SynBoxUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_READY);
  1101. }
  1102. mLog::Info("send RW1 by Preview.workflows GenSynState = {$}", m_SynBoxUnit.m_GenSynState->Get());
  1103. SetSignal("GENAECCONTROL", 1); //控制AEC信号低
  1104. mLog::Info("send OT0 by Preview.workflows");
  1105. SetSignal("DETREACQREQUEST", 0);
  1106. }
  1107. }
  1108. break;
  1109. case 7://用于PSG-MG5L AEC rad开启AEC
  1110. {
  1111. if (m_iGridStatus != 1)
  1112. {
  1113. if (m_bGenAECStatus)
  1114. {
  1115. //mLog::Info("send RW0 by RAD.workflows");
  1116. //SetSignal("GENAECCONTROL", 0); //控制AEC信号高
  1117. m_bAECSecExpFlag = true;
  1118. }
  1119. }
  1120. else
  1121. {
  1122. mLog::Info("GridStatus is 1,not send RW0 by RAD.workflows");
  1123. }
  1124. }
  1125. break;
  1126. case 8://用于PSG-MG5L 尝试AEC正式曝光关闭
  1127. {
  1128. if (m_bGenAECStatus)
  1129. {
  1130. m_bGenAECStatus = 0;
  1131. mLog::Info("send RW1 by RAD.workflows");
  1132. SetSignal("GENAECCONTROL", 1); //控制AEC信号低
  1133. }
  1134. mLog::Info("send RT0 by RAD.workflows");
  1135. SetSignal("GENEXPREQUEST", 0);
  1136. mLog::Info("send OT0 by RAD.workflows");
  1137. SetSignal("DETREACQREQUEST", 0);
  1138. mLog::Info("send OW0 by RAD.workflows");
  1139. SetSignal("VIBRATEGRIDSTART", 0);
  1140. mLog::Debug("enable m_hLoopEvent");
  1141. SetEvent(m_hLoopBeginEvent);
  1142. }
  1143. break;
  1144. default:
  1145. mLog::Warn("SetGenAECSignal:can not deal with signal[{$}]", signal);
  1146. break;
  1147. }
  1148. return RET_STATUS::RET_SUCCEED;
  1149. }
  1150. //探测器方法
  1151. RET_STATUS nsSYN::SyncBoxDevice::PrepareAcquisition()
  1152. {
  1153. return RET_STATUS::RET_SUCCEED;
  1154. }
  1155. RET_STATUS nsSYN::SyncBoxDevice::StartWindowRequest()
  1156. {
  1157. if (m_SynBoxUnit.m_GenSynState->Get() == AttrKey::GENERATOR_RAD_READY) //add by wxx:解决OT1信号在 配置 及 工作流中重复发送的问题
  1158. {
  1159. mLog::Info("send OT1 by workflows");
  1160. Sleep(1000);
  1161. SetSignal("DETREACQREQUEST", 1);
  1162. }
  1163. else
  1164. {
  1165. if(m_bGenAECStatus)
  1166. mLog::Info("there is already send OT1 in this AEC Exposure");
  1167. else
  1168. mLog::Info("there is not start Exposure yet");
  1169. }
  1170. return RET_STATUS::RET_SUCCEED;
  1171. }
  1172. RET_STATUS nsSYN::SyncBoxDevice::StopWindowRequest()
  1173. {
  1174. mLog::Info("send OT0 by workflows");
  1175. SetSignal("DETREACQREQUEST", 0);
  1176. return RET_STATUS::RET_SUCCEED;
  1177. }
  1178. RET_STATUS nsSYN::SyncBoxDevice::SetExposureTimes(int nNum)
  1179. {
  1180. mLog::Debug("Enter SetExposureTimes:[{$}]", nNum);
  1181. m_nExpTimes = nNum;
  1182. if (m_pMechDev != nullptr)
  1183. {
  1184. SetVibrateGridExpoTimes(nNum);
  1185. }
  1186. else
  1187. {
  1188. mLog::Warn("m_pMechDev is null");
  1189. }
  1190. return RET_STATUS::RET_SUCCEED;
  1191. }
  1192. RET_STATUS nsSYN::SyncBoxDevice::SetFrameRate(FLOAT frameRate)
  1193. {
  1194. SetPWM(frameRate);
  1195. return RET_STATUS::RET_SUCCEED;
  1196. }
  1197. //机架、遮光器处理
  1198. RET_STATUS nsSYN::SyncBoxDevice::SetCollimatorDev(OemCollimator* dev)
  1199. {
  1200. if (dev)
  1201. {
  1202. m_pCollDev.reset(dev);
  1203. if (m_pMechDev != nullptr)
  1204. {
  1205. mLog::Info("CANDevice start");
  1206. SetCANState(true);
  1207. }
  1208. //默认SID
  1209. if (m_SYNConfig.GetKeyCount("DefaultSID") > 0)
  1210. {
  1211. m_iConfSID = (int)m_SYNConfig["DefaultSID"];
  1212. m_pCollDev->UpdateCollimatorSID(m_iConfSID);
  1213. }
  1214. }
  1215. return RET_STATUS::RET_SUCCEED;
  1216. }
  1217. RET_STATUS nsSYN::SyncBoxDevice::SetMechDev(OemMechanical* dev)
  1218. {
  1219. if (dev)
  1220. {
  1221. m_pMechDev.reset(dev);
  1222. if (m_pCollDev != nullptr)
  1223. {
  1224. mLog::Info("CANDevice start");
  1225. SetCANState(true);
  1226. }
  1227. //无效压力闯值
  1228. if (m_SYNConfig.GetKeyCount("InvalidPressureThreshold") > 0)
  1229. {
  1230. int cfgValue = (int)m_SYNConfig["InvalidPressureThreshold"];
  1231. if(m_pMechDev != nullptr)
  1232. m_pMechDev->UpdateMammo_PressureErrorValue((unsigned int)cfgValue);
  1233. }
  1234. }
  1235. return RET_STATUS::RET_SUCCEED;
  1236. }
  1237. //立柱板节点
  1238. RET_STATUS nsSYN::SyncBoxDevice::SetConfigInfo(int nPanelType, int nRobotArmAngle)
  1239. {
  1240. if (nRobotArmAngle < 30 || nRobotArmAngle > 60)
  1241. return RET_STATUS::RET_SUCCEED;
  1242. BYTE data[16];
  1243. data[0] = 0x43; //C
  1244. data[1] = 0x53; //S
  1245. data[2] = 0x94; //ID:0x4A0
  1246. data[3] = 0x08;
  1247. data[4] = 0x00;
  1248. data[5] = 0x02;
  1249. data[6] = nPanelType;//平板选择:1.ANRAD;2.VARIAN;3.CAREVIEW
  1250. data[7] = nRobotArmAngle;//C臂MLO位:角度30-60
  1251. data[8] = 0x00;
  1252. data[9] = 0x00;
  1253. data[10] = 0x00;
  1254. data[11] = 0x00;
  1255. data[12] = 0x0D;
  1256. data[13] = 0x0A;
  1257. data[14] = 0x0;
  1258. //不确定是否需要转0--->0x30
  1259. for (int i = 0; i <= 13; i++)
  1260. {
  1261. if (data[i] == 0)
  1262. data[i] = 0x30;
  1263. }
  1264. return HWSend((char*)data);
  1265. }
  1266. RET_STATUS nsSYN::SyncBoxDevice::SetPhotographyMode(int nExpoMode, int nAECfield, int nAECdensity)
  1267. {
  1268. BYTE data[16];
  1269. data[0] = 0x43; //C
  1270. data[1] = 0x53; //S
  1271. data[2] = 0x94; //ID:0x4A0
  1272. data[3] = 0x08;
  1273. data[4] = 0x00;
  1274. data[5] = 0x03;
  1275. data[6] = nExpoMode;//曝光模式:1-4(1-3为自动,4手动);6(48KV);8(校准)
  1276. data[7] = nAECfield;
  1277. data[8] = nAECdensity;
  1278. data[9] = 0x00;
  1279. data[10] = 0x00;
  1280. data[11] = 0x00;
  1281. data[12] = 0x0D;
  1282. data[13] = 0x0A;
  1283. data[14] = 0x0;
  1284. //不确定是否需要转0--->0x30
  1285. for (int i = 0; i <= 13; i++)
  1286. {
  1287. if (data[i] == 0)
  1288. data[i] = 0x30;
  1289. }
  1290. return HWSend((char*)data);
  1291. }
  1292. RET_STATUS nsSYN::SyncBoxDevice::SetExposureProcess(int nState)
  1293. {
  1294. mLog::Debug("Enter SetExposureProcess:[{$}]", nState);
  1295. //10 平板准备好
  1296. //20 发生器准备好
  1297. //30 曝光开始
  1298. //40 曝光结束
  1299. //50 流程结束
  1300. //61 "1:ANRAN平板未准备好; 2:ANRAN平板准备好"
  1301. BYTE data[16];
  1302. data[0] = 0x43; //C
  1303. data[1] = 0x53; //S
  1304. data[2] = 0x94; //ID:0x4A0
  1305. data[3] = 0x08;
  1306. data[4] = 0x00;
  1307. data[5] = 0x04;
  1308. data[6] = nState;
  1309. data[7] = 0x00;
  1310. data[8] = 0x00;
  1311. data[9] = 0x00;
  1312. data[10] = 0x00;
  1313. data[11] = 0x00;
  1314. data[12] = 0x0D;
  1315. data[13] = 0x0A;
  1316. data[14] = 0x0;
  1317. //不确定是否需要转0--->0x30
  1318. for (int i = 0; i <= 13; i++)
  1319. {
  1320. if (data[i] == 0)
  1321. data[i] = 0x30;
  1322. }
  1323. return HWSend((char*)data);
  1324. }
  1325. RET_STATUS nsSYN::SyncBoxDevice::SetSendMessageEnable(int enableFlag)
  1326. {
  1327. BYTE data[16];
  1328. data[0] = 0x43; //C
  1329. data[1] = 0x53; //S
  1330. data[2] = 0x94; //ID:0x4A0
  1331. data[3] = 0x08;
  1332. data[4] = 0x01;
  1333. data[5] = 0x13;//19
  1334. data[6] = enableFlag;//1.禁止给图像发报文 2:允许发送
  1335. data[7] = 0x00;
  1336. data[8] = 0x00;
  1337. data[9] = 0x00;
  1338. data[10] = 0x00;
  1339. data[11] = 0x00;
  1340. data[12] = 0x0D;
  1341. data[13] = 0x0A;
  1342. data[14] = 0x0;
  1343. //不确定是否需要转0--->0x30
  1344. for (int i = 0; i <= 13; i++)
  1345. {
  1346. if (data[i] == 0)
  1347. data[i] = 0x30;
  1348. }
  1349. return HWSend((char*)data);
  1350. }
  1351. //C臂控制板节点
  1352. RET_STATUS nsSYN::SyncBoxDevice::SetPressureLimit(int nforePressureLimit, int nAllPressureLimit)
  1353. {
  1354. BYTE data[16];
  1355. data[0] = 0x43; //C
  1356. data[1] = 0x53; //S
  1357. data[2] = 0x94; //ID:0x4A1
  1358. data[3] = 0x28;
  1359. data[4] = 0x01;
  1360. data[5] = 0x02;
  1361. data[6] = nforePressureLimit;
  1362. data[7] = nAllPressureLimit;
  1363. data[8] = 0x00;
  1364. data[9] = 0x00;
  1365. data[10] = 0x00;
  1366. data[11] = 0x00;
  1367. data[12] = 0x0D;
  1368. data[13] = 0x0A;
  1369. data[14] = 0x0;
  1370. //不确定是否需要转0--->0x30
  1371. for (int i = 0; i <= 13; i++)
  1372. {
  1373. if (data[i] == 0)
  1374. data[i] = 0x30;
  1375. }
  1376. return HWSend((char*)data);
  1377. }
  1378. RET_STATUS nsSYN::SyncBoxDevice::SetAutoTracking(int nAutoTracking)
  1379. {
  1380. mLog::Debug("Enter SetAutoTracking:[{$}]", nAutoTracking);
  1381. int cmdAutoTracking = 0;
  1382. switch (nAutoTracking)//释放类型:1.自动释放;2.手动释放
  1383. {
  1384. case 0://close
  1385. cmdAutoTracking = 2;
  1386. break;
  1387. case 1://open
  1388. cmdAutoTracking = 1;
  1389. break;
  1390. }
  1391. BYTE data[16];
  1392. data[0] = 0x43; //C
  1393. data[1] = 0x53; //S
  1394. data[2] = 0x94; //ID:0x4A1
  1395. data[3] = 0x28;
  1396. data[4] = 0x01;
  1397. data[5] = 0x03;
  1398. data[6] = m_bOppressiveMode;
  1399. data[7] = cmdAutoTracking;
  1400. data[8] = 0x00;
  1401. data[9] = 0x00;
  1402. data[10] = 0x00;
  1403. data[11] = 0x00;
  1404. data[12] = 0x0D;
  1405. data[13] = 0x0A;
  1406. data[14] = 0x0;
  1407. //不确定是否需要转0--->0x30
  1408. for (int i = 0; i <= 13; i++)
  1409. {
  1410. if (data[i] == 0)
  1411. data[i] = 0x30;
  1412. }
  1413. return HWSend((char*)data);
  1414. }
  1415. RET_STATUS nsSYN::SyncBoxDevice::SetGrid(unsigned int GridType)
  1416. {
  1417. mLog::Debug("Enter SetGrid:[{$}]", GridType);
  1418. int cmdGridType = 0;
  1419. switch (GridType)//振栅状态:1.图像IN;2.图像OUT;3.运动中
  1420. {
  1421. case 0://off
  1422. cmdGridType = 2;
  1423. break;
  1424. case 1://on
  1425. cmdGridType = 1;
  1426. break;
  1427. case 2://soft
  1428. return RET_STATUS::RET_SUCCEED;;
  1429. break;
  1430. }
  1431. BYTE data[16];
  1432. data[0] = 0x43; //C
  1433. data[1] = 0x53; //S
  1434. data[2] = 0x94; //ID:0x4A1
  1435. data[3] = 0x28;
  1436. data[4] = 0x01;
  1437. data[5] = 0x04;
  1438. data[6] = m_bGridMode;//振栅模式:1.正常模式;2.放大模式
  1439. data[7] = cmdGridType;
  1440. data[8] = 0x00;
  1441. data[9] = 0x00;
  1442. data[10] = 0x00;
  1443. data[11] = 0x00;
  1444. data[12] = 0x0D;
  1445. data[13] = 0x0A;
  1446. //不确定是否需要转0--->0x30
  1447. for (int i = 0; i <= 13; i++)
  1448. {
  1449. if (data[i] == 0)
  1450. data[i] = 0x30;
  1451. }
  1452. data[14] = 0x0;
  1453. return HWSend((char*)data);
  1454. }
  1455. RET_STATUS nsSYN::SyncBoxDevice::SetPressureManualRelease()
  1456. {
  1457. mLog::Debug("Enter SetPressureManualRelease");//当作自动释放触发
  1458. if (m_pMechDev && m_pMechDev->GetMammo_Depress() == 1)
  1459. {
  1460. BYTE data[16];
  1461. data[0] = 0x43; //C
  1462. data[1] = 0x53; //S
  1463. data[2] = 0x94; //ID:0x4A1
  1464. data[3] = 0x28;
  1465. data[4] = 0x01;
  1466. data[5] = 0x0B; //11
  1467. data[6] = 0x00;
  1468. data[7] = 0x00;
  1469. data[8] = 0x00;
  1470. data[9] = 0x00;
  1471. data[10] = 0x00;
  1472. data[11] = 0x00;
  1473. data[12] = 0x0D;
  1474. data[13] = 0x0A;
  1475. //不确定是否需要转0--->0x30
  1476. for (int i = 0; i <= 13; i++)
  1477. {
  1478. if (data[i] == 0)
  1479. data[i] = 0x30;
  1480. }
  1481. data[14] = 0x0;
  1482. return HWSend((char*)data);
  1483. }
  1484. else
  1485. {
  1486. mLog::Debug("SetPressureManualRelease:not auto release");
  1487. }
  1488. return RET_STATUS::RET_SUCCEED;
  1489. }
  1490. RET_STATUS nsSYN::SyncBoxDevice::SetRecvMessageEnable(bool enableFlag)
  1491. {
  1492. int cmdEnableFlag = 0;
  1493. switch (enableFlag)//1.禁止给图像发报文 2:允许发送
  1494. {
  1495. case 0://close
  1496. cmdEnableFlag = 1;
  1497. break;
  1498. case 1://open
  1499. cmdEnableFlag = 2;
  1500. break;
  1501. }
  1502. BYTE data[16];
  1503. data[0] = 0x43; //C
  1504. data[1] = 0x53; //S
  1505. data[2] = 0x94; //ID:0x4A1
  1506. data[3] = 0x28;
  1507. data[4] = 0x01;
  1508. data[5] = 0x15; //21
  1509. data[6] = cmdEnableFlag;
  1510. data[7] = 0x00;
  1511. data[8] = 0x00;
  1512. data[9] = 0x00;
  1513. data[10] = 0x00;
  1514. data[11] = 0x00;
  1515. data[12] = 0x0D;
  1516. data[13] = 0x0A;
  1517. //不确定是否需要转0--->0x30
  1518. for (int i = 0; i <= 13; i++)
  1519. {
  1520. if (data[i] == 0)
  1521. data[i] = 0x30;
  1522. }
  1523. data[14] = 0x0;
  1524. return HWSend((char*)data);
  1525. }
  1526. RET_STATUS nsSYN::SyncBoxDevice::QueryError()
  1527. {
  1528. BYTE data[16];
  1529. data[0] = 0x43; //C
  1530. data[1] = 0x53; //S
  1531. data[2] = 0x94; //ID:0x4A1
  1532. data[3] = 0x28;
  1533. data[4] = 0x01;
  1534. data[5] = 0x12; //18
  1535. data[6] = 0x00;
  1536. data[7] = 0x00;
  1537. data[8] = 0x00;
  1538. data[9] = 0x00;
  1539. data[10] = 0x00;
  1540. data[11] = 0x00;
  1541. data[12] = 0x0D;
  1542. data[13] = 0x0A;
  1543. //不确定是否需要转0--->0x30
  1544. for (int i = 0; i <= 13; i++)
  1545. {
  1546. if (data[i] == 0)
  1547. data[i] = 0x30;
  1548. }
  1549. data[14] = 0x0;
  1550. return HWSend((char*)data);
  1551. }
  1552. RET_STATUS nsSYN::SyncBoxDevice::SetFilter(int filter)
  1553. {
  1554. mLog::Debug("Enter SetFilter:[{$}]", filter);
  1555. int cmdFilter = 0;
  1556. //col滤过类型:1Mo,2Rh
  1557. if (filter == m_iFilterMO)
  1558. {
  1559. cmdFilter = 1;
  1560. }
  1561. if (filter == m_iFilterRH)
  1562. {
  1563. cmdFilter = 2;
  1564. }
  1565. BYTE data[16];
  1566. data[0] = 0x43; //C
  1567. data[1] = 0x53; //S
  1568. data[2] = 0x94; //ID:0x4A1
  1569. data[3] = 0x28;
  1570. data[4] = 0x01;
  1571. data[5] = 0x07;
  1572. data[6] = cmdFilter;
  1573. data[7] = 0x00;
  1574. data[8] = 0x00;
  1575. data[9] = 0x00;
  1576. data[10] = 0x00;
  1577. data[11] = 0x00;
  1578. data[12] = 0x0D;
  1579. data[13] = 0x0A;
  1580. data[14] = 0x0;
  1581. //不确定是否需要转0--->0x30
  1582. for (int i = 0; i <= 13; i++)
  1583. {
  1584. if (data[i] == 0)
  1585. data[i] = 0x30;
  1586. }
  1587. return HWSend((char*)data);
  1588. }
  1589. RET_STATUS nsSYN::SyncBoxDevice::QueryInfo()
  1590. {
  1591. char data[20] = { 0 };
  1592. data[0] = 0x43; //C
  1593. data[1] = 0x53; //S
  1594. data[2] = 0x94; //ID:0x4A1
  1595. data[3] = 0x28;
  1596. data[4] = 0x01;
  1597. data[5] = 0x08;
  1598. data[6] = 0x3F;
  1599. data[7] = 0x3F;
  1600. data[8] = 0x00;
  1601. data[9] = 0x00;
  1602. data[10] = 0x00;
  1603. data[11] = 0x00;
  1604. data[12] = 0x0D;
  1605. data[13] = 0x0A;
  1606. for (int i = 0; i <= 11; i++)
  1607. {
  1608. if (data[i] == 0)
  1609. data[i] = 0x30;
  1610. }
  1611. data[14] = 0x0;
  1612. return HWSend((char*)data);
  1613. }
  1614. //振动栅节点
  1615. RET_STATUS nsSYN::SyncBoxDevice::SetVibrateGridExpoTimes(int nTimes)
  1616. {
  1617. mLog::Debug("Enter SetVibrateGridExpoTimes:[{$}]", nTimes);
  1618. if(nTimes < 500 || nTimes > 2000)
  1619. return RET_STATUS::RET_SUCCEED;
  1620. //时间(高字节)
  1621. int gridHeight = nTimes / 256;
  1622. //时间(低字节)
  1623. int gridWidth = nTimes % 256;
  1624. BYTE data[16];
  1625. data[0] = 0x43; //C
  1626. data[1] = 0x53; //S
  1627. data[2] = 0x94; //ID:0x4A4
  1628. data[3] = 0x88;
  1629. data[4] = 0x04;
  1630. data[5] = 0x02;
  1631. data[6] = gridHeight;
  1632. data[7] = gridWidth;
  1633. data[8] = 0x00;
  1634. data[9] = 0x00;
  1635. data[10] = 0x00;
  1636. data[11] = 0x00;
  1637. data[12] = 0x0D;
  1638. data[13] = 0x0A;
  1639. data[14] = 0x0;
  1640. //不确定是否需要转0--->0x30
  1641. for (int i = 0; i <= 13; i++)
  1642. {
  1643. if (data[i] == 0)
  1644. data[i] = 0x30;
  1645. }
  1646. return HWSend((char*)data);
  1647. }
  1648. RET_STATUS nsSYN::SyncBoxDevice::StartVibrateGrid()
  1649. {
  1650. mLog::Debug("Enter StartVibrateGrid");
  1651. m_bVibrateGridReady = 0;
  1652. mLog::Info("send OW1 by workflows");
  1653. SetSignal("VIBRATEGRIDSTART", 1);
  1654. return RET_STATUS::RET_SUCCEED;
  1655. }
  1656. RET_STATUS nsSYN::SyncBoxDevice::StopVibrateGrid()
  1657. {
  1658. mLog::Debug("Enter StopVibrateGrid");
  1659. m_bVibrateGridReady = 0;
  1660. mLog::Info("send OW0 by workflows");
  1661. SetSignal("VIBRATEGRIDSTART", 0);
  1662. return RET_STATUS::RET_SUCCEED;
  1663. }
  1664. int nsSYN::SyncBoxDevice::GridMSMargin()
  1665. {
  1666. if (m_bGenAECStatus <= 0)
  1667. {
  1668. mLog::Debug("GridMSMargin:NOAEC GridMS[{$}]", m_iGridMSRadMargin);
  1669. return m_iGridMSRadMargin;
  1670. }
  1671. else
  1672. {
  1673. mLog::Debug("GridMSMargin:AEC GridMS[{$}]", m_iGridMSRadMargin);
  1674. return m_iGridMSAECMargin;
  1675. }
  1676. return 0;
  1677. }
  1678. //CAN口处理
  1679. void nsSYN::SyncBoxDevice::DealReceiveData(char* data_can, int length_can_data)
  1680. {
  1681. //暂时无用
  1682. if (length_can_data == 5)//CO4
  1683. {
  1684. //set baud ok.
  1685. if (data_can[2] == 0)
  1686. {
  1687. m_bSetBaudOK = true;
  1688. }
  1689. else
  1690. {
  1691. m_bSetBaudOK = false;
  1692. }
  1693. }
  1694. if (length_can_data == 4)//EC
  1695. {
  1696. //echo ok
  1697. }
  1698. int idHigh = (unsigned char)(data_can[2]);
  1699. int idLow = (unsigned char)(data_can[3]);
  1700. int cmdID = idHigh*225+idLow;
  1701. if (idHigh == 0x80 && idLow == 0xA8)//0x405
  1702. cmdID = 0x405;
  1703. else if (idHigh == 0x84 && idLow == 0xA8)//0x425
  1704. cmdID = 0x425;
  1705. else if (idHigh == 0x90 && idLow == 0xA8)//0x485
  1706. cmdID = 0x485;
  1707. idHigh = (unsigned char)(data_can[4]);
  1708. idLow = (unsigned char)(data_can[5]);
  1709. int cmdType = idHigh * 100 + idLow;
  1710. if(m_bCanLogEnableFlag)
  1711. mLog::Info("DealReceiveData:id[0x{$:x04}],type[{$},{$}->{$}],data[{$},{$},{$},{$}]",
  1712. cmdID, (int)data_can[4], (int)data_can[5], cmdType,(int)data_can[6], (int)data_can[7], (int)data_can[8], (int)data_can[9]);
  1713. if (cmdID == 0x405)//0x405:立柱板节点
  1714. {
  1715. switch (cmdType)
  1716. {
  1717. case 1://心跳报文
  1718. {
  1719. //recv 425 heart
  1720. //if (m_bCanLogEnableFlag)
  1721. // mLog::Debug("recv 405 : heart beat.");
  1722. }
  1723. break;
  1724. case 2://配置信息-回复
  1725. {
  1726. //平板选择:1.ANRAD;2.VARIAN;3.CAREVIEW
  1727. int nPanelType = (BYTE)data_can[6];
  1728. //C臂MLO位:角度30-60
  1729. int nML0Angle = (BYTE)data_can[7];
  1730. //if (m_pMechDev)
  1731. //{
  1732. // m_pMechDev->UpdateMammo_MechAngle(nML0Angle);
  1733. //}
  1734. if (m_bCanLogEnableFlag)
  1735. mLog::Debug("recv 405 : panelType[{$}] ,MLOangle[{$}]", nPanelType, nML0Angle);
  1736. }
  1737. break;
  1738. case 3://摄影模式选择-回复
  1739. {
  1740. //曝光模式:1-4(1-3为自动,4手动);6(48KV);8(校准)
  1741. int nExpoMode = (BYTE)data_can[6];
  1742. //AEC区域(不判)
  1743. int nAECfield = (BYTE)data_can[7];
  1744. //AEC浓度(不判)
  1745. int nAECdensity = (BYTE)data_can[8];
  1746. if (m_bCanLogEnableFlag)
  1747. mLog::Debug("recv 425 : exposure mode[{$}],AECfield[{$}],AECdensity[{$}]", nExpoMode, nAECfield, nAECdensity);
  1748. }
  1749. break;
  1750. case 4://流程状态
  1751. {
  1752. //曝光流程报文
  1753. int nFlowsStatus = (BYTE)data_can[6];
  1754. switch (nFlowsStatus)
  1755. {
  1756. case 10:
  1757. {
  1758. if (m_bCanLogEnableFlag)
  1759. mLog::Debug("recv 405 : exposure workflows[FPD ready]");
  1760. }
  1761. break;
  1762. case 20:
  1763. {
  1764. if (m_bCanLogEnableFlag)
  1765. mLog::Debug("recv 405 : exposure workflows[GEN ready]");
  1766. }
  1767. break;
  1768. case 30:
  1769. {
  1770. if (m_bCanLogEnableFlag)
  1771. mLog::Debug("recv 405 : exposure workflows[EXPO begin]");
  1772. }
  1773. break;
  1774. case 40:
  1775. {
  1776. if (m_bCanLogEnableFlag)
  1777. mLog::Debug("recv 405 : exposure workflows[EXPO end]");
  1778. }
  1779. break;
  1780. case 50:
  1781. {
  1782. if (m_bCanLogEnableFlag)
  1783. mLog::Debug("recv 405 : exposure workflows[workFlows end]");
  1784. }
  1785. break;
  1786. case 61://平板状态
  1787. {
  1788. if (m_bCanLogEnableFlag)
  1789. {
  1790. int nPanelStatus = (BYTE)data_can[7];
  1791. if (nPanelStatus == 1)
  1792. mLog::Debug("recv 405 : exposure workflows[FPD not ready]");
  1793. else
  1794. mLog::Debug("recv 405 : exposure workflows[FPD ready]");
  1795. }
  1796. }
  1797. break;
  1798. default:
  1799. if (m_bCanLogEnableFlag)
  1800. mLog::Error("recv 405 : exposure workflows[{$}]Unrecognized", nFlowsStatus);
  1801. break;
  1802. }
  1803. int nValue = (BYTE)data_can[6];
  1804. //AEC区域(不判)
  1805. int nPanelStatus = (BYTE)data_can[7];
  1806. if (m_bCanLogEnableFlag)
  1807. mLog::Debug("recv 425 : [{$}],PanelStatus[{$}]", nValue, nPanelStatus);
  1808. }
  1809. break;
  1810. default:
  1811. if (m_bCanLogEnableFlag)
  1812. mLog::Debug("recv 405 : can not deal with[{$}]", cmdType);
  1813. break;
  1814. }
  1815. }
  1816. else if (cmdID == 0x425)//0x425:C臂控制板节点
  1817. {
  1818. switch (cmdType)
  1819. {
  1820. case 101://心跳报文
  1821. {
  1822. //recv 425 heart
  1823. //if (m_bCanLogEnableFlag)
  1824. // mLog::Debug("recv 425 : heart beat.");
  1825. }
  1826. break;
  1827. case 102://预压迫和全压迫设置信息-回复
  1828. {
  1829. if (m_pMechDev)
  1830. {
  1831. //预压迫压力限制值
  1832. int nPreCompPressureLimit = (BYTE)data_can[6];
  1833. //全压迫压力限制值
  1834. int nAllCompPressureLimit = (BYTE)data_can[7];
  1835. if (m_bCanLogEnableFlag)
  1836. mLog::Debug("recv 425 : PreCompPressureLimit[{$}],AllCompPressureLimit[{$}]", nPreCompPressureLimit, nAllCompPressureLimit);
  1837. }
  1838. }
  1839. break;
  1840. case 103://压迫和释放信息-回复
  1841. {
  1842. if (m_pMechDev)
  1843. {
  1844. //压迫模式:普通压迫(01); 预压迫(10); 全压迫(11)
  1845. int nCompPressureMode = (BYTE)data_can[6];
  1846. //压迫器:自动释放(01); 手动释放(10)
  1847. int nDepress = (BYTE)data_can[7];
  1848. switch ((int)data_can[7])//APP释放类型:1.open;2.close
  1849. {
  1850. case 1://自动释放
  1851. nDepress = 1;
  1852. break;
  1853. case 2://手动释放
  1854. nDepress = 0;
  1855. break;
  1856. default:
  1857. nDepress = m_pMechDev->GetMammo_Depress();
  1858. }
  1859. //if (m_bCanLogEnableFlag && m_pMechDev->GetMammo_CompPressureDEC()!=nCompPressureMode && m_pMechDev->GetMammo_Depress()!=nDepress)
  1860. // mLog::Debug("recv 425 : CompPressureMode[{$}->{$}],Auto release mode[{$}->{$}]",
  1861. // m_pMechDev->GetMammo_CompPressureDEC(), nCompPressureMode, m_pMechDev->GetMammo_Depress(), nDepress);
  1862. //m_pMechDev->UpdateMammo_CompPressureDEC(nCompPressureMode);//压缩机压力下降
  1863. if (m_bCanLogEnableFlag && m_pMechDev->GetMammo_Depress() != nDepress)
  1864. mLog::Debug("recv 425 : CompPressureMode[{$}],Auto release mode[{$}->{$}]",
  1865. nCompPressureMode, m_pMechDev->GetMammo_Depress(), nDepress);
  1866. m_pMechDev->UpdateMammo_Depress(nDepress);//vmi doc文档中,DF0 DF1 也表示自动释放
  1867. }
  1868. }
  1869. break;
  1870. case 104://振栅位置有变化,栅进出位置息-回复
  1871. {
  1872. //振栅模式:1.正常模式;2.放大模式
  1873. int nGridMode = (BYTE)data_can[6];//此处更像是mag
  1874. //振栅状态:1.图像IN;2.图像OUT;3.运动中
  1875. int nGridStatus = (BYTE)data_can[7];
  1876. switch ((int)data_can[7])//APP振栅状态:0.off;1.on;3.soft
  1877. {
  1878. case 1://图像IN
  1879. nGridStatus = 1;
  1880. break;
  1881. case 2://图像OUT
  1882. nGridStatus = 0;
  1883. break;
  1884. case 3://运动中
  1885. //m_iGridStatus = 2;
  1886. default:
  1887. nGridStatus = m_pMechDev->GetGrid();
  1888. break;
  1889. }
  1890. if (m_iGridStatus != nGridStatus)
  1891. {
  1892. m_iGridStatus = nGridStatus;
  1893. #if Dios_V3
  1894. if (m_pGenClient != NULL)
  1895. {
  1896. if (!m_pGenClient->IsClosed())
  1897. {
  1898. ResDataObject Request, Response;
  1899. Request.add("P0", nGridStatus);
  1900. m_pGenClient->Action("SetVibrationGrid", Request, Response, 4993, "DIOS/DEVICE/Generator");
  1901. mLog::Debug("V2COM_DM Client execute [SetVibrationGrid][{$}]",nGridStatus);
  1902. }
  1903. else
  1904. {
  1905. mLog::Debug("V2COM_DM Client is Close");
  1906. }
  1907. }
  1908. else
  1909. {
  1910. mLog::Debug("V2COM_DM Client is NULL");
  1911. }
  1912. #endif
  1913. }
  1914. if (m_pMechDev)
  1915. {
  1916. if (m_bCanLogEnableFlag && m_pMechDev->GetMammo_MAG()!=nGridMode && m_pMechDev->GetGrid()!=nGridStatus)
  1917. mLog::Debug("recv 425 : grid mode[{$}->{$}],gird status[{$}->{$}]",
  1918. m_pMechDev->GetMammo_MAG(), nGridMode, m_pMechDev->GetGrid(), nGridStatus);
  1919. m_pMechDev->UpdateMammo_MAG(nGridMode);
  1920. m_pMechDev->UpdateGrid(nGridStatus);
  1921. }
  1922. }
  1923. break;
  1924. case 105://压迫数据
  1925. {
  1926. //压迫厚度 - 用于显示
  1927. int nThickness = (BYTE)data_can[6];
  1928. //压迫压力-用于显示
  1929. int nPressValue = (BYTE)data_can[7];
  1930. if (m_pMechDev)
  1931. {
  1932. //change by wxx for 万东bug5975:实际设备厚度会超过100,放开限制
  1933. //if (nThickness > 100)//add by wxx for 万东:解决压迫厚度超限导致APR参数全为0
  1934. //{
  1935. // nThickness = 100;
  1936. //}
  1937. //else if (nThickness < 0)
  1938. //{
  1939. // nThickness = 0;
  1940. //}
  1941. }
  1942. if (m_pMechDev)
  1943. {
  1944. if (m_bCanLogEnableFlag && m_pMechDev->GetMammo_PressureState()!=nThickness && m_pMechDev->GetMammo_PressureValue()!=nPressValue)
  1945. mLog::Debug("recv 425 : thickness[{$}->{$}], pressvalue[{$}->{$}]",
  1946. m_pMechDev->GetMammo_PressureState(), nThickness, m_pMechDev->GetMammo_PressureValue(), nPressValue);
  1947. m_pMechDev->UpdateMammo_PressureState(nThickness);//note :thickness
  1948. m_pMechDev->UpdateMammo_PressureValue(nPressValue);
  1949. }
  1950. }
  1951. break;
  1952. case 6://C臂旋转角度
  1953. {
  1954. //C arm angle
  1955. int angle = (BYTE)data_can[7];
  1956. int nSign = (BYTE)data_can[6];
  1957. if (nSign == 2)
  1958. {
  1959. angle *= -1;
  1960. }
  1961. //if (m_bCanLogEnableFlag)
  1962. // mLog::Debug("recv 425 : CARM angle[{$}]", angle);
  1963. if (m_pCollDev)
  1964. {
  1965. if (m_bCanLogEnableFlag && m_pCollDev->GetCollimatorAngle()!=angle)
  1966. mLog::Debug("recv 425 : CollimatorAngle[{$}->{$}]", m_pCollDev->GetCollimatorAngle(), angle);
  1967. m_pCollDev->UpdateCollimatorAngle(angle);
  1968. }
  1969. if (m_pMechDev)
  1970. {
  1971. if (m_bCanLogEnableFlag && m_pMechDev->GetMammo_MechAngle()!=angle)
  1972. mLog::Debug("recv 425 : MechAngle[{$}->{$}]", m_pMechDev->GetMammo_MechAngle(), angle);
  1973. m_pMechDev->UpdateMammo_MechAngle(angle);
  1974. }
  1975. }
  1976. break;
  1977. case 106://限束器视野有变化
  1978. {
  1979. //光野长-高字节,光野长-低字节
  1980. int colHeight = (BYTE)data_can[6] * 256 + (BYTE)data_can[7];
  1981. //光野宽-高字节,光野宽-低字节
  1982. int colWidth = (BYTE)data_can[8] * 256 + (BYTE)data_can[9];
  1983. if (m_pCollDev)
  1984. {
  1985. if (m_bCanLogEnableFlag && m_pCollDev->GetCollimatorXSize()!=colWidth && m_pCollDev->GetCollimatorYSize()!=colHeight)
  1986. mLog::Debug("recv 425 : coll: x[{$}->{$}],y[{$}->{$}]",
  1987. m_pCollDev->GetCollimatorXSize(), colWidth, m_pCollDev->GetCollimatorYSize(), colHeight);
  1988. m_pCollDev->UpdateCollimatorXSize(colWidth);
  1989. m_pCollDev->UpdateCollimatorYSize(colHeight);
  1990. }
  1991. }
  1992. break;
  1993. case 107://限束器滤过变化MORH-回复
  1994. {
  1995. //col滤过类型:1Mo,2Rh
  1996. int nFilter = (BYTE)data_can[6];
  1997. //if (m_bCanLogEnableFlag)
  1998. //mLog::Debug("recv 425 : fileter[{$}]", nFilter);
  1999. if (m_pCollDev)
  2000. {
  2001. if (m_bCanLogEnableFlag && m_pCollDev->GetCollimatorFilter()!=nFilter)
  2002. mLog::Debug("recv 425 : CollimatorFilter[{$}->{$}]", m_pCollDev->GetCollimatorFilter(), nFilter);
  2003. m_pCollDev->UpdateCollimatorFilter(nFilter);
  2004. }
  2005. if (m_pMechDev)
  2006. {
  2007. if (m_bCanLogEnableFlag && m_pMechDev->GetMammo_FT() != nFilter)
  2008. mLog::Debug("recv 425 : MechFilter[{$}->{$}]", m_pMechDev->GetMammo_FT(), nFilter);
  2009. m_pMechDev->UpdateMammo_FT(nFilter);
  2010. }
  2011. }
  2012. break;
  2013. case 112://机架状态上报
  2014. {
  2015. int nStatus = (BYTE)data_can[6];
  2016. switch (nStatus)
  2017. {
  2018. case 0:
  2019. if (m_bCanLogEnableFlag)
  2020. mLog::Debug("recv 425 : status[no error]");
  2021. break;
  2022. case 1:
  2023. if (m_bCanLogEnableFlag)
  2024. mLog::Debug("recv 425 : status[Compressor initialization not in place]");//压迫器初始化未到位
  2025. break;
  2026. case 2:
  2027. if (m_bCanLogEnableFlag)
  2028. mLog::Debug("recv 425 : status[Compressor upper limit error]");//压迫器上限位错误
  2029. break;
  2030. case 3:
  2031. if (m_bCanLogEnableFlag)
  2032. mLog::Debug("recv 425 : status[Overvoltage error]");//过压错误
  2033. break;
  2034. case 4:
  2035. if (m_bCanLogEnableFlag)
  2036. mLog::Debug("recv 425 : status[Overcurrent error]");//过流错误
  2037. break;
  2038. case 5:
  2039. if (m_bCanLogEnableFlag)
  2040. mLog::Debug("recv 425 : status[Automatic release incomplete]");//自动释放未完成
  2041. break;
  2042. case 6:
  2043. if (m_bCanLogEnableFlag)
  2044. mLog::Debug("recv 425 : status[Beam limiter initialization successful]");//限束器初始化成功
  2045. break;
  2046. case 7:
  2047. if (m_bCanLogEnableFlag)
  2048. mLog::Debug("recv 425 : status[Release of oppression completed]");//压迫释放完成
  2049. break;
  2050. default:
  2051. if (m_bCanLogEnableFlag)
  2052. mLog::Debug("recv 425 : status[{$}] can not deal with", nStatus);
  2053. break;
  2054. }
  2055. }
  2056. break;
  2057. case 18://收到图像查询错误状态报文后回复
  2058. {
  2059. //1双电位器错误,0无错误
  2060. int nError = (BYTE)data_can[6];
  2061. if (m_bCanLogEnableFlag)
  2062. {
  2063. if (nError == 0)
  2064. mLog::Debug("recv 425 : no error");
  2065. else
  2066. mLog::Debug("recv 425 : Dual potentiometer error");//双电位器错误
  2067. }
  2068. }
  2069. break;
  2070. case 119://压迫板ID
  2071. {
  2072. //压迫板类型:1.大压迫板。2.小压迫板。3.放大摄影压迫板
  2073. int nPlateID = (BYTE)data_can[6];
  2074. std::string strPlateID = "";
  2075. if (m_pMechDev)
  2076. {
  2077. if (1 == nPlateID)
  2078. {
  2079. strPlateID = "Large compression plate";
  2080. }
  2081. else if (2 == nPlateID)
  2082. {
  2083. strPlateID = "Small compression plate";
  2084. }
  2085. else if (3 == nPlateID)
  2086. {
  2087. strPlateID = "Magnification compression plate";
  2088. }
  2089. if (m_bCanLogEnableFlag)
  2090. mLog::Info("recv 425 : CompressPaddle type[{$}]", nPlateID);
  2091. m_pMechDev->UpdateMammo_CompressPaddle(strPlateID);
  2092. }
  2093. }
  2094. break;
  2095. default:
  2096. if (m_bCanLogEnableFlag)
  2097. mLog::Debug("recv 425 : can not deal with[{$}]", cmdType);
  2098. break;
  2099. }
  2100. }
  2101. else if (cmdID == 0x485)//0x485:振动栅节点
  2102. {
  2103. switch (cmdType)
  2104. {
  2105. case 403://故障报文
  2106. {
  2107. //故障状态:0.正确 ;1.初始化错误
  2108. int nFailStatus = (BYTE)data_can[6];
  2109. if (m_bCanLogEnableFlag)
  2110. {
  2111. if(nFailStatus == 0)
  2112. mLog::Debug("recv 485 : Correct vibration grating");//振动栅正确
  2113. else
  2114. mLog::Debug("recv 485 : Vibration barrier initialization error");//振动栅初始化错误
  2115. }
  2116. }
  2117. break;
  2118. default:
  2119. if (m_bCanLogEnableFlag)
  2120. mLog::Debug("recv 485 : can not deal with[{$}]", cmdType);
  2121. break;
  2122. }
  2123. }
  2124. else
  2125. {
  2126. if (m_bCanLogEnableFlag)
  2127. {
  2128. switch (cmdID)
  2129. {
  2130. case 0x740c:
  2131. break;
  2132. case 0x70a8:
  2133. break;
  2134. default:
  2135. mLog::Debug("recv [{$:x04}] : can not deal with", cmdID);
  2136. break;
  2137. }
  2138. }
  2139. }
  2140. }
  2141. void nsSYN::SyncBoxDevice::OnCallBack()
  2142. {
  2143. mLog::Info("SyncBoxDevice::OnCallBack in");
  2144. auto HWDoNothing = [](const char* value, int length) -> void
  2145. {
  2146. };
  2147. auto HWNotProcess = [](const char* value, int length) -> void
  2148. {
  2149. mLog::Warn(" This commands didn't need to process!");
  2150. };
  2151. auto HWHB = [this](const char* value, int length) -> void
  2152. {
  2153. //assert(value && length >= 3);
  2154. char cChannelValue;
  2155. cChannelValue = value[2]; //status : on /off
  2156. string strChannel = ((string)value).substr(0, 2);
  2157. bool bStatus = ChartoInt(cChannelValue);
  2158. if (m_bCanLogEnableFlag)
  2159. mLog::Info("==IN ==:HWHB:{$}", value);
  2160. DealtheHB(strChannel.c_str(), bStatus);
  2161. };
  2162. auto HWSignal = [this](const char* value, int length) -> void
  2163. {
  2164. //assert(value && length >= 3);
  2165. char cChannelValue;
  2166. cChannelValue = value[2]; //status : on /off
  2167. string strChannel = ((string)value).substr(0, 2);
  2168. bool bStatus = ChartoInt(cChannelValue);
  2169. mLog::Info("==IN ==:HWSignal:{$:3}",value);
  2170. if (m_bDebugSignal)
  2171. {
  2172. FireNotify("RecvSignal", value);
  2173. }
  2174. if (strChannel == "TB")
  2175. {
  2176. if (bStatus)
  2177. {
  2178. mLog::Debug("disable m_hLoopEvent");
  2179. ResetEvent(m_hLoopBeginEvent);
  2180. SetEvent(m_hLoopEndEvent);
  2181. }
  2182. else
  2183. {
  2184. //mLog::Debug("enable m_hLoopEvent");
  2185. //SetEvent(m_hLoopBeginEvent);
  2186. }
  2187. }
  2188. DealtheSignal(strChannel.c_str(), bStatus);
  2189. };
  2190. /*
  2191. --485 立柱板节点
  2192. 43 52 80 A8 30 01 30 30 30 30 30 30 0D 0A --405 heart 振动栅节点
  2193. 43 52 84 A8 01 01 30 30 30 30 30 30 0D 0A --425 heart C臂控制板节点
  2194. 43 52 84 A8 01 07 01 30 30 30 30 30 0D 0A --filter 1
  2195. 43 52 84 A8 01 07 02 30 30 30 30 30 0D 0A --filtr 2
  2196. */
  2197. auto HWCAN = [this](const char* value, int length)
  2198. {
  2199. char data_can[MAX_COMMAND_LEN] = { 0 };
  2200. for (int i = 0; i < length; i++)
  2201. {
  2202. if (value[i] == 0x30)
  2203. data_can[i] = 0x0;
  2204. else if (value[i] == 0x61)
  2205. data_can[i] = 0x0a;
  2206. else if (value[i] == 0x64)
  2207. data_can[i] = 0x0d;
  2208. else
  2209. data_can[i] = value[i];
  2210. }
  2211. string strcmd = data_can;
  2212. string sCmdID = strcmd.substr(2, 2);
  2213. DealReceiveData(data_can, length);
  2214. };
  2215. // 有部分前缀是包含关系, 长的包含短的, 例如 KVS 包含了 KV.
  2216. // 因此长的在前面, 短的在后面
  2217. // !!! Device 是个短寿命对象, 而 arFrame 是静态变量 !!!
  2218. // !!! 因此, 在添加到 arFrame 之前, 务必先清零 !!!
  2219. arFrame.clear();
  2220. arFrame["CO"] = tFrameMapping(HWNotProcess, tFrameMapping::OverType_directly, false);
  2221. arFrame["CS"] = tFrameMapping(HWDoNothing , tFrameMapping::OverType_WaitTime, false, 100);
  2222. arFrame["EC"] = tFrameMapping(HWHB , tFrameMapping::OverType_WaitTime, false, 100);
  2223. arFrame["GR"] = tFrameMapping(HWCAN, tFrameMapping::OverType_WaitTime, false, 100);
  2224. arFrame["CR"] = tFrameMapping(HWCAN, tFrameMapping::OverType_WaitTime, false, 100);
  2225. arFrame["TB"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2226. arFrame["WB"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2227. arFrame["GT"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2228. arFrame["GW"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2229. arFrame["PT"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2230. arFrame["PW"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2231. arFrame["ER"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2232. arFrame["RT"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2233. arFrame["RW"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2234. arFrame["OT"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2235. arFrame["OW"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2236. arFrame["PR"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2237. arFrame["FT"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2238. arFrame["FW"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2239. arFrame["TT"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2240. arFrame["TW"] = tFrameMapping(HWSignal, tFrameMapping::OverType_WaitTime, false, 30);
  2241. }
  2242. //-----------------------------------------------------------------------------
  2243. // DynBoxDriver
  2244. //-----------------------------------------------------------------------------
  2245. //SyncBoxDevice* nsSYN::DynBoxDriver::pSDCDevice = nullptr;
  2246. nsSYN::DynBoxDriver::DynBoxDriver ()
  2247. {
  2248. m_bConnected = false;
  2249. m_pAttribute.reset(new ResDataObject());
  2250. m_pDescription.reset(new ResDataObject());
  2251. #ifdef _WIN64
  2252. g_strAppPath = GetProcessDirectory() + R"(\OEMDrivers\SyncBox\V2COM\DIOS.Dev.SyncBox.V2COM64.dll)";
  2253. mLog::Fatal("Version: {$} (64-bit)", FileVersion(g_strAppPath.c_str()).GetVersionString());
  2254. #else
  2255. g_strAppPath = GetProcessDirectory() + R"(\OEMDrivers\SyncBox\V2COM\DIOS.Dev.SyncBox.V2COM.dll)";
  2256. mLog::Fatal("Version: {$}", FileVersion(g_strAppPath.c_str()).GetVersionString());
  2257. #endif
  2258. //m_MapChannel.push_back("GR");
  2259. //m_MapChannel.push_back("CR");
  2260. //m_MapChannel.push_back("EC");
  2261. //m_MapChannel.push_back("CO");
  2262. //m_MapChannel.push_back("TB");
  2263. //m_MapChannel.push_back("WB");
  2264. //m_MapChannel.push_back("GT");
  2265. //m_MapChannel.push_back("GW");
  2266. //m_MapChannel.push_back("PT");
  2267. //m_MapChannel.push_back("PW");
  2268. //m_MapChannel.push_back("ER");
  2269. //m_MapChannel.push_back("RT");
  2270. //m_MapChannel.push_back("RW");
  2271. //m_MapChannel.push_back("OT");
  2272. //m_MapChannel.push_back("OW");
  2273. //m_MapChannel.push_back("PR");
  2274. //m_MapChannel.push_back("FT");
  2275. //m_MapChannel.push_back("FW");
  2276. //m_MapChannel.push_back("TT");
  2277. //m_MapChannel.push_back("TW");
  2278. }
  2279. nsSYN::DynBoxDriver::~DynBoxDriver ()
  2280. {
  2281. mLog::Info("set pIODriver null");
  2282. pIODriver = nullptr;
  2283. }
  2284. auto nsSYN::DynBoxDriver::CreateDevice (int index) -> std::unique_ptr <IODevice>
  2285. {
  2286. mLog::Info("CreateDevice index ={$}",index);
  2287. if (!m_SCF.isConnected())
  2288. {
  2289. mLog::Error("CreateDevice but scf no connect");
  2290. return nullptr;
  2291. }
  2292. //pSDCDevice = new nsSYN::DynBoxDevice(EventCenter,m_SCF);
  2293. if (index == 0)
  2294. {
  2295. pSDCDevice = new SyncBoxDevice(EventCenter, m_SCF, m_ConfigFileName);
  2296. //auto pSDCDevice = std::unique_ptr <DynBoxDevice>(new DynBoxDevice(EventCenter, m_SCF));
  2297. auto dev = std::unique_ptr <IODevice>(new IODevice(pSDCDevice));
  2298. ResDataObject r_config;
  2299. if (r_config.loadFile(m_ConfigFileName.c_str()))
  2300. {
  2301. pSDCDevice->ResDYNConfig = r_config["CONFIGURATION"]["DeviceConfig"];
  2302. //pSDCDevice->m_CollimatorDevice->ResDYNConfig = r_config["CONFIGURATION"]["DeviceConfig"];
  2303. mLog::Info("Load config ok");
  2304. }
  2305. return dev;
  2306. }
  2307. //ysj++
  2308. else if (index == 1)
  2309. {
  2310. mLog::Info("Enter CreateDevice COLL");
  2311. m_pDriCollDev = new OemCollimator(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  2312. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriCollDev));
  2313. m_pDriCollDev->SetCtrlDev(pSDCDevice);
  2314. pSDCDevice->SetCollimatorDev(m_pDriCollDev);
  2315. mLog::Info("Leave CreateDevice COLL");
  2316. return dev;
  2317. }
  2318. else if (index == 2)
  2319. {
  2320. mLog::Info("Enter CreateDevice Mech");
  2321. m_pDriMechDev = new OemMechanical(std::shared_ptr<IOEventCenter>(new IOEventCenter()));
  2322. auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDriMechDev));
  2323. m_pDriMechDev->SetCtrlDev(pSDCDevice);
  2324. pSDCDevice->SetMechDev(m_pDriMechDev);
  2325. mLog::Info("Leave CreateDevice Mech");
  2326. return dev;
  2327. }
  2328. return nullptr;
  2329. }
  2330. void nsSYN::DynBoxDriver::FireNotify (int code, std::string key, std::string content)
  2331. {
  2332. EventCenter->OnNotify (code, key, content);
  2333. }
  2334. Log4CPP::Logger* mLog::gLogger = nullptr;
  2335. void nsSYN::DynBoxDriver::Prepare ()
  2336. {
  2337. string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\SyncBox\Conf\Log4CPP.Config.SYN.xml)";
  2338. //Log4CPP::ThreadContext::Map::Set("LogFileName", "SYN.V2COM");
  2339. Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "SYN.V2COM");
  2340. auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
  2341. if (!rc)
  2342. {
  2343. printf("\n Load log configfile failed!\n");
  2344. }
  2345. mLog::gLogger = Log4CPP::LogManager::GetLogger("SYN.V2COM");
  2346. //add by wxx:自动获取版本号并更新到日志
  2347. string version;
  2348. if (GetVersion(version, hMyModule))
  2349. mLog::Info("--Func-- driver prepare : version:{$}\n", version.c_str());
  2350. else
  2351. mLog::Info("--Func-- driver prepare, v1.0.0.1 \n");
  2352. m_SCFDllName = GetConnectDLL(m_ConfigFileName);
  2353. super::Prepare ();
  2354. }
  2355. bool nsSYN::DynBoxDriver::Connect ()
  2356. {
  2357. ResDataObject Connection = GetConnectParam(m_ConfigFileName);
  2358. mLog::Info("connections:{$} \n", Connection.encode());
  2359. super::DecodePack(false);
  2360. auto erCode = m_SCF.Connect(Connection.encode(), &nsSYN::DynBoxDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  2361. if (erCode != SCF_ERR::SCF_SUCCEED)
  2362. {
  2363. mLog::Error("scf connect failed");
  2364. return false; //return erCode;
  2365. }
  2366. mLog::Info("connect success");
  2367. Sleep(200);
  2368. //CanShakeHand();
  2369. //SetCANState(true);//open can
  2370. Sleep(1000);
  2371. //super::SetThread_Priority(THREAD_PRIORITY_TIME_CRITICAL);
  2372. auto rc = super::Connect();
  2373. if (!rc)
  2374. {
  2375. LPVOID lpMsgBuf;
  2376. DWORD dw = GetLastError();
  2377. FormatMessage(
  2378. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2379. FORMAT_MESSAGE_FROM_SYSTEM |
  2380. FORMAT_MESSAGE_IGNORE_INSERTS,
  2381. NULL,
  2382. dw,
  2383. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  2384. (LPTSTR)&lpMsgBuf,
  2385. 0, NULL);
  2386. string msgContent = (TCHAR*)lpMsgBuf;
  2387. mLog::Debug("super_Connect:error msg[{$}:{$}]", (int)dw, msgContent.c_str());
  2388. return false;
  2389. }
  2390. else
  2391. {
  2392. mLog::Info("connect scf ok");
  2393. }
  2394. return true; //return SCF_ERR::SCF_SUCCEED;
  2395. }
  2396. bool nsSYN::DynBoxDriver::ReConnection(nsSCF::SCF& DevSCF)
  2397. {
  2398. super::Disconnect();
  2399. mLog::Info("ReConnection:SCF Disconnect");
  2400. ResDataObject r_config;
  2401. if (!r_config.loadFile(m_ConfigFileName.c_str()))
  2402. {
  2403. mLog::Info("ReConnection:open configFile failed");
  2404. return SCF_ERR::SCF_OPEN_FAILED;
  2405. }
  2406. ResDataObject Connection = r_config["CONFIGURATION"]["connections"][0];
  2407. mLog::Info("ReConnection:{$} \n", Connection.encode());
  2408. auto erCode = m_SCF.Connect(Connection.encode(), &nsSYN::DynBoxDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
  2409. if (erCode == SCF_ERR::SCF_SUCCEED)
  2410. {
  2411. Sleep(1000);
  2412. auto rc = super::Connect();
  2413. if (!rc)
  2414. {
  2415. mLog::Info("ReConnection:super Connect failed");
  2416. }
  2417. else
  2418. {
  2419. DevSCF = m_SCF;
  2420. return true;
  2421. }
  2422. }
  2423. else
  2424. {
  2425. mLog::Info("ReConnection failed");
  2426. }
  2427. return false;
  2428. }
  2429. void nsSYN::DynBoxDriver::Disconnect()
  2430. {
  2431. super::Disconnect();
  2432. m_SCF.Disconnect();
  2433. pSDCDevice = nullptr;
  2434. m_bConnected = false;
  2435. mLog::Info("Disconnect ok");
  2436. }
  2437. bool nsSYN::DynBoxDriver::isConnected() const
  2438. {
  2439. if (super::isConnected())
  2440. {
  2441. return true;
  2442. }
  2443. else
  2444. {
  2445. if (SyncBoxDevice::m_bHeartBeatFlag) //避过平台层的断连检测
  2446. return true;
  2447. else
  2448. return false;
  2449. }
  2450. }
  2451. std::string nsSYN::DynBoxDriver::DriverProbe ()
  2452. {
  2453. ResDataObject r_config, HardwareInfo;
  2454. if (r_config.loadFile (m_ConfigFileName.c_str ()))
  2455. {
  2456. HardwareInfo.add ("MajorID", r_config ["CONFIGURATION"] ["MajorID"]);
  2457. HardwareInfo.add ("MinorID", r_config ["CONFIGURATION"] ["MinorID"]);
  2458. HardwareInfo.add ("VendorID", r_config ["CONFIGURATION"] ["VendorID"]);
  2459. HardwareInfo.add ("ProductID", r_config ["CONFIGURATION"] ["ProductID"]);
  2460. HardwareInfo.add ("SerialID", r_config ["CONFIGURATION"] ["SerialID"]);
  2461. }
  2462. else
  2463. {
  2464. HardwareInfo.add("MajorID", "SYN");
  2465. HardwareInfo.add("MinorID", "Dr");
  2466. HardwareInfo.add("VendorID", "ECOM");
  2467. HardwareInfo.add("ProductID", "DYN");
  2468. HardwareInfo.add("SerialID", "1234");
  2469. }
  2470. string ret = HardwareInfo.encode ();
  2471. return ret;
  2472. }
  2473. bool nsSYN::DynBoxDriver::GetDeviceConfig(std::string& Cfg)
  2474. {
  2475. Cfg = m_DeviceConfig.encode();
  2476. printf("GetDeviceConfig over : %s \n", Cfg.c_str());
  2477. return true;
  2478. }
  2479. bool nsSYN::DynBoxDriver::SetDeviceConfig(std::string Cfg)
  2480. {
  2481. mLog::Info("--Func-- SetDeviceConfig {$}\n", Cfg.c_str());
  2482. ResDataObject DeviceConfig;
  2483. DeviceConfig.decode(Cfg.c_str());
  2484. ResDataObject DescriptionTempEx;
  2485. DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
  2486. mLog::Debug("Attribute:{$}", DescriptionTempEx.encode());
  2487. bool bSaveFile = false; //true:重新保存配置文件
  2488. string strAccess = "";
  2489. for (int i = 0; i < DescriptionTempEx.size(); i++)
  2490. {
  2491. string strKey = DescriptionTempEx.GetKey(i);
  2492. mLog::Info("{$}", strKey.c_str());
  2493. try
  2494. {
  2495. if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
  2496. {
  2497. strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
  2498. if ("RW" == strAccess)
  2499. {
  2500. //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
  2501. //1. 修改内存中的值,用于给上层发消息
  2502. (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
  2503. //2. 拿到Innerkey
  2504. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2505. mLog::Info("nConfigInfoCount {$}", nConfigInfoCount);
  2506. string strTemp = ""; //存储AttributeKey
  2507. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2508. {
  2509. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2510. if (strTemp == strKey)
  2511. {
  2512. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2513. break;
  2514. }
  2515. }
  2516. //3. 修改配置文件中的值
  2517. if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
  2518. {
  2519. mLog::Debug("SetDeviceConfigValue over");
  2520. bSaveFile = true;
  2521. }
  2522. }
  2523. else
  2524. {
  2525. mLog::Info("{$} is not a RW configuration item", strKey.c_str());
  2526. }
  2527. }
  2528. else
  2529. {
  2530. mLog::Info("without this attribute {$}", strKey.c_str());
  2531. }
  2532. }
  2533. catch (ResDataObjectExption& e)
  2534. {
  2535. mLog::Error("SetDriverConfig crashed: {$}", e.what());
  2536. return false;
  2537. }
  2538. }
  2539. if (bSaveFile)
  2540. {
  2541. //3. 重新保存配置文件
  2542. SaveConfigFile(true);
  2543. }
  2544. return true;
  2545. }
  2546. bool nsSYN::DynBoxDriver::SaveConfigFile(bool bSendNotify)
  2547. {
  2548. m_ConfigAll["CONFIGURATION"] = m_Configurations;
  2549. bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
  2550. mLog::Info("SaveConfigFile over {$}", bRt);
  2551. return true;
  2552. }
  2553. bool nsSYN::DynBoxDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
  2554. {
  2555. strValue = "";
  2556. string strTemp = pInnerKey;
  2557. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2558. {
  2559. int pos = 0;
  2560. ResDataObject resTemp= config;
  2561. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2562. {
  2563. string Key = strTemp.substr(0, pos);
  2564. string TempValue = resTemp[Key.c_str()].encode();
  2565. resTemp.clear();
  2566. resTemp.decode(TempValue.c_str());
  2567. strTemp= strTemp.substr(pos+1,strTemp.length()-pos-1);
  2568. }
  2569. if (strTemp != "")
  2570. {
  2571. strValue=(string)resTemp[strTemp.c_str()];
  2572. }
  2573. else
  2574. {
  2575. strValue = (string)resTemp;
  2576. }
  2577. }
  2578. return true;
  2579. }
  2580. bool nsSYN::DynBoxDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
  2581. {
  2582. string strTemp = pInnerKey;
  2583. mLog::Debug("Begin to change {$} item value to {$}", pInnerKey, szValue);
  2584. if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
  2585. {
  2586. try {
  2587. int pos = 0;
  2588. ResDataObject *resTemp = &config;
  2589. while ((pos = strTemp.find_first_of(',')) != string::npos)
  2590. {
  2591. string Key = strTemp.substr(0, pos);
  2592. resTemp = &(*resTemp)[Key.c_str()];
  2593. strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
  2594. }
  2595. if (strTemp != "")
  2596. {
  2597. (*resTemp)[strTemp.c_str()]= szValue;
  2598. }
  2599. else
  2600. {
  2601. *resTemp = szValue;
  2602. }
  2603. }
  2604. catch (ResDataObjectExption& e)
  2605. {
  2606. mLog::Error("SetDriverConfigvalue crashed: {$}", e.what());
  2607. return false;
  2608. }
  2609. }
  2610. return true;
  2611. }
  2612. std::string nsSYN::DynBoxDriver::GetResource ()
  2613. {
  2614. ResDataObject r_config, temp;
  2615. if (!temp.loadFile(m_ConfigFileName.c_str()))
  2616. {
  2617. return "";
  2618. }
  2619. m_ConfigAll = temp;
  2620. r_config = temp["CONFIGURATION"];
  2621. m_Configurations = r_config;
  2622. ResDataObject DescriptionTemp;
  2623. ResDataObject ListTemp;
  2624. string strTemp = ""; //用于读取字符串配置信息
  2625. string strIndex = ""; //用于读取配置信息中的List项
  2626. int nTemp = -1; //用于读取整型配置信息
  2627. char sstream[10] = { 0 }; //用于转换值
  2628. string strValue = ""; //用于存储配置的值
  2629. string strType = ""; //用于存储配置的类型 int/float/string...
  2630. /***
  2631. * 1. 通过循环,将所有配置项写到pDeviceConfig
  2632. * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
  2633. ***/
  2634. try
  2635. {
  2636. int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
  2637. //mLog::Info(g_pFPDCtrlLog, "ConfigInfo Count: {$}", nConfigInfoCount);
  2638. m_pAttribute->clear();
  2639. m_pDescription->clear();
  2640. for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
  2641. {
  2642. DescriptionTemp.clear();
  2643. ListTemp.clear();
  2644. //AttributeType
  2645. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
  2646. DescriptionTemp.add(ConfKey::AttributeType, strTemp.c_str());
  2647. //DescriptionTemp= m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"];
  2648. //mLog::Info(g_pFPDCtrlLog, "--> {$}: {$}", AttributeType, strTemp.c_str());
  2649. strType = strTemp; //记录配置项的类型
  2650. //AttributeKey
  2651. //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
  2652. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
  2653. nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
  2654. GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue);
  2655. //2. 赋值
  2656. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2657. if ("int" == strType)
  2658. {
  2659. (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
  2660. //mLog::Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atoi(strValue.c_str()));
  2661. }
  2662. else if ("float" == strType)
  2663. {
  2664. (*m_pAttribute).add(strTemp.c_str(), atof(strValue.c_str()));
  2665. //mLog::Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), atof(strValue.c_str()));
  2666. }
  2667. else //其它先按string类型处理
  2668. {
  2669. (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
  2670. //mLog::Info(g_pFPDCtrlLog, "Key {$}: {$}", strTemp.c_str(), strValue.c_str());
  2671. }
  2672. //AttributeAccess
  2673. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
  2674. DescriptionTemp.add(ConfKey::AttributeAccess, strTemp.c_str());
  2675. //mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeAccess, strTemp.c_str());
  2676. //AttributeRangeMin
  2677. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
  2678. if (strTemp != "") //不需要的配置项为空
  2679. {
  2680. DescriptionTemp.add(ConfKey::AttributeRangeMin, strTemp.c_str());
  2681. //mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMin, strTemp.c_str());
  2682. }
  2683. //AttributeRangeMax
  2684. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
  2685. if (strTemp != "") //不需要的配置项为空
  2686. {
  2687. DescriptionTemp.add(ConfKey::AttributeRangeMax, strTemp.c_str());
  2688. //mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRangeMax, strTemp.c_str());
  2689. }
  2690. //AttributeList
  2691. nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
  2692. if (nTemp > 0) //ListNum不大于0时说明不需要list配置
  2693. {
  2694. for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
  2695. {
  2696. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
  2697. //sprintf_s(sstream, "{$}", nListIndex);
  2698. auto temKey = std::to_string(nListIndex);
  2699. ListTemp.add(temKey.c_str(), strTemp.c_str());
  2700. //mLog::Info(g_pFPDCtrlLog, "list {$}: {$}", nListIndex, strTemp.c_str());
  2701. }
  2702. DescriptionTemp.add(ConfKey::AttributeList, ListTemp.encode());
  2703. }
  2704. //AttributeRequired
  2705. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
  2706. DescriptionTemp.add(ConfKey::AttributeRequired, strTemp.c_str());
  2707. //mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeRequired, strTemp.c_str());
  2708. //AttributeDefaultValue
  2709. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
  2710. if (strTemp != "") //不需要的配置项为空
  2711. {
  2712. DescriptionTemp.add(ConfKey::AttributeDefaultValue, strTemp.c_str());
  2713. //mLog::Info(g_pFPDCtrlLog, "{$}: {$}", AttributeDefaultValue, strTemp.c_str());
  2714. }
  2715. strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
  2716. (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
  2717. }
  2718. }
  2719. catch (ResDataObjectExption& e)
  2720. {
  2721. mLog::Error("Get config error: {$}", e.what());
  2722. return "";
  2723. }
  2724. ResDataObject resDeviceResource;
  2725. resDeviceResource.add(ConfKey::DiosAttribute, (*m_pAttribute));
  2726. resDeviceResource.add(ConfKey::DiosDescription, (*m_pDescription));
  2727. ResDataObject DescriptionTempEx;
  2728. DescriptionTempEx.add(ConfKey::DiosConfig, resDeviceResource);
  2729. m_DeviceConfig.clear();
  2730. m_DeviceConfig = DescriptionTempEx;
  2731. string res = DescriptionTempEx.encode();
  2732. #if 0
  2733. mLog::Debug("get resource over {$}", DescriptionTempEx.encode());
  2734. printf("get resource over : %s \n", DescriptionTempEx.encode());
  2735. #endif // 0
  2736. return res;
  2737. }
  2738. std::string nsSYN::DynBoxDriver::DeviceProbe ()
  2739. {
  2740. ResDataObject r_config, HardwareInfo;
  2741. if (r_config.loadFile (m_ConfigFileName.c_str ()))
  2742. {
  2743. HardwareInfo.add ("MajorID", r_config ["CONFIGURATION"] ["MajorID"]);
  2744. HardwareInfo.add ("MinorID", r_config ["CONFIGURATION"] ["MinorID"]);
  2745. HardwareInfo.add ("VendorID", r_config ["CONFIGURATION"] ["VendorID"]);
  2746. HardwareInfo.add ("ProductID", r_config ["CONFIGURATION"] ["ProductID"]);
  2747. HardwareInfo.add ("SerialID", r_config ["CONFIGURATION"] ["SerialID"]);
  2748. }
  2749. else
  2750. {
  2751. HardwareInfo.add ("MajorID", "SYN");
  2752. HardwareInfo.add ("MinorID", "Dr");
  2753. HardwareInfo.add ("VendorID", "ECOM");
  2754. HardwareInfo.add ("ProductID", "DYN");
  2755. HardwareInfo.add ("SerialID", "1234");
  2756. }
  2757. string ret = HardwareInfo.encode ();
  2758. return ret;
  2759. }
  2760. void nsSYN::DynBoxDriver::Dequeue (const char * Packet, DWORD Length)
  2761. {
  2762. #if 0
  2763. char data[4] = { 0 };
  2764. strncpy_s(data, Packet, 3);
  2765. mLog::Debug("Enter Dequeue[{$}]", data);
  2766. #endif
  2767. DecodeFrame (Packet, Length);
  2768. }
  2769. PACKET_RET nsSYN::DynBoxDriver::callbackPackageProcess (const char * RecData, DWORD nLength, DWORD& PacketLength)
  2770. {
  2771. //判断是否是整包
  2772. /*
  2773. 这个是回调函数,我收到的数据会需要这个回调函数帮我判断是否是整个的包;
  2774. 如果有整个的包,返回值为true,在PacketLength处返回给我整个包的长度,我再截取后放入缓存供上层使用;
  2775. 如果缓存中的数据没有整个的数据包,那么返回false
  2776. */
  2777. #if 0
  2778. char tempData[3]{ 0 };
  2779. tempData[0] = RecData[0];
  2780. if(nLength >= 2)
  2781. tempData[1] = RecData[1];
  2782. if(strncmp(tempData, "EC",2) == 0)
  2783. mLog::Debug("RecData[{$}],lengh[{$}]", tempData, nLength);
  2784. #endif
  2785. bool bHasHead = false;
  2786. if (nLength < 3)
  2787. {
  2788. //mLog::Error ("nLength[{$}] < 3", nLength);
  2789. PacketLength = 0;
  2790. return PACKET_NOPACKET;
  2791. }
  2792. else if (nLength >= C2COM_Com_NormalLen)
  2793. {
  2794. mLog::Error("nLength[{$}] > [{$}] ", nLength, C2COM_Com_NormalLen);
  2795. PacketLength = nLength;
  2796. return PACKET_USELESS;
  2797. }
  2798. #if 0
  2799. string cmdHead;
  2800. cmdHead.push_back(RecData[0]);
  2801. cmdHead.push_back(RecData[1]);
  2802. if (find(m_MapChannel.begin(), m_MapChannel.end(), cmdHead) != m_MapChannel.end())
  2803. {
  2804. bHasHead = true;
  2805. }
  2806. #else
  2807. char data[3] = { 0 };
  2808. strncpy_s(data, RecData, 2);
  2809. auto found = arFrame.find(data);
  2810. if (found != arFrame.end())
  2811. {
  2812. bHasHead = true;
  2813. }
  2814. #endif // 0
  2815. for (DWORD i = 0; i < nLength-1; i++)
  2816. {
  2817. if (RecData [i] == 0x0d && RecData [i + 1] == 0x0a)
  2818. {
  2819. PacketLength = i + 2;
  2820. char strtemp[C2COM_Com_NormalLen] = { 0 };
  2821. memcpy(strtemp, RecData, i);//0d 0a 不要了。
  2822. strtemp[PacketLength + 1] = 0;
  2823. if (bHasHead)
  2824. {
  2825. //if (pSDCDevice != nullptr && pSDCDevice->GetConnectFlag() != 3)
  2826. //{
  2827. // if (strncmp(RecData, "EC", 2) != 0)
  2828. // {
  2829. // mLog::Info("==IN ==:[{$}]discard because lost connect", strtemp);
  2830. // return PACKET_USELESS;
  2831. // }
  2832. // else
  2833. // {
  2834. // mLog::Info("==IN ==:[{$}]get reconnectFlag success", strtemp);
  2835. // return PACKET_ISPACKET;
  2836. // }
  2837. //}
  2838. if (strncmp(RecData, "GR",2) != 0 && strncmp(RecData, "CR", 2) != 0 && strncmp(RecData, "EC", 2) != 0) // && strncmp(RecData, "EC", 2) != 0
  2839. {
  2840. mLog::Info("==IN==:[{$}]", strtemp);
  2841. found->second.tCheckWaitState(strtemp);
  2842. mLog::Debug("finish tCheckWaitState");
  2843. }
  2844. return PACKET_ISPACKET;
  2845. }
  2846. else
  2847. {
  2848. mLog::Error("==IN==:cmd[{$}][{$}] useless", PacketLength, RecData);
  2849. return PACKET_USELESS;
  2850. }
  2851. }
  2852. }
  2853. if (bHasHead)
  2854. {
  2855. PacketLength = 0;
  2856. }
  2857. return PACKET_NOPACKET;
  2858. }
  2859. //-----------------------------------------------------------------------------
  2860. //
  2861. //-----------------------------------------------------------------------------
  2862. void nsSYN::DynBoxDriver::CanShakeHand()
  2863. {
  2864. int nTimeout = 100;
  2865. char cCmd[MAX_COMMAND_LEN] = "EC";// "SECA00";
  2866. int nCmdSize = 2;// 6;
  2867. FormatCmd(cCmd, nCmdSize);
  2868. string strLog;
  2869. CmdtoString(cCmd, nCmdSize, strLog);
  2870. mLog::Info("[Send:{$}]", strLog.c_str());
  2871. //printf("[Send:%s]\n", strLog.c_str());
  2872. mLog::Info("CanShakeHand ==OUT==: {$} ", cCmd);
  2873. int ret = 0;
  2874. m_SCF.Lock(msTimeOut_Lock)
  2875. .SendPacket(cCmd, nCmdSize, nTimeout, ret);
  2876. Sleep(nTimeout);
  2877. }
  2878. //-----------------------------------------------------------------------------
  2879. // GetIODriver & CreateIODriver
  2880. //-----------------------------------------------------------------------------
  2881. static nsSYN::DynBoxDriver gIODriver;
  2882. extern "C" DIOS::Dev::IODriver * __cdecl GetIODriver () // 返回静态对象的引用, 调用者不能删除 !
  2883. {
  2884. return &gIODriver;
  2885. }
  2886. extern "C" DIOS::Dev::IODriver * __cdecl CreateIODriver () // 返回新对象, 调用者必须自行删除此对象 !
  2887. {
  2888. pIODriver = new nsSYN::DynBoxDriver();
  2889. return pIODriver;
  2890. }