Exemplo n.º 1
0
        public static async Task SendAdminMenu()
        {
            if (!await AsyncCamCom.TryConnect().ConfigureAwait(false))
            {
                return;
            }

            AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFB, 0x03 });
            AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFD, 0x05 });
            AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFC, 0x04 });
            AsyncCamCom.SendNonAsync(new byte[] { 0xFF, 0x01, 0x00, 0x07, 0x00, 0xFE, 0x06 });
        }
Exemplo n.º 2
0
        public static async Task QuickCommand(string command, bool sendAsync = true, int manualAdr = -5)
        {
            try {
                if (!await AsyncCamCom.TryConnect().ConfigureAwait(false))
                {
                    MessageBox.Show("Not connected to camera!\nTried sending: " + command);
                    return;
                }

                uint adr = Tools.MakeAdr();

                if (manualAdr != -5) //if sending preset
                {
                    adr = Convert.ToUInt32(manualAdr);
                }

                ScriptCommand send = CheckForCommands(command, adr, false).Result;
                if (send.codeContent == PelcoD.noCommand)
                {
                    if (command.Length == 0)
                    {
                        MessageBox.Show("Command length is 0!\nMake sure to check the command in the settings!");
                        return;
                    }
                    else
                    {
                        byte[] code = Tools.ConvertMsgToByte(command);
                        if (code == null)
                        {
                            MessageBox.Show("Command invalid!\nMake sure to enter command in the correct format!\n(FF 0x xx xx xx xx yy OR [command] [value])");
                            return;
                        }
                        send = new ScriptCommand(new string[] { "custom" }, code, "", 0);
                    }
                }

                if (!sendAsync)
                {
                    AsyncCamCom.SendNonAsync(send.codeContent);
                }
                else
                {
                    var t = Task.Factory.StartNew(() => {
                        AsyncCamCom.SendScriptCommand(send);
                    });
                    Task.WaitAll();
                }
            } catch (Exception e) {
                Tools.ShowPopup("Failed to send quick command!\nShow more?", "Error Occurred!", e.ToString());
            }
        }
Exemplo n.º 3
0
        public async Task ConnectToCamera()
        {
            if (!MainForm.m.finishedLoading)
            {
                return;
            }

            ConfigControl.savedIP.UpdateValue(tB_IPCon_Adr.Text);

            int parsed;

            if (int.TryParse(cB_IPCon_Port.Text, out parsed))
            {
                ConfigControl.savedPort.UpdateValue(parsed.ToString());
            }

            AsyncCamCom.TryConnect(false).ConfigureAwait(false);
        }
Exemplo n.º 4
0
        void PresetLearnGoto(bool learn)
        {
            if (!Tools.CheckIfNameValid(tB_Presets_Number.Text, true) || tB_Presets_Number.Text.ToString() == "")
            {
                MessageBox.Show("Invalid Preset!");
                return;
            }

            byte presetNumber = Convert.ToByte(tB_Presets_Number.Text);

            if (learn)
            {
                AsyncCamCom.SendNewCommand(D.protocol.Preset(Tools.MakeAdr(), presetNumber, D.PresetAction.Set));
            }
            else
            {
                AsyncCamCom.SendNewCommand(D.protocol.Preset(Tools.MakeAdr(), presetNumber, D.PresetAction.Goto));
            }
        }
