public static bool FilterCommandsToUbiquitiRadio(ref string command)
    {
        //       byte[] msgData = utilHexToBin(text.TrimEnd('\r', '\n', ' '));
        byte[] msgData = utilHexToBin(command);

        switch (msgData[0])
        {
        case (byte)RadioCommands.SET_DATE:                                          //pick date and convert it to the RTC format

            WindowsFormsApplication1.Form2 customForm = new WindowsFormsApplication1.Form2();
            customForm.dateTimePicker1.Format     = DateTimePickerFormat.Long;
            customForm.dateTimePicker1.ShowUpDown = false;
            var fr = customForm.ShowDialog();

            if (DialogResult.Cancel == fr)                                          //data pick was canceled
            {
                customForm.Dispose();
                return(false);
            }
            else
            {
                if (DayOfWeek.Sunday == customForm.dateTimePicker1.Value.DayOfWeek)
                {
                    command = " " + ByteTohexString((byte)RtcDayOfWeek.sun);
                }
                else
                {
                    command = " " + ByteTohexString((byte)customForm.dateTimePicker1.Value.DayOfWeek);
                }
                command += " " + ByteTohexString((byte)customForm.dateTimePicker1.Value.Day);
                command += " " + ByteTohexString((byte)(((customForm.dateTimePicker1.Value.Month / 10) << 4) + customForm.dateTimePicker1.Value.Month % 10));
                command += " " + ByteTohexString((byte)((((customForm.dateTimePicker1.Value.Year - 2000) / 10) << 4) + (customForm.dateTimePicker1.Value.Year - 2000) % 10));
            }

            customForm.Dispose();
            return(true);

        case (byte)RadioCommands.SET_TIME:                                          //pick time and convert it to the RTC format

            WindowsFormsApplication1.Form2 customForm2 = new WindowsFormsApplication1.Form2();
            customForm2.dateTimePicker1.Format     = DateTimePickerFormat.Time;
            customForm2.dateTimePicker1.ShowUpDown = true;
            var fr2 = customForm2.ShowDialog();

            if (DialogResult.Cancel == fr2)                                          //time pick was canceled
            {
                customForm2.Dispose();
                return(false);
            }
            else
            {
                command  = " " + ByteTohexString((byte)(((customForm2.dateTimePicker1.Value.Hour / 10) << 4) + customForm2.dateTimePicker1.Value.Hour % 10));
                command += " " + ByteTohexString((byte)(((customForm2.dateTimePicker1.Value.Minute / 10) << 4) + customForm2.dateTimePicker1.Value.Minute % 10));
                command += " " + ByteTohexString((byte)(((customForm2.dateTimePicker1.Value.Second / 10) << 4) + customForm2.dateTimePicker1.Value.Second % 10));
            }

            customForm2.Dispose();
            return(true);

        case (byte)RadioCommands.SET_ALARM:                                          //pick time and convert it to the RTC format

            WindowsFormsApplication1.Alarm customForm3 = new WindowsFormsApplication1.Alarm();
            var fr3 = customForm3.ShowDialog();

            if (DialogResult.Cancel == fr3)                                          //time pick was canceled
            {
                customForm3.Dispose();
                return(false);
            }
            else
            {
                command  = " " + ByteTohexString((byte)(((customForm3.dateTimePickerTime.Value.Hour / 10) << 4) + customForm3.dateTimePickerTime.Value.Hour % 10));
                command += " " + ByteTohexString((byte)(((customForm3.dateTimePickerTime.Value.Minute / 10) << 4) + customForm3.dateTimePickerTime.Value.Minute % 10));
                command += " " + ByteTohexString((byte)(((customForm3.dateTimePickerTime.Value.Second / 10) << 4) + customForm3.dateTimePickerTime.Value.Second % 10));

                command += " " + ByteTohexString((byte)(customForm3.dateTimePickerDate.Value.Day));
                if (customForm3.checkBoxEveryDay.Checked)
                {
                    command += " 80";
                }
                else
                {
                    command += " 00";
                }
                if (customForm3.checkBoxEveryDay.Checked)
                {
                    command += " 80";
                }
                else
                {
                    command += " 00";
                }
                if (customForm3.checkBoxEveryDay.Checked)
                {
                    command += " 80";
                }
                else
                {
                    command += " 00";
                }
                if (customForm3.checkBoxEveryDay.Checked)
                {
                    command += " 80";
                }
                else
                {
                    command += " 00";
                }
            }

            customForm3.Dispose();
            return(true);

        default:
            break;
        }

        return(false);
    }
Exemple #2
0
 private void button7_Click(object sender, EventArgs e)
 {
     a = new Alarm(con);
     a.ShowDialog();
 }