/****************************** Main function ***************************/
void main()
{
 init_devices();
 xbee_reset();
 xbee();
 while(1)
 {
    if(DATA_RECEIVED == 1)
    {
	   int val;
	   val=RECEIVE();
      xbee_I_RECEIVE(val);
    }
    xbee_I_FRONT_IR_VALUE(FRONT_IR);
    xbee();
 }
}
Beispiel #2
0
void xbee_routine_thread(void)
{
	int ret=0;
    pthread_t id;
	uint8 _i,_adr[8];
	uint8 *HeadMidAdr=NULL;

	time_t timetTime;
    struct tm *pTmTime;

	timetTime = time(NULL);		//获取当前系统时间
	//printf("timetTime=%d\n", (uint32)timetTime);
	strncpy(CoorInfo.logname,"xbee_dev_log_",13);
    pTmTime = localtime(&timetTime);	//time_t 结构转换成tm结构
    snprintf(CoorInfo.logname+13 , 24 , "%04d_%02d_%02d_%02d_%02d_%02d.txt", pTmTime->tm_year+1900, pTmTime->tm_mon+1, pTmTime->tm_mday, pTmTime->tm_hour, pTmTime->tm_min, pTmTime->tm_sec);
	printf("CoorInfo.logname=%s\n", CoorInfo.logname);
	err_log(CoorInfo.logname , strlen(CoorInfo.logname));

	xbee_gpio_init();
	xbee_serial_port_init(115200);

	for(_i=0;_i<8;_i++)
		_adr[_i] = 0;

		MUTEX_LOCK(&mutex13_pSourcePathList);
			pSourcePathList = CreatRouterLink(_adr,0,HeadMidAdr,0);
		MUTEX_UNLOCK(&mutex13_pSourcePathList);

		MUTEX_LOCK(&mutex01_serial_rbuf);
			creat_circular_queue( &serial_rbuf );
		MUTEX_UNLOCK(&mutex01_serial_rbuf);

		MUTEX_LOCK(&mutex08_trans_status_buf);
			creat_circular_queue( &trans_status_buf );
		MUTEX_UNLOCK(&mutex08_trans_status_buf);

		MUTEX_LOCK(&mutex09_xbee_other_api_buf);
			creat_circular_queue( &xbee_other_api_buf );
		MUTEX_UNLOCK(&mutex09_xbee_other_api_buf);

		MUTEX_LOCK(&mutex10_serial_wbuf);
			creat_circular_queue( &serial_wbuf );
		MUTEX_UNLOCK(&mutex10_serial_wbuf);

		MUTEX_LOCK(&mutex12_trans_req_buf);
			creat_circular_queue( &trans_req_buf );
		MUTEX_UNLOCK(&mutex12_trans_req_buf);

		MUTEX_LOCK(&mutex11_route_record_buf);
			creat_circular_queue( &route_record_buf );
		MUTEX_UNLOCK(&mutex11_route_record_buf);

	//printf("\033[33mstart xbee_routine_thread_write_serial...\033[0m\r\n");
	do{
	    if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_write_serial,NULL)) != 0)
		{
	        printf ("Create xbee_routine_thread_write_serial error!\n");
			err_log("Create xbee_routine_thread_write_serial error!" , strlen("Create xbee_routine_thread_write_serial error!"));
	    }
	}while(ret != 0);

	//printf("\033[33mstart xbee_routine_thread_read_serial...\033[0m\r\n");
	do{
	    if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_read_serial,NULL)) != 0)
		{
	        printf ("Create xbee_routine_thread_read_serial error!\n");
			err_log("Create xbee_routine_thread_read_serial error!" , strlen("Create xbee_routine_thread_read_serial error!"));
	    }
	}while(ret != 0);

	//printf("\033[33mstart xbee_routine_thread_process_serial_rbuf...\033[0m\r\n");
	do{
    	if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_process_serial_rbuf,NULL)) != 0)
		{
       		printf ("Create xbee_routine_thread_process_serial_rbuf error!\n");
			err_log("Create xbee_routine_thread_process_serial_rbuf error!" , strlen("Create xbee_routine_thread_process_serial_rbuf error!"));
    	}
	}while(ret != 0);

	xbee_reset();
	sleep(1);
	XBeeNetInit();
	get_mac();

	//printf("\033[33mstart xbee_routine_thread_process_trans_status_buf...\033[0m\r\n");
	do{
    	if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_process_trans_status_buf,NULL)) != 0)
		{
        	printf ("Create xbee_routine_thread_process_trans_status_buf error!\n");
			err_log("Create xbee_routine_thread_process_trans_status_buf error!" , strlen("Create xbee_routine_thread_process_trans_status_buf error!"));
    	}
	}
	while(ret != 0);

	//printf("\033[33mstart xbee_routine_thread_process_trans_req_buf...\033[0m\r\n");
	do{
    	if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_process_trans_req_buf,NULL)) != 0)
		{
    	    printf ("Create xbee_routine_thread_process_trans_req_buf error!\n");
			err_log("Create xbee_routine_thread_process_trans_req_buf error!" , strlen("Create xbee_routine_thread_process_trans_req_buf error!"));
    	}
	}
	while(ret != 0);

	//printf("\033[33mstart xbee_routine_thread_process_route_record_buf...\033[0m\r\n");
	do{
    	if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_process_route_record_buf,NULL)) != 0)
		{
			printf ("Create xbee_routine_thread_process_route_record_buf error!\n");
			err_log("Create xbee_routine_thread_process_route_record_buf error!" , strlen("Create xbee_routine_thread_process_route_record_buf error!"));
		}
	}
	while(ret != 0);

	//printf("\033[33mstart xbee_routine_thread_process_other_api_buf...\033[0m\r\n");
	do{
    	if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_process_other_api_buf,NULL)) != 0)
		{
			printf ("Create xbee_routine_thread_process_other_api_buf error!\n");
			err_log("Create xbee_routine_thread_process_other_api_buf error!" , strlen("Create xbee_routine_thread_process_other_api_buf error!"));
    	}
	}while(ret != 0);

#if __XBEE_TEST__
	//printf("\033[33mstart xbee_routine_thread_test...\033[0m\r\n");
	do{
		if((ret=pthread_create(&id,NULL,(void *) xbee_routine_thread_test,NULL)) != 0)
		{
	        printf ("Create xbee_routine_thread_test error!n");
	    }
	}while(ret != 0);
#endif
	while(1)
	{
		uint16 i=0,n=0;
		SourceRouterLinkType *p=NULL;
		MUTEX_LOCK(&mutex13_pSourcePathList);
		n = LinkLenth(pSourcePathList);
		for(i=1;i<=n;i++)
		{
			p = FindnNode(pSourcePathList,i);
			if(p->cnt-- < 1)
				DeleteNode(pSourcePathList,p);
			p = NULL;
		}
		MUTEX_UNLOCK(&mutex13_pSourcePathList);
		usleep(5000000);
		//usleep(2000000);
	}
}