Exemple #1
0
void switch_init()
{
    int status ;
    pthread_t out_monitor_id ;
    // Initialize the routing table
    cam_init() ;

    // Initialize the output buffer
    output_buffer = calloc(1,sizeof(buf_queue));
    output_buffer->head = NULL ;
    output_buffer->tail = NULL ;
    output_buffer->size = 0 ;
    status = pthread_mutex_init(&(output_buffer->mutex),NULL);
    if(status != 0) {
        printf("Error Initializing mutex ...\n") ;
    }

    // Create the thread that will monitor the output buffer
    printf("Starting output buffer thread .\n");
    status = pthread_create(&out_monitor_id,NULL,output_monitor_routine,NULL);
    if(status != 0) {
        printf("Error creating monitor thread.\n") ;
    }
    status = pthread_detach(out_monitor_id);
    if(status != 0) {
        printf("Error detaching monitor thread.\n") ;
    }

}
Exemple #2
0
INT frontend_init()
{
   /* hardware initialization */

   cam_init();
   cam_crate_clear(CRATE);
   cam_crate_zinit(CRATE);

   /* enable LAM in IO unit */
   camc(CRATE, SLOT_IO, 0, 26);

   /* enable LAM in crate controller */
   cam_lam_enable(CRATE, SLOT_IO);

   /* reset external LAM Flip-Flop */
   camo(CRATE, SLOT_IO, 1, 16, 0xFF);
   camo(CRATE, SLOT_IO, 1, 16, 0);

   /* register CNAF functionality from cnaf_callback.c with debug output */
   register_cnaf_callback(1);

   /* print message and return FE_ERR_HW if frontend should not be started */

   return SUCCESS;
}
int main(void) {
    pthread_attr_t attr;
    int status; 

    signal(SIGINT, sig_handler);

    thread1_init();
    cam_init();

    pthread_attr_init(&attr);
    pthread_attr_setstacksize(&attr, 1024*1024);
    
    printf("Creating thread1\n");
    status = pthread_create(&thread1, &attr, (void*)&thread1_main, NULL);
    if (status != 0) {
        printf("Failed to create thread1 with status = %d\n", status);
        ASSERT(status == 0);
    }    

    printf("Creating CAM thread\n");
    status = pthread_create(&cam, &attr, (void*)&cam_main, NULL);
    if (status != 0) {
        printf("Failed to create CAM thread with status = %d\n", status);
        ASSERT(status == 0);
    }

    pthread_join(thread1, NULL);
    pthread_join(cam, NULL);

    return 0;
}
Exemple #4
0
void pixyInit(uint32_t slaveRomStart, const unsigned char slaveImage[], uint32_t imageSize)
{
	// write stack guard word
 	STACK_GUARD = STACK_GUARD_WORD;

	commonInit();

	IPC_haltSlave();

	ADCInit();
   	SCTInit();
	CameraInit();

	// start slave
	if (slaveRomStart && slaveImage && imageSize)
	{
		IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize);
		IPC_startSlave();
	}

	// initialize chirp objects
	USBLink *usbLink = new USBLink;
	g_chirpUsb = new Chirp(false, false, usbLink);
	SMLink *smLink = new SMLink;
  	g_chirpM0 = new Chirp(false, true, smLink);

	// initialize devices/modules
	led_init();
	if (prm_init(g_chirpUsb)<0) // error, let user know (don't just continue like nothing's happened)
		showError(1, 0x0000ff, "Flash is corrupt, parameters have been lost\n");
	pwr_init();
	cam_init();
	rcs_init();
	//cc_init();
}
Exemple #5
0
void exec_init() {
	// initialize all sub-systems
	hl_init();
	schd_init();
	lcd_init();
	cam_init();	
	adc_init();
	serv_init();
	cont_init();
	ui_init();
	mot_init();
	//comms_init();	
	
	// disable interrupt
	disable_irq(EXEC_PIT_IRQ_NUM);
	
	// enable the clock to the PIT module (pg. 299)
	SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

	// enable clock for PIT timers and allow timers to continue to
	// run in debug mode (pg. 1038)
	PIT_MCR = 0x0; 
	
	exec_disablePit();
	
	exec_sysMode = EXEC_MODE_IDLE;
	lcd_update();
	exec_update();		
}
Exemple #6
0
void cam_set(int func)
{
    if(cam_data)
        free(cam_data);

    if (func == 1 || func == 2)
    {
#if DEBUG
        printf(" func is 1 or 2  320*240\n");
#endif
        camif_cfg.dst_x = 320 ;
        camif_cfg.dst_y = 240;

        camif_cfg.bpp = 16;
        camif_cfg.flip = 0 ;

        image_size = 320*240*2;

        cam_data = (unsigned char*)malloc(image_size);
    }

    else if(func == 3)
    {
#if DEBIG
        printf(" mode is 2 640*480\n");
#endif
        camif_cfg.dst_x = 640 ;
        camif_cfg.dst_y = 480;

        camif_cfg.bpp = 16;
        camif_cfg.flip = 0 ;

        image_size = 640*480*2 ;

        cam_data = (unsigned char*)malloc(640*480*2);
    }

    if(cam_data <0)
    {
        perror(" cam_data malloc err\n");
        exit(1);
    }


    if ( func > 0 && func <4)
    {

        cam_fd = cam_init();
#if DEBUG
        printf(" cam init() cam_fd is %d func is %d\n", cam_fd, func);
#endif
        if (ioctl(cam_fd, CMD_CAMERA_INIT, &camif_cfg)) {
            perror("ioctl");
            exit(1);
        }

        write(cam_fd,"O",2); // cam start code
    }
}
Exemple #7
0
gboolean
gst_dvb_base_bin_plugin_init (GstPlugin * plugin)
{
  GST_DEBUG_CATEGORY_INIT (dvb_base_bin_debug, "dvbbasebin", 0, "DVB bin");

  cam_init ();

  return gst_element_register (plugin, "dvbbasebin",
      GST_RANK_NONE, GST_TYPE_DVB_BASE_BIN);
}
Exemple #8
0
void pixyInit(uint32_t slaveRomStart, const unsigned char slaveImage[], uint32_t imageSize)
{
	platformInit();

	// button, SPI_SSEL
	LPC_GPIO_PORT->MASK[5] = 0;
	LPC_GPIO_PORT->PIN[5] = 0x20; // negate SPI_SS
	LPC_GPIO_PORT->DIR[5] = 0x20; // SPI_SS - output

	// deal with P4_1, GPIO2[1]
	LPC_GPIO_PORT->MASK[2] = 0;
	LPC_GPIO_PORT->DIR[2] = 0;

	// set timer so we count clock cycles
	LPC_TIMER1->IR = 0;
 	LPC_TIMER1->TCR = 1;
	LPC_TIMER1->PR = 0;

	// microsecond timer
	LPC_TIMER2->IR = 0;
 	LPC_TIMER2->TCR = 1;
	LPC_TIMER2->PR = CLKFREQ_US-1;

  	debug_frmwrk_init_clk(CLKFREQ);

	USB_UserInit();

	lpc_printf("M4 start\n");

	IPC_haltSlave();

	ADCInit();
   	SCTInit();
	CameraInit();

	// start slave
	IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize);
	IPC_startSlave();

	// initialize chirp objects
	g_chirpUsb = new ChirpUsb();
  	g_chirpM0 = new ChirpM0();

	// initialize devices/modules
	pwr_init();
	spi_init();
	cam_init();
	rcs_init();
	led_init();
	//cc_init();
}
Exemple #9
0
//?
void Capture::openCapture()
{
    //??
    //capture = cvCaptureFromCAM(0);
    //capture = cvCreateCameraCapture();
    /*if( ! capture )
    {
        qDebug("Could not initialize capture!");
        return ;
    }*/
    open_cam_flag=1;
    if(this->first_open_cam_flag == 0)
    {
    if(cam_init())
        {
        qDebug("camera init!");
        start_capture();
        timer->start(100);
        this->first_open_cam_flag = 1;
        ui->take_photo_pushButton->setDisabled(false);
        ui->open_pushButton->setDisabled(true);
        ui->close_pushButton->setDisabled(false);
    }
    else
    {
        qDebug("camera init error!");
        QMessageBox::information(this,tr("Waring!"),tr("Can't Open Camera!"),QMessageBox::Yes);
        ui->open_pushButton->setDisabled(false);
        ui->close_pushButton->setDisabled(true);
    }
   // start_capture();
    //timer->start(100);
    //this->first_open_cam_flag = 1;
    }
    else
    {
        timer->start(100);
        ui->open_pushButton->setDisabled(true);
        ui->close_pushButton->setDisabled(false);
    }



    //timer->start(32);  //ü?????
    //ui->close_pushButton->setDisabled(false);
    //ui->open_pushButton->setDisabled(true);

}
Exemple #10
0
void car_process_init(car_tcp_package *rec_pack){
    device_using_rmv_all();
    int i;
    for(i=0;i<rec_pack->device_num;i++){
        car_device_info sinfo=rec_pack->device_info[i];
        printf("sinfo:id=%d,p1=%ld,p2=%ld\n",sinfo.device_id,sinfo.param[0],sinfo.param[1]);
        switch((device_type)(sinfo.param[0])){
            case DTYPE_HMC :
                    HMC_process_Init(&sinfo);//no need for init params
                   break;//
            case DTYPE_MOTOR_Direc:
                    motor_direc_process_Init(sinfo);
                    break;
            case DTYPE_MOTOR_Drive:
                    motor_drive_process_Init(sinfo);
                    break;
            case DTYPE_ROITRACER:
                    roitracer_init(sinfo);
                    break;//no setting function
            case DTYPE_CAM:
                    cam_init(sinfo);
                    break;
            case DTYPE_BITS:
                    gpio_init(sinfo);
                    break;
            case DTYPE_STEER_ARM:
                    steer_arm_Init(sinfo);
                    break;
            case DTYPE_ULTRAL_SOUND:
                    ultra_sound_Init(sinfo);
                    break;
            case DTYPE_ADXL:

                    break;
            default :
                    break;


                    }
    }

   /* while(1){
         sleep(1);
    get_HMC_Direction(*hmc_i);

    }*/

}
Exemple #11
0
void pixyInit(void)
#endif
{
	// write stack guard word
 //	STACK_GUARD = STACK_GUARD_WORD;

	commonInit();

#ifdef KEIL
	IPC_haltSlave();
#endif

	// clear RC servo registers to prevent and glitches upon initialization
	rcs_enable(0, 0);
	rcs_enable(1, 0);

	ADCInit();
   	SCTInit();
	CameraInit();

	// initialize shared memory interface before running M0
	SMLink *smLink = new SMLink;

	// start slave
#ifdef KEIL
	if (slaveRomStart && slaveImage && imageSize)
	{
		IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize);
		IPC_startSlave();
	}
