public TXRequestEventArgs(DCID_Enum dcID, byte[] buffer, int buffer_cnt) { DCID = dcID; DataCnt = buffer_cnt; Data = new byte[buffer_cnt]; for (int i = 0; i < buffer_cnt; i++) { Data[i] = buffer[i]; } }
public void uMCP_DC_Input_Process(DCID_Enum dcID, byte[] buffer) { for (int i = 0; i < buffer.Length; i++) { uMCP_OnNewByte(dcID, buffer[i]); } //if (Serial.available()) //{ // uMCP_OnNewByte(DCID_Enum.HOST_DC_ID, Serial.read()); //} //while (Serial1.available()) //{ // uMCP_OnNewByte(DCID_Enum.LINE_DC_ID, Serial1.read()); //} }
void uMCP_OnNewByte(DCID_Enum chID, byte c) { if (chID == DCID_Enum.HOST_DC_ID) { if (ih_Cnt <= HOST_BUFFER_SIZE) { ih_ring[ih_wPos] = c; ih_wPos = Convert.ToUInt16((ih_wPos + 1) % HOST_BUFFER_SIZE); ih_Cnt++; ih_TS = millis(); } else { //Serial.print("!TX_OVF"); TX_Overflow_Event.Rise(this, new EventArgs()); } } else if (chID == DCID_Enum.LINE_DC_ID) { if (ip_start) { if (ip_pos == 1) { ip_ahchk = CRC8_Update(ip_ahchk, c); ip_type = (uMCP_PacketType)c; if (ip_type == uMCP_PacketType.uMCP_PTYPE_INVALID) { ip_start = false; } else { ip_pos++; } } else if (ip_pos <= 3) { ip_ahchk = CRC8_Update(ip_ahchk, c); if (ip_pos == 3) { ip_tid = c; } else if (ip_pos == 2) { ip_sid = c; } ip_pos++; } else { if ((ip_type == uMCP_PacketType.uMCP_PTYPE_STR) || (ip_type == uMCP_PacketType.uMCP_PTYPE_STA)) { if (ip_ahchk == c) // CRC OK { ip_start = false; ip_ready = true; } } else { if (ip_pos == 4) { ip_tcnt = c; ip_pos++; ip_ahchk = CRC8_Update(ip_ahchk, c); } else { if (ip_type == uMCP_PacketType.uMCP_PTYPE_REP) { if (ip_ahchk == c) { ip_ready = true; } ip_start = false; } else { if (ip_pos == 5) { ip_rcnt = c; ip_pos++; ip_ahchk = CRC8_Update(ip_ahchk, c); } else { if (ip_pos == 6) // header checksum { if (ip_ahchk == c) { if (ip_type == uMCP_PacketType.uMCP_PTYPE_ACK) { ip_ready = true; ip_start = false; } else { ip_pos++; } } else { ip_start = false; } } else { if (ip_pos == 7) // dcnt { ip_dcnt = c; if (ip_dcnt >= 1) { ip_ahchk = CRC8_Update(0xff, c); ip_pos++; } else { ip_start = false; ip_ready = true; ip_type = uMCP_PacketType.uMCP_PTYPE_ACK; } } else if (ip_pos == 8 + ip_dcnt) { if (ip_ahchk == c) // data block CRC ok { ip_ready = true; } else { ip_type = uMCP_PacketType.uMCP_PTYPE_ACK; } ip_start = false; } else { ip_datablock[ip_pos - 8] = c; ip_ahchk = CRC8_Update(ip_ahchk, c); ip_pos++; } } } } } } } } else if (c == UMCP_SIGN) { ip_start = true; ip_pos = 1; ip_ahchk = CRC8_Update(0xff, UMCP_SIGN); ip_type = uMCP_PacketType.uMCP_PTYPE_INVALID; ip_dcnt = 0; } } }