private void cwDetectionStart_Click(object sender, EventArgs e)
 {
     bool isSLCRx = false;
     int mid = 220;
     int sid = 1;
     byte channelType = 0;
     this.comm.CMC.TxCurrentTransmissionType = (CommonClass.TransmissionType) this.comm.TxCurrentTransmissionType;
     string protocol = "OSP";
     isSLCRx = this.comm.RxType == CommunicationManager.ReceiverType.SLC;
     ArrayList list = this.comm.m_Protocols.GetDefaultMsgFieldList(isSLCRx, mid, sid, "CW Controller Input_CONFIG", protocol);
     InputMsg[] fieldList = new InputMsg[list.Count];
     for (int i = 0; i < list.Count; i++)
     {
         fieldList[i].messageID = ((InputMsg) list[i]).messageID;
         fieldList[i].subID = ((InputMsg) list[i]).subID;
         fieldList[i].messageName = ((InputMsg) list[i]).messageName;
         fieldList[i].fieldNumber = ((InputMsg) list[i]).fieldNumber;
         fieldList[i].fieldName = ((InputMsg) list[i]).fieldName;
         fieldList[i].bytes = ((InputMsg) list[i]).bytes;
         fieldList[i].datatype = ((InputMsg) list[i]).datatype;
         fieldList[i].units = ((InputMsg) list[i]).units;
         fieldList[i].scale = ((InputMsg) list[i]).scale;
         fieldList[i].defaultValue = ((InputMsg) list[i]).defaultValue;
         fieldList[i].savedValue = ((InputMsg) list[i]).savedValue;
     }
     try
     {
         string text = this.cwConfigComboBox.Text;
         if (text == string.Empty)
         {
             return;
         }
         if (text.StartsWith("2:"))
         {
             fieldList[2].defaultValue = "2";
             this.comm.CWInterferenceDetectModeIndex = 1;
         }
         else if (text.StartsWith("3:"))
         {
             fieldList[2].defaultValue = "3";
             this.comm.CWInterferenceDetectModeIndex = 2;
         }
         else if (text.StartsWith("4:"))
         {
             fieldList[2].defaultValue = "4";
             this.comm.CWInterferenceDetectModeIndex = 3;
         }
         else
         {
             fieldList[2].defaultValue = "0";
             this.comm.CWInterferenceDetectModeIndex = 0;
         }
         if (this.comm.CWInterferenceDetectModeIndex != 3)
         {
             this.detectionOnCheckBox.BackgroundBrush = new SolidBrush(Color.Green);
             this.detectionOnCheckBox.Checked = true;
             this.detectionOnCheckBox.Refresh();
         }
         else
         {
             this.detectionOnCheckBox.BackgroundBrush = new SolidBrush(Color.Gray);
             this.detectionOnCheckBox.Checked = false;
             this.detectionOnCheckBox.Refresh();
         }
     }
     catch (Exception exception)
     {
         string str3 = exception.ToString();
         string str4 = "### Interference Report GUI handler error -- " + str3;
         this.comm.WriteApp(str4);
     }
     string msg = this.comm.m_Protocols.FieldList_to_HexMsgStr(isSLCRx, fieldList, channelType);
     this.comm.WriteData(msg);
 }
