void ShellClass::digitalWriteCmd(String& params){
	int pin = nextParam(params).toInt();
	int level = nextParam(params).toInt();

	if (g_APinDescription[pin].ulPinType == PIO_NOT_A_PIN){
		Log.e(SHELL_TAG) << F("Pin number ") << pin << F(" is not a valid digital I/O pin for this board") << Endl;
	}
	else{
		pinMode(pin, OUTPUT);
		digitalWrite(pin, level);
		Log.i(SHELL_TAG) << F("OK") << Endl;
	}
}
void ShellClass::analogWriteCmd(String& params){
	int pin = A0 + nextParam(params).toInt();
	int value = nextParam(params).toInt();

	uint32_t attr = g_APinDescription[pin].ulPinAttribute;

	if ((attr & PIN_ATTR_ANALOG) != PIN_ATTR_ANALOG && (attr & PIN_ATTR_PWM) != PIN_ATTR_PWM){
		Log.e(SHELL_TAG) << F("Pin number A") << pin << F(" is not a valid analog I/O pin for this board") << Endl;
	}
	else{
		pinMode(pin, OUTPUT);
		analogWrite(pin, value);
		Log.i(SHELL_TAG) << F("OK") << Endl;
	}
}
//S
void ShellClass::SDMkDirCmd(String& params){
	String path = nextParam(params);

	if (SD.mkdir(path)){
		Log.i(SHELL_TAG) << F("OK") << Endl;
	}
	else{
		Log.e(SHELL_TAG) << F("Error creating new directory: is SD inserted?") << Endl;
	}
}
void ShellClass::channelValueCmd(String& params){
	int id = nextParam(params).toInt();
	Channel* c = channelsConfig.getChannelByID(id);

	if (c == NULL){
		Log.e(SHELL_TAG) << F("Channel not found") << Endl;
	}
	else{
		Log.i(SHELL_TAG) << c->getID() << "\t" << channelsBuffer.getValueAsString(id) << "\t" << channelsBuffer.getValueAsByteArray(id).toHexString() << Endl;
	}
}
//Cmds
//A
void ShellClass::analogReadCmd(String& params){
	int pin = A0 + nextParam(params).toInt();
	uint32_t attr = g_APinDescription[pin].ulPinAttribute;

	if ((attr & PIN_ATTR_ANALOG) != PIN_ATTR_ANALOG){
		Log.e(SHELL_TAG) << F("Pin number A") << pin << F(" is not a valid analog I/O pin for this board") << Endl;
	}
	else{
		pinMode(pin, INPUT);
		Log.i(SHELL_TAG) << F("Readed ") << analogRead(pin) << Endl;
	}
}
void ShellClass::SDRmCmd(String& params){
	String path = nextParam(params);

	if (SD.exists(path)){
		if (SD.remove(path)){
			Log.i(SHELL_TAG) << F("OK") << Endl;
		}
		else{
			Log.e(SHELL_TAG) << F("Error deleting file") << Endl;
		}
	}
	else{
		Log.e(SHELL_TAG) << F("File not found") << Endl;
	}
}
void ShellClass::SDRmDirCmd(String& params){
	String path = nextParam(params);

	if (SD.exists(path)){
		if (SD.rmdir(path)){
			Log.i(SHELL_TAG) << F("OK") << Endl;
		}
		else{
			Log.e(SHELL_TAG) << F("Error deleting directory") << Endl;
		}
	}
	else{
		Log.e(SHELL_TAG) << F("Directory not found") << Endl;
	}

}
void ShellClass::SDOpenCmd(String& params){
	String path = nextParam(params);

	if (SD.exists(path)){
		File f = SD.open(path);
		f.setTimeout(100);
		if (f){
			while (f.available()){
				Log.i(SHELL_TAG) << f.readStringUntil('\n') << Endl;
			}
			f.close();
		}
		else{
			Log.e(SHELL_TAG) << F("Error opening file") << Endl;
		}
	}
	else{
		Log.e(SHELL_TAG) << F("File not found") << Endl;
	}
}
Пример #9
0
char getChar(char sep, istream& I) {
  nextParam(sep, I);
  char c; 
  I>>c;
  return c;
}
Пример #10
0
void getStr(char sep, istream& I, char* s) {
  nextParam(sep, I);
  I>>s;
}
Пример #11
0
int getInt(char sep, istream& I) {
  nextParam(sep, I);
  int i;
  I>>i;  // get the number
  return i;
}
Пример #12
0
unsigned long getLongInt(char sep, istream& I) {
  nextParam(sep, I);
  unsigned long i;
  I>>i;  // get the number
  return i;
}
Пример #13
0
double getDouble(char sep, istream& I) {
  nextParam(sep, I);
  double d;
  I>>d;  // get the number
  return d;
}
Пример #14
0
void ViBenchMarker3::process2()
{
	int time = mTime.elapsed();
	QObject::disconnect(mCurrentObject.data(), SIGNAL(noiseGenerated()), this, SLOT(process2()));

	/*QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit()));
	mCurrentObject->encode(ViAudio::Noise);
	return;*/

	qreal maxMAT = 0;
	qint64 maxTP = 0, maxTN = 0, maxFP = 0, maxFN = 0;
	qint64 i, lengthIndex, offset1 = 0, offset2 = 0;
	int noChange = 0;

	ViAudioReadData corrupted(mCurrentObject->buffer(ViAudio::Noise));
	ViAudioReadData realMask(mCurrentObject->buffer(ViAudio::CustomMask));
	ViAudioReadData length(mCurrentObject->buffer(ViAudio::Custom));
	corrupted.setSampleCount(WINDOW_SIZE);
	realMask.setSampleCount(WINDOW_SIZE);
	length.setSampleCount(WINDOW_SIZE);

	ViSampleChunk *nData1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nData2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nRealMask1 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nRealMask2 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nLength1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nLength2 = new ViSampleChunk(corrupted.bufferSamples() / 2);

	while(corrupted.hasData() && realMask.hasData())
	{
		corrupted.read();
		ViSampleChunk &corrupted1 = corrupted.splitSamples(0);
		ViSampleChunk &corrupted2 = corrupted.splitSamples(1);

		realMask.read();
		ViSampleChunk &realMask1 = realMask.splitSamples(0);
		ViSampleChunk &realMask2 = realMask.splitSamples(1);

		length.read();
		ViSampleChunk &length1 = length.splitSamples(0);
		ViSampleChunk &length2 = length.splitSamples(1);

		for(i = 0; i < corrupted1.size(); ++i)
		{
			(*nData1)[i + offset1] = corrupted1[i];
			(*nRealMask1)[i + offset1] = realMask1[i];
			(*nLength1)[i + offset1] = length1[i];
		}
		offset1 += corrupted1.size();
		for(i = 0; i < corrupted2.size(); ++i)
		{
			(*nData2)[i + offset2] = corrupted2[i];
			(*nRealMask2)[i + offset2] = realMask2[i];
			(*nLength2)[i + offset2] = length2[i];
		}
		offset2 += corrupted2.size();
	}

	mCurrentObject->clearBuffer(ViAudio::Target);
	mCurrentObject->clearBuffer(ViAudio::Noise);
	mCurrentObject->clearBuffer(ViAudio::NoiseMask);

	ViNoise noise1(nData1, nMask1, mCurrentThreshold);
	ViNoise noise2(nData2, nMask2, mCurrentThreshold);

	QVector<qreal> lengthTP(ViNoiseCreator::noiseSizeCount());
	QVector<qreal> lengthFN(ViNoiseCreator::noiseSizeCount());
	lengthTP.fill(0);
	lengthFN.fill(0);
	QVector<qreal> maxLengthTP, maxLengthFN;

	for(mCurrentThreshold = MASK_START; mCurrentThreshold <= MASK_END; mCurrentThreshold += MASK_INTERVAL)
	{
		noise1.setThreshold(mCurrentThreshold);
		noise1.generateMask(ViNoise::NOISE_TYPE);
		noise2.setThreshold(mCurrentThreshold);
		noise2.generateMask(ViNoise::NOISE_TYPE);

		qint64 truePositives = 0, falsePositives = 0, trueNegatives = 0, falseNegatives = 0;

		for(i = 0; i < nRealMask1->size(); ++i)
		{
			if((*nRealMask1)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength1)[i]) - 1;
				if((*nMask1)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask1)[i] == 0)
			{
				if((*nMask1)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		for(i = 0; i < nRealMask2->size(); ++i)
		{
			if((*nRealMask2)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength2)[i]) - 1;
				if((*nMask2)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask2)[i] == 0)
			{
				if((*nMask2)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		qreal math = matthews(truePositives, trueNegatives, falsePositives, falseNegatives);
		if(math > maxMAT)
		{
			maxMAT = math;
			maxTP = truePositives;
			maxTN = trueNegatives;
			maxFP = falsePositives;
			maxFN = falseNegatives;
			maxLengthTP = lengthTP;
			maxLengthFN = lengthFN;
			noChange = 0;
		}
		++noChange;
		if(noChange > NO_CHANGE) break;
	}

	delete nRealMask1;
	delete nRealMask2;
	delete nLength1;
	delete nLength2;

	++mDoneParamIterations;
	if(maxMAT > mBestMatthews) mBestMatthews = maxMAT;
	printFileData(time, maxTP, maxTN, maxFP, maxFN, maxLengthTP, maxLengthFN);
	printTerminal(time, maxTP, maxTN, maxFP, maxFN, mBestMatthews);

	if(nextParam()) process1(false);
	else nextFile();
}