#else
    cr_start_m0(SLAVE_M0APP,&__core_m0app_START__);
#endif

	// initialize chirp objects
	USBLink *usbLink = new USBLink;
	g_chirpUsb = new Chirp(false, false, usbLink);
	g_chirpUsb->setSendTimeout(3000); // set a high timeout because the host can sometimes go AWOL for a second or two....
	g_chirpUsb->setRecvTimeout(3000); // set a high timeout because the host can sometimes go AWOL for a second or two....

  	g_chirpM0 = new Chirp(false, true, smLink);

	// initialize devices/modules
	led_init();
	prm_init(g_chirpUsb);
	pwr_init();
	cam_init();
}
Exemple #12
0
//void pixyInit(uint32_t slaveRomStart, const unsigned char slaveImage[], uint32_t imageSize)
void pixyInit(void)
{
	// write stack guard word
 //	STACK_GUARD = STACK_GUARD_WORD;

	commonInit();

	IPC_haltSlave();

	ADCInit();
   	SCTInit();
	CameraInit();
/*	IPC_startSlave(); */
	// start slave
/*	if (slaveRomStart && slaveImage && imageSize)
	{
		IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize);

	} */

	// initialize shared memory interface before running M0
	SMLink *smLink = new SMLink;

	// run M0
    cr_start_m0(SLAVE_M0APP,&__core_m0app_START__);

	// initialize chirp objects
	USBLink *usbLink = new USBLink;
	g_chirpUsb = new Chirp(false, false, usbLink);
  	g_chirpM0 = new Chirp(false, true, smLink);

	// initialize devices/modules
	led_init();
	if (prm_init(g_chirpUsb)<0) // error, let user know (don't just continue like nothing's happened)
		showError(1, 0x0000ff, "Flash is corrupt, parameters have been lost\n");
	pwr_init();
	cam_init();
	rcs_init();
	//cc_init();
}
Exemple #13
0
void pixyInit(uint32_t slaveRomStart, const unsigned char slaveImage[], uint32_t imageSize)
{
	// write stack guard word
 	STACK_GUARD = STACK_GUARD_WORD;

	commonInit();

	IPC_haltSlave();

	// clear RC servo registers to prevent and glitches upon initialization
	rcs_enable(0, 0);
	rcs_enable(1, 0);

	ADCInit();
   	SCTInit();
	CameraInit();

	// start slave
	if (slaveRomStart && slaveImage && imageSize)
	{
		IPC_downloadSlaveImage(slaveRomStart, slaveImage, imageSize);
		IPC_startSlave();
	}

	// initialize chirp objects
	USBLink *usbLink = new USBLink;
	g_chirpUsb = new Chirp(false, false, usbLink);
	g_chirpUsb->setSendTimeout(3000); // set a high timeout because the host can sometimes go AWOL for a second or two....
	SMLink *smLink = new SMLink;
  	g_chirpM0 = new Chirp(false, true, smLink);

	// initialize devices/modules
	led_init();
	prm_init(g_chirpUsb);
	pwr_init();
	cam_init();
	rcs_init();
	//cc_init();
}
Exemple #14
0
result_t wld_initmgr()
{
    result_t r;
    r = hashtable_open_create(mem_heap(), &g_wld.stable, 5, 10, 0);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "Initializing world manager failed");
        return r;
    }

    r = arr_create(mem_heap(), &g_wld.sections, sizeof(struct wld_section), 5, 10, 0);
    if (IS_FAIL(r)) {
        err_print(__FILE__, __LINE__, "Initializing world manager failed");
        return r;
    }

    /* camera */
    struct vec3f pos;
    cam_init(&g_wld.default_cam, vec3_setf(&pos, 0.0f, 0.0f, -1.0f), &g_vec3_zero, CAM_NEAR,
        CAM_FAR, math_torad(CAM_FOV));
    g_wld.cam = &g_wld.default_cam;

    return RET_OK;
}
Exemple #15
0
int main(int argc, char **argv)
{
   char host_name[HOST_NAME_LENGTH], exp_name[NAME_LENGTH], fe_name[256], rpc_server[256];
   char cmd[256];
   INT i, status;
   BOOL debug, cmd_mode = FALSE;

   /* set default */
   host_name[0] = '\0';
   exp_name[0] = '\0';
   fe_name[0] = '\0';
   rpc_server[0] = '\0';
   debug = FALSE;

   /* get parameters */
   cm_get_environment(host_name, sizeof(host_name), exp_name, sizeof(exp_name));

   /* parse command line parameters */
   for (i = 1; i < argc; i++) {
      if (argv[i][0] == '-' && argv[i][1] == 'd')
         debug = TRUE;
      else if (argv[i][0] == '-') {
         if (i + 1 >= argc || argv[i + 1][0] == '-')
            goto usage;
         if (strncmp(argv[i], "-e", 3) == 0)
            strcpy(exp_name, argv[++i]);
         else if (strncmp(argv[i], "-h", 3) == 0)
            strcpy(host_name, argv[++i]);
         else if (strncmp(argv[i], "-f", 3) == 0)
            strcpy(fe_name, argv[++i]);
         else if (strncmp(argv[i], "-s", 3) == 0)
            strcpy(rpc_server, argv[++i]);
         else if (argv[i][1] == 'c') {
            if (strlen(argv[i]) >= 256) {
               printf("error: command line too long (>256).\n");
               return 0;
            }
            strcpy(cmd, argv[++i]);
            cmd_mode = TRUE;
         } else {
          usage:
            printf
                ("usage: mcnaf [-f Frontend] [-h Hostname] [-e Experiment] [-s RPC server]\n");
            printf("             [-c Command] [-c @CommandFile] \n\n");
            return 0;
         }
      }
   }

   if (rpc_server[0])
      status = cam_init_rpc("", "", "", "mcnaf", rpc_server);
   else
      status = cam_init_rpc(host_name, exp_name, fe_name, "mcnaf", "");
   if (status == SUCCESS) {
      status = cam_init();
      if (status == SUCCESS)
         status = cnafsub(cmd_mode, cmd);
   }
   cam_exit();
//  printf("status:%d\n", status);
   return status;
}
Exemple #16
0
int main() {

    clock_init();
    pc.baud(115200);
    pc.printf("Initializing camera...");

    cam_init();


    while(1) {


		ADCLight1=AinLight1;
		ADCLight2=AinLight2;
		ADCLight3=AinLight3;
		ADCLight4=AinLight4;
//if constanly sense the light, reduct the hp value		
		if(ADCLight1>0.57 | ADCLight2>0.57 | ADCLight3>0.57 | ADCLight4>0.57)
		{
		cnt++;
		}else{
		cnt=0;}

		if(cnt>3){
		  life=life-cnt;
		  cnt=0;
		  }
		
//checking Hp of the tank
		if(life>10){
		Life1=1;
		Life2=1;
		}
		else if(life>0 && life<=10){
		Life1=1;
		Life2=0;
		}
		else{
		Life1=0;
		Life2=0;
		tank.stop();
		calibrate(); // if first tank is dead, switch tile so the second one would start moving.
		system("pasuse");

		}


	int cam[12];
    int LED[8];
	read_data(cam);
	load(cam, LED);
	double posoh[3];
	Locate(posoh);
			int state;
			 pc.printf("x:%f\n\r",posoh[0]);
 			 pc.printf("y:%f\n\r",posoh[1]);
			 pc.printf("angle:%f\n\r",posoh[2]);
 /////Tank start moving from this point//////////
		   if(okx0==0)	  ///////////move to the first check point
				   {

					if(-0.30>= posoh[2] && posoh[2] >= -0.45)
					{
						state =1;
					}
					if (posoh[2] >-0.30)
					{
						state =2;
					}
					if(posoh[2]<-0.45)
					{
						state =3;
					}

					switch(state)
					{
						case 1:
							if(posoh[0]<=-150)
							{
							tank.forward(0.1);
							 }
							 else{
							 tank.stop();
							 okx0=1;
							 okt0=1;
							 }

							break;
						case 2:
							tank.right(0.068);
						break;
						case 3:
							tank.left(0.068);
						break;

						default:
						break;
					}


			}


////////////////////////////////done x0//////////////////
			if(okt0==1)
			{
					if(1.30>= posoh[2] && posoh[2] >= 1.15)		//if the degree is within 1.3 and 1.15, then move
					{
						state =1;
					}
					if (posoh[2] >1.33)
					{
						state =2;
					}
					if(posoh[2]<1.15)			   
					{
						state =3;
					}

					switch(state)
					{
						case 1:
							if(posoh[1]<=-50)	  //move until reach 	y=-50
							{
							tank.forward(0.1);
							 }
							 else{
							 tank.stop();
							 okt0=0;
							 okt1=1;
							 }

							break;
						case 2:
							tank.right(0.073);
						break;
						case 3:
							tank.left(0.073);
						break;

						default:
						break;
					}
			}
//////////////done x and t 0////////
			if(okt1==1)
			{
					if(posoh[2]<2.7)
					{
						tank.left(0.08);
					}

					else if(posoh[2]>=2.7)
					{
						 tank.stop();
						 okt1=0;
						 okx1=1;

					}
			}
////////////////////////		move x///////
					if(okx1==1)
			{
					if(posoh[0]>-20)	   //until x=-20
					{
						tank.forward(0.1);
					}
					else
					{
					tank.stop();
					okx1=0;
					okt2=1;
					}
			}

// ////////////////////////turn ////////////////////
 			if(okt2==1)
			{
			 if(abs(posoh[2])>1.75)
			 {
				tank.left(0.075);
			 }

			 else
			 {
			 tank.stop();
			 	okt2=0;
				oky0=1;
			 }
			}
// /////////////////move x to 2///////////
			if(oky0==1)
			{
			 	if(posoh[1]>-25)			  //until y= -25
				{
					tank.forward(0.1);
				}
				if(posoh[1]<=-25)
				{
				 	tank.stop();
					oky0=0;
					okt3=1;
				}
			}
//  ///////////////turn3///////////////////
			if(okt3==1)
			{
			 if(posoh[2]<2.76)
			 {
			 	 tank.right(0.075);
			 }

			 if(posoh[2]<=2.9 &&posoh[2]>=2.76)
			 {
			 	tank.stop();
				okt3=0;
				okx2=1;
			  }
			}
// ///////////////move x////////////////////
 			if(okx2==1)
			{
				if(posoh[0]>-175)
				{
					tank.forward(0.1);
				}

				if(posoh[0]<=-175)
				{
					tank.stop();
					okx2=0;
					okt4=1;
				}
			}
////////////////turn 4///////////////////////

			 if(okt4==1)
			 {
				if(posoh[2]>1.33)
				{
					tank.right(0.07);
				}
				if(posoh[2]<=1.33)
				{
					tank.stop();
					okt4=0;
					oky1=1;
				}
			 }
//////////////////move y/////////////
///////middle point of the map/////
 			if(oky1==1)
			{
				if(posoh[1]<-50)
				{
					tank.forward(0.1);
				}

				if(posoh[1]>=-50)
				{
					tank.stop();
					
					calibrate(); //tile switch
					wait(2);
					oky1=0;
					//tok0=1;
					tok0=1;
				}
			}
////////////////////////////second round////////////////////////
///using the second tile system//////////

			if(tok0==1)
			{
					if(1.7>= abs(posoh[2]) && abs(posoh[2]) >= 1.5)
					{
						state =1;
					}
					if (abs(posoh[2])<1.5)
					{
						state =2;
					}
					if(abs(posoh[2])>1.7)
					{
						state =3;
					}

					switch(state)
					{
						case 1:
							if(posoh[1]>=-30)
							{
							tank.forward(0.1);
							 }
							 else{
							 tank.stop();
							 tok0=0;
							 tok1=1;
							 }

							break;
						case 2:
							tank.right(0.07);
						break;
						case 3:
							tank.left(0.07);
						break;

						default:
						break;
					}
			}		
		
		
			
			if(tok1==1)
			{
				  	if(posoh[2]<2.85 || posoh[2]>3)
				{
				tank.right(0.07);
				}
				else{
				tank.stop();
				tok1=0;
				tok2=1;
				}
			}

			if(tok2==1)
			{
				if(posoh[0]>-140)
				{
					tank.forward(0.1);
				}
				else
				{
					tank.stop();
					tok2=0;
					tok3=1;
				}

			}

			if(tok3==1)
			{
				     				
				if(abs(posoh[2])>1.7)
				 {
				 tank.left(0.07);
				 }
				 else
				 {
				 tank.stop();
				 tok3=0;
				  tok4=1;
				 }
			
			}
			if(tok4==1)
			{
   				
				if(abs(posoh[2])>1.7)
				 {
				 tank.left(0.07);
				 }
				 else
				 {
				 tank.stop();
				  tok4=0;
				  tok5=1;
				 }
			}


 //////////////done moving	   ///////////////////

 			if(tok5==1)	  ////////////////start shooting
			{
				wait(0.5);
				Fire=0;
				wait(0.5);
				Fire=1;
			}
			
		}



	

/////////////////////////////////// Wii IR Finish///////////////////////////
}
Exemple #17
0
int main(void)
{  
	//Konfiguration der Ausgänge bzw. Eingänge
	//definition erfolgt in der config.h
	DDRA = OUTA;
	#if USE_SER_LCD
		DDRC = OUTC;
	#else
		DDRC = OUTC;
		#if PORTD_SCHALT
			DDRD = OUTD;
		#endif
	#endif
	// RoBue:
	// Pullups einschalten
	PORTA = (1 << PORTA0) | (1 << PORTA1) | (1 << PORTA2) | (1 << PORTA3) | (1 << PORTA4) | (1 << PORTA5) | (1 << PORTA6);
	
    unsigned long a;
	#if USE_SERVO
		servo_init ();
	#endif //USE_SERVO
	
    usart_init(BAUDRATE); // setup the UART
	
	#if USE_ADC
		ADC_Init();
	#endif
	
	usart_write("\n\rSystem Ready\n\r");
    usart_write("Compiliert am "__DATE__" um "__TIME__"\r\n");
    usart_write("Compiliert mit GCC Version "__VERSION__"\r\n");
	for(a=0;a<1000000;a++){asm("nop");};

	//Applikationen starten
	stack_init();
	httpd_init();
	telnetd_init();
	
	//Spielerrei mit einem LCD
	#if USE_SER_LCD
		udp_lcd_init();
		lcd_init();
		// RoBue:
		// LCD-Ausgaben:
		lcd_clear();
		lcd_print(0,0,"*AVR-NET-IO "Version"*");
		lcd_print(2,0,"Counter: ");
		lcd_print(3,0,"Zeit:");
	#endif

	//Ethernetcard Interrupt enable
	ETH_INT_ENABLE;
	
	#if USE_SER_LCD
		// RoBue:
		// IP auf LCD
		lcd_print(1,0,"%1i.%1i.%1i.%1i",myip[0],myip[1],myip[2],myip[3]);
	#endif
	
	//Globale Interrupts einschalten
	sei(); 
	
	#if USE_CAM
		#if USE_SER_LCD
			lcd_print(1,0,"CAMERA INIT");
		#endif //USE_SER_LCD
		for(a=0;a<2000000;a++){asm("nop");};
		cam_init();
		max_bytes = cam_picture_store(CAM_RESELUTION);
		#if USE_SER_LCD
			back_light = 0;
			lcd_print(1,0,"CAMERA READY");
		#endif //USE_SER_LCD
	#endif // -> USE_CAM
	
	#if USE_NTP
	        ntp_init();
	        ntp_request();
	#endif //USE_NTP
	
	#if USE_WOL
	        wol_init();
	#endif //USE_WOL
    
	#if USE_MAIL
	        mail_client_init();
	#endif //USE_MAIL  

	// Startwerte für ow_array setzen
	#if USE_OW
		uint8_t i = 0;
		for (i=0;i<MAXSENSORS;i++){
			ow_array[i]=OW_START;
		}
		for (i=MAXSENSORS;i<MAXSENSORS*3;i++){
			ow_array[i]=OW_MINMAX;
		}
		DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
		for(a=0;a<1000000;a++){asm("nop");};
		auslesen = 0;
		minmax = 1;
	#endif


//Hauptschlfeife
// *************
		
	while(1)
	{

	#if USE_ADC
		ANALOG_ON;
	#endif

	eth_get_data();
		
        //Terminalcommandos auswerten
	if (usart_status.usart_ready){
	usart_write("\r\n");
		if(extract_cmd(&usart_rx_buffer[0]))
		{
			usart_write("Ready\r\n\r\n");
		}
		else
		{
			usart_write("ERROR\r\n\r\n");
		}
		usart_status.usart_ready =0;
	
	}
	
	// RoBue:
	// Counter ausgeben
	#if USE_SER_LCD
		lcd_print(2,9,"%4i",var_array[MAX_VAR_ARRAY-1]);
	#endif

	// RoBue:
	// Uhrzeit bestimmen und auf LCD ausgeben
	hh = (time/3600)%24;
	mm = (time/60)%60;
	ss = time%60;

	#if USE_SER_LCD
		lcd_print(3,7,"%2i:%2i:%2i",hh,mm,ss);
	#endif

	#if USE_HIH4000
		var_array[VA_OUT_HIH4000] = ((var_array[VA_IN_HIH4000]-160)/6);
	#endif

	#if USE_OW
	// RoBue:
	// Zurücksetzen der Min/Max-Werte um 00:00 Uhr einschalten
	if (( hh == 00 )&&( mm == 00 )) {
		minmax = 1;
	}
	#endif

	// ******************************************************************
	// RoBue:
	// 1-Wire-Temperatursensoren (DS18B20) abfragen
	// ******************************************************************

		#if USE_OW

		uint8_t i = 0;
		uint8_t subzero, cel, cel_frac_bits;
		uint8_t tempID[OW_ROMCODE_SIZE];

		// Messen bei ss=5,15,25,35,45,55		
		if ( ss%10 == 5 ) {

		// Messen?
		if ( messen == 1 ) {

		// RoBue Anmerkung:
		// Hiermit werden ALLE Sensoren zum Messen aufgefordert.
		// Aufforderung nur bestimmter Sensoren:
		// "NULL" durch "tempID" ersetzen
		
		// RoBue Testausgabe UART:
		// usart_write("Starte Messvorgang ...\r\n");		 

		DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
		
		// Kein Messen mehr bis ss=5,15,25,35,45,55
		messen = 0;

		// Jetzt kann ausgelesen werden
		auslesen = 1;

		}	// -> if messen
		
		}	// -> if ss

		// Auslesen bei ss=8,18,28,38,48,58
		if ( ss%10 == 8 ) {

		// Auslesen?
		if ( auslesen == 1 ) {

		// (erste) ID ins RAM holen
		memcpy_P(tempID,DS18B20IDs[0],OW_ROMCODE_SIZE);	
				
		while ( tempID[0] != 0 ) {
		//while ( tempID[0] == 0x10 ) {
				
			// RoBue Anmerkung:
			// Hiermit wird jeweils ein einzelner Sensor ausgelesen
			// und die Temperatur in ow_array abgelegt.
			// Achtung:
			// Pro Sekunde können max. ca. 10 Sensoren ausgelesen werden!
			if ( DS18X20_read_meas( tempID, &subzero,&cel, &cel_frac_bits) == DS18X20_OK ) {

				ow_array[i] = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);

				// Minuswerte:
					if ( subzero )
						ow_array[i] *= (-1);
				
				// min/max:
				if ( minmax == 1 ) {
					// Zurücksetzen der Min/Max_Werte 1x/Tag
					// auf die gerade aktuellen Temperaturen 
					ow_array[i+MAXSENSORS] = ow_array[i];
					ow_array[i+MAXSENSORS*2] = ow_array[i];
				}
				else {
					// Abgleich der Temp. mit den gespeicherten Min/Max-Werten
					if (ow_array[i]  < ow_array[i+MAXSENSORS])
        					ow_array[i+MAXSENSORS] = ow_array[i];
               				if (ow_array[i]  > ow_array[i+MAXSENSORS*2])
						ow_array[i+MAXSENSORS*2] = ow_array[i];
        			}

				//TWert = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);
				//ow_array[i] = TWert;
				
				// RoBue:
				// Testausgabe UART:
				// usart_write("%2i:%2i:%2i: Temperatur: %3i Grad\r\n",hh,mm,ss,ow_array[i]/10);
				
			}	// -> if
			else {
				usart_write("\r\nCRC Error (lost connection?) ");
				DS18X20_show_id_uart( tempID, OW_ROMCODE_SIZE );


			}	// -> else
		
		// nächste ID ins RAM holen
		memcpy_P(tempID,DS18B20IDs[++i],OW_ROMCODE_SIZE);

		}	// -> while
		
		// RoBue:
		// Temperatur auf LCD ausgeben (IP von Startausgabe (s.o.) wird Überschrieben)
		#if USE_SER_LCD
			lcd_print(1,0,"Tmp:            ");
			lcd_print(1,5,"%i C",ow_array[0]/10);
			lcd_print(1,11,"%i C",ow_array[1]/10);
		#endif

		}	// -> if auslesen

		auslesen = 0;	// Auslesen vorläufig abschalten
		messen = 1;	// Messen wieder ermöglichen
		minmax = 0;	// Min/Max-Werte vergleichen

		}	// -> if ss
		
	#endif
	

	// **********************************************************
	// RoBue:
	// Schalten der Ports (PORTC) durch bestimmte Bedingungen
	// - Temperatur (1-Wire -> PORTA7) mit/ohne Lüftungsautomatik
	// - digital, analog (-> PORTA0-6)
	// - Zeit
	// **********************************************************
	
	// Automatik eingeschaltet?
	if ( var_array[9] == 1 ) {

	if ( ss%10 == 1 ) {
		schalten = 1;
	}

	// Abfrage bei ss =0,10,20,30,40,50
	if ( ss%10 == 0 ) {
	if ( schalten == 1 ) {
	
	// RoBue Testausgabe UART:
	// usart_write("%2i:%2i: Schaltfunktionen testen ...\r\n",hh,mm);	


	// PORTC0:
	// Über Temperatur: var_array[10] - Sensor0		
	if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) {
		PORTC |= (1 << PC0); // ein
	//
	// Über Temperatur: var_array[10] - Sensor0 - PORTA0
	// if ((PINA&0b00000001) == 0 ) {		// PORTA0: Fenster geschlossen?
	//	if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) {
	//		PORTC |= (1 << PC0); // ein
	//	}
	//  	else { 
	//     		PORTC &= ~(1 << PC0); // aus
	//	}
	}
	else {
	      	PORTC &= ~(1 << PC0); // aus
	}

	// PORTC1:
	// Über Temperatur: var_array[11] - Sensor1
	// if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) {
	//	PORTC |= (1 << PC1); // ein
	//
	// Über Temperatur: var_array[11] - Sensor1 - PORTA1
	if ((PINA&0b00000010) == 0 ) {		// PORTA1: Fenster geschlossen?
		if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) {
			PORTC |= (1 << PC1); // ein
		}
		else {
			PORTC &= ~(1 << PC1); // aus
		}
	}
	else {
		PORTC &= ~(1 << PC1); // aus
	}
		
	// PORTC2:
	// Über Temperatur: var_array[12] - Sensor2
	// if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) {						
	//	PORTC |= (1 << PC2); // ein
	// Über Temperatur: var_array[12] - Sensor2 - PORTA2
	// if ((PINA&0b00000100) == 0 ) {		// PORTA2: Fenster geschlossen?
	//	if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) {
	//		PORTC |= (1 << PC2); // ein
	//	}
	//	else {
	//		PORTC &= ~(1 << PC2); // aus
	//	}
	//}
	//else {
	//	PORTC &= ~(1 << PC2); // aus
	//}

	// PORTC4:
	// Über 2 Temperaturen (Differenz)
	// var_array[13] - Sensor3 Vorlauf, Sensor4 Ruecklauf
	//
	// z.B. Zirkulationspumpe für Warmwasser
	// Achtung: Temp. von Sensor3 MUSS höher/gleich sein als Temp. von Sensor4
	// Ansonsten laeuft die Pumpe immer
	//
		if ( (ow_array[3]/10 - ow_array[4]/10) >= var_array[14] ) {						
		PORTC |= (1 << PC4); // ein
	}
	else {
		PORTC &= ~(1 << PC4); // aus
	}

		// PORTC6:
	// Über Analogwert:
	if ( var_array[6] > var_array[18] ) {
		PORTC |= (1 << PC6); // ein
	}
	else {
		PORTC &= ~(1 << PC6); // aus
	}

	// PORTC7:
	// Über Zeit: ein/aus
	if ( hh == var_array[20] ) {
		if ( mm == var_array[21] ) {
			PORTC |= (1 << PC7); // ein
		}
	}
	if ( hh == var_array[22] ) {
		if ( mm == var_array[23] ) {
			PORTC &= ~(1 << PC7); // aus
		}
	}


	schalten = 0;	// Vorerst nicht mehr schalten

	} // -> schalten == 1
	} // -> if ss == ...
	} // -> if var_array == 1
	
	
        //Wetterdaten empfangen (Testphase)
        #if GET_WEATHER
        http_request ();
        #endif
        
        //Empfang von Zeitinformationen
	#if USE_NTP
		if(!ntp_timer){
		ntp_timer = NTP_REFRESH;
		ntp_request();
		}
	#endif //USE_NTP
		
        //Versand von E-Mails
        #if USE_MAIL
	        if (mail_enable == 1)
	        {
	            mail_enable = 0;
	            mail_send();
	        }
        #endif //USE_MAIL
        
        //Rechner im Netzwerk aufwecken
        #if USE_WOL
	        if (wol_enable == 1)
	        {
	            wol_enable = 0;
	            wol_request();
	        }
        #endif //USE_WOL
           
	//USART Daten für Telnetanwendung?
	telnetd_send_data();
    }

