private void UpdateView(StreamingDataModel streamingDataModel)
        {
            if (streamingDataModel != null && streamingDataModel.StreamInfoNewComingDate > DateTime.MinValue)
            {
                var dateStartMeasurements = streamingDataModel.StreamInfoNewComingDate;

                #region UpdateTextbox

                var prevDate = textBoxDateMesaure.Text;
                if (prevDate != dateStartMeasurements.ToString(DATE_FORMAT))
                {
                    UpdateTextBox(textBoxDateMesaure, dateStartMeasurements.ToString(DATE_FORMAT));
                    UpdateTextBox(textBox_SR, streamingDataModel.SamplingFrequency.ToString());
                    UpdateTextBox(textBox_ActiveSensor, streamingDataModel.NumberOfActivSensors.ToString());
                    UpdateTextBox(textBox_measureCycle_Notif, streamingDataModel.MeasureCycle_Notif.ToString());
                    UpdateTextBox(textBox_acqDuration, streamingDataModel.AcqDuration.ToString());
                }
                UpdateTextBox(textBox_NumberOfDaqPerChannel, streamingDataModel.NumberOfDaqPerChannel.ToString());
                UpdateTextBox(textBox_segmentNumber, streamingDataModel.SegmentNumber.ToString());
                UpdateTextBox(textBox_Lqi_Value, streamingDataModel.Lqi_Value.ToString());
                if (checkBox_Is_DeviceVersionHigherOrEqualThanV3R8.Checked)
                {
                    UpdateTextBox(textBoxSynchro, streamingDataModel.IsSynchronized.ToString());
                }
                else
                {
                    UpdateTextBox(textBoxSynchro, "NA");
                }
                #endregion

                var _Measures    = new List <List <double> >();
                var _Dates       = new List <DateTime>();
                var _Index       = new List <long>();
                var refDate      = this.handler.CurrentStreaming_Date;
                var sensoridList = this.handler.SensIdList;

                this.handler.ExtractMeasurement2(out _Measures, out _Dates, out _Index);
                if (checkBoxScreenLog.Checked)
                {
                    var displayThread = new Thread(new ThreadStart(() => { Work(_Index, _Measures); }));
                    // start the thread
                    displayThread.Start();
                }
                if (checkBoxLogFolder.Checked)
                {
                    AppendData(streamingDataModel, _Index, _Measures);
                }


                //if (checkBoxScreenLog.Checked)
                //{
                //    var displayThread = new Thread(new ThreadStart(() => { Work(Measurements); }));
                //    // start the thread
                //    displayThread.Start();
                //}
            }
        }
        private string BuildFileHeader(StreamingDataModel streamingDataModel)
        {
            var _header = new StringBuilder();

            /* write header into the new file */
            _header.AppendLine("---------------------------------------------------------------------");
            _header.AppendLine("Topic : " + Topic);
            _header.AppendLine("Date : " + streamingDataModel.StreamInfoNewComingDate.ToString(DATE_FORMAT));
            _header.AppendLine("Sampling Frequency(hz) : " + streamingDataModel.SamplingFrequency);
            _header.AppendLine("Daq acq.Cycle(sec) : " + streamingDataModel.MeasureCycle_Notif);
            _header.AppendLine("Daq acq.Duration(sec) : " + streamingDataModel.AcqDuration);
            _header.AppendLine("---------------------------------------------------------------------");
            _header.AppendLine(buildHeader(streamingDataModel.SensIdList));

            return(_header.ToString());
        }
        private void AppendData(StreamingDataModel streamingDataModel, List <long> _Index, List <List <double> > _Measures)

        {
            try
            {
                var    fileNameStart = "TX_";
                string data          = String.Empty;
                String directory     = Settings.SUB_LOG_DIRECTORY;

                if (directory.Length > 0)
                {
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }
                    #region BuilData
                    var sensorlist = this.handler.SensIdList;
                    var str        = new StringBuilder();
                    if (_Index != null && _Measures != null && sensorlist != null &&
                        _Measures.Count == sensorlist.Count &&
                        _Measures[0].Count == _Index.Count)
                    {
                        for (int measureIndex = 0; measureIndex < _Index.Count; measureIndex++)
                        {
                            //0;2.0;.3;...
                            //n_index;2.0;.3;...
                            long   currentIndex = _Index[measureIndex];
                            string line         = currentIndex.ToString();
                            for (int sensorindex = 0; sensorindex < sensorlist.Count; sensorindex++)
                            {
                                double measure = _Measures[sensorindex][measureIndex];
                                line += ";" + measure;
                            }
                            str.AppendLine(line);
                        }
                    }
                    data = str.ToString();
                    #endregion

                    var _fileInfo = GetFileInfo(streamingDataModel.StreamInfoNewComingDate, directory);
                    if (_fileInfo != null)
                    {
                        if (_fileInfo.Exists)
                        {
                            using (TextWriter tw = _fileInfo.AppendText())
                                tw.Write(data);
                        }
                        else
                        {
                            using (TextWriter tw = _fileInfo.CreateText())
                            {
                                if (_fileInfo.FullName.Contains("_part") == false)
                                {
                                    tw.WriteLine(BuildFileHeader(streamingDataModel));
                                }
                                tw.Write(data);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
        }
Пример #4
0
        public StreamingDataModel StreaminSynchronizationFrame(byte[] incomingMessage)
        {
            //Wrong Message
            if (incomingMessage.Length < MIN_MESSAGE_SIZE)
            {
                return(null);
            }
            var model     = new StreamingDataModel();
            int dataIndex = 2;

            this.Message = incomingMessage;

            //--ReferenceTime  4 Byte startIndex=2
            byte[] AUX_DateInUnixTimeFormat = new byte[4];
            Array.Copy(this.Message, dataIndex, AUX_DateInUnixTimeFormat, 0, 4);
            streamInfoNewComingDate = GetTime(AUX_DateInUnixTimeFormat);
            dataIndex += 4;

            // Millisecond =2 Byte startIndex=4
            this.Millisecond = 0;/* should be initialised*/
            //if (this.SOFT_VERS >= BeanComConfig.MIN_SOFT_VERS_SUPPORT_Milliseconds)
            //{
            Millisecond = BitConverter.ToUInt16(incomingMessage, dataIndex);
            dataIndex  += 2;
            // }
            streamInfoNewComingDate       = streamInfoNewComingDate.AddMilliseconds(this.Millisecond);
            model.StreamInfoNewComingDate = streamInfoNewComingDate;

            if (laststreamInfoComingDate != streamInfoNewComingDate)
            {
                laststreamInfoComingDate       = streamInfoNewComingDate;
                BeanAirMqttToolkits.PartNumber = 0;
                System.Diagnostics.Trace.TraceInformation("PartNumber =  " + BeanAirMqttToolkits.PartNumber);
            }

            //--SamplingFreq 2 Byte  startIndex=6
            this.samplingFrequency  = BitConverter.ToUInt16(this.Message, dataIndex);
            model.SamplingFrequency = samplingFrequency;



            dataIndex += 2;
            //--sensorEnabledBitmap    Byte startIndex=8
            this.sensorEnabledBitmap = BitConverter.ToUInt32(this.Message, dataIndex);
            dataIndex += 4;
            sensIdList.Clear();
            for (byte i = 0; i < 5; i++)
            {
                if ((sensorEnabledBitmap & (1 << i)) == (1 << i))
                {
                    sensIdList.Add(i);
                }
            }
            model.SensIdList = sensIdList;


            ///numberOfActivSensors
            this.numberOfActivSensors = (byte)sensIdList.Count;

            model.NumberOfActivSensors = numberOfActivSensors;

            //-- SegmentNumber   Byte startIndex=12
            byte[] FrameSeqId = new byte[4];
            Array.Copy(this.Message, dataIndex, FrameSeqId, 0, 3);
            segmentNumber       = BitConverter.ToUInt32(FrameSeqId, 0);
            dataIndex          += 3;
            model.SegmentNumber = segmentNumber;


            ////NumberOfDaqPerSensor 2 Byte startIndex=15 , NumberOfDaqPerSensor its the number of packet
            NumberOfDaqPerChannel       = BitConverter.ToUInt16(this.Message, dataIndex);
            dataIndex                  += 2;
            model.NumberOfDaqPerChannel = NumberOfDaqPerChannel;

            // measureCycle_Notif;//3byte --- ToDo show notif device working well but there is no alarm s.e.t

            byte[] AUX_measureCycle_Notif = new byte[4];
            Array.Copy(incomingMessage, dataIndex, AUX_measureCycle_Notif, 0, 3);
            var measureCycle_Notif = BitConverter.ToUInt32(AUX_measureCycle_Notif, 0);

            dataIndex += 3;

            model.MeasureCycle_Notif = measureCycle_Notif;


            // acqDuration;//3byte

            byte[] AUX_acqDuration = new byte[4];
            Array.Copy(incomingMessage, dataIndex, AUX_acqDuration, 0, 3);
            var acqDuration = BitConverter.ToUInt32(AUX_acqDuration, 0);

            dataIndex += 3;

            model.AcqDuration = acqDuration;



            byte[] AUX_NumberOfDaqPerChannel_Prev = new byte[2];
            Array.Copy(incomingMessage, dataIndex, AUX_NumberOfDaqPerChannel_Prev, 0, 1);
            NumberOfDaqPerChannel_Prev = BitConverter.ToUInt16(AUX_NumberOfDaqPerChannel_Prev, 0);
            dataIndex += 2;
            if (Is_DeviceVersionHigherOrEqualThanV3R8)
            {
                model.TimeSynchronization = incomingMessage[dataIndex];
                dataIndex++;
            }
            else // these are a freee byte
            {
                dataIndex++;/// free for timeSynchronization
            }

            //Lqi_Value;//1byte
            model.Lqi_Value = incomingMessage[dataIndex];
            dataIndex      += 1;



            if (this.measureModeType == MeasureModeType.StreamingAlarm)
            {
                var FirstChannelAlarmDetected = incomingMessage[dataIndex];
                //BeanLog.Log.Instance.AddLog("FirstChannelAlarmDetected : " + FirstChannelAlarmDetected);
                dataIndex += 1;
            }

            /*_NEW_*/

            if (this.measureModeType == MeasureModeType.ShockDetectEventMode)//case of shock detection
            {
                var shockEventSource = incomingMessage[dataIndex++];
                Array.Copy(incomingMessage, dataIndex, shockvalue, 0, 6);//Schock detection first schock value
                dataIndex += 6;
            }


            DataLength = dynamic// 3byte for each measure
                         * this.numberOfActivSensors
                         * NumberOfDaqPerChannel;

            DYNAMIC_HEADER_LENGTH = dataIndex;


            ////// END UPDATING DATA
            if (CurrentStreaming_Date != streamInfoNewComingDate)//exist but a new one occured
            {
                CurrentStreaming_Date = streamInfoNewComingDate;
            }
            var measureNumber = DataLength;

            measureNumber       /= dynamic * this.numberOfActivSensors;
            calculatedPayDataLen = (measureNumber * dynamic * this.numberOfActivSensors);

            L("NumberOfDaqPerChannel: " + NumberOfDaqPerChannel + "NumberOfDaqPerChannel_Prev : " + NumberOfDaqPerChannel_Prev);

            /* Check data validity with calculated data length */
            if (calculatedPayDataLen != DataLength)
            {
                return(null);
            }
            return(model);
        }