map/das-dn/hostadsbf/hostadsbf.h

142 lines
3.8 KiB
C
Raw Normal View History

2024-12-03 10:36:06 +08:00
#ifndef _ISS_ADSBF_PROCESS_H_
#define _ISS_ADSBF_PROCESS_H_
#include "ryFileDef.h"
#include "process.h"
2024-12-10 10:14:40 +08:00
#include <thread>
2024-12-03 10:36:06 +08:00
#include "Log.h"
#include "AdsLib.h"
#include "AdsVariable.h"
#include "RouterAccess.h"
2024-12-09 09:41:04 +08:00
using namespace Beckhoff::Ads;
2024-12-26 19:59:34 +08:00
#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;
2025-01-13 09:43:46 +08:00
if (*m_Handle.get() == 0) return FALSE;
2024-12-26 19:59:34 +08:00
auto error = m_Route.ReadReqEx2(m_IndexGroup,
*m_Handle,
size,
data,
&bytesRead);
if (error || (size != bytesRead)) {
2024-12-30 10:54:46 +08:00
vLog(LOG_ERROR, "AdsVariable read failed: %d, %s\n", error, strerror(errno));
2024-12-26 19:59:34 +08:00
return FALSE;
}
return TRUE;
}
private:
const AdsDevice& m_Route;
const uint32_t m_IndexGroup;
const AdsHandle m_Handle;
};
}
}
2024-12-03 10:36:06 +08:00
typedef std::unordered_map<short, short> register2typemap;
2024-12-04 08:48:18 +08:00
typedef struct
{
BOOLEAN inuse;
WORD adsDataMemAddr;
WORD adsDataMaxAddr;
register2typemap adsDataBlocks;
} struADSData;
typedef std::vector<struADSData> adsReadDataVector;
2024-12-10 10:14:40 +08:00
2024-12-03 10:36:06 +08:00
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;
2024-12-10 10:14:40 +08:00
2024-12-03 10:36:06 +08:00
//增加websocket连接
2024-12-11 16:30:53 +08:00
pthread_t m_cpid;
2024-12-03 10:36:06 +08:00
std::string m_localIp; //本机IP地址
std::string m_localNetId; //本机IP地址
std::string m_remoteIp; //PLC设备ip地址
std::string m_remoteNetId;
2024-12-24 12:14:20 +08:00
std::string m_adsUser;
std::string m_adsPassword;
2024-12-03 10:36:06 +08:00
AdsDevice *m_turbine;
2024-12-11 10:30:30 +08:00
BOOLEAN m_bRouteAdded; //路由是否添加成功
2024-12-26 10:08:40 +08:00
DWORD m_connect_count;
2024-12-11 20:25:29 +08:00
DWORD m_apdu_t0_begin;
2024-12-03 10:36:06 +08:00
int m_total_length;
DWORD last_sec;
2024-12-10 10:14:40 +08:00
struADSData m_adsDatas[4];
2024-12-03 10:36:06 +08:00
public:
2024-12-10 10:14:40 +08:00
std::string m_pidName;
2024-12-03 10:36:06 +08:00
BOOLEAN m_bHaveFTP; //存在FTP协议
2025-01-10 09:12:01 +08:00
char m_cpidName[16];
2024-12-03 10:36:06 +08:00
//ftp参数信息
char m_user[64];
char m_password[64];
char m_remotePath[128];
char m_localPath[128];
2024-12-04 16:02:58 +08:00
WORD m_remotePort;
2024-12-03 10:36:06 +08:00
//文件信息
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_