Beispiel #2
0
 private void OkButton_Click(object sender, EventArgs e)
 {
     bool isSLCRx = false;
     int mid = 0xe4;
     int sid = 0;
     byte channelType = 0;
     try
     {
         this.comm.CMC.TxCurrentTransmissionType = (CommonClass.TransmissionType) this.comm.TxCurrentTransmissionType;
         string protocol = "OSP";
         isSLCRx = this.comm.RxType == CommunicationManager.ReceiverType.SLC;
         ArrayList list = this.comm.m_Protocols.GetDefaultMsgFieldList(isSLCRx, mid, sid, "Encryption Control Settings", protocol);
         InputMsg[] ltc = new InputMsg[list.Count];
         for (int i = 0; i < list.Count; i++)
         {
             ltc[i].messageID = ((InputMsg) list[i]).messageID;
             ltc[i].subID = ((InputMsg) list[i]).subID;
             ltc[i].messageName = ((InputMsg) list[i]).messageName;
             ltc[i].fieldNumber = ((InputMsg) list[i]).fieldNumber;
             ltc[i].fieldName = ((InputMsg) list[i]).fieldName;
             ltc[i].bytes = ((InputMsg) list[i]).bytes;
             ltc[i].datatype = ((InputMsg) list[i]).datatype;
             ltc[i].units = ((InputMsg) list[i]).units;
             ltc[i].scale = ((InputMsg) list[i]).scale;
             ltc[i].defaultValue = ((InputMsg) list[i]).defaultValue;
             ltc[i].savedValue = ((InputMsg) list[i]).savedValue;
         }
         try
         {
             this.ConvertCheckBoxesToEcryptCtrlMsgStruct(this.EncryCtrlDataGridView, ref EcryptCtrlMsg);
             this.UpdateLocalMsgCopyWithEncCtrlSettings(ref ltc, EcryptCtrlMsg);
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.ToString());
         }
         string msg = this.comm.m_Protocols.FieldList_to_HexMsgStr(isSLCRx, ltc, channelType);
         if (clsGlobal.PerformOnAll)
         {
             foreach (string str3 in clsGlobal.g_objfrmMDIMain.PortManagerHash.Keys)
             {
                 PortManager manager = (PortManager) clsGlobal.g_objfrmMDIMain.PortManagerHash[str3];
                 if ((manager != null) && manager.comm.IsSourceDeviceOpen())
                 {
                     manager.comm.WriteData(msg);
                 }
             }
             clsGlobal.PerformOnAll = false;
         }
         else
         {
             this.comm.WriteData(msg);
         }
     }
     catch (Exception exception2)
     {
         if (!this.comm.IsSourceDeviceOpen())
         {
             MessageBox.Show("Source Device is not open", "frmEncryCtrl: OkButton_Click()");
         }
         else
         {
             MessageBox.Show(exception2.ToString(), "frmEncryCtrl: OkButton_Click()");
         }
     }
 }
Beispiel #3
0
 private void UpdateLocalMsgCopyWithEncCtrlSettings(ref InputMsg[] ltc, EcryptCtrlMsgStruct ecm)
 {
     ltc[2].defaultValue = ecm.LevelChange.ToString();
     string[] strArray = ecm.strDbgLevels.Split(new char[] { ' ' });
     for (int i = 0; i < 0x31; i++)
     {
         ltc[i + 3].defaultValue = Convert.ToInt16(strArray[i], 0x10).ToString();
     }
 }
