public BLETestViewModel()
        {
            Title = "BLE Test";

            ConnectCommand = new Command(async() => {
                if (await AnalyzerDevice.ConnectToDeviceAsync())
                {
                    MessagingCenter.Send(this, "DeviceConnectedOk");
                }
                else
                {
                    MessagingCenter.Send(this, "DeviceConnectedFailed");
                }
            });

            TestCommand = new Command(async() => {
                try
                {
                    if (await AnalyzerDevice.TestCommandAsync())
                    {
                        MessagingCenter.Send(this, "DeviceTestOk");
                    }
                    else
                    {
                        MessagingCenter.Send(this, "DeviceTestFailed");
                    }
                }
                catch (Exception ex)
                {
                    MessagingCenter.Send <BLETestViewModel, string>(this, "TestError", ex.Message);
                }
            });
        }
Beispiel #2
0
        public FileListViewModel(SpyFileType fileType)
        {
            files                = new List <SpyFile>();
            isDownloadingList    = false;
            isDownloadedList     = false;
            isDownloadingFile    = false;
            downloadFileProgress = 0;

            downloadFileCommand = new Command <string>(async(fileName) => {
                try
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        foreach (SpyFile file in Files)
                        {
                            file.IsDownloadingFile = true;
                        }

                        IsDownloadingFile = true;
                    });

                    var fileContent = await AnalyzerDevice.GetSpyFile(fileType, fileName);

                    // Devo condividere fileContent, che sarà un byte[]
                    var filePath = Path.Combine(FileSystem.CacheDirectory, fileName);
                    File.WriteAllBytes(filePath, fileContent);

                    await Share.RequestAsync(new ShareFileRequest
                    {
                        Title = Path.GetFileNameWithoutExtension(fileName),
                        File  = new ShareFile(filePath)
                    });
                }
                catch (Exception ex)
                {
                    MessagingCenter.Send <FileListViewModel, string>(this, "DownloadFileError", ex.Message);
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    foreach (SpyFile file in Files)
                    {
                        file.IsDownloadingFile = false;
                    }

                    IsDownloadingFile = true;

                    DownloadFileProgress = 0;
                });
            });

            MessagingCenter.Subscribe <IAnalyzerDevice, double>(this, "DownloadFileProgress", (sender, progress) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    DownloadFileProgress = progress;
                });
            });
        }
Beispiel #3
0
        public async Task DownloadFilesList(SpyFileType fileType)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                IsDownloadingList = true;
            });

            try
            {
                var fileNum = await AnalyzerDevice.GetSpyFileNumber(fileType);

                if (fileNum > 0)
                {
                    var fileNames = await AnalyzerDevice.GetSpyFileNames(fileType);

                    var fileSizes = await AnalyzerDevice.GetSpyFileSizes(fileType);

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        for (int fileIndex = 0; fileIndex < fileNum; fileIndex++)
                        {
                            Files.Add(new SpyFile {
                                FileName          = fileNames[fileIndex],
                                FileSize          = fileSizes[fileIndex],
                                ItemTappedCommand = downloadFileCommand,
                                IsDownloadingFile = false
                            });
                        }
                    });
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    IsDownloadedList = true;
                });
            }
            catch (Exception ex)
            {
                MessagingCenter.Send <FileListViewModel, string>(this, "DownloadFilesListError", ex.Message);
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                IsDownloadingList = false;
            });
        }
        public DeviceSettingsViewModel()
        {
            Title = "Device Settings";

            AppVersion = Assembly.GetEntryAssembly().GetName().Version.ToString();

            ConnectCommand = new Command(async() => {
                Device.BeginInvokeOnMainThread(() =>
                {
                    IsConnecting = true;
                    IsConnected  = false;
                });

                try
                {
                    if (await AnalyzerDevice.ConnectToDeviceAsync())
                    {
                        MessagingCenter.Send <DeviceSettingsViewModel>(this, "DeviceConnectedOk");
                    }
                    else
                    {
                        MessagingCenter.Send <DeviceSettingsViewModel>(this, "DeviceConnectedFailed");
                    }
                }
                catch (Exception ex)
                {
                    MessagingCenter.Send <DeviceSettingsViewModel, string>(this, "DeviceConnectedError", ex.Message);
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    IsConnecting = false;
                    IsConnected  = AnalyzerDevice.IsConnected();

                    if (IsConnected)
                    {
                        SerialNumber    = AnalyzerDevice.GetSerialNumber();
                        FirmwareVersion = AnalyzerDevice.GetFirmwareVersion();
                    }
                });
            });
        }
Beispiel #5
0
        public async void UpdateMonitorBuffer(Object source, ElapsedEventArgs e)
        {
            try
            {
                // Fermo il timer
                requestBufferTimer.Enabled = false;

                var buff = await AnalyzerDevice.GetSpyBuffer((lineNumber == 1)?Services.SpyType.CANSpyOne : Services.SpyType.CANSpyTwo);

                var tempList = new List <CANSpyMessage>();
                for (int messageIndex = 0; messageIndex < buff.Length / CANSpyMessage.StructSize; messageIndex++)
                {
                    var message = new CANSpyMessage();
                    message.Time      = ArrConverter.STM32.GetUInt32FromBuffer(buff, messageIndex * CANSpyMessage.StructSize);
                    message.Id        = ArrConverter.STM32.GetUInt32FromBuffer(buff, (messageIndex * CANSpyMessage.StructSize) + 4);
                    message.DataSize  = buff[(messageIndex * CANSpyMessage.StructSize) + 10];
                    message.IsError   = buff[(messageIndex * CANSpyMessage.StructSize) + 11] != 0x00;
                    message.ErrorCode = ArrConverter.STM32.GetUInt32FromBuffer(buff, (messageIndex * CANSpyMessage.StructSize) + 12);
                    message.Data      = new byte[8];
                    buff.Skip((messageIndex * CANSpyMessage.StructSize) + 16).Take(8).ToArray().CopyTo(message.Data, 0);

                    tempList.Add(message);
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    MonitorBuffer = new List <CANSpyMessage>(tempList);
                });

                // Riavvio il timer
                requestBufferTimer.Enabled = true;
            }
            catch (Exception ex)
            {
                // Riavvio il timer
                requestBufferTimer.Enabled = true;
            }
        }
Beispiel #6
0
        public CANSpyViewModel(int line)
        {
            if (line == 1)
            {
                Title = "CAN Line 1";
            }
            else
            {
                Title = "CAN Line 2";
            }

            bitTimings = new List <int>();
            bitTimings.Add(50000);
            bitTimings.Add(100000);
            bitTimings.Add(125000);
            bitTimings.Add(200000);
            bitTimings.Add(250000);
            bitTimings.Add(400000);
            bitTimings.Add(500000);
            bitTimings.Add(1000000);

            selectedBitTiming = 50000;

            samplingPoints = new List <double>();
            samplingPoints.Add(75.00);
            samplingPoints.Add(87.50);

            selectedSamplingPoint = 75.00;

            frameFormats = new List <string>();
            FrameFormats.Add(frameFormat11Bit);
            FrameFormats.Add(frameFormat29Bit);

            selectedFrameFormat = frameFormat11Bit;

            enableErrorReception = true;
            applyMask            = false;

            lineNumber = line;

            isSpying = false;

            requestBufferTimer          = new Timer(5000);
            requestBufferTimer.Elapsed += UpdateMonitorBuffer;

            requestBufferTimer.AutoReset = true;
            requestBufferTimer.Enabled   = false;

            MonitorBuffer = new List <CANSpyMessage>();

            StartCommand = new Command(async() =>
            {
                try
                {
                    var param       = new CANSpyParameters();
                    param.BitTiming = SelectedBitTiming;
                    //param.SamplingPoint = SelectedSamplingPoint;

                    if (selectedFrameFormat == frameFormat11Bit)
                    {
                        param.FrameFormat = CANSpyParameters.SimpleFrameFormat;
                    }
                    else
                    {
                        param.FrameFormat = CANSpyParameters.LongFrameFormat;
                    }

                    param.ErrorReception = EnableErrorReception;
                    param.ApplyMask      = ApplyMask;
                    param.Mask           = Convert.ToUInt32(Mask, 16);
                    param.ID             = Convert.ToUInt32(ID, 16);

                    if (lineNumber == 1)
                    {
                        await AnalyzerDevice.SetCANParametersAsync(Services.SpyType.CANSpyOne, param);
                        await AnalyzerDevice.StartSpyAsync(Services.SpyType.CANSpyOne);
                    }
                    else if (lineNumber == 2)
                    {
                        await AnalyzerDevice.SetCANParametersAsync(Services.SpyType.CANSpyTwo, param);
                        await AnalyzerDevice.StartSpyAsync(Services.SpyType.CANSpyTwo);
                    }

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        IsSpying = true;
                    });

                    requestBufferTimer.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessagingCenter.Send <CANSpyViewModel, string>(this, "StartError", ex.Message);
                }
            });

            StopCommand = new Command(async() =>
            {
                try
                {
                    if (lineNumber == 1)
                    {
                        await AnalyzerDevice.StopSpyAsync(Services.SpyType.CANSpyOne);
                    }
                    else if (lineNumber == 2)
                    {
                        await AnalyzerDevice.StopSpyAsync(Services.SpyType.CANSpyTwo);
                    }

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        IsSpying = false;
                    });

                    requestBufferTimer.Enabled = false;
                }
                catch (Exception ex)
                {
                    MessagingCenter.Send <CANSpyViewModel, string>(this, "StopError", ex.Message);
                }
            });
        }