Ejemplo n.º 1
0
// Control the LED's.
MbedResponse *NetCentricApp::ledCommand(MbedRequest *request) {
    DigitalOut led1(LED1);
    DigitalOut led2(LED2);
    DigitalOut led3(LED3);
    DigitalOut led4(LED4);
    
    if (request->n > 0) led1 = request->args[0];
    if (request->n > 1) led2 = request->args[1];
    if (request->n > 2) led3 = request->args[2];
    if (request->n > 3) led4 = request->args[3];
    
    MbedResponse *r = new MbedResponse();
    r->requestId = request->id;
    r->commandId = request->commandId;
    r->error = NO_ERROR;
    r->n = 4;
    r->values = new float[4];
    r->values[0] = led1;
    r->values[1] = led2;
    r->values[2] = led3;
    r->values[3] = led4;
    
    
    
    return r;
}
Ejemplo n.º 2
0
MbedResponse *NetCentricApp::rotateR(MbedRequest *request) {
    printf("---------------IK BEN HIER___________");
    DigitalOut led1(LED1);
    DigitalOut led2(LED2);
    DigitalOut led3(LED3);
    DigitalOut led4(LED4);
    
    if (request->n > 0) led1 = request->args[0];
    if (request->n > 1) led2 = request->args[1];
    if (request->n > 2) led3 = request->args[2];
    if (request->n > 3) led4 = request->args[3];
    
    MbedResponse *r = new MbedResponse();
    r->requestId = request->id;
    r->commandId = request->commandId;
    r->error = NO_ERROR;
    r->n = 4;
    r->values = new float[4];
    r->values[0] = led1;
    r->values[1] = led2;
    r->values[2] = led3;
    r->values[3] = led4;
    callServo(request->args[0]);

    return r;
}
Ejemplo n.º 3
0
void leds_state(int leds)
{
	led1( ( leds & (1<<0) ) && (1<<0)  );
	led2( ( leds & (1<<1) ) && (1<<1)  );
	led3( ( leds & (1<<2) ) && (1<<2)  );
	led4( ( leds & (1<<3) ) && (1<<3)  );
	led5( ( leds & (1<<4) ) && (1<<4)  );
	led6( ( leds & (1<<5) ) && (1<<5)  );
}
Ejemplo n.º 4
0
int main(void)
{
	//Hier wird alles initialisiert, dh Grundeinstellungen festgelegt
	
	init_Motor();				//Motor einstellen
	init_system_tick();			//System Tick einstellen
	init_drehzahlsensor();		//Drehzahlsensor einstellen
	init_leds();				//LEDs einstellen
	init_hupe();				//Hupe einstellen
	sei();						//Alle Interrupts einschalten
    
	
	while(1)		//Alles innerhalb der while Schleife wird immer wieder wiederholt
    {	
		
		if (~PINB & 0x01)			//Wenn der invertierte Wert des ersten Bits in PINB 1 ist, dann (also wenn der Button gedrückt wird)
		{
			led1(AN);				//Mach die LEDs 1 und 3 an
			led3(AN);
			m_r(255,0);				//Und die Motoren mit Vollgas (255) in 2 Richtungen
			m_l(255,1);
			_delay_ms(500);			//Warte 500 ms
			led1(AUS);				//LEDs 1 und 3 aus, LEDs 2 und 4 an
			led3(AUS);
			led2(AN);
			led4(AN);
			m_r(255,1);				//Richtungen ändern
			m_l(255,0);
			_delay_ms(500);			//und wieder 500ms in die andere Richtung
			m_r(0,0);				//Motoren aus
			m_l(0,0);
			led2(AUS);				//Leds aus
			led4(AUS);
			hupe(AN);				//Hupe an
			_delay_ms(1000);		//1 s warten
			hupe(AUS);				//Hupe aus
			_delay_ms(300);			//300ms warten
			hupe(AN);				//Hupe an
			_delay_ms(500);			//warte 500 ms
			hupe(AUS);				//Hupe aus
		}							//wieder nach oben
	}
}
void FaultInjector::generateFaults() {

//	WeatherStation::getInstance()->getLogger()->log("Inserting faults");

	DigitalOut led4(LED4);

	led4 = 1;
	logger.log(" memorySize %hu\t", memorySize);
	injectFaults(DEFAULT_CHANGED_BYTES, DEFAULT_CHANGED_BITS);
	wait(0.5);
	led4 = 0;
}
Ejemplo n.º 6
0
void animation(void)
{
	volatile int i;
	for(i = 50;i<ANIMATION_MAX;i+=15)
	{
		led1(ON);
		delay_ms(i);
		led2(ON);
		delay_ms(i);
		led3(ON);
		delay_ms(i);
		led4(ON);
		delay_ms(i);
		
		led1(OFF);
		delay_ms(i);
		led2(OFF);
		delay_ms(i);
		led3(OFF);
		delay_ms(i);
		led4(OFF);
		delay_ms(i);
	}
}
Ejemplo n.º 7
0
static void appTaskLeds(void *pdata) {
  DigitalOut led1(LED1);
  DigitalOut led2(LED2);
  DigitalOut led3(LED3);
  DigitalOut led4(LED4);

  /* Task main loop */
  while (true) {
    if (led1Flashing) {
      led1 = !led1;
    }
    if (led2Flashing) {
      led2 = !led2;
    }
    if (led3Flashing) {
      led3 = !led3;
    }
    if (led4Flashing) {
      led4 = !led4;
    }
    OSTimeDlyHMSM(0,0,0,500);
  }
}
Ejemplo n.º 8
0
int main (void)
{

	ioport_set_pin_dir(IO_1,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_2,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_3,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_4,IOPORT_DIR_OUTPUT);
	init_octopus();
 	initial_animation();
	 
	pwm_ini(SERVO_0);
	pwm_update(SERVO_0,0);
	delay_ms(1000);
	pwm_update(SERVO_0,500);
	delay_ms(1000);
	pwm_update(SERVO_0,1000);
	 
	char aux;
	char aux2;
	int dimmer=0;
	for(;;)
	{
		if(bluetooth_is_rx_complete())
		{
			scanf("%1c",&aux);
			switch (aux)
			{
				case 'C':
					scanf("%1c",&aux);
					if (aux=='1')
					{
						led1(ON);
						ioport_set_pin_level(IO_1,ON);
					}
					else
					{
						led1(OFF);
						ioport_set_pin_level(IO_1,OFF);
					}
				break;
				case 'T':
					scanf("%1c",&aux);
					if (aux=='1')
					{
						led2(ON);
						ioport_set_pin_level(IO_2,ON);
					}
					else
					{
						led2(OFF);
						ioport_set_pin_level(IO_2,OFF);
					}
				break;
				case 'D':
					scanf("%i",&dimmer);
				break;
				case 'O':
					scanf("%1c",&aux);
					scanf("%1c",&aux);
					scanf("%1c",&aux2);
					if(aux == '1')
					{
						if(aux2=='1')
						{
							led3(ON);
							ioport_set_pin_level(IO_3,ON);
						}
						else
						{
							led3(OFF);
							ioport_set_pin_level(IO_3,OFF);
						}
					}
					else
					{
						if(aux2=='1')
						{
							led4(ON);
							ioport_set_pin_level(IO_4,ON);
						}
						else
						{
							led4(OFF);
							ioport_set_pin_level(IO_4,OFF);
						}
					}
				break;
				
			}
		}

	dimmer=dimmer*10;	
	pwm_update(SERVO_0,dimmer);	
		
	}
}
/**
 * Inject faults in the system.
 *
 * @param startAddr    - start address
 * @param endAddr      - end address
 * @param changedBytes - number of bytes changed in within the address range
 * @param changedBits  - number of bits changed (0 (auto)... 8)
 */