Exemplo n.º 5
0
        async Task Fire(FireType type)
        {
            try {
                if (type == FireType.IP)
                {
                    if (!await AsyncCamCom.TryConnect(false).ConfigureAwait(false))
                    {
                        if (Tools.ShowPopup("Failed to connect to camera!\nIP: " + ConfigControl.savedIP.stringVal
                                            + "\nPort: " + ConfigControl.savedPort.stringVal + "\nCancel script execution?", "Failed to Connect!", null, false))
                        {
                            b_PD_Fire.Enabled = true;
                            return;
                        }
                    }
                }

                Invoke((MethodInvoker) delegate {
                    b_PD_Fire.Enabled = false;
                    b_PD_Stop.Enabled = true;
                });

                loopAmount = 0;
                loopPos    = -1;
                for (int i = 0; i < tB_Commands.Lines.Length; i++)
                {
                    string l = tB_Commands.Lines[i];
                    if (!stop)
                    {
                        await CheckLine(l, i, type);
                    }
                    else
                    {
                        stop = false;
                        break;
                    }

                    if (loopNow && loopPos != -1)
                    {
                        MainForm.m.WriteToResponses("Looped " + currentLoops.ToString() + "/" + loopAmount.ToString(), true, false);
                        if (currentLoops < loopAmount)
                        {
                            i = loopPos;
                        }
                        else
                        {
                            loopPos      = -1;
                            currentLoops = 0;
                        }
                        loopNow = false;
                    }

                    await Task.Delay(100).ConfigureAwait(false);
                }
            } catch (Exception e) {
                Tools.ShowPopup("Failed to send commands!\nShow more?", "Command firing failed", e.ToString());
            }

            Invoke((MethodInvoker) delegate {
                MessageBox.Show("Finished sending commands!");
                stop = false;
                b_PD_Stop.Enabled = false;
                b_PD_Fire.Enabled = true;
            });
        }
Exemplo n.º 6
0
        public async Task UpdateNext()
        {
            try {
                if (!isActive)
                {
                    return;
                }

                if (commandPos >= 4)
                {
                    commandPos = 0;
                    return;
                }

                tickCount = 0;

                int id = 0;
                switch (commandPos)
                {
                case 0:
                    id = panID;
                    break;

                case 1:
                    id = tiltID;
                    break;

                case 2:
                    id = fovID;
                    break;

                case 3:
                    id = tFovID;
                    break;
                }

                string result = await AsyncCamCom.QueueRepeatingCommand(id);

                if (result == OtherCamCom.defaultResult)
                {
                    UpdateNext();
                    return;
                }

                string commandType = result.Substring(9, 2);

                switch (commandType)
                {
                case "59":     //pan
                    pan = OtherCamCom.CalculatePan(result);
                    break;

                case "5B":     //tilt
                    tilt = OtherCamCom.CalculateTilt(result);
                    break;

                case "5D":     //fov
                    if (InfoPanel.i.commandPos == 2)
                    {
                        fov = OtherCamCom.ReturnedHexValToFloat(result);
                        Console.WriteLine("BBB " + result);
                    }
                    else
                    {
                        Console.WriteLine("AAA " + result);
                        tfov = OtherCamCom.ReturnedHexValToFloat(result);
                    }
                    break;

                default:
                    return;
                }

                Invoke((MethodInvoker) delegate {
                    l_Tilt.Text = "TILT: " + tilt.ToString() + " °";
                    l_FOV.Text  = "DAYLIGHT FOV: " + fov.ToString() + " °";
                    l_TFOV.Text = "THERMAL FOV: " + tfov.ToString() + " °";
                    l_Pan.Text  = "PAN: " + pan.ToString() + " °";
                });

                commandPos++;
                UpdateNext();
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
            }
        }
Exemplo n.º 7
0
        static async Task WaitForCommandResponse(Command com)
        {
            try {
                SendTimer.Stop();

                if (com.isInfo)
                {
                    com.done = false;
                }

                int  i        = 0;
                bool repeated = false;
                while (i < commandRetries)
                {
                    repeated = i > 0;

                    AsyncCamCom.SendCurrent(repeated);
                    if (!com.spammable && !com.isInfo)
                    {
                        break;
                    }

                    if (com.done)
                    {
                        break;
                    }
                    else
                    {
                        await Task.Delay(commandRate);
                    }
                    i++;
                }
                if (repeated)
                {
                    MainForm.m.WriteToResponses("Sent command " + i + " times!", true, com.isInfo);
                }

                if (!com.done)
                {
                    MainForm.m.WriteToResponses(GetNameString() + "No response!", true, com.isInfo);
                }
                else
                {
                    string msg = com.myReturn.msg;
                    if (com.name.Contains("query"))
                    {
                        msg = OtherCamCom.ConvertQueryResult(com.name, com.myReturn.msg);
                    }

                    MainForm.m.WriteToResponses(GetNameString() + "Received: " + msg, false, com.isInfo);
                }

                com.done = true;

                if (queueList.Contains(com))
                {
                    queueList.Remove(com);
                }

                SendTimer.Start();
            } catch (Exception e) {
                Tools.ShowPopup("Failed to process message return!\nShow more?", "Response Failed!", e.ToString());
            }
        }
