示例#1
0
        public override void CanPacketReceived(CanPacket canPacket)
        {
            if (canPacket == null)
            {
                throw new ArgumentNullException(nameof(canPacket));
            }

            try
            {
                if (isRecording)
                {
                    string newLine = "";
                    packetNumber++;

                    newLine += CanUtilities.AlignLeft(DateTime.Now.ToString("HH:mm:ss.fff"), 14, false);
                    newLine += CanUtilities.AlignLeft(packetNumber.ToString(), 12, true);
                    newLine += CanUtilities.AlignLeft(canPacket.CanIdAsHex, 12, true);
                    newLine += CanUtilities.AlignLeft(canPacket.Flags, 7, true);

                    byte[] dataBytes = canPacket.DataBytes;
                    Array.Reverse(dataBytes, 0, dataBytes.Length);

                    newLine += CanUtilities.AlignLeft("0x" + CanUtilities.ByteArrayToString(dataBytes), 20, true);
                    newLine += CanUtilities.AlignLeft(canPacket.Float1.ToString(), 15, true);
                    newLine += CanUtilities.AlignLeft(canPacket.Float0.ToString(), 15, true);
                    newLine += CanUtilities.AlignLeft(canPacket.SourceIPAddress.ToString(), 7, true);

                    recordStatus = "Recording Can Packet No : " + packetNumber;

                    recordStream.WriteLine(newLine);
                    recordStream.Flush();

                    if (currentDataLoggerConfig.IsRotateByMB())
                    {
                        if (recordStream.BaseStream.Length > currentDataLoggerConfig.RotateBytes())
                        {
                            RollLogAndManage();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
            }
        }
        private void LoadConfigButton_Click(object sender, EventArgs e)
        {
            Stream ioStream;

            this.openFileDialog = new OpenFileDialog
            {
                RestoreDirectory = true,
                Filter           = "DataLogger config files (*.dlconf)|*.dlconf|All files (*.*)|*.*",
                FilterIndex      = 1
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if ((ioStream = openFileDialog.OpenFile()) != null)
                {
                    recordReplayService.StopRecording();
                    UpdateButtons();

                    // Not using the instance here
                    DataLogger dataLoggerConfig = CanRecordReplayDebugService.LoadConfig(ioStream);

                    if (dataLoggerConfig.IsLogToLocalDisk())
                    {
                        logLocally.Checked = true;
                    }
                    else if (dataLoggerConfig.IsLogToFTP())
                    {
                        logViaFTP.Checked = true;
                    }
                    else if (dataLoggerConfig.IsLogToSFTP())
                    {
                        logViaSFTP.Checked = true;
                    }

                    if (dataLoggerConfig.ArchiveLogs)
                    {
                        archive.Checked = true;
                    }
                    if (dataLoggerConfig.CompressLogs)
                    {
                        compress.Checked = true;
                    }
                    if (dataLoggerConfig.LimitArchive)
                    {
                        limitArchive.Checked     = true;
                        ArchiveLimitTextBox.Text = dataLoggerConfig.LimitArchiveFileNum.ToString();
                    }

                    if (dataLoggerConfig.IsRotateByMin())
                    {
                        timeRotate.Checked = true;
                    }
                    else if (dataLoggerConfig.IsRotateByMB())
                    {
                        sizeRotate.Checked = true;
                    }

                    minutesTextBox.Text = dataLoggerConfig.RotateMinutes.ToString();
                    MBtextBox.Text      = dataLoggerConfig.RotateMB.ToString();

                    localDirTextBox.Text   = dataLoggerConfig.LocalDirectory;
                    archiveDirTextBox.Text = dataLoggerConfig.ArchiveDirectory;
                    remoteHostTextBox.Text = dataLoggerConfig.RemoteHost;
                    remotePortTextBox.Text = dataLoggerConfig.RemotePort.ToString();
                    remoteDirTextBox.Text  = dataLoggerConfig.RemoteDirectory;
                    usernameTextBox.Text   = dataLoggerConfig.Username;
                    passwordTextBox.Text   = dataLoggerConfig.Password;
                }
            }

            UpdatePanels();
        }