Merge branch 'main' of https://git.jsspisoft.com/ry-das
This commit is contained in:
commit
1352dcac99
@ -450,10 +450,11 @@ BOOLEAN CRYDevice::GetUnitYCIsForceArchive(int uid, int order) const
|
|||||||
int udb;
|
int udb;
|
||||||
struUnit* pUnit;
|
struUnit* pUnit;
|
||||||
struUnitYC* pYC;
|
struUnitYC* pYC;
|
||||||
if (uid < 0 || uid >= UNIT_NUM) return 0;
|
if (uid < 0 || uid >= UNIT_NUM) return FALSE;
|
||||||
pUnit = &config.units[uid];
|
pUnit = &config.units[uid];
|
||||||
if ((pUnit->state & 0x01) != TRUE) return 0;
|
if ((pUnit->state & 0x01) != TRUE) return FALSE;
|
||||||
if (order < 0 || order >= pUnit->yccount) return 0;
|
if ((pUnit->state & 0x20) == 0x20) return TRUE;
|
||||||
|
if (order < 0 || order >= pUnit->yccount) return FALSE;
|
||||||
pYC = &pUnit->ycs[order];
|
pYC = &pUnit->ycs[order];
|
||||||
udb = pYC->order;
|
udb = pYC->order;
|
||||||
if (udb < 0 || udb >= DATABASE_YC_NUM)
|
if (udb < 0 || udb >= DATABASE_YC_NUM)
|
||||||
@ -468,10 +469,11 @@ BOOLEAN CRYDevice::GetUnitYXIsForceArchive(int uid, int order) const
|
|||||||
int udb;
|
int udb;
|
||||||
struUnit* pUnit;
|
struUnit* pUnit;
|
||||||
struUnitYX* pYX;
|
struUnitYX* pYX;
|
||||||
if (uid < 0 || uid >= UNIT_NUM) return 0;
|
if (uid < 0 || uid >= UNIT_NUM) return FALSE;
|
||||||
pUnit = &config.units[uid];
|
pUnit = &config.units[uid];
|
||||||
if ((pUnit->state & 0x01) != TRUE) return 0;
|
if ((pUnit->state & 0x01) != TRUE) return FALSE;
|
||||||
if (order < 0 || order >= pUnit->yxcount) return 0;
|
if ((pUnit->state & 0x20) == 0x20) return TRUE;
|
||||||
|
if (order < 0 || order >= pUnit->yxcount) return FALSE;
|
||||||
pYX = &pUnit->yxs[order];
|
pYX = &pUnit->yxs[order];
|
||||||
udb = pYX->order;
|
udb = pYX->order;
|
||||||
if (udb < 0 || udb >= DATABASE_YX_NUM)
|
if (udb < 0 || udb >= DATABASE_YX_NUM)
|
||||||
|
@ -382,7 +382,7 @@ static void* ryftp_process(void* param)
|
|||||||
char* escaped_string = escape_char_in_string(mbt->m_remotePath, ' ');
|
char* escaped_string = escape_char_in_string(mbt->m_remotePath, ' ');
|
||||||
if (escaped_string == NULL)
|
if (escaped_string == NULL)
|
||||||
{
|
{
|
||||||
vLog(LOG_DEBUG, "路径转义错误!\n");
|
vLog(LOG_DEBUG, "%s 路径转义错误!\n", processName);
|
||||||
return ((void*)0);
|
return ((void*)0);
|
||||||
}
|
}
|
||||||
snprintf(remotePath, sizeof(remotePath), "%s", escaped_string);
|
snprintf(remotePath, sizeof(remotePath), "%s", escaped_string);
|
||||||
@ -488,7 +488,7 @@ static void* ryftp_process(void* param)
|
|||||||
vLog(LOG_DEBUG, "%s get %s to local memory, with name: %s, and password: %s okay, and file length is: %d.\n", processName, remote, user, password, chunk.size);
|
vLog(LOG_DEBUG, "%s get %s to local memory, with name: %s, and password: %s okay, and file length is: %d.\n", processName, remote, user, password, chunk.size);
|
||||||
ftpget_retry_count = 0;
|
ftpget_retry_count = 0;
|
||||||
if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) {
|
if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) {
|
||||||
vLog(LOG_DEBUG, "PLC文件生成未完成!\n");
|
vLog(LOG_DEBUG, "%s PLC文件生成未完成!\n", processName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -784,6 +784,7 @@ BOOLEAN CHostADSBFProcess::calc(void)
|
|||||||
void CHostADSBFProcess::tryStartup()
|
void CHostADSBFProcess::tryStartup()
|
||||||
{
|
{
|
||||||
m_turbine = NULL;
|
m_turbine = NULL;
|
||||||
|
pthread_setname_np(pthread_self(), m_pidName.c_str());
|
||||||
while (m_threadRun) {
|
while (m_threadRun) {
|
||||||
if (m_turbine == NULL) {
|
if (m_turbine == NULL) {
|
||||||
SetLocalAmsNetId(AmsNetId(m_localNetId));
|
SetLocalAmsNetId(AmsNetId(m_localNetId));
|
||||||
@ -836,11 +837,14 @@ BOOLEAN CHostADSBFProcess::OnPreCreate(int id)
|
|||||||
m_bHaveFTP = m_nOptions.bHaveFTP;
|
m_bHaveFTP = m_nOptions.bHaveFTP;
|
||||||
calc();
|
calc();
|
||||||
|
|
||||||
vLog(LOG_DEBUG, "%s local ip is: %s, netid is: %s, remote ip is: %s, and netid is: %s\n", m_pidName.c_str(), m_localIp.c_str(), m_localNetId.c_str(), m_remoteIp.c_str(), m_remoteNetId.c_str());
|
//vLog(LOG_DEBUG, "%s local ip is: %s, netid is: %s, remote ip is: %s, and netid is: %s\n", m_pidName.c_str(), m_localIp.c_str(), m_localNetId.c_str(), m_remoteIp.c_str(), m_remoteNetId.c_str());
|
||||||
|
|
||||||
m_turbine = NULL;
|
m_turbine = NULL;
|
||||||
|
SetLocalAmsNetId(AmsNetId(m_localNetId));
|
||||||
|
#if 0
|
||||||
m_threadRun = TRUE;
|
m_threadRun = TRUE;
|
||||||
m_startup = std::thread(&CHostADSBFProcess::tryStartup, this);
|
m_startup = std::thread(&CHostADSBFProcess::tryStartup, this);
|
||||||
|
#endif
|
||||||
if (m_bHaveFTP)
|
if (m_bHaveFTP)
|
||||||
{
|
{
|
||||||
snprintf(m_user, sizeof(m_user), "%s", m_nOptions.ftp.user);
|
snprintf(m_user, sizeof(m_user), "%s", m_nOptions.ftp.user);
|
||||||
@ -877,7 +881,7 @@ BOOLEAN CHostADSBFProcess::OnPreCreate(int id)
|
|||||||
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
||||||
|
|
||||||
if (pthread_create(&m_pid, &attr, ryftp_process, this) < 0) {
|
if (pthread_create(&m_pid, &attr, ryftp_process, this) < 0) {
|
||||||
vLog(LOG_ERROR, "create ryftp_process error(%d,%s).\n", errno, strerror(errno));
|
vLog(LOG_ERROR, "ads create ryftp_process error(%d,%s).\n", errno, strerror(errno));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
char name[17];
|
char name[17];
|
||||||
@ -910,9 +914,22 @@ BOOLEAN CHostADSBFProcess::OnTimer(void)
|
|||||||
}
|
}
|
||||||
if (sec_changed)
|
if (sec_changed)
|
||||||
{
|
{
|
||||||
if (m_turbine == NULL) return TRUE;
|
if (m_turbine == NULL) {
|
||||||
|
m_turbine = new AdsDevice{m_remoteIp, AmsNetId(m_remoteNetId), m_remotePort};
|
||||||
|
const auto state = m_turbine->GetState();
|
||||||
|
//vLog(LOG_DEBUG, "%s ADS state: %d devState: %d\n", m_pidName.c_str(), (uint16_t)state.ads, (uint16_t)state.device);
|
||||||
|
if ((uint16_t)state.ads >= ADSSTATE::ADSSTATE_MAXSTATES || (uint16_t)state.device >= ADSSTATE::ADSSTATE_MAXSTATES)
|
||||||
|
{
|
||||||
|
vLog(LOG_DEBUG, "read device state error.\n");
|
||||||
|
long ret = AddRemoteRoute(m_remoteIp, m_localNetId, m_localIp, std::string("isoftstone"), std::string("admin"), std::string("admin"));
|
||||||
|
vLog(LOG_DEBUG, "bbb %s add route return value is: %d\n", m_pidName.c_str(), ret);
|
||||||
|
delete m_turbine;
|
||||||
|
m_turbine = NULL;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
if (!m_turbine->IsConnected()) return TRUE;
|
if (!m_turbine->IsConnected()) return TRUE;
|
||||||
try {
|
//try {
|
||||||
if (m_bHaveFTP)
|
if (m_bHaveFTP)
|
||||||
{ //启动时读取一次,后面自己维护序号
|
{ //启动时读取一次,后面自己维护序号
|
||||||
if ((m_currentDirNo == -1) && (m_currentFileNo == -1))
|
if ((m_currentDirNo == -1) && (m_currentFileNo == -1))
|
||||||
@ -921,11 +938,11 @@ BOOLEAN CHostADSBFProcess::OnTimer(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
readRealData();
|
readRealData();
|
||||||
} catch (const AdsException& ex) {
|
// } catch (const AdsException& ex) {
|
||||||
vLog(LOG_ERROR, "%s AdsException message: %s, remote is: %s:%d\n", m_pidName.c_str(), ex.what(), m_remoteIp.c_str(), m_remotePort);
|
// vLog(LOG_ERROR, "%s AdsException message: %s, remote is: %s:%d\n", m_pidName.c_str(), ex.what(), m_remoteIp.c_str(), m_remotePort);
|
||||||
} catch (const std::runtime_error& ex) {
|
// } catch (const std::runtime_error& ex) {
|
||||||
vLog(LOG_ERROR, "%s %s\n", m_pidName.c_str(), ex.what());
|
// vLog(LOG_ERROR, "%s %s\n", m_pidName.c_str(), ex.what());
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -981,7 +998,7 @@ BOOLEAN CHostADSBFProcess::readFileID()
|
|||||||
//判断是否有要读取的文件
|
//判断是否有要读取的文件
|
||||||
if (m_curStartDirNo <= m_lastReadDirNo && m_curStartFileNo <= m_lastReadFileNo)
|
if (m_curStartDirNo <= m_lastReadDirNo && m_curStartFileNo <= m_lastReadFileNo)
|
||||||
{
|
{
|
||||||
vLog(LOG_DEBUG, "不存在未读的文件。\n");
|
vLog(LOG_DEBUG, "%s 不存在未读的文件。\n", m_pidName.c_str());
|
||||||
m_bHaveUnReadFile = FALSE;
|
m_bHaveUnReadFile = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -416,12 +416,12 @@ static void* ryftp_process(void* param)
|
|||||||
//char pathName[128] = "./";
|
//char pathName[128] = "./";
|
||||||
|
|
||||||
char processName[128];
|
char processName[128];
|
||||||
snprintf(processName, sizeof(processName), "%s", mbt->GetCurProcessName());
|
snprintf(processName, sizeof(processName), "%s", mbt->m_pidName.c_str());
|
||||||
//配置远方路径
|
//配置远方路径
|
||||||
char* escaped_string = escape_char_in_string(mbt->m_remotePath, ' ');
|
char* escaped_string = escape_char_in_string(mbt->m_remotePath, ' ');
|
||||||
if (escaped_string == NULL)
|
if (escaped_string == NULL)
|
||||||
{
|
{
|
||||||
vLog(LOG_DEBUG, "路径转义错误!\n");
|
vLog(LOG_DEBUG, "%s 路径转义错误!\n", processName);
|
||||||
return ((void*)0);
|
return ((void*)0);
|
||||||
}
|
}
|
||||||
snprintf(remotePath, sizeof(remotePath), "%s", escaped_string);
|
snprintf(remotePath, sizeof(remotePath), "%s", escaped_string);
|
||||||
@ -527,7 +527,7 @@ static void* ryftp_process(void* param)
|
|||||||
vLog(LOG_DEBUG, "%s get %s to local memory, with name: %s, and password: %s okay, and file length is: %d.\n", processName, remote, user, password, chunk.size);
|
vLog(LOG_DEBUG, "%s get %s to local memory, with name: %s, and password: %s okay, and file length is: %d.\n", processName, remote, user, password, chunk.size);
|
||||||
ftpget_retry_count = 0;
|
ftpget_retry_count = 0;
|
||||||
if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) {
|
if (chunk.size <= (int)(sizeof(struRYDeviceData) << 5)) {
|
||||||
vLog(LOG_DEBUG, "PLC文件生成未完成!\n");
|
vLog(LOG_DEBUG, "%s PLC文件生成未完成!\n", processName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1115,6 +1115,8 @@ BOOLEAN CHostModbusTcpBFProcess::OnPreCreate(int id)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_pidName = std::string(GetCurProcessName());
|
||||||
|
|
||||||
m_bHaveFTP = m_nOptions.bHaveFTP;
|
m_bHaveFTP = m_nOptions.bHaveFTP;
|
||||||
m_nTimeout = 200;
|
m_nTimeout = 200;
|
||||||
calc2();
|
calc2();
|
||||||
@ -1146,7 +1148,7 @@ BOOLEAN CHostModbusTcpBFProcess::OnPreCreate(int id)
|
|||||||
//启动后,创建ftp线程
|
//启动后,创建ftp线程
|
||||||
if (m_pid <= 0) {
|
if (m_pid <= 0) {
|
||||||
m_bFtpRun = TRUE;
|
m_bFtpRun = TRUE;
|
||||||
vLog(LOG_DEBUG, "create a ftp thread.\n");
|
vLog(LOG_DEBUG, "rymodbus create a ftp thread.\n");
|
||||||
|
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
@ -1154,11 +1156,11 @@ BOOLEAN CHostModbusTcpBFProcess::OnPreCreate(int id)
|
|||||||
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
||||||
|
|
||||||
if (pthread_create(&m_pid, &attr, ryftp_process, this) < 0) {
|
if (pthread_create(&m_pid, &attr, ryftp_process, this) < 0) {
|
||||||
vLog(LOG_ERROR, "create ryftp_process error(%d,%s).\n", errno, strerror(errno));
|
vLog(LOG_ERROR, "rymodbus create ryftp_process error(%d,%s).\n", errno, strerror(errno));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
char name[17];
|
char name[17];
|
||||||
snprintf(name, 16, "%s_ftp", GetCurProcessName());
|
snprintf(name, 16, "%s_ftp", m_pidName.c_str());
|
||||||
pthread_setname_np(m_pid, name);
|
pthread_setname_np(m_pid, name);
|
||||||
|
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
@ -1754,7 +1756,7 @@ BOOLEAN CHostModbusTcpBFProcess::OnReceiveIDData(CHostModbusTcpBFProcessItem *pI
|
|||||||
|
|
||||||
m_iv = iv;
|
m_iv = iv;
|
||||||
if (iv) {
|
if (iv) {
|
||||||
vLog(LOG_DEBUG, "路径信息无效\n");
|
vLog(LOG_DEBUG, "%s 路径信息无效\n", m_pidName.c_str());
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
//当前文件夹路径名
|
//当前文件夹路径名
|
||||||
@ -1770,7 +1772,7 @@ BOOLEAN CHostModbusTcpBFProcess::OnReceiveIDData(CHostModbusTcpBFProcessItem *pI
|
|||||||
//判断是否有要读取的文件
|
//判断是否有要读取的文件
|
||||||
if (m_curStartDirNo <= m_lastReadDirNo && m_curStartFileNo <= m_lastReadFileNo)
|
if (m_curStartDirNo <= m_lastReadDirNo && m_curStartFileNo <= m_lastReadFileNo)
|
||||||
{
|
{
|
||||||
vLog(LOG_DEBUG, "不存在未读的文件。\n");
|
vLog(LOG_DEBUG, "%s 不存在未读的文件。\n", m_pidName.c_str());
|
||||||
m_bHaveUnReadFile = FALSE;
|
m_bHaveUnReadFile = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1778,10 +1780,10 @@ BOOLEAN CHostModbusTcpBFProcess::OnReceiveIDData(CHostModbusTcpBFProcessItem *pI
|
|||||||
m_bHaveUnReadFile = TRUE;
|
m_bHaveUnReadFile = TRUE;
|
||||||
int dir_count = m_curStartDirNo - m_lastReadDirNo + 1;
|
int dir_count = m_curStartDirNo - m_lastReadDirNo + 1;
|
||||||
int file_count = m_curStartFileNo - m_lastReadFileNo;
|
int file_count = m_curStartFileNo - m_lastReadFileNo;
|
||||||
vLog(LOG_DEBUG, "总共有%d个目录的%d个文件未读取。\n", dir_count, file_count);
|
vLog(LOG_DEBUG, "%s 总共有%d个目录的%d个文件未读取。\n", m_pidName.c_str(), dir_count, file_count);
|
||||||
}
|
}
|
||||||
/*文件从保存的最后读取的文件目录的文件一直督导当前开始目录*/
|
/*文件从保存的最后读取的文件目录的文件一直督导当前开始目录*/
|
||||||
vLog(LOG_DEBUG, "最新文件夹编号: %ld, 最新文件名编号: %ld: 最新文件夹中第一个文件的编号: %ld\n", m_currentDirNo, m_currentFileNo, m_currentDirStartFileNo);
|
vLog(LOG_DEBUG, "%s 最新文件夹编号: %ld, 最新文件名编号: %ld: 最新文件夹中第一个文件的编号: %ld\n", m_pidName.c_str(), m_currentDirNo, m_currentFileNo, m_currentDirStartFileNo);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ private:
|
|||||||
BOOLEAN publishAnalogData(void);
|
BOOLEAN publishAnalogData(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
std::string m_pidName;
|
||||||
BOOLEAN m_bHaveFTP; //存在FTP协议
|
BOOLEAN m_bHaveFTP; //存在FTP协议
|
||||||
|
|
||||||
//ftp参数信息
|
//ftp参数信息
|
||||||
|
3
das-dn/third_party/AdsLib/AdsDevice.cpp
vendored
3
das-dn/third_party/AdsLib/AdsDevice.cpp
vendored
@ -144,12 +144,13 @@ long AdsDevice::GetLocalPort() const
|
|||||||
|
|
||||||
AdsDeviceState AdsDevice::GetState() const
|
AdsDeviceState AdsDevice::GetState() const
|
||||||
{
|
{
|
||||||
uint16_t state[2];
|
uint16_t state[2] = {ADSSTATE::ADSSTATE_MAXSTATES, ADSSTATE::ADSSTATE_MAXSTATES};
|
||||||
if(m_Connected == true){
|
if(m_Connected == true){
|
||||||
auto error = AdsSyncReadStateReqEx(GetLocalPort(), &m_Addr, &state[0], &state[1]);
|
auto error = AdsSyncReadStateReqEx(GetLocalPort(), &m_Addr, &state[0], &state[1]);
|
||||||
if (error) {
|
if (error) {
|
||||||
LOG_ERROR("AdsDevice can not read device state.");
|
LOG_ERROR("AdsDevice can not read device state.");
|
||||||
//throw AdsException(error);
|
//throw AdsException(error);
|
||||||
|
return {static_cast<ADSSTATE>(state[0]), static_cast<ADSSTATE>(state[1])};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i : state) {
|
for (auto i : state) {
|
||||||
|
6
das-dn/third_party/AdsLib/AdsVariable.h
vendored
6
das-dn/third_party/AdsLib/AdsVariable.h
vendored
@ -53,6 +53,7 @@ struct AdsVariable {
|
|||||||
|
|
||||||
void Read(const size_t size, void* data) const
|
void Read(const size_t size, void* data) const
|
||||||
{
|
{
|
||||||
|
if (!m_Route.IsConnected()) return;
|
||||||
uint32_t bytesRead = 0;
|
uint32_t bytesRead = 0;
|
||||||
auto error = m_Route.ReadReqEx2(m_IndexGroup,
|
auto error = m_Route.ReadReqEx2(m_IndexGroup,
|
||||||
*m_Handle,
|
*m_Handle,
|
||||||
@ -61,16 +62,17 @@ struct AdsVariable {
|
|||||||
&bytesRead);
|
&bytesRead);
|
||||||
|
|
||||||
if (error || (size != bytesRead)) {
|
if (error || (size != bytesRead)) {
|
||||||
LOG_ERROR("AdsVariable read failed: "<<std::dec<<error);
|
LOG_ERROR("AdsVariable read failed: "<< std::dec << error);
|
||||||
//throw AdsException(error);
|
//throw AdsException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write(const size_t size, const void* data) const
|
void Write(const size_t size, const void* data) const
|
||||||
{
|
{
|
||||||
|
if (!m_Route.IsConnected()) return;
|
||||||
auto error = m_Route.WriteReqEx(m_IndexGroup, *m_Handle, size, data);
|
auto error = m_Route.WriteReqEx(m_IndexGroup, *m_Handle, size, data);
|
||||||
if (error) {
|
if (error) {
|
||||||
LOG_ERROR("AdsVariable write failed:"<<std::dec<<error);
|
LOG_ERROR("AdsVariable write failed:" << std::dec << error);
|
||||||
//throw AdsException(error);
|
//throw AdsException(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user