NumberFive
27.03.2004, 02:56
Ich finde man kann es schon kopleziert machen um zwei Bytes zu übertragen.
__stdcall CVPBrick::OnReceived (BSTR strData )
{
CString csValue = "";
USES_CONVERSION;
csValue = W2A(strData);
if (csValue.Left(4) == "0x13")
{
if(csValue.GetLength() > 4)
{
csValue = csValue.Mid(5,csValue.GetLength()-4);
}
else
{
csValue = "";
}
//Hat nix damit zu tun das der brick lebt
}
if(csValue.GetLength() > 0)
{
if(csValue.Left(14) = "0x55,0xff,0x00")
{
// MessageHeader OK
csValue = csValue.Mid(15,csValue.GetLength()-14);
int lengthStr = csValue.GetLength() / 4;
BYTE* buffer;
BYTE* daten;
int i,x;
BYTE sum = 0;
buffer = new BYTE[lengthStr];
daten = new BYTE[lengthStr/2];
char wert[5];
for(i = 0;i<lengthStr;i++)
{
strcpy(wert,csValue.Mid(0,4));
csValue = csValue.Mid(5,csValue.GetLength()-5);
DWORD test = strtoul(wert,0,16);
buffer[i] = LOBYTE(test);
}
x = 0;
for(i = 0;i<lengthStr;i=i+2)
{
BYTE temp = ~buffer[i+1];
if (buffer[i] == temp)
{
daten[x] = buffer[i];
sum += daten[x];
x++;
}
}
if (x == lengthStr/2)
{
//PARITY OK
if (daten[x] = sum)
{
//Checksumme ok
ATLTRACE("*** Daten");
for(i=0;i<x-1;i++)
{
ATLTRACE(" 0x%02X ",daten[i]);
}
ATLTRACE(" ***\n");
ATLTRACE(" *** Prüfsumme (0x%02X) ***\n",daten[x-1]);
if (daten[0] == 0xF7)
{
// InternMessage
if(!m_bOnline)
{
m_pGobalControl->SetOnline();
m_bOnline = true;
}
}
}
}
delete buffer;
delete daten;
}
}
}
__stdcall CVPBrick::OnReceived (BSTR strData )
{
CString csValue = "";
USES_CONVERSION;
csValue = W2A(strData);
if (csValue.Left(4) == "0x13")
{
if(csValue.GetLength() > 4)
{
csValue = csValue.Mid(5,csValue.GetLength()-4);
}
else
{
csValue = "";
}
//Hat nix damit zu tun das der brick lebt
}
if(csValue.GetLength() > 0)
{
if(csValue.Left(14) = "0x55,0xff,0x00")
{
// MessageHeader OK
csValue = csValue.Mid(15,csValue.GetLength()-14);
int lengthStr = csValue.GetLength() / 4;
BYTE* buffer;
BYTE* daten;
int i,x;
BYTE sum = 0;
buffer = new BYTE[lengthStr];
daten = new BYTE[lengthStr/2];
char wert[5];
for(i = 0;i<lengthStr;i++)
{
strcpy(wert,csValue.Mid(0,4));
csValue = csValue.Mid(5,csValue.GetLength()-5);
DWORD test = strtoul(wert,0,16);
buffer[i] = LOBYTE(test);
}
x = 0;
for(i = 0;i<lengthStr;i=i+2)
{
BYTE temp = ~buffer[i+1];
if (buffer[i] == temp)
{
daten[x] = buffer[i];
sum += daten[x];
x++;
}
}
if (x == lengthStr/2)
{
//PARITY OK
if (daten[x] = sum)
{
//Checksumme ok
ATLTRACE("*** Daten");
for(i=0;i<x-1;i++)
{
ATLTRACE(" 0x%02X ",daten[i]);
}
ATLTRACE(" ***\n");
ATLTRACE(" *** Prüfsumme (0x%02X) ***\n",daten[x-1]);
if (daten[0] == 0xF7)
{
// InternMessage
if(!m_bOnline)
{
m_pGobalControl->SetOnline();
m_bOnline = true;
}
}
}
}
delete buffer;
delete daten;
}
}
}