Exemplo n.º 8
0
        static async Task DoCustomCommand(ScriptCommand com, string line)
        {
            try {
                if (com.codeContent == PelcoD.pause)
                {
                    int value = CheckForVal(line);
                    MainForm.m.WriteToResponses("Waiting: " + value.ToString() + "ms", true);

                    while (value > 0)
                    {
                        if (stopScript)
                        {
                            break;
                        }
                        value -= 200;
                        await Task.Delay(200).ConfigureAwait(false);
                    }
                    stopScript = false;
                }
                else if (com.codeContent == PelcoD.connect)
                {
                    int ipmarker   = line.IndexOf(" ");
                    int portmarker = line.IndexOf(":");
                    if (ipmarker == -1 || portmarker == -1)
                    {
                        MainForm.m.WriteToResponses("Failed to parse IP or port! (" + line + ")", false);
                        return;
                    }

                    IPAddress parsed;
                    int       port;
                    if (IPAddress.TryParse(line.Substring(ipmarker + 1, portmarker - ipmarker - 1), out parsed) && int.TryParse(line.Substring(portmarker + 1), out port))
                    {
                        await AsyncCamCom.TryConnect(false, new IPEndPoint(parsed, port));
                    }
                }
                else if (com.codeContent == PelcoD.reconfig)
                {
                    InfoPanel.i.CheckForCamera();
                }
                else if (com.codeContent == PelcoD.mainplay)
                {
                    int marker = line.IndexOf(" "); //maybe move this up if more customs need it
                    if (marker <= 0)
                    {
                        marker = line.IndexOf(":");
                    }

                    MainForm.m.mainPlayer.Play(false, false);
                }
                else if (com.codeContent == PelcoD.swapPreset)
                {
                    //ComboBox cb = MainForm.m.setPage.cB_ipCon_CamType;
                    //string oldVal = cb.Text;

                    //int marker = line.IndexOf(" ");
                    //if (marker <= 0)
                    //    marker = line.IndexOf(":");

                    //string val = line.Substring(marker + 1).Trim().ToLower();
                    //int foundInt;

                    //if (int.TryParse(val, out foundInt) && cb.Items[foundInt - 1] != null) //index of preset
                    //    cb.SelectedIndex = foundInt - 1;
                    //else {
                    //    foreach (DataGridViewRow row in MainForm.m.up.dgv_Presets.Rows) {
                    //        if (row.Cells[0].Value != null) {
                    //            if (row.Cells[0].Value.ToString().ToLower().Trim().Contains(val)) { //set it to the preset found
                    //                cb.Text = row.Cells[0].Value.ToString();
                    //                break;
                    //            }
                    //        }
                    //    }
                    //}

                    //if (cb.Text != oldVal)
                    //    MainForm.m.setPage.UpdateID(cb);
                    //else
                    //    MainForm.m.WriteToResponses("Failed to find user preset: " + val, false);
                }
            }catch (Exception e) {
                MainForm.m.WriteToResponses("Failed to execute custom command: " + line + Tools.ShowScriptCommandInfo(com, false) + "\n" + e.ToString(), false);
            }
        }
Exemplo n.º 9
0
        public static async Task <string> QuickQuery(string command)
        {
            ScriptCommand send = CheckForCommands(command, Tools.MakeAdr(), false).Result;

            return(await AsyncCamCom.QueryNewCommand(send));
        }