1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733 |
- // CCOS.Dev.GEN.Delta.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include <assert.h>
- #include <functional>
- #include <fstream>
- using namespace std::placeholders;
- #include "Helper.JSON.hpp"
- #include "CCOS.Dev.Generator.Delta_80KAXB.h"
- using namespace CCOS::Dev::Detail::Generator;
- namespace nsGEN = CCOS::Dev::Detail::Generator;
- #pragma warning (disable:4244)
- #pragma warning (disable:4305)
- #pragma warning (disable:4267)
- #pragma comment(lib, "version.lib")
- static const int msTimeOut_Lock = 500;
- #ifdef _WIN64
- #ifdef _DEBUG
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64D.dll";
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64D.dll";
- #else
- static const auto COM_SCFDllName = "Ccos.Dev.SerialSCFX64.dll";
- static const auto TCP_SCFDllName = "Ccos.Dev.TcpipSCFX64.dll";
- #endif
- #endif
- #define Delta_Com_NormalLen 20
- #define Delta_LoopDefTime 1500
- #define Delta_LoopExpTime 100
- #define KVP_MAX 150
- #define KVP_MIN 40
- #define WORD_HIGH(a) (a>>4)
- #define WORD_LOW(a) (( a & 0x0F))
- #define COMMANDHEAD 0xF0
- #define COMMANDEND 0x88
- #define HANDSWITCHCOMMAND 0x0D
- #define HANDSWITCHFIRST 0x52
- #define XRAYONCOMMAND 0x58
- #define XRAYOFFCOMMAND 0x4F
- /* Control characters */
- #define STX 0x02 /* Start of DATA */
- #define ETX 0x03 /* End of DATA */
- #define ACK 0x06 /* Acknowlage */
- #define NAK 0x15 /* not acknowlage */
- #define BYTE_1 1
- #define BYTE_2 2
- #define BYTE_4 4
- #define BYTE_6 6
- #define BYTE_10 10
- #define BYTE_12 12
- //-----------------------------------------------------------------------------
- // 计算校验码
- //-----------------------------------------------------------------------------
- UINT8 GetCRC8(char* pBuffer, UINT16 bufSize)
- {
- char High[16] = { 0x00, 0x70, 0xe0, 0x90, 0xc7, 0xb7, 0x27, 0x57, 0x89, 0xf9, 0x69, 0x19, 0x4e, 0x3e, 0xae, 0xde };
- char Low[16] = { 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d };
- UINT8 crc = 0;
- if (bufSize <= 0)
- return crc;
- for (int i = 0; i < bufSize; i++)
- {
- UINT8 result = (crc ^ pBuffer[i]);
- UINT8 high = WORD_HIGH(result);
- UINT8 low = WORD_LOW(result);
- crc = High[high] ^ Low[low];
- }
- return crc;
- }
- //-----------------------------------------------------------------------------
- // DeltaDevice
- //-----------------------------------------------------------------------------
- nsSerialGPM::CDeliverModule nsGEN::DeltaDevice::m_tDelivermodule;
- nsGEN::DeltaDevice* nsGEN::DeltaDevice::g_GenDevice = NULL;
- atomic<int> nsGEN::DeltaDevice::m_iLoopTime = Delta_LoopDefTime;
- nsGEN::DeltaDevice::DeltaDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF, string configfile) : super(center, SCF)
- {
- assert(EventCenter);
- g_GenDevice = this;
- //两种日志方式自行选择
- string version;
- if (GetVersion(version, hMyModule))
- FINFO("\n===============log begin : module version:{$} ===================\n", version.c_str());
- else
- FINFO("\n===============log begin : version:0.0.0.0 ===================\n");
- //获取delta动态库版本号
- string strPath;
- strPath = GetDynamicLibraryPath() + "\\CCOS.Dev.Generator.Delta_80KAXB64.dll";
- string strVersion;
- strVersion = GetFileVersion(strPath);
- FINFO("=====================log begin :delta dll version{$}===strPath {$}====================", strVersion, strPath);
- //初始化参数
- m_DoseUnit.m_KV.reset(new KVMould(70.0, 40.0, 150.0, 1.0));
- m_DoseUnit.m_MA.reset(new MAMould(20.0, 10.0, 1000.0, 1.0));
- m_DoseUnit.m_MS.reset(new MSMould(20.0, 1.0, 63000.0, 1.0));
- m_DoseUnit.m_MAS.reset(new MASMould(0.4, 0.4, 10000.0, 1.0));
- m_DoseUnit.m_Techmode.reset(new TECHMODEMould(AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_NOAEC_3P, AttrKey::TECHMODE_MAX, 1));
- m_DoseUnit.m_WS.reset(new WORKSTATIONMould(AttrKey::TABLE, AttrKey::TABLE, AttrKey::GENWS_MAX, 1));
- m_DoseUnit.m_Focus.reset(new FOCUSMould(AttrKey::FOCUS_LARGE, AttrKey::FOCUS_SMALL, AttrKey::FOCUS_LARGE, 1));
- m_DoseUnit.m_AECField.reset(new AECFIELDMould(0, 0, 111, 1));
- m_DoseUnit.m_AECFilm.reset(new AECFILMMould(0, 0, 3, 1));
- m_DoseUnit.m_AECDensity.reset(new AECDENSITYMould(0, -4, 4, 1));
- m_DoseUnit.m_HE.reset(new TUBEHEATMould(0, 0, 100, 1));
- m_DoseUnit.m_PostKV.reset(new POSTKVMould(40.0, 40.0, 150.0, 1.0));
- m_DoseUnit.m_PostMA.reset(new POSTMAMould(10.0, 10.0, 1000.0, 1.0));
- m_DoseUnit.m_PostMS.reset(new POSTMSMould(1.0, 1.0, 63000.0, 1.0));
- m_DoseUnit.m_PostMAS.reset(new POSTMASMould(0.4, 0.4, 10000.0, 1.0));
- m_DoseUnit.m_KVList.reset(new KVLISTMould(""));
- m_DoseUnit.m_MAList.reset(new MALISTMould(""));
- m_DoseUnit.m_mAsList.reset(new MASLISTMould(""));
- m_DoseUnit.m_MSList.reset(new MSLISTMould(""));
- m_DoseUnit.m_GenSynState.reset(new GENSYNSTATEMould(AttrKey::GENERATOR_RAD_OFF, AttrKey::GENERATOR_SYNC_ERR, AttrKey::GENERATOR_SYNC_MAX, 1));
- m_DoseUnit.m_GenState.reset(new GENSTATEMould(AttrKey::GENERATOR_STATUS_INIT, AttrKey::GENERATOR_STATUS_SHUTDOWN, AttrKey::GENERATOR_STATUS_MAX, 1));
- m_DoseUnit.m_GenTotalExpNumber.reset(new TOTALEXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTotalAcqTimes.reset(new TOTALACQTIMESMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeCoolWaitTimes.reset(new TUBECOOLTIMEMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenTubeOverLoadNumber.reset(new TUBEOVERLOADNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_GenCurrentExpNumber.reset(new CUREXPNUMMould(0, 0, 9999, 1));
- m_DoseUnit.m_ExpMode.reset(new EXPMODEMould(AttrKey::EXPMODE_TYPE::Single));
- m_DoseUnit.m_FrameRate.reset(new FRAMERATEMould(0, 0, 30, 1));
- m_DoseUnit.m_FLMode.reset(new FLUModeMould(AttrKey::GENERATOR_FLUMode::GENERATOR_FLMODE_NOTFLU));
- m_DAP.reset(new DevDAP::DOSEMould(0.0, 0.0, 1000.0, 0.01));
- m_MSGUnit.reset(new nsDetail::MSGUnit(center, nsGEN::GeneratorUnitType));
- //注册
- Register();
- //使用drivermodule类,用来做ack交互
- m_tDelivermodule.InitSendModle(this, &ProcessClientData, WriteLog);
- m_nCMDType_ACK = m_tDelivermodule.SetPriority(false, true);
- m_nCMDType_WaitTime = m_tDelivermodule.SetPriority(true, false, false, true, 100);
- m_nCMDType_WaitACK = m_tDelivermodule.SetPriority(true, false, 0, false, 0, false, 0, true, 100);
- m_nCMDType_WaitSELF = m_tDelivermodule.SetPriority(true, false, 3, false, 0, true, 1000);
- char ackCMD[3] = {ACK ,ETX ,0};
- m_tDelivermodule.SetACKCMDHead(ackCMD,2);
- //从配置文件获取对应配置内容
- //GetConfData();
- //循环
- m_hExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hHUstatus = CreateEvent(NULL, TRUE, FALSE, NULL);
- m_hGENstatus = CreateEvent(NULL, TRUE, FALSE, NULL);
- m_hLoopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- m_hArrayEvent[0] = m_hExitEvent;
- m_hArrayEvent[1] = m_hHUstatus;
- m_hArrayEvent[2] = m_hGENstatus;
- m_hArrayEvent[3] = m_hLoopEvent;
- StartHardwareStatusThread();
- SetEvent(m_hHUstatus);
- SetEvent(m_hGENstatus);
- SetEvent(m_hLoopEvent);
- m_nCountTimes = 0;
- //确定版本号
- RetrieveFirewareVersion();
- //警告,错误信息
- m_ErrorMessages = {
- {"DELTA_ERR_0000", "LOST CONNECT"},
- {"DELTA_ERR_0001", "PC Invalid Command"},
- {"DELTA_ERR_0002", "Door Interlock"},
- {"DELTA_ERR_0003", "Interlock"},
- {"DELTA_ERR_0004", "Prep Timeout"},
- {"DELTA_ERR_0005", "Ready Timeout"},
- {"DELTA_ERR_0006", "Filament Timeout"},
- {"DELTA_ERR_0007", "No Library Data"},
- {"DELTA_ERR_0008", "No Calibration Data"},
- {"DELTA_ERR_0009", "SW Configuration File Empty"},
- {"DELTA_ERR_0010", "Calibration Manually Terminated"},
- {"DELTA_ERR_0011", "Manually Terminate Exposure"},
- {"DELTA_ERR_0012", "PREP Manually Terminate"},
- {"DELTA_ERR_0013", "Seasoning Manually Terminated"},
- {"DELTA_ERR_0014", "AC Voltage UVP"},
- {"DELTA_ERR_0015", "Bucky ready open"},
- {"DELTA_ERR_0017", "Not get AEC Ramp"},
- {"DELTA_ERR_0018", "AEC calibration over range"},
- {"DELTA_ERR_0019", "AEC exposure time out"},
- {"DELTA_ERR_0020", "Snap over power rating"},
- {"DELTA_ERR_1001", "SW OTP"},
- {"DELTA_ERR_1002", "Thermal Switch"},
- {"DELTA_ERR_1003", "XRAY Over HU"},
- {"DELTA_ERR_1004", "Aux Power Off"},
- {"DELTA_ERR_1005", "DR reset fail"},
- {"DELTA_ERR_1006", "DR ready fail"},
- {"DELTA_ERR_1007", "Battery communication loss"},
- {"DELTA_ERR_1008", "DAP communication loss"},
- {"DELTA_ERR_1009", "Fluoroscopic time out"},
- {"DELTA_ERR_1010", "DAP device error"},
- {"DELTA_ERR_1011", "Snap over time"},
- {"DELTA_ERR_2001", "SW Vout OVP"},
- {"DELTA_ERR_2002", "SW Vout UVP"},
- {"DELTA_ERR_2003", "SW Anode OCP"},
- {"DELTA_ERR_2004", "SW Anode UCP"},
- {"DELTA_ERR_2005", "Input Voltage OVP" },
- {"DELTA_ERR_2006", "Input Voltage UVP" },
- {"DELTA_ERR_2007", "24 VDC UVP" },
- {"DELTA_ERR_2008", "HW Vout OVP"},
- {"DELTA_ERR_2009", "Capacitive Protection"},
- {"DELTA_ERR_2010", "Primary OCP"},
- {"DELTA_ERR_2011", "HW Cathode OCP"},
- {"DELTA_ERR_2012", "HW Anode OCP"},
- {"DELTA_ERR_2013", "Charger OTP" },
- {"DELTA_ERR_2014", "PFC BUS UVP" },
- {"DELTA_ERR_2015", "Flow fault"},
- {"DELTA_ERR_2016", "PFC start fail"},
- {"DELTA_ERR_3001", "SW Thermal sense fault"},
- {"DELTA_ERR_3002", "Fan 1 Fault"},
- {"DELTA_ERR_3003", "Fan 2 Fault"},
- {"DELTA_ERR_3004", "Filament Power Fault"},
- {"DELTA_ERR_3005", "Soft Start Fail"},
- {"DELTA_ERR_3006", "MA Test Point Open"},
- {"DELTA_ERR_3007", "Tank Connect" },
- {"DELTA_ERR_3008", "Self-Test FERROR"},
- {"DELTA_ERR_3009", "Motor Short"},
- {"DELTA_ERR_3010", "Motor Invalid command"},
- {"DELTA_ERR_3011", "Motor OCP1"},
- {"DELTA_ERR_3012", "Motor OCP2"},
- {"DELTA_ERR_3013", "Motor Communication Loss"},
- {"DELTA_ERR_3014", "Motor Main Open"},
- {"DELTA_ERR_3015", "Motor Shift Open"},
- {"DELTA_ERR_3016", "Charger Fail"},
- {"DELTA_ERR_3017", "Bus UVP"},
- {"DELTA_ERR_3018", "Battery UVP"},
- {"DELTA_ERR_3019", "Cart UVP"},
- {"DELTA_ERR_3020", "Inverter error"},
- {"DELTA_ERR_3021", "Discharge Relay Fail" },
- {"DELTA_ERR_3022", "Battery OVP"},
- {"DELTA_ERR_3023", "Battery OCP" },
- {"DELTA_ERR_3024", "Battery OTP" },
- {"DELTA_ERR_3025", "Battery Fail"},
- {"DELTA_ERR_3026", "APS1 Fail"},
- {"DELTA_ERR_3027", "APS2 Fail"},
- {"DELTA_ERR_3028", "APS3 Fail"},
- {"DELTA_ERR_3029", "Capacitator error" },
- {"DELTA_ERR_3030", "Fan 3 Fault"},
- {"DELTA_ERR_3031", "Fan 4 Fault"},
- {"DELTA_ERR_3032", "PFC OTP and Brown out"},
- {"DELTA_ERR_4001", "SW Current Unbalance"},
- {"DELTA_ERR_4002", "SW Filament OCP"},
- {"DELTA_ERR_4003", "Shoot Inv1"},
- {"DELTA_ERR_4004", "Shoot Inv2"},
- {"DELTA_ERR_4005", "HW Filament Rms"},
- {"DELTA_ERR_4006", "FERROR Repeat 5 Times"},
- };
- m_WarnMessages = {
- {"DELTA_WARN_001", "mode inhibited"},
- {"DELTA_WARN_002", "out of tube rating"},
- {"DELTA_WARN_003", "out of power"},
- {"DELTA_WARN_004", "out of work"},
- {"DELTA_WARN_005", "out of voltage range"},
- {"DELTA_WARN_006", "out of current range"},
- {"DELTA_WARN_007", "out of time or FPS range"},
- {"DELTA_WARN_008", "out of mas range"},
- {"DELTA_WARN_009", "time too small"},
- {"DELTA_WARN_010", "parameter ok"},
- {"DELTA_WARN_011", "mas too small"},
- {"DELTA_WARN_012", "no cmd"},
- {"DELTA_WARN_013", "data not complete(reserved)"},
- {"DELTA_WARN_014", "out of tube HU"},
- {"DELTA_WARN_015", "out of filament current range"},
- {"DELTA_WARN_016", "no library data" },
- {"DELTA_WARN_017", "tube PN not match"},
- {"DELTA_WARN_018", "focal spot not support"},
- {"DELTA_WARN_019", "data break"},
- {"DELTA_WARN_020", "EEPROM BUSY"},
- {"DELTA_WARN_021", "exposure result empty"},
- {"DELTA_WARN_022", "tube calibration data empty" },
- {"DELTA_WARN_023", "XRAY interval time"},
- {"DELTA_WARN_024", "filament current limit"},
- {"DELTA_WARN_025", "out of generator HU"},
- {"DELTA_WARN_026", "out of motor HU"},
- {"DELTA_WARN_160", "invalid cmd"},
- };
- }
- std::string CCOS::Dev::Detail::Generator::DeltaDevice::GetDynamicLibraryPath()
- {
- HMODULE hModule = GetModuleHandle("CCOS.Dev.Generator.Delta_80KAXB64.dll");
- char path[MAX_PATH];
- GetModuleFileName(hModule, path, MAX_PATH);
- std::string fullPath(path);
- size_t pos = fullPath.find_last_of("\\/");
- FINFO("FullPath {$}", fullPath);
- return fullPath.substr(0, pos);
- }
- bool CCOS::Dev::Detail::Generator::DeltaDevice::GetConfData()
- {
- //暂时使用上面定义的数组,不用非要读取配置文件。
- int Num;
- if (m_GenConfig.GetKeyCount("RadKV") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadKVSize") > 0)
- {
- Num = (int)m_GenConfig["RadKVSize"];
- for (int i = 0; i < Num; i++)
- {
- int nKV = (int)m_GenConfig["RadKV"][i];
- m_vecKV.push_back(nKV);
- }
- //m_DoseUnit.m_KVList->Update((string)m_GenConfig["RadKV"]);
- //FireNotify(m_DoseUnit.m_KVList->GetKey(), m_DoseUnit.m_KVList->JSGet());
- }
- FINFO("m_vecKV {$}", m_vecKV.size());
- }
- else
- {
- FINFO("no RadKV");
- }
- if (m_GenConfig.GetKeyCount("RadMAS") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadMASSize") > 0)
- {
- Num = (int)m_GenConfig["RadMASSize"];
- for (int i = 0; i < Num; i++)
- {
- float fMAS = m_GenConfig["RadMAS"][i];
- m_vecMAS.push_back(fMAS);
- }
- //m_DoseUnit.m_mAsList->Update((string)m_GenConfig["RadMAS"]);
- //FireNotify(m_DoseUnit.m_mAsList->GetKey(), m_DoseUnit.m_mAsList->JSGet());
- }
- FINFO("m_vecMAS {$}", m_vecMAS.size());
- }
- else
- {
- FINFO("no RadMAS");
- }
- if (m_GenConfig.GetKeyCount("RadMA") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadMASize") > 0)
- {
- Num = (int)m_GenConfig["RadMASize"];
- for (int i = 0; i < Num; i++)
- {
- float fMA = m_GenConfig["RadMA"][i];
- m_vecMA.push_back(fMA);
- }
- //m_DoseUnit.m_MAList->Update((string)m_GenConfig["RadMA"]);
- //FireNotify(m_DoseUnit.m_MAList->GetKey(), m_DoseUnit.m_MAList->JSGet());
- }
- FINFO("m_vecMA {$}", m_vecMA.size());
- }
- else
- {
- FINFO("no RadMA");
- }
- if (m_GenConfig.GetKeyCount("RadMS") > 0)
- {
- if (m_GenConfig.GetKeyCount("RadMSSize") > 0)
- {
- Num = (int)m_GenConfig["RadMSSize"];
- for (int i = 0; i < Num; i++)
- {
- float fMS = m_GenConfig["RadMS"][i];
- m_vecMS.push_back(fMS);
- }
- //m_DoseUnit.m_MSList->Update((string)m_GenConfig["RadMS"]);
- //FireNotify(m_DoseUnit.m_MSList->GetKey(), m_DoseUnit.m_MSList->JSGet());
- }
- FINFO("m_vecMS {$}", m_vecMS.size());
- }
- else
- {
- FINFO("no RadMS");
- }
- if (m_GenConfig.GetKeyCount("TableDAEC") > 0)
- {
- m_nTableUsePanelAEC = (int)(m_GenConfig["TableDAEC"]);
- FINFO("TableDAEC {$}", m_nTableUsePanelAEC);
- }
- else
- {
- FINFO("TableDAEC disable");
- }
- if (m_GenConfig.GetKeyCount("FreeDAEC") > 0)
- {
- m_nFreeUsePanelAEC = (int)(m_GenConfig["FreeDAEC"]);
- FINFO("FreeDAEC {$}", m_nFreeUsePanelAEC);
- }
- else
- {
- FINFO("FreeDAEC disable");
- }
- if (m_GenConfig.GetKeyCount("WallDAEC") > 0)
- {
- m_nWallUsePanelAEC = (int)(m_GenConfig["WallDAEC"]);
- FINFO("WallDAEC {$}", m_nWallUsePanelAEC);
- }
- else
- {
- FINFO("WallDAEC disable");
- }
- if (m_GenConfig.GetKeyCount("TableDDR") > 0)
- {
- m_nTableUsePanelDDR = (int)(m_GenConfig["TableDDR"]);
- FINFO("TableDDR {$}", m_nTableUsePanelDDR);
- }
- else
- {
- FINFO("TableDDR disable");
- }
- if (m_GenConfig.GetKeyCount("WallDDR") > 0)
- {
- m_nWallUsePanelDDR = (int)(m_GenConfig["WallDDR"]);
- FINFO("WallDDR {$}", m_nWallUsePanelDDR);
- }
- else
- {
- FINFO("WallDDR disable");
- }
- if (m_GenConfig.GetKeyCount("FreeDDR") > 0)
- {
- m_nFreeUsePanelDDR = (int)(m_GenConfig["FreeDDR"]);
- FINFO("FreeDDR {$}", m_nFreeUsePanelDDR);
- }
- else
- {
- FINFO("FreeDDR disable");
- }
- if (m_GenConfig.GetKeyCount("SendXwindowToDetector") > 0)
- {
- m_bSendXwindowToDector = ((int)m_GenConfig["SendXwindowToDetector"] > 1) ? true : false;
- FINFO("SendXwindowToDetector {$}", m_bSendXwindowToDector);
- }
- if (m_GenConfig.GetKeyCount("DEframeRate") > 0)
- {
- m_nDEFrameRate = (int)m_GenConfig["DEframeRate"];
- }
- FINFO("DEframeRate {$}", m_nDEFrameRate);
- return false;
- }
- nsGEN::DeltaDevice::~DeltaDevice()
- {
- ResetEvent(m_hHUstatus);
- ResetEvent(m_hGENstatus);
- SetEvent(m_hExitEvent);
- g_GenDevice = nullptr;
- if (m_pDetectorClient)
- {
- if (!m_pDetectorClient->IsClosed())
- {
- m_pDetectorClient->Close();
- }
- delete m_pDetectorClient;
- m_pDetectorClient = NULL;
- }
- }
- std::string nsGEN::DeltaDevice::GetGUID() const
- {
- FINFO("\n===============GetGUID : {$} ===================\n", GeneratorUnitType);
- return GeneratorUnitType;
- }
- void nsGEN::DeltaDevice::Register()
- {
- auto Disp = &Dispatch;
- superGen::Register(Disp);
- superGen::RegisterRAD(Disp);
- superGen::RegisterAEC(Disp);
- superGen::RegisterExpEnable(Disp);
- superGen::RegisterGeneratortoSyncStatus(Disp);
- Disp->Get.Push(m_MSGUnit->GetKey().c_str(), [this](std::string& out) { out = m_MSGUnit->JSGet(); return RET_STATUS::RET_SUCCEED; });
- }
- RET_STATUS nsGEN::DeltaDevice::IncKV()
- {
- if (!m_DoseUnit.m_KV->CanInc()) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_KV->Inc();
- SetKV(m_DoseUnit.m_KV->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecKV()
- {
- if (!m_DoseUnit.m_KV->CanDec()) return RET_STATUS::RET_SUCCEED;
- m_DoseUnit.m_KV->Dec();
- SetKV(m_DoseUnit.m_KV->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetKV(float value)
- {
- if (!m_DoseUnit.m_KV->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("KV: {$}", value);
- ChangeGenParam((int)value, m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::IncMA()
- {
- if (!m_DoseUnit.m_MA->CanInc()) return RET_STATUS::RET_SUCCEED;
- float fMA = m_DoseUnit.m_MA->Get();
- int pos = GetFacFloatValue(m_vecMA, fMA);
- FINFO("Current ma: {$}, pos: {$}", fMA, pos);
- pos++;
- if (pos >= 0 && pos < m_vecMA.size())
- {
- if (m_vecMAS[pos] == (m_nTubeMaBFMinValue * 100))
- {
- SetFocus(AttrKey::FOCUS_LARGE);
- }
- fMA = m_vecMA[pos];
- FINFO("Inc to MA: {$}", fMA);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), fMA, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecMA()
- {
- if (!m_DoseUnit.m_MA->CanDec()) return RET_STATUS::RET_SUCCEED;
- float fMA = m_DoseUnit.m_MA->Get();
- int pos = GetFacFloatValue(m_vecMA, fMA);
- FINFO("Current ma: {$}, pos: {$}", fMA, pos);
- pos--;
- if (pos >= 0 && pos < m_vecMA.size())
- {
- if (m_vecMA[pos] == (m_nTubeMaSFMaxValue * 100)) //small focus max value
- {
- SetFocus(AttrKey::FOCUS_TYPE::FOCUS_SMALL);//设置为小焦点
- }
- fMA = m_vecMA[pos];
- FINFO("Dec to MA: {$}", fMA);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), fMA, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetMA(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("MA: {$}", value);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), value, m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::IncMS()
- {
- if (!m_DoseUnit.m_MS->CanInc()) return RET_STATUS::RET_SUCCEED;
- float fMS = m_DoseUnit.m_MS->Get();
- int pos = GetFacFloatValue(m_vecMS, fMS);
- FINFO("Current ms: {$}, pos: {$}", fMS, pos);
- pos++;
- if (pos >= 0 && pos < m_vecMS.size())
- {
- fMS = m_vecMS[pos];
- FINFO("Inc to MS: {$}", fMS);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), fMS, m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecMS()
- {
- if (!m_DoseUnit.m_MS->CanDec()) return RET_STATUS::RET_SUCCEED;
- float fMS = m_DoseUnit.m_MS->Get();
- int pos = GetFacFloatValue(m_vecMS, fMS);
- FINFO("Current ms: {$}, pos: {$}", fMS, pos);
- pos--;
- if (pos >= 0 && pos < m_vecMS.size())
- {
- float fms = m_vecMS[pos];
- FINFO("Dec to MS: {$}", fms);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), fms, m_DoseUnit.m_MAS->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetMS(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("MS: {$}", value);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), value, m_DoseUnit.m_MAS->Get());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::IncMAS()
- {
- if (!m_DoseUnit.m_MAS->CanInc()) return RET_STATUS::RET_SUCCEED;
- float fMAS = m_DoseUnit.m_MAS->Get();
- int pos = GetFacFloatValue(m_vecMAS, fMAS);
- FINFO("Current mas: {$}, pos: {$}", fMAS, pos);
- pos++;
- if (pos >= 0 && pos < m_vecMAS.size())
- {
- fMAS = m_vecMAS[pos];
- FINFO("Inc to MAS: {$}", fMAS);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), fMAS);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::DecMAS()
- {
- if (!m_DoseUnit.m_MAS->CanDec()) return RET_STATUS::RET_SUCCEED;
- float fMAS = m_DoseUnit.m_MAS->Get();
- int pos = GetFacFloatValue(m_vecMAS, fMAS);
- FINFO("Current mas: {$}, pos: {$}", fMAS, pos);
- pos--;
- if (pos >= 0 && pos < m_vecMAS.size())
- {
- fMAS = m_vecMAS[pos];
- FINFO("Dec to MAS: {$}", fMAS);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), fMAS);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetMAS(float value)
- {
- if (!m_DoseUnit.m_MA->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("MAS: {$}", value);
- ChangeGenParam(m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetTechmode(int value)
- {
- //0 MS 1 MAS 2 AEC
- //if (!m_DoseUnit.m_Techmode->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("[0xF0, 0x51, 0xA1, 0x0{$}]", value);
- char cmdbuf[20] = { 0xF0, 0x51, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- m_DoseUnit.m_Techmode->Update(value);
- if (value == 0)
- {
- SetDAECEnable(0);//禁用DAEC
- cmdbuf[3] = 2;
- }
- else if (value == 1)
- {
- SetDAECEnable(0);//禁用DAEC
- cmdbuf[3] = 3;
- }
- else if (value == 2)
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- SetDAECEnable(1);
- cmdbuf[3] = 2;//time
- }
- else
- {
- SetDAECEnable(0);
- cmdbuf[3] = 1;//应用GEN的aec功能
- cmdbuf[4] = m_nChamberIndex;//chabmer index
- int nAECFieldSel = 2;
- switch (m_DoseUnit.m_AECField->Get())
- {
- case 100:
- nAECFieldSel = 1;
- break;
- case 10:
- nAECFieldSel = 2;
- break;
- case 110:
- nAECFieldSel = 3;
- break;
- case 1:
- nAECFieldSel = 4;
- break;
- case 101:
- nAECFieldSel = 5;
- break;
- case 11:
- nAECFieldSel = 6;
- break;
- case 111:
- nAECFieldSel = 7;
- break;
- default:
- nAECFieldSel = 2;
- break;
- }
- cmdbuf[5] = nAECFieldSel;//field
- cmdbuf[6] = 0;
- cmdbuf[7] = 0;
- SetAECInformation(m_nChamberIndex, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- SetDAECEnable(1);
- cmdbuf[3] = 2;//time
- }
- else
- {
- SetDAECEnable(0);
- cmdbuf[3] = 1;//应用GEN的aec功能
- cmdbuf[4] = m_nChamberIndex;//chabmer index
- int nAECFieldSel = 2;
- switch (m_DoseUnit.m_AECField->Get())
- {
- case 100:
- nAECFieldSel = 1;
- break;
- case 10:
- nAECFieldSel = 2;
- break;
- case 110:
- nAECFieldSel = 3;
- break;
- case 1:
- nAECFieldSel = 4;
- break;
- case 101:
- nAECFieldSel = 5;
- break;
- case 11:
- nAECFieldSel = 6;
- break;
- case 111:
- nAECFieldSel = 7;
- break;
- default:
- nAECFieldSel = 2;
- break;
- }
- cmdbuf[5] = nAECFieldSel;//field
- cmdbuf[6] = 0;
- cmdbuf[7] = 0;
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- SetDAECEnable(1);
- cmdbuf[3] = 2;//time
- }
- else
- {
- SetDAECEnable(0);
- cmdbuf[3] = 1;//应用GEN的aec功能
- cmdbuf[4] = m_nChamberIndex;//chabmer index
- int nAECFieldSel = 2;
- switch (m_DoseUnit.m_AECField->Get())
- {
- case 100:
- nAECFieldSel = 1;
- break;
- case 10:
- nAECFieldSel = 2;
- break;
- case 110:
- nAECFieldSel = 3;
- break;
- case 1:
- nAECFieldSel = 4;
- break;
- case 101:
- nAECFieldSel = 5;
- break;
- case 11:
- nAECFieldSel = 6;
- break;
- case 111:
- nAECFieldSel = 7;
- break;
- default:
- nAECFieldSel = 2;
- break;
- }
- cmdbuf[5] = nAECFieldSel;//field
- cmdbuf[6] = 0;
- cmdbuf[7] = 0;
- if (m_DoseUnit.m_AECFilm->Get() == 0)
- SetAECInformation(m_nChamberIndex, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
- }
- }
- }
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetFocus(int value)
- {
- if (!m_DoseUnit.m_Focus->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("[0xF0, 0x5A, 0xA1, 0x00] focus: {$}", value);
- char cmdbuf[20] = { 0xF0, 0x5A, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- if (value == 0)
- {
- cmdbuf[3] = 2;
- }
- else if (value == 1)
- {
- cmdbuf[3] = 1;
- }
- else
- {
- cmdbuf[3] = 3;
- }
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAECDensity(int value)
- {
- if (!m_DoseUnit.m_AECDensity->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("AECDensity: {$}", value);
- if (value < -3)
- {
- value = -3;
- }
- else if (value > 3)
- {
- value = 3;
- }
- if (m_DoseUnit.m_AECDensity->Get() != value)
- {
- SetAECInformation(1, m_DoseUnit.m_AECField->Get(), value, m_DoseUnit.m_AECFilm->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAECField(int value)
- {
- if (!m_DoseUnit.m_AECField->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("AECField: {$}", value);
- if (m_DoseUnit.m_AECField->Get() != value)
- {
- SetAECInformation(1, value, m_DoseUnit.m_AECDensity->Get(), m_DoseUnit.m_AECFilm->Get());
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAECFilm(int value)
- {
- if (!m_DoseUnit.m_AECFilm->Verify(value)) return RET_STATUS::RET_SUCCEED;
- FINFO("AECFilm: {$}", value);
- if (m_DoseUnit.m_AECFilm->Get() != value)
- {
- SetAECInformation(1, m_DoseUnit.m_AECField->Get(), m_DoseUnit.m_AECDensity->Get(), value);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetWS(const string value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetAPR(const _tAPRArgs& t)
- {
- m_tAPRdata = t;
- FINFO("Focus: {$}, Techmode: {$}, AECField: {$}, AECFilm: {$}, AECDensity: {$}, KV: {$}, MA: {$}, MS: {$}, KV2: {$}, MA2: {$}, MS2: {$}, MAS: {$}",
- m_tAPRdata.nFocus, m_tAPRdata.nTechmode, m_tAPRdata.nAECField, m_tAPRdata.nAECFilm, m_tAPRdata.nAECDensity, m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS, m_tAPRdata.fKV2, m_tAPRdata.fMA2, m_tAPRdata.fMS2, m_tAPRdata.fMAS);
- if (m_tAPRdata.fKV2 != 0)
- {
- SetDualEnergyCommand(m_tAPRdata);
- }
- else
- {
- SetRadMode(0, 0);
- if ((int)m_tAPRdata.fMA > m_nTubeMaSFMaxValue)
- {
- SetFocus(1);
- }
- else
- {
- SetFocus(0);
- }
- SetTechmode(m_tAPRdata.nTechmode);
- if (m_tAPRdata.nTechmode == AttrKey::TECHMODE_AEC_3P)
- {
- if (m_tAPRdata.nWS == AttrKey::TABLE)
- {
- if (m_nTableUsePanelAEC != 1)
- {
- if (m_DoseUnit.m_AECFilm->Get() == 0)
- m_DoseUnit.m_AECFilm->Update(1);
- SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
- SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- else if (m_tAPRdata.nWS == AttrKey::WALL)
- {
- if (m_nWallUsePanelAEC != 1)
- {
- if (m_tAPRdata.nAECFilm == 0)
- m_tAPRdata.nAECFilm = 1;
- SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
- SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- else if (m_tAPRdata.nWS == AttrKey::MOBILE)
- {
- if (m_nFreeUsePanelAEC != 1)
- {
- if (m_tAPRdata.nAECFilm == 0)
- m_tAPRdata.nAECFilm = 1;
- SetAECInformation(m_nChamberIndex, m_tAPRdata.nAECField, m_tAPRdata.nAECDensity, m_tAPRdata.nAECFilm);
- SetAECKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- }
- else if (m_tAPRdata.nTechmode == AttrKey::TECHMODE_NOAEC_2P)
- {
- SetRADKV_MAS((int)m_tAPRdata.fKV, m_tAPRdata.fMAS);
- }
- else
- {
- SetRADKV_MA_MS((int)m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS);
- }
- }
- m_bSetAPR = true;
- return RET_STATUS::RET_SUCCEED;
- }
- bool nsGEN::DeltaDevice::SetDualEnergyCommand(const _tAPRArgs& t)
- {
- if (!m_bIsDualExp)
- SetRadMode(1, 1);
- if (m_nExposureNumber == 0)
- {
- FINFO("Dual Energy First APR KV: {$}, MA: {$}, MS: {$}, MAS: {$}", t.fKV, t.fMA, t.fMS, t.fMAS);
- m_bIsDualExp = true;
- //设置双能第一组曝光参数
- SetAPRForDual(t.nWS, t.nFocus, t.nTechmode, t.nAECField, t.nAECFilm, t.nAECDensity, t.fKV, t.fMA, t.fMS, t.fMAS);
- //双能是序列点片,是需要配置帧率的
- FINFO("Set de framerate[0xF0, 0x6D, 0xAD, 0xxx]");
- char cmdbuf[20] = { 0xF0, 0x6D, 0xAD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xDB, 0x00, 0x88 };
- cmdbuf[3] = m_nDEFrameRate * 10;
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- else if (m_nExposureNumber == 1)
- {
- //2 set 2nd array param
- FINFO("Dual Energy Second APR KV: {$}, MA: {$}, MS: {$}", t.fKV2, t.fMA2, t.fMS2);
- //设置第二组参数
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_AEC_3P)
- {
- SetAECInformation(m_nChamberIndex, t.nAECField, t.nAECDensity, 0);
- SetAECKV_MA_MS((int)t.fKV2, t.fMA2, t.fMS2);
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_NOAEC_2P)
- {
- SetRADKV_MAS((int)t.fKV2, t.fMA2 * t.fMS2 / 1000);
- }
- else
- {
- SetRADKV_MA_MS((int)t.fKV2, t.fMA2, t.fMS2);
- }
- //m_bIsDualExp = false; //第二次设定之后,主动false
- //m_nExposureNumber = 0;
- }
- return true;
- }
- bool nsGEN::DeltaDevice::SetAPRForDual(int nWS, int nFO, int nET, int nAECFieldSel, int nAECFilmSel, float fAECDensity, float fKV, float fMA, float fMS, float fMAS)
- {
- FINFO("Focus: {$}, Techmode: {$}, AECField: {$},AECFilm: {$}, AECDensity: {$}, KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
- m_tAPRdata.nFocus, m_tAPRdata.nTechmode, m_tAPRdata.nAECField, m_tAPRdata.nAECFilm, m_tAPRdata.nAECDensity, m_tAPRdata.fKV, m_tAPRdata.fMA, m_tAPRdata.fMS, m_tAPRdata.fMAS);
- //客户说160是 small FO的最大值。 180是大焦点的最小值
- if ((int)fMA > m_nTubeMaSFMaxValue)
- {
- SetFocus(1);
- }
- else
- {
- SetFocus(0);
- }
- if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_AEC_3P)
- {
- if (nAECFilmSel == 0)
- nAECFilmSel = 1;
- SetAECInformation(m_nChamberIndex, nAECFieldSel, fAECDensity, nAECFilmSel);
- SetAECKV_MA_MS((int)fKV, fMA, fMS);
- }
- else if (m_DoseUnit.m_Techmode->Get() == AttrKey::TECHMODE_NOAEC_2P)
- {
- SetRADKV_MAS((int)fKV, fMAS);
- }
- else
- {
- SetRADKV_MA_MS((int)fKV, fMA, fMS);
- }
- return true;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryHE(int& value)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostKV(float& value)
- {
- m_DoseUnit.m_PostKV->Update(m_DoseUnit.m_KV->Get());
- value = m_DoseUnit.m_PostKV->Get();
- return RET_STATUS::RET_FAILED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostMA(float& value)
- {
- value = m_DoseUnit.m_PostMA->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostMS(float& value)
- {
- value = m_DoseUnit.m_PostMS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::QueryPostMAS(float& value)
- {
- value = m_DoseUnit.m_PostMAS->Get();
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetGenSynState(int value)
- {
- FINFO("GenSynState: {$}", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetGenState(int value)
- {
- FINFO("GenState: {$}", value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetExpMode(std::string value)
- {
- FINFO("ExpMode: {$}", value.c_str());
- m_DoseUnit.m_ExpMode->Update(value);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetFLFMode(std::string value)
- {
- FINFO("FLFMode: {$}", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetEXAMMode(std::string value)
- {
- FINFO("EXAMMode: {$}", value.c_str());
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetFrameRate(FLOAT frameRate)
- {
- if (m_DoseUnit.m_FrameRate->Verify(frameRate))
- {
- FINFO("[0xF0, 0x56, 0xA2, 0x00] FrameRate: {$}", frameRate);
- char cmdbuf[13] = { 0xF0, 0x56, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- int nPPS = (int)(frameRate * 10);
- cmdbuf[3] = nPPS / 256;
- cmdbuf[4] = nPPS % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
-
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- //貌似最好有时间间隔
- RET_STATUS nsGEN::DeltaDevice::RefreshData()
- {
- FINFO("RefreshData");
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetExpEnable()
- {
- char cmdbuf[13] = { 0xF0, 0x5C, 0xA3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5, 0x00, 0x88 };
- FINFO("[0xF0, 0x5C, 0xA3, 0x00]");
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::SetExpDisable()
- {
- char cmdbuf[13] = { 0xF0, 0x5C, 0xA3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, 0x88 };
- FINFO("ExpEnable[0xF0, 0x5C, 0xA3, 0x01]");
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
-
- HWSendWaitACKCMD(m_strCommand, 4);
- m_nProcessXrayon = false;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS nsGEN::DeltaDevice::Reset()
- {
- FINFO("[0xF0 ,0x59 ,0xA1 ,CurErrLevel{$}]", m_nCurErrLevel);
- char cmdbuf[13] = { 0xF0 ,0x59 ,0xA1 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x88 };
- cmdbuf[3] = m_nCurErrLevel;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return RET_STATUS::RET_SUCCEED;
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::DeltaDevice::ProcessClientData(const char* pData, unsigned long nDataLength, void* lparam)
- {
- DeltaDevice* pCurGen = (DeltaDevice*)lparam;
- pCurGen->HWSend(pData, nDataLength);
- }
- void nsGEN::DeltaDevice::WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level)
- {
- }
- RET_STATUS nsGEN::DeltaDevice::HWSendWaitACKCMD(string strCommand, int headLengh)
- {
- return m_tDelivermodule.ProcessCommand(strCommand, m_nCMDType_WaitACK, headLengh);
- }
- RET_STATUS nsGEN::DeltaDevice::HWSend(const char* strCommand, int lengh, int nTimeOut)
- {
- FINFO("{$}", m_SCF.isConnected());
- if (m_SCF.isConnected())
- {
- char strtemp[10] = { 0 };
- string str = "";
- for (int i = 0; i < lengh; i++)
- {
- sprintf_s(strtemp, sizeof(strtemp), "%02X", (BYTE)strCommand[i]);
- str += strtemp;
- str += ",";
- }
- FINFO("==OUT==: {$}", str);
- if (!m_SCF)
- return RET_STATUS::RET_FAILED;
- int retLength;
- m_SCF.Lock(msTimeOut_Lock)
- .SendPacket(strCommand, lengh, nTimeOut, retLength);
- }
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::DeltaDevice::FireErrorMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string ErrorCode("DELTA_ERR_");
- ErrorCode += std::to_string(Code);
- int level = DELTA_ABNORMAL_LEVEL::REG_ERRO;
- if (Act)
- {
- FERROR("add {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->AddErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", ErrorCode.c_str(), ResInfo);
- m_MSGUnit->DelErrorMessage(ErrorCode.c_str(), level, ResInfo);
- }
- }
- void nsGEN::DeltaDevice::FireWarnMessage(const bool Act, const int Code, const char* ResInfo)
- {
- string WarnCode("DELTA_WAR_");
- WarnCode += std::to_string(Code);
- int level = DELTA_ABNORMAL_LEVEL::REG_WARN;
- if (Act)
- {
- FERROR("add {$}:{$}", WarnCode.c_str(), ResInfo);
- m_MSGUnit->AddWarnMessage(WarnCode.c_str(), level, ResInfo);
- }
- else
- {
- FERROR("del {$}:{$}", WarnCode.c_str(), ResInfo);
- m_MSGUnit->DelWarnMessage(WarnCode.c_str(), level, ResInfo);
- }
- }
- //-----------------------------------------------------------------------------
- // ProcessCmd
- //-----------------------------------------------------------------------------
- void nsGEN::DeltaDevice::FireNotify(std::string key, std::string content)
- {
- EventCenter->OnNotify(1, key, content);
- }
- void nsGEN::DeltaDevice::ProcessCommand(const char* strPackage, int Index, int End)
- {
- if ((BYTE)strPackage[Index] == 0xF0)
- {
- if (strPackage[End - 4] != 0x0A)
- {
- //GetLastExpParamenters();
- char WarnCode[20];
- sprintf_s(WarnCode, "DELTA_WARN_%03d", (BYTE)strPackage[End - 4]);
- int level = 1;
- FINFO("{$}", WarnCode);
- auto it = m_WarnMessages.find(WarnCode);
- if (it != m_WarnMessages.end())
- {
- m_MSGUnit->AddWarnMessage(WarnCode, level, it->second.c_str());
- //return false;
- }
- }
- }
- m_bReconnect = false;
- const char* chdigital;
- m_nCountTimes = 0;
- if (UINT8(strPackage[Index]) != 0xF0)
- {
- FINFO("simple cmd:{$}", strPackage);
- if (strPackage[Index] == 'C' && strPackage[Index + 1] == 'X' && strPackage[Index + 2] == 'L')
- {
- m_nProcessXrayon = false;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- if (strPackage[Index] == 'E' && strPackage[Index + 1] == 'R' && strPackage[Index + 2] == 'R')
- {
- m_nProcessXrayon = false;
- chdigital = strPackage + 3;
- int errornumber = atoi(chdigital);
- if (errornumber < 3000) //warn
- {
- char WarnCode[20];
- sprintf_s(WarnCode, "DELTA_WARN_%03d", (BYTE)strPackage[End - 4]);
- int level = 1;
- FINFO("{$}", WarnCode);
- auto itwarn = m_WarnMessages.find(WarnCode);
- if (itwarn != m_WarnMessages.end())
- {
- m_MSGUnit->AddWarnMessage(WarnCode, level, itwarn->second.c_str());
- //return false;
- }
- //如果error=0012,那么表示一档松开。那么应该发送release,取消本次曝光,否则会出现超时的问题
- if (errornumber == 12 || errornumber == 1006)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_RAD_OFF);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- }
- if (errornumber >= 4000)
- {
- m_nCurErrLevel = 3;
- }
- if (errornumber >= 3000)
- {
- m_nCurErrLevel = 1;
- }
- char ErrCode[20];
- sprintf_s(ErrCode, "DELTA_ERR_%04d", (BYTE)strPackage[3]);
- FINFO("{$}", ErrCode);
- auto iterr = m_ErrorMessages.find(ErrCode);
- if (iterr != m_ErrorMessages.end())
- {
- m_MSGUnit->AddErrorMessage(ErrCode, level, iterr->second.c_str());
- //return false;
- }
- }
- }
- if (strPackage[Index] == 'R' && strPackage[Index + 1] == 'O' && strPackage[Index + 2] == 'N')//RON RDY XON OFF
- {
- m_nProcessXrayon = true;
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::CONVENTIONAL)
- {
- m_DoseUnit.m_Handswitch->Update(AttrKey::HANDSWITCH_STATUS::HANDSWITCH_STATUS_Release);
- FireNotify(m_DoseUnit.m_Handswitch->GetKey(), m_DoseUnit.m_Handswitch->JSGet());
- FINFO("Updata m_DoseUnit.m_Handswitch: {$}", m_DoseUnit.m_Handswitch->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- }
- if (strPackage[Index] == 'R' && strPackage[Index + 1] == 'D' && strPackage[Index + 2] == 'Y')//RON RDY XON OFF
- {
- m_nProcessXrayon = true;
- if (m_DoseUnit.m_GenSynState->Get() != AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_PREPARE);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_READY);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- Sleep(20);//此发生器RDY和XON有时消息会过快,导致工作流没反应过来。所以加个睡眠。
- FINFO("m_bIsDualExp: {$} m_nExposureNumber: {$}", m_bIsDualExp, m_nExposureNumber);
- if (m_bIsDualExp && (m_nExposureNumber == 1))
- {
- if (m_bSendXwindowToDector)
- {
- m_pDetectorClient = new LogicClient("DV3_Detector", "", "NSQ", false);
- if (m_pDetectorClient->Open("CCOS/DEVICE/Detector", ALL_ACCESS)) //换成探测器的路径
- {
- FDEBUG("Ccos_V3 Create DV3_Detector Client success");
- }
- }
- if (m_pDetectorClient != NULL)
- {
- if (!m_pDetectorClient->IsClosed())
- {
- FINFO("m_pDetectorClient is open");
- ResDataObject Request, Response;
- Request.add("P0", 1);
- m_pDetectorClient->Action("DualSecondExpReady", Request, Response, 4993);
- }
- else
- {
- FINFO("DV3_Detector Client is Close");
- }
- }
- else
- {
- FINFO("DV3_FullUCB Client is NULL");
- }
- m_bIsDualExp = false; //第二次设定之后,主动false
- m_nExposureNumber = 0;
- }
- }
- if (strPackage[Index] == 'X' && strPackage[Index + 1] == 'O' && strPackage[Index + 2] == 'N')//RON RDY XON OFF
- {
- m_nProcessXrayon = true;
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYON);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- m_bXronMsg = true;
- }
- if (strPackage[Index] == 'O' && strPackage[Index + 1] == 'F' && strPackage[Index + 2] == 'F')//RON RDY XON OFF
- {
- if (m_bXronMsg == false)
- {
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYON);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- }
- m_DoseUnit.m_GenSynState->Update(AttrKey::GENERATOR_SYNC::GENERATOR_RAD_XRAYOFF);
- FireNotify(m_DoseUnit.m_GenSynState->GetKey(), m_DoseUnit.m_GenSynState->JSGet());
- FINFO("Updata m_DoseUnit.m_GenSynState: {$}", m_DoseUnit.m_GenSynState->JSGet());
- GetLastExpParamenters();
- if (m_bIsDualExp)
- {
- m_nExposureNumber = 1;
- SetDualEnergyCommand(m_tAPRdata);
- FINFO("dual: setapr 2nd.");
- }
- m_nProcessXrayon = false;
- m_bXronMsg = false;
- }
- return;
- }
- switch (UINT8(strPackage[Index + 1]))
- {
- case 0x50:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- //50A1
- FINFO("Restore factory settings successfully");
- break;
- default:
- break;
- }
- break;
- }
- case 0x51:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5101
- int nET = (int)(strPackage[Index + 3]);
- FINFO("ET{$}", nET);
- if (nET == 1)//AEC
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else if (nET == 2)//MS
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (nET == 3)//MAS
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_2P);
- }
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- FINFO("[51 01]: ET {$}", m_DoseUnit.m_Techmode->Get());
- break;
- }
- case 0xA1:
- {
- //51A1
- int nET = (int)(strPackage[Index + 3]);
- if (nET == 1)//AEC
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_TYPE::TECHMODE_AEC_3P);
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- m_AECinformation.Chamber = (int)(strPackage[4]);
- m_AECinformation.Field = (int)(strPackage[5]);
- m_AECinformation.Density = (int)(strPackage[6]);
- m_AECinformation.FilmScreenSpeed = (int)(strPackage[7]);
- UpdataAECInformation(m_AECinformation);
- }
- else if (nET == 2)//如果当前是DAEC模式,那么返回的是time,但是可能需要选中 AEC 按钮
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_AEC_3P);
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- }
- else
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_3P);
- }
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- }
- else if (nET == 3)
- {
- m_DoseUnit.m_Techmode->Update(AttrKey::TECHMODE_NOAEC_2P);
- }
- FireNotify(m_DoseUnit.m_Techmode->GetKey(), m_DoseUnit.m_Techmode->JSGet());
- FINFO("[51 A1]: ET {$}", m_DoseUnit.m_Techmode->Get());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x52:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5201
- FINFO("[52 01]");
- break;
- }
- case 0xA1:
- {
- //52A1
- FINFO("[52 A1]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x53:
- {
- switch (UINT8(strPackage[2]))
- {
- case 0x01:
- {
- //5301
- FINFO("[53 01]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x54:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5401
- FINFO("[54 01]");
- break;
- }
- case 0x02:
- {
- //5402
- FINFO("[54 02]");
- break;
- }
- case 0xA1:
- {
- //54A1
- FINFO("[54 A1]");
- break;
- }
- case 0xA2:
- {
- //54A2
- FINFO("[54 A2]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x55:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- case 0xA1:
- {
- //55A1
- m_AECinformation.Chamber = (int)(strPackage[Index + 3]);
- m_AECinformation.Field = (int)(strPackage[Index + 4]);
- m_AECinformation.Density = (int)(strPackage[Index + 5]);
- m_AECinformation.FilmScreenSpeed = (int)(strPackage[Index + 6]);
- UpdataAECInformation(m_AECinformation);
- FINFO("[55 A1]: AEC");
- break;
- }
- case 0xA2:
- {
- //55A2
- //kv
- int nKv = (BYTE)(strPackage[Index + 3]);
- m_DoseUnit.m_KV->Update(nKv);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- //ma
- float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
- m_DoseUnit.m_MA->Update(fMA);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- //aec reference kv
- //not ms
- float m_fMS = ((BYTE)strPackage[Index + 6] * 256 + (BYTE)strPackage[Index + 7]) / 10.0f;
- m_DoseUnit.m_MS->Update(m_fMS);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- int hundred_aec_referenc_kv = (BYTE)strPackage[Index + 6] * 256 + (BYTE)strPackage[Index + 7];
- float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
- GetFacFloatValue(m_vecMAS, mas);
- m_DoseUnit.m_MAS->Update(mas);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- FINFO("[55 A2]: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
- m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x56:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x02:
- {
- //5602
- //查询脉冲帧率,不用
- FINFO("[56 02]: AEC.");
- break;
- }
- case 0xA1:
- {
- //56A1
- //kv
- int nKv = (BYTE)(strPackage[Index + 3]);
- m_DoseUnit.m_KV->Update(nKv);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- //ma
- float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
- m_DoseUnit.m_MA->Update(fMA);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- //ms
- float fMS = ((BYTE)(strPackage[Index + 6]) * 65536 + (BYTE)strPackage[Index + 7] * 256 + (BYTE)strPackage[Index + 8]) / 10.0f;
- m_DoseUnit.m_MS->Update(fMS);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
- GetFacFloatValue(m_vecMAS, mas);
- m_DoseUnit.m_MAS->Update(mas);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- FINFO("[56 A1]: Time mode: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}",
- m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- break;
- }
- case 0xA2:
- {
- //56A2设置脉冲帧率,暂时不用
- FINFO("[56 A2]:");
- break;
- }
- case 0xA3:
- {
- //56A3透视检查的kv ma mas,暂时用不到,不解析了。
- FINFO("[56 A3]:");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x57://-----------------------------------------------------------首次进入时,直接切换到mas,ma ms 没有消失****************bug
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- {
- //57A1mas模式下的 kv mas 解析
- //kv
- int nKv = (int)(strPackage[Index + 3]);
- m_DoseUnit.m_KV->Update(nKv);
- FireNotify(m_DoseUnit.m_KV->GetKey(), m_DoseUnit.m_KV->JSGet());
- //ma
- float fMA = ((BYTE)(strPackage[Index + 4]) * 256 + (BYTE)strPackage[Index + 5]) / 10.0f;
- m_DoseUnit.m_MA->Update(fMA);
- FireNotify(m_DoseUnit.m_MA->GetKey(), m_DoseUnit.m_MA->JSGet());
- //ms----MAS 模式下,返回的ms值。
- float fMS = ((BYTE)(strPackage[Index + 6]) * 65536 + (BYTE)strPackage[Index + 7] * 256 + (BYTE)strPackage[Index + 8]) / 10.0f;
- m_DoseUnit.m_MS->Update(fMS);
- FireNotify(m_DoseUnit.m_MS->GetKey(), m_DoseUnit.m_MS->JSGet());
- float mas = m_DoseUnit.m_MA->Get() * m_DoseUnit.m_MS->Get() / 1000.0f;
- GetFacFloatValue(m_vecMAS, mas);
- m_DoseUnit.m_MAS->Update(mas);
- FireNotify(m_DoseUnit.m_MAS->GetKey(), m_DoseUnit.m_MAS->JSGet());
- FINFO("[57 A1]: MAS mode: Updata: KV: {$}, MA: {$}, MS: {$}, MAS: {$}(calc)", m_DoseUnit.m_KV->Get(), m_DoseUnit.m_MA->Get(), m_DoseUnit.m_MS->Get(), m_DoseUnit.m_MAS->Get());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x58:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 1:
- {
- int dapStatus = (int)(strPackage[Index + 2]);
- if (1 == dapStatus)
- {
- //dap enable
- float fDap = 0;
- UINT8 tmpBuf[4] = { 0 };
- tmpBuf[0] = strPackage[Index + 7];
- tmpBuf[1] = strPackage[Index + 6];
- tmpBuf[2] = strPackage[Index + 5];
- tmpBuf[3] = strPackage[Index + 4];
- memcpy(&fDap, tmpBuf, 4);
- int nDAP = (int)fDap;
- }
- else
- {
- //dap disable
- }
- break;
- }
- case 2:
- {
- //dap rate
- float fDapRate = 0;
- UINT8 tmpBuf[4] = { 0 };
- tmpBuf[0] = strPackage[Index + 6];
- tmpBuf[1] = strPackage[Index + 5];
- tmpBuf[2] = strPackage[Index + 4];
- tmpBuf[3] = strPackage[Index + 3];
- memcpy(&fDapRate, tmpBuf, 4);
- //mGycm^2/s
- break;
- }
- case 0xA1:
- {
- FINFO("[58 A1]: clear dap and dap rate success!");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x59:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- {
- //59A1
- int nResetLevel = (int)(strPackage[Index + 3]);
- FINFO("[59 A1]:");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5A:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5A01
- FINFO("[5A 01]:");
- break;
- }
- case 0xA1:
- {
- //5AA1
- int nFo = (int)(strPackage[Index + 3]);
- if (1 == nFo)
- {
- m_DoseUnit.m_Focus->Update(1);
- }
- else if (2 == nFo)
- {
- m_DoseUnit.m_Focus->Update(0);
- }
- else//auto
- {
- m_DoseUnit.m_Focus->Update(0);
- }
- FireNotify(m_DoseUnit.m_Focus->GetKey(), m_DoseUnit.m_Focus->JSGet());
- //RetrieveGeneratroDerating();
- FINFO("[5A A1]: FO= {$}", m_DoseUnit.m_Focus->Get());
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5B:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5B01
- FINFO("[5B 01]");
- break;
- }
- case 0xA1:
- {
- //5BA1
- FINFO("[5B A1]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5C:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0xA1:
- {
- //5CA1
- FINFO("[5C A1]:Gen Operate Status is Shutdown");
- break;
- }
- case 0xA2:
- {
- //5CA2
- FINFO("[5C A2]:Gen Operate Status is StandBy");
- break;
- }
- case 0x03:
- case 0xA3:
- {
- //5CA3
- int nExpEnable = (int)(strPackage[Index + 3]);
- FINFO("[5C A3/03]:m_bExpEnable");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5E:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- FINFO("[5E 01]:tube id is 1");
- break;
- }
- case 0x02:
- {
- FINFO("[5E 01]:tube id is 2");
- break;
- }
- case 0x03:
- {
- FINFO("[5E 03]");
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x5F:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //5F01
- int TenTubeHU = BYTE(strPackage[Index + 3]) * 256 + (BYTE)strPackage[Index + 4];
- m_DoseUnit.m_HE->Update(TenTubeHU / 10);
- FireNotify(m_DoseUnit.m_HE->GetKey(), m_DoseUnit.m_HE->JSGet());
- ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_HE, this->m_nTubeHeat);
- //int TenGenHU = BYTE(strPackage[5]) * 256 + (BYTE)strPackage[6];
- //m_nGenHeat = TenGenHU / 10;
- ////GEN_PARAM_GENHEAT->侯雷确认 是温度。不应该用于这里
- ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_GENHEAT, this->m_nGenHeat);
- ////GEN_TUBEHU_STATUS 是状态,协议中没有根据genhu的值来定义状态的规定。因此不用这段代码
- ////::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_TUBEHU_STATUS, this->m_nGenHeat);
- //int TenMotorHU = BYTE(strPackage[7]) * 256 + (BYTE)strPackage[8];
- //strlog.Format("5F 01,tube HU = %d,gen HU*10=%d MotorHU*10=%d", m_nTubeHeat, TenGenHU, TenMotorHU);
- //logfile->WriteLog(strlog, LOG_INFORMATION, LOG_DEBUG, true);
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x61:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- string GenFirmwareVersion = AnalysisCommand(BYTE_6, chdigital, TransToType::tochar);
- string ConsoleFirmwareVersion = AnalysisCommand(BYTE_6, chdigital, TransToType::tochar);
- FINFO("[61 01]:Generator firmware version {$}, Console firmware version {$}", GenFirmwareVersion, ConsoleFirmwareVersion);
- break;
- }
- case 0x02:
- {
- break;
- }
- case 0x03:
- {
- break;
- }
- case 0x04:
- {
- int maxKw = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int maxMa = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int maxMas = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int maxKv = (int)(strPackage[Index + 9]);
- int nFo = (int)(strPackage[Index + 10]);
- int nRotor = (int)(strPackage[Index + 11]);
- int nMotorFirmwareVersion = (int)(strPackage[Index + 12] << 8 | strPackage[Index + 13]);
- int nSWCfgFileVersion = (int)(strPackage[Index + 14]);
- break;
- }
- case 0x05:
- {
- m_nMaxKW = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int maxDeratingMa = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int maxDeratingMas = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int maxDeratingKv = (int)(strPackage[Index + 9]);
- int minDeratingMa = (int)(strPackage[Index + 10] << 8 | strPackage[Index + 11]);
- int maxDeratingMs = (int)(strPackage[Index + 12] << 8 | strPackage[Index + 13]);
- break;
- }
- case 0x06:
- {
- break;
- }
- case 0xA5:
- {
- break;
- }
- case 0x07:
- case 0xA7:
- {
- int nAccuracy = (int)(strPackage[Index + 3]);
- if (1 == nAccuracy)
- {
- //logfile->WriteLog("61 07 / A7 :now is R10' series.", LOG_INFORMATION, LOG_DEBUG, true);
- }
- else if (2 == nAccuracy)
- {
- //logfile->WriteLog("61 07 / A7 :now is R20' series.", LOG_INFORMATION, LOG_DEBUG, true);
- }
- break;
- }
- case 0xAC:
- {
- //DAEC enable status
- int nDaecStatus = (int)(strPackage[Index + 3]);
- //m_nDAECStatus = nDaecStatus;
- //if (nDaecStatus == 1)
- //{
- // logfile->WriteLog("recv 6e AC: daec enable", LOG_INFORMATION, LOG_DEBUG, true);
- //}
- //else if (nDaecStatus == 2)
- //{
- // logfile->WriteLog("recv 6e AC: daec disable", LOG_INFORMATION, LOG_DEBUG, true);
- //}
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x62:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- break;
- }
- case 0x02:
- {
- chdigital = strPackage + 3;
- int SF_LS_MaxPower = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int LF_LS_MaxPower = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int SF_HS_MaxPower = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_HS_MaxPower = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0x03:
- {
- int SF_standbycurrent = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int SF_maxcurrent = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int LF_standbycurrent = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_maxcurrent = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0x04:
- {
- int HUWarning = (int)(strPackage[Index + 3]);
- int HULimit = (int)(strPackage[Index + 4]);
- break;
- }
- case 0x05:
- {
- int maxTubeKv = (int)(strPackage[Index + 3]);
- int max_SF_TubecurrentMA = (int)(strPackage[Index + 4] << 8 | strPackage[Index + 5]);
- int max_LF_TubecurrentMA = (int)(strPackage[Index + 6] << 8 | strPackage[Index + 7]);
- break;
- }
- case 0xA2:
- {
- int SF_LS_MaxPower = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int LF_LS_MaxPower = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int SF_HS_MaxPower = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_HS_MaxPower = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0xA3:
- {
- int SF_standbycurrent = (int)(strPackage[Index + 3] << 8 | strPackage[Index + 4]);
- int SF_maxcurrent = (int)(strPackage[Index + 5] << 8 | strPackage[Index + 6]);
- int LF_standbycurrent = (int)(strPackage[Index + 7] << 8 | strPackage[Index + 8]);
- int LF_maxcurrent = (int)(strPackage[Index + 9] << 8 | strPackage[Index + 10]);
- break;
- }
- case 0xA4:
- {
- int HUWarning = (int)(strPackage[Index + 3]);
- int HULimit = (int)(strPackage[Index + 4]);
- break;
- }
- case 0xA5:
- {
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x63:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- break;
- }
- case 0x02:
- {
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x64:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- /*
- 0x00 = INITIAL
- 0x01 = STANDBY
- 0x02 = READY
- 0x03 = OPERATE
- 0x04 = SHUTDOWN
- 0x05 = CALIBRATION
- 0x06 = SEASON
- */
- //6401
- int nGenStatus = (int)(strPackage[Index + 3]);
- if (0 == nGenStatus)
- {
- FINFO("[64 01 01]:GENERATOR_STATUS_INIT");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_INIT);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (1 == nGenStatus)
- {
- FINFO("[64 01 01]:GENERATOR_STATUS_STANDBY");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_STANDBY);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (2 == nGenStatus)
- {
- FINFO("[64 01 02]: GENERATOR_STATUS_STANDBY");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_STANDBY);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (3 == nGenStatus)
- {
- FINFO("[64 01 03]: GENERATOR_STATUS_EXP");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_EXP);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (4 == nGenStatus)
- {
- FINFO("[64 01 04]: GENERATOR_STATUS_SHUTDOWN");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_SHUTDOWN);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (5 == nGenStatus)
- {
- FINFO("[64 01 05]: GENERATOR_STATUS_CALIBRATION");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_CALIBRATION);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- else if (6 == nGenStatus)
- {
- FINFO("[64 01 06]: GENERATOR_STATUS_ERROR");
- m_DoseUnit.m_GenState->Update(AttrKey::GENERATOR_STATUS::GENERATOR_STATUS_ERROR);
- FireNotify(m_DoseUnit.m_GenState->GetKey(), m_DoseUnit.m_GenState->JSGet());
- }
- break;
- }
- case 0x02:
- {
- break;
- }
- case 0x03:
- {
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x65:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- {
- //6501
- //kv
- int postKv = (BYTE)(strPackage[Index + 3]) << 8 + (BYTE)strPackage[Index + 4];
- m_DoseUnit.m_PostKV->Update(postKv);
- FireNotify(m_DoseUnit.m_PostKV->GetKey(), m_DoseUnit.m_PostKV->JSGet());
- //ma
- int nPostMa = (BYTE)(strPackage[Index + 5]) << 8 + (BYTE)strPackage[Index + 6];
- float fpostMa = nPostMa / 10.0f;
- m_DoseUnit.m_PostMA->Update(fpostMa);
- FireNotify(m_DoseUnit.m_PostMA->GetKey(), m_DoseUnit.m_PostMA->JSGet());
- //ap-postmas
- int nPostMas = (BYTE)(strPackage[Index + 7]) << 16 + (BYTE)strPackage[Index + 8] << 8 + (BYTE)strPackage[Index + 9];
- float fpostMAS = nPostMas / 100.0f;
- m_DoseUnit.m_PostMAS->Update(fpostMAS);
- FireNotify(m_DoseUnit.m_PostMAS->GetKey(), m_DoseUnit.m_PostMAS->JSGet());
- //at-postms
- int nPostMs = (BYTE)(strPackage[Index + 10]) << 16 + (BYTE)strPackage[Index + 11] << 8 + (BYTE)strPackage[Index + 12];
- float fpostMS = nPostMs / 10.0f;
- m_DoseUnit.m_PostMS->Update(fpostMS);
- FireNotify(m_DoseUnit.m_PostMS->GetKey(), m_DoseUnit.m_PostMS->JSGet());
- FINFO("[65 01]: post{$}kv, post{$}ma, post{$}mas, post{$}Ms", postKv, fpostMa, fpostMAS, fpostMS);
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x6B:
- {
- }
- break;
- case 0x6C:
- {
- int soc = (BYTE)(strPackage[Index + 3]) << 8 + (BYTE)strPackage[Index + 4];
- int vol = (BYTE)(strPackage[Index + 5]) << 8 + (BYTE)strPackage[Index + 6];
- int charge = (BYTE)(strPackage[Index + 7]) << 8 + (BYTE)strPackage[Index + 8];
- int temperature = (BYTE)(strPackage[Index + 9]) << 8 + (BYTE)strPackage[Index + 10];
- int ac = (BYTE)strPackage[Index + 11];
- }
- break;
- case 0x6E:
- {
- switch (UINT8(strPackage[Index + 2]))
- {
- case 0x01:
- case 0xA1:
- {
- //6EA1
- break;
- }
- case 0x02:
- case 0xA2:
- {
- //6EA2
- //此命令比较特殊,切换为胶片模式,需要把下面俩值都设置为0.
- int nDetector1SynMode = (int)(strPackage[Index + 3]);
- int nDetector2SynMode = (int)(strPackage[Index + 4]);
- if (nDetector1SynMode == 0 && nDetector2SynMode == 0)//no detector.
- {
- // m_nWS = WSGen2UI(m_DoseUnit.m_WS->Get());
- //::PostMessage(this->m_hWnd, MSG_GEN_PARAM, GEN_PARAM_WS, m_nWS);//
- //logfile->WriteLog("6E A2:ws convertion mode", LOG_INFORMATION, LOG_DEBUG, true);
- }
- break;
- }
- default:
- break;
- }
- break;
- }
- default:
- break;
- }
- }
- bool nsGEN::DeltaDevice::DecodeFrame(const char* strPackage, int nLength)
- {
- if (strPackage == nullptr || nLength <= 0) {
- FINFO("strPackage: nullptr, nLength: <= 0");
- return false;
- }
- char strSendCommand[10] = { 0 };
- string str = "";
- int PacketLength = 0;
- for (int i = 0; i < nLength; i++)
- {
- sprintf_s(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)strPackage[i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("==IN== {$}", str);
- // 将新数据追加到缓冲区
- if (bufferLength + nLength > sizeof(buffer)) {
- FINFO("Buffer overflow!");
- bufferLength = 0;
- return false;
- }
- std::memcpy(buffer + bufferLength, strPackage, nLength);
- bufferLength += nLength;
- int index = 0;
- while (index < bufferLength) {
- str = ""; // 清空 str 字符串
- // 规则 1:F0 开头,88 结尾,长度为 13
- if (index + 12 < bufferLength && static_cast<uint8_t>(buffer[index]) == 0xF0 && static_cast<uint8_t>(buffer[index + 12]) == 0x88) {
- for (int i = 0; i < 13; ++i) {
- sprintf_s(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)buffer[index + i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("Rule 1: ==IN== {$}", str);
- ProcessCommand(strPackage, index, index + 13);
- index += 13;
- }
- // 规则 2:F0 开头,88 结尾,长度为 19
- else if (index + 18 < bufferLength && static_cast<uint8_t>(buffer[index]) == 0xF0 && static_cast<uint8_t>(buffer[index + 18]) == 0x88) {
- for (int i = 0; i < 19; ++i) {
- sprintf_s(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)buffer[index + i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("Rule 2: ==IN== {$}", str);
- ProcessCommand(strPackage, index, index + 19);
- index += 19;
- }
- // 规则 3:以 0D 结尾,指令包含 0D 和 0D 前三个字符
- else if (index >= 3 && static_cast<uint8_t>(buffer[index]) == 0x0D) {
- for (int i = 0; i < 4; ++i) {
- sprintf_s(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)buffer[index - 3 + i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("Rule 3: ==IN== {$}", str);
- ProcessCommand(strPackage, index - 3, index + 1);
- index++;
- }
- else {
- index++;
- }
- }
- // 移除已处理的数据
- int processedLength = index;
- std::memmove(buffer, buffer + processedLength, bufferLength - processedLength);
- bufferLength -= processedLength;
- return true;
- }
- bool nsGEN::DeltaDevice::ChangeGenParam(int kv, float fma, float fms, float fmas)
- {
- FINFO("KV: {$}, MA: {$}, MS: {$}, MAS: {$}", kv, fma, fms, fmas);
- if (m_DoseUnit.m_Techmode->Get() == 0)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else if (m_DoseUnit.m_Techmode->Get() == 1)
- {
- SetRADKV_MAS(kv, fmas);
- }
- else if (m_DoseUnit.m_Techmode->Get() == 2)
- {
- if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::TABLE)
- {
- if (m_nTableUsePanelAEC == 1)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else
- {
- SetAECKV_MA_MS(kv, fma, fms);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::WALL)
- {
- if (m_nWallUsePanelAEC == 1)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else
- {
- SetAECKV_MA_MS(kv, fma, fms);
- }
- }
- else if (m_DoseUnit.m_WS->Get() == AttrKey::GENWS_TYPE::MOBILE)
- {
- if (m_nFreeUsePanelAEC == 1)
- {
- SetRADKV_MA_MS(kv, fma, fms);
- }
- else
- {
- SetAECKV_MA_MS(kv, fma, fms);
- }
- }
- }
- return true;
- }
- //F0 6E A2 01 01 00 00 00 00 00 00 00 00 00 00 00 6C 00 88 发送消息
- bool nsGEN::DeltaDevice::SetRADKV_MA_MS(int kv, float ma, float ms)
- {
- FINFO("[0xF0, 0x56, 0xA1]: KV: {$}, MA: {$}, MS: {$}", kv, ma, ms);
- char cmdbuf[20] = { 0xF0, 0x56, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- cmdbuf[3] = kv;
- //确保ma合理
- int posMA = GetFacFloatValue(m_vecMA, ma);//找到之后,再缩小10倍,写入数据帧
- int nTemp = ma * 10;
- cmdbuf[4] = nTemp >> 8;
- cmdbuf[5] = nTemp % 256;
- //确保ms合理
- int posMS = GetFacFloatValue(m_vecMS, ms);
- nTemp = ms * 10;
- cmdbuf[6] = nTemp >> 16;
- cmdbuf[7] = nTemp >> 8;
- cmdbuf[8] = nTemp % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return true;
- }
- bool nsGEN::DeltaDevice::SetRADKV_MAS(int kv, float mas)
- {
- //57A1
- FINFO("[0xF0, 0x57, 0xA1]:KV: {$}, MAS: {$}", kv, mas);
- char cmdbuf[13] = { 0xF0, 0x57, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- cmdbuf[3] = kv;
- //确保mas合理
- int posMAS = GetFacFloatValue(m_vecMAS, mas);
- //设置mas指令中的数= 实际想要下发的数*100
- int nTemp = mas * 100;
- cmdbuf[6] = nTemp >> 16;
- cmdbuf[7] = nTemp >> 8;
- cmdbuf[8] = nTemp % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return true;
- }
- bool nsGEN::DeltaDevice::SetAECKV_MA_MS(int kv, float ma, float ms)
- {
- //55A2
- FINFO("[0xF0, 0x55, 0xA2]: KV: {$}, MA; {$}, MS: {$}", kv, ma, ms);
- char cmdbuf[13] = { 0xF0, 0x55, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x88 };
- cmdbuf[3] = kv;
- //确保ma合理
- int posMA = GetFacFloatValue(m_vecMA, ma);
- int nTemp = ma *10;
- cmdbuf[4] = nTemp >> 8;
- cmdbuf[5] = nTemp % 256;
- //确保ms合理
- int posMS = GetFacFloatValue(m_vecMS, ms);
- nTemp = ms * 10;
- cmdbuf[6] = nTemp >> 16;
- cmdbuf[7] = nTemp >> 8;
- cmdbuf[8] = nTemp % 256;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return true;
- }
- bool nsGEN::DeltaDevice::SetAECInformation(int chamber, int field, int density, int film)
- {
- FINFO("[0xF0, 0x55, 0xA1]: chamber: {$}, field: {$}, density: {$}, film: {$}", chamber, field, density, film);
- char cmdbuf[13] = { 0xF0, 0x55, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x88 };
- cmdbuf[3] = chamber;
- //field转换
- switch (field)
- {
- case 1:
- cmdbuf[4] = 0x04;
- break;
- case 10:
- cmdbuf[4] = 0x02;
- break;
- case 100:
- cmdbuf[4] = 0x01;
- break;
- case 101:
- cmdbuf[4] = 0x05;
- break;
- case 110:
- cmdbuf[4] = 0x03;
- break;
- case 11:
- cmdbuf[4] = 0x06;
- break;
- case 111:
- cmdbuf[4] = 0x07;
- break;
- default:
- break;
- }
- //density转换
- switch (density)
- {
- case -3:
- cmdbuf[5] = 0;
- break;
- case -2:
- cmdbuf[5] = 1;
- break;
- case -1:
- cmdbuf[5] = 2;
- break;
- case 0:
- cmdbuf[5] = 3;
- break;
- case 1:
- cmdbuf[5] = 4;
- break;
- case 2:
- cmdbuf[5] = 5;
- break;
- case 3:
- cmdbuf[5] = 6;
- break;
- default:
- cmdbuf[5] = 0;
- break;
- }
- if (film > 3)
- {
- film = 3;
- }
- cmdbuf[6] = 0;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return true;
- }
- //int nsGEN::DeltaDevice::GetFacValue(vector<int> Index, int& value)
- //{
- // int nlength = static_cast <int>(Index.size());
- // if (nlength == 0)
- // {
- // return -1;
- // }
- //
- // int nPos = 0;
- // int nValue = 0;
- // for (int i = 0; i < nlength; i++)
- // {
- // if (value == Index[i])
- // {
- // nPos = i;
- // break;
- // }
- // else if (i == nlength - 1)
- // {
- // nPos = i;
- // break;
- // }
- // else if ((value > Index[i]) && (value < Index[i + 1]))
- // {
- // nPos = (abs(value - Index[i + 1]) > abs(value - Index[i])) ? i : (i + 1);//就近原则
- // break;
- // }
- // else if (value < Index[0])
- // {
- // nPos = 0;
- // break;
- // }
- // }
- // value = Index[nPos];
- // return nPos;
- //}
- int CCOS::Dev::Detail::Generator::DeltaDevice::GetFacFloatValue(vector<float> Index, float& value)
- {
- int nlength = static_cast <int>(Index.size());
- if (nlength == 0)
- {
- return -1;
- }
- int nPos = 0;
- int nValue = 0;
- for (int i = 0; i < nlength; i++)
- {
- if (value == Index[i])
- {
- nPos = i;
- break;
- }
- else if (i == nlength - 1)
- {
- nPos = i;
- break;
- }
- else if ((value > Index[i]) && (value < Index[i + 1]))
- {
- nPos = (abs(value - Index[i + 1]) > abs(value - Index[i])) ? i : (i + 1);//就近原则
- break;
- }
- else if (value < Index[0])
- {
- nPos = 0;
- break;
- }
- }
- value = Index[nPos];
- return nPos;
- }
- bool nsGEN::DeltaDevice::SetRadMode(int radmode, int desmode)
- {
- FINFO("[0xF0, 0x54, 0xA1]: RadMode: {$}, desmode: {$}", radmode, desmode);
- char cmdbuf[13] = { 0xF0, 0x54, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A, 0x00, 0x88 };
- cmdbuf[3] = radmode;
- cmdbuf[4] = desmode;
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return true;
- }
- std::string nsGEN::DeltaDevice::uint8ArrayToHexStr(const UINT8* array, size_t length)
- {
- std::ostringstream ss;
- ss << std::hex << std::setfill('0'); // 设置十六进制格式和填充字符
- for (size_t i = 0; i < length; ++i) {
- ss << std::setw(2) << static_cast<int>(array[i]) << ' '; // 转换为int以支持十六进制输出,并设置宽度为2
- }
- return ss.str(); // 返回转换后的字符串
- }
- bool nsGEN::DeltaDevice::SetDAECEnable(int enable)
- {
- if (enable)
- {
- FINFO("[0xF0, 0x61, 0xAC, 0x01]: DAECEnable: {$}", enable);
- char cmdbuf[19] = { 0xF0, 0x61, 0xAC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xDB, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- else
- {
- FINFO("[0xF0, 0x61, 0xAC, 0x02]: DAECEnable: {$}", enable);
- char cmdbuf[19] = { 0xF0, 0x61, 0xAC, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- return true;
- }
- int nsGEN::DeltaDevice::WSGen2UI(int InputWS)
- {
- int OutputWS = -1;
- //if (m_nSettingWS == GEN_WS_TABLE) //table lying
- //{
- // if (InputWS == GenConfig.m_nGenWSLying)
- // {
- // OutputWS = GEN_WS_TABLE;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_WALL) //table standing
- //{
- // if (InputWS == GenConfig.m_nGenWSStand)
- // {
- // OutputWS = GEN_WS_WALL;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_CONVENTIONAL)
- //{
- // if (InputWS == GenConfig.m_nGenWSConventional)
- // {
- // OutputWS = GEN_WS_CONVENTIONAL;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_MOBILE) //Free ws
- //{
- // if (InputWS == GenConfig.m_nGenWSFree)
- // {
- // OutputWS = GEN_WS_MOBILE;
- // }
- //}
- //else if (m_nSettingWS == GEN_WS_TOMO)
- //{
- // if (InputWS == GenConfig.m_nGenWSTomo)
- // {
- // OutputWS = GEN_WS_TOMO;
- // }
- //}
- //else
- //{
- // this->logfile->WriteLog("Input WS is wrong", LOG_INFORMATION, LOG_DEBUG, true);
- //}
- //if (OutputWS < 0)
- //{
- // this->logfile->WriteLog("Seting WS is different with Geting WS!", LOG_INFORMATION, LOG_DEBUG, true);
- // if (InputWS == GenConfig.m_nGenWSLying)
- // {
- // OutputWS = GEN_WS_TABLE;
- // }
- // else if (InputWS == GenConfig.m_nGenWSStand)
- // {
- // OutputWS = GEN_WS_WALL;
- // }
- // else if (InputWS == GenConfig.m_nGenWSConventional)
- // {
- // OutputWS = GEN_WS_CONVENTIONAL;
- // }
- // else if (InputWS == GenConfig.m_nGenWSFree)
- // {
- // OutputWS = GEN_WS_MOBILE;
- // }
- // else if (InputWS == GenConfig.m_nGenWSTomo)
- // {
- // OutputWS = GEN_WS_TOMO;
- // }
- // else
- // {
- // //OutputWS = GEN_WS_TABLE;
- // OutputWS = -1;
- // this->logfile->WriteLog("Geting WS is wrong", LOG_INFORMATION, LOG_DEBUG, true);
- // }
- //}
- return OutputWS;
- }
- //-----------------------------------------------------------------------------
- // DecodeFrame
- //-----------------------------------------------------------------------------
- static bool DecodeFrame(const char* strFrame, int length)
- {
- if (nsGEN::DeltaDevice::g_GenDevice)
- {
- nsGEN::DeltaDevice::g_GenDevice->DecodeFrame(strFrame, length);
- }
- return true;
- }
- bool nsGEN::DeltaDevice::GetLastExpParamenters(void)
- {
- FINFO("[0xF0, 0x65, 0x01]");
- char cmdbuf[19] = { 0xF0, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCB, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- return true;
- }
- int nsGEN::DeltaDevice::FormatCommand(char* buf, int len)
- {
- if (len < 4)
- {
- return -1;
- }
- UINT8 crc = GetCRC8(buf + 1, len - 4);
- buf[len - 3] = crc;
- return crc;
- }
- void nsGEN::DeltaDevice::RetrieveFirewareVersion()
- {
- FINFO("[0xF0, 0x61, 0x01, 0x00]");
- char cmdbuf[19] = { 0xF0, 0x61, 0x01, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- std::string nsGEN::DeltaDevice::GetFileVersion(std::string strFilePathName)
- {
- DWORD dwVerSize = GetFileVersionInfoSize(strFilePathName.c_str(), NULL);
- if (dwVerSize == 0)
- {
- return false;
- }
- LPVOID pVersionBuffer = malloc(dwVerSize);
- GetFileVersionInfo(strFilePathName.c_str(), 0, dwVerSize, pVersionBuffer);
- VS_FIXEDFILEINFO* pInfo;
- UINT nInfoLen;
- std::string strVersion = "";
- if (VerQueryValue(pVersionBuffer, "\\", (void**)&pInfo, &nInfoLen))
- {
- strVersion = to_string(HIWORD(pInfo->dwFileVersionMS)) + "." + to_string(LOWORD(pInfo->dwFileVersionMS)) + "."
- + to_string(HIWORD(pInfo->dwFileVersionLS)) + "." + to_string(LOWORD(pInfo->dwFileVersionLS));
- }
- return strVersion;
- }
- //"HWS": "1",
- //"CMD" : "2",
- //"FRE" : "3"
- RET_STATUS nsGEN::DeltaDevice::ActiveSyncMode(_tSyncModeArgs value)
- {
- m_cfgCurrentWSSYN = value;
- FINFO("WS: {$}, SyncMode: {$}, SyncValue: {$}", m_cfgCurrentWSSYN.strWS, m_cfgCurrentWSSYN.strSyncMode, m_cfgCurrentWSSYN.strSyncValue);
- if (m_cfgCurrentWSSYN.strWS == "Free")
- {
- SetNoDrMode();
- }
- else
- {
- if (m_cfgCurrentWSSYN.strSyncMode == "FRE")
- {
- SetNoDrMode();
- }
- else
- {
- SetSyncOutMode();
- //if (m_cfgCurrentWSSYN.strWS == "Table")
- //{
- SeleckDetectorNumber(1);
- //}
- //else
- //{
- //SeleckDetectorNumber(2);
- //}
- }
- }
- return RET_STATUS::RET_SUCCEED;
- }
- void nsGEN::DeltaDevice::SetNoDrMode()
- {
- FINFO("[0xF0, 0x6E, 0xA2, 0x00]");
- char cmdbuf[20] = { 0xF0, 0x6E, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- void nsGEN::DeltaDevice::SetSyncOutMode()
- {
- FINFO("[0xF0, 0x6E, 0xA2, 0x01]");
- char cmdbuf[20] = { 0xF0, 0x6E, 0xA2, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- void nsGEN::DeltaDevice::SeleckDetectorNumber(int detectorID)
- {
- FINFO("[0xF0, 0x6E, 0xA1, 0x0{$}]", detectorID);
- char cmdbuf[20] = { 0xF0, 0x6E, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x00, 0x88 };
- cmdbuf[3] = detectorID;
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- /*下面的线程函数,其实用来充当定时器功能。*/
- bool nsGEN::DeltaDevice::StartHardwareStatusThread()
- {
- FDEBUG("Enter StartHardwareStatusThread");
- if (m_pHardwareStatusThread == NULL)
- {
- DWORD m_HardwareStatusID;
- m_pHardwareStatusThread = CreateThread(0, 0, HardwareStatusThread, this, 0, &m_HardwareStatusID);
- if (m_pHardwareStatusThread == NULL)
- {
- FERROR("Start HardwareStatus Thread Failed");
- return false;
- }
- }
- return true;
- }
- DWORD nsGEN::DeltaDevice::HardwareStatusThread(LPVOID pParam)
- {
- FDEBUG("Enter HardwareStatusThread");
- DeltaDevice* pCurGen = (DeltaDevice*)pParam;
- if (pCurGen == NULL)
- {
- return 0;
- }
- if (pCurGen->m_GenConfig.GetFirstOf("loopTime") >= 0)
- {
- if ((int)pCurGen->m_GenConfig["loopTime"] >= 100)
- {
- pCurGen->m_iLoopTime = (int)pCurGen->m_GenConfig["loopTime"];
- }
- }
- FINFO("loopTime = {$}", pCurGen->m_iLoopTime.load());
- int currtTime = pCurGen->m_iLoopTime;
- int waitTime = INFINITE;
- DWORD event = 0;
- bool bExit = false;
- int cmdNumber = 1;
- while (!bExit)
- {
- event = WaitForMultipleObjects(4, pCurGen->m_hArrayEvent, FALSE, waitTime);
- switch (event)
- {
- case WAIT_OBJECT_0:
- {
- FDEBUG("HardwareStatusThread: exited");
- bExit = TRUE;
- return 0;
- }break;
- case (WAIT_TIMEOUT):
- {
- FWARN("HardwareStatusThread: Get loop EVENT timeout");
- }break;
- case (WAIT_OBJECT_0 + 1):
- {
- if (pCurGen->m_nProcessXrayon == false)
- {
- currtTime = pCurGen->m_iLoopTime;
- Sleep(currtTime);
- pCurGen->RetrieveHU();
- pCurGen->CheckGeneratorStatus();
- FINFO("ConnectStatus: {$}", pCurGen->m_bReconnect);
- if (!pCurGen->m_bSetAPR)
- {
- pCurGen->m_tAPRdata.nWS = pCurGen->m_DoseUnit.m_WS->Get();
- pCurGen->m_tAPRdata.nTechmode = pCurGen->m_DoseUnit.m_Techmode->Get();
- pCurGen->m_tAPRdata.nFocus = pCurGen->m_DoseUnit.m_Focus->Get();
- pCurGen->m_tAPRdata.fKV = pCurGen->m_DoseUnit.m_KV->Get();
- pCurGen->m_tAPRdata.fMA = pCurGen->m_DoseUnit.m_MA->Get();
- pCurGen->m_tAPRdata.fMS = pCurGen->m_DoseUnit.m_MS->Get();
- pCurGen->m_tAPRdata.fMAS = pCurGen->m_DoseUnit.m_MAS->Get();
- pCurGen->m_tAPRdata.nAECDensity = pCurGen->m_DoseUnit.m_AECDensity->Get();
- pCurGen->m_tAPRdata.nAECFilm = pCurGen->m_DoseUnit.m_AECFilm->Get();
- pCurGen->m_tAPRdata.nAECField = pCurGen->m_DoseUnit.m_AECField->Get();
- pCurGen->SetAPR(pCurGen->m_tAPRdata);
- }
- m_nCountTimes++;
- if (m_nCountTimes >= 25)
- {
- char ErrCode[20];
- sprintf_s(ErrCode, "DELTA_ERR_%04d", 0);
- FINFO("{$}", ErrCode);
- int level = DELTA_ABNORMAL_LEVEL::REG_ERRO;
- auto iterr = pCurGen->m_ErrorMessages.find(ErrCode);
- if (iterr != pCurGen->m_ErrorMessages.end())
- {
- pCurGen->m_bReconnect = true;
- pCurGen->m_MSGUnit->AddErrorMessage(ErrCode, level, iterr->second.c_str());
- exit(0);
- }
- }
- }
- }break;
- default:
- {
- FDEBUG("HardwareStatusThread: unknown event");
- }break;
- }
- }
- return 0;
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveHU()
- {
- if (!m_nProcessXrayon)
- {
- FINFO("[0xF0, 0x5F, 0x01]");
- char cmdbuf[13] = { 0xF0, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x88 };
- FormatCommand(cmdbuf, 13);
- string temp(cmdbuf, 13);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- else
- {
- FINFO("Xrayon Processing Dont RetrieveHU");
- }
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::CheckGeneratorStatus()
- {
- if (!m_nProcessXrayon)
- {
- FINFO("[0xF0, 0x64, 0x01]");
- char cmdbuf[19] = { 0xF0, 0x64, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- else
- {
- FINFO("Xrayon Processing Dont CheckGeneratorStatus");
- }
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveMaxRating()
- {
- //6104
- FINFO("[0xF0, 0x61, 0x04]");
- char cmdbuf[19] = { 0xF0, 0x61, 0x04, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::UpdataAECInformation(AECINFORM aec)
- {
- switch (aec.Field)
- {
- case 1:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_100);
- break;
- case 2:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
- break;
- case 3:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_110);
- break;
- case 4:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_001);
- break;
- case 5:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_101);
- break;
- case 6:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
- break;
- case 7:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_111);
- break;
- default:
- m_DoseUnit.m_AECField->Update(AttrKey::AEC_010);
- break;
- }
- FireNotify(m_DoseUnit.m_AECField->GetKey(), m_DoseUnit.m_AECField->JSGet());
- FINFO("AEC: field: {$}", m_DoseUnit.m_AECField->GetKey());
- //density
- switch (aec.Density)
- {
- case 0:
- m_DoseUnit.m_AECDensity->Update(-3);
- break;
- case 1:
- m_DoseUnit.m_AECDensity->Update(-2);
- break;
- case 2:
- m_DoseUnit.m_AECDensity->Update(-1);
- break;
- case 3:
- m_DoseUnit.m_AECDensity->Update(0);
- break;
- case 4:
- m_DoseUnit.m_AECDensity->Update(1);
- break;
- case 5:
- m_DoseUnit.m_AECDensity->Update(2);
- break;
- case 6:
- m_DoseUnit.m_AECDensity->Update(3);
- break;
- default:
- m_DoseUnit.m_AECDensity->Update(0);
- break;
- }
- FireNotify(m_DoseUnit.m_AECDensity->GetKey(), m_DoseUnit.m_AECDensity->JSGet());
- FINFO("AEC: Density: {$}", m_DoseUnit.m_AECDensity->GetKey());
- //film --->ysj++ 是否需要转换??
- int nAECFilmSpeed = 0;
- switch (aec.FilmScreenSpeed)
- {
- case 0:
- nAECFilmSpeed = 100;
- break;
- case 1:
- nAECFilmSpeed = 200;
- break;
- case 2:
- nAECFilmSpeed = 400;
- break;
- case 3:
- nAECFilmSpeed = 800;
- break;
- default:
- break;
- }
- m_DoseUnit.m_AECFilm->Update(nAECFilmSpeed);
- FireNotify(m_DoseUnit.m_AECFilm->GetKey(), m_DoseUnit.m_AECFilm->JSGet());
- FINFO("AEC: Film: {$}", m_DoseUnit.m_AECFilm->GetKey());
- }
- void CCOS::Dev::Detail::Generator::DeltaDevice::RetrieveGeneratroDerating()
- {
- //6105
- FINFO("[0xF0, 0x61, 0x05]");
- char cmdbuf[19] = { 0xF0, 0x61, 0x05, 0x00, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x00, 0x00, 0x00, 0x88 };
- FormatCommand(cmdbuf, 19);
- string temp(cmdbuf, 19);
- m_strCommand = temp;
- HWSendWaitACKCMD(m_strCommand, 4);
- }
- bool CCOS::Dev::Detail::Generator::DeltaDevice::LoadConfig(string configfile)
- {
- std::ifstream file(configfile);
- if (!file) {
- FINFO("Config file does not exist: {$}", configfile.c_str());
- return false;
- }
- if (m_bLoadConfigFile)
- {
- FINFO("Configuration already loaded");
- return true;
- }
- m_strConfigPath = configfile;
- ResDataObject temp;
- temp.loadFile(m_strConfigPath.c_str());
- m_GenConfig = temp["CONFIGURATION"];
- TransJsonText(m_GenConfig);
- GetConfData();
- m_bLoadConfigFile = true;
- return true;
- }
- int CCOS::Dev::Detail::Generator::DeltaDevice::GetGenState()
- {
- if (m_DoseUnit.m_GenState != NULL)
- {
- return m_DoseUnit.m_GenState->Get();
- }
- else
- {
- return 0;
- }
- }
- string CCOS::Dev::Detail::Generator::DeltaDevice::AnalysisCommand(int number, const char* chdigital, int type)
- {
- string str = "";
- char arrChar[BYTE_4] = { 0 };
- for (int i = 0; i < number; i++)
- {
- if (type == TransToType::tochar)
- {
- //转成符号
- sprintf_s(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%c", (BYTE)chdigital[i]);
- }
- else if (type == TransToType::toint)
- {
- //转成int数
- sprintf_s(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%d", (BYTE)chdigital[i]);
- }
- else
- {
- //转成hex
- sprintf_s(arrChar, sizeof(arrChar) / sizeof(arrChar[0]), "%X", (BYTE)chdigital[i]);
- }
- str += arrChar;
- }
- return str;
- }
- //-----------------------------------------------------------------------------
- // DeltaDriver
- //-----------------------------------------------------------------------------
- nsGEN::DeltaDriver::DeltaDriver()
- {
- m_bDemoConnected = false;
- m_pAttribute.reset(new ResDataObject);
- m_pDescription.reset(new ResDataObject);
- }
- nsGEN::DeltaDriver::~DeltaDriver()
- {
- }
- auto nsGEN::DeltaDriver::CreateDevice(int index) -> std::unique_ptr <IODevice>
- {
- FINFO("CreateDevice:{$}", index);
- m_pDevice = new DeltaDevice(EventCenter, m_SCF, m_ConfigFileName);
- auto dev = std::unique_ptr <IODevice>(new IODevice(m_pDevice));
- return dev;
- }
- void nsGEN::DeltaDriver::FireNotify(int code, std::string key, std::string content)
- {
- EventCenter->OnNotify(code, key, content);
- }
- Log4CPP::Logger* gLogger = nullptr;
- void nsGEN::DeltaDriver::Prepare()
- {
- string strLogPath = GetProcessDirectory() + R"(\OEMDrivers\Generator\Conf\Log4CPP.Config.GEN.xml)";
- Log4CPP::GlobalContext::Map::Set(ECOM::Utility::Hash("LogFileName"), "GEN.Delta80KAXB");
- auto rc = Log4CPP::LogManager::LoadConfigFile(strLogPath.c_str());
- gLogger = Log4CPP::LogManager::GetLogger("GEN.Delta80KAXB");
- m_SCFDllName = GetConnectDLL(m_ConfigFileName);
- super::Prepare();
- }
- bool nsGEN::DeltaDriver::Connect()
- {
- FINFO("ConfigFileName: {$}", m_ConfigFileName.c_str());
- super::Disconnect();
- m_SCF.Disconnect();
- std::ifstream file(m_ConfigFileName);
- if (!file) {
- // 文件不存在,直接返回空的Connection对象
- FINFO("{$} does not exist", m_ConfigFileName);
- return false;
- }
- ResDataObject Connection = GetConnectParam(m_ConfigFileName);
- FINFO("Connections:{$} \n", Connection.encode());
- printf("Connections:%s \n", Connection.encode());
- auto erCode = m_SCF.Connect(Connection.encode(), &nsGEN::DeltaDriver::callbackPackageProcess, SCF_PACKET_TRANSFER, 3000);
- if (erCode != SCF_ERR::SCF_SUCCEED)
- {
- FINFO("SCF connection failed: erCode != SCF_ERR::SCF_SUCCEED");
- super::Disconnect();
- m_SCF.Disconnect();
- return false;
- }
- auto rc = super::Connect();
- if (!rc)
- {
- FINFO("super::Connect() failed");
- super::Disconnect();
- m_SCF.Disconnect();
- return false;
- }
- if (m_pDevice == nullptr)
- {
- return false;
- }
- FINFO("Connect Successful");
- return true;
- }
- void nsGEN::DeltaDriver::Disconnect()
- {
- FINFO("Enter Disconnect");
- super::Disconnect();
- m_SCF.Disconnect();
- m_bDemoConnected = false;
- }
- bool nsGEN::DeltaDriver::isConnected() const
- {
- if (!super::isConnected())
- {
- FINFO("No valid connection!!!");
- return false;
- }
- if (m_pDevice == nullptr)
- {
- FINFO("m_pDevice: nullptr");
- return false;
- }
- if (!m_pDevice->LoadConfig(m_ConfigFileName))
- {
- return false; //return 0;
- }
- int genState = m_pDevice->GetGenState();
- FINFO("m_pDevice->GetGenState(): {$}", genState);
- return genState > 0;
- }
- std::string nsGEN::DeltaDriver::DriverProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "Delta");
- HardwareInfo.add("ProductID", "DMG80KAXB");
- HardwareInfo.add("SerialID", "Drv");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- std::string nsGEN::DeltaDriver::GetResource()
- {
- ResDataObject r_config, temp;
- if (!temp.loadFile(m_ConfigFileName.c_str()))
- {
- return "";
- }
- m_ConfigAll = temp;
- r_config = temp["CONFIGURATION"];
- m_Configurations = r_config;
- ResDataObject DescriptionTemp;
- ResDataObject DescriptionSend;
- ResDataObject m_DescriptionSend;
- ResDataObject ListTemp;
- string strTemp = ""; //用于读取字符串配置信息
- string strIndex = ""; //用于读取配置信息中的List项
- int nTemp = -1; //用于读取整型配置信息
- char sstream[10] = { 0 }; //用于转换值
- string strValue = ""; //用于存储配置的值
- string strType = ""; //用于存储配置的类型 int/float/string...
- /***
- * 1. 通过循环,将所有配置项写到pDeviceConfig
- * 2. 记录配置项的内部key以及配置类型,类型对应了不同配置文件路径,用于读写真实值
- ***/
- try
- {
- //便利ConfigToolInfo 中 所有的AttributeInfo 属性段
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- m_pAttribute->clear();
- m_pDescription->clear();
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- DescriptionTemp.clear();
- DescriptionSend.clear();
- ListTemp.clear();
- //AttributeType
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Type"];
- DescriptionTemp.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- DescriptionSend.add(ConfKey::CcosType, strTemp.c_str());//CcosGeneratorAttribute
- strType = strTemp; //记录配置项的类型
- //AttributeKey
- //1. 根据AttributeType,内部key和配置路径,拿到当前的真实值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- nTemp = (int)m_Configurations["ConfigToolInfo"][nInfoIndex]["PathID"];
- GetDeviceConfigValue(r_config, strTemp.c_str(), nTemp, strValue); //得到strValue的值
- //2. 赋值
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if ("int" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else if ("float" == strType)
- {
- (*m_pAttribute).add(strTemp.c_str(), atoi(strValue.c_str()));
- }
- else //其它先按string类型处理
- {
- (*m_pAttribute).add(strTemp.c_str(), strValue.c_str());
- }
- //AttributeAccess
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Access"];
- DescriptionTemp.add(ConfKey::CcosAccess, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosAccess, strTemp.c_str());
- /*
- //AttributeRangeMin
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMin"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMin, strTemp.c_str());
- }
- //AttributeRangeMax
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["RangeMax"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosRangeMax, strTemp.c_str());
- }
- */
- //AttributeList
- nTemp = m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListNum"];
- if (nTemp > 0) //ListNum不大于0时说明不需要list配置
- {
- for (int nListIndex = 0; nListIndex < nTemp; nListIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["ListInfo"][nListIndex];
- auto temKey = std::to_string(nListIndex);
- ListTemp.add(temKey.c_str(), strTemp.c_str());
- }
- DescriptionTemp.add(ConfKey::CcosList, ListTemp);
- DescriptionSend.add(ConfKey::CcosList, ListTemp.encode());
- }
- //AttributeRequired
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["Required"];
- DescriptionTemp.add(ConfKey::CcosRequired, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosRequired, strTemp.c_str());
- //AttributeDefaultValue
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeDescripition"]["DefaultValue"];
- if (strTemp != "") //不需要的配置项为空
- {
- DescriptionTemp.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- DescriptionSend.add(ConfKey::CcosDefaultValue, strTemp.c_str());
- }
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- (*m_pDescription).add(strTemp.c_str(), DescriptionTemp);
- m_DescriptionSend.add(strTemp.c_str(), DescriptionSend.encode());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("Get config error: {$}", e.what());
- return "";
- }
- ResDataObject resDeviceResource;
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, (*m_pDescription));
- ResDataObject DescriptionTempEx;
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfig.clear();
- m_DeviceConfig = DescriptionTempEx;
- FINFO("local ************* get resource over {$}", DescriptionTempEx.encode());
- resDeviceResource.clear();
- resDeviceResource.add(ConfKey::CcosGeneratorAttribute, (*m_pAttribute));
- resDeviceResource.add(ConfKey::CcosGeneratorDescription, m_DescriptionSend);
- DescriptionTempEx.clear();
- DescriptionTempEx.add(ConfKey::CcosGeneratorConfig, resDeviceResource);
- m_DeviceConfigSend.clear();
- m_DeviceConfigSend = DescriptionTempEx;
- string res = m_DeviceConfigSend.encode();
- FINFO("get resource over {$}", DescriptionTempEx.encode());
- return res;
- }
- std::string nsGEN::DeltaDriver::DeviceProbe()
- {
- ResDataObject r_config, HardwareInfo;
- if (r_config.loadFile(m_ConfigFileName.c_str()))
- {
- HardwareInfo.add("MajorID", r_config["CONFIGURATION"]["MajorID"]);
- HardwareInfo.add("MinorID", r_config["CONFIGURATION"]["MinorID"]);
- HardwareInfo.add("VendorID", r_config["CONFIGURATION"]["VendorID"]);
- HardwareInfo.add("ProductID", r_config["CONFIGURATION"]["ProductID"]);
- HardwareInfo.add("SerialID", r_config["CONFIGURATION"]["SerialID"]);
- }
- else
- {
- HardwareInfo.add("MajorID", "Generator");
- HardwareInfo.add("MinorID", "Dr");
- HardwareInfo.add("VendorID", "Delta");
- HardwareInfo.add("ProductID", "DMG80KAXB");
- HardwareInfo.add("SerialID", "Dev");
- }
- string ret = HardwareInfo.encode();
- return ret;
- }
- void nsGEN::DeltaDriver::Dequeue(const char* Packet, DWORD Length)
- {
- DecodeFrame(Packet, Length);
- }
- PACKET_RET nsGEN::DeltaDriver::callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength)
- {
- //PacketLength = nLength + 1; //+1 because ETX
- //char strtemp[Delta_Com_NormalLen] = { 0 };
- //memcpy(strtemp, RecData, PacketLength); //只有ETX+数据,-2 排除 checkSum ETX。
- FINFO("==IN==: {$}, nLength: {$}", strtemp, nLength);
- //DeltaDevice::m_tDelivermodule.CheckReceive(strtemp, 2);
- //return PACKET_ISPACKET;
- char strSendCommand[10] = { 0 };
- string str = "";
- //int PacketLength = 0;
- for (int i = 0; i < nLength; i++)
- {
- sprintf_s(strSendCommand, sizeof(strSendCommand), "%02X", (BYTE)RecData[i]);
- str += strSendCommand;
- str += ",";
- }
- FINFO("==IN== {$}, nLength: {$}", str, nLength);
- bool bHasHead = false;
- for (DWORD i = 0; i < nLength; i++)
- {
- //寻找包头
- if ((UINT8)RecData[i] == COMMANDHEAD)
- {
- if ((i != 0) && (bHasHead == false)) //包头之前的数据格式不对,全部扔掉
- {
- PacketLength = i;
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength);
- FERROR("==IN unknown format data ==:{$},UselessDataLength={$},TotalLength={$} \n", strtemp, PacketLength, nLength);
- return PACKET_USELESS;
- }
- else
- {
- bHasHead = true;
- }
- }
- //寻找包尾
- if (((UINT8)RecData[i] == COMMANDEND) && ((nLength - 1) == i))
- {
- if (bHasHead)
- {
- PacketLength = i + 1; //+1 because ETX
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength); //只有ETX+数据,-2 排除 checkSum ETX。
- FINFO("==IN==:[{$}]", strtemp);
- DeltaDevice::m_tDelivermodule.CheckReceive(strtemp, 2);
- return PACKET_ISPACKET;
- }
- else //有包尾但无包头
- {
- PacketLength = i + 1;
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength);
- FERROR("==IN no head data ==:[{$:X}],NoHeadDataLength={$},TotalLength={$} \n", (UINT8)strtemp, PacketLength, nLength);
- return PACKET_USELESS;
- }
- }
- else if (((BYTE)RecData[i] == 0x0D) && (3 == i))
- {
- bHasHead = true;
- PacketLength = i + 1; //+1 because ETX
- char strtemp[Delta_Com_NormalLen] = { 0 };
- memcpy(strtemp, RecData, PacketLength); //只有ETX+数据,-2 排除 checkSum ETX。
- FINFO("==IN==:[{$}]", strtemp);
- DeltaDevice::m_tDelivermodule.CheckReceive(strtemp, 2);
- return PACKET_ISPACKET;
- }
- }
- if (bHasHead)
- {
- PacketLength = 0;
- }
- return PACKET_NOPACKET;
- }
- bool nsGEN::DeltaDriver::GetDeviceConfig(std::string& Cfg)
- {
- Cfg = m_DeviceConfigSend.encode();
- return true;
- }
- bool nsGEN::DeltaDriver::SetDeviceConfig(std::string Cfg)
- {
- FINFO("--Func-- SetDeviceConfig {$}", Cfg.c_str());
- ResDataObject DeviceConfig;
- DeviceConfig.decode(Cfg.c_str());
- ResDataObject DescriptionTempEx;
- DescriptionTempEx = DeviceConfig["DeviceConfig"]["Attribute"];
- FINFO("Attribute:{$}", DescriptionTempEx.encode());
- bool bSaveFile = false; //true:重新保存配置文件
- string strAccess = "";
- for (int i = 0; i < DescriptionTempEx.size(); i++)
- {
- string strKey = DescriptionTempEx.GetKey(i);
- FINFO("{$}", strKey.c_str());
- try
- {
- if (m_pAttribute->GetFirstOf(strKey.c_str()) >= 0)
- {
- strAccess = (string)(*m_pDescription)[strKey.c_str()]["Access"];
- if ("RW" == strAccess)
- {
- //修改对应配置,在其他单元的配置项要同时调用其修改函数修改真实值
- //1. 修改内存中的值,用于给上层发消息
- (*m_pAttribute)[strKey.c_str()] = DescriptionTempEx[i];
- //2. 拿到Innerkey
- int nConfigInfoCount = (int)m_Configurations["ConfigToolInfo"].GetKeyCount("AttributeInfo");
- FINFO("nConfigInfoCount {$}", nConfigInfoCount);
- string strTemp = ""; //存储AttributeKey
- for (int nInfoIndex = 0; nInfoIndex < nConfigInfoCount; nInfoIndex++)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["AttributeKey"];
- if (strTemp == strKey)
- {
- strTemp = (string)m_Configurations["ConfigToolInfo"][nInfoIndex]["InnerKey"];
- break;
- }
- }
- //3. 修改配置文件中的值
- if (SetDeviceConfigValue(m_Configurations, strTemp.c_str(), 1, DescriptionTempEx[i]))
- {
- FINFO("SetDeviceConfigValue over");
- bSaveFile = true;
- }
- }
- else
- {
- FINFO("{$} is not a RW configuration item", strKey.c_str());
- }
- }
- else
- {
- FINFO("without this attribute {$}", strKey.c_str());
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfig crashed: {$}", e.what());
- return false;
- }
- }
- if (bSaveFile)
- {
- //3. 重新保存配置文件
- SaveConfigFile(true);
- }
- return true;
- }
- bool nsGEN::DeltaDriver::SaveConfigFile(bool bSendNotify)
- {
- m_ConfigAll["CONFIGURATION"] = m_Configurations;
- bool bRt = m_ConfigAll.SaveFile(m_ConfigFileName.c_str());
- FINFO("SaveConfigFile over {$}", bRt);
- return true;
- }
- bool nsGEN::DeltaDriver::GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue)
- {
- strValue = "";
- string strTemp = pInnerKey;
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- int pos = 0;
- ResDataObject resTemp = config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- string TempValue = resTemp[Key.c_str()].encode();
- resTemp.clear();
- resTemp.decode(TempValue.c_str());
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- strValue = (string)resTemp[strTemp.c_str()];
- }
- else
- {
- strValue = (string)resTemp;
- }
- }
- return true;
- }
- bool nsGEN::DeltaDriver::SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue)
- {
- string strTemp = pInnerKey;
- FINFO("Begin to change {$} item value to {$}", pInnerKey, szValue);
- if (1 == nPathID) //从DriverConfig路径下每个DPC自己的配置文件读取
- {
- try {
- int pos = 0;
- ResDataObject* resTemp = &config;
- while ((pos = strTemp.find_first_of(',')) != string::npos)
- {
- string Key = strTemp.substr(0, pos);
- resTemp = &(*resTemp)[Key.c_str()];
- strTemp = strTemp.substr(pos + 1, strTemp.length() - pos - 1);
- }
- if (strTemp != "")
- {
- (*resTemp)[strTemp.c_str()] = szValue;
- }
- else
- {
- *resTemp = szValue;
- }
- }
- catch (ResDataObjectExption& e)
- {
- FERROR("SetDriverConfigvalue crashed: {$}", e.what());
- return false;
- }
- }
- return true;
- }
- //-----------------------------------------------------------------------------
- // GetIODriver & CreateIODriver
- //-----------------------------------------------------------------------------
- static nsGEN::DeltaDriver gIODriver;
- extern "C" CCOS::Dev::IODriver * __cdecl GetIODriver() // 返回静态对象的引用, 调用者不能删除 !
- {
- return &gIODriver;
- }
- extern "C" CCOS::Dev::IODriver * __cdecl CreateIODriver() // 返回新对象, 调用者必须自行删除此对象 !
- {
- return new nsGEN::DeltaDriver();
- }
|