void FaultInjector::injectFaults(unsigned long startAddr, unsigned long endAddr,
		unsigned long changedBytes, uint8_t changedBits) {

	int count, temp, position;
	unsigned char *addr;
//	char buffer[32];
	bool drawn[8]; // bits sorteados (para não alterar o mesmo bit mais de uma vez).

	if (changedBytes < 1 || changedBytes > (endAddr - startAddr))
		changedBytes = DEFAULT_CHANGED_BYTES;

	if (changedBits > 8) // 0 para automático, 8 para alterar todos os bits
		changedBits = DEFAULT_CHANGED_BITS;

	temp = changedBits;

//	Logger l = Logger("/local/log.txt", true);

//	LocalFileSystem local("local");
//	FILE *fp = fopen("/local/falhas.txt", "a");
//	if (fp != NULL) {
//		time_t seconds = time(NULL);
//		strftime(buffer, 32, "%d/%m/%Y %H:%M:%S", localtime(&seconds));
//      fprintf(fp, "start address: %d\n", startAddr);
//      fprintf(fp, "end address: %d\n", endAddr);
//      fprintf(fp, "changed bytes: %d\n", changedBytes);
//      fprintf(fp, "changed bits: %d\n\n", changedBits);

	for (unsigned long i = 0; i < changedBytes; i++) {

		DigitalOut led4(LED4);

		led4 = 1;
		wait(0.5);
		led4 = 0;

		char value[9];
		//addr = (unsigned char *) getByteMemory(startAddr, endAddr);
		addr = (unsigned char *) getRandomUInt(startAddr, endAddr);

		itoa(value, *addr, 2);

		logger.log("%lu\n\tAddress: %p\n\tCorrect value: %s\t", i + 1, addr,
				value);
//		l.log("%lu\n\tAddress: %p\n\tCorrect value: %s", i + 1, addr, value);

		if (changedBits == 0)
			temp = getRandomUInt(1, 8); // Valor 0 altera n bits automaticamente.

		for (count = 0; count < 8; count++)
			drawn[count] = false;

		count = 0;
		while (count < temp) {
			position = getRandomUInt(0, 7);
			if (drawn[position] != true) {
				drawn[position] = true;
				count++;
				(*addr) ^= (1 << position); // Altera um bit de um endereço (byte) de memória.
			}
		}

		itoa(value, *addr, 2);

//		fprintf(fp, "Valor alterado: %s\n\n", value);
		logger.log("\tChanged value: %s\r", value);
//		l.log("\tChanged value: %s\n", value);
	}

//		fclose(fp);
//	}

}
Ejemplo n.º 10
0
int main (void)
{

	ioport_set_pin_dir(IO_1,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_2,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_3,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_4,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_5,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_6,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_7,IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(IO_8,IOPORT_DIR_INPUT);
	init_octopus();
 	animation();
	 
	//Activate button interrupt
	pmic_init();
	pmic_set_scheduling(PMIC_SCH_ROUND_ROBIN);
	PORTC.INTCTRL = 0x03;
	PORTC.INT0MASK = (1<<3);
	PORTC.PIN3CTRL |= (1<<1);
	cpu_irq_enable();
	
	
	//Activate ZCD signal interruption 
	 cpu_irq_disable();
	 PORTD.INTCTRL = 0x03;
	 PORTD.INT0MASK = (1<<5);
	 PORTD.PIN5CTRL |= 0x01;
	 cpu_irq_enable();
	 
	//Activate RTC
	rtc_init();
	 
// 	pwm_ini(SERVO_0);
// 	pwm_update(SERVO_0,0);
// 	delay_ms(1000);
// 	pwm_update(SERVO_0,500);
// 	delay_ms(1000);
// 	pwm_update(SERVO_0,1000);
	 
	char aux;
	char aux2;
	for(;;)
	{
		printf("hello");
		if(bluetooth_is_rx_complete())
		{
			scanf("%1c",&aux);
			switch (aux)
			{
				case 'C':
					scanf("%1c",&aux);
					if (aux=='1')
					{
						led1(ON);
						ioport_set_pin_level(IO_1,ON);
					}
					else
					{
						led1(OFF);
						ioport_set_pin_level(IO_1,OFF);
					}
				break;
				case 'T':
					scanf("%1c",&aux);
					if (aux=='1')
					{
						led2(ON);
						ioport_set_pin_level(IO_2,ON);
					}
					else
					{
						led2(OFF);
						ioport_set_pin_level(IO_2,OFF);
					}
				break;
				case 'D':
					scanf("%i",&dimmer);
					RTC.COMP=dimmer;
										
				break;
				case 'O':
					scanf("%1c",&aux);
					scanf("%1c",&aux);
					scanf("%1c",&aux2);
					if(aux == '1')
					{
						if(aux2=='1')
						{
							led3(ON);
							ioport_set_pin_level(IO_3,ON);
						}
						else
						{
							led3(OFF);
							ioport_set_pin_level(IO_3,OFF);
						}
					}
					else
					{
						if(aux2=='1')
						{
							led4(ON);
							ioport_set_pin_level(IO_4,ON);
						}
						else
						{
							led4(OFF);
							ioport_set_pin_level(IO_4,OFF);
						}
					}
				break;
				
			}
		}
		
	}
}