Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        private bool ValidateIncomingMsg(byte[] msg, ref int cmd)
        {
            bool result = false;

            try
            {
                if (msg.Length > MSG_MIN_LEN)
                {
                    int address = msg[0];

                    if (address == device_address)
                    {
                        if (use_cryptograthy)
                        {
                            CCTCrypt.Decrypt(msg, 2, msg.Length - 2, encryption_key);
                        }

                        if (msg[1] != msg.Length - 5)
                        {
                            WriteLogFile("ERROR IN MSG", ByteArrayToString(msg));
                        }

                        cmd    = msg[3];
                        result = true;
                    }
                    else if (!(address == 2 || address == 0x28))
                    {
                        WriteLogFile("ERROR IN MSG (WRONG ADDRESS)", ByteArrayToString(msg));
                    }
                }
                else
                {
                    WriteLogFile("ERROR IN MSG", ByteArrayToString(msg));
                }
            }
            catch
            {
            }

            return(result);
        }
Exemple #4
0
        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);
        }