/// <summary> /// Get ADC Details from response packet /// </summary> /// <param name="receivedPacket"></param> private void GetADCDetails(Packet.Packet receivedPacket) { try { adclist = new ArrayList(); receivedPacket.CurrentPos = 0; List<ConfigurationVO> configlist = ApplicationUtil.ApplicationUtil.ReadconfigCsvfile(); List<ADCVO> firstChannel = new List<ADCVO>(); List<ADCVO> secondChannel = new List<ADCVO>(); List<ADCVO> singleChannel = new List<ADCVO>(); receivedPacket.UseLittleEndian = true; // if ( (adc_resolution == 2) || (adc_resolution == 3) && isContineousStartClick) { if (neglectValue) { Array.Resize(ref receivedPacket.DataArray, receivedPacket.DataArray.Length + 1); Array.Copy(receivedPacket.DataArray, 0, receivedPacket.DataArray, 1, receivedPacket.DataArray.Length - 1); receivedPacket.CurrentPos = 0; receivedPacket.Append(lastRemoveByte); if (IsEvenValue(receivedPacket.DataArray.Length)) { m_logger.Debug("E"); NUMBER_OF_RECORDS += 1; } neglectValue = false; } if (!IsEvenValue(receivedPacket.DataArray.Length)) { m_logger.Debug("O"); neglectValue = true; receivedPacket.CurrentPos = receivedPacket.DataArray.Length - 1; lastRemoveByte = receivedPacket.RemoveByte(); } receivedPacket.UseLittleEndian = false; receivedPacket.CurrentPos = 0; m_logger.Debug("N : " + NUMBER_OF_RECORDS + " L : " + responsePacket.DataArray.Length); } for (int i = 0; i < NUMBER_OF_RECORDS; i++) { if (receivedPacket.CurrentPos + 2 < receivedPacket.DataLength) { ADCVO adc = new ADCVO(); //receivedPacket.UseLittleEndian = true; //if (adc_resolution == EnumAndConstants.BIT_CHECKER) receivedPacket.UseLittleEndian = false; adc.AdcValue = receivedPacket.RemoveInt16(); //else if (adc_resolution == 2) //{ // adc.AdcValue = receivedPacket.RemoveUInt16(); // adc.AdcValue &= 0x3ff; //} //else if (adc_resolution == 3) //{ // adc.AdcValue = (receivedPacket.RemoveUInt16() & 0xfff); // adc.AdcValue &= 0xfff; //} //receivedPacket.UseLittleEndian = false; //m_logger.Debug("AV : " + adc.AdcValue); if (sampling_rate == 0) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 100; AdcCurrentDate = AdcCurrentDate.AddTicks(1000000); } if (sampling_rate == EnumAndConstants.BIT_CHECKER) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.5; AdcCurrentDate = AdcCurrentDate.AddTicks(5000); } else if (sampling_rate == 2) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.3333; AdcCurrentDate = AdcCurrentDate.AddTicks(3333); } else if (sampling_rate == 3) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.2500; AdcCurrentDate = AdcCurrentDate.AddTicks(2500); } else if (sampling_rate == 4) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.2000; AdcCurrentDate = AdcCurrentDate.AddTicks(2000); } else if (sampling_rate == 5) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.1666; AdcCurrentDate = AdcCurrentDate.AddTicks(1666); } else if (sampling_rate == 6) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.1000; AdcCurrentDate = AdcCurrentDate.AddTicks(1000); } else if (sampling_rate == 7) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.0833; AdcCurrentDate = AdcCurrentDate.AddTicks(833); } else if (sampling_rate == 8) { ApplicationUtil.ApplicationUtil.SAMPLING_RATE_DATE_ADD_VALUE = 0.0666; AdcCurrentDate = AdcCurrentDate.AddTicks(666); } adc.AdcDate = AdcCurrentDate; if (i == 0 && adc.AdcValue == 0) continue; if (isBothClicked) { if (IsEvenValue(i)) { adc.Channel = ChannelA; firstChannel.Add(adc); m_logger.Debug(ChannelA, adc.AdcDate, adc.AdcValue); } else { adc.Channel = ChannelB; secondChannel.Add(adc); m_logger.Debug(ChannelB, adc.AdcDate, adc.AdcValue); } } else { adc.Channel = ChannelA; singleChannel.Add(adc); m_logger.Debug(ChannelA, adc.AdcDate, adc.AdcValue); } } } // m_logger.Debug("AdcCurrentDate : " + AdcCurrentDate.Ticks); if (singleChannel.Count == 0) { adclist.Add(firstChannel); adclist.Add(secondChannel); //m_logger.Debug(ChannelA, firstChannel,secondChannel); } else { adclist.Add(singleChannel); } if (isContineousStartClick) { ApplicationUtil.ApplicationUtil.adcValueList = singleChannel; } else { ApplicationUtil.ApplicationUtil.adcValueList = null; } if (stateVar.packetState != PacketState.CONTINUOUS_ADC_COUNT) { stateVar = new ReadState(); stateVar.packetState = PacketState.START_OF_PACKET; stateVar.currentPos = 0; } int operationMode = configlist[0].mode_operation; //if (Channel > 2) // Channel = 1; ArrayList comblist = new ArrayList(); ArrayList comblist_Other = new ArrayList(); comblist.Add(configlist); comblist.Add(adclist);//create arraylist containing configlist and adclist if (adclist == null || adclist.Count == 0) return; fileName = ApplicationUtil.ApplicationUtil.GetFileNameWithDateTime(EnumAndConstants.CSV_FORMAT);//get name of file if (ApplicationUtil.ApplicationUtil.CurrentFolderPath == "" || ApplicationUtil.ApplicationUtil.CurrentFolderPath == null) { ApplicationUtil.ApplicationUtil.CurrentFolderPath = Path.Combine(ApplicationUtil.ApplicationUtil.GetApplicationPath(), ApplicationUtil.ApplicationUtil.GetFileNameWithDateTime("")); } directory = Path.Combine(ApplicationUtil.ApplicationUtil.CurrentFolderPath, fileName); if (stateVar.packetState != PacketState.CONTINUOUS_ADC_COUNT) { //directory = System.Configuration.ConfigurationManager.AppSettings["DirectoryPath"]; try { if (!Directory.Exists(ApplicationUtil.ApplicationUtil.CurrentFolderPath) && ApplicationUtil.ApplicationUtil.IsDirectoryCreateAllowed == true) { if (!Directory.Exists(ApplicationUtil.ApplicationUtil.CurrentFolderPath)) { Directory.CreateDirectory(ApplicationUtil.ApplicationUtil.CurrentFolderPath+"1"); Directory.Delete(ApplicationUtil.ApplicationUtil.CurrentFolderPath+"1"); } } // throw new IOException(); } catch (IOException e) { ApplicationUtil.ApplicationUtil.IsDirectoryCreateAllowed = false; if (DirectoryCreationErrorEvent != null) DirectoryCreationErrorEvent(ApplicationUtil.ApplicationUtil.CurrentFolderPath); } } if (operationMode == 1) confirmation = true; FileObjectVO file = new FileObjectVO(); //CacheStore.getInstance().comblist = null; //CacheStore.getInstance().ChannelA = ChannelA; //CacheStore.getInstance().ChannelB = ChannelB; //CacheStore.getInstance().directory = directory; //CacheStore.getInstance().comblist = comblist; file.Data = comblist; file.channel1 = ChannelA; file.channel2 = ChannelB; file.filePath = directory; FileLoggingQueue.EnqueObject(file); isDataReceived = true; //ApplicationUtil.ApplicationUtil.addFileNameToList(configlist[0].ChannelValue, fileName); //ApplicationUtil.ApplicationUtil.CreateCsvArrayList(comblist, directory, ChannelA, ChannelB);//create arraylist containing configlist adclist and directories //if (CreateNewFile == true) //{ // ApplicationUtil.ApplicationUtil.CreateCsvArrayListVersion2(comblist,directory, ChannelA, ChannelB, true); //} //else //{ // //ApplicationUtil.ApplicationUtil.CreateCsvArrayList(comblist, directory, ChannelA, ChannelB);//create arraylist containing configlist adclist and directories // ApplicationUtil.ApplicationUtil.CreateCsvArrayListVersion2(comblist, directory, ChannelA, ChannelB, false); //} // read the csv for both channels selected mode //if (filecreateEvent != null) // filecreateEvent(directory); } catch (Exception ex) { m_logger.Error(ex); } }
/// <summary> /// Parsing of Data packet /// </summary> /// <param name="receivedPacket"></param> public void ParsingData(Packet.Packet receivedPacket) { int responceId = -1; try { receivedPacket.CurrentPos = 0; receivedPacket.RemoveBytes(EnumAndConstants.CONSTANT_VALUE);//SOF receivedPacket.RemoveByte();//Protocol version receivedPacket.RemoveByte();//Unique number responceId = receivedPacket.RemoveByte();//Request ID : 6 int PacketLength = receivedPacket.RemoveByte(); //Packet length if ((responceId == (int)ADCStatus.START_ADC || responceId == (int)ADCStatus.END_ADC) && isNewRequestSend == true) { return; } if (responceId == (int)ADCStatus.START_ADC || responceId == (int)ADCStatus.END_ADC) { GetTriggerModeRequest(receivedPacket, responceId); return; } isNewRequestSend = false; if (PacketLength > 0) { GetConfigurationDetails(receivedPacket); } receivedPacket.RemoveByte(); //CRC waitHandle.Set(); } catch (Exception ex) { m_logger.Error(ex); } }
/// <summary> /// Get configuration details and create CSV /// </summary> /// <param name="receivedPacket"></param> private static void GetConfigurationDetails(Packet.Packet receivedPacket) { try { ConfigurationVO configVo = ConfigurationVO.GetInstance(); //receivedPacket.RemoveByte(); configVo.mode_operation = receivedPacket.RemoveByte(); //Mode of Operation configVo.NumberOfSelectedChannels = receivedPacket.RemoveByte(); configVo.ChannelValue = receivedPacket.RemoveUInt16(); // Channel //configVo.adcresolution = receivedPacket.RemoveByte(); // ADC resolution //adc_resolution = configVo.adcresolution; configVo.sampaling_rate = receivedPacket.RemoveByte(); // Sampling rate sampling_rate = configVo.sampaling_rate; // MAITREYEE:two paramters added according to the new requirement. configVo.T5VDAC = receivedPacket.RemoveByte(); configVo.T7VDAC = receivedPacket.RemoveByte(); receivedPacket.UseLittleEndian = true; configVo.T1 = receivedPacket.RemoveUInt16(); configVo.T2 = receivedPacket.RemoveUInt16(); configVo.T3 = receivedPacket.RemoveUInt16(); configVo.T4 = receivedPacket.RemoveUInt16(); configVo.T5 = receivedPacket.RemoveUInt16(); configVo.T6 = receivedPacket.RemoveUInt16(); configVo.T7 = receivedPacket.RemoveUInt16(); configVo.T8 = receivedPacket.RemoveUInt16(); configVo.T9 = receivedPacket.RemoveUInt16(); configVo.T10 = receivedPacket.RemoveUInt16(); receivedPacket.UseLittleEndian = false; List<ConfigurationVO> configlist = new List<ConfigurationVO>(); configlist.Add(configVo); string applicationConfigurationPath = ApplicationUtil.ApplicationUtil.GetApplicationPath(); applicationConfigurationPath += EnumAndConstants.CONFIGURATION_FILE; if (ApplicationUtil.ApplicationUtil.CheckFileExists(applicationConfigurationPath) == true) { File.Delete(applicationConfigurationPath); } ApplicationUtil.ApplicationUtil.CreateCSVFromGenericList(configlist, applicationConfigurationPath); //if (null != SetStatusEvent) // SetStatusEvent(true, true); } catch (Exception ex) { m_logger.Error(ex); } }
/// <summary> /// Get trigger mode values /// </summary> /// <param name="receivedPacket"></param> /// <param name="responceId"></param> private void GetTriggerModeRequest(Packet.Packet receivedPacket, int responceId) { if (responceId == (int)ADCStatus.START_ADC) { //TODO : Make 2 bytes ChannelValue = receivedPacket.RemoveUInt16();//CHANNEL ID //if (ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue == 0) //{ // ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue = ChannelValue; //} //else //{ // if (ChannelValue == ApplicationUtil.ApplicationUtil.FirstRecievedChannelValue) // { // CreateNewFile = true; // } //} List<int> channels = new List<int>(); ApplicationUtil.ApplicationUtil.GetValueFromNumber(ChannelValue, out channels); if (channels.Count == 1 && channels.Count!=0) { //adc_resolution = 1; ChannelA = channels[0]; ChannelB = -1; isBothClicked = false; } else if (channels.Count > 1 && channels.Count != 0) { //adc_resolution = 0; ChannelA = channels[0]; ChannelB = channels[1]; isBothClicked = true; } //As per new Doc //adc_resolution = receivedPacket.RemoveByte();//adc resolution //TODO : 2 byte sampling_rate = receivedPacket.RemoveByte();//sampling rate receivedPacket.UseLittleEndian = true; NUMBER_OF_RECORDS = receivedPacket.RemoveUInt16();//Number of records //if (adc_resolution != EnumAndConstants.BIT_CHECKER) //{ // NUMBER_OF_RECORDS /= 2; //} receivedPacket.UseLittleEndian = false; stateVar = new ReadState(); stateVar.currentPos = 0; stateVar.packetState = PacketState.ADC_COUNT; //if (adc_resolution == EnumAndConstants.BIT_CHECKER) //{ stateVar.ReadBuffer = new byte[NUMBER_OF_RECORDS * EnumAndConstants.CONSTANT_VALUE]; //} //else //{ // stateVar.ReadBuffer = new byte[NUMBER_OF_RECORDS * EnumAndConstants.CONSTANT_VALUE]; //} } receivedPacket.RemoveByte(); //CRC waitHandle.Set(); }