DIOS.Dev.Mech.HanQing3D.hpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #pragma once
  2. #include <string>
  3. #include <deque>
  4. #include "DIOS.Dev.IODevice.Detail.hpp"
  5. //#include "DiosDevThread.h"
  6. #include "DiosThread.h"
  7. #include "IODeviceWithSCF.tlh"
  8. #include "IODeviceWithSCF.tli"
  9. #include "DIOS.Dev.MSGMould.hpp"
  10. #include "DIOS.Dev.MECH.Mould.hpp"
  11. //#include "ATLComTime.h"
  12. #include "DeliverModule.h"
  13. #define Dios_V3 0
  14. #if Dios_V3
  15. #include "LogicClient.h"
  16. #endif // Dios_V3
  17. #ifdef DIOSDEVMECHOTCSTITCH_EXPORTS
  18. #define _DIOSDEVMECHOTCSTITCH_API __declspec(dllexport)
  19. #else
  20. #define _DIOSDEVMECHOTCSTITCH_API __declspec(dllimport)
  21. #endif
  22. namespace nsSerialGPM = DIOS::Dev::MODLE::SerialGPM;
  23. enum OTC_MG_REGULATION_LEVEL { //故障等级
  24. REG_ERRO,
  25. REG_WARN
  26. };
  27. typedef enum _HAND_SWITCH {
  28. HAND_OFF,
  29. HAND_DWON1,
  30. HAND_DWON2,
  31. HAND_MAX
  32. }HAND_SWITCH;
  33. struct Axis
  34. {
  35. enum AxisState {
  36. AXIS_STOP,
  37. AXIS_MOVE
  38. };
  39. Axis(string name = "", AxisState state = AXIS_STOP) : m_strAxisName(name), m_nAxisState(state){};
  40. string GetName() { return m_strAxisName; };
  41. AxisState GetState() { return m_nAxisState; };
  42. void SetState(AxisState state) { m_nAxisState = state; };
  43. void SetState(int state) { m_nAxisState = (AxisState)state; };
  44. int GetPosition() { return m_nPosition; };
  45. void SetPosition(int pos) { m_nPosition = pos; };
  46. private:
  47. string m_strAxisName;
  48. AxisState m_nAxisState{ AXIS_STOP };
  49. int m_nPosition{ 0 };
  50. };
  51. #define AxisCount 4
  52. namespace DIOS::Dev::Detail::MECH
  53. {
  54. using cbFun = std::function <void(char*, int)>;
  55. struct tFrameMapItem
  56. {
  57. cbFun m_fFun; //处理函数
  58. tFrameMapItem();
  59. tFrameMapItem(cbFun f);
  60. tFrameMapItem& operator =(const tFrameMapItem& value);
  61. };
  62. static const int TIMEOUTVALUE = 100;
  63. struct tTomoResult
  64. {
  65. float nAngle{ 0 };
  66. float nHeight{ 0 };
  67. tTomoResult() :nAngle(0), nHeight(0) {}
  68. tTomoResult(float angle, float height) :nAngle(angle), nHeight(height){}
  69. };
  70. //-----------------------------------------------------------------------------
  71. // HanQing3DDevice
  72. //-----------------------------------------------------------------------------
  73. class _DIOSDEVMECHOTCSTITCH_API HanQing3DDevice : public IODeviceWithSCF <IODeviceDetail>, public MECHMould
  74. {
  75. using super = IODeviceWithSCF <IODeviceDetail>;
  76. using superMech = MECHMould;
  77. public:
  78. HanQing3DDevice(std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF,string configfile="");
  79. ~HanQing3DDevice();
  80. //上层继承
  81. virtual std::string GetGUID() const override;
  82. RET_STATUS RefreshData();
  83. //串口处理层
  84. static nsSerialGPM::CDeliverModule m_tDelivermodule;
  85. int m_nCMDType_WaitTime{ 0 };
  86. int m_nCMDType_HB{ 0 };
  87. int m_nCMDType_WaitACK{ 0 };
  88. static void __stdcall ProcessClientData(const char* pData, unsigned long DataLength, void* lparam);
  89. static void __stdcall WriteLog(const char* pData, nsSerialGPM::LOG_V2_LEVEL level);
  90. RET_STATUS HWSendWaittimeCMD(char* strCommand, int lengh, int headLengh = 3);
  91. RET_STATUS HWSendHBCMD(char* strCommand, int lengh, int headLengh = 3);
  92. RET_STATUS HWSendWaitACKCMD(char* strCommand, int lengh, int headLengh = 3);
  93. //检查信息接口
  94. virtual RET_STATUS SetStudyInfo(ResDataObject& pParam) override;
  95. virtual RET_STATUS SetViewInfo(ResDataObject& pParam)override;
  96. virtual RET_STATUS SetPatientInfo(ResDataObject& pParam) override;
  97. //系统指令
  98. virtual RET_STATUS Reset()override; //重置错误
  99. virtual RET_STATUS SetTechParamsInfo(ResDataObject& pParam) override;
  100. virtual RET_STATUS SetPositionNumber(int pn) override;
  101. virtual RET_STATUS SetSID(float value) override;
  102. virtual RET_STATUS SetSOD(float value) override;
  103. virtual RET_STATUS MoveToHome(string& value) override;
  104. virtual RET_STATUS MoveMech(string& value) override;
  105. virtual RET_STATUS StopMech(string& value) override;
  106. virtual RET_STATUS SetGrid(AttrKey::MECH_GRIDSTATE GridState) override;
  107. virtual RET_STATUS SetAutoTracking(int nAutoTracking) override;
  108. //3D运动基本接口
  109. virtual RET_STATUS SetTomoEnable(bool enable) override;
  110. virtual RET_STATUS SetTomoExpMode(string& value) override;
  111. virtual RET_STATUS SetTomoTechnical(string& value) override;
  112. virtual RET_STATUS GetTomoResults(std::string& result) override;
  113. //拼接相应接口
  114. virtual RET_STATUS BeginStitching() override;
  115. virtual RET_STATUS InitStitching() override;
  116. virtual RET_STATUS EndStitching() override;
  117. virtual RET_STATUS SetupStitching(string& value) override;
  118. virtual RET_STATUS AcceptStitchingImage() override;
  119. virtual RET_STATUS RejectStitchingImage() override;
  120. virtual RET_STATUS CancelStitching() override;
  121. virtual RET_STATUS CompleteStitching() override;
  122. virtual RET_STATUS NewExtraView() override;
  123. virtual RET_STATUS RepeatStitching() override;
  124. virtual RET_STATUS SetAutoPosiitonNo(int nPN) override;
  125. //牛头
  126. virtual RET_STATUS SetExpEnable(bool nExpEnabled) override;
  127. virtual RET_STATUS SetWS(int nWS) override;
  128. virtual RET_STATUS SetKV(int nKV) override;
  129. virtual RET_STATUS SetMA(float fMA) override;
  130. virtual RET_STATUS SetMS(float fMS) override;
  131. virtual RET_STATUS SetMAS(float fMAS) override;
  132. virtual RET_STATUS SetFO(int nFO) override;
  133. virtual RET_STATUS SetTechMode(int nET) override;
  134. virtual RET_STATUS SetAECField(int nAECFieldSel) override;
  135. virtual RET_STATUS SetDensity(float nAECDensity) override;
  136. virtual RET_STATUS SetBodySize(string strSize) override;
  137. //悬吊特有
  138. RET_STATUS StopAllAxis();
  139. RET_STATUS MoveToRelativeDistance(int axisNum, int distance);
  140. RET_STATUS MoveToPositionNumber(int axisNum, int PosNum);
  141. RET_STATUS GetAllAxisPosition();
  142. RET_STATUS SetAxisPositionNumber(int axisNum, int xPos, int yPos, int zPos, int rPos);
  143. #if Dios_V3
  144. //V3新方法
  145. LogicClient* m_pSynClient; //订阅SYN调用端
  146. #endif
  147. bool SetFunToOtherUnit(const char* Signal, int SWstatus);
  148. static int m_iLoopTime; //循环间隔时间(毫秒)
  149. Axis MechStatus[AxisCount]{ {"X"}, {"Y"}, {"Z"}, {"R"} };//4个轴[位置,运动状态]
  150. HANDLE m_hExitEvent;//退出事件
  151. HANDLE m_hMoveBeginEvent;//开始移动事件
  152. private:
  153. //错误上报
  154. std::unique_ptr<nsDetail::MSGUnit> m_MSGUnit;
  155. HANDLE m_pHardwareStatusThread; //轮询线程句柄
  156. bool StartHardwareStatusThread(); //启动轮询线程
  157. static DWORD HardwareStatusThread(LPVOID pParam); //定时查询状态信息
  158. RET_STATUS HWSend(const char* strCommand, int lengh, bool reSend = false, int nTimeOut = TIMEOUTVALUE); //指令发送接口
  159. void OnCallBack(); //处理指令回调函数
  160. void Register(); //注册对外提供的属性、方法
  161. void FireNotify(std::string key, std::string context); //向上层上报消息
  162. void FireNotify(std::string key, const int context); //向上层上报消息
  163. void FireNotify(std::string key, const float context); //向上层上报消息
  164. void FireErrorMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报错误消息
  165. void FireWarnMessage(const bool Act, const int Code, const char* ResInfo = ""); //上报告警消息
  166. protected:
  167. ResDataObject m_MechConfig;
  168. map<int, tTomoResult> m_mTomoResult;//TOMO每张图的位置信息
  169. int m_nFPDLengh{ 43 };//探测器长度
  170. //拼接计划使用
  171. int m_nMinAngle{ -150 };//标装-170~170,球管旋转90度是水平正对立柱
  172. int m_nMaxAngle{ 150 };
  173. int m_nMinHeight{ 22 };//标装20~200,球管中心是最低22,最高198
  174. int m_nMaxHeight{ 198 };
  175. //发生器参数记录
  176. int m_nWS{ 0 };
  177. int m_nKV{ 0 };
  178. int m_fMA{ 0 };
  179. int m_fMS{ 0 };
  180. int m_fMAS{ 0 };
  181. int m_nFocus{ 0 };
  182. int m_nET{ 0 };
  183. int m_nAECField{ 0 };
  184. int m_nAECFilm{ 0 };
  185. int m_nAECDensity{ 0 };
  186. int m_nBodySize{ 0 };
  187. };
  188. }
  189. //-----------------------------------------------------------------------------
  190. // DEMODriver
  191. //-----------------------------------------------------------------------------
  192. namespace DIOS::Dev::Detail::MECH
  193. {
  194. class _DIOSDEVMECHOTCSTITCH_API HanQing3DDriver : public IODriverWithSCF <DriverMould>
  195. {
  196. using super = IODriverWithSCF <DriverMould>;
  197. ResDataObject m_GenConfig;
  198. public:
  199. HanQing3DDriver();
  200. virtual ~HanQing3DDriver();
  201. virtual void Prepare() override;
  202. virtual bool Connect() override;
  203. virtual void Disconnect() override;
  204. virtual bool isConnected() const override;
  205. virtual void Dequeue(const char* Packet, DWORD Length) override;
  206. virtual void FireNotify(int code, std::string key, std::string content) override;
  207. virtual auto CreateDevice(int index)->std::unique_ptr <IODevice> override;
  208. virtual std::string DriverProbe() override;
  209. virtual std::string GetResource() override;
  210. virtual std::string DeviceProbe() override;
  211. virtual bool GetDeviceConfig(std::string& Cfg) override;
  212. virtual bool SetDeviceConfig(std::string Cfg) override;
  213. HanQing3DDevice* m_pDriGenDev;// = nullptr;
  214. private:
  215. static PACKET_RET callbackPackageProcess(const char* RecData, DWORD nLength, DWORD& PacketLength);
  216. //for webconfig
  217. ResDataObject m_DeviceConfigSend;
  218. ResDataObject m_DeviceConfig;
  219. string g_strAppPath;
  220. ResDataObject m_ConfigAll; //存储当前的配置,用于修改配置时写回文件
  221. ResDataObject m_Configurations; //存储当前配置中“CONFIGURATION”节点的内容
  222. std::unique_ptr <ResDataObject> m_pAttribute;
  223. std::unique_ptr <ResDataObject> m_pDescription;
  224. bool SaveConfigFile(bool bSendNotify);
  225. bool GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue);
  226. bool SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue);
  227. };
  228. }