示例#1
0
        async Task IPSend(ScriptCommand send, string curLine)
        {
            Command sendCommand = AsyncCamCom.SendScriptCommand(send);

            if (sendCommand == null || sendCommand.invalid)
            {
                MainForm.m.WriteToResponses("Command: " + curLine + " could not be sent because it's invalid!", true);
            }
        }
示例#2
0
        bool IsNullSC(ScriptCommand sc)
        {
            bool returnVal = (sc == null || sc.names == null || sc.codeContent == null);

            if (returnVal)
            {
                Console.WriteLine("null com");
            }

            return(returnVal);
        }
示例#3
0
        void EditCustomCommand(DataGridViewRow row)
        {
            try {
                Console.WriteLine("edit");

                ScriptCommand newsc = CreateCommand(row);

                if (IsNullSC(newsc))
                {
                    return;
                }

                for (int i = 0; i < CustomScriptCommands.userAddedCommands.Count; i++)
                {
                    bool foundCode = false;
                    bool foundName = false;

                    if (Tools.ReadCommand(CustomScriptCommands.userAddedCommands[i].codeContent) == Tools.ReadCommand(newsc.codeContent))
                    {
                        foundCode = true;
                    }

                    if (!foundCode)
                    {
                        for (int x = 0; x < newsc.names.Length; x++)
                        {
                            if (CustomScriptCommands.userAddedCommands[i].names.Contains(newsc.names[x].Trim()))
                            {
                                foundName = true;
                                break;
                            }
                        }
                    }

                    if (foundCode || foundName)
                    {
                        if (foundName)
                        {
                            newsc.valueCount = CustomScriptCommands.userAddedCommands[i].valueCount;
                        }

                        CustomScriptCommands.userAddedCommands.RemoveAt(i);
                        CustomScriptCommands.userAddedCommands.Add(newsc);
                        return;
                    }
                }

                AddCustomCommand(row); //if it cant find the scriptcommand
            }catch (Exception e) {
                MessageBox.Show("EDIT\n" + e.ToString());
            }
        }
示例#4
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());
            }
        }
示例#5
0
        ScriptCommand CreateCommand(DataGridViewRow row)
        {
            int countedVals = CountValues(row);

            if (countedVals < 0)
            {
                return(null);
            }

            byte[] fullCom = MainForm.m.pd.MakeCommand(row.Cells[1].Value.ToString().Replace("X", "0"));

            ScriptCommand sc = new ScriptCommand(GenNames(row), new byte[] { fullCom[2], fullCom[3], fullCom[4], fullCom[5] },
                                                 GenDescription(row), countedVals);

            return(sc);
        }
示例#6
0
        static async Task <ScriptCommand> RefineCode(ScriptCommand com, uint adr, int value)
        {
            byte[] code = com.codeContent;

            if (com.valueCount == 1)
            {
                code[3] = Convert.ToByte(value);
            }
            else if (com.valueCount == 2)
            {
                string hexVal = (value * 100).ToString("X4");

                code[2] = Convert.ToByte(int.Parse(hexVal.Substring(0, 2), System.Globalization.NumberStyles.HexNumber));
                code[3] = Convert.ToByte(int.Parse(hexVal.Substring(2, 2), System.Globalization.NumberStyles.HexNumber));
            }

            uint checksum = Tools.GetCheckSum(code, adr);

            com.codeContent = new byte[] { 0xFF, (byte)adr, code[0], code[1], code[2], code[3], (byte)checksum };
            return(com);
        }
