This commit is contained in:
coco
2026-07-03 16:05:30 +08:00
commit df489d5640
1101 changed files with 779140 additions and 0 deletions
@@ -0,0 +1,404 @@
// DialDevStatusTimerShow.cpp : implementation file
//
#include "stdafx.h"
#include "geomative.h"
#include "DialQueryPLCStatus.h"
#include "TaskDataOper.h"
#include "FileOperTools.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialDevStatusTimerShow dialog
extern int g_iUILanguage;
extern time_t Str2GmtTm(CString szTime);
extern CString Tm2LocalStr(time_t t);
extern float tcp_ntohf(float f);
CDialQueryPLCStatus::CDialQueryPLCStatus(CWnd* pParent /*=NULL*/)
: CNetRequestDialog(CDialQueryPLCStatus::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialDevStatusTimerShow)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_PLCID = 0;
m_bAppendData = FALSE;
}
void CDialQueryPLCStatus::DoDataExchange(CDataExchange* pDX)
{
CNetRequestDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialDevStatusTimerShow)
DDX_Control(pDX, IDC_LIST_PLC_STATUS, m_listData);
DDX_Control(pDX, IDC_DATETIMEPICKER_STARTTIME, m_StartTime);
DDX_Control(pDX, IDC_DATETIMEPICKER_ENDTIME, m_EndTime);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialQueryPLCStatus, CNetRequestDialog)
//{{AFX_MSG_MAP(CDialDevStatusTimerShow)
ON_BN_CLICKED(IDC_BTN_QUERY_PLC_STATUS, &CDialQueryPLCStatus::OnBnQueryPLCStatus)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialDevStatusTimerShow message handlers
/*struct stPLCStatus
{
UINT32 uStatusTime;
float fSimulation1; //模拟量
float fSimulation2; //模拟量
float fSimulation3; //模拟量
float fSimulation4; //模拟量
float fVoltage; //电压
float fTemperature; //温度
float fSimulation7; //模拟量
float fSimulation8; //模拟量
float fReserve; //预留
BYTE bSwitch1; //控制变量
BYTE bSwitch2; //控制变量
BYTE bSwitch3; //控制变量
BYTE bSwitch4; //控制变量
BYTE bSwitch5; //控制变量
BYTE bSwitch6; //控制变量
BYTE bSwitch7; //控制变量
BYTE bSwitch8; //控制变量
BYTE bSwitch9; //控制变量
BYTE bSwitch10; //控制变量
BYTE bReserve; //预留
};*/
BOOL CDialQueryPLCStatus::OnInitDialog()
{
CNetRequestDialog::OnInitDialog();
if (LANG_ZHCN == g_iUILanguage)
{
SetWindowText(_T("设备状态"));
GetDlgItem(IDC_STATIC_START_TIME)->SetWindowText(_T("开始时间:"));
GetDlgItem(IDC_STATIC_END_TIME)->SetWindowText(_T("结束时间:"));
GetDlgItem(IDC_BTN_QUERY_PLC_STATUS)->SetWindowText(_T("查询"));
}
// TODO: Add extra initialization here
CString strColTitle;
int iColIndex = 0;
m_listData.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP
| LVS_EX_ONECLICKACTIVATE | LVS_EX_GRIDLINES);
CRect rect;
m_listData.GetClientRect(&rect);
int iWidth = rect.right - rect.left;
int iColCount = 5;
if (LANG_ZHCN == g_iUILanguage)
{
m_listData.InsertColumn(iColIndex++, _T("时间"), LVCFMT_CENTER, iWidth / iColCount);
// m_listData.InsertColumn(iColIndex++, _T("Voltage1(V)"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Voltage2(V)"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Voltage3(V)"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Voltage4(V)"), LVCFMT_CENTER, 90);
m_listData.InsertColumn(iColIndex++, _T("电池电压(V)"), LVCFMT_CENTER, iWidth / iColCount);
m_listData.InsertColumn(iColIndex++, _T("温度(℃)"), LVCFMT_CENTER, iWidth / iColCount);
// m_listData.InsertColumn(iColIndex++, _T("Switch1"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Switch2"), LVCFMT_CENTER, 90);
m_listData.InsertColumn(iColIndex++, _T("主机开关"), LVCFMT_CENTER, iWidth / iColCount);//K3
m_listData.InsertColumn(iColIndex++, _T("电源开关"), LVCFMT_CENTER, iWidth / iColCount);//K4
}
else
{
m_listData.InsertColumn(iColIndex++, _T("Time"), LVCFMT_CENTER, iWidth / iColCount);
// m_listData.InsertColumn(iColIndex++, _T("Voltage1(V)"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Voltage2(V)"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Voltage3(V)"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Voltage4(V)"), LVCFMT_CENTER, 90);
m_listData.InsertColumn(iColIndex++, _T("Battery Voltage(V)"), LVCFMT_CENTER, iWidth / iColCount);
m_listData.InsertColumn(iColIndex++, _T("Temperature(℃)"), LVCFMT_CENTER, iWidth / iColCount);
// m_listData.InsertColumn(iColIndex++, _T("Switch1"), LVCFMT_CENTER, 90);
// m_listData.InsertColumn(iColIndex++, _T("Switch2"), LVCFMT_CENTER, 90);
m_listData.InsertColumn(iColIndex++, _T("GD Swit"), LVCFMT_CENTER, iWidth / iColCount);//K3
m_listData.InsertColumn(iColIndex++, _T("BP Swit"), LVCFMT_CENTER, iWidth / iColCount);//K4
}
// m_listData.InsertItem(0,"1");
// m_listData.InsertItem(1, "2");
//任务时间间隔默认5分钟
CTime time;
CTime TDate;
time_t tTime;
CString strTime;
CString strDate;
m_StartTime.GetTime(TDate);
strDate = TDate.Format("%Y-%m-%d"); //获取到的为日期 如:2010-03-05
strTime = time.Format(" 00:00:00");
strDate += strTime;
tTime = Str2GmtTm(strDate);
m_StartTime.SetTime(tTime);
m_EndTime.GetTime(TDate);
//strDate.Format(_T("%d-%d-%d"), TDate.GetYear(), TDate.GetMonth(), TDate.GetDay() + 3); //获取到的为日期 如:2010-03-05
strDate = TDate.Format("%Y-%m-%d");
strTime = time.Format(" 23:59:59");
strDate += strTime;
tTime = Str2GmtTm(strDate);
m_EndTime.SetTime(tTime);
//初始化任务列表
OnBnQueryPLCStatus();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDialQueryPLCStatus::OnBnQueryPLCStatus()
{
// TODO: 在此添加控件通知处理程序代码
m_bAppendData = FALSE;
CTime time;
CTime TDate;
time_t tStartTime,tEndTime;
CString strTime;
CString strDate;
m_StartTime.GetTime(TDate);
//m_CDTTimeStart.GetTime(time);
strDate = TDate.Format("%Y-%m-%d"); //获取到的为日期 如:2010-03-05
strTime = time.Format(" 00:00:00");
strDate += strTime;
tStartTime = Str2GmtTm(strDate);
m_EndTime.GetTime(TDate);
//m_CDTTimeEnd.GetTime(time);
strDate = TDate.Format("%Y-%m-%d"); //获取到的为日期 如:2010-03-05
strTime = time.Format(" 23:59:59");
strDate += strTime;
tEndTime = Str2GmtTm(strDate);
CString strLog;
strLog.Format(_T("zm:PLC status:query starttime=%s,endtime=%s"), Tm2LocalStr(tStartTime), Tm2LocalStr(tEndTime));
CFileOperTools::GetInstance()->WriteComLog(strLog);
CTime clsStart(tStartTime);
CTime clsStop(tEndTime);
CTimeSpan timeSpan1 = clsStop - clsStart;
int iDay = timeSpan1.GetDays();
if (iDay > 10)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("最多支持续10天内的状态查询"));
else
MessageBoxEx(NULL, _T("Maximum number of status queries for 10 days"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
m_tSaveQueryStartTime = tStartTime;
m_tSaveQueryEndTime = tEndTime;
m_tQueryStartTime = tStartTime;
m_tQueryEndTime = tStartTime + LOAD_PLC_STATUS_BY_DATE_CELL*24 * 3600;
STPLCStatusInfoRequest request;
request.uPLCID = htonl(m_PLCID);
request.uStartTime = htonl(m_tQueryStartTime);
request.uEndTime = htonl(m_tQueryEndTime);
PostNetRequest(EN_REQ_QUERY_PLC_STATUS, this->m_hWnd, (char*)&request, sizeof(STPLCStatusInfoRequest),10*1024);
}
void CDialQueryPLCStatus::PreNetResponse(WPARAM wParam, LPARAM lParam)
{
LPRESPONSEPACKET pResponsePacket = (LPRESPONSEPACKET)lParam;
if (pResponsePacket == NULL)
{
return;
}
switch (pResponsePacket->clsPacketBase.ucCmd)
{
case EN_REQ_QUERY_PLC_STATUS://删除循环任务响应
{
if (!m_bAppendData)
{
OnPLCStatusResponse(wParam, lParam);
}
else
{
OnAppendPLCStatusResponse(wParam, lParam);
}
CString strLog;
CTime clsStart(m_tSaveQueryStartTime);
CTime clsStop(m_tSaveQueryEndTime);
//strLog.Format(_T("zm:CDialTaskTree::PreNetResponse query time rangestarttime=%s,endTime=%s\n"), Tm2LocalStr(m_tSaveQueryStartTime), Tm2LocalStr(m_tSaveQueryEndTime));
//OutputDebugString(strLog);
CTimeSpan timeSpan1 = clsStop - clsStart;
int iDay = timeSpan1.GetDays();
if (iDay > 0)
{
m_bAppendData = TRUE;
CTimeSpan ts(1, 0, 0, 0); // 加1天
clsStart = clsStart + ts;
CString date = clsStart.Format("%Y-%m-%d %H:%M:%S ");
m_tSaveQueryStartTime = Str2GmtTm(date);
time_t uiCurTime = 0;
time_t uiStartTime = 0;
m_tQueryStartTime = m_tSaveQueryStartTime;
m_tQueryEndTime = m_tSaveQueryStartTime + LOAD_PLC_STATUS_BY_DATE_CELL * 24 * 3600 + 3600;//3600预留一小时,客户端与服务器偏差时间
strLog.Format(_T("zm:CDialQueryPLCStatus::PreNetResponse request start time%s,end time=%s\n"), Tm2LocalStr(m_tQueryStartTime), Tm2LocalStr(m_tQueryEndTime));
OutputDebugString(strLog);
STPLCStatusInfoRequest request;
request.uPLCID = htonl(m_PLCID);
request.uStartTime = htonl(m_tQueryStartTime);
request.uEndTime = htonl(m_tQueryEndTime);
PostNetRequest(EN_REQ_QUERY_PLC_STATUS, this->m_hWnd, (char*)&request, sizeof(STPLCStatusInfoRequest), 10 * 1024);
}
}
break;
default:
break;
}
}
BOOL CDialQueryPLCStatus::OnPLCStatusResponse(WPARAM wParam, LPARAM lParam)
{
LPRESPONSEPACKET pResponsePacket = (LPRESPONSEPACKET)lParam;
if (pResponsePacket == NULL)
{
return FALSE;
}
if ((1 > pResponsePacket->wDataLen) || (EN_RECV_SUCCESS != pResponsePacket->pData[0]))
{
//theApp.m_NetWorkOper.SetSuspendForThread(false);
return FALSE;
}
else
{
m_listData.DeleteAllItems();
UINT32 *uiRevData = (UINT32*)(pResponsePacket->pData);
UINT32 iTotalNum = ntohl(uiRevData[0]);
STPLCSTATUS* pStatus = (STPLCSTATUS*)(&pResponsePacket->pData[sizeof(UINT32)]);
STPLCSTATUS status;
CString strTemp;
int iColIndex = 0;
int j = 0;
for (int i = 0; i < iTotalNum; i++)
{
iColIndex = 0;
status = pStatus[i];
m_listData.InsertItem(i, _T(""));
m_listData.SetItemText(i, iColIndex++, Tm2LocalStr(ntohl(status.uStatusTime)));
// j = 0;
// for (; j < 4; j++)
// {
// strTemp.Format(_T("%.2f"), tcp_ntohf(status.fSimulation[j]));
// m_listData.SetItemText(i, iColIndex++, strTemp);
// }
strTemp.Format(_T("%.2f"), tcp_ntohf(status.fVoltage));
m_listData.SetItemText(i, iColIndex++, strTemp);
strTemp.Format(_T("%.2f"), tcp_ntohf(status.fTemperature));
m_listData.SetItemText(i, iColIndex++, strTemp);
for (j = 2; j < 4; j++)//for (j = 0; j < 4; j++)
{
strTemp = (status.bSwitch[j] == 0) ? _T("OFF") : _T("ON");
m_listData.SetItemText(i, iColIndex++, strTemp);
}
}
}
return TRUE;
}
BOOL CDialQueryPLCStatus::OnAppendPLCStatusResponse(WPARAM wParam, LPARAM lParam)
{
LPRESPONSEPACKET pResponsePacket = (LPRESPONSEPACKET)lParam;
if (pResponsePacket == NULL)
{
return FALSE;
}
if ((1 > pResponsePacket->wDataLen) || (EN_RECV_SUCCESS != pResponsePacket->pData[0]))
{
return FALSE;
}
else
{
UINT32 *uiRevData = (UINT32*)(pResponsePacket->pData);
UINT32 iTotalNum = ntohl(uiRevData[0]);
STPLCSTATUS* pStatus = (STPLCSTATUS*)(&pResponsePacket->pData[sizeof(UINT32)]);
STPLCSTATUS status;
CString strTemp;
int iColIndex = 0,j;
int iItemCount = m_listData.GetItemCount();
for (int i = 0; i < iTotalNum; i++)
{
iColIndex = 0;
status = pStatus[i];
m_listData.InsertItem(i + iItemCount, _T(""));
m_listData.SetItemText(i + iItemCount, iColIndex++, Tm2LocalStr(ntohl(status.uStatusTime)));
// int j = 0;
// for (; j < 4; j++)
// {
// strTemp.Format(_T("%.2f"), tcp_ntohf(status.fSimulation[j]));
// m_listData.SetItemText(i + iItemCount, iColIndex++, strTemp);
// }
strTemp.Format(_T("%.2f"), tcp_ntohf(status.fVoltage));
m_listData.SetItemText(i + iItemCount, iColIndex++, strTemp);
strTemp.Format(_T("%.2f"), tcp_ntohf(status.fTemperature));
m_listData.SetItemText(i + iItemCount, iColIndex++, strTemp);
for (j = 2; j < 4; j++)//for (j = 0; j < 4; j++)
{
strTemp = (status.bSwitch[j] == 0) ? _T("OFF") : _T("ON");
m_listData.SetItemText(i + iItemCount, iColIndex++, strTemp);
}
}
}
return TRUE;
}
/*void CDialQueryPLCStatus::ShowPlcStatusData()
{
CTaskDataOper dataOper;
std::vector<STPlcStatusInfo> vtPlcData;
vtPlcData.clear();
if (dataOper.QueryPlcStatusData(vtPlcData))
{
int iColIndex = 0;
CString strTxt;
for (int i = 0; i < vtPlcData.size(); i++)
{
strTxt.Empty();
strTxt.Format(_T("%s %s"),vtPlcData[i].strRepDate, vtPlcData[i].strRepTime);
// m_listData.SetItemText(i, iColIndex++, strTxt);
m_listData.InsertItem(i,strTxt);
iColIndex = 1;
int j = 0;
for (; j < 6; j++)
{
strTxt.Empty();
strTxt.Format(_T("%.2f"),vtPlcData[i].fAnalog[j]);
m_listData.SetItemText(i, iColIndex++, strTxt);
}
for (j = 0; j < 4; j++)
{
strTxt = (vtPlcData[i].shCtrl[j] == 0) ? _T("OFF") : _T("ON");
m_listData.SetItemText(i, iColIndex++, strTxt);
}
}
}
} */