Home > other >  9 modules axis attitude PC raw data resolution protocol has failed to teach?
9 modules axis attitude PC raw data resolution protocol has failed to teach?

Time:11-06

I made of MFC + MSComm control read nine axis attitude data, but is unable to realize data packet parsing! The parsing process has been making mistakes! Who have done this, please guide? Help me to look at the problem in where?

The header file:
Public:
Struct STime stcTime;
Struct SAcc stcAcc;
Struct SGyro stcGyro;
Struct SAngle stcAngle;
Struct SMag stcMag;
Struct STime
{
Unsigned char ucYear;
Unsigned char ucMonth;
Unsigned char ucDay;
Unsigned char ucHour;
Unsigned char ucMinute;
Unsigned char ucSecond;
Unsigned short usMiliSecond;
};
Struct SAcc
{
Short a, [3].
Short T;
};
Struct SGyro
{
Short w [3];
Short T;
};
Struct SAngle
{
Short Angle [3].
Short T;
};
Struct SMag
{
Short h [3];
Short T;
};
The CPP file:
Oid CIMUDlg: : OnCommMscomm1 ()
{
//TODO: add message handler code here
//receive buffer data
If (m_mscom get_CommEvent ()==2)
{
//Receive1COMData ();
Cstrings STR, str1;
Cstrings strtemp;
BYTE chrBuffer [2000].
The static unsigned char ucRxCnt=0;
The static unsigned short usRxLength=0;
Long k;
Unsigned short usLength=0, usCnt=0, uklength=0;
The VARIANT InputData=https://bbs.csdn.net/topics/m_mscom.get_Input ();
COleSafeArray fs.
Fs=InputData;
Long ulComm;
UlComm=m_comb2. GetCurSel ();
Uklength=fs. GetOneDimSize ();
//usLength=CollectData (ulComm chrBuffer);
For (k=0; K & lt; Uklength; K++)//error
{
Fs. GetElement (& amp; K, chrBuffer + k);//to write data into the array
BYTE bt=* (char *) (chrBuffer + k);//character
If (m_ctrlHexReceive GetCheck ())
Strtemp. The Format (_T (" % 02 x "), bt);//in hexadecimal characters into temporary variables strtemp deposit, note here to join an empty partition, with space to display when
The else
Strtemp. The Format (_T (" % c "), bt);//the character into temporary variables strtemp store
M_EditRev +=strtemp;//add receive corresponding string edit box
}
The UpdateData (false);
}
Use the following method is a problem has been showing
UsLength=fs. GetOneDimSize ();
Memcpy (chrBuffer, fs, usLength);
UsRxLength +=usLength;
While (usRxLength & gt;=11)
{
If (chrBuffer [0]!=0 x55)
{
UsRxLength -;
Memcpy (& amp; ChrBuffer [0], & amp; ChrBuffer [1], usLength);
continue;
}

The switch (chrBuffer [1])
{
Case 0 x50:
Memcpy (& amp; StcTime, & amp; ChrBuffer [2], 8);
break;
Case 0 x51:
Memcpy (& amp; StcAcc, & amp; ChrBuffer [2], 8);
break;
Case 0 x52:
Memcpy (& amp; StcGyro, & amp; ChrBuffer [2], 8);
break;
Case 0 x53:
Memcpy (& amp; StcAngle, & amp; ChrBuffer [2], 8);
break;
Case 0 x54:
Memcpy (& amp; StcMag, & amp; ChrBuffer [2], 8);
break;
}
UsRxLength -=11;
Memcpy (& amp; ChrBuffer [0], & amp; ChrBuffer [1], usLength);
}
}

Cstrings str_T;
Str_T. The Format (_T (" Time: d - 20% - % d % d % d: % d: %, 3 f \ r \ n "), (short) stcTime. UcYear, (short) stcTime. UcMonth,
(short) stcTime ucDay, (short) stcTime. UcHour, (short) stcTime. UcMinute, (float) stcTime. UcSecond + (float) stcTime. UsMiliSecond/1000);
Cstrings str_A;
Str_A. The Format (_T (" Acc: %. 3 f %. 3 f %. 3 f \ r \ n "), (float) stcAcc. A [0]/* 16, 32768 (float) stcAcc. A [1]/* 16, 32768 (float) stcAcc. [2] a/32768 * 16);
Cstrings str_G;
Str_G. The Format (_T (" Gyro: %, 3 f % % 3 f, 3 f \ r \ n "), (float) stcGyro. W [0]/32768 * 2000, (float) stcGyro. W [1]/* 2000, 32768 (float) stcGyro. W [2]/32768 * 2000);
Cstrings str_AG;
Str_AG. The Format (_T (" Angle: %, 3 f % % 3 f, 3 f \ r \ n "), (float) stcAngle. Angle [0]/32768 * 180, (float) stcAngle. Angle [1]/* 180, 32768 (float) stcAngle. Angle [2]/32768 * 180);
Cstrings str_M;
Str_M. The Format (_T (" Mag: % d % d % d \ r \ n "), stcMag. H [0], stcMag. H [1], stcMag. H [2]).

M_EditRev +=str_T;
M_EditRev +=str_A;
M_EditRev +=str_G;
M_EditRev +=str_AG;
M_EditRev +=str_M;

//the UpdateData (false);//the data displayed in the screen corresponding controls,


}
  • Related