📄 sirstate.cpp
字号:
//**********************************************************************
//
// Filename: sirstate.cpp
//
// Description: Includes the state machine for sir.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// Copyright(c) Cirrus Logic Corporation 2001, All Rights Reserved
//
//**********************************************************************
#include <windows.h>
extern "C"
{
#include <ndis.h>
#include <ntddndis.h>
}
#include <linklist.h>
#include <ceddk.h>
#include "settings.h"
#include "debugzone.h"
#include "recvlist.h"
#include "sirstate.h"
#include "irdahw.h"
#include "irmacutl.h"
//****************************************************************************
// SirState::ProcessBytes
//****************************************************************************
// Converts a byte stream into frames by getting rid of the BOF, EOF and
// Escape Sequences. Also makes sure that the frame has the proper check sums.
//
//
void ReceivedSirState::ProcessByte
(
unsigned char bRead
)
{
ULONG fcs;
//
// If we don't have a frame available just drop the byte.
//
if(!m_pRxBuf)
{
return;
}
switch (m_eRxState)
{
case RX_STATE_READY:
if (bRead == SLOW_IR_BOF)
{
m_eRxState = RX_STATE_BOF;
m_pucCurrent = m_pucBuffer;
}
// else - Ignore all other data.
break; // RX_STATE_READY.
case RX_STATE_BOF:
switch (bRead)
{
case SLOW_IR_BOF:
// Ignore.
break;
case SLOW_IR_ESC:
m_eRxState = RX_STATE_IN_ESC;
break;
case SLOW_IR_EOF:
m_eRxState = RX_STATE_READY;
break;
default:
// Should be first character.
ASSERT(m_pucBuffer == m_pucCurrent);
m_eRxState = RX_STATE_RX;
*m_pucCurrent++ = bRead;
break;
}
break; // RX_STATE_BOF.
case RX_STATE_IN_ESC:
switch (bRead)
{
// If (ESC + BOF) Then state = BOF.
case SLOW_IR_BOF:
// Reset.
m_eRxState = RX_STATE_BOF;
m_pucCurrent = m_pucBuffer;
DEBUGMSG(ZONE_ERROR, (TEXT("Rx:Invalid BOF[1].\r\n")));
break;
// If (ESC + (ESC || EOF)) Then state = READY.
case SLOW_IR_ESC:
case SLOW_IR_EOF:
m_eRxState = RX_STATE_READY;
DEBUGMSG(ZONE_ERROR, (TEXT("Rx:Protocol error[1].\r\n")));
break;
// Escape sequence for BOF, EOF or ESC.
case SLOW_IR_BOF^SLOW_IR_ESC_COMP:
case SLOW_IR_EOF^SLOW_IR_ESC_COMP:
case SLOW_IR_ESC^SLOW_IR_ESC_COMP:
// Fall through, do same as default.
// Unnecessary escape sequence.
default:
if (m_pucCurrent < m_pucEnd)
{
m_eRxState = RX_STATE_RX;
*m_pucCurrent++ = bRead^SLOW_IR_ESC_COMP;
}
else
{
// Overflow. Reset.
m_eRxState = RX_STATE_READY;
m_ulPacketsRxOverflow++;
DEBUGMSG(ZONE_ERROR,
(TEXT("Rx:Overflow[1] count = %d.\r\n"),
m_ulPacketsRxOverflow)
);
}
break;
}
break; // RX_STATE_IN_ESC.
case RX_STATE_RX:
switch (bRead)
{
case SLOW_IR_BOF:
// Reset.
m_eRxState = RX_STATE_BOF;
m_pucCurrent = m_pucBuffer;
DEBUGMSG(ZONE_ERROR, (TEXT("Rx:Invalid BOF[2].\r\n")));
break;
case SLOW_IR_ESC:
m_eRxState = RX_STATE_IN_ESC;
break;
case SLOW_IR_EOF:
m_eRxState = RX_STATE_READY;
//
// Compute data size.
//
m_pRxBuf->cbData = (DWORD)(m_pucCurrent - m_pucBuffer);
fcs = ComputeFCS
(
m_pucBuffer,
m_pRxBuf->cbData
);
if (fcs == GOOD_FCS)
{
//
// Take off size of FCS.
//
m_ulPacketSize -= SLOW_IR_FCS_SIZE;
m_bPacketAvaliable = TRUE;
++m_ulPacketsRx;
}
else
{
//
// Reset.
//
m_ulPacketsRxDropped++;
DEBUGMSG(ZONE_ERROR,
(TEXT("Rx:Bad FCS (%x) count = %d\r\n"),
fcs, m_ulPacketsRxDropped)
);
}
break;
default:
if (m_pucCurrent < m_pucEnd)
{
*m_pucCurrent++ = bRead;
}
else
{
// Overflow. Reset.
m_eRxState = RX_STATE_READY;
m_ulPacketsRxOverflow++;
DEBUGMSG(ZONE_ERROR,
(TEXT("Rx:Overflow[2] count = %d.\r\n"),
m_ulPacketsRxOverflow)
);
}
break;
}
break; // RX_STATE_RX.
//case RX_STATE_SHUTDOWN:
// DEBUGMSG(ZONE_WARN, (TEXT("Rx:Shutting down receive thread.\r\n")));
// fSuccess = FALSE;
// goto done;
default:
// Illegal state.
ASSERT(FALSE);
m_eRxState = RX_STATE_READY;
break;
}
}
//****************************************************************************
// ReceivedSirState::SetNextBuffer
//****************************************************************************
// Set the Next Buffer to be processed.
//
//
void ReceivedSirState::SetNextBuffer
(
PRX_BUFFER pRxBuf
)
{
ASSERT(pRxBuf);
m_pRxBuf = pRxBuf;
m_bPacketAvaliable = FALSE;
if(pRxBuf)
{
pRxBuf->cbData = 0;
m_eRxState = RX_STATE_READY;
m_pucBuffer = m_pucCurrent = pRxBuf->pbBuffer;
m_pucEnd = pRxBuf->pbBuffer + pRxBuf->cbBuffer;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -