Esempio n. 1
0
            public MyReaderFormatMatchCallback(Object lockObj)
            {
                mLock   = lockObj;
                mResult = new MyReaderMatchResult();

                lock (mLock)
                {
                    mCallbackCompleted = false;
                }
            }
Esempio n. 2
0
        private void ShowLearningResult(MyReaderMatchResult matchResult)
        {
            lvResultList.Items.Clear();

            // remember the current match result for later use (if needed)
            mCurrentMatchResult = matchResult;

            if (null == matchResult)
            {
                return;
            }

            ListViewItem lvItem = new ListViewItem();

            if (matchResult.MatchResult == null)
            {
                if (matchResult.RawLearningData != null)
                {
                    lvItem.Text = Properties.Resources.UNRECOGNIZED_FORMAT;
                    lvItem.UseItemStyleForSubItems = false;
                    lvItem.SubItems[0].ForeColor   = Color.Red;
                    lvResultList.Items.Add(lvItem);
                    lvResultList.Items[0].Selected = true;
                }
            }
            else
            {
                lvItem.Text = matchResult.MatchResult.formatId;

                if (matchResult.MatchResult.customCode >= 0)
                {
                    lvItem.SubItems.Add(String.Format("0x{0:X}", matchResult.MatchResult.customCode));
                }
                else
                {
                    lvItem.SubItems.Add("");
                }

                if (matchResult.MatchResult.keyCode >= 0)
                {
                    lvItem.SubItems.Add(String.Format("0x{0:X}", matchResult.MatchResult.keyCode));
                }
                else
                {
                    lvItem.SubItems.Add("");
                }

                lvResultList.Items.Add(lvItem);
            }
        }
Esempio n. 3
0
        private ListViewItem GetKeyListViewItem(String keyId, MyReaderMatchResult matchResult)
        {
            ListViewItem lvItem = new ListViewItem();

            lvItem.UseItemStyleForSubItems = false;

            // Key ID
            lvItem.Text = keyId;

            // Key Name
            KeyName keyData;

            if (mKeyNameTable.TryGetValue(keyId, out keyData))
            {
                lvItem.SubItems.Add(keyData.LocalizedName);
                lvItem.SubItems[0].ForeColor = Color.Black;
            }
            else
            {
                lvItem.SubItems.Add("");
                lvItem.SubItems[0].ForeColor = Color.Red;
            }

            lvItem.Tag = matchResult;

            // IR format
            if (matchResult != null)
            {
                if (null != matchResult.MatchResult)
                {
                    lvItem.SubItems.Add(matchResult.MatchResult.formatId);
                    lvItem.SubItems.Add(
                        matchResult.MatchResult.customCode == -1 ? "" :
                        String.Format("0x{0:X}", matchResult.MatchResult.customCode));
                    lvItem.SubItems.Add(
                        matchResult.MatchResult.keyCode == -1 ? "" :
                        String.Format("0x{0:X}", matchResult.MatchResult.keyCode));
                }
                else
                {
                    if (null != matchResult.RawLearningData)
                    {
                        lvItem.SubItems.Add(Resources.UNRECOGNIZED_FORMAT);
                    }
                }
            }

            return(lvItem);
        }
Esempio n. 4
0
        private void UpdateKeyListViewItem(ListViewItem item, String keyId, MyReaderMatchResult matchResult)
        {
            ListViewItem tmpItem = GetKeyListViewItem(keyId, matchResult);

            item.SubItems.Clear();
            item.Tag = matchResult;
            for (int i = 0; i < tmpItem.SubItems.Count; i++)
            {
                if (i == 0)
                {
                    item.SubItems[i] = tmpItem.SubItems[i];
                }
                else
                {
                    item.SubItems.Add(tmpItem.SubItems[i]);
                }
            }
        }