return(0);
}
Exemple #18
0
int main(int argc, char *argv[])
{
	struct timeval tv1;		//监控键盘输入的select时间参数
	unsigned long size;		//一帧画面的字节数
	int index=0;			//V4L2 input索引号
	struct v4l2_capability cap;		//V4L2设备功能结构体变量
	struct v4l2_input i;		//V4L2设备输入信息
	struct v4l2_framebuffer fb;		//V4L2的一帧设备缓存
	int on=1;				//控制V4L2设备overlay的参数
	int tmp;
	fd_set fds1;			//监控键盘输入的select fd_set变量
	int fd;				//监控键盘输入的select句柄
	char cmd[256];			//存储从键盘读入的字符串
	
	cam_fp = cam_init();		//获得摄像头句柄
	fb_fp = fb_init();			//获得帧缓冲句柄
	
	size=width*height*fb_bpp/8;

	if((tmp=ioctl(cam_fp, VIDIOC_QUERYCAP, &cap))<0) 
	{		//查询驱动功能
		printf("VIDIOC_QUERYCAP error, ret=0x%x\n",tmp);
		goto err;
	}
	printf("Driver:%s, Card:%s, cap=0x%x,bus info is %s\n",cap.driver,cap.card,cap.capabilities,cap.bus_info);
	
	memset(&i, 0, sizeof(i));
	i.index=index;
	if(ioctl(cam_fp, VIDIOC_ENUMINPUT, &i)<0)
	{//枚举输入源
		goto err;
	}
	printf("input name:%s\n",i.name);	
	
	index=0;
	if(ioctl(cam_fp, VIDIOC_S_INPUT, &index)<0)		//设置输入源
	{
	    printf("VIDIOC_S_INPUT failed\n");
		goto err;
    }
	if(ioctl(cam_fp, VIDIOC_S_OUTPUT, &index)<0)		//设置输出源
	{
	    
	    printf(" VIDIOC_S_OUTPUT failed\n");
	        goto err;
	}
	if(ioctl(cam_fp, VIDIOC_G_FBUF, &fb)<0)		//获取V4L2设备FB属性参数
	{
	    printf(" VIDIOC_G_FBUF failed\n");
		goto err;
	}

	printf("g_fbuf:capabilities=0x%x,flags=0x%x,width=%d,height=%d\n"
	       "pixelformat=0x%x,bytesperline=%d,colorspace=%d,base=0x%x\n",
		    fb.capability,fb.flags,fb.fmt.width,fb.fmt.height
		    ,fb.fmt.pixelformat,fb.fmt.bytesperline,fb.fmt.colorspace
		    ,fb.base);
		    
	fb.capability = cap.capabilities;	//V4L2设备功能赋值给V4L2的FB功能属性
	fb.fmt.width =width;				//LCD的FB宽度赋值给V4L2的FB宽度
	fb.fmt.height = height;				//LCD的FB高度赋值给V4L2的FB高度
	fb.fmt.pixelformat = (fb_bpp==32)?V4L2_PIX_FMT_BGR32:V4L2_PIX_FMT_RGB565;		//赋值V4L2的FB像素位数

	if(ioctl(cam_fp, VIDIOC_S_FBUF, &fb)<0)		//设置新的FB属性给摄像头
	{
	
        printf(" VIDIOC_S_FBUF failed\n");
   		goto err;
    }
    
	on = 1;
	if(ioctl(cam_fp, VIDIOC_OVERLAY, &on)<0)//使能摄像头的overlay
	{
	
        printf(" VIDIOC_OVERLAY failed\n");
		goto err;
	}
	
	vf_buff = (char*)malloc(size);
	if(vf_buff==NULL)
	{
		goto err;
	}

	if(fb_bpp==16)
	{	//16位BMP
	    *((unsigned int*)(bmp_head_t+18)) = width;
	    *((unsigned int*)(bmp_head_t+22)) = height;
	    *((unsigned short*)(bmp_head_t+28)) = 16;
	}
	else
	{
    	bmp_head[0] = 'B';
    	bmp_head[1] = 'M';
    	*((unsigned int*)(bmp_head+2)) = (width*fb_bpp/8)*height+54;		//整个位图大小
    	*((unsigned int*)(bmp_head+10)) = 54;				//从54字节开始存图像
    	*((unsigned int*)(bmp_head+14)) = 40;				//图像描述信息块的大小
    	*((unsigned int*)(bmp_head+18)) = width;
    	*((unsigned int*)(bmp_head+22)) = height;
    	*((unsigned short*)(bmp_head+26)) = 1;				//图像的plane总数
    	*((unsigned short*)(bmp_head+28)) = fb_bpp;
    	*((unsigned short*)(bmp_head+34)) = (width*fb_bpp/8)*height;		//图像数据区大小
	}
	
	while(1)
	{
	    if (!read_data(cam_fp, vf_buff, width, height, fb_bpp))		//读摄像头数据到vf_buff
	    {
		    printf("read error\n");
	    }
	    memcpy(fb_addr,vf_buff,width*height*fb_bpp/8);		//将读到的图像数据从内存拷贝到帧缓冲地址
	    fd=0;							//键盘句柄
	    tv1.tv_sec=0;
	    tv1.tv_usec=0;						//无限等待
	    FD_ZERO(&fds1);
	    FD_SET(fd,&fds1);					//绑定句柄跟监控对象
	    select(fd+1,&fds1,NULL,NULL,&tv1);			//监控键盘输入
	    if(FD_ISSET(fd,&fds1))					//如果键盘有输入
	    {
		    memset(cmd,0,sizeof(cmd));
		    read(fd,cmd,256);					//读取键盘输入的字符
		    if(strncmp(cmd,"quit",4)==0)
		    {			//如果键盘输入quit
    		    printf("-->quit\n");
    		    on=0;
    		    if(ioctl(cam_fp, VIDIOC_OVERLAY, &on)<0)//关掉V4L2设备的overlay
    		    {
    			    goto err;
    			}
    		    close(fb_fp);
    		    close(cam_fp);					//释放FB跟摄像头的句柄
    		    return 0;
		    }
		    else if(strncmp(cmd,"capt",4)==0)
		    {			//如果键盘输入capt
    		    printf("-->capture\n");
    		    printf("write to img --> ");
    		    writeImageToFile(size);				//把FB数据保存到位图中
    		    printf("OK\n");
		    }
	    }
	}

err:
	if (cam_fp)
		close(cam_fp);
	if (fb_fp)
		close(fb_fp);
	return 1;
}
Exemple #19
0
void switch_init()
{
	cam_init();
}
Exemple #20
0
int main(){
    Buzzer.write(0);
    mrf.SetChannel(com_channel); 
    clock_init();
    cam_init();
    pc.baud(115200);
    State = WAITING;
    Battery_Level = Battery_Time;
    t_battery.reset();
    int start_x, start_y, y_min, y_max, dest_x;
    active = 1;
    mrf.SetChannel(15);
    for (int i=0; i<3; i++){        //load the tile it is under;
        rxLen = rf_receive(rxBuffer, 128);
        while (rxLen <= 0){
            rxLen = rf_receive(rxBuffer, 128);
        }
        sscanf(rxBuffer,"active: %d\r\n", &active);
    }
    pc.printf("the active value is: %d\r\n", active);   
    mrf.SetChannel(com_channel);
    while(1){
        switch(State){      //use a state machine to control the behavior or a slave
            default:
                State = WAITING;
                break;
            
            case 1:     //Waiting
                sprintf(txBuffer, "Ready\r\n");
                rf_send(txBuffer, strlen(txBuffer) + 1);
                robot.stop();
                rxLen = rf_receive(rxBuffer, 128);
                if (rxLen > 0){
                    int res = sscanf(rxBuffer, "%d %d %d %d %d\r\n", &start_x, &start_y, &y_min, &y_max, &dest_x);
                    if (res){
                        sprintf(txBuffer, "Yes\r\n");
                        rf_send(txBuffer, strlen(txBuffer) + 1);
                        State = WORKING;
                    }
                }else{
                    State = WAITING;
                }
                break;
            
            case 2:     //Working
                Buzzer.write(1);
                wait(0.2);
                Buzzer.write(0);
                go_to(start_x, start_y);
                Buzzer.write(1);
                wait(0.6);
                Buzzer.write(0);
                if (zig_zag(y_max, y_min, dest_x) > 0){
                    robot.stop();
                    sprintf(txBuffer, "Finished\r\n");
                    rf_send(txBuffer, strlen(txBuffer) + 1);
                    State = WAITING;
                }else{
                    robot.stop();       
                    rotate(90);
                    Locate(position);
                    sprintf(txBuffer, "Died: %3.2f,%3.2f\r\n",position[0],position[1]);
                    rf_send(txBuffer, strlen(txBuffer) + 1);
                    for (int b=0; b<3; b++){
                        Buzzer.write(1);
                        wait(0.2);
                        Buzzer.write(0);
                        wait(0.2);
                    }
                    go_to(Charging_X, Charging_Y);
                    State = CHARGING;
                }
                break;
                
            case 3:     //charging
                sprintf(txBuffer, "Charging: %d\r\n",Battery_Level);
                rf_send(txBuffer, strlen(txBuffer) + 1);
                rxLen = rf_receive(rxBuffer, 128);
                if (rxLen > 0){
                    int res = sscanf(rxBuffer, "%d %d %d %d %d\r\n", &start_x, &start_y, &y_min, &y_max, &dest_x);
                    if (res){
                        State = WORKING;
                     }
                }else{
                    State = CHARGING;
                }
                wait(1);
                Battery_Level += 3;
                if (Battery_Level >= Battery_Time){
                    Battery_Level = Battery_Time;
                    State = WAITING;
                }
                break;
        }       
    }
}