📄 myobject.cpp
字号:
// MyObject.cpp: implementation of the CMyObject class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "mbpc.h"
#include "MyObject.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CMyObject, CObject, 0)
CMyObject::CMyObject()
{
}
CMyObject::CMyObject(BYTE *pPacket)
{
m_nChgCntr = 0;
memset(m_Time,0,sizeof(m_Time));
memset(m_frame,0,sizeof(m_frame));
memset(m_bStatus,0,sizeof(m_bStatus));
memcpy(m_frame, pPacket, 1280);
int i,j;
switch(m_frame[8])
{
case SEND_DI_CHANGE:
{
memcpy(m_Time, &m_frame[25], 8);
m_Time[8] = SEND_DI_CHANGE;
for(i = 0; i < 8; i++)
{
for(j = 0; j < 8; j++)
{
if(m_frame[9 + i] & (int)pow(2,j))
{
m_bStatus[i*8+j] = TRUE;
}
else
{
m_bStatus[i*8+j] = FALSE;
}
if(m_frame[17 + i] & (int)pow(2,j))
{
m_nChgCntr++;
}
}
}
break;
}
case SEND_DO_CHANGE:
{
memcpy(m_Time, &m_frame[17], 8);
m_Time[8] = SEND_DO_CHANGE;
for(i = 0; i < 4; i++)
{
for(j = 0; j < 8; j++)
{
if(m_frame[9 + i] & (int)pow(2,j))
{
m_bStatus[i*8+j] = TRUE;
}
else
{
m_bStatus[i*8+j] = FALSE;
}
if(m_frame[13 + i] & (int)pow(2,j))
{
m_nChgCntr++;
}
}
}
break;
}
case SEND_ENABLE_CHANGE:
{
memcpy(m_Time, &m_frame[17], 8);
m_Time[8] = SEND_ENABLE_CHANGE;
for(i = 0; i < 4; i++)
{
for(j = 0; j < 8; j++)
{
if(m_frame[9 + i] & (int)pow(2,j))
{
m_bStatus[i*8+j] = TRUE;
}
else
{
m_bStatus[i*8+j] = FALSE;
}
if(m_frame[13 + i] & (int)pow(2,j))
{
m_nChgCntr++;
}
}
}
break;
}
case SEND_ALARM:
{
memcpy(m_Time, &m_frame[17], 8);
m_Time[8] = SEND_ALARM;
for(i = 0; i < 4; i++)
{
for(j = 0; j < 8; j++)
{
if(m_frame[9 + i] & (int)pow(2,j))
{
m_bStatus[i*8+j] = TRUE;
}
else
{
m_bStatus[i*8+j] = FALSE;
}
if(m_frame[13 + i] & (int)pow(2,j))
{
m_nChgCntr++;
}
}
}
break;
}
case SEND_RECORD_CHANGE:
{
memcpy(m_Time, &m_frame[17], 8);
m_Time[8] = SEND_RECORD_CHANGE;
for(i = 0; i < 4; i++)
{
for(j = 0; j < 8; j++)
{
if(m_frame[9 + i] & (int)pow(2,j))
{
m_bStatus[i*8+j] = TRUE;
}
else
{
m_bStatus[i*8+j] = FALSE;
}
if(m_frame[13 + i] & (int)pow(2,j))
{
m_nChgCntr++;
}
}
}
break;
}
}
}
CMyObject::~CMyObject()
{
}
//DEL void CMyObject::FormatMyObject(CString& str)
//DEL {
//DEL //str.Format(_T("{%i, %.4f, %s}"), m_int, m_float, (LPCTSTR)m_str);
//DEL switch(m_frame[8])
//DEL {
//DEL default:
//DEL {
//DEL str.Empty();
//DEL break;
//DEL }
//DEL case SEND_DI_CHANGE:
//DEL {
//DEL break;
//DEL }
//DEL case SEND_DO_CHANGE:
//DEL {
//DEL break;
//DEL }
//DEL case SEND_ENABLE_CHANGE:
//DEL {
//DEL break;
//DEL }
//DEL case SEND_ALARM:
//DEL {
//DEL break;
//DEL }
//DEL case SEND_RECORD_CHANGE:
//DEL {
//DEL break;
//DEL }
//DEL }
//DEL }
void CMyObject::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
for(int i = 0; i < 1280; i++)
{
ar << m_frame[i];
}
}
else
{
for(int i = 0; i < 1280; i++)
{
ar >> m_frame[i];
}
}
}
BOOL AFXAPI operator ==( CMyObject& MyObj ,BYTE *frame)
{
if(memcmp(MyObj.m_frame, frame,50) == 0)
{
return TRUE;
}
else
return FALSE;
}
BOOL AFXAPI operator ==(BYTE *frame, CMyObject& MyObj)
{
if(memcmp(MyObj.m_frame, frame,50) == 0)
{
return TRUE;
}
else
return FALSE;
}
BOOL AFXAPI operator >(CMyObject &MyObj, CMyObject &MyObj1)
{
if(memcmp(MyObj.m_Time, MyObj1.m_Time, 8) > 0)
return TRUE;
else
return FALSE;
}
BOOL AFXAPI operator <(CMyObject &MyObj, CMyObject &MyObj1)
{
if(memcmp(MyObj.m_Time, MyObj1.m_Time, 8) < 0)
return TRUE;
else
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -