Exemplo n.º 1
0
unsigned int Element::getNeighbors( vector< Id >& ret, const Finfo* finfo )
	const
{
	assert( finfo );
	
	const SrcFinfo* srcF = dynamic_cast< const SrcFinfo* >( finfo );
	const DestFinfo* destF = dynamic_cast< const DestFinfo* >( finfo );
	const SharedFinfo* sharedF = dynamic_cast< const SharedFinfo* >( finfo );
	assert( srcF || destF || sharedF );

	ret.resize( 0 );
	
	if ( srcF )
		return getOutputs( ret, srcF );
	else if ( destF )
		return getInputs( ret, destF );
	else
		if ( ! sharedF->src().empty() )
			return getOutputs( ret, sharedF->src().front() );
		else if ( ! sharedF->dest().empty() ) {
			Finfo* subFinfo = sharedF->dest().front();
			const DestFinfo* subDestFinfo =
				dynamic_cast< const DestFinfo* >( subFinfo );
			assert( subDestFinfo );
			return getInputs( ret, subDestFinfo );
		} else {
			assert( 0 );
		}
	return 0;
}
Exemplo n.º 2
0
// Reactivates all following Plugins
void ParameterFileModel::reactivate(){
    QString tmpPrefix = _prefix;
    QStringList outputsOfOneSlot;
    int parameterIndex = 0;
    for (int p = 0; p < _keys.size(); p++){
        if (_keys[p].contains("active")){
            parameterIndex = p;
            break;
        }
    }
    if (getValue(_keys[parameterIndex]) == "false"){
        setValue(_keys[parameterIndex], "true");
        for (int i = 0; i < tmpPrefix.size(); i++){
            if (tmpPrefix.at(i) == '.'){
                tmpPrefix.truncate(i);
            }
        }
        for (int i = 0; i < getOutputs(tmpPrefix).size(); i++){
            if (getValue(tmpPrefix + "."+ getOutputs(tmpPrefix).at(i)).contains(";")){
                outputsOfOneSlot = getValue(tmpPrefix + "."+ getOutputs(tmpPrefix).at(i)).split(";");
                for (int o = 0; o < outputsOfOneSlot.size(); o++){
                    setPrefix(outputsOfOneSlot.at(o));
                    reactivate();
                }
            }
            else if (getValue(tmpPrefix + "."+ getOutputs(tmpPrefix).at(i)) != ""){
                setPrefix(getValue(tmpPrefix + "."+ getOutputs(tmpPrefix).at(i)));
                reactivate();
            }
        }

    }
}
float Filter::process(float in)
{
  //TODO: add a flag to calculate coefficients here instead of calculating them at every param change

  common::add_dc(in);
  if (m_mode == k_filter_off)
    return in;
  //"clamping" with tanh
/*#if defined(WIN32)
  in = tanhf(in);
#else
  in = dnload_tanhf(in);
#endif*/

  //svf process implementation
  --m_calc_interval;
  if (m_calc_coefficients)
    if (m_calc_interval < 0)
    {
      calculateCoefficients();
      m_calc_interval = STATE_CALC_INTERVAL;
    }
  float yL, yB, yH;
  getOutputs(in, yL, yB, yH);

#if defined(APPROXIMATE_TANH)
  return m_output_level * common::rational_tanh((m_c_low * yL + m_c_band * yB + m_c_high * yH)*(1.0f + (3.0f*m_drive)));
#else
#if defined(WIN32)
  return m_output_level * tanhf((m_c_low * yL + m_c_band * yB + m_c_high * yH)*(1.0f+(3.0f*m_drive)));
#else
  return m_output_level * dnload_tanhf((m_c_low * yL + m_c_band * yB + m_c_high * yH)*(1.0f + (3.0f*m_drive)));
#endif
#endif
}
Exemplo n.º 4
0
void ANN::activate(const std::vector<double>& instance, std::vector<double>& result ){
	result.clear();
	// Layer loop
	for( int i = 0; i < network.size(); i++){
		// Neuron loop. For every neuron, activate on output of previous layer
		// or instance if input layer.
		std::vector<double> lastOutputs;
		if( i != 0 ){ getOutputs( i - 1, lastOutputs);} 
		for( int j = 0; j < network[i].size(); j++ ){
			// if input layer, pass instance.
			if( i == 0 ){
				network[i][j]->activate( instance );
			}
			// Otherwise pass last layers outputs
			else{
				// If last activation, save outputs for return
				if( i == network.size() - 1 ){
					result.push_back(network[i][j]->activate(lastOutputs));
				}
				else{
					network[i][j]->activate(lastOutputs);
				}
			}
		}
	}
	//std::cout << "DONE" << std::endl;
}
Exemplo n.º 5
0
void CodecCommander::onTimerAction()
{
    // if infinite checks are enabled - essentially are for monitoring fugue state, sleep is fine with finite check
    if (checkInfinite) {
        // check if hda codec is powered
        parseCodecPowerState();
        // if no power after semi-sleep (fugue) state and power was restored - set EAPD bit
        if (eapdPoweredDown && (hdaCurrentPowerState == 0x1 || hdaCurrentPowerState == 0x2)) {
            DEBUG_LOG("CodecCommander: cc: --> hda codec power restored\n");
            setOutputs();
            // if popping requested - generate stream at fugue-wake
            if (!coldBoot && generatePop){
                createAudioStream();
            }
            // simulate headphone jack replug
            simulateHedphoneJack(); // <------ makes sure this is needed?
        }
    }
    
    // check if audio stream is up on given output
    parseAudioEngineState();
    // get EAPD bit status from command response if audio stream went up
    if (hdaEngineState == 0x1) {
        getOutputs();
         // if engine output stream has started, but EAPD isn't up
        if(response == 0x0) {
            // set EAPD bit
            setOutputs();
        }
    }

    fTimer->setTimeoutMS(updateInterval);
}
Exemplo n.º 6
0
SoUnknownEngine::~SoUnknownEngine()
//
////////////////////////////////////////////////////////////////////////
{
    //
    // The fields of the unknown engine have been allocated by the SoFieldData
    // class.  The unknown engine will delete them here, because the field
    // data does not have enough information to know where its fields are
    // stored.  This could be redesigned.
    //
    SoFieldList fieldList;
    int         numFields = getFields(fieldList);

    for (int i=0; i<numFields; i++)
        delete fieldList[i];

    // Delete the Engine Outputs that have also been allocated.
    SoEngineOutputList outputList;
    int         numOutputs = getOutputs(outputList);

    for (int j=0; j<numOutputs; j++)
        delete outputList[j];

    if (className) free((void *)className);
}
static void getOutputs_test( void ) {
    Network *network;
    int *outputs;

    network = setupTestNetwork();

    network->testInputs[0] = 0; network->testInputs[1] = 1;
    outputs = getOutputs( network );
    assert( outputs != NULL && "Should have had some outputs returned" );
    assert( outputs[0] == 4 && outputs[1] == 5 && "Wrong outputs returned" );

    network->testInputs[0] = 2; network->testInputs[1] = 3;
    outputs = getOutputs( network );
    assert( outputs != NULL && "Should have had some outputs returned" );
    assert( outputs[0] == 6 && outputs[1] == 7 && "Wrong outputs returned" );
}
Exemplo n.º 8
0
void Node::disconnectAllOutputs()
{
	NodeRef thisRef = shared_from_this();

	auto outputs = getOutputs(); // first make a copy of only the still-alive NodeRef's
	for( const auto &output : outputs )
		disconnect( output );
}
Exemplo n.º 9
0
float FCNetwork::squaredError(const Vector &targets) {
    Vector outputs = getOutputs();
    assert(targets.rows() == outputs.rows());

    float sum = 0;
    for (int i = 0; i < outputs.rows(); ++i)
        sum += (outputs[i] - targets[i]) * (outputs[i] - targets[i]);

    return 0.5f * sum;
}
Exemplo n.º 10
0
float FCNetwork::flatError(const Vector &targets) {
    Vector outputs = getOutputs();
    assert(targets.rows() == outputs.rows());

    float sum = 0;
    for (int i = 0; i < outputs.rows(); ++i)
        sum += std::abs(outputs[i] - targets[i]);

    return sum / outputs.rows();
}
Exemplo n.º 11
0
void NodeAutoPullable::updatePullMethod()
{
	bool hasOutputs = ! getOutputs().empty();
	if( ! hasOutputs && ! mIsPulledByContext ) {
		mIsPulledByContext = true;
		getContext()->addAutoPulledNode( shared_from_this() );
	}
	else if( hasOutputs && mIsPulledByContext ) {
		mIsPulledByContext = false;
		getContext()->removeAutoPulledNode( shared_from_this() );
	}
}
Exemplo n.º 12
0
 RadialCorrectionInversionCostFunction(
         RadialCorrection &input,
         RadialCorrection &guess,
         int steps,
         int h, int w
 ) : FunctionArgs(MODEL_SIZE, getOutputs(steps)),
     mInput(input),
     mGuess(guess),
     mSteps(steps),
     mH(h),
     mW(w)
 {}
Exemplo n.º 13
0
	void DocumentDatasLinksList::updateLinks(const graphics::DrawColors& colors)
	{
		LinksList::updateLinks(colors);

		auto pen = colors.penColor;
		int inputIndex = 0, outputIndex = 0;
		for (const auto& gdr : m_documentDatasView.dataRects())
		{
			const auto data = gdr.first;
			const auto& dataRect = gdr.second;
			if (data->isInput())
			{
				auto d1 = dataRect.center();
				for (const auto& output : data->getOutputs())
				{
					if (BaseData* data = dynamic_cast<BaseData*>(output))
					{
						Rect dataRect;
						if (!getDataRect(data, dataRect))
							continue;

						auto d2 = dataRect.center();
						Point w = { (d2.x - d1.x) / 2, 0 };
						m_linksDrawList->addBezierCurve(d1, d1 + w, d2 - w, d2, pen, 1);
					}
				}
			}
		
			if (data->isOutput())
			{
				auto d2 = dataRect.center();
				for (const auto& input : data->getInputs())
				{
					if (BaseData* data = dynamic_cast<BaseData*>(input))
					{
						Rect dataRect;
						if (!getDataRect(data, dataRect))
							continue;

						auto d1 = dataRect.center();
						Point w = { (d2.x - d1.x) / 2, 0 };
						m_linksDrawList->addBezierCurve(d1, d1 + w, d2 - w, d2, pen, 1);
					}
				}
			}
		}
	}
Exemplo n.º 14
0
long Scene::replace(unsigned long oldID, sptr<IAction> newNode){
	std::lock_guard<std::recursive_mutex> lock(mMutex);
	if(!isPartOfScene(oldID) || !newNode || isPartOfScene(newNode->getID())){
		throw MaudioException("cannot replace!");
	}
	std::vector<unsigned long> inputs = getInputs(oldID);
	std::vector<unsigned long> outputs = getOutputs(oldID);
	remove(oldID);
	add(newNode);
	for(unsigned int i = 0; i < inputs.size(); i++){
		connect(inputs[i], newNode->getID());
	}
	for(unsigned int i = 0; i < outputs.size(); i++){
		connect(newNode->getID(), outputs[i]);
	}
	return newNode->getID();
}
Exemplo n.º 15
0
void Scene::remove(unsigned long id){
	std::lock_guard<std::recursive_mutex> lock(mMutex);
	if(!isPartOfScene(id)) return;
	std::vector<unsigned long> inputs = getInputs(id);
	std::vector<unsigned long> outputs = getOutputs(id);
	
	for(unsigned int i = 0; i < inputs.size(); i++){
		disconnect(inputs[i], id);
	}
	for(unsigned int i = 0; i < outputs.size(); i++){
		disconnect(id, outputs[i]);
	}
	mNodes.erase(mNodes.find(id));
	mAdjacencyList.erase(mAdjacencyList.find(id));
	notifyObservers(ON_CHANGE, "node removed");
	return;
}
Exemplo n.º 16
0
void BlockBrowser::updateExplorer(bool block)
{    
    if(block)
    {
        ui->heightLabel->show();
        ui->heightLabel_2->show();
        ui->hashLabel->show();
        ui->hashBox->show();
        ui->merkleLabel->show();
        ui->merkleBox->show();
        ui->nonceLabel->show();
        ui->nonceBox->show();
        ui->bitsLabel->show();
        ui->bitsBox->show();
        ui->timeLabel->show();
        ui->timeBox->show();
        ui->hardLabel->show();
        ui->hardBox->show();;
        ui->pawLabel->show();
        ui->pawBox->show();
        int height = ui->heightBox->value();
        if (height > pindexBest->nHeight)
        {
            ui->heightBox->setValue(pindexBest->nHeight);
            height = pindexBest->nHeight;
        }
        int Pawrate = getBlockHashrate(height);
        double Pawrate2 = 0.000;
        Pawrate2 = ((double)Pawrate / 1000);
        std::string hash = getBlockHash(height);
        std::string merkle = getBlockMerkle(height);
        int nBits = getBlocknBits(height);
        int nNonce = getBlockNonce(height);
        int atime = getBlockTime(height);
        double hardness = getBlockHardness(height);
        QString QHeight = QString::number(height);
        QString QHash = QString::fromUtf8(hash.c_str());
        QString QMerkle = QString::fromUtf8(merkle.c_str());
        QString QBits = QString::number(nBits);
        QString QNonce = QString::number(nNonce);
        QString QTime = QString::number(atime);
        QString QHardness = QString::number(hardness, 'f', 6);
        QString QPawrate = QString::number(Pawrate2, 'f', 3);
        ui->heightLabel->setText(QHeight);
        ui->hashBox->setText(QHash);
        ui->merkleBox->setText(QMerkle);
        ui->bitsBox->setText(QBits);
        ui->nonceBox->setText(QNonce);
        ui->timeBox->setText(QTime);     
        ui->hardBox->setText(QHardness);
        ui->pawBox->setText(QPawrate + " KH/s");
    } 
    
    if(block == false) {
        ui->txID->show();
        ui->txLabel->show();
        ui->valueLabel->show();
        ui->valueBox->show();
        ui->inputLabel->show();
        ui->inputBox->show();
        ui->outputLabel->show();
        ui->outputBox->show();
        ui->feesLabel->show();
        ui->feesBox->show();
        std::string txid = ui->txBox->text().toUtf8().constData();
        double value = getTxTotalValue(txid);
        double fees = getTxFees(txid);
        std::string outputs = getOutputs(txid);
        std::string inputs = getInputs(txid);
        QString QValue = QString::number(value, 'f', 6);
        QString QID = QString::fromUtf8(txid.c_str());
        QString QOutputs = QString::fromUtf8(outputs.c_str());
        QString QInputs = QString::fromUtf8(inputs.c_str());
        QString QFees = QString::number(fees, 'f', 6);
        ui->valueBox->setText(QValue + " FNX");
        ui->txID->setText(QID);
        ui->outputBox->setText(QOutputs);
        ui->inputBox->setText(QInputs);
        ui->feesBox->setText(QFees + " FNX");
    }
}
Exemplo n.º 17
0
int main() {

    double inputs[MAX_NO_OF_INPUTS];
    double outputTargets[MAX_NO_OF_OUTPUTS];

    /* determine layer paramaters */
    int noOfLayers = 2; // input layer excluded
    int noOfNeurons[] = {10,1};
    int noOfInputs[] = {2,10};
    char axonFamilies[] = {'g','l'};
    double actFuncFlatnesses[] = {1,1,1};

    createNet(noOfLayers, noOfNeurons, noOfInputs, axonFamilies, actFuncFlatnesses, 1);

    /* train it using batch method */
    int i;
    double tempTotal1, tempTotal2;
    int counter = 0;
    for(i = 0; i < TRAINING_ITERATION; i++) {
        inputs[0] = getRand();
        inputs[1] = getRand();
        inputs[2] = getRand();
        inputs[3] = getRand();
        tempTotal1 = inputs[0] + inputs[1];
        tempTotal2 = inputs[2] - inputs[3];
        // tempTotal = inputs[0] + inputs[1];
        feedNetInputs(inputs);
        updateNetOutput();
        // outputTargets[0] = sin(tempTotal1)*2+0.5*exp(tempTotal2)-cos(inputs[1]+inputs[3])/2;
        outputTargets[0] = sin(tempTotal1)*2+0.5*exp(tempTotal2);
 //       outputTargets[1] = (double)cos(tempTotal);
        /* train using batch training ( don't update weights, just cumulate them ) */
        //trainNet(0, 0, 1, outputTargets);
        trainNet(0, 0, 1, outputTargets);
        counter++;
        /* apply batch changes after 100 loops use .8 learning rate and .8 momentum */
        if(counter == 100) { applyBatchCumulations(.3,.3); counter = 0;}  //!~~~swd: should be within (0,1)
    }

    /* test it */
    double *outputs;
    double target_out[50];
    double actual_out[50];
    printf("Sin Target \t Output \n");
    printf("---------- \t -------- \t ---------- \t --------\n");
    for(i = 0; i < 50; i++) {
        inputs[0] = getRand();
        inputs[1] = getRand();
        inputs[2] = getRand();
        inputs[3] = getRand();
        tempTotal1 = inputs[0] + inputs[1];
        tempTotal2 = inputs[2] - inputs[3];

	target_out[i] = sin(tempTotal1)*2+0.5*exp(tempTotal2);
    // target_out[i] = sin(tempTotal1)*2+0.5*exp(tempTotal2)-cos(inputs[1]+inputs[3])/2;

        feedNetInputs(inputs);
        updateNetOutput();
        outputs = getOutputs();

	actual_out[i] = outputs[0];
	

        printf( "%f \t %f \n", target_out[i], actual_out[i]);
    }
    
    float Rsquared_ans=Rsquared(target_out, actual_out, 50);
    printf("Result Summary: \n");
    printf("The Rsquared Value is : %f \n", Rsquared_ans);
    printf("finish!!!\n");

    //getch();
    return 0;

}
Exemplo n.º 18
0
void CAnalogueRepeaterApp::createThread()
{
	CAnalogueRepeaterThread* thread = new CAnalogueRepeaterThread;

	wxString openId, closeId, beacon1, beacon2;
	unsigned int speed, freq;
	wxFloat32 level1, level2;
	AUDIO_SOURCE openIdSource, closeIdSource, beacon1Source, beacon2Source;
	getCallsign(openIdSource, openId, closeIdSource, closeId, beacon1Source, beacon1, beacon2Source, beacon2, speed, freq, level1, level2);
	wxLogInfo(wxT("Open ID source: %d, value: \"%s\", close ID source: %d, value: \"%s\", beacon 1 source: %d, value: \"%s\", beacon 2 source: %d, value: \"%s\", speed: %u WPM, freq: %u Hz, level1: %.3f, level2: %.3f"), int(openIdSource), openId.c_str(), int(closeIdSource), closeId.c_str(), int(beacon1Source), beacon1.c_str(), int(beacon2Source), beacon2.c_str(), speed, freq, level1, level2);

	IFixedAudioSource* openIdAudio  = NULL;
	IFixedAudioSource* closeIdAudio = NULL;
	IFixedAudioSource* beacon1Audio = NULL;
	IFixedAudioSource* beacon2Audio = NULL;

	switch (openIdSource) {
		case AS_CW_KEYER:
			openIdAudio = new CCWKeyer(openId, speed, freq, ANALOGUE_RADIO_SAMPLE_RATE);
			break;
		case AS_WAV_FILE: {
				CWAVFileStore* audio = new CWAVFileStore;
				bool res = audio->load(openId, ANALOGUE_RADIO_SAMPLE_RATE);
				if (!res)
					delete audio;
				else
					openIdAudio = audio;
			}
			break;
	}

	switch (closeIdSource) {
		case AS_CW_KEYER:
			closeIdAudio = new CCWKeyer(closeId, speed, freq, ANALOGUE_RADIO_SAMPLE_RATE);
			break;
		case AS_WAV_FILE: {
				CWAVFileStore* audio = new CWAVFileStore;
				bool res = audio->load(closeId, ANALOGUE_RADIO_SAMPLE_RATE);
				if (!res)
					delete audio;
				else
					closeIdAudio = audio;
			}
			break;
	}

	switch (beacon1Source) {
		case AS_CW_KEYER:
			beacon1Audio = new CCWKeyer(beacon1, speed, freq, ANALOGUE_RADIO_SAMPLE_RATE);
			break;
		case AS_WAV_FILE: {
				CWAVFileStore* audio = new CWAVFileStore;
				bool res = audio->load(beacon1, ANALOGUE_RADIO_SAMPLE_RATE);
				if (!res)
					delete audio;
				else
					beacon1Audio = audio;
			}
			break;
	}

	switch (beacon2Source) {
		case AS_CW_KEYER:
			beacon2Audio = new CCWKeyer(beacon2, speed, freq, ANALOGUE_RADIO_SAMPLE_RATE);
			break;
		case AS_WAV_FILE: {
				CWAVFileStore* audio = new CWAVFileStore;
				bool res = audio->load(beacon2, ANALOGUE_RADIO_SAMPLE_RATE);
				if (!res)
					delete audio;
				else
					beacon2Audio = audio;
			}
			break;
	}

	thread->setCallsign(openIdAudio, closeIdAudio, beacon1Audio, beacon2Audio, level1, level2);

	wxString radioAck, extAck, batteryAck;
	unsigned int ack, minimum;
	wxFloat32 level;
	AUDIO_SOURCE radioAckSource, extAckSource, batteryAckSource;
	getAck(radioAckSource, radioAck, extAckSource, extAck, batteryAckSource, batteryAck, speed, freq, level, ack, minimum);
	wxLogInfo(wxT("Radio ack source: %d, radio ack: \"%s\", network ack source: %d, network ack: \"%s\", battery ack source: %d, battery ack: \"%s\", speed: %u WPM, freq: %u Hz, level: %.3f, ack: %u ms, minimum: %u ms"), int(radioAckSource), radioAck.c_str(), int(extAckSource), extAck.c_str(), int(batteryAckSource), batteryAck.c_str(), speed, freq, level, ack, minimum);

	IFixedAudioSource* radioAckAudio   = NULL;
	IFixedAudioSource* extAckAudio     = NULL;
	IFixedAudioSource* batteryAckAudio = NULL;

	switch (radioAckSource) {
		case AS_CW_KEYER:
			radioAckAudio = new CCWKeyer(radioAck, speed, freq, ANALOGUE_RADIO_SAMPLE_RATE);
			break;
		case AS_WAV_FILE: {
				CWAVFileStore* audio = new CWAVFileStore;
				bool res = audio->load(radioAck, ANALOGUE_RADIO_SAMPLE_RATE);
				if (!res)
					delete audio;
				else
					radioAckAudio = audio;
			}
			break;
	}

	switch (extAckSource) {
		case AS_CW_KEYER:
			extAckAudio = new CCWKeyer(extAck, speed, freq, ANALOGUE_RADIO_SAMPLE_RATE);
			break;
		case AS_WAV_FILE: {
				CWAVFileStore* audio = new CWAVFileStore;
				bool res = audio->load(extAck, ANALOGUE_RADIO_SAMPLE_RATE);
				if (!res)
					delete audio;
				else
					extAckAudio = audio;
			}
			break;
	}

	switch (batteryAckSource) {
		case AS_CW_KEYER:
			batteryAckAudio = new CCWKeyer(batteryAck, speed, freq, ANALOGUE_RADIO_SAMPLE_RATE);
			break;
		case AS_WAV_FILE: {
				CWAVFileStore* audio = new CWAVFileStore;
				bool res = audio->load(extAck, ANALOGUE_RADIO_SAMPLE_RATE);
				if (!res)
					delete audio;
				else
					batteryAckAudio = audio;
			}
			break;
	}

	thread->setAck(radioAckAudio, extAckAudio, batteryAckAudio, level, ack, minimum);

	unsigned int callsignTime, timeout, lockoutTime, hangTime, latchTime;
	getTimes(callsignTime, timeout, lockoutTime, hangTime, latchTime);
	thread->setTimes(callsignTime, timeout, lockoutTime, hangTime, latchTime);
	wxLogInfo(wxT("Times set to: callsign time: %u secs, timeout: %u secs, lockout time: %u secs, hang time: %u secs, latch time: %u secs"), callsignTime, timeout, lockoutTime, hangTime, latchTime);

	bool tbEnable, ctcssInternal;
	wxFloat32 tbThreshold, ctcssFreq, ctcssThresh, ctcssLevel;
	unsigned int ctcssHangTime;
	ANALOGUE_CTCSS_OUTPUT ctcssOutput;
	getTones(tbEnable, tbThreshold, ctcssFreq, ctcssInternal, ctcssThresh, ctcssLevel, ctcssHangTime, ctcssOutput);
	thread->setTones(tbEnable, tbThreshold, ctcssFreq, ctcssInternal, ctcssThresh, ctcssLevel, ctcssHangTime, ctcssOutput);
	wxLogInfo(wxT("Tones set to: toneburst enable: %u, threshold: %.3f, CTCSS freq: %.1f Hz, internal: %u, threshold: %.3f, level: %.3f, hang time: %u ms, output: %d"), tbEnable, tbThreshold, ctcssFreq, ctcssInternal, ctcssThresh, ctcssLevel, ctcssHangTime * 20U, ctcssOutput);

	ANALOGUE_CALLSIGN_START callsignAtStart;
	unsigned int callsignStartDelay;
	bool callsignAtEnd;
	ANALOGUE_TIMEOUT_TYPE timeoutType;
	ANALOGUE_CALLSIGN_HOLDOFF callsignHoldoff;
	getFeel(callsignAtStart, callsignStartDelay, callsignAtEnd, timeoutType, callsignHoldoff);
	thread->setFeel(callsignAtStart, callsignStartDelay, callsignAtEnd, timeoutType, callsignHoldoff);
	wxLogInfo(wxT("Feel set to: callsignAtStart: %d, callsignStartDelay: %u s, callsignAtEnd: %u, timeoutType: %d, callsignHoldoff: %d"), callsignAtStart, callsignStartDelay, callsignAtEnd, timeoutType, callsignHoldoff);

	wxString readDevice, writeDevice;
	unsigned int audioDelay;
	bool deEmphasis, preEmphasis, vogad;
	getRadio(readDevice, writeDevice, audioDelay, deEmphasis, preEmphasis, vogad);
	wxLogInfo(wxT("Radio soundcard set to %s:%s, delay: %u ms, de-emphasis: %d, pre-emphasis %d, vogad: %d"), readDevice.c_str(), writeDevice.c_str(), audioDelay * 20U, int(deEmphasis), int(preEmphasis), int(vogad));

	if (!readDevice.IsEmpty() && !writeDevice.IsEmpty()) {
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, ANALOGUE_RADIO_SAMPLE_RATE, ANALOGUE_RADIO_BLOCK_SIZE);
		soundcard->setCallback(thread, SOUNDCARD_RADIO);

		bool res = soundcard->open();
		if (!res)
			wxLogError(wxT("Cannot open the radio sound card"));
		else
			thread->setRadio(soundcard, audioDelay, deEmphasis, preEmphasis, vogad);
	}

	wxString type;
	unsigned int pttDelay, squelchDelay, cfg;
	bool pttInvert, squelchInvert;
	getController(type, cfg, pttDelay, squelchDelay, pttInvert, squelchInvert);
	wxLogInfo(wxT("Controller set to %s, config: %u, ptt delay: %u ms, squelch delay: %u ms, ptt invert: %d, squelch invert: %d"), type.c_str(), cfg, pttDelay * 20U, squelchInvert * 20U, pttInvert, squelchInvert);

	CExternalController* controller = NULL;

	wxString port;
	if (type.StartsWith(wxT("Velleman K8055 - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CExternalController(new CK8055Controller(num), pttInvert, squelchInvert);
	} else if (type.StartsWith(wxT("Serial - "), &port)) {
		controller = new CExternalController(new CSerialLineController(port, cfg), pttInvert, squelchInvert);
	} else if (type.StartsWith(wxT("Arduino - "), &port)) {
		controller = new CExternalController(new CArduinoController(port), pttInvert, squelchInvert);
#if defined(GPIO)
	} else if (type.IsSameAs(wxT("GPIO"))) {
		controller = new CExternalController(new CGPIOController(cfg), pttInvert, squelchInvert);
#endif
	} else {
		controller = new CExternalController(new CDummyController, pttInvert, squelchInvert);
	}

	bool res = controller->open();
	if (!res)
		wxLogError(wxT("Cannot open the hardware interface - %s"), type.c_str());
	else
		thread->setController(controller, pttDelay, squelchDelay);

	ANALOGUE_EXTERNAL_MODE mode;
	wxString device;
	SERIALPIN txPin, rxPin;
	bool background;
	getExternal(mode, readDevice, writeDevice, audioDelay, deEmphasis, preEmphasis, vogad, device, txPin, rxPin, background);
	wxLogInfo(wxT("External mode: %d, soundcard set to %s:%s, delay: %u ms, de-emphasis: %d, pre-emphasis %d, vogad: %u, interface set to %s, tx %d, rx %d, background: %d"), mode, readDevice.c_str(), writeDevice.c_str(), audioDelay * 20U, int(deEmphasis), int(preEmphasis), int(vogad), device.c_str(), txPin, rxPin, int(background));

	if (mode != AEM_DISABLED) {
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, ANALOGUE_RADIO_SAMPLE_RATE, ANALOGUE_RADIO_BLOCK_SIZE);
		soundcard->setCallback(thread, SOUNDCARD_EXTERNAL);

		bool res = soundcard->open();
		if (!res) {
			wxLogError(wxT("Cannot open the external sound card"));
		} else {
			// This works even for an empty device name
			CNetworkController* controller = new CNetworkController(device, txPin, rxPin);

			res = controller->open();
			if (!res)
				wxLogError(wxT("Cannot open serial port - %s"), device.c_str());
			else
				thread->setExternal(mode, soundcard, audioDelay, deEmphasis, preEmphasis, vogad, controller, background);
		}
	}

	bool out1, out2, out3, out4;
	getOutputs(out1, out2, out3, out4);
	thread->setOutputs(out1, out2, out3, out4);
	m_frame->setOutputs(out1, out2, out3, out4);
	wxLogInfo(wxT("Output 1: %d, output 2: %d, output 3: %d, output 4: %d"), out1, out2, out3, out4);

	bool dtmfRadio, dtmfExternal;
	wxString dtmfShutdown, dtmfStartup, dtmfTimeout, dtmfTimeReset, dtmfOutput1, dtmfOutput2, dtmfOutput3, dtmfOutput4;
	wxString dtmfCommand1, dtmfCommand1Line, dtmfCommand2, dtmfCommand2Line;
	wxFloat32 dtmfThreshold;
	getDTMF(dtmfRadio, dtmfExternal, dtmfShutdown, dtmfStartup, dtmfTimeout, dtmfTimeReset, dtmfCommand1, dtmfCommand1Line, dtmfCommand2, dtmfCommand2Line, dtmfOutput1, dtmfOutput2, dtmfOutput3, dtmfOutput4, dtmfThreshold);
	thread->setDTMF(dtmfRadio, dtmfExternal, dtmfShutdown, dtmfStartup, dtmfTimeout, dtmfTimeReset, dtmfCommand1, dtmfCommand1Line, dtmfCommand2, dtmfCommand2Line, dtmfOutput1, dtmfOutput2, dtmfOutput3, dtmfOutput4, dtmfThreshold);
	wxLogInfo(wxT("DTMF: Radio: %d, External: %d, Shutdown: %s, Startup: %s, Timeout: %s, Time Reset: %s, Command1: %s = %s, Command2: %s = %s, Output1: %s, Output2: %s, Output3: %s, Output4: %s, Threshold: %f"), dtmfRadio, dtmfExternal, dtmfShutdown.c_str(), dtmfStartup.c_str(), dtmfTimeout.c_str(), dtmfTimeReset.c_str(), dtmfCommand1.c_str(), dtmfCommand1Line.c_str(), dtmfCommand2.c_str(), dtmfCommand2Line.c_str(), dtmfOutput1.c_str(), dtmfOutput2.c_str(), dtmfOutput3.c_str(), dtmfOutput4.c_str(), dtmfThreshold);

	unsigned int activeHangTime;
	getActiveHang(activeHangTime);
	thread->setActiveHang(activeHangTime);
	wxLogInfo(wxT("Active Hang: time: %u"), activeHangTime);

	// Convert the worker class into a thread
	m_thread = new CAnalogueRepeaterThreadHelper(thread);
	m_thread->start();
}
Exemplo n.º 19
0
int main(int argc, const char * argv[]) {

    // Implementing MNIST character recognition

    /*
     * RESULTS:
     * 50 trainings - 50 hidden, .45 learning : 96.77% (only trial) <-- CURRENT BEST!!
     * 50 trainings - 45 hidden, .4 learning : 96.74% (only trial) 
     * 50 trainings - 40 hidden, .25 learning : 96.16% (best trial of 2)
     * 50 trainings - 35 hidden, .35 learning : 96.18% (only trial)
     * 50 trainings - 30 hidden, .4 learning : 95.47% (only trial)
     * 50 trainings - 25 hidden, .4 learning : 94.95% (only trial)
     * 50 trainings - 20 hidden, .5 learning : 93.97% (only trial)
     *
     *
     * Note: It seems I was overfitting, not sure if this was
     * a waste of time or a lesson (probably both). I can train
     * 10 or more times less than the 50 trainings I was using
     * before and still get ~96% accuracy on the testing set.
     * However, with less training, I don't overfit the training
     * set as much, allowing better accuracy with more general
     * testing data, e.g. the handwritten digits collected from
     * my friends and colleagues.
     *
     * P.S. Even with only 3 trainings, 96% accuracy is still achievable
     *
     * P.S.S. Two trainings yielded poorer results on friend set
     *
     * Higher hidden layer widths seem to do better - getting into 97%
     *
     */

    // If changing parameters, make sure to change export filename


/*
 * Preprocessor macros/conditionals to make
 * switching between training and utilizing
 * easier - relies on this TRAINING definition
 */

// #define TRAINING


#define IMAGE_START 16
#define LABEL_START 8
#define NUM_PIXELS 784
#define NUM_OUTPUTS 10

#ifdef TRAINING
    // EACH LEARNING FROM SCRATCH VERSION
    std::vector<unsigned int> hiddenSizes = {80};
    auto netTest = new NeuralNetwork(NUM_PIXELS, 1, NUM_OUTPUTS, hiddenSizes, sigmoid, sigmoidPrime, 0.5, 0.4, 0.2);
#endif

#ifndef TRAINING
    // CONTINUED LESSONS VERSION
    auto netTest = new NeuralNetwork("saved/mnist_048545.json");
#endif

    std::vector<double> input = {};
    std::vector<double> expected = {};

#ifdef TRAINING
    std::ifstream trainingImages;
    std::ifstream trainingLabels;
    trainingImages.open("mnist_data/train_images", ios::in | ios::binary);
    trainingLabels.open("mnist_data/train_labels", ios::in | ios::binary);
#endif

    char read;

#define NUM_TRAININGS 4
#define NUM_TRAINING_DIGITS 60000
#define HUNDREDTHS_OF_PERCENT_PER_TRAINING 2500 // 100 * (100 / NUM_TRAININGS)
#define TRAININGS_PER_HUNDREDTH_OF_PERCENT 24 // NUM_TRAINING_DIGITS / HUNDREDTHS_OF_PERCENT_PER_TRAINING

#ifdef TRAINING
    //Training loop
    for (unsigned int j = 0; j < NUM_TRAININGS; j++) {
        trainingImages.seekg(IMAGE_START);
        trainingLabels.seekg(LABEL_START);

        for (unsigned int i = 0; i < NUM_TRAINING_DIGITS; i++) {
            if (i % TRAININGS_PER_HUNDREDTH_OF_PERCENT == 0) {
                int curr_percent = (j * HUNDREDTHS_OF_PERCENT_PER_TRAINING) + (1 * i/TRAININGS_PER_HUNDREDTH_OF_PERCENT);
                if (curr_percent) printf("\r");
                std::cout << curr_percent/100 << ".";
                std::cout << ((curr_percent%100 < 10) ? "0" : "") << curr_percent%100;
                std::cout << "% done training..." << std::flush;
            }

            // Setup
            input.clear();
            expected.clear();
            for (unsigned int k = 0; k < NUM_PIXELS; k++) {
                trainingImages.read((&read), 1);
                input.push_back((double)((unsigned char)read)/255);
            }
            trainingLabels.read((&read), 1);
            for (unsigned int k = 0; k < 10; k++) {
                    expected.push_back(0);
            }
            expected.at(read) = 1;

            netTest->propagate(&input, &expected);
        }
    }

    std::cout << "\r100% done training!" << std::endl;
#endif

    std::ifstream testImages;
    std::ifstream testLabels;

#ifndef TRAINING
    testImages.open("mnist_preprocessing/converted/converted_images", ios::in | ios::out | ios::binary);
    testLabels.open("mnist_preprocessing/converted/converted_labels", ios::in | ios::out | ios::binary);
#endif

#ifdef TRAINING    
    testImages.open("mnist_data/test_images", ios::in | ios::out | ios::binary);
    testLabels.open("mnist_data/test_labels", ios::in | ios::out | ios::binary);
#endif

    testImages.seekg(IMAGE_START);
    testLabels.seekg(LABEL_START);

    unsigned int numCorrect = 0;

#ifndef TRAINING
    #define NUM_TESTS 80
#else
    #define NUM_TESTS 10000
#endif

    for (unsigned int j = 0; j < NUM_TESTS; j++) {
        // Setup
        input.clear();
        expected.clear();

        for (unsigned int k = 0; k < NUM_PIXELS; k++) {
            testImages.read((&read), 1);
            input.push_back((double)((unsigned char)read)/255);
        }
        testLabels.read((&read), 1);
        for (unsigned int k = 0; k < 10; k++) {
                expected.push_back(0);
        }
        expected.at(read) = 1;

        std::cout << "Expected digit: " << (unsigned int)read << std::endl;

        printDigitAscii(&input);

        std::vector<double> output = netTest->getOutputs(&input);

        unsigned int outputDigit = determineDigit(&output);

        std::cout << "Output digit: " << outputDigit << std::endl;

        if (outputDigit == (unsigned int)read) {
            numCorrect++;
        }
    }

#ifndef TRAINING
    #define DIVISOR 0.8
#else
    #define DIVISOR 100
#endif

    std::cout << "Total number correct: " << numCorrect << std::endl;
    std::cout << "Percentage correct: " << (double)numCorrect / DIVISOR << '%' << std::endl;

#ifdef TRAINING
    std::cout << "Writing network to file..." << std::endl;
    netTest->exportNN("saved/mnist_0480504020.json"); // Export network to file
    std::cout << "File written!" << std::endl;
#endif

    return 0;
}
Exemplo n.º 20
0
void CGMSKRepeaterApp::createThread()
{
	wxString callsign, gateway;
	DSTAR_MODE mode;
	ACK_TYPE ack;
	bool restriction, rpt1Validation;
	getCallsign(callsign, gateway, mode, ack, restriction, rpt1Validation);

	IGMSKRepeaterThread* thread = NULL;
	switch (mode) {
		case MODE_RXONLY:
			thread = new CGMSKRepeaterRXThread;
			break;
		case MODE_TXONLY:
			thread = new CGMSKRepeaterTXThread;
			break;
		case MODE_TXANDRX:
			thread = new CGMSKRepeaterTXRXThread;
			break;
		default:
			thread = new CGMSKRepeaterTRXThread;
			break;
	}

	thread->setCallsign(callsign, gateway, mode, ack, restriction, rpt1Validation);
	wxLogInfo(wxT("Callsign set to \"%s\", gateway set to \"%s\", mode: %d, ack: %d, restriction: %d, RPT1 validation: %d"), callsign.c_str(), gateway.c_str(), int(mode), int(ack), restriction, rpt1Validation);

	wxString gatewayAddress, localAddress;
	unsigned int gatewayPort, localPort;
	getNetwork(gatewayAddress, gatewayPort, localAddress, localPort);
	wxLogInfo(wxT("Gateway set to %s:%u, local set to %s:%u"), gatewayAddress.c_str(), gatewayPort, localAddress.c_str(), localPort);

	if (!gatewayAddress.IsEmpty()) {
		CRepeaterProtocolHandler* handler = new CRepeaterProtocolHandler(gatewayAddress, gatewayPort, localAddress, localPort);

		bool res = handler->open();
		if (!res)
			wxLogError(wxT("Cannot open the protocol handler"));
		else
			thread->setProtocolHandler(handler);
	}

	unsigned int timeout, ackTime;
	getTimes(timeout, ackTime);
	thread->setTimes(timeout, ackTime);
	wxLogInfo(wxT("Timeout set to %u secs, ack time set to %u ms"), timeout, ackTime);

	unsigned int beaconTime;
	wxString beaconText;
	bool beaconVoice;
	TEXT_LANG language;
	getBeacon(beaconTime, beaconText, beaconVoice, language);
	if (mode == MODE_GATEWAY)
		beaconTime = 0U;
	thread->setBeacon(beaconTime, beaconText, beaconVoice, language);
	wxLogInfo(wxT("Beacon set to %u mins, text set to \"%s\", voice set to %d, language set to %d"), beaconTime / 60U, beaconText.c_str(), int(beaconVoice), int(language));

	GMSK_MODEM_TYPE modemType;
	unsigned int modemAddress;
	getModem(modemType, modemAddress);

#if defined(WIN32)
	IGMSKModem* modem = NULL;
	switch (modemType) {
		case GMT_LIBUSB:
			wxLogInfo(wxT("GMSK modem: type: LibUsb, address: 0x%04X"), modemAddress);
			modem =	new CGMSKModemLibUsb(modemAddress);
			break;
		case GMT_WINUSB:
			wxLogInfo(wxT("GMSK modem: type: WinUSB, address: 0x%04X"), modemAddress);
			modem =	new CGMSKModemWinUSB(modemAddress);
			break;
		default:
			wxLogError(wxT("Unknown GMSK Modem type - %d"), int(modemType));
			break;
	}
#else
	wxLogInfo(wxT("GMSK modem: type: LibUsb, address: 0x%04X"), modemAddress);
	IGMSKModem* modem =	new CGMSKModemLibUsb(modemAddress);
#endif

	if (modem != NULL) {
		bool res = modem->open();
		if (!res)
			wxLogError(wxT("Cannot open the GMSK modem"));
		else
			thread->setModem(modem);
	}

	wxString controllerType;
	unsigned int activeHangTime;
	getController(controllerType, activeHangTime);
	wxLogInfo(wxT("Controller set to %s, active hang time: %u ms"), controllerType.c_str(), activeHangTime);

	CExternalController* controller = NULL;

	wxString port;
	if (controllerType.StartsWith(wxT("Velleman K8055 - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CExternalController(new CK8055Controller(num), false, false);
	} else if (controllerType.IsSameAs(wxT("Raspberry Pi"))) {
		controller = new CExternalController(new CRaspberryController, false, false);
	} else {
		controller = new CExternalController(new CDummyController, false, false);
	}

	bool res = controller->open();
	if (!res)
		wxLogError(wxT("Cannot open the hardware interface - %s"), controllerType.c_str());
	else
		thread->setController(controller, activeHangTime);

	bool out1, out2, out3, out4;
	getOutputs(out1, out2, out3, out4);
	thread->setOutputs(out1, out2, out3, out4);
	m_frame->setOutputs(out1, out2, out3, out4);
	wxLogInfo(wxT("Output 1 = %d, output 2 = %d, output 3 = %d, output 4 = %d"), out1, out2, out3, out4);

	bool enabled;
	wxString rpt1Callsign, rpt2Callsign;
	wxString shutdown, startup;
	wxString status1, status2, status3, status4, status5;
	wxString command1, command1Line, command2, command2Line;
	wxString command3, command3Line, command4, command4Line;
	wxString output1, output2, output3, output4;
	getControl(enabled, rpt1Callsign, rpt2Callsign, shutdown, startup, status1, status2, status3, status4, status5, command1, command1Line, command2, command2Line, command3, command3Line, command4, command4Line, output1, output2, output3, output4);
	thread->setControl(enabled, rpt1Callsign, rpt2Callsign, shutdown, startup, status1, status2, status3, status4, status5, command1, command1Line, command2, command2Line, command3, command3Line, command4, command4Line, output1, output2, output3, output4);
	wxLogInfo(wxT("Control: enabled: %d, RPT1: %s, RPT2: %s, shutdown: %s, startup: %s, status1: %s, status2: %s, status3: %s, status4: %s, status5: %s, command1: %s = %s, command2: %s = %s, command3: %s = %s, command4: %s = %s, output1: %s, output2: %s, output3: %s, output4: %s"), enabled, rpt1Callsign.c_str(), rpt2Callsign.c_str(), shutdown.c_str(), startup.c_str(), status1.c_str(), status2.c_str(), status3.c_str(), status4.c_str(), status5.c_str(), command1.c_str(), command1Line.c_str(), command2.c_str(), command2Line.c_str(), command3.c_str(), command3Line.c_str(), command4.c_str(), command4Line.c_str(), output1.c_str(), output2.c_str(), output3.c_str(), output4.c_str());

	bool logging;
	getLogging(logging);
	thread->setLogging(logging, m_audioDir);
	m_frame->setLogging(logging);
	wxLogInfo(wxT("Frame logging set to %d, in %s"), int(logging), m_audioDir.c_str());

	wxFileName wlFilename(wxFileName::GetHomeDir(), WHITELIST_FILE_NAME);
	bool exists = wlFilename.FileExists();
	if (exists) {
		CCallsignList* list = new CCallsignList(wlFilename.GetFullPath());
		bool res = list->load();
		if (!res) {
			wxLogError(wxT("Unable to open white list file - %s"), wlFilename.GetFullPath().c_str());
			delete list;
		} else {
			wxLogInfo(wxT("%u callsigns loaded into the white list"), list->getCount());
			thread->setWhiteList(list);
		}
	}

	wxFileName blFilename(wxFileName::GetHomeDir(), BLACKLIST_FILE_NAME);
	exists = blFilename.FileExists();
	if (exists) {
		CCallsignList* list = new CCallsignList(blFilename.GetFullPath());
		bool res = list->load();
		if (!res) {
			wxLogError(wxT("Unable to open black list file - %s"), blFilename.GetFullPath().c_str());
			delete list;
		} else {
			wxLogInfo(wxT("%u callsigns loaded into the black list"), list->getCount());
			thread->setBlackList(list);
		}
	}

	// Convert the worker class into a thread
	m_thread = new CGMSKRepeaterThreadHelper(thread);
	m_thread->start();
}
Exemplo n.º 21
0
void BlockBrowser::updateExplorer(bool block)
{
    if(block)
    {
        ui->heightLabelBE1->show();
        ui->heightLabelBE1->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->heightLabelBE2->show();
        ui->heightLabelBE1->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->hashLabel->show();
        ui->hashLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->hashBox->show();
        ui->hashBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->merkleLabel->show();
        ui->merkleLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->merkleBox->show();
        ui->merkleBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->nonceLabel->show();
        ui->nonceLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->nonceBox->show();
        ui->nonceBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->bitsLabel->show();
        ui->bitsLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->bitsBox->show();
        ui->bitsBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->timeLabel->show();
        ui->timeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->timeBox->show();
        ui->timeBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        // ui->hardLabel->show();
        // ui->hardLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        // ui->hardBox->show();;
        // ui->hardBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        // ui->pawLabel->show();
        // ui->pawLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        // ui->pawBox->show();
        // ui->pawBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        int64_t height = ui->heightBox->value();
		CBlock block;
		CBlockIndex* pindexBest = mapBlockIndex[chainActive.Tip()->GetBlockHash()];
        if (height > pindexBest->nHeight)
        {
            ui->heightBox->setValue(pindexBest->nHeight);
            height = pindexBest->nHeight;
        }
        //int64_t Pawrate = getBlockHashrate(height); Wtf
        //double Pawrate2 = 0.000;
        //Pawrate2 = ((double)Pawrate / 1000000);
        std::string hash = getBlockHash(height);
        std::string merkle = getBlockMerkle(height);
        int64_t nBits = getBlocknBits(height);
        int64_t nNonce = getBlockNonce(height);
        int64_t atime = getBlockTime(height);
        //double hardness = getBlockHardness(height);
        QString QHeight = QString::number(height);
        QString QHash = QString::fromUtf8(hash.c_str());
        QString QMerkle = QString::fromUtf8(merkle.c_str());
        QString QBits = QString::number(nBits);
        QString QNonce = QString::number(nNonce);
        QString QTime = QString::number(atime);
        //QString QHardness = QString::number(hardness, 'f', 6);
        //QString QPawrate = QString::number(0);
        ui->heightLabelBE1->setText(QHeight);
        ui->hashBox->setText(QHash);
        ui->merkleBox->setText(QMerkle);
        ui->bitsBox->setText(QBits);
        ui->nonceBox->setText(QNonce);
        ui->timeBox->setText(QTime);
        //ui->hardBox->setText(QHardness);
        //ui->pawBox->setText(QPawrate + " MH/s");
    }

    if(block == false) {
        ui->txID->show();
        ui->txID->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->txLabel->show();
        ui->txLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->valueLabel->show();
        ui->valueLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->valueBox->show();
        ui->valueBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->inputLabel->show();
        ui->inputLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->inputBox->show();
        ui->inputBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->outputLabel->show();
        ui->outputLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->outputBox->show();
        ui->outputBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->feesLabel->show();
        ui->feesLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
        ui->feesBox->show();
        ui->feesBox->setTextInteractionFlags(Qt::TextSelectableByMouse);
        std::string txid = ui->txBox->text().toUtf8().constData();
        double value = getTxTotalValue(txid);
        double fees = getTxFees(txid);
        std::string outputs = getOutputs(txid);
        std::string inputs = getInputs(txid);
        QString QValue = QString::number(value, 'f', 6);
        QString QID = QString::fromUtf8(txid.c_str());
        QString QOutputs = QString::fromUtf8(outputs.c_str());
        QString QInputs = QString::fromUtf8(inputs.c_str());
        QString QFees = QString::number(fees, 'f', 6);
        ui->valueBox->setText(QValue + " MUE");
        ui->txID->setText(QID);
        ui->outputBox->setText(QOutputs);
        ui->inputBox->setText(QInputs);
        ui->feesBox->setText(QFees + " MUE");
    }
}
void CDVRPTRRepeaterApp::createThread()
{
	wxString callsign, gateway;
	DSTAR_MODE mode;
	ACK_TYPE ack;
	bool restriction, rpt1Validation;
	getCallsign(callsign, gateway, mode, ack, restriction, rpt1Validation);

	IDVRPTRRepeaterThread* thread = NULL;
	switch (mode) {
		case MODE_RXONLY:
			thread = new CDVRPTRRepeaterRXThread;
			break;
		case MODE_TXONLY:
			thread = new CDVRPTRRepeaterTXThread;
			break;
		case MODE_TXANDRX:
			thread = new CDVRPTRRepeaterTXRXThread;
			break;
		default:
			thread = new CDVRPTRRepeaterTRXThread;
			break;
	}

	thread->setCallsign(callsign, gateway, mode, ack, restriction, rpt1Validation);
	wxLogInfo(wxT("Callsign set to \"%s\", gateway set to \"%s\", mode: %d, ack: %d, restriction: %d, RPT1 validation: %d"), callsign.c_str(), gateway.c_str(), int(mode), int(ack), restriction, rpt1Validation);

	wxString gatewayAddress, localAddress;
	unsigned int gatewayPort, localPort;
	getNetwork(gatewayAddress, gatewayPort, localAddress, localPort);
	wxLogInfo(wxT("Gateway set to %s:%u, local set to %s:%u"), gatewayAddress.c_str(), gatewayPort, localAddress.c_str(), localPort);

	if (!gatewayAddress.IsEmpty()) {
		CRepeaterProtocolHandler* handler = new CRepeaterProtocolHandler(gatewayAddress, gatewayPort, localAddress, localPort);

		bool res = handler->open();
		if (!res)
			wxLogError(wxT("Cannot open the protocol handler"));
		else
			thread->setProtocolHandler(handler);
	}

	unsigned int timeout, ackTime;
	getTimes(timeout, ackTime);
	thread->setTimes(timeout, ackTime);
	wxLogInfo(wxT("Timeout set to %u secs, ack time set to %u ms"), timeout, ackTime);

	unsigned int beaconTime;
	wxString beaconText;
	bool beaconVoice;
	TEXT_LANG language;
	getBeacon(beaconTime, beaconText, beaconVoice, language);
	if (mode == MODE_GATEWAY)
		beaconTime = 0U;
	thread->setBeacon(beaconTime, beaconText, beaconVoice, language);
	wxLogInfo(wxT("Beacon set to %u mins, text set to \"%s\", voice set to %d, language set to %d"), beaconTime / 60U, beaconText.c_str(), int(beaconVoice), int(language));

	DVRPTR_VERSION modemVersion;
	CONNECTION_TYPE modemType;
	wxString modemUSBPort, modemAddress, modemUSBPath;
	bool rxInvert, txInvert, channel;
	unsigned int modemPort, modLevel, txDelay;
	getModem(modemVersion, modemType, modemUSBPort, modemAddress, modemPort, rxInvert, txInvert, channel, modLevel, txDelay);
	wxLogInfo(wxT("DV-RPTR modem: version: %d, type: %d, USB port: %s, address: %s:%u, RX invert: %d, TX invert: %d, channel: %s, mod level: %u%%, TX delay: %u ms"), int(modemVersion), int(modemType), modemUSBPort.c_str(), modemAddress.c_str(), modemPort, int(rxInvert), int(txInvert), channel ? wxT("B") : wxT("A"), modLevel, txDelay);

	if (modemType == CT_USB) {
		if (!modemUSBPort.IsEmpty()) {
			getModem(modemUSBPath);
			if (!modemUSBPath.IsEmpty())
				wxLogInfo(wxT("DV-RPTR modem: path: %s"), modemUSBPath.c_str());

			IDVRPTRController* controller = NULL;
			switch (modemVersion) {
				case DVRPTR_V1:
					controller = new CDVRPTRControllerV1(modemUSBPort, modemUSBPath, rxInvert, txInvert, channel, modLevel, txDelay);
					break;
				case DVRPTR_V2:
					controller = new CDVRPTRControllerV2(modemUSBPort, modemUSBPath, txInvert, modLevel, mode == MODE_DUPLEX || mode == MODE_TXANDRX, callsign);
					break;
				default:
					wxLogError(wxT("Unknown DV-RPTR modem version - %d"), int(modemVersion));
					break;
			}

			if (controller != NULL) {
				bool res = controller->open();
				if (!res) {
					wxLogError(wxT("Cannot open the DV-RPTR modem"));
				} else {
					thread->setModem(controller);
					setModem(controller->getPath());
				}
			}
		}
	} else if (modemType == CT_NETWORK) {
		if (!modemAddress.IsEmpty()) {
			CDVRPTRControllerV2* controller = new CDVRPTRControllerV2(modemAddress, modemPort, txInvert, modLevel, mode == MODE_DUPLEX || mode == MODE_TXANDRX, callsign);
			bool res = controller->open();
			if (!res)
				wxLogError(wxT("Cannot open the DV-RPTR modem"));
			else
				thread->setModem(controller);
		}
	}

	wxString controllerType;
	unsigned int activeHangTime;
	getController(controllerType, activeHangTime);
	wxLogInfo(wxT("Controller set to %s, active hang time: %u ms"), controllerType.c_str(), activeHangTime);

	CExternalController* controller = NULL;

	wxString port;
	if (controllerType.StartsWith(wxT("Velleman K8055 - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CExternalController(new CK8055Controller(num), false, false);
	} else if (controllerType.IsSameAs(wxT("Raspberry Pi"))) {
		controller = new CExternalController(new CRaspberryController, false, false);
	} else {
		controller = new CExternalController(new CDummyController, false, false);
	}

	bool res = controller->open();
	if (!res)
		wxLogError(wxT("Cannot open the hardware interface - %s"), controllerType.c_str());
	else
		thread->setController(controller, activeHangTime);

	bool out1, out2, out3, out4;
	getOutputs(out1, out2, out3, out4);
	thread->setOutputs(out1, out2, out3, out4);
	m_frame->setOutputs(out1, out2, out3, out4);
	wxLogInfo(wxT("Output 1 = %d, output 2 = %d, output 3 = %d, output 4 = %d"), out1, out2, out3, out4);

	bool enabled;
	wxString rpt1Callsign, rpt2Callsign;
	wxString shutdown, startup;
	wxString status1, status2, status3, status4, status5;
	wxString command1, command1Line, command2, command2Line;
	wxString command3, command3Line, command4, command4Line;
	wxString output1, output2, output3, output4;
	getControl(enabled, rpt1Callsign, rpt2Callsign, shutdown, startup, status1, status2, status3, status4, status5, command1, command1Line, command2, command2Line, command3, command3Line, command4, command4Line, output1, output2, output3, output4);
	thread->setControl(enabled, rpt1Callsign, rpt2Callsign, shutdown, startup, status1, status2, status3, status4, status5, command1, command1Line, command2, command2Line, command3, command3Line, command4, command4Line, output1, output2, output3, output4);
	wxLogInfo(wxT("Control: enabled: %d, RPT1: %s, RPT2: %s, shutdown: %s, startup: %s, status1: %s, status2: %s, status3: %s, status4: %s, status5: %s, command1: %s = %s, command2: %s = %s, command3: %s = %s, command4: %s = %s, output1: %s, output2: %s, output3: %s, output4: %s"), enabled, rpt1Callsign.c_str(), rpt2Callsign.c_str(), shutdown.c_str(), startup.c_str(), status1.c_str(), status2.c_str(), status3.c_str(), status4.c_str(), status5.c_str(), command1.c_str(), command1Line.c_str(), command2.c_str(), command2Line.c_str(), command3.c_str(), command3Line.c_str(), command4.c_str(), command4Line.c_str(), output1.c_str(), output2.c_str(), output3.c_str(), output4.c_str());

	bool logging;
	getLogging(logging);
	thread->setLogging(logging, m_audioDir);
	m_frame->setLogging(logging);
	wxLogInfo(wxT("Frame logging set to %d, in %s"), int(logging), m_audioDir.c_str());

	wxFileName wlFilename(wxFileName::GetHomeDir(), WHITELIST_FILE_NAME);
	bool exists = wlFilename.FileExists();
	if (exists) {
		CCallsignList* list = new CCallsignList(wlFilename.GetFullPath());
		bool res = list->load();
		if (!res) {
			wxLogError(wxT("Unable to open white list file - %s"), wlFilename.GetFullPath().c_str());
			delete list;
		} else {
			wxLogInfo(wxT("%u callsigns loaded into the white list"), list->getCount());
			thread->setWhiteList(list);
		}
	}

	wxFileName blFilename(wxFileName::GetHomeDir(), BLACKLIST_FILE_NAME);
	exists = blFilename.FileExists();
	if (exists) {
		CCallsignList* list = new CCallsignList(blFilename.GetFullPath());
		bool res = list->load();
		if (!res) {
			wxLogError(wxT("Unable to open black list file - %s"), blFilename.GetFullPath().c_str());
			delete list;
		} else {
			wxLogInfo(wxT("%u callsigns loaded into the black list"), list->getCount());
			thread->setBlackList(list);
		}
	}

	// Convert the worker class into a thread
	m_thread = new CDVRPTRRepeaterThreadHelper(thread);
	m_thread->start();
}
void CSoundCardRepeaterApp::createThread()
{
	wxString callsign, gateway;
	DSTAR_MODE mode;
	ACK_TYPE ack;
	bool restriction, rpt1Validation;
	getCallsign(callsign, gateway, mode, ack, restriction, rpt1Validation);

	switch (mode) {
		case MODE_RXONLY:
			m_thread = new CSoundCardRepeaterRXThread;
			break;
		case MODE_TXONLY:
			m_thread = new CSoundCardRepeaterTXThread;
			break;
		case MODE_TXANDRX:
			m_thread = new CSoundCardRepeaterTXRXThread;
			break;
		default:
			m_thread = new CSoundCardRepeaterTRXThread;
			break;
	}

	m_thread->setCallsign(callsign, gateway, mode, ack, restriction, rpt1Validation);
	wxLogInfo(wxT("Callsign set to \"%s\", gateway set to \"%s\", mode: %d, ack: %d, restriction: %d, RPT1 validation: %d"), callsign.c_str(), gateway.c_str(), int(mode), int(ack), restriction, rpt1Validation);

	wxString gatewayAddress, localAddress;
	unsigned int gatewayPort, localPort;
	getNetwork(gatewayAddress, gatewayPort, localAddress, localPort);
	wxLogInfo(wxT("Gateway set to %s:%u, local set to %s:%u"), gatewayAddress.c_str(), gatewayPort, localAddress.c_str(), localPort);

	if (!gatewayAddress.IsEmpty()) {
		CRepeaterProtocolHandler* handler = new CRepeaterProtocolHandler(gatewayAddress, gatewayPort, localAddress, localPort);

		bool res = handler->open();
		if (!res)
			wxLogError(wxT("Cannot open the protocol handler"));
		else
			m_thread->setProtocolHandler(handler);
	}

	unsigned int timeout, ackTime, hangTime;
	getTimes(timeout, ackTime, hangTime);
	m_thread->setTimes(timeout, ackTime, hangTime);
	wxLogInfo(wxT("Timeout set to %u secs, Ack time set to %u ms, Hang time set to %u ms"), timeout, ackTime, hangTime);

	unsigned int beaconTime;
	wxString beaconText;
	bool beaconVoice;
	TEXT_LANG language;
	getBeacon(beaconTime, beaconText, beaconVoice, language);
	m_thread->setBeacon(beaconTime, beaconText, beaconVoice, language);
	wxLogInfo(wxT("Beacon set to %u mins, text set to \"%s\", voice set to %d, language set to %d"), beaconTime / 60U, beaconText.c_str(), int(beaconVoice), int(language));

	wxString readDevice, writeDevice;
	bool rxInvert, txInvert;
	wxFloat32 rxLevel, txLevel, squelchLevel;
	SQUELCH_MODE squelchMode;
	getRadio(readDevice, writeDevice, rxLevel, txLevel, squelchMode, squelchLevel, rxInvert, txInvert);
	wxLogInfo(wxT("Soundcard set to %s:%s, levels: %.2f:%.2f, GMSK Inversion set to %d:%d, squelch: mode: %d level: %.2f"), readDevice.c_str(), writeDevice.c_str(), rxLevel, txLevel, rxInvert, txInvert, int(squelchMode), squelchLevel);

	if (!readDevice.IsEmpty() && !writeDevice.IsEmpty()) {
#if defined(__WINDOWS__)
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, DSTAR_RADIO_BLOCK_SIZE);
#else
		CSoundCardReaderWriter* soundcard = new CSoundCardReaderWriter(readDevice, writeDevice, DSTAR_RADIO_SAMPLE_RATE, 64U);
#endif
		soundcard->setCallback(m_thread, 0U);

		bool res = soundcard->open();
		if (!res)
			wxLogError(wxT("Cannot open the sound card"));
		else
			m_thread->setSoundCard(soundcard, rxLevel, txLevel, squelchMode, squelchLevel, rxInvert, txInvert);
	}

	wxString type;
	unsigned int cfg;
	int pttDelay;
	bool pttInvert;
	getController(type, cfg, pttDelay, pttInvert);
	wxLogInfo(wxT("Controller set to %s, config: %u, ptt delay: %d ms, PTT Inversion set to %d"), type.c_str(), cfg, pttDelay * 20, pttInvert);

	CExternalController* controller = NULL;

	wxString port;
	if (type.StartsWith(wxT("Velleman K8055 - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CExternalController(new CK8055Controller(num), pttInvert, false);
	} else if (type.StartsWith(wxT("URI USB - "), &port)) {
		unsigned long num;
		port.ToULong(&num);
		controller = new CExternalController(new CURIUSBController(num, false), pttInvert, false);
	} else if (type.StartsWith(wxT("Serial - "), &port)) {
		controller = new CExternalController(new CSerialController(port, cfg), pttInvert, false);
	} else {
		controller = new CExternalController(new CDummyController, pttInvert, false);
	}

	bool res = controller->open();
	if (!res)
		wxLogError(wxT("Cannot open the hardware interface - %s"), type.c_str());
	else
		m_thread->setController(controller, pttDelay);

	bool out1, out2, out3, out4;
	getOutputs(out1, out2, out3, out4);
	m_thread->setOutputs(out1, out2, out3, out4);
	m_frame->setOutputs(out1, out2, out3, out4);
	wxLogInfo(wxT("Output 1 = %d, output 2 = %d, output 3 = %d, output 4 = %d"), out1, out2, out3, out4);

	bool enabled;
	wxString rpt1Callsign, rpt2Callsign;
	wxString shutdown, startup;
	wxString status1, status2, status3, status4, status5;
	wxString command1, command1Line, command2, command2Line;
	wxString command3, command3Line, command4, command4Line;
	wxString output1, output2, output3, output4;
	getControl(enabled, rpt1Callsign, rpt2Callsign, shutdown, startup, status1, status2, status3, status4, status5, command1, command1Line, command2, command2Line, command3, command3Line, command4, command4Line, output1, output2, output3, output4);
	m_thread->setControl(enabled, rpt1Callsign, rpt2Callsign, shutdown, startup, status1, status2, status3, status4, status5, command1, command1Line, command2, command2Line, command3, command3Line, command4, command4Line, output1, output2, output3, output4);
	wxLogInfo(wxT("Control: enabled: %d, RPT1: %s, RPT2: %s, shutdown: %s, startup: %s, status1: %s, status2: %s, status3: %s, status4: %s, status5: %s, command1: %s = %s, command2: %s = %s, command3: %s = %s, command4: %s = %s, output1: %s, output2: %s, output3: %s, output4: %s"), enabled, rpt1Callsign.c_str(), rpt2Callsign.c_str(), shutdown.c_str(), startup.c_str(), status1.c_str(), status2.c_str(), status3.c_str(), status4.c_str(), status5.c_str(), command1.c_str(), command1Line.c_str(), command2.c_str(), command2Line.c_str(), command1.c_str(), command1Line.c_str(), command2.c_str(), command2Line.c_str(), command3.c_str(), command3Line.c_str(), command4.c_str(), command4Line.c_str(), output1.c_str(), output2.c_str(), output3.c_str(), output4.c_str());

	unsigned int activeHangTime;
	getActiveHang(activeHangTime);
	m_thread->setActiveHang(activeHangTime);
	wxLogInfo(wxT("Active Hang: time: %u"), activeHangTime);

	bool logging;
	getLogging(logging);
	m_thread->setLogging(logging, ::wxGetHomeDir());
	m_frame->setLogging(logging);
	wxLogInfo(wxT("Frame logging set to %d, in %s"), int(logging), ::wxGetHomeDir().c_str());

	wxFileName wlFilename(wxFileName::GetHomeDir(), WHITELIST_FILE_NAME);
	bool exists = wlFilename.FileExists();
	if (exists) {
		CCallsignList* list = new CCallsignList(wlFilename.GetFullPath());
		bool res = list->load();
		if (!res) {
			wxLogError(wxT("Unable to open white list file - %s"), wlFilename.GetFullPath().c_str());
			delete list;
		} else {
			wxLogInfo(wxT("%u callsigns loaded into the white list"), list->getCount());
			m_thread->setWhiteList(list);
		}
	}

	wxFileName blFilename(wxFileName::GetHomeDir(), BLACKLIST_FILE_NAME);
	exists = blFilename.FileExists();
	if (exists) {
		CCallsignList* list = new CCallsignList(blFilename.GetFullPath());
		bool res = list->load();
		if (!res) {
			wxLogError(wxT("Unable to open black list file - %s"), blFilename.GetFullPath().c_str());
			delete list;
		} else {
			wxLogInfo(wxT("%u callsigns loaded into the black list"), list->getCount());
			m_thread->setBlackList(list);
		}
	}

	m_thread->start();
}
Exemplo n.º 24
0
 std::vector<Output> Address::getOutputs() const {
     auto &instance = DataAccess::Instance();
     return getOutputs(*instance.addressIndex, *instance.chain);
 }