Beispiel #1
0
void pwmout_write(pwmout_t *obj, float value)
{
    uint16_t oldPulseWidth;

    NRF_TIMER2->EVENTS_COMPARE[3] = 0;
    NRF_TIMER2->TASKS_STOP        = 1;

    if (value < 0.0f) {
        value = 0.0;
    } else if (value > 1.0f) {
        value = 1.0;
    }

    oldPulseWidth          = ACTUAL_PULSE[obj->pwm];
    ACTUAL_PULSE[obj->pwm] = PULSE_WIDTH[obj->pwm]  = value * PERIOD;

    if (PULSE_WIDTH[obj->pwm] == 0) {
        PULSE_WIDTH[obj->pwm] = 1;
        setModulation(obj, 0, 0);
    } else if (PULSE_WIDTH[obj->pwm] == PERIOD) {
        PULSE_WIDTH[obj->pwm] = PERIOD - 1;
        setModulation(obj, 0, 1);
    } else if ((oldPulseWidth == 0) || (oldPulseWidth == PERIOD)) {
        setModulation(obj, 1, oldPulseWidth == PERIOD);
    }

    NRF_TIMER2->INTENSET    = TIMER_INTENSET_COMPARE3_Msk;
    NRF_TIMER2->SHORTS      = TIMER_SHORTS_COMPARE3_CLEAR_Msk | TIMER_SHORTS_COMPARE3_STOP_Msk;
    NRF_TIMER2->TASKS_START = 1;
}
Beispiel #2
0
void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
    uint32_t pulseInTicks  = us/8;
    uint16_t oldPulseWidth = ACTUAL_PULSE[obj->pwm];
    
    ACTUAL_PULSE[obj->pwm] = PULSE_WIDTH[obj->pwm]  = pulseInTicks;
    
    if(PULSE_WIDTH[obj->pwm] == 0){
        PULSE_WIDTH[obj->pwm] = 1;
        setModulation(obj,0,0);
    }
    else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){
        PULSE_WIDTH[obj->pwm] = PERIOD[obj->pwm]-1;
        setModulation(obj,0,1);
    }
    else if( (oldPulseWidth == 0) || (oldPulseWidth == PERIOD[obj->pwm]) ){
        setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]);
    }
}
Beispiel #3
0
void OutPort::setModulation( LinkData* linkData )
{
    INT16 idx = getIndex( linkData );
    ASSERT( idx >= 0 );
    if( idx >= 0 ) 
    {
        setModulation( idx, linkData->value_, -1 );
    }
}
Beispiel #4
0
void OutPort::initModulation()
{
    bufModulation_.resize( 0 );
    modulation_ = bufModulation_.resize( numTargets_ * numVoices_ );
    
    for( UINT16 i=0; i<targets_.size(); i++ )
    {
        LinkData* linkData = targets_[i];
        setModulation( i, linkData->value_ );
    }
}
Beispiel #5
0
void OutPort::onController( INT16 controller, FLOAT value )
{
    for( UINT16 i=0; i<targets_.size(); i++ )
    {
        LinkData* linkData = targets_[i];
        if( linkData->scaleController( controller, value )) 
        {
            linkData->value_ = value;
            setModulation( i, value );
        }
    }
}
Beispiel #6
0
void pwmout_pulsewidth_us(pwmout_t *obj, int us)
{
    uint32_t pulseInTicks  = us / TIMER_PRECISION;
    uint16_t oldPulseWidth = ACTUAL_PULSE[obj->pwm];

    NRF_TIMER2->EVENTS_COMPARE[3] = 0;
    NRF_TIMER2->TASKS_STOP        = 1;

    ACTUAL_PULSE[obj->pwm] = PULSE_WIDTH[obj->pwm]  = pulseInTicks;

    if (PULSE_WIDTH[obj->pwm] == 0) {
        PULSE_WIDTH[obj->pwm] = 1;
        setModulation(obj, 0, 0);
    } else if (PULSE_WIDTH[obj->pwm] == PERIOD) {
        PULSE_WIDTH[obj->pwm] = PERIOD - 1;
        setModulation(obj, 0, 1);
    } else if ((oldPulseWidth == 0) || (oldPulseWidth == PERIOD)) {
        setModulation(obj, 1, oldPulseWidth == PERIOD);
    }
    NRF_TIMER2->INTENSET    = TIMER_INTENSET_COMPARE3_Msk;
    NRF_TIMER2->SHORTS      = TIMER_SHORTS_COMPARE3_CLEAR_Msk | TIMER_SHORTS_COMPARE3_STOP_Msk;
    NRF_TIMER2->TASKS_START = 1;
}
Beispiel #7
0
void OutPort::onGate( FLOAT gate, UINT16 voice )
{
    for( UINT16 i=0; i<targets_.size(); i++ )
    {
        LinkData* linkData = targets_[i];
        if( linkData->veloSens_ )
        {
            float value = linkData->makeLogarithmic( linkData->value_ );
            gate       *= linkData->veloSens_;
            value      += gate;
            setModulation( i, value, voice );
        }
    }
}
Beispiel #8
0
void pwmout_write(pwmout_t* obj, float value) {
    uint16_t oldPulseWidth;
    
    if (value < 0.0f) {
        value = 0.0;
    } else if (value > 1.0f) {
        value = 1.0;
    }
    
    oldPulseWidth           = ACTUAL_PULSE[obj->pwm];
    ACTUAL_PULSE[obj->pwm]  = PULSE_WIDTH[obj->pwm]  = value* PERIOD[obj->pwm];
    
    if(PULSE_WIDTH[obj->pwm] == 0){
        PULSE_WIDTH[obj->pwm] = 1;
        setModulation(obj,0,0);
    }
    else if(PULSE_WIDTH[obj->pwm] == PERIOD[obj->pwm]){
        PULSE_WIDTH[obj->pwm] = PERIOD[obj->pwm]-1;
        setModulation(obj,0,1);
    }
    else if( (oldPulseWidth == 0) || (oldPulseWidth == PERIOD[obj->pwm]) ){
        setModulation(obj,1,oldPulseWidth == PERIOD[obj->pwm]);
    }
}
void* CDVAPController::Entry()
{
	wxLogMessage(wxT("Starting DVAP Controller thread"));

	while (!m_stopped) {
		unsigned int length;
		RESP_TYPE type = getResponse(m_buffer, length);

		switch (type) {
			case RT_TIMEOUT:
				break;
			case RT_ERROR:
				wxLogMessage(wxT("Stopping DVAP Controller thread"));
				m_serial.close();
				return NULL;
			case RT_STATE:
				m_signal      = int(m_buffer[4U]) - 256;
				m_squelchOpen = m_buffer[5U] == 0x01U;
				m_space       = m_buffer[6U];
				break;
			case RT_PTT:
				m_ptt = m_buffer[4U] == 0x01U;	
				break;
			case RT_START:
				break;
			case RT_STOP:
				wxLogWarning(wxT("DVAP has stopped, restarting"));
				start();
				break;
			case RT_HEADER: {
					m_mutex.Lock();

					unsigned int space = m_rxData.freeSpace();
					if (space < 43U) {
						wxLogMessage(wxT("Out of space in the DVAP RX queue"));
					} else {
						unsigned char hdr[2U];
						hdr[0U] = TAG_HEADER;
						hdr[1U] = RADIO_HEADER_LENGTH_BYTES;
						m_rxData.addData(hdr, 2U);
						m_rxData.addData(m_buffer + 6U, RADIO_HEADER_LENGTH_BYTES);
					}

					m_mutex.Unlock();
				}
				break;
			case RT_HEADER_ACK:
				break;
			case RT_GMSK_DATA: {
					m_mutex.Lock();

					unsigned int space = m_rxData.freeSpace();
					if (space < (length - 4U)) {
						wxLogMessage(wxT("Out of space in the DVAP RX queue"));
					} else {
						bool end = (m_buffer[4U] & 0x40U) == 0x40U;
						unsigned char hdr[2U];
						hdr[0U] = end ? TAG_DATA_END : TAG_DATA;
						hdr[1U] = length - 6U;
						m_rxData.addData(hdr, 2U);
						m_rxData.addData(m_buffer + 6U, length - 6U);
					}

					m_mutex.Unlock();
				}
				break;
			case RT_FM_DATA:
				wxLogWarning(wxT("The DVAP has gone into FM mode, restarting the DVAP"));
				stop();
				setModulation();
				start();
				break;
			default:
				wxLogMessage(wxT("Unknown message"));
				CUtils::dump(wxT("Buffer dump"), m_buffer, length);
				break;
		}

		if (m_space > 0U) {
			if (!m_txData.isEmpty()) {
				m_mutex.Lock();

				unsigned char len = 0U;
				m_txData.getData(&len, 1U);

				unsigned char data[100U];
				m_txData.getData(data, len);

				m_mutex.Unlock();

				// CUtils::dump(wxT("Write"), data, len);

				int ret = m_serial.write(data, len);
				if (ret != int(len))
					wxLogWarning(wxT("Error when writing data to the modem"));

				m_space--;
			}
		}

		Sleep(5UL);
	}

	wxLogMessage(wxT("Stopping DVAP Controller thread"));

	stop();

	m_serial.close();

	return NULL;
}
bool CDVAPController::open()
{
	bool res = m_serial.open();
	if (!res)
		return false;

	res = getName();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = getFirmware();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = getSerial();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = setModulation();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = setMode();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = setSquelch();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = setPower();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = setFrequency();
	if (!res) {
		m_serial.close();
		return false;
	}

	res = start();
	if (!res) {
		m_serial.close();
		return false;
	}

	Create();
	SetPriority(100U);
	Run();

	return true;
}
Beispiel #11
0
void CCommand::Initialize()
{
    // Set Baud rate
    setRadio(0);
    setSquelch(255);
    setSoundVolume(0);
    setRadio(1);
    setSoundVolume(0);
    setSquelch(255);
    /*
    dbgWin->slotSendSerial("G2?");
    dbgWin->slotSendSerial("G4?");
    dbgWin->slotSendSerial("GE?");
    dbgWin->slotSendSerial("GD?");
    dbgWin->slotSendSerial("GA0?");
    dbgWin->slotSendSerial("GA1?");
    dbgWin->slotSendSerial("GA2?");
    dbgWin->slotSendSerial("GF?");
    */
    sleep(1);
    setUpdateMode(CCommand::eUpdOn);
    /*  NOT NEEDED */
    //dbgWin->slotSendSerial("J730000");
    setRadio(0);
    // Noise blanker is off
    setNoiseBlanker(false);
    setRadio(1);
    setNoiseBlanker(false);

    // Init radio 0 Frequency;

    setRadio(0);
    setModulation(CCommand::eWFM);
    setFilter(CCommand::e230k);
    setFrequency(106500000);
    setSquelch(0);
    setVoiceControl(CCommand::eVSCOff);
    setIFShift(128);

    // Init radio 1 Frequency
    setRadio(1);
    setModulation(CCommand::eFM);
    setFilter(CCommand::e15k);
    setFrequency(145425000);
    setSquelch(0);
    setSoundVolume(0);
    setVoiceControl(CCommand::eVSCOff);
    setIFShift(128);

    /*  NOT NEEDED */

    /* Unknown
    dbgWin->slotSendSerial("J4200");
    dbgWin->slotSendSerial("J4700");
    dbgWin->slotSendSerial("J6700");


    dbgWin->slotSendSerial("JC400");
    dbgWin->slotSendSerial("J7100");
    dbgWin->slotSendSerial("J720000");
    dbgWin->slotSendSerial("JC000");
    */
    // Mute radio before restoring values
    setRadio(0);
    setSoundMute(true);
    setSoundVolume(0);

    /* Unknown
    dbgWin->slotSendSerial("J8001");
    dbgWin->slotSendSerial("J8100");
    dbgWin->slotSendSerial("J8200");
    dbgWin->slotSendSerial("J8300");
    dbgWin->slotSendSerial("JC500");
    */
    setRadio(0);
    setSquelch(255);
    setVoiceControl(CCommand::eVSCOff);
    setRadio(1);
    setSquelch(255);
    setVoiceControl(CCommand::eVSCOff);

    setRadio(0);
    setSoundVolume(0);
    setRadio(1);
    setSoundVolume(0);
    setSquelch(255);
    setRadioMode(CCommand::eBoth);
    //dbgWin->slotSendSerial("JB000");
    setRadio(1);
    setSquelch(255);
    setVoiceControl(CCommand::eVSCOff);

    setRadio(0);
    setSquelch(1);
    setVoiceControl(CCommand::eVSCOff);
    setRadio(1);
    setVoiceControl(CCommand::eVSCOff);
    setSquelch(1);

    setRadio(0);
    setSoundVolume(60);
    setSoundMute(false);
}