Exemple #1
0
        private void AddScannedDevicesFromFile(object sender, FileSystemEventArgs e)
        {
            Thread.Sleep(1000);

            MatchCollection matches;

            using (StreamReader streamReader = File.OpenText(DevicesPath))
            {
                Regex regex = new Regex(@"devName:(\r\n|\r|\n)*(?<DevName>.{0,})(\r\n|\r|\n)*DevEui:(\r\n|\r|\n)*(?<DevEui>.{0,})(\r\n|\r|\n)*AppEui:(\r\n|\r|\n)*(?<AppEui>.{0,})(\r\n|\r|\n)*AppKey:(\r\n|\r|\n)*(?<AppKey>.{0,})(\r\n|\r|\n)*DevAddr:(\r\n|\r|\n)*(?<DevAdd>.{0,})(\r\n|\r|\n)*AppSKey:(\r\n|\r|\n)*(?<AppSKey>.{0,})(\r\n|\r|\n)*NwkSKEY:(\r\n|\r|\n)*(?<NwkSKey>.{0,})(\r\n|\r|\n)?");
                matches = regex.Matches(streamReader.ReadToEnd());
            }

            int i = 1;

            App.Current.Dispatcher.Invoke((Action) delegate
            {
                foreach (Match match in matches)
                {
                    ScannedDevices.Add(new Device
                    {
                        Index   = i,
                        DevName = match.Groups["DevName"].Value.Trim(),
                        DevEui  = match.Groups["DevEui"].Value.Trim(),
                        AppEui  = match.Groups["AppEui"].Value.Trim(),
                        AppKey  = match.Groups["AppKey"].Value.Trim(),
                        //DevAdd = int.Parse(match.Groups["DevAdd"].Value.Trim()).ToString("X8"),
                        DevAdd  = match.Groups["DevAdd"].Value.Trim(),
                        AppSKey = match.Groups["AppSKey"].Value.Trim(),
                        NwkSKey = match.Groups["NwkSKey"].Value.Trim()
                    });

                    i++;
                }
            });
        }
Exemple #2
0
        private void CreateProtocol(object selectedItems)
        {
            IList         items   = (IList)selectedItems;
            List <Device> devices = new List <Device>(items.Cast <Device>());

            for (int i = 0; i < devices.Count(); i++)
            {
                ScannedDevices.Remove(devices[i]);
            }
            items.Clear();

            Protocol protocol = new Protocol
            {
                Tester   = Tester,
                DateTime = DateTime.Now,
                Devices  = new ObservableCollection <Device>(devices)
            };

            context.Attach(protocol);
            context.SaveChanges();

            //context.Entry(protocol.Devices).State = EntityState.Detached;

            Services.Excel.Export.ProtocolToXlsx(ProtocolPath, protocol);
        }
Exemple #3
0
        private void UpdateScannedDevicesFromResponse(object sender, FileSystemEventArgs e)
        {
            Thread.Sleep(1000);

            string text;

            using (StreamReader sr2 = File.OpenText(ResponsePath))
            {
                text = sr2.ReadToEnd();
            }

            Regex regex = new Regex(@"(?<DevEui>\w{16})\s(?<Snr>\d+\.?\d*)\s(?<PackageType>\w{2})(?<FactoryNumber>\w{8})(?<CurrentTime>\w{8})(?<Model>\w{2})(?<Phases>\w{2})(?<Tarrifs>\w{2})(?<Garbage>\w{2})(?<ReleaseDate>\w{8})(?<SoftwareVersion>\w{8})(?<Indications>\w{8})(?<Temperature>\w{2})(?<RelayStatus>\w{2})(?<Stasus>\w{6})(?<Reason>\w{4})(?<UUID>\w{4})(?<Unused>.*)");

            MatchCollection matches = regex.Matches(text);

            foreach (Match match in matches)
            {
                Device device = ScannedDevices.Where(d => d.DevEui == match.Groups["DevEui"].Value.Trim()).LastOrDefault();

                if (device != null)
                {
                    device.Snr           = match.Groups["Snr"].Value.Trim();
                    device.FactoryNumber = Convert.ToUInt64(ReverseWord(match.Groups["FactoryNumber"].Value.Trim()), 16).ToString();
                    device.TimeBefore    = DateTime.Now.ToString();                                                                                    //kostyl'
                    //device.TimeBefore = Convert.ToDateTime(Convert.ToInt64(new DateTime(1970, 1, 1)) + (Convert.ToInt64(ReverseWord(match.Groups["TimeBefore"].Value.Trim()), 16))).ToString("dd:MM:yyyy");
                    device.SoftwareVersion = DevideBy10((Convert.ToUInt64(ReverseWord(match.Groups["SoftwareVersion"].Value.Trim()), 16)).ToString()); //device.SoftwareVersion = "1.1";
                    if (device.Snr != null)
                    {
                        device.Notes = "1-й пакет";
                    }
                    if ((Convert.ToUInt32(ReverseWord(match.Groups["FactoryNumber"].Value.Trim()), 16) < 2800000000) || (Convert.ToUInt32(ReverseWord(match.Groups["FactoryNumber"].Value.Trim()), 16) > 2800001000))
                    {
                        device.Notes = "Номер?";
                    }
                    if (match.Groups["RelayStatus"].Value.Trim() == "00" || match.Groups["RelayStatus"].Value.Trim() == "01" || match.Groups["RelayStatus"].Value.Trim() == "02" || match.Groups["RelayStatus"].Value.Trim() == "03")
                    {
                        device.Relay = "выкл.";

                        //string answer = String.Empty;
                        //using (StreamWriter sr3 = File.OpenWrite(AnswerPath))
                        //{
                        //    sr3.WriteLine("06" + match.Groups["FactoryNumber"].Value.Trim() + "010ff0");
                        //}
                        //using (StreamWriter sr3 = File.OpenWrite(AnswerPath))
                        //{
                        //    sr3.WriteLine("02" + match.Groups["FactoryNumber"].Value.Trim() + "0ff0");
                        //}
                        //записать в файл Zapros.txt строку = "06"+match.Groups["FactoryNumber"].Value.Trim()+"010ff0";
                        //записать в файл Zapros.txt строку = "02"+match.Groups["FactoryNumber"].Value.Trim()+"0ff0";
                    }
                    else if (match.Groups["RelayStatus"].Value.Trim() == "04" || match.Groups["RelayStatus"].Value.Trim() == "05" || match.Groups["RelayStatus"].Value.Trim() == "06" || match.Groups["RelayStatus"].Value.Trim() == "07")
                    {
                        device.Relay = "вкл.";
                    }
                }
            }
        }