Example #1
0
        public void Write(MainWindow mainForm, uint user_number)
        {
            byte[] byte_array = new byte[240]; // verificar este tamanho
            user_number = user_number - 1;
            string description = "";

            try
            {
                description = ((string)mainForm.databaseDataSet.User.Rows[(int)(user_number)]["Description"]).ToUpper();
            }
            catch
            {
            }

            #region User options read from dataset
            ////USER OPTIONS
            Int32 user_options = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can arm away"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_arm_away"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can arm stay"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_arm_stay"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can disarm away"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_disarm_away"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can disarm stay"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_disarm_stay"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Security guard code"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["security_guard_code"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can divert"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_divert"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can view event memory"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_view_events"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["User active"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["user_active"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can change own code"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_change_own_code"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can change all codes"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_change_all_codes"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Allow installer mode"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["allow_installer_mode"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can change phone numbers"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_change_phone_numbers"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Can change clock"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["can_change_clock"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Allow DTMF codes"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["allow_dtmf_codes"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Check timezones"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["check_timezones"])[0]));
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Check date"].Equals(true))
            {
                user_options += (int)(0xFFFFFFFF & (((int[])this.attributes["options"]["check_date"])[0]));
            }
            #endregion

            ulong user_code = ulong.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["UserCode"].ToString());

            short user_type    = (short)((int)mainForm.databaseDataSet.User.Rows[(int)(user_number)]["User type"]);
            short group_id     = (short)((int)mainForm.databaseDataSet.User.Rows[(int)(user_number)]["Group Id"]);
            short partition_id = 0;
            #region USER PARTITIONS FLAGS
            //User partitions
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 1"].Equals(true))
            {
                partition_id += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 2"].Equals(true))
            {
                partition_id += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 3"].Equals(true))
            {
                partition_id += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 4"].Equals(true))
            {
                partition_id += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 5"].Equals(true))
            {
                partition_id += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 6"].Equals(true))
            {
                partition_id += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 7"].Equals(true))
            {
                partition_id += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Area 8"].Equals(true))
            {
                partition_id += 0x80;
            }
            #endregion
            short reserved = (short)((int)mainForm.databaseDataSet.User.Rows[(int)(user_number)]["Reserved"]);

            #region USER TIMEZONES FLAGS
            short timezones_while_active = 0;
            ///TIMEZONE while active
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 1 while active"].Equals(true))
            {
                timezones_while_active += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 2 while active"].Equals(true))
            {
                timezones_while_active += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 3 while active"].Equals(true))
            {
                timezones_while_active += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 4 while active"].Equals(true))
            {
                timezones_while_active += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 5 while active"].Equals(true))
            {
                timezones_while_active += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 6 while active"].Equals(true))
            {
                timezones_while_active += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 7 while active"].Equals(true))
            {
                timezones_while_active += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 8 while active"].Equals(true))
            {
                timezones_while_active += 0x80;
            }
            ///TIMEZONE while inactive
            short timezones_while_inactive = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 1 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 2 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 3 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 4 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 5 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 6 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 7 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Timezone 8 while inactive"].Equals(true))
            {
                timezones_while_inactive += 0x80;
            }
            #endregion
            DateTime initial_date = (DateTime)(mainForm.databaseDataSet.User.Rows[(int)(user_number)]["Initial date"]);
            DateTime final_date   = (DateTime)(mainForm.databaseDataSet.User.Rows[(int)(user_number)]["Final date"]);

            #region USER BUTTONS CONFIGURATION
            #region PARTITIONS AWAY
            //BUTTON A
            byte user_button_a_part_away = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 1"].Equals(true))
            {
                user_button_a_part_away += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 2"].Equals(true))
            {
                user_button_a_part_away += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 3"].Equals(true))
            {
                user_button_a_part_away += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 4"].Equals(true))
            {
                user_button_a_part_away += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 5"].Equals(true))
            {
                user_button_a_part_away += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 6"].Equals(true))
            {
                user_button_a_part_away += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 7"].Equals(true))
            {
                user_button_a_part_away += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part away 8"].Equals(true))
            {
                user_button_a_part_away += 0x80;
            }

            //BUTTON B
            byte user_button_b_part_away = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 1"].Equals(true))
            {
                user_button_b_part_away += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 2"].Equals(true))
            {
                user_button_b_part_away += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 3"].Equals(true))
            {
                user_button_b_part_away += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 4"].Equals(true))
            {
                user_button_b_part_away += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 5"].Equals(true))
            {
                user_button_b_part_away += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 6"].Equals(true))
            {
                user_button_b_part_away += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 7"].Equals(true))
            {
                user_button_b_part_away += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part away 8"].Equals(true))
            {
                user_button_b_part_away += 0x80;
            }

            //BUTTON C
            byte user_button_c_part_away = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 1"].Equals(true))
            {
                user_button_c_part_away += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 2"].Equals(true))
            {
                user_button_c_part_away += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 3"].Equals(true))
            {
                user_button_c_part_away += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 4"].Equals(true))
            {
                user_button_c_part_away += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 5"].Equals(true))
            {
                user_button_c_part_away += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 6"].Equals(true))
            {
                user_button_c_part_away += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 7"].Equals(true))
            {
                user_button_c_part_away += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part away 8"].Equals(true))
            {
                user_button_c_part_away += 0x80;
            }

            //BUTTON D
            byte user_button_d_part_away = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 1"].Equals(true))
            {
                user_button_d_part_away += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 2"].Equals(true))
            {
                user_button_d_part_away += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 3"].Equals(true))
            {
                user_button_d_part_away += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 4"].Equals(true))
            {
                user_button_d_part_away += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 5"].Equals(true))
            {
                user_button_d_part_away += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 6"].Equals(true))
            {
                user_button_d_part_away += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 7"].Equals(true))
            {
                user_button_d_part_away += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part away 8"].Equals(true))
            {
                user_button_d_part_away += 0x80;
            }
            #endregion
            #region PARTITIONS STAY
            //BUTTON A
            byte user_button_a_part_stay = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 1"].Equals(true))
            {
                user_button_a_part_stay += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 2"].Equals(true))
            {
                user_button_a_part_stay += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 3"].Equals(true))
            {
                user_button_a_part_stay += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 4"].Equals(true))
            {
                user_button_a_part_stay += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 5"].Equals(true))
            {
                user_button_a_part_stay += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 6"].Equals(true))
            {
                user_button_a_part_stay += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 7"].Equals(true))
            {
                user_button_a_part_stay += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button A part stay 8"].Equals(true))
            {
                user_button_a_part_stay += 0x80;
            }

            //BUTTON B
            byte user_button_b_part_stay = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 1"].Equals(true))
            {
                user_button_b_part_stay += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 2"].Equals(true))
            {
                user_button_b_part_stay += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 3"].Equals(true))
            {
                user_button_b_part_stay += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 4"].Equals(true))
            {
                user_button_b_part_stay += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 5"].Equals(true))
            {
                user_button_b_part_stay += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 6"].Equals(true))
            {
                user_button_b_part_stay += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 7"].Equals(true))
            {
                user_button_b_part_stay += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button B part stay 8"].Equals(true))
            {
                user_button_b_part_stay += 0x80;
            }

            //BUTTON C
            byte user_button_c_part_stay = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 1"].Equals(true))
            {
                user_button_c_part_stay += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 2"].Equals(true))
            {
                user_button_c_part_stay += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 3"].Equals(true))
            {
                user_button_c_part_stay += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 4"].Equals(true))
            {
                user_button_c_part_stay += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 5"].Equals(true))
            {
                user_button_c_part_stay += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 6"].Equals(true))
            {
                user_button_c_part_stay += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 7"].Equals(true))
            {
                user_button_c_part_stay += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button C part stay 8"].Equals(true))
            {
                user_button_c_part_stay += 0x80;
            }

            //BUTTON D
            byte user_button_d_part_stay = 0;
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 1"].Equals(true))
            {
                user_button_d_part_stay += 0x01;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 2"].Equals(true))
            {
                user_button_d_part_stay += 0x02;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 3"].Equals(true))
            {
                user_button_d_part_stay += 0x04;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 4"].Equals(true))
            {
                user_button_d_part_stay += 0x08;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 5"].Equals(true))
            {
                user_button_d_part_stay += 0x10;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 6"].Equals(true))
            {
                user_button_d_part_stay += 0x20;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 7"].Equals(true))
            {
                user_button_d_part_stay += 0x40;
            }
            if (mainForm.databaseDataSet.User.Rows[(int)user_number]["Button D part stay 8"].Equals(true))
            {
                user_button_d_part_stay += 0x80;
            }
            #endregion
            #endregion
            byte[] buttons_part_away_bytes = new byte[5];
            buttons_part_away_bytes[0] = user_button_a_part_away;
            buttons_part_away_bytes[1] = user_button_b_part_away;
            buttons_part_away_bytes[2] = user_button_c_part_away;
            buttons_part_away_bytes[3] = user_button_d_part_away;
            byte[] buttons_part_stay_bytes = new byte[5];
            buttons_part_stay_bytes[0] = user_button_a_part_stay;
            buttons_part_stay_bytes[1] = user_button_b_part_stay;
            buttons_part_stay_bytes[2] = user_button_c_part_stay;
            buttons_part_stay_bytes[3] = user_button_d_part_stay;


            #region AUDIO TRACKS
            byte[] audio_tracks = new byte[8];
            if (user_number < 32)
            {
                audio_tracks[0] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 1"].ToString()) - 1) & 0xFF);
                audio_tracks[1] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 1"].ToString()) - 1) >> 8);
                audio_tracks[2] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 2"].ToString()) - 1) & 0xFF);
                audio_tracks[3] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 2"].ToString()) - 1) >> 8);
                audio_tracks[4] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 3"].ToString()) - 1) & 0xFF);
                audio_tracks[5] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 3"].ToString()) - 1) >> 8);
                audio_tracks[6] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 4"].ToString()) - 1) & 0xFF);
                audio_tracks[7] = (byte)((int.Parse(mainForm.databaseDataSet.User.Rows[(int)user_number]["Audio track 4"].ToString()) - 1) >> 8);
            }
            #endregion

            #region Output permissions
            long outputs_permissions = 0;
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output1Permissions"]).Equals(true))
            {
                outputs_permissions += 0x01;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output2Permissions"]).Equals(true))
            {
                outputs_permissions += 0x02;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output3Permissions"]).Equals(true))
            {
                outputs_permissions += 0x04;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output4Permissions"]).Equals(true))
            {
                outputs_permissions += 0x08;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output5Permissions"]).Equals(true))
            {
                outputs_permissions += 0x10;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output6Permissions"]).Equals(true))
            {
                outputs_permissions += 0x20;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output7Permissions"]).Equals(true))
            {
                outputs_permissions += 0x40;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output8Permissions"]).Equals(true))
            {
                outputs_permissions += 0x80;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output9Permissions"]).Equals(true))
            {
                outputs_permissions += 0x100;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output10Permissions"]).Equals(true))
            {
                outputs_permissions += 0x200;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output11Permissions"]).Equals(true))
            {
                outputs_permissions += 0x400;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output12Permissions"]).Equals(true))
            {
                outputs_permissions += 0x800;
            }
            if (Convert.ToBoolean(mainForm.databaseDataSet.User.Rows[(int)user_number]["Output13Permissions"]).Equals(true))
            {
                outputs_permissions += 0x1000;
            }
            #endregion

            byte[] user_code_bytes = GetIntArray(user_code);

            byte[] description_bytes = new byte[64];
            description_bytes = Encoding.GetEncoding("UTF-8").GetBytes(description);
            byte[] user_options_bytes                  = BitConverter.GetBytes(user_options);
            byte[] user_type_bytes                     = BitConverter.GetBytes(user_type);
            byte[] user_group_id_bytes                 = BitConverter.GetBytes(group_id);
            byte[] user_partitions_bytes               = BitConverter.GetBytes(partition_id);
            byte[] user_reserved_bytes                 = BitConverter.GetBytes(reserved);
            byte[] user_timezones_while_active_bytes   = BitConverter.GetBytes(timezones_while_active);
            byte[] user_timezones_while_inactive_bytes = BitConverter.GetBytes(timezones_while_inactive);
            byte[] initial_date_bytes                  = new byte[4];
            initial_date_bytes[0] = (byte)(initial_date.Day);
            initial_date_bytes[1] = (byte)(initial_date.Month);
            initial_date_bytes[2] = (BitConverter.GetBytes(initial_date.Year))[0];
            initial_date_bytes[3] = (BitConverter.GetBytes(initial_date.Year))[1];
            byte[] final_date_bytes = new byte[4];
            final_date_bytes[0] = (byte)(final_date.Day);
            final_date_bytes[1] = (byte)(final_date.Month);
            final_date_bytes[2] = (BitConverter.GetBytes(final_date.Year))[0];
            final_date_bytes[3] = (BitConverter.GetBytes(final_date.Year))[1];

            byte[] outputs_permissions_bytes = BitConverter.GetBytes(outputs_permissions);

            int  i            = 0;
            uint j            = 0;
            uint user_address = 0x45000 + (256 * (user_number));
            byte_array[i++] = 0x40;
            byte_array[i++] = (byte)((user_address >> 16) & 0xFF);
            byte_array[i++] = (byte)((user_address >> 8) & 0xFF);
            byte_array[i++] = (byte)(user_address & 0xFF);

            byte_array[i++] = 240;
            int temp = i;
            //TODO: Create a function for this for

            //Description
            for (i = temp, j = 0; i < (temp + description_bytes.Length); i++, j++)
            {
                byte_array[i] = description_bytes[j];
                if ((description_bytes.Length - 1) == (j))
                {
                    for (i = i + 1; i < (64 + temp); i++)
                    {
                        byte_array[i] = 0;
                    }
                }
            }
            //Options
            for (i = (temp + (int)this.attributes["options"]["address"]), j = 0; i < (temp + (int)this.attributes["options"]["address"] + user_options_bytes.Length); i++, j++)
            {
                byte_array[i] = user_options_bytes[j];
            }

            //user code
            for (i = (int)this.attributes["user_code"]["address"] + temp, j = 0; i < ((int)this.attributes["user_code"]["address"] + temp + user_code_bytes.Length); i++, j++)
            {
                byte_array[i] = 0xFF;
                byte_array[i] = (byte)(user_code_bytes[j]);

                //Add 0xFF if code doesn't have maximum length
                if (i.Equals(((int)this.attributes["user_code"]["address"] + temp + (user_code_bytes.Length - 1))) && user_code_bytes.Length < 8)
                {
                    int counter = 8 - user_code_bytes.Length;
                    for (int k = counter; k > 0; k--)
                    {
                        byte_array[i + k] = 0xFF;
                    }
                }
            }

            //user type
            for (i = (temp + (int)this.attributes["user_type"]["address"]), j = 0; i < (temp + (int)this.attributes["user_type"]["address"] + user_type_bytes.Length); i++, j++)
            {
                byte_array[i] = user_type_bytes[j];
            }
            //group_id
            for (i = (temp + (int)this.attributes["group_id"]["address"]), j = 0; i < (temp + (int)this.attributes["group_id"]["address"] + user_group_id_bytes.Length); i++, j++)
            {
                byte_array[i] = user_group_id_bytes[j];
            }
            //partition_id
            for (i = (temp + (int)this.attributes["partition_id"]["address"]), j = 0; i < (temp + (int)this.attributes["partition_id"]["address"] + user_partitions_bytes.Length); i++, j++)
            {
                byte_array[i] = user_partitions_bytes[j];
            }
            //reserved
            for (i = (temp + (int)this.attributes["reserved"]["address"]), j = 0; i < (temp + (int)this.attributes["reserved"]["address"] + user_reserved_bytes.Length); i++, j++)
            {
                byte_array[i] = user_reserved_bytes[j];
            }
            ////initial_date
            for (i = (temp + (int)this.attributes["initial_date"]["address"]), j = 0; i < (temp + (int)this.attributes["initial_date"]["address"] + initial_date_bytes.Length); i++, j++)
            {
                byte_array[i] = initial_date_bytes[j];
            }
            //final date
            for (i = (temp + (int)this.attributes["final_date"]["address"]), j = 0; i < (temp + (int)this.attributes["final_date"]["address"] + final_date_bytes.Length); i++, j++)
            {
                byte_array[i] = final_date_bytes[j];
            }
            //timezones while active
            for (i = (temp + (int)this.attributes["timezones_while_active"]["address"]), j = 0; i < (temp + (int)this.attributes["timezones_while_active"]["address"] + user_timezones_while_active_bytes.Length); i++, j++)
            {
                byte_array[i] = user_timezones_while_active_bytes[j];
            }
            //timezones while inactive
            for (i = (temp + (int)this.attributes["timezones_while_inactive"]["address"]), j = 0; i < (temp + (int)this.attributes["timezones_while_inactive"]["address"] + user_timezones_while_inactive_bytes.Length); i++, j++)
            {
                byte_array[i] = user_timezones_while_inactive_bytes[j];
            }

            #region Button config
            //AWAY
            for (i = (temp + (int)this.attributes["particoes_bot_away"]["address"]), j = 0; i < (temp + (int)this.attributes["particoes_bot_away"]["address"] + buttons_part_away_bytes.Length); i++, j++)
            {
                byte_array[i] = buttons_part_away_bytes[j];
            }
            //STAY
            for (i = (temp + (int)this.attributes["particoes_bot_stay"]["address"]), j = 0; i < (temp + (int)this.attributes["particoes_bot_stay"]["address"] + buttons_part_stay_bytes.Length); i++, j++)
            {
                byte_array[i] = buttons_part_stay_bytes[j];
            }
            #endregion

            #region Audio tracks
            for (i = ((int)attributes["audio_tracks"]["address"] + temp), j = 0; i < ((int)attributes["audio_tracks"]["address"] + temp + (audio_tracks.Length)); i++, j++)
            {
                byte_array[i] = audio_tracks[j];
            }
            #endregion

            #region Outputs permissions
            for (i = ((int)attributes["outputs_permissions"]["address"] + temp), j = 0; i < ((int)attributes["outputs_permissions"]["address"] + temp + (outputs_permissions_bytes.Length)); i++, j++)
            {
                byte_array[i] = outputs_permissions_bytes[j];
            }
            #endregion

            byte_array[4] = (byte)(i - temp);
            General protocol = new General();
            protocol.send_msg((uint)(i), byte_array, mainForm.cp_id, mainForm);
        }
Example #2
0
        public void Write(MainWindow mainWindow, uint phone_number)
        {
            byte[] byte_array = new byte[240]; // verificar este tamanho
            phone_number = phone_number - 1;
            string description = ((string)mainWindow.databaseDataSet.Phone.Rows[(int)(phone_number)]["Description"]).ToUpper();

            byte[] description_bytes = new byte[64];
            description_bytes = Encoding.GetEncoding("UTF-8").GetBytes(description);

            //phone number
            ulong phone_dial_number = ulong.Parse(mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Phone number"].ToString());

            //prefix
            ulong phone_prefix = ulong.Parse(mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Prefix"].ToString());

            //Max Communication attempts
            byte com_attempts = byte.Parse(mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Communication attempts"].ToString());

            //communication protocol
            byte[] com_protocol = (byte[])mainWindow.databaseDataSet.Phone.Rows[(int)(phone_number)]["Communication protocol"];

            #region PARTITIONS
            short partition_id = 0;
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 1"].Equals(true))
            {
                partition_id += 0x01;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 2"].Equals(true))
            {
                partition_id += 0x02;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 3"].Equals(true))
            {
                partition_id += 0x04;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 4"].Equals(true))
            {
                partition_id += 0x08;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 5"].Equals(true))
            {
                partition_id += 0x10;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 6"].Equals(true))
            {
                partition_id += 0x20;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 7"].Equals(true))
            {
                partition_id += 0x40;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Area 8"].Equals(true))
            {
                partition_id += 0x80;
            }
            #endregion

            #region RESERVED
            byte[] reserved_1_bytes = (byte[])mainWindow.databaseDataSet.Phone.Rows[(int)(phone_number)]["Reserved 1"];
            byte[] reserved_2_bytes = (byte[])mainWindow.databaseDataSet.Phone.Rows[(int)(phone_number)]["Reserved 2"];
            #endregion

            #region Phone options read from dataset
            ////Phone OPTIONS
            ulong phone_options = 0;
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Stop dialling if kissed off voice"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_STOP_DIALLING_IF_KISSED_OFF_VOICE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Stop dialling if kissed off CID"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_STOP_DIALLING_IF_KISSED_OFF_CID"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Always report"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_ALLWAYS_REPORT"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Monitor call progress"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_MONITOR_CALL_PROGRESS"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Blind dial"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_BLIND_DIAL"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Stay on line after report 2 way voice"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_STAY_ON_LINE_ATFER_REPORT_2WAY_VOICE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Use prefix"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_USE_DIALLING_PREFIX"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Call back number"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_CALL_BACK_NUMBER"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report 230V fail"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_MAINS_FUSE_FAILURE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report battery low"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_BATTERY_LOW"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report radio battery low"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_RADIO_BATTERY_LOW"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report line fail"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_LINE_FAIL"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report system tamper"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_SYSTEM_TAMPER"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report keypad tamper"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_KEYPAD_TAMPER"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report zone tamper"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_ZONE_TAMPER"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report radio zone tamper"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_RADIO_ZONE_TAMPER"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report duress alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_DURESS_ALARM"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report supervised radio alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_SUPERVISED_RADIO_ALARM"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report sensor watch alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_SENSOR_WATCH_ALARM"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report manual panic alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_MANUAL_PANIC_ALARM"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report manual fire alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_MANUAL_FIRE_ALARM"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report manual medical alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_MANUAL_MEDICAL_ALARM"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report manual pedant panic alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_MANUAL_PEDANT_PANIC_ALARM"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report zone bypass"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_ZONE_BYPASS"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report arm/disarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_ARM_DISARM"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report stay mode arm/disarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_STAY_MODE_ARM_DISARM"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report disarm only after activation"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_DISARM_ONLY_AFTER_ACTIVATION"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report stay mode disarm only after activation"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_STAY_MODE_DISARM_ONLY_AFTER_ACTIVATION"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report stay mode zone alarm"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_STAY_MODE_ZONE_ALARM"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report access to program mode"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_ACCESS_TO_PROGRAM_MODE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report access to installer mode"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_ACCESS_TO_INSTALLER_MODE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report 24h alarms when set domestic voice"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_24HOUR_ALARMS_WHEN_SET_DOMESCTIC_VOICE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report Zones restore"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_ZONES_RESTORES"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report latch keys"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_LATCH_KEYS"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report delinquent"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_DELINQUENT"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report tests"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_TESTS"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report fuse failure"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_FUSE_FAILURE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report outputs failure"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_OUTPUTS_FAIL"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report date/hour change"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_RTC_TIME_CHANGE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report keypad communication problems"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_KEYPAD_BUS_TROUBLE"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report RF problems detected"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_RF_INTERFERENCE_DETECTED"])[0]));
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report system problems"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_SYSTEM_PROBLEMS"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Test call"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELF_REP_TEST_CALL"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Voice call"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELT_REP_CHAMADA_VOZ"])[0]));
            }

            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Report on"].Equals(true))
            {
                phone_options += (ulong)(0xFFFFFFFFFFFFFFFF & (((ulong[])this.attributes["options"]["KP_TELT_REP_ATIVO"])[0]));
            }
            #endregion

            //Hour test
            DateTime test_hour = Convert.ToDateTime(mainWindow.databaseDataSet.Phone.Rows[(int)(phone_number)]["Test hour"].ToString());
            byte     hour_test = (byte)test_hour.Hour;
            //minute test
            byte minute_test = (byte)test_hour.Minute;


            //WEEK DAYS
            byte week_days = 0;
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Monday"].Equals(true))
            {
                week_days += 0x01;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Tuesday"].Equals(true))
            {
                week_days += 0x02;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Wednesday"].Equals(true))
            {
                week_days += 0x04;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Thursday"].Equals(true))
            {
                week_days += 0x08;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Friday"].Equals(true))
            {
                week_days += 0x10;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Saturday"].Equals(true))
            {
                week_days += 0x20;
            }
            if (mainWindow.databaseDataSet.Phone.Rows[(int)phone_number]["Sunday"].Equals(true))
            {
                week_days += 0x40;
            }


            byte[] phone_number_bytes     = GetIntArray(phone_dial_number);
            byte[] phone_prefix_bytes     = GetIntArray(phone_prefix);
            byte[] phone_partitions_bytes = BitConverter.GetBytes(partition_id);
            byte[] phone_options_bytes    = BitConverter.GetBytes(phone_options);

            int  i            = 0;
            uint j            = 0;
            uint user_address = 0x6A000 + (256 * (phone_number));
            byte_array[i++] = 0x40;
            byte_array[i++] = (byte)((user_address >> 16) & 0xFF);
            byte_array[i++] = (byte)((user_address >> 8) & 0xFF);
            byte_array[i++] = (byte)(user_address & 0xFF);
            byte_array[i++] = 240;
            int temp = i;

            //Description
            for (i = temp, j = 0; i < (temp + description_bytes.Length); i++, j++)
            {
                byte_array[i] = description_bytes[j];
                if ((description_bytes.Length - 1) == (j))
                {
                    for (i = i + 1; i < (64 + temp); i++)
                    {
                        byte_array[i] = 0;
                    }
                }
            }

            //phone number
            for (i = (int)attributes["phone_number"]["address"] + temp, j = 0; i < ((int)attributes["phone_number"]["address"] + temp + phone_number_bytes.Length); i++, j++)
            {
                byte_array[i] = (byte)phone_number_bytes[j];
                if (phone_number_bytes.Length < 16 && i == ((int)attributes["phone_number"]["address"] + temp + phone_number_bytes.Length - 1))
                {
                    byte_array[i + 1] = 0xFF;
                }
            }

            //phone prefix
            if (phone_prefix_bytes.Length == 0)
            {
                phone_prefix_bytes = new byte [] { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
                for (i = (int)attributes["prefix"]["address"] + temp, j = 0; i < ((int)attributes["prefix"]["address"] + temp + phone_prefix_bytes.Length); i++, j++)
                {
                    byte_array[i] = (byte)phone_prefix_bytes[j];
                }
            }
            else
            {
                for (i = (int)attributes["prefix"]["address"] + temp, j = 0; i < ((int)attributes["prefix"]["address"] + temp + phone_prefix_bytes.Length); i++, j++)
                {
                    byte_array[i] = (byte)phone_prefix_bytes[j];
                    if (phone_prefix_bytes.Length < 6 && i == ((int)attributes["prefix"]["address"] + temp + phone_prefix_bytes.Length - 1))
                    {
                        byte_array[i + 1] = 0xFF;
                    }
                }
            }



            // max com attempts
            i             = (temp + (int)this.attributes["max_com_attempts"]["address"]);
            byte_array[i] = com_attempts;
            i++;

            //Com protocol
            for (i = (temp + (int)this.attributes["com_protocol"]["address"]), j = 0; i < (temp + (int)this.attributes["com_protocol"]["address"] + com_protocol.Length); i++, j++)
            {
                byte_array[i] = com_protocol[j];
            }

            //partitions
            for (i = (temp + (int)this.attributes["partition_id"]["address"]), j = 0; i < (temp + (int)this.attributes["partition_id"]["address"] + phone_partitions_bytes.Length); i++, j++)
            {
                byte_array[i] = phone_partitions_bytes[j];
            }

            //Reserved 1
            for (i = (temp + (int)this.attributes["reserved_1"]["address"]), j = 0; i < (temp + (int)this.attributes["reserved_1"]["address"] + reserved_1_bytes.Length); i++, j++)
            {
                byte_array[i] = reserved_1_bytes[j];
            }

            //Reserved 2
            for (i = (temp + (int)this.attributes["reserved_2"]["address"]), j = 0; i < (temp + (int)this.attributes["reserved_2"]["address"] + reserved_2_bytes.Length); i++, j++)
            {
                byte_array[i] = reserved_2_bytes[j];
            }

            //options
            for (i = (temp + (int)this.attributes["options"]["address"]), j = 0; i < (temp + (int)this.attributes["options"]["address"] + phone_options_bytes.Length); i++, j++)
            {
                byte_array[i] = phone_options_bytes[j];
            }

            //hour test
            i             = (temp + (int)this.attributes["hour_test"]["address"]);
            byte_array[i] = hour_test;
            i++;

            //minute test
            i             = (temp + (int)this.attributes["minute_test"]["address"]);
            byte_array[i] = minute_test;
            i++;

            //Week days
            i             = (temp + (int)this.attributes["week_days"]["address"]);
            byte_array[i] = week_days;
            i++;

            byte_array[4] = (byte)(i - temp);
            General protocol = new General();
            protocol.send_msg((uint)(i), byte_array, mainWindow.cp_id, mainWindow);
        }
Example #3
0
        public void Write(MainWindow mainWindow, uint timezone_number)
        {
            byte[] byte_array = new byte[240]; // verificar este tamanho
            timezone_number = timezone_number - 1;
            string description = ((string)mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Description"]).ToUpper();

            byte[] description_bytes = new byte[64];
            description_bytes = Encoding.GetEncoding("UTF-8").GetBytes(description);

            //Initial hour
            DateTime initial_hour_date_time = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Initial hour"].ToString());
            byte     initial_hour           = (byte)initial_hour_date_time.Hour;
            //Initial minute
            byte initial_minute = (byte)initial_hour_date_time.Minute;
            //Final hour
            DateTime final_hour_date_time = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Final hour"].ToString());
            byte     final_hour           = (byte)final_hour_date_time.Hour;
            //Final minute
            byte final_minute = (byte)final_hour_date_time.Minute;

            //WEEK DAYS
            byte week_days = 0;

            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Monday"].Equals(true))
            {
                week_days += 0x01;
            }
            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Tuesday"].Equals(true))
            {
                week_days += 0x02;
            }
            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Wednesday"].Equals(true))
            {
                week_days += 0x04;
            }
            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Thursday"].Equals(true))
            {
                week_days += 0x08;
            }
            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Friday"].Equals(true))
            {
                week_days += 0x10;
            }
            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Saturday"].Equals(true))
            {
                week_days += 0x20;
            }
            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Sunday"].Equals(true))
            {
                week_days += 0x40;
            }

            //excluded_days
            byte excluded_days = 0;

            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Exception 1"].Equals(true))
            {
                excluded_days += 0x01;
            }

            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Exception 2"].Equals(true))
            {
                excluded_days += 0x02;
            }

            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Exception 3"].Equals(true))
            {
                excluded_days += 0x04;
            }

            if (mainWindow.databaseDataSet.Timezone.Rows[(int)timezone_number]["Exception 4"].Equals(true))
            {
                excluded_days += 0x08;
            }

            //reserved
            byte[] timezone_reserved = (byte[])mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Reserved"];

            //Excluded initial date
            //1
            DateTime excluded_initial_date_1 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 1 initial date"].ToString());
            //2
            DateTime excluded_initial_date_2 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 2 initial date"].ToString());
            //3
            DateTime excluded_initial_date_3 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 3 initial date"].ToString());
            //4
            DateTime excluded_initial_date_4 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 4 initial date"].ToString());

            byte[] excluded_initial_month = (byte[])attributes["excluded_initial_month"]["value"];
            excluded_initial_month[0] = (byte)excluded_initial_date_1.Month;
            excluded_initial_month[1] = (byte)excluded_initial_date_2.Month;
            excluded_initial_month[2] = (byte)excluded_initial_date_3.Month;
            excluded_initial_month[3] = (byte)excluded_initial_date_4.Month;

            byte[] excluded_initial_day = (byte[])attributes["excluded_initial_day"]["value"];
            excluded_initial_day[0] = (byte)excluded_initial_date_1.Day;
            excluded_initial_day[1] = (byte)excluded_initial_date_2.Day;
            excluded_initial_day[2] = (byte)excluded_initial_date_3.Day;
            excluded_initial_day[3] = (byte)excluded_initial_date_4.Day;

            //Excluded final date
            //1
            DateTime excluded_final_date_1 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 1 final date"].ToString());
            //2
            DateTime excluded_final_date_2 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 2 final date"].ToString());
            //3
            DateTime excluded_final_date_3 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 3 final date"].ToString());
            //4
            DateTime excluded_final_date_4 = Convert.ToDateTime(mainWindow.databaseDataSet.Timezone.Rows[(int)(timezone_number)]["Exception 4 final date"].ToString());

            byte[] excluded_final_month = (byte[])attributes["excluded_final_month"]["value"];
            excluded_final_month[0] = (byte)excluded_final_date_1.Month;
            excluded_final_month[1] = (byte)excluded_final_date_2.Month;
            excluded_final_month[2] = (byte)excluded_final_date_3.Month;
            excluded_final_month[3] = (byte)excluded_final_date_4.Month;

            byte[] excluded_final_day = (byte[])attributes["excluded_final_day"]["value"];
            excluded_final_day[0] = (byte)excluded_final_date_1.Day;
            excluded_final_day[1] = (byte)excluded_final_date_2.Day;
            excluded_final_day[2] = (byte)excluded_final_date_3.Day;
            excluded_final_day[3] = (byte)excluded_final_date_4.Day;



            int  i            = 0;
            uint j            = 0;
            uint user_address = 0x65000 + (512 * (timezone_number));

            byte_array[i++] = 0x40;
            byte_array[i++] = (byte)((user_address >> 16) & 0xFF);
            byte_array[i++] = (byte)((user_address >> 8) & 0xFF);
            byte_array[i++] = (byte)(user_address & 0xFF);
            byte_array[i++] = 240;
            int temp = i;

            //Description
            for (i = temp, j = 0; i < (temp + description_bytes.Length); i++, j++)
            {
                byte_array[i] = description_bytes[j];
                if ((description_bytes.Length - 1) == (j))
                {
                    for (i = i + 1; i < (64 + temp); i++)
                    {
                        byte_array[i] = 0;
                    }
                }
            }

            //initial hour
            i             = (temp + (int)this.attributes["inicial_hour"]["address"]);
            byte_array[i] = initial_hour;
            i++;

            //initial minute
            i             = (temp + (int)this.attributes["inicial_minute"]["address"]);
            byte_array[i] = initial_minute;
            i++;

            //final hour
            i             = (temp + (int)this.attributes["final_hour"]["address"]);
            byte_array[i] = final_hour;
            i++;

            //final minute
            i             = (temp + (int)this.attributes["final_minute"]["address"]);
            byte_array[i] = final_minute;
            i++;

            //Week days
            i             = (temp + (int)this.attributes["week_days"]["address"]);
            byte_array[i] = week_days;
            i++;

            //Excluded days
            i             = (temp + (int)this.attributes["excluded_days"]["address"]);
            byte_array[i] = excluded_days;
            i++;

            //Reserved
            for (i = (temp + (int)this.attributes["reserved"]["address"]), j = 0; i < (temp + (int)this.attributes["reserved"]["address"] + timezone_reserved.Length); i++, j++)
            {
                byte_array[i] = timezone_reserved[j];
            }

            //Excluded initial month
            for (i = (temp + (int)this.attributes["excluded_initial_month"]["address"]), j = 0; i < (temp + (int)this.attributes["excluded_initial_month"]["address"] + excluded_initial_month.Length); i++, j++)
            {
                byte_array[i] = excluded_initial_month[j];
            }
            //Excluded initial day
            for (i = (temp + (int)this.attributes["excluded_initial_day"]["address"]), j = 0; i < (temp + (int)this.attributes["excluded_initial_day"]["address"] + excluded_initial_day.Length); i++, j++)
            {
                byte_array[i] = excluded_initial_day[j];
            }
            //Excluded final month
            for (i = (temp + (int)this.attributes["excluded_final_month"]["address"]), j = 0; i < (temp + (int)this.attributes["excluded_final_month"]["address"] + excluded_final_month.Length); i++, j++)
            {
                byte_array[i] = excluded_final_month[j];
            }
            //Excluded final day
            for (i = (temp + (int)this.attributes["excluded_final_day"]["address"]), j = 0; i < (temp + (int)this.attributes["excluded_final_day"]["address"] + excluded_final_day.Length); i++, j++)
            {
                byte_array[i] = excluded_final_day[j];
            }

            byte_array[4] = (byte)(i - temp);
            General protocol = new General();

            protocol.send_msg((uint)(i), byte_array, mainWindow.cp_id, mainWindow);
        }