示例#7
0
        public async Task CheckLine(string line, int linePos, FireType type)
        {
            try {
                if (line != "" && !line.StartsWith("//"))
                {
                    line = line.Replace(",", "").Trim();
                    line = line.ToLower().Replace("x", "0");

                    ScriptCommand sendCom = new ScriptCommand(null, new byte[] { 0, 0, 0, 0 }, null, 0);
                    if (line.Length == 20)
                    {
                        sendCom = new ScriptCommand(new string[] { "" }, Tools.ConvertMsgToByte(line), "", 0);
                    }
                    else
                    {
                        uint adr = 0;
                        Invoke((MethodInvoker) delegate {
                            adr = Tools.MakeAdr();
                        });
                        sendCom = await CustomScriptCommands.CheckForCommands(line, adr, true).ConfigureAwait(false);

                        if (sendCom.codeContent == noCommand)
                        {
                            sendCom = new ScriptCommand(new string[] { "" }, MakeCommand(line), "", 0);
                        }
                    }

                    if (sendCom == null || sendCom.codeContent == null || sendCom.custom)
                    {
                        if ((sendCom == null || sendCom.codeContent == null) && !sendCom.custom)
                        {
                            MainForm.m.WriteToResponses(line + " is invalid!", true);
                        }
                        else if (sendCom.codeContent == loop)
                        {
                            int val = CustomScriptCommands.CheckForVal(line);
                            if (val > 0)
                            {
                                loopPos    = linePos;
                                loopAmount = val;
                            }
                        }
                        else if (sendCom.codeContent == loopStop)
                        {
                            if (loopPos != -1)
                            {
                                currentLoops++;
                            }
                            loopNow = true;
                        }

                        if (sendCom != null && !sendCom.custom)
                        {
                            Console.WriteLine("null command");
                        }
                        return;
                    }

                    if (type == FireType.IP)
                    {
                        await IPSend(sendCom, line);
                    }
                    else
                    {
                        //SerialSend(send, line);
                    }
                }
            } catch (Exception e) {
                MainForm.m.WriteToResponses("Failed to parse line! (" + line + ")\n" + e.ToString()
                                            , false);
            }
        }
示例#8
0
        void LoadContents()
        {
            ScriptCommand[][] coms = CustomScriptCommands.cameraArrayCommands;
            defaultCommandCount = 0;

            foreach (ScriptCommand[] commandArray in coms)
            {
                defaultCommandCount += commandArray.Length;
                foreach (ScriptCommand sc in commandArray)
                {
                    DataGridViewRow row    = (DataGridViewRow)dgv_Coms.Rows[0].Clone();
                    ScriptCommand   curCom = sc;

                    string names = "";
                    for (int x = 0; x < curCom.names.Length; x++)
                    {
                        names += curCom.names[x];
                        if (curCom.valueCount > 0)
                        {
                            names += " X";
                        }

                        if (x < curCom.names.Length - 1)
                        {
                            names += ", ";
                        }
                    }
                    row.Cells[0].Value = names;

                    if (!curCom.custom)
                    {
                        string comContent = Tools.ReadCommand(curCom.codeContent, true);
                        //comcontent(11) = XX XX YY YY

                        if (curCom.valueCount == 1)
                        {
                            comContent = comContent.Substring(0, 9) + "XX";
                        }
                        else if (curCom.valueCount == 2)
                        {
                            comContent = comContent.Substring(0, 6) + "XX XX";
                        }


                        row.Cells[1].Value = comContent;
                    }
                    else
                    {
                        row.Cells[1].Value = "Scripting";
                        row.Cells[2].Value = "(Scripting Command) ";
                    }

                    string description = curCom.description;
                    if (curCom.valueCount > 0 && !curCom.custom)
                    {
                        int xIndex = description.IndexOf("X") + 1;

                        string vals = " (" + curCom.validValues + ") ";

                        description = description.Substring(0, xIndex) + vals
                                      + description.Substring(xIndex);
                    }

                    row.Cells[2].Value += description;

                    dgv_Coms.Rows.Add(row);
                }
            }
        }
示例#9
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);
            }
        }
示例#10
0
        public static async Task <string> QuickQuery(string command)
        {
            ScriptCommand send = CheckForCommands(command, Tools.MakeAdr(), false).Result;

            return(await AsyncCamCom.QueryNewCommand(send));
        }
示例#11
0
        public async static Task <string> QueryNewCommand(ScriptCommand com)
        {
            Command sendCommand = new Command(com.codeContent, false, false, com.isQuery, com.names[0]);

            return(await WaitForResponse(sendCommand));
        }
示例#12
0
        public static Command SendScriptCommand(ScriptCommand com)
        {
            Command sendCommand = new Command(com.codeContent, false, false, com.isQuery, com.names[0]); //Creating a command will immediately queue it

            return(sendCommand);
        }
示例#13
0
 private void b_Debug_Click(object sender, EventArgs e)
 {
     sc = CustomScriptCommands.CheckForCommands(tB_Debug.Text, 0, false).Result;
     Tools.ShowScriptCommandInfo(sc, true);
 }