Esempio n. 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // make sure we have decoded data to add
            if (lvResultList.Items.Count == 0 || null == mCurrentMatchResult)
            {
                Program.ShowError(Resources.E_NO_LEARNING_DATA);
                return;
            }
            else
            {
                String       keyId        = txtKeyId.Text.Trim();
                ListViewItem selectedItem = lvKeyList.SelectedItems[0];
                if (selectedItem.Text.Equals(keyId))
                {
                    // save the match result to ListViewItem's Tag
                    selectedItem.Tag = mCurrentMatchResult;

                    // update the list view item content
                    UpdateKeyListViewItem(selectedItem, keyId, mCurrentMatchResult);

                    // move to next item
                    if (lvKeyList.SelectedIndices[0] < lvKeyList.Items.Count - 1)
                    {
                        lvKeyList.Items[lvKeyList.SelectedIndices[0] + 1].Selected = true;
                        lvKeyList.EnsureVisible(lvKeyList.SelectedIndices[0]);
                    }

                    // check all learning result for possible learning error
                    CheckLearningKeyList();

                    // clear the current result
                    mCurrentMatchResult = null;
                    lvResultList.Items.Clear();
                }
            }

            mBmsFileNotSaved = true;
        }
        private void ReTransmitIRData()
        {
            if (lvKeyList.SelectedItems.Count > 0)
            {
                if (mIsLearning)
                {
                    if (DialogResult.Yes != Program.ShowQuestion(Resources.Q_STOP_LEARNING_NOW))
                    {
                        return;
                    }

                    StopLearning();
                }

                if (lvKeyList.SelectedItems.Count == 0)
                {
                    Program.ShowError(Resources.E_NO_SELECTED_KEY);
                    return;
                }

                int          selIdx = lvKeyList.SelectedIndices[0];
                ListViewItem lvItem = lvKeyList.SelectedItems[0];

                MyReaderMatchResult matchResult = (MyReaderMatchResult)lvItem.Tag;
                if (null != matchResult && null != matchResult.RawLearningData)
                {
                    if (mMyIrReader != null)
                    {
                        mMyIrReader.sendLearningData(matchResult.RawLearningData);
                    }
                }
                else
                {
                    Program.ShowError(Resources.E_NO_LEARNING_DATA);
                    return;
                }
            }
        }
        private JObject GetLearningResultJson(KeyValuePair <String, MyReaderMatchResult> result)
        {
            JObject jResult = new JObject();

            jResult.Add("key_id", result.Key);  // key id

            if (null != result.Value)
            {
                MyReaderMatchResult matchResult = result.Value;

                if (matchResult.MatchResult != null)
                {
                    JObject jMatchedResult = new JObject();
                    jMatchedResult.Add("format_id", matchResult.MatchResult.formatId);
                    jMatchedResult.Add("custom_code", String.Format("0x{0:X}", matchResult.MatchResult.customCode));
                    jMatchedResult.Add("key_code", String.Format("0x{0:X}", matchResult.MatchResult.keyCode));

                    jResult.Add("match_result", jMatchedResult);
                }

                if (matchResult.RawLearningData != null)
                {
                    String rawDataString = "";
                    foreach (byte byteData in matchResult.RawLearningData)
                    {
                        rawDataString += String.Format("0x{0:X},", byteData);
                    }
                    //remove the tailing comma
                    rawDataString = rawDataString.TrimEnd(new char[] { ',' });

                    jResult.Add("raw_learning_data", rawDataString);
                }
            }

            return(jResult);
        }
        public Boolean Load(String filePath)
        {
            if (!File.Exists(filePath))
            {
                return(false);
            }

            if (null == mResultList)
            {
                mResultList = new Dictionary <String, MyReaderMatchResult>();
            }
            else
            {
                mResultList.Clear();
            }

            Dictionary <String, MyReaderMatchResult> resultMap = new Dictionary <String, MyReaderMatchResult>();

            try
            {
                using (StreamReader file = File.OpenText(filePath))
                {
                    using (JsonTextReader reader = new JsonTextReader(file))
                    {
                        JObject jRoot = (JObject)JToken.ReadFrom(reader);

                        JArray jResults = (JArray)jRoot["learning_results"];

                        MyReaderMatchResult matchResult;
                        JObject             tmpJObject = new JObject();
                        for (int idx = 0; idx < jResults.Count; idx++)
                        {
                            matchResult = new MyReaderMatchResult();

                            try
                            {
                                JObject jRemoteKey = (JObject)jResults[idx];

                                String keyId = (String)jRemoteKey["key_id"];

                                if (null != jRemoteKey["raw_learning_data"])
                                {
                                    List <byte> byteDataList    = new List <byte>();
                                    String      rawDataString   = (String)jRemoteKey["raw_learning_data"];
                                    String[]    byteStirngArray = rawDataString.Split(new char[] { ',' });
                                    for (int i = 0; i < byteStirngArray.Length; i++)
                                    {
                                        if (byteStirngArray[i].Length == 0)
                                        {
                                            continue;
                                        }

                                        if (byteStirngArray[i].StartsWith("0x") || byteStirngArray[i].StartsWith("0X"))
                                        {
                                            byteDataList.Add(Convert.ToByte(byteStirngArray[i].Substring(2), 16));
                                        }
                                        else
                                        {
                                            byteDataList.Add(Convert.ToByte(byteStirngArray[i], 16));
                                        }
                                    }

                                    matchResult.RawLearningData = byteDataList.ToArray();
                                }
                                else
                                {
                                    matchResult.RawLearningData = null;
                                }

                                // match result
                                JObject jMatchResult = (JObject)jRemoteKey["match_result"];
                                if (null == jMatchResult)
                                {
                                    matchResult.MatchResult = null;
                                }
                                else
                                {
                                    String formatId   = "";
                                    long   customCode = 0;
                                    long   keyCode    = 0;

                                    if (jMatchResult["format_id"] != null)
                                    {
                                        formatId = (String)jMatchResult["format_id"];
                                    }
                                    if (jMatchResult["custom_code"] != null)
                                    {
                                        customCode = GetInt64FromString((String)jMatchResult["custom_code"]);
                                    }
                                    if (jMatchResult["key_code"] != null)
                                    {
                                        customCode = GetInt64FromString((String)jMatchResult["key_code"]);
                                    }

                                    matchResult.MatchResult = new ReaderMatchResult(formatId, customCode, keyCode);
                                }

                                resultMap.Add(keyId, matchResult);
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }

            mResultList = resultMap;
            return(true);
        }