public bool IS_consistentCheckSumByte() { if (C_CheckSum.GET_checkSum_fromWholePacket(PacketBytes) == 0) { return(true); } else { return(false); } }
public byte[] CREATE_instructionPacket_bytes(bool forChecksum) { // Instruction Packet = from pc to servo // OXFF | 0XFF | ID | LENGTH | INSTRUCTION | PARAMETER_1 | … | PARAMETER_N | CHECK_SUM // this function adds first two startBytes [0xFF,0xFF], its id byte, length byte, instruction byte and Checksum byte // around parameters and returns the byte array of it //packetNumOfBytes = par.Count + 4; byte[] _packetBytes = new byte[packetNumOfBytes]; //List<byte> _lsPacketBytes = new List<byte>(5); int q = 0; // id _packetBytes[IndexOfId] = byteId; // length byte _packetBytes[IndexOfLength] = byteLength; // instruction _packetBytes[IndexOfInstructionOrError] = byteInstructionOrError; // parameters q = IndexOfFirstParam; foreach (byte by in par) { _packetBytes[q] = by; q++; } // checksum - counted without PACKETSTART _packetBytes[q] = C_CheckSum.GET_checkSum_fromDataBytes(_packetBytes); // packet start for (q = IndexOfPacketStart; q < C_DynAdd.SIZEOF_PACKETSTART; q++) { _packetBytes[q] = C_DynAdd.PACKETSTART[q]; } if (forChecksum == true) { int from = C_DynAdd.INDEXOF_ID_IN_STATUSPACKET; int count = packetNumOfBytes - from - C_DynAdd.SIZEOF_CHECKSUM; return((new ArraySegment <byte>(_packetBytes, from, count)).ToArray()); } else { return(_packetBytes); } }
//public C_Packet(C_Packet pack): //{ // IdByte = pack.idByte; // lengthByte = pack.lengthByte; //} //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #endregion constructor //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #region REFRESH //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% public void REFRESH_checkSum() { // count checksum from whole cmd byteCheckSum = C_CheckSum.GET_checkSum_fromWholePacket(PacketBytes); }