Ejemplo n.º 1
0
Power PowerControlKnob::findLowestPowerLimitRequest()
{
	if (m_requests.size() == 0)
	{
		const auto& pl1Capabilities = m_powerControl->getCapabilities().getCapability(PowerControlType::PL1);
		return pl1Capabilities.getMaxPowerLimit();
	}
	else
	{
		Power lowestPower;
		for (auto request = m_requests.begin(); request != m_requests.end(); request++)
		{
			if (lowestPower.isValid() == false)
			{
				lowestPower = request->second;
			}
			else
			{
				if (request->second < lowestPower)
				{
					lowestPower = request->second;
				}
			}
		}
		return lowestPower;
	}
}
Ejemplo n.º 2
0
void StartInstance::Launch()
{
	isInit = true;
	VirtualMachine *vm = new VirtualMachine();


	if (isInit)
	{
		  Power *p = new Power();

            std::cout << "V1" << std::endl;
			map->seeMap();
            std::cout << "-----------" << std::endl;
            map = p->findPowerOnMap(map);
            std::cout << "V2" << std::endl;
            map->seeMap();
			std::cout << "-----------" << std::endl;
	
			vm->setMap(map->getMap());		
			vm->Launch(*map->getMap());

	}
	else
	{
	std::string error = "Error Initialisation";
		throw myException(error);

	}
}
Ejemplo n.º 3
0
// TODO: Expand to allow for more functions.
// TODO: When parsing e^(f(z)), use Exponential class instead of Power class.
// Evaluates the given expression tree on the given variable value.
ComplexNumber evaluate_tree(const ExpressionTreeNode *root, const ComplexNumber z) {
    if (root->is_op_node()) {
        ExpressionTreeBinaryOp *temp = (ExpressionTreeBinaryOp *) root;
        ComplexNumber left = evaluate_tree(temp->get_left(), z);
        ComplexNumber right = evaluate_tree(temp->get_right(), z);

        // Find the appropriate operator, apply, then return.
        if (temp->get_operator() == PLUS) {
            return left + right;
        } else if (temp->get_operator() == MINUS) {
            return left - right;
        } else if (temp->get_operator() == TIMES) {
            return left * right;
        } else if (temp->get_operator() == DIVIDE) {
            return left / right;
        } else { // temp->get_operator() == EXP
            Power p (right);
            return p.eval(left);
        }
    } else if (root->is_func_node()) {
        ExpressionTreeFunction *temp = (ExpressionTreeFunction *) root;
        ComplexNumber arg = evaluate_tree(temp->get_argument(), z);

        // Find the appropriate function, evaluate, then return.
        if (temp->get_function() == LOG) {
            Logarithm l (1, 0);
            return l.eval(arg);
        } else if (temp->get_function() == SIN) {
            Sine s (1, 1, 0);
            return s.eval(arg);
        } else if (temp->get_function() == COS) {
            Cosine c (1, 1, 0);
            return c.eval(arg);
        } else { // temp->get_function() == TAN
            Tangent t (1, 1, 0);
            return t.eval(arg);
        }
    } else if (root->is_leaf_node()) {
        ExpressionTreeLeaf *temp = (ExpressionTreeLeaf *) root;
        return temp->get_val(); // Return the value itself
    } else if (root->is_const_node()) {
        ExpressionTreeConstant *temp = (ExpressionTreeConstant *) root;

        // Return the corresponding mathematical constant
        if (temp->get_constant() == e) {
            return E;
        } else if (temp->get_constant() == pi) {
            return PI;
        } else { // temp->get_constant() == phi
            return PHI;
        }
    } else { // root->is_var_node()
        return z;
    }
}
Ejemplo n.º 4
0
Expression * Division::shallowReduce(Context& context, AngleUnit angleUnit) {
  Expression * e = Expression::shallowReduce(context, angleUnit);
  if (e != this) {
    return e;
  }
  Power * p = new Power(operand(1), new Rational(-1), false);
  Multiplication * m = new Multiplication(operand(0), p, false);
  detachOperands();
  p->shallowReduce(context, angleUnit);
  replaceWith(m, true);
  return m->shallowReduce(context, angleUnit);
}
Ejemplo n.º 5
0
std::shared_ptr<XmlNode> PowerControlKnob::getXml() const
{
	auto knobStatus = XmlNode::createWrapperElement("power_control_status");
	if (m_powerControl->supportsPowerControls())
	{
		auto pl1Capabilities = m_powerControl->getCapabilities().getCapability(PowerControlType::PL1);
		knobStatus->addChild(pl1Capabilities.getXml());
		Power currentPowerLimit = m_powerControl->getPowerLimitPL1();
		auto powerControl = XmlNode::createDataElement("power_limit", currentPowerLimit.toString());
		knobStatus->addChild(powerControl);
	}
	return knobStatus;
}
Ejemplo n.º 6
0
void Power::throwIfInvalid(const Power& power) const
{
    if (power.isValid() == false)
    {
        throw dptf_exception("Power is invalid.");
    }
}
Ejemplo n.º 7
0
Bool Power::operator==(const Power& rhs) const
{
    // Do not throw an exception if power is not valid.

    if (this->isValid() == true && rhs.isValid() == true)
    {
        return (this->m_power == rhs.m_power);
    }
    else if (this->isValid() == false && rhs.isValid() == false)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Ejemplo n.º 8
0
void PowerControlKnob::limit(UIntN target)
{
	if (canLimit(target))
	{
		try
		{
			getPolicyServices().messageLogging->writeMessageDebug(PolicyMessage(
				FLF, "Calculating request to limit power controls.", getParticipantIndex(), getDomainIndex()));

			const auto& pl1Capabilities = m_powerControl->getCapabilities().getCapability(PowerControlType::PL1);
			Power minimumPowerLimit = pl1Capabilities.getMinPowerLimit();
			Power stepSize = pl1Capabilities.getPowerStepSize();

			Power nextPowerLimit(pl1Capabilities.getMaxPowerLimit());
			Power targetRequest = getTargetRequest(target);
			if (targetRequest >= pl1Capabilities.getMaxPowerLimit())
			{
				// limit one step from current power
				Power currentPower = m_powerControl->getAveragePower();
				getPolicyServices().messageLogging->writeMessageDebug(PolicyMessage(
					FLF, "Current power is " + currentPower.toString() + ".", getParticipantIndex(), getDomainIndex()));
				nextPowerLimit = calculateNextLowerPowerLimit(currentPower, minimumPowerLimit, stepSize, targetRequest);
			}
			else
			{
				// limit one step size down
				nextPowerLimit = std::max((int)targetRequest - (int)stepSize, (int)minimumPowerLimit);
			}
			m_requests[target] = nextPowerLimit;

			stringstream message;
			message << "Requesting to limit power to " << nextPowerLimit.toString() << ".";
			getPolicyServices().messageLogging->writeMessageDebug(
				PolicyMessage(FLF, message.str(), getParticipantIndex(), getDomainIndex()));
		}
		catch (std::exception& ex)
		{
			getPolicyServices().messageLogging->writeMessageDebug(
				PolicyMessage(FLF, ex.what(), getParticipantIndex(), getDomainIndex()));
			throw ex;
		}
	}
}
Ejemplo n.º 9
0
Bool PowerControlKnob::commitSetting()
{
	try
	{
		if (m_powerControl->supportsPowerControls())
		{
			// find lowest power limit in request
			Power lowestPowerLimit = snapToCapabilitiesBounds(findLowestPowerLimitRequest());

			// set new power status
			Power currentPowerLimit = m_powerControl->getPowerLimitPL1();
			if (currentPowerLimit != lowestPowerLimit)
			{
				stringstream messageBefore;
				messageBefore << "Attempting to change power limit to " << lowestPowerLimit.toString() << ".";
				getPolicyServices().messageLogging->writeMessageDebug(
					PolicyMessage(FLF, messageBefore.str(), getParticipantIndex(), getDomainIndex()));
				m_powerControl->setPowerLimitPL1(lowestPowerLimit);

				stringstream messageAfter;
				messageAfter << "Changed power limit to " << lowestPowerLimit.toString() << ".";
				getPolicyServices().messageLogging->writeMessageDebug(
					PolicyMessage(FLF, messageAfter.str(), getParticipantIndex(), getDomainIndex()));
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	catch (std::exception& ex)
	{
		getPolicyServices().messageLogging->writeMessageDebug(
			PolicyMessage(FLF, ex.what(), getParticipantIndex(), getDomainIndex()));
		throw ex;
	}
}
Ejemplo n.º 10
0
std::string DomainPlatformPowerControl_001::createStatusStringForLimitValue(PlatformPowerLimitType::Type limitType)
{
    try
    {
        if (isEnabled(limitType))
        {
            Power powerLimit = getPlatformPowerLimit(getParticipantIndex(), getDomainIndex(),
                limitType);
            return powerLimit.toString();
        }
        else
        {
            return "DISABLED";
        }
    }
    catch (...)
    {
        return "ERROR";
    }
}
Ejemplo n.º 11
0
std::string DomainPowerControl_001::createStatusStringForLimitValue(PowerControlType::Type controlType)
{
    try
    {
        if (isEnabled(controlType))
        {
            Power powerLimit = getPowerLimit(getParticipantIndex(), getDomainIndex(), controlType);
            return powerLimit.toString();
        }
        else
        {
            return "DISABLED";
        }
    }
    catch (primitive_not_found_in_dsp)
    {
        return "NOT SUPPORTED";
    }
    catch (...)
    {
        return "ERROR";
    }
}
Ejemplo n.º 12
0
void shutdown() {
	display.shutdown();
	
	radio::disable();
	audio_codec.reset();
	clock_manager.shutdown();

	power.shutdown();
	// TODO: Wait a bit for supplies to discharge?

	chSysDisable();

	systick_stop();

	hackrf::one::reset();
}
Ejemplo n.º 13
0
int main(void)
{
	char i = 0;
	
	Systick_Init();
	
	button.rise(&toggle);
	
  while (1)
  {		
		Delay(250);
		led1 = !led1;
		
		if(i >= 20)
		{
			i = 0;
			led1 = 0;
			
			power.stop();
		}
		else i++;
  }
}
Ejemplo n.º 14
0
void init() {
	for(const auto& pin : pins) {
		pin.init();
	}

	/* Configure other pins */
	LPC_SCU->SFSI2C0 =
		  (1U <<  3)
		| (1U << 11)
		;

	power.init();

	gpio_max5864_select.set();
	gpio_max5864_select.output();

	gpio_max2837_select.set();
	gpio_max2837_select.output();

	led_usb.setup();
	led_rx.setup();
	led_tx.setup();

	clock_manager.init();
	clock_manager.set_reference_ppb(persistent_memory::correction_ppb());
	clock_manager.run_at_full_speed();

	clock_manager.start_audio_pll();
	audio_codec.init();

	clock_manager.enable_first_if_clock();
	clock_manager.enable_second_if_clock();
	clock_manager.enable_codec_clocks();
	radio::init();

	touch::adc::init();
}
Ejemplo n.º 15
0
int main(){

	Power *p = new Power();
	// printf("ResistanceVal : %f",p->ResistanceVal());
    int loop=1;
    while(loop){
    	printf("Enter one of the Menu items:\n");
        printf("1.Resistance:\n");
        printf("2.Current:\n");
        printf("3.Band colors:\n");
        printf("4.Exit:\n");
        
        int inp;
        float r,c;
        char str1[8],str2[8],str3[8]; 
    	scanf("%d",&inp);
		switch(inp){
	    case 1  :
	       printf("Enter Resistance\n");
	       scanf("%f",&r);
	       p->ChangeResistance(r);
	       printf("ResistanceVal:=%f\n",p->ResistanceVal());
	       printf("CurrentVal:=%f\n",p->CurrentVal());
	       printf("VoltageVal:=%f\n",p->VoltageVal());
	       printf("Power:=%f\n",p->get_power());
	       break; 
	    case 2  :
	       printf("Enter Current\n");
	       scanf("%f",&c);
	       p->ChangeCurrent(c);
	       printf("ResistanceVal:=%f\n",p->ResistanceVal());
	       printf("CurrentVal:=%f\n",p->CurrentVal());
	       printf("VoltageVal:=%f\n",p->VoltageVal());
	       printf("Power:=%f\n",p->get_power());
	       break; 
	    case 3  :
	       printf("Enter First String\n");
	       gets(str1);
	       printf("Enter Second String\n");
	       gets(str2);
	       printf("Enter Third String\n");
	       gets(str3);
	       p->BandResistance(str1,str2,str3);
	       printf("ResistanceVal:=%f\n",p->ResistanceVal());
	       printf("CurrentVal:=%f\n",p->CurrentVal());
	       printf("VoltageVal:=%f\n",p->VoltageVal());
	       printf("Power:=%f\n",p->get_power());
	       break;
	    case 4  :
	       loop=0;
	       break;
	  
	    }
	}
	return 0;
}
Ejemplo n.º 16
0
namespace portapack {

portapack::IO io {
	portapack::gpio_dir,
	portapack::gpio_lcd_rd,
	portapack::gpio_lcd_wr,
	portapack::gpio_io_stbx,
	portapack::gpio_addr,
	portapack::gpio_lcd_te,
	portapack::gpio_unused,
};

lcd::ILI9341 display;

I2C i2c0(&I2CD0);
SPI ssp0(&SPID1);
SPI ssp1(&SPID2);

wolfson::wm8731::WM8731 audio_codec { i2c0, portapack::wm8731_i2c_address };

si5351::Si5351 clock_generator {
	i2c0, hackrf::one::si5351_i2c_address
};

ClockManager clock_manager {
	i2c0, clock_generator
};

ReceiverModel receiver_model {
	clock_manager
};

TransmitterModel transmitter_model {
	clock_manager
};

uint8_t bl_tick_counter = 0;

class Power {
public:
	void init() {
		/* VAA powers:
		 * MAX5864 analog section.
		 * MAX2837 registers and other functions.
		 * RFFC5072 analog section.
		 *
		 * Beware that power applied to pins of the MAX2837 may
		 * show up on VAA and start powering other components on the
		 * VAA net. So turn on VAA before driving pins from MCU to
		 * MAX2837.
		 */
		/* Turn on VAA */
		gpio_vaa_disable.clear();
		gpio_vaa_disable.output();

		/* 1V8 powers CPLD internals.
		 */
		/* Turn on 1V8 */
		gpio_1v8_enable.set();
		gpio_1v8_enable.output();

		/* Set VREGMODE for switching regulator on HackRF One */
		gpio_vregmode.set();
		gpio_vregmode.output();
	}

	void shutdown() {
		gpio_1v8_enable.clear();
		gpio_vaa_disable.set();
	}

private:
};

static Power power;

void init() {
	for(const auto& pin : pins) {
		pin.init();
	}

	/* Configure other pins */
	LPC_SCU->SFSI2C0 =
		  (1U <<  3)
		| (1U << 11)
		;

	power.init();

	gpio_max5864_select.set();
	gpio_max5864_select.output();

	gpio_max2837_select.set();
	gpio_max2837_select.output();

	led_usb.setup();
	led_rx.setup();
	led_tx.setup();

	clock_manager.init();
	clock_manager.set_reference_ppb(persistent_memory::correction_ppb());
	clock_manager.run_at_full_speed();

	clock_manager.start_audio_pll();
	audio_codec.init();

	clock_manager.enable_first_if_clock();
	clock_manager.enable_second_if_clock();
	clock_manager.enable_codec_clocks();
	radio::init();

	touch::adc::init();
}

void shutdown() {
	display.shutdown();
	
	radio::disable();
	audio_codec.reset();
	clock_manager.shutdown();

	power.shutdown();
	// TODO: Wait a bit for supplies to discharge?

	chSysDisable();

	systick_stop();

	hackrf::one::reset();
}

extern "C" {

void __late_init(void) {

	reset();

	/*
	 * System initializations.
	 * - HAL initialization, this also initializes the configured device drivers
	 *   and performs the board-specific initializations.
	 * - Kernel initialization, the main() function becomes a thread and the
	 *   RTOS is active.
	 */
	halInit();

	/* After this call, scheduler, systick, heap, etc. are available. */
	/* By doing chSysInit() here, it runs before C++ constructors, which may
	 * require the heap.
	 */
	chSysInit();
}

}

} /* namespace portapack */
Ejemplo n.º 17
0
// Override.
ComplexNumber NthRoot::eval(const ComplexNumber z) const {
    Power power (1 / n);
    return power.eval(z);
}