반응형
//패킷 디코딩
public static bool DecodePacket(byte[] btBuf, out uint uCommand, out object oData, out uint uLen)
{
uCommand = 0;
oData = 0;
uLen = 0;
ASCIIEncoding encoding = new ASCIIEncoding();
int nOffset = 0;
Object oResult;
Object oResult;
//StartCode
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
if ((uint)oResult != STARTCODE)
return false;
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
if ((uint)oResult != STARTCODE)
return false;
//Session No
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
//Length => CMD + DATA
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
uLen = (uint)oResult;
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
//Length => CMD + DATA
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
uLen = (uint)oResult;
//CMD
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
uCommand = (uint)oResult;
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
uCommand = (uint)oResult;
if (0 < uLen - sizeof(uint)) //Length에서 CMD 길이를 뺀게 0보다 크면 -> 데이터가 남았음
{
//Data
AssignByteAsLength(out oResult, ref nOffset, btBuf, uLen - sizeof(uint));
oData = oResult;
}
{
//Data
AssignByteAsLength(out oResult, ref nOffset, btBuf, uLen - sizeof(uint));
oData = oResult;
}
//EndCode
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
if ((uint)oResult == ENDCODE)
return true;
AssignByteAsLength(out oResult, ref nOffset, btBuf, sizeof(uint));
if ((uint)oResult == ENDCODE)
return true;
return false;
}
}
반응형
'프로그래밍' 카테고리의 다른 글
C#과 MFC Socket 통신하기 참조 (0) | 2010.06.09 |
---|---|
C#에서 byte배열의 해당 길이만큼 가져옴 (0) | 2010.06.09 |
DataGridView 사용 팁 17가지 (0) | 2010.06.08 |
DataGridView에서 DataGridViewComboBoxCell 사용시... Selection을 잘 먹지 않는 경우... (0) | 2010.06.08 |
C#에서의 Socket 통신시 byte배열로 변환하기 [패킷화 하기] (0) | 2010.05.25 |
댓글