Beispiel #4
0
 public List<InputMsg> GetInputMessages(string protocol)
 {
     List<InputMsg> list = new List<InputMsg>();
     InputMsg item = new InputMsg();
     XmlDocument document = new XmlDocument();
     document.Load(this.m_XmlFile);
     XmlNodeList list2 = document.SelectNodes("/protocols/protocol[@name='" + protocol + "']/input/message");
     try
     {
         foreach (XmlNode node in list2)
         {
             item.messageID = int.Parse(node.Attributes["mid"].Value);
             try
             {
                 item.subID = int.Parse(node.Attributes["subid"].Value);
             }
             catch (Exception)
             {
                 item.subID = -1;
             }
             item.messageName = node.Attributes["name"].Value;
             list.Add(item);
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
     list.Sort(new Comparison<InputMsg>(MsgFactory.InputMsgCompare));
     return list;
 }
Beispiel #5
0
 public string FieldList_to_HexMsgStr(bool isSLCRx, InputMsg[] fieldList, byte channelType)
 {
     string message = "";
     int num = 0;
     for (int i = 0; i < fieldList.Length; i++)
     {
         message = message + ConvertDecimalToHex(fieldList[i].defaultValue, fieldList[i].datatype, fieldList[i].scale);
         num += fieldList[i].bytes;
     }
     if (isSLCRx && (channelType != 0))
     {
         num++;
         message = channelType.ToString("X").PadLeft(2, '0') + message;
     }
     return ("A0A2" + num.ToString("X").PadLeft(4, '0') + message + this.GetChecksum(message, isSLCRx) + "B0B3");
 }
Beispiel #6
0
 private string GetRawData(string csvMessage, string messageName, string protocol)
 {
     int num = 0;
     int num2 = 0;
     int mid = 0;
     int sid = -1;
     int num5 = 0;
     bool slcRx = false;
     string[] strArray = csvMessage.Split(new char[] { ',' });
     try
     {
         if ((((protocol == "SSB") && ((int.Parse(strArray[0]) == 0xee) || (int.Parse(strArray[0]) == 0xcc))) || ((protocol == "LPL") || ((protocol == "F") && (int.Parse(strArray[0]) == 2)))) || ((protocol == "AI3") && (int.Parse(strArray[0]) == 1)))
         {
             num2 = int.Parse(strArray[0]);
             if ((strArray.Length > 1) && (strArray[1].ToString() != ""))
             {
                 mid = int.Parse(strArray[1]);
             }
             if ((strArray.Length > 2) && (strArray[2].ToString() != ""))
             {
                 sid = int.Parse(strArray[2]);
             }
         }
         else
         {
             mid = int.Parse(strArray[0]);
             if ((strArray.Length > 1) && (strArray[1].ToString() != ""))
             {
                 sid = int.Parse(strArray[1]);
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, "Error reading message definition", MessageBoxButtons.OK, MessageBoxIcon.Hand);
         return "";
     }
     ArrayList list = new ArrayList();
     StringBuilder builder = new StringBuilder();
     list = this.GetInputMessageStructure(mid, sid, messageName, protocol);
     switch (num2)
     {
         case 0xee:
         case 0xcc:
         case 2:
         case 1:
             num5 = 1;
             slcRx = true;
             num++;
             builder.Append(Convert.ToString(num2, 0x10).PadLeft(2, '0').PadRight(3, ' ').ToUpper());
             break;
     }
     string str2 = string.Empty;
     InputMsg msg = new InputMsg();
     for (int i = 0; i < list.Count; i++)
     {
         if (strArray[i + num5].Length > 0)
         {
             msg = (InputMsg) list[i];
             try
             {
                 str2 = ConvertDecimalToHex(strArray[i + num5], msg.datatype, msg.scale);
             }
             catch
             {
                 MessageBox.Show((("Problem with input field " + msg.fieldName + "\r\n") + "Datatype must be " + msg.datatype + "\r\n") + "Value entered is " + strArray[i + num5].ToString(), "Error building input message!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                 return string.Empty;
             }
             if (msg.datatype == "TEXT")
             {
                 int bytes = ((InputMsg) list[i]).bytes;
                 int num8 = str2.Length / 2;
                 if (num8 <= bytes)
                 {
                     builder.Append(" ");
                     builder.Append(str2);
                     num += num8;
                     for (int j = 0; j < (bytes - num8); j++)
                     {
                         builder.Append("00");
                         num++;
                     }
                 }
                 else
                 {
                     builder.Append(" ");
                     builder.Append(str2.Substring(0, bytes * 2));
                     num += strArray[i + num5].Length;
                 }
             }
             else if (msg.datatype == "RAW_HEX")
             {
                 builder.Append(" ");
                 builder.Append(str2);
                 num += str2.Length / 2;
             }
             else
             {
                 builder.Append(" ");
                 builder.Append(str2);
                 num += ((InputMsg) list[i]).bytes;
             }
         }
     }
     string message = builder.ToString();
     string str5 = "A0A2 " + num.ToString("X").PadLeft(4, '0') + message + " " + this.GetChecksum(message, slcRx) + " B0B3";
     list.Clear();
     return str5;
 }
Beispiel #7
0
 private static int InputMsgCompare(InputMsg A, InputMsg B)
 {
     int num = 0;
     if (A.messageID == B.messageID)
     {
         if (A.subID > B.subID)
         {
             num = 1;
         }
         else if (A.subID < B.subID)
         {
             num = -1;
         }
     }
     if (A.messageID > B.messageID)
     {
         return 1;
     }
     if (A.messageID < B.messageID)
     {
         num = -1;
     }
     return num;
 }
Beispiel #8
0
        public void MsgFactoryInit(string xmlFile)
        {
            this.m_msgHash.Clear();
            XmlDocument document = new XmlDocument();
            document.Load(xmlFile);
            foreach (XmlNode node in document.DocumentElement)
            {
                int num = 0;
                string str = node.Attributes["name"].Value;
                switch (str)
                {
                    case "F":
                    case "AI3":
                        num = 1;
                        break;
                }
                foreach (XmlElement element2 in node.ChildNodes)
                {
                    string name = element2.Name;
                    switch (name)
                    {
                        case "output":
                        {
                            OutputMsg msg = new OutputMsg();
                            foreach (XmlElement element3 in element2.ChildNodes)
                            {
                                string attribute = element3.GetAttribute("mid");
                                string str4 = element3.GetAttribute("subid");
                                element3.GetAttribute("name");
                                int num2 = 0;
                                int num3 = 0;
                                int num4 = 0;
                                try
                                {
                                    msg.messageID = Convert.ToInt32(attribute);
                                    int messageID = 0;
                                    if (msg.messageID == 0x45)
                                    {
                                        messageID = msg.messageID;
                                        msg.fieldNumber = messageID;
                                    }
                                    int num6 = 0;
                                    ArrayList list = new ArrayList();
                                    int count = element3.ChildNodes.Count;
                                    for (int i = 0; i < count; i++)
                                    {
                                        if (element3.ChildNodes[i].NodeType != XmlNodeType.Comment)
                                        {
                                            XmlElement element4 = (XmlElement) element3.ChildNodes[i];
                                            if (element4.GetAttribute("name").Contains("LOOP"))
                                            {
                                                num2 = int.Parse(element4.GetAttribute("numloops"));
                                                num3 = int.Parse(element4.GetAttribute("numlines"));
                                                int num9 = i + 1;
                                                for (int j = 0; j < num2; j++)
                                                {
                                                    for (int k = 0; k < num3; k++)
                                                    {
                                                        element4 = (XmlElement) element3.ChildNodes[num9 + k];
                                                        msg.fieldNumber = ++num6;
                                                        msg.fieldName = element4.GetAttribute("name") + string.Format("{0}", j + 1);
                                                        msg.bytes = int.Parse(element4.GetAttribute("bytes"));
                                                        msg.datatype = element4.GetAttribute("datatype");
                                                        msg.units = element4.GetAttribute("units");
                                                        try
                                                        {
                                                            msg.scale = (element4.GetAttribute("scale") == "") ? (msg.scale = 1.0) : (msg.scale = double.Parse(element4.GetAttribute("scale")));
                                                        }
                                                        catch
                                                        {
                                                            msg.scale = 1.0;
                                                        }
                                                        msg.startByte = ((4 + num) + 1) + num4;
                                                        msg.endByte = (msg.startByte + msg.bytes) - 1;
                                                        if (element4.Attributes["referenceField"] != null)
                                                        {
                                                            msg.referenceField = element4.GetAttribute("referenceField");
                                                        }
                                                        else
                                                        {
                                                            msg.referenceField = "";
                                                        }
                                                        num4 += msg.bytes;
                                                        list.Add(msg);
                                                    }
                                                }
                                                i += num3;
                                            }
                                            else
                                            {
                                                msg.fieldNumber = ++num6;
                                                msg.fieldName = element4.GetAttribute("name");
                                                msg.bytes = int.Parse(element4.GetAttribute("bytes"));
                                                msg.datatype = element4.GetAttribute("datatype");
                                                msg.units = element4.GetAttribute("units");
                                                try
                                                {
                                                    msg.scale = (element4.GetAttribute("scale") == "") ? (msg.scale = 1.0) : (msg.scale = double.Parse(element4.GetAttribute("scale")));
                                                }
                                                catch
                                                {
                                                    msg.scale = 1.0;
                                                }
                                                msg.startByte = ((4 + num) + 1) + num4;
                                                msg.endByte = (msg.startByte + msg.bytes) - 1;
                                                if (element4.Attributes["referenceField"] != null)
                                                {
                                                    msg.referenceField = element4.GetAttribute("referenceField");
                                                }
                                                else
                                                {
                                                    msg.referenceField = "";
                                                }
                                                num4 += msg.bytes;
                                                list.Add(msg);
                                            }
                                        }
                                    }
                                    if (str4 == string.Empty)
                                    {
                                        str4 = "NA";
                                    }
                                    list.Add(num4);
                                    string key = str + "_" + name + "_" + attribute + "_" + str4;
                                    this.m_msgHash.Add(key, list);
                                }
                                catch
                                {
                                }
                            }
                            break;
                        }
                        case "input":
                        {
                            InputMsg msg2 = new InputMsg();
                            foreach (XmlElement element5 in element2.ChildNodes)
                            {
                                string str7 = element5.GetAttribute("mid");
                                string str8 = element5.GetAttribute("subid");
                                string str9 = element5.GetAttribute("name");
                                int num12 = 0;
                                int num13 = 0;
                                int num14 = 0;
                                try
                                {
                                    msg2.messageID = Convert.ToInt32(str7);
                                    int num15 = 0;
                                    ArrayList list2 = new ArrayList();
                                    int num16 = element5.ChildNodes.Count;
                                    for (int m = 0; m < num16; m++)
                                    {
                                        if (element5.ChildNodes[m].NodeType == XmlNodeType.Comment)
                                        {
                                            continue;
                                        }
                                        XmlElement element6 = (XmlElement) element5.ChildNodes[m];
                                        if (element6.GetAttribute("name").Contains("LOOP"))
                                        {
                                            num12 = int.Parse(element6.GetAttribute("numloops"));
                                            num13 = int.Parse(element6.GetAttribute("numlines"));
                                            int num18 = m + 1;
                                            for (int n = 0; n < num12; n++)
                                            {
                                                for (int num20 = 0; num20 < num13; num20++)
                                                {
                                                    element6 = (XmlElement) element5.ChildNodes[num18 + num20];
                                                    msg2.fieldNumber = ++num15;
                                                    msg2.fieldName = element6.GetAttribute("name");
                                                    msg2.bytes = int.Parse(element6.GetAttribute("bytes"));
                                                    msg2.datatype = element6.GetAttribute("datatype");
                                                    msg2.units = element6.GetAttribute("units");
                                                    if (element6.GetAttribute("scale") == "")
                                                    {
                                                        msg2.scale = 1.0;
                                                    }
                                                    else
                                                    {
                                                        msg2.scale = double.Parse(element6.GetAttribute("scale"));
                                                    }
                                                    switch (str)
                                                    {
                                                        case "NMEA":
                                                        case "LPL":
                                                            msg2.defaultValue = element6.GetAttribute("default");
                                                            break;

                                                        default:
                                                            if (element6.GetAttribute("default") != null)
                                                            {
                                                                if (msg2.datatype != "RAW")
                                                                {
                                                                    msg2.defaultValue = ConvertHexToDecimal(element6.GetAttribute("default"), msg2.datatype, msg2.scale);
                                                                }
                                                                else
                                                                {
                                                                    msg2.defaultValue = element6.GetAttribute("default");
                                                                }
                                                            }
                                                            else
                                                            {
                                                                msg2.defaultValue = "0";
                                                            }
                                                            break;
                                                    }
                                                    if (element6.GetAttribute("savedValue") != null)
                                                    {
                                                        msg2.savedValue = element6.GetAttribute("savedValue");
                                                    }
                                                    else
                                                    {
                                                        msg2.savedValue = "0";
                                                    }
                                                    num14 += msg2.bytes;
                                                    list2.Add(msg2);
                                                }
                                            }
                                            m += num13;
                                            continue;
                                        }
                                        msg2.fieldNumber = ++num15;
                                        msg2.fieldName = element6.GetAttribute("name");
                                        msg2.bytes = int.Parse(element6.GetAttribute("bytes"));
                                        msg2.datatype = element6.GetAttribute("datatype");
                                        msg2.units = element6.GetAttribute("units");
                                        if (element6.GetAttribute("scale") == "")
                                        {
                                            msg2.scale = 1.0;
                                        }
                                        else
                                        {
                                            msg2.scale = double.Parse(element6.GetAttribute("scale"));
                                        }
                                        switch (str)
                                        {
                                            case "NMEA":
                                            case "LPL":
                                                msg2.defaultValue = element6.GetAttribute("default");
                                                break;

                                            default:
                                                if (element6.GetAttribute("default") != null)
                                                {
                                                    if (msg2.datatype != "RAW")
                                                    {
                                                        msg2.defaultValue = ConvertHexToDecimal(element6.GetAttribute("default"), msg2.datatype, msg2.scale);
                                                    }
                                                    else
                                                    {
                                                        msg2.defaultValue = element6.GetAttribute("default");
                                                    }
                                                }
                                                else
                                                {
                                                    msg2.defaultValue = "0";
                                                }
                                                break;
                                        }
                                        if (element6.GetAttribute("savedValue") != null)
                                        {
                                            msg2.savedValue = element6.GetAttribute("savedValue");
                                        }
                                        else
                                        {
                                            msg2.savedValue = "0";
                                        }
                                        num14 += msg2.bytes;
                                        list2.Add(msg2);
                                    }
                                    if (str8 == string.Empty)
                                    {
                                        str8 = "NA";
                                    }
                                    list2.Add(num14);
                                    string str11 = string.Format(clsGlobal.MyCulture, "{0}_{1}_{2}_{3}_{4}", new object[] { str, name, str7, str8, str9 });
                                    this.m_msgHash.Add(str11, list2);
                                }
                                catch
                                {
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }