Beispiel #1
0
        private bool Write_Block(byte p_slave_addr, uint p_start_addr, ref byte[] p_array)
        {
            byte[] array = new byte[48];
            uint   num   = p_start_addr;
            int    num2  = 0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 48; k++)
                    {
                        array[k] = p_array[num2++];
                    }
                    if (!BL16.Write(p_slave_addr, num, 48, ref array))
                    {
                        return(false);
                    }
                    num += 32u;
                }
                if (!BL16.Program(p_slave_addr))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #2
0
        private bool Read_Block(byte p_slave_addr, uint p_start_addr, ref byte[] p_array)
        {
            byte[] array = new byte[252];
            int    num   = 0;
            uint   num2  = p_start_addr;

            for (int i = 0; i < 6; i++)
            {
                if (!BL16.Read(p_slave_addr, num2, 252, ref array))
                {
                    return(false);
                }
                for (int j = 0; j < 252; j++)
                {
                    p_array[num++] = array[j];
                }
                num2 += 168u;
            }
            if (!BL16.Read(p_slave_addr, num2, 24, ref array))
            {
                return(false);
            }
            for (int k = 0; k < 24; k++)
            {
                p_array[num++] = array[k];
            }
            return(true);
        }
Beispiel #3
0
        public static bool BootLoader_Is_Enabled(byte p_slave_addr)
        {
            bool result = false;

            byte[] array  = new byte[3];
            byte[] array2 = array;
            if (BL16.Read_Status(p_slave_addr, ref array2) && (array2[2] & 1) == 1)
            {
                result = true;
            }
            return(result);
        }
Beispiel #4
0
        public static bool Count_Num_Blocks(string p_file_name, ref int p_num_blocks, ref int p_err_code)
        {
            uint num    = 0u;
            uint num2   = 0u;
            uint num3   = 0u;
            bool flag   = true;
            bool result = true;

            p_err_code = 0;
            if (File.Exists(p_file_name))
            {
                string text = " ,\t";
                text.ToCharArray();
                try
                {
                    StreamReader streamReader = File.OpenText(p_file_name);
                    p_num_blocks = 0;
                    while (streamReader.Peek() >= 0)
                    {
                        string text2 = streamReader.ReadLine();
                        if (text2 == ":00000001FF")
                        {
                            break;
                        }
                        if (text2 != "" && text2[0] == ':')
                        {
                            string text3 = "0x";
                            string text4 = "0x";
                            string text5 = "0x";
                            string text6 = "0x";
                            text3 += text2[1];
                            text3 += text2[2];
                            int num4 = Utilities.Convert_Value_To_Int(text3);
                            text4 += text2[3];
                            text4 += text2[4];
                            text4 += text2[5];
                            text4 += text2[6];
                            text5 += text2[7];
                            text5 += text2[8];
                            uint num5 = (uint)Utilities.Convert_Value_To_Int(text4);
                            byte b    = (byte)Utilities.Convert_Value_To_Int(text5);
                            if (b == 4)
                            {
                                text6 += text2[9];
                                text6 += text2[10];
                                text6 += text2[11];
                                text6 += text2[12];
                                num3   = (uint)Utilities.Convert_Value_To_Int(text6);
                                num3 <<= 16;
                            }
                            else
                            {
                                num5 += num3;
                                if ((num5 / 2u > num2 || num5 / 2u < num) && !flag)
                                {
                                    flag = true;
                                }
                                if (flag)
                                {
                                    p_num_blocks++;
                                    flag = false;
                                    if (!BL16.Calculate_Device_Starting_Block_Addr(num5, ref num, ref num2))
                                    {
                                        streamReader.Close();
                                        p_err_code = 1;
                                        bool result2 = false;
                                        return(result2);
                                    }
                                }
                                for (int i = 0; i < 2 * num4; i += 2)
                                {
                                    string text7 = "0x";
                                    text7 += text2[9 + i];
                                    text7 += text2[10 + i];
                                    if (num > num5 / 2u)
                                    {
                                        streamReader.Close();
                                        p_err_code = 1;
                                        bool result2 = false;
                                        return(result2);
                                    }
                                }
                            }
                        }
                    }
                    streamReader.Close();
                    return(result);
                }
                catch (Exception)
                {
                    p_err_code = 2;
                    result     = false;
                    return(result);
                }
            }
            result     = false;
            p_err_code = 2;
            return(result);
        }