123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- #pragma once
- #include <thread>
- #include <mutex>
- #include <condition_variable>
- #include <atomic>
- #include <memory>
- #include <functional>
- #include <chrono>
- #include "CCOS.Dev.Generator.Mould.hpp"
- #include "DAP.BasicMoulds.hpp"
- #include "CCOS.Dev.MSGMould.hpp"
- #include "CCOS.Dev.IODevice.Detail.hpp"
- #include "SCFWrapper.h"
- #define _CCOSDEVGENREMEDYST_API __attribute__((visibility("default")))
- // Linux 兼容的数据类型定义
- using DWORD = unsigned long;
- using LPVOID = void*;
- using BOOL = int;
- using HANDLE = void*;
- #define TRUE 1
- #define FALSE 0
- // 睡眠函数(以毫秒为单位)
- inline void Sleep(unsigned int milliseconds) {
- std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
- }
- #define REMEDYST_LoopDefTime 1500
- #define REMEDYST_LoopExpTime 300
- namespace CCOS::Dev::Detail::Generator
- {
- static const int TIMEOUTVALUE = 100;
- //-----------------------------------------------------------------------------
- // REMEDYSTDevice
- //-----------------------------------------------------------------------------
- namespace nDev = CCOS::Dev;
- namespace DevDAP = CCOS::Dev::Detail::DAP;
- class _CCOSDEVGENREMEDYST_API REMEDYSTDevice : public IODeviceDetail,public GeneratorMould
- {
- using super = IODeviceDetail;
- using superGen = GeneratorMould;
-
- public:
- //REMEDYSTDevice (std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF);
- REMEDYSTDevice(std::shared_ptr <IOEventCenter> center, std::shared_ptr<SCFWrapper> SCF,string configfile);
- ~REMEDYSTDevice ();
- virtual std::string GetGUID() const override;
- public:
- static atomic<int> m_iLoopTime; //循环查询时间(毫秒)
- static atomic<bool> m_bExtraFlag; //使能标记
- float m_fPFLimitMaxMA;
- float m_fPFLimitMaxKV;
- float m_fPFLimitMinMA;
- float m_fPFLimitMinKV;
- float m_fHLFLimitMaxMA;
- float m_fHLFLimitMaxKV;
- float m_fHLFLimitMinMA;
- float m_fHLFLimitMinKV;
- bool m_bMasR20;
- bool m_bUseEAcmd;
- private:
- RET_STATUS HWSend (const char * strCommand, int length = 0, bool reSend = false, int nTimeOut = TIMEOUTVALUE);
- void OnCallBack ();
- std::shared_ptr<SCFWrapper> m_SCF;
- std::unique_ptr<DevDAP::DOSEMould> m_DAP;
- std::unique_ptr<nsDetail::MSGUnit> m_MSGUnit;
- bool StartHardwareStatusThread();
- static void HardwareStatusThread(REMEDYSTDevice* pParam);
- std::thread m_pHardwareStatusThread;
-
- private:
- void Register();
- public:
- virtual RET_STATUS IncKV() override;
- virtual RET_STATUS DecKV() override;
- virtual RET_STATUS SetKV(float value) override;
- virtual RET_STATUS IncMA() override;
- virtual RET_STATUS DecMA() override;
- virtual RET_STATUS SetMA(float value) override;
- virtual RET_STATUS IncMS() override;
- virtual RET_STATUS DecMS() override;
- virtual RET_STATUS SetMS(float value) override;
- virtual RET_STATUS IncMAS() override;
- virtual RET_STATUS DecMAS() override;
- virtual RET_STATUS SetMAS(float value) override;
- virtual RET_STATUS SetTechmode(int value) override;
- virtual RET_STATUS SetFocus(int value) override;
- virtual RET_STATUS SetAECDensity(int value) override;
- virtual RET_STATUS SetAECField(int value) override;
- virtual RET_STATUS SetAECFilm(int value) override;
- virtual RET_STATUS SetWS(const std::string value) override;
- virtual RET_STATUS SetAPR(const _tAPRArgs& t) override;
- virtual RET_STATUS QueryHE(int& value) override;
- virtual RET_STATUS QueryPostKV(float& value) override;
- virtual RET_STATUS QueryPostMA(float& value) override;
- virtual RET_STATUS QueryPostMS(float& value) override;
- virtual RET_STATUS QueryPostMAS(float& value) override;
- virtual RET_STATUS SetGenSynState(int value) override;
- virtual RET_STATUS SetGenState(int value) override;
- virtual RET_STATUS SetExpEnable() override;
- virtual RET_STATUS SetExpDisable()override;
- virtual RET_STATUS Reset()override;
- virtual RET_STATUS SetExpMode(std::string value) override;
- virtual RET_STATUS SetFrameRate(float frameRate) override;
- virtual RET_STATUS SetFLFMode(std::string value) override;
- virtual RET_STATUS SetEXAMMode(std::string value) override;
- void HandleError(const char* value, const char* prefix, const std::string& type);
- virtual RET_STATUS ActiveSyncMode(_tSyncModeArgs value) override;
- RET_STATUS Clear_DAP();
- RET_STATUS GetValue_DAP(float& value);
- RET_STATUS StartMove();
- RET_STATUS EndMove();
- /********************透视相关****************************/
- virtual RET_STATUS SetAPF(const _tAPFArgs& t) override;
- virtual RET_STATUS IncFluKV() override;
- virtual RET_STATUS DecFluKV() override;
- virtual RET_STATUS SetFluKV(float value) override;
- virtual RET_STATUS IncFluMA() override;
- virtual RET_STATUS DecFluMA() override;
- virtual RET_STATUS SetFluMA(float value) override;
- virtual RET_STATUS INCPPS() override;
- virtual RET_STATUS DECPPS() override;
- virtual RET_STATUS SetPPS(float value) override;
- virtual RET_STATUS SetABSMode(int nMode) override;
- virtual RET_STATUS SetABSCurve(int curveNum) override;
- virtual RET_STATUS IncABSCurve() override;
- virtual RET_STATUS DecABSCurve() override;
- virtual RET_STATUS GetABSCurve();
- virtual float GetFluIntTimer() override;
- virtual float GetFluAccTimer() override;
- virtual RET_STATUS ResetFluTimer(int ntype) override;
- virtual RET_STATUS SetFluPre(int value) override;
- virtual RET_STATUS SetFluEXP(int value) override;
- virtual RET_STATUS SetFluMode(std::string value) ;
- virtual RET_STATUS SetFluDoseLever(int value) override;
- void UpdateLimits(const std::string& key, float& currentValue, float defaultValue);
- void UpdateLimitsInt(const std::string& key, int& currentValue, int defaultValue);
- int GetGenState();
- int LoadConfig(string configfile);
- protected:
- RET_STATUS RefreshData ();
- RET_STATUS SetRPS(int rps);//连续曝光片帧率
- private:
- void FireNotify (std::string key, std::string context);
- HANDLE m_hGenPostEvent; //暂时不使用了.
- _tAPRArgs m_t; //放射曝光的参数
- string m_strConfigPath; //REMEDYST generator confile.
- ResDataObject m_GenConfig; //driver's config file.
- bool m_bDAPEnable;
- bool m_bAKEnable;
- bool m_bResetActive;
- bool m_bIsConfigLoaded;
- vector<string> m_localErrorlist; //保存error list,用于触发error时判断是否已经string了
- vector<string> m_localWarnlist; //保存warn list,用于触发warn 时判断是否已经string了
- string WSUI2Gen(int nUIWS); //根据nWS得到string WS.
- };
- }
- //-----------------------------------------------------------------------------
- // REMEDYSTDriver
- //-----------------------------------------------------------------------------
- namespace CCOS::Dev::Detail::Generator
- {
- class _CCOSDEVGENREMEDYST_API REMEDYSTDriver : public DriverMould
- {
- using super = DriverMould;
- public:
- REMEDYSTDriver ();
- virtual ~REMEDYSTDriver ();
- public:
- virtual void Prepare () override;
- virtual bool DATA_ACTION Connect () override;
- virtual void Disconnect() override;
- virtual bool isConnected() const override;
- virtual void Dequeue (const char * Packet, DWORD Length) ;
- virtual void FireNotify (int code, std::string key, std::string content) ;
- virtual auto CreateDevice (int index)->std::unique_ptr <IODevice> override;
- virtual std::string DriverProbe () override;
- virtual std::string GetResource () override;
- virtual std::string DeviceProbe () override;
- bool SaveConfigFile(bool bSendNotify);
- virtual bool GetDeviceConfig(std::string& Cfg) override;
- virtual bool SetDeviceConfig(std::string Cfg) override;
- bool GetDeviceConfigValue(ResDataObject config, const char* pInnerKey, int nPathID, string& strValue);
- bool SetDeviceConfigValue(ResDataObject& config, const char* pInnerKey, int nPathID, const char* szValue);
- std::shared_ptr<SCFWrapper> m_scfWrapper;
- private:
- static PACKET_RET callbackPackageProcess (const char* RecData, uint32_t nLength, uint32_t& PacketLength);
- bool m_bDemoMode;
- bool m_bDemoConnected; // 在 DEMO 模式下, 调用过 Connect 吗?
- ResDataObject m_DeviceConfig;
- ResDataObject m_DeviceConfigSend;
- string g_strAppPath;
- ResDataObject m_ConfigAll; //存储当前配置项,如果修改配置时写入文件
- ResDataObject m_Configurations; //存储当前配置项中CONFIGURATION节点内容
- enum class ConnectionState {
- Disconnected,
- Connecting,
- Connected,
- Failed
- };
- enum class ConnectionType {
- Serial, // 串口
- Ethernet // 网口
- };
- std::atomic<ConnectionState> m_connectionState{ ConnectionState::Disconnected };
- std::chrono::steady_clock::time_point m_lastConnectionAttempt;
- std::mutex m_connectionMutex;
- const std::chrono::seconds RESET_RETRY_AFTER{ 60 };
- // 修改成员变量定义,添加mutable允许const函数修改
- mutable int m_connectionRetryCount{ 0 }; // 关键:用mutable修饰
- const int MAX_RETRY_COUNT = 3;
- const std::chrono::seconds RETRY_INTERVAL{ 5 };
- // 串口相关(固定支持的端口,可从配置扩展)
- std::vector<std::string> m_serialPorts{ "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4" };
- int m_currentSerialPortIndex{ 0 }; // 当前尝试的串口端口索引
- ConnectionType m_currentConnType{ ConnectionType::Serial };
- //webconfig使用
- std::string m_SCFDllName;
- std::unique_ptr <ResDataObject> m_pAttribute;
- std::unique_ptr <ResDataObject> m_pDescription;
- REMEDYSTDevice* m_pDevice{ nullptr };
- };
- }
|