Ejemplo n.º 1
0
void sleep_syscall(unsigned long millis __attribute__((unused)))
{
    size_t wait_time = get_millis() + millis;
    enable_interrupts();
    while (get_millis() < wait_time);
    disable_interrupts();
}
Ejemplo n.º 2
0
void Player::read_payload(payload p)
{
    if(p.type == 0)
    {
        if(p.message2 == Player::Id)
            Player::last_success_ping += 1600;
    }
    else if(p.type == 2)
    {
        Player::team0_hill_status = p.message;
        Player::team1_hill_status = p.message2;
        Player::last_receive = get_millis();
    }
    else if(p.type == 3)
    {
        Player::team0_global_status = p.message;
        Player::team1_global_status = p.message2;
        Player::last_receive = get_millis();
    }
    else if(p.type == 4)
    {
        if(Player::gameStatus == INIT)
        {
            Player::global_points_max = p.message | p.message2;
            
            Player::gameStatus = START;

            Player::prelude_start_time = get_millis();
        }
    }

}
Ejemplo n.º 3
0
/**
 * Delay for a number of milliseconds, based off the systick timer
 * Delays around a small number of milliseconds may be inaccurate
 * @param delay Number of milliseconds to delay.
 */
void delay_ms(const uint32_t delay)
{
	uint32_t millis;

    millis = get_millis();
    while((get_millis() - millis) < delay);
}
Ejemplo n.º 4
0
void wait(uint32_t length){
	uint32_t dummy_count = 0;
	uint32_t now = get_millis();
	while(get_millis() <= (now + length)){
		dummy_count ++;
	}
	
	return;
}
Ejemplo n.º 5
0
static void client()
{
	int drmfd, ret;
	unsigned int time;

	wait_event(0, SERVER_READY);

	/* XXX: Should make sure we open the same DRM as the master */
	drmfd = drm_open_any();

	client_auth(drmfd);

	/* Wait for the server to grab the lock, then grab it ourselves (to
	 * contest it).  Hopefully we hit it within the window of when the
	 * server locks.
	 */
	wait_event(0, SERVER_LOCKED);
	ret = drmGetLock(drmfd, lock2, 0);
	time = get_millis();
	if (ret != 0)
		err(1, "Failed to get lock on client\n");
	drmUnlock(drmfd, lock2);

	/* Tell the server that our locking completed, and when it did */
	send_event(0, CLIENT_LOCKED);
	ret = write(commfd[0], &time, sizeof(time));

	close(drmfd);
	exit(0);
}
Ejemplo n.º 6
0
static void mavlink_request_data_streams(struct timer *t, void *d)
{
    unsigned char i;
    
    if (get_millis() - uav_last_seen > 5)
        return;
    
    for (i = 1; i < sizeof(mavlink_stream_map); i++)
        mavlink_request_data_stream(i, config.mav.streams[i - 1]);
}
Ejemplo n.º 7
0
static void start_calc_stats(void)
{
    /* flight start time */
    stats.flight_start = get_millis();
    stats.max_air_speed = 0;
    stats.max_gnd_speed = 0;
    stats.max_altitude = 0;
    stats.max_home_distance = 0;

    /* start calcs in a 100ms interval */
    add_timer(TIMER_ALWAYS, 1, calc_stats, NULL);
}
Ejemplo n.º 8
0
static void shell_cmd_stats(char *args, void *data)
{
    mavlink_status_t *status;
    unsigned char i;

    for (i = 0; i < MAVLINK_COMM_NUM_BUFFERS; i++) {
        status = mavlink_get_channel_status(i);
        shell_printf("\nMavlink channel %d\n", i);
        shell_printf(" msg_received=%d\n", status->msg_received);
        shell_printf(" packet_rx_drop_count=%d\n", status->packet_rx_drop_count);
        shell_printf(" packet_rx_success_count=%d\n", status->packet_rx_success_count);
    }
    shell_printf("\nActive channel mask=%x\n", active_channel_mask);
    shell_printf("\nUAV last seen %lums ago\n", get_millis() - uav_last_seen);
}
Ejemplo n.º 9
0
static void
update( Context *context )
{
     unsigned long     t;
     IDirectFBSurface *surface = context->surface;
     static __u8  r = 0, g = 0, b = 0;
    
     
     context->gl->Lock( context->gl );

     glClearColor( r++/255.0, g++/255.0, b++/255.0, 1.0 );
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     context->gl->Unlock( context->gl );
     
     if (context->fps) {
          char buf[16];

          snprintf(buf, sizeof(buf), "%.1f FPS\n", context->fps);

          surface->SetColor( surface, 0xff, 0x00, 0x00, 0xff );
          surface->DrawString( surface, buf, -1,
                               context->width - 5, 5, DSTF_TOPRIGHT );
     }
     
     surface->Flip( surface, NULL, 0 );

     context->frames++;

     t = get_millis();
     if (t - context->last_time >= 2000) {
          float seconds = (t - context->last_time) / 1000.0f;

          context->fps = context->frames / seconds;

          context->last_time = t;
          context->frames    = 0;
     }
}
Ejemplo n.º 10
0
static void mav_heartbeat(struct timer *t, void *d)
{
    mavlink_message_t msg;

    LED = ~LED;

    if (get_millis() - uav_last_seen > UAV_LAST_SEEN_TIMEOUT) {
        set_timer_period(t, 5);
        return;
    } else {
        set_timer_period(t, 10);
    }
    
    mavlink_msg_heartbeat_pack(config.mav.osd_sysid,
            MAV_COMP_ID_OSD, &msg, MAV_TYPE_ALCEOSD,
            MAV_AUTOPILOT_INVALID,
            MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, // base_mode
            0, //custom_mode
            MAV_STATE_ACTIVE);

    mavlink_send_msg(&msg);
}
Ejemplo n.º 11
0
static void server()
{
	int drmfd, tempfd, ret;
	unsigned int client_time, unlock_time;

	drmfd = drm_open_any_master();

	test_lock_unlock(drmfd);
	test_unlock_unlocked(drmfd);
	test_unlock_unowned(drmfd);
	test_open_close_locked(drmfd);

	/* Perform the authentication sequence with the client. */
	server_auth(drmfd);

	/* Now, test that the client attempting to lock while the server
	 * holds the lock works correctly.
	 */
	ret = drmGetLock(drmfd, lock1, 0);
	assert(ret == 0);
	send_event(1, SERVER_LOCKED);
	/* Wait a while for the client to do its thing */
	sleep(1);
	ret = drmUnlock(drmfd, lock1);
	assert(ret == 0);
	unlock_time = get_millis();

	wait_event(1, CLIENT_LOCKED);
	ret = read(commfd[1], &client_time, sizeof(client_time));
	if (ret == -1)
		err(1, "Failure to read client magic");

	if (client_time < unlock_time)
		errx(1, "Client took lock before server released it");

	close(drmfd);
}
Ejemplo n.º 12
0
size_t time_syscall(void)
{
    return get_millis();
}
Ejemplo n.º 13
0
static void tab_switch_task(struct timer *t, void *d)
{
    struct tab_change_config *cfg = (struct tab_change_config*) d;
    unsigned int idx;
    unsigned char new_tab;


    if (get_millis() < 5000) {
        if (active_tab != 0)
            load_tab(0);
        return;
    } else if (active_tab == 0) {
        load_tab(1);
    }


    switch (cfg->mode) {
        case TAB_CHANGE_CHANNEL:
        default:
            idx = ((val * tab_list[0]) / 101) + 1;
            new_tab = tab_list[idx];
            if (new_tab != active_tab) {
                DTABS("tab_change_channel: change to tab %d\n", new_tab);
                load_tab((unsigned char) new_tab);
            }
            break;
        case TAB_CHANGE_FLIGHTMODE:
            /* idle */
            if (tmr == TAB_TIMER_IDLE) {
                break;
            } else if (tmr < cfg->time_window) {
                tmr++;
            } else {
                tmr = TAB_TIMER_IDLE;
            }
            break;
        case TAB_CHANGE_TOGGLE:
            /* idle val not acquired */
            if (val == 0)
                break;

            /* idle */
            if (tmr == TAB_TIMER_IDLE) {
                break;
            } else if (tmr < cfg->time_window) {
                tmr++;
                /* switch returned to idle position */
                if (prev_val == val) {
                    /* next tab */
                    active_tab_idx++;
                    if (active_tab_idx >= tab_list[0])
                        active_tab_idx = 0;
                    load_tab(tab_list[active_tab_idx+1]);

                    tmr = TAB_TIMER_IDLE;
                }
            } else if (tmr == cfg->time_window) {
                tmr++;
                /* previous tab */
                if (active_tab_idx == 0)
                    active_tab_idx = tab_list[0]-1;
                else
                    active_tab_idx--;
                load_tab(tab_list[active_tab_idx+1]);
            } else {
                /* wait until switch  returns to idle state */
                if (val == prev_val)
                    tmr = TAB_TIMER_IDLE;
            }

            break;
        case TAB_CHANGE_DEMO:
            tmr++;
            if (tmr > cfg->time_window) {
                /* next tab */
                active_tab_idx++;
                if (active_tab_idx >= tab_list[0])
                    active_tab_idx = 0;
                load_tab(tab_list[active_tab_idx+1]);

                tmr = 0;
            }
            break;
    }
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
	int quit = 0;
	DFBResult err;
	DFBSurfaceDescription dsc;

	DFBCHECK(DirectFBInit(&argc, &argv));

	// create the super interface
	DFBCHECK(DirectFBCreate(&dfb));

	// create an event buffer for all devices with these caps
	DFBCHECK(dfb->CreateInputEventBuffer(dfb, DICAPS_KEYS | DICAPS_AXES, DFB_FALSE, &events));

	// set our cooperative level to DFSCL_FULLSCREEN for exclusive access to the primary layer
	dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN);

	// get the primary surface, i.e. the surface of the primary layer we have exclusive access to
	dsc.flags = DSDESC_CAPS;
	dsc.caps  = DSCAPS_PRIMARY | DSCAPS_DOUBLE | DSCAPS_OPENGL_HINT;

	DFBCHECK(dfb->CreateSurface(dfb, &dsc, &primary));

	// get the size of the surface and fill it
	DFBCHECK(primary->GetSize(primary, &screen_width, &screen_height));
	DFBCHECK(primary->FillRectangle(primary, 0, 0, screen_width, screen_height));
	primary->Flip(primary, NULL, 0);

	// create the default font and set it
	DFBCHECK(dfb->CreateFont(dfb, NULL, NULL, &font));
	DFBCHECK(primary->SetFont(primary, font));

	// get the GL context
	DFBCHECK(primary->GetGL(primary, &primary_gl));

	DFBCHECK(primary_gl->Lock(primary_gl));

	init(argc, argv);
	reshape(screen_width, screen_height);

	DFBCHECK(primary_gl->Unlock(primary_gl));

	T0 = get_millis();

	while (!quit)
	{
		DFBInputEvent evt;
		unsigned long t;

		DFBCHECK(primary_gl->Lock(primary_gl));

		draw();

		DFBCHECK(primary_gl->Unlock(primary_gl));

		if (fps)
		{
			char buf[64];

			snprintf(buf, 64, "%4.1f FPS\n", fps);

			primary->SetColor(primary, 0xff, 0, 0, 0xff);
			primary->DrawString(primary, buf, -1, screen_width - 5, 5, DSTF_TOPRIGHT);
		}

		primary->Flip(primary, NULL, 0);
		Frames++;


		t = get_millis();
		if (t - T0 >= 2000)
		{
			GLfloat seconds = (t - T0) / 1000.0;

			fps = Frames / seconds;

			T0 = t;
			Frames = 0;
		}


		while (events->GetEvent(events, DFB_EVENT(&evt)) == DFB_OK)
		{
			switch (evt.type)
			{
				case DIET_KEYPRESS:
					switch (evt.key_symbol)
					{
						case DIKS_ESCAPE:
							quit = 1;
							break;
						case DIKS_CURSOR_UP:
 							inc_y = 0.1;
							break;
						case DIKS_CURSOR_DOWN:
							inc_y = -0.1;
							break;
						case DIKS_CURSOR_LEFT:
							inc_x = -0.1;
							break;
						case DIKS_CURSOR_RIGHT:
							inc_x = 0.1;
							break;
						case DIKS_PAGE_UP:
							inc_z = 0.01;
							break;
						case DIKS_PAGE_DOWN:
							inc_z = -0.01;
							break;
						default:
							;
					}
					break;
				case DIET_KEYRELEASE:
					switch (evt.key_symbol)
					{
						case DIKS_CURSOR_UP:
							inc_y = 0;
							break;
						case DIKS_CURSOR_DOWN:
							inc_y = 0;
							break;
						case DIKS_CURSOR_LEFT:
							inc_x = 0;
							break;
						case DIKS_CURSOR_RIGHT:
							inc_x = 0;
							break;
						case DIKS_PAGE_UP:
							inc_z = 0;
							break;
						case DIKS_PAGE_DOWN:
							inc_z = 0;
							break;
						default:
							;
					}
					break;
				case DIET_AXISMOTION:
					if (evt.flags & DIEF_AXISREL)
					{
						switch (evt.axis)
						{
							case DIAI_X:
								view_x += evt.axisrel / 2.0;
								break;
							case DIAI_Y:
								view_y -= evt.axisrel / 2.0;
								break;
							case DIAI_Z:
								view_z += evt.axisrel / 2.0;
								break;
							default:
								;
						}
					}
					break;
				default:
					;
			}
		}

		view_x += inc_x;
		view_y += inc_y;
		view_z += inc_z;
	}

	// release our interfaces to shutdown DirectFB
	primary_gl->Release(primary_gl);
	primary->Release(primary);
	font->Release(font);
	events->Release(events);
	dfb->Release(dfb);

	return 0;
}
Ejemplo n.º 15
0
int
main( int argc, char *argv[] )
{
     DirectResult         ret;
     FusionWorld         *world;
     FusionCall           call = {0};
     FusionSHMPoolShared *pool;
     void                *buffer;
     int           i, max_busy = 0, active = 1;
     long long     t1 = 0, t2;
     long long     start       = 0;
     long long     bytes       = 0;
     long long     last_bytes  = 0;
     unsigned long blocks      = 0;
     unsigned long last_blocks = 0;
     unsigned long last_busy   = 0;
     u32           checksum    = 0;
     bool          produce     = true;
     int           delay       = 66000;

     if (parse_cmdline( argc, argv ))
          return -1;

     if (bit_rate) {
          int blocks_per_sec = (bit_rate * 1024 / 8) / block_size;

          if (blocks_per_sec < 100)
               delay = 900000 / blocks_per_sec - 2000;
          else
               delay = 300000 * 100 / blocks_per_sec;

          num_blocks = bit_rate * 1024 / 8 / block_size * delay / 900000;

          if (num_blocks > MAX_NUM_BLOCKS)
               num_blocks = MAX_NUM_BLOCKS;

          if (!num_blocks) {
               num_blocks = 1;
               delay = 970 * block_size / (bit_rate * 1024 / 8) * 1000 - 2000;
          }
     }

     sync();

     if (run_busy) {
          pthread_create( &busy_thread, NULL, busy_loop, NULL );

          printf( "Calibrating...\n" );
     
          pthread_mutex_lock( &busy_lock );
     
          for (i=0; i<7; i++) {
               int busy_rate;
     
               busy_count = 0;
     
               t1 = get_millis();
               pthread_mutex_unlock( &busy_lock );
     
               usleep( 300000 );
     
               pthread_mutex_lock( &busy_lock );
               t2 = get_millis();
     
               busy_rate = busy_count * 1000 / (t2 - t1);
     
               if (busy_rate > max_busy)
                    max_busy = busy_rate;
          }
     
          printf( "Calibrating done. (%d busy counts/sec)\n", max_busy );
     }

     ret = fusion_enter( -1, 23, FER_MASTER, &world );
     if (ret)
          return ret;

     ret = fusion_call_init( &call, call_handler, NULL, world );
     if (ret)
          return ret;

     ret = fusion_shm_pool_create( world, "Stream Buffer", block_size + 8192, false, &pool );
     if (ret)
          return ret;

     ret = fusion_shm_pool_allocate( pool, block_size, false, true, &buffer );
     if (ret)
          return ret;



     /*
      * Do the fork() magic!
      */
     if (do_fork) {
          fusion_world_set_fork_action( world, FFA_FORK );

          switch (fork()) {
               case -1:
                    D_PERROR( "fork() failed!\n" );
                    return -1;

               case 0:
                    /* child continues as the producer */
                    run_busy = false;
                    break;

               default:
                    /* parent is the consumer (callback in Fusion Dispatch thread) */
                    produce = false;

                    usleep( 50000 );
          }

          fusion_world_set_fork_action( world, FFA_CLOSE );
     }


     start = t1 = get_millis();

     if (run_busy) {
          busy_count = 0;
          pthread_mutex_unlock( &busy_lock );
     }

#ifdef LINUX_2_4
     delay -= 10000;
#endif

     do {
          if (bit_rate || !produce) {
               if (delay > 10)
                    usleep( delay );
          }

          if (produce) {
               for (i=0; i<num_blocks; i++) {
                    int  n;
                    u32  retsum;
                    u32 *values = buffer;

                    for (n=0; n<block_size/4; n++) {
                         values[n] = n;
                         checksum += n;
                    }

                    bytes += block_size;

                    fusion_call_execute( &call, do_thread ? FCEF_NODIRECT : FCEF_NONE,
                                         0, buffer, (int*) &retsum );

                    if (retsum != checksum)
                         D_ERROR( "Checksum returned by consumer (0x%08x) does not match 0x%08x!\n", retsum, checksum );
               }

               blocks += num_blocks;
          }


          t2 = get_millis();
          if (t2 - t1 > 2000) {
               if (produce) {
                    long long kbits = 0, avgkbits, total_time, diff_time, diff_bytes;

                    printf( "\n\n\n" );

                    total_time = t2 - start;
                    diff_time  = t2 - t1;
                    diff_bytes = bytes - last_bytes;

                    avgkbits   = (long long)bytes * 8LL * 1000LL / (long long)total_time / 1024LL;

                    if (diff_time)
                         kbits = (long long)diff_bytes * 8LL * 1000LL / (long long)diff_time / 1024LL;

                    printf( "Total Time:       %7lld ms\n", total_time );
                    printf( "Stream Size:      %7lld kb\n", bytes / 1024 );
                    printf( "Stream Rate:      %7lld kb/sec -> %lld.%03lld MBit (avg. %lld.%03lld MBit)\n",
                            kbits / 8,
                            (kbits * 1000 / 1024) / 1000, (kbits * 1000 / 1024) % 1000,
                            (avgkbits * 1000 / 1024) / 1000, (avgkbits * 1000 / 1024) % 1000 );
                    printf( "\n" );


                    if (last_bytes && bit_rate) {
                         long long diff_bytes = (bytes - last_bytes) * 1000 / (t2 - t1);
                         long long need_bytes = bit_rate * 1024 / 8;

                         if (diff_bytes) {
                              int new_blocks = (num_blocks * need_bytes + diff_bytes/2) / diff_bytes;

                              num_blocks = (new_blocks + num_blocks + 1) / 2;

                              if (num_blocks > MAX_NUM_BLOCKS)
                                   num_blocks = MAX_NUM_BLOCKS;
                         }
                    }


                    read_stat();

                    if (ftotal != ctotal && dtotal) {
                         int load, aload;

                         load  = 1000 - didle * 1000 / dtotal;
                         aload = 1000 - (cidle - fidle) * 1000 / (ctotal - ftotal);

                         printf( "Overall Stats\n" );
                         printf( "  Total Time:      %7lld ms\n", t2 - start );
                         printf( "  Block Size:      %7ld\n", block_size );
                         printf( "  Blocks/cycle:    %7ld\n", num_blocks );
                         printf( "  Blocks/second:   %7lld\n", (blocks - last_blocks) * 1000 / diff_time );
                         printf( "  Delay:           %7d\n", delay );
                         printf( "  CPU Load:        %5d.%d %% (avg. %d.%d %%)\n",
                                 load / 10, load % 10, aload / 10, aload % 10 );
                    }


                    last_bytes  = bytes;
                    last_blocks = blocks;
               }

               if (run_busy) {
                    pthread_mutex_lock( &busy_lock );

                    if (last_busy) {
                         int busy_diff;
                         int busy_rate, busy_load;
                         int abusy_rate, abusy_load;

                         busy_diff = busy_count - last_busy;
                         busy_rate = max_busy - (busy_diff * 1000 / (t2 - t1));
                         busy_load = busy_rate * 1000 / max_busy;
                         abusy_rate = max_busy - (busy_count * 1000 / (t2 - start));
                         abusy_load = abusy_rate * 1000 / max_busy;

                         printf( "  Real CPU Load:   %5d.%d %% (avg. %d.%d %%)\n",
                                 busy_load / 10, busy_load % 10,
                                 abusy_load / 10, abusy_load % 10 );
                    }

                    last_busy = busy_count;

                    pthread_mutex_unlock( &busy_lock );
               }

               t1 = t2;
          }
     } while (active > 0);


     if (run_busy) {
          busy_alive = 0;

          pthread_join( busy_thread, NULL );
     }

     return -1;
}
Ejemplo n.º 16
0
int
main( int argc, char *argv[] )
{
     DFBResult ret;
     int       i;
     int       quit = 0;
     const int num = 2;
     Context   contexts[num];

     DFBCHECK(DirectFBInit( &argc, &argv ));

     /* create the super interface */
     DFBCHECK(DirectFBCreate( &dfb ));

     DFBCHECK(dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer ));

     /* create the default font */
     DFBCHECK(dfb->CreateFont( dfb, NULL, NULL, &font ));

     for (i=0; i<num; i++) {
          IDirectFBWindow      *window;
          IDirectFBSurface     *surface;
          IDirectFBGL          *gl;
          DFBWindowDescription  desc;

          desc.flags  = DWDESC_POSX | DWDESC_POSY |
                        DWDESC_WIDTH | DWDESC_HEIGHT;
          desc.posx   = (i%3) * 200 + 10;
          desc.posy   = (i/3) * 200 + 10;
          desc.width  = 180;
          desc.height = 180;

          DFBCHECK(layer->CreateWindow( layer, &desc, &window ));
          DFBCHECK(window->GetSurface( window, &surface ));
          DFBCHECK(surface->GetGL( surface, &gl ));

          contexts[i].window    = window;
          contexts[i].surface   = surface;
          contexts[i].gl        = gl;

          contexts[i].last_time = get_millis();
          contexts[i].frames    = 0;
          contexts[i].fps       = 0;

          setup( &contexts[i] );

          if (events)
               DFBCHECK(window->AttachEventBuffer( window, events ));
          else
               DFBCHECK(window->CreateEventBuffer( window, &events ));
          
          DFBCHECK(surface->SetFont( surface, font ));

          window->SetOpacity( window, 0xff );
     }
     
     while (!quit) {
          DFBWindowEvent evt;

          for (i=0; i<num; i++)
               update( &contexts[i] );
          
          while (events->GetEvent( events, DFB_EVENT(&evt) ) == DFB_OK) {
               switch (evt.type) {
                    case DWET_KEYDOWN:
                         switch (evt.key_symbol) {
                              case DIKS_ESCAPE:
                                   quit = 1;
                                   break;

                              default:
                                   break;
                         }
                         break;

                    default:
                         break;
               }
          }
     }

     events->Release( events );

     for (i=0; i<num; i++) {
          contexts[i].gl->Release( contexts[i].gl );
          contexts[i].surface->Release( contexts[i].surface );
          contexts[i].window->Release( contexts[i].window );
     }

     font->Release( font );
     layer->Release( layer );
     dfb->Release( dfb );

     return 0;
}
Ejemplo n.º 17
0
int main (void)
{
	if (!IK220Find (IKCard)) {		// Look for IK 220
		printf ("Error: IK220Find\n");
		if (!IK220DllStatus (&DllStatus, &DllInfo)) {
			printf ("Error: IK220DllStatus\n");		// Read DLL-Status
        }
		printf ("DLL-Status: 0x%08lX     DLL-Info: 0x%08lX", DllStatus, DllInfo);
		return;
	}

	for (Ax=0; Ax<6; Ax++) {
		if (IKCard[Ax]) {
			if (!IK220Init (Ax)) {                          // Initialize IK 220
				printf ("Error: IK220Init axis %d\n", Ax);
            }
			else {
				printf ("Axis %d initialized  -  ", Ax);

				// Read port address of IK card(s)
				if (!IK220Version (Ax, &VersCard[0], &VersDrv[0], &VersDll[0])) {
					printf ("Error: IKVersion\n");		// Read port address of IK card(s)
                }
				else {
					printf ("Card: %s  %s  %s\n", VersCard, VersDrv, VersDll);
               }
			}
		}
    }

	for (Ax=0; Ax<6; Ax++) {
		if (IKCard[Ax]) {
			printf ("IK 220 (%2d) at address: 0x%08lX\n", Ax, IKCard[Ax]);	
            printf ("\n");

            m_Active[Ax]            = 0;
            OldSta[Ax]              = 0xFFFF;
            m_SignalPeriod[Ax]      = 0.020;
            m_EncoderType[Ax]       = 1;
            m_SignalType[Ax]        = 1;

			if ( !IK220WritePar (Ax, 1, m_EncoderType[Ax]) ) 
				printf ("IK 220 (%2d) not set!\n", Ax);

			if ( !IK220WritePar (Ax, 2, m_SignalType[Ax]) ) 
				printf ("IK 220 (%2d) not set!\n", Ax);

			if (!IK220ResetEn  (Ax, &EnStatus)) 
				printf ("IK 220 (%2d) not reset!\n", Ax);

			if (!IK220ConfigEn (Ax, &EnStatus, &EnType, &EnPeriod, &EnStep, 
						              &EnTurns, &EnRefDist, &EnCntDir)) 
				printf ("IK 220 (%2d) not reset!\n", Ax);
			
			printf ("Axis %d: Status:%d Steps:%d Period:%d EnTurns:%d   \n",
											Ax, EnStatus, EnStep, EnPeriod, EnTurns);
//			if (!IK220StartRef  (Ax)) printf ("IK 220 (%2d) not started!\n", Ax);
//			if (!IK220ResetRef  (Ax)) printf ("IK 220 (%2d) not started!\n", Ax);
	    }
    }

	//sleep(3);

    printf("Now reading IK220 axes.\n");
    int trail_skip = 10;
    int trail_i = 0;
    while(1) {
        int rename_ret;
        char tmpname[] = "/var/dagor/run/position.tmp";
        char trailname[] = "/var/dagor/run/trail.txt";
        char txtname[] = "/var/dagor/run/position.txt";
        FILE *f = fopen(tmpname, "w");
        char f2_tim[] = "";
        double cntvals[6];
        int64_t millis = get_millis();
        if (f == NULL) {
            printf("Error opening file!\n");
            exit(1);
        }
        fprintf(f, "%u-%"PRId64"\n", (unsigned)time(NULL), millis);
        for (Ax=0; Ax<6; Ax++) {
            if (IKCard[Ax]) {
                if (!IK220ReadEn (Ax, &EnStatus, &CntVal, &EnAlarm)) {
                    cntvals[Ax] = 0;
                    printf ("Error: IK220Read48 card %d\n", Ax);	// Read counter value
                    fprintf(f, "%s\n", "ERROR");
                }
                else {
                    //printf("Axis %d: %12.4f  Status:%d   \n", Ax, CntVal, EnStatus);
                    cntvals[Ax] = CntVal;
                    fprintf(f,"%12.4f\n", CntVal);
                }
            }
        }
        if (trail_i >= trail_skip || trail_i == 0) {
            if( access( trailname, F_OK ) != -1 ) {
                trail_i = 0;
                FILE *f2 = fopen(trailname, "a+");
                fprintf(f2, "%"PRId64"\n%12.4f\n%12.4f\n", millis, cntvals[0], cntvals[1]);
                fclose(f2);
            }
        }
        fclose(f);
        rename_ret = rename(tmpname, txtname);
        if(rename_ret != 0) {
            printf("Error: unable to rename the file");
            exit(1);
        }
        nanosleep((struct timespec[]){{0, 0.01 * 1000000000}}, NULL);  // 0.01 sec
        trail_i++;
    }
Ejemplo n.º 18
0
static void mav_heartbeat_cbk(mavlink_message_t *msg, void *d)
{
    uav_last_seen = get_millis();
}