private byte[] PrepareMessage(byte[] msg) { CCTCrc16 crc16 = new CCTCrc16(); int msg_len = msg.Length; byte[] reply = new byte[msg_len + 5]; reply[0] = master_address; reply[1] = (byte)msg_len; reply[3] = 0; Array.Copy(msg, 0, reply, 4, msg_len); crc16.Reset(); crc16.PushByte(reply[0]); crc16.PushByte(reply[1]); crc16.PushData(reply, 3, msg_len + 1); reply[2] = (byte)(crc16.CRC & (ushort)0x00FF); reply[4 + msg_len] = (byte)(crc16.CRC >> 8); if (use_cryptograthy) { CCTCrypt.Encrypt(reply, 2, 3 + msg_len, encryption_key); } return(reply); }
private byte[] OnBillIdRequest(byte[] msg) { string bill_id; CCTCrc16 crc16 = new CCTCrc16(); bool result = money_id_list.TryGetValue((int)msg[4], out bill_id); if (!result) { money_id_list.TryGetValue(-1, out bill_id); //get default value } int msg_size = bill_id.Length; byte[] reply = new byte[msg_size + 5]; reply[0] = master_address; reply[1] = (byte)msg_size; reply[3] = 0; Array.Copy(System.Text.Encoding.ASCII.GetBytes(bill_id), 0, reply, 4, msg_size); crc16.Reset(); crc16.PushByte(reply[0]); crc16.PushByte(reply[1]); crc16.PushData(reply, 3, msg_size + 1); reply [2] = (byte)(crc16.CRC & (ushort)0x00FF); reply[4 + msg_size] = (byte)(crc16.CRC >> 8); if (use_cryptograthy) { CCTCrypt.Encrypt(reply, 2, 3 + msg_size, encryption_key); } return(reply); }
private byte[] SendACK() { CCTCrc16 crc16 = new CCTCrc16(); byte[] reply = new byte[5]; reply[0] = master_address; reply[1] = 0; reply[3] = 0; crc16.Reset(); crc16.PushByte(reply[0]); crc16.PushByte(reply[1]); crc16.PushByte(reply[3]); reply[2] = (byte)(crc16.CRC & (ushort)0x00FF); reply[4] = (byte)(crc16.CRC >> 8); if (use_cryptograthy) { CCTCrypt.Encrypt(reply, 2, 3, encryption_key); } return(reply); }