<commit_before>#include "hardware/parsing/Samples.h"
#include "exception/Base.h"

namespace blitzortung {
  namespace hardware {
    namespace parsing {

      Samples::Samples(const std::vector<std::string> fields, const hardware::gps::Base& gps) :
	Base()
      {
	data::Format::CP dataFormat;
	pt::ptime eventtime;
	pt::time_duration sampleDt;

	// the counter value is always at the second position
	eventtime = gps.getTime(parseHex(fields[1]));

	if (fields[0] == "BLSIG") {
	  if (fields.size() > 3) {
	    if (fields[2].size() == 2 && fields[3].size() ==2) {
	      // BLSIG type 1
	      dataFormat = data::Format::CP(new data::Format(8, 2, 1));
	      sampleDt = pt::nanoseconds(0);
	      rawData_ = fields[2] + fields[3];
	    } else if (fields[2].size() == 3 && fields[3].size() ==3) {
	      // BLSIG type 2
	      dataFormat = data::Format::CP(new data::Format(12, 2, 1));
	      sampleDt = pt::nanoseconds(0);
	      rawData_ = fields[2] + fields[3];
	    }
	  }
	} else if (fields[0] == "BLSEQ") {
	  if (fields[2].size() == 256) {
	    // BLSIG type 2
	    dataFormat = data::Format::CP(new data::Format(8, 2, 64));
	    sampleDt = pt::nanoseconds(3125);
	    rawData_ = fields[2];
	  }
	} else if (fields[0] == "BD") {
	  if (fields[2].size() == 256) {
	    // BD type 1
	    dataFormat = data::Format::CP(new data::Format(8, 2, 64));
	    sampleDt = pt::nanoseconds(2930);
	    rawData_ = fields[2];
	  }
	} else if (fields[0] == "BM") {
	  // BM type 1
	  dataFormat = data::Format::CP(new data::Format(8, 1, 128));
	  sampleDt = pt::nanoseconds(2930);
	  rawData_ = fields[2];
	}

	// parse lighning event information

	

	if (gps.isValid() && eventtime != pt::not_a_date_time) {
	  int numberOfEvents = rawData_.size() >> 2;

	  data::Array::AP array(new data::Array(dataFormat));

	  unsigned short hexCharsPerSample = (dataFormat->getNumberOfBitsPerSample() + 3 ) / 4;
	  unsigned short numberOfChannels = dataFormat->getNumberOfChannels();
	  int offset = 1 << (dataFormat->getNumberOfBitsPerSample() - 1);

	  for (int sample=0; sample < numberOfEvents; sample++) {

	    int index = sample * hexCharsPerSample;

	    for (int channel=0; channel < numberOfChannels; channel++) {
	      array->set(parseHex(rawData_.substr(index, hexCharsPerSample)) - offset, sample, channel);
	    }
	  }

	  waveform_ = data::Waveform::AP(new data::Waveform(array, eventtime, sampleDt));
	  valid_ = true;
	}

      }

      data::Waveform::AP Samples::getWaveform() {
	return waveform_;
      }

      const std::string& Samples::getRawData() const {<commit_msg>fix parsing of sample data for more than one channel<commit_after>#include "hardware/parsing/Samples.h"
#include "exception/Base.h"

namespace blitzortung {
  namespace hardware {
    namespace parsing {

      Samples::Samples(const std::vector<std::string> fields, const hardware::gps::Base& gps) :
	Base()
      {
	data::Format::CP dataFormat;
	pt::ptime eventtime;
	pt::time_duration sampleDt;

	// the counter value is always at the second position
	eventtime = gps.getTime(parseHex(fields[1]));

	if (fields[0] == "BLSIG") {
	  if (fields.size() > 3) {
	    if (fields[2].size() == 2 && fields[3].size() ==2) {
	      // BLSIG type 1
	      dataFormat = data::Format::CP(new data::Format(8, 2, 1));
	      sampleDt = pt::nanoseconds(0);
	      rawData_ = fields[2] + fields[3];
	    } else if (fields[2].size() == 3 && fields[3].size() ==3) {
	      // BLSIG type 2
	      dataFormat = data::Format::CP(new data::Format(12, 2, 1));
	      sampleDt = pt::nanoseconds(0);
	      rawData_ = fields[2] + fields[3];
	    }
	  }
	} else if (fields[0] == "BLSEQ") {
	  if (fields[2].size() == 256) {
	    // BLSIG type 2
	    dataFormat = data::Format::CP(new data::Format(8, 2, 64));
	    sampleDt = pt::nanoseconds(3125);
	    rawData_ = fields[2];
	  }
	} else if (fields[0] == "BD") {
	  if (fields[2].size() == 256) {
	    // BD type 1
	    dataFormat = data::Format::CP(new data::Format(8, 2, 64));
	    sampleDt = pt::nanoseconds(2930);
	    rawData_ = fields[2];
	  }
	} else if (fields[0] == "BM") {
	  // BM type 1
	  dataFormat = data::Format::CP(new data::Format(8, 1, 128));
	  sampleDt = pt::nanoseconds(2930);
	  rawData_ = fields[2];
	}

	// parse lighning event information

	

	if (gps.isValid() && eventtime != pt::not_a_date_time) {
	  int numberOfEvents = rawData_.size() >> 2;

	  data::Array::AP array(new data::Array(dataFormat));

	  unsigned short hexCharsPerSample = (dataFormat->getNumberOfBitsPerSample() + 3 ) / 4;
	  unsigned short numberOfChannels = dataFormat->getNumberOfChannels();
	  int offset = 1 << (dataFormat->getNumberOfBitsPerSample() - 1);

	  for (int sample=0; sample < numberOfEvents; sample++) {

	    int index = sample * hexCharsPerSample;

	    for (int channel=0; channel < numberOfChannels; channel++) {
	      array->set(parseHex(rawData_.substr(index + hexCharsPerSample * channel, hexCharsPerSample)) - offset, sample, channel);
	    }
	  }

	  waveform_ = data::Waveform::AP(new data::Waveform(array, eventtime, sampleDt));
	  valid_ = true;
	}

      }

      data::Waveform::AP Samples::getWaveform() {
	return waveform_;
      }

      const std::string& Samples::getRawData() const {
{'fraction_non_alphanumeric': 0.16829595552999807, 'fraction_numerical': 0.02875215641173088, 'mean_word_length': 3.399662731871838, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1995617', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1778, 'n_words': 405}