/// <summary> /// HDLC层接收数据 /// </summary> /// <param name="b">字节数据</param> private void InputWrite(byte b) { try { if (b == HDLC_ESCAPE) { m_bInputEscaping = true; } else { if (m_bInputEscaping == true) { // Kous: 注意一下转化时候按思路执行的 b = (byte)(b ^ HDLC_ESCAPE_MASK); m_bInputEscaping = false; } // add byte to input buffer m_u8aInputBuf[m_u8InputBufFill] = b; m_u8InputBufFill++; // iterate through CRC calculator m_u16InputCrc = FCS.Fcs16CalcByte(m_u16InputCrc, b); } } catch (Exception ex) { CommStackLog.RecordErr(enLogLayer.eHdlc, "InputBuf(" + m_u8InputBufFill + ") " + ex.ToString()); } }
/// <summary> /// HDLC层发送数据 /// </summary> /// <param name="b"></param> public void OutputWrite(byte b) { m_u8aOutputPacketBuf[m_u8OutputPacketFill++] = b; m_u16OutputCrc = FCS.Fcs16CalcByte(m_u16OutputCrc, b); // write optional escape byte if (b == HDLC_FLAG || b == HDLC_ESCAPE) { m_u8aOutputBuf[m_u8OutputBufFill++] = HDLC_ESCAPE; b = (byte)(b ^ HDLC_ESCAPE_MASK); } // data byte m_u8aOutputBuf[m_u8OutputBufFill++] = b; }