#ifndef _ISS_ADSBF_PROCESS_H_ #define _ISS_ADSBF_PROCESS_H_ #include "ryFileDef.h" #include "process.h" #include #include "Log.h" #include "AdsLib.h" #include "AdsVariable.h" #include "RouterAccess.h" using namespace Beckhoff::Ads; #include "AdsDevice.h" namespace Beckhoff { namespace Ads { struct myAdsVariable { myAdsVariable(const AdsDevice& route, const std::string& symbolName) : m_Route(route), m_IndexGroup(ADSIGRP_SYM_VALBYHND), m_Handle(route.GetHandle(symbolName)) {} myAdsVariable(const AdsDevice& route, const uint32_t group, const uint32_t offset) : m_Route(route), m_IndexGroup(group), m_Handle(route.GetHandle(offset)) {} BOOLEAN Read(const size_t size, void* data) const { if (!m_Route.IsConnected()) return FALSE; uint32_t bytesRead = 0; if (m_Handle.get() == 0) return FALSE; auto error = m_Route.ReadReqEx2(m_IndexGroup, *m_Handle, size, data, &bytesRead); if (error || (size != bytesRead)) { vLog(LOG_ERROR, "AdsVariable read failed: %d, %s\n", error, strerror(errno)); return FALSE; } return TRUE; } private: const AdsDevice& m_Route; const uint32_t m_IndexGroup; const AdsHandle m_Handle; }; } } typedef std::unordered_map register2typemap; typedef struct { BOOLEAN inuse; WORD adsDataMemAddr; WORD adsDataMaxAddr; register2typemap adsDataBlocks; } struADSData; typedef std::vector adsReadDataVector; class CHostADSBFProcess : public CProcess { public: CHostADSBFProcess(); virtual ~CHostADSBFProcess(); virtual BOOLEAN OnPreCreate(int id); virtual BOOLEAN Run(void); virtual BOOLEAN OnTimer(void); private: struRYADSOption m_nOptions; //增加websocket连接 pthread_t m_cpid; std::string m_localIp; //本机IP地址 std::string m_localNetId; //本机IP地址 std::string m_remoteIp; //PLC设备ip地址 std::string m_remoteNetId; std::string m_adsUser; std::string m_adsPassword; AdsDevice *m_turbine; BOOLEAN m_bRouteAdded; //路由是否添加成功 DWORD m_connect_count; DWORD m_apdu_t0_begin; int m_total_length; DWORD last_sec; struADSData m_adsDatas[4]; public: std::string m_pidName; BOOLEAN m_bHaveFTP; //存在FTP协议 char m_cpidName[16]; //ftp参数信息 char m_user[64]; char m_password[64]; char m_remotePath[128]; char m_localPath[128]; WORD m_remotePort; //文件信息 int m_iv; LONG m_currentDirNo; //当前目录编号 LONG m_currentFileNo; //当前文件编号 LONG m_lastDirNo; //上一目录编号 LONG m_lastFileNo; //上一文件编号 LONG m_currentDirStartFileNo; //当前目录文件开始编号 LONG m_lastReadDirNo; //最后获取的目录编号 LONG m_lastReadFileNo; //最后获取的文件编号 LONG m_lastReadDirStartFileNo; //最后获取的目录文件开始编号 LONG m_curStartDirNo; //当前获取的目录编号 LONG m_curStartFileNo; //当前获取的文件编号 BOOLEAN m_bHaveUnReadFile; //存在未读的文件 BOOLEAN m_bFtpRun; const char* getRemoteIp(void) {return m_remoteIp.c_str(); } private: BOOLEAN calc(void); BOOLEAN readRealData(void); BOOLEAN readFileID(void); }; #endif //_ISS_ADSBF_PROCESS_H_