Ejemplo n.º 1
0
void service_delete(struct service_t * service) {
	if (service) {
		if (service->lparser) lua_close(service->lparser);
		if (service->timer) timer_destroy(service->timer);
		FREE(service);
	}
}
Ejemplo n.º 2
0
/// test few results known as good
static void test_t1(void **state)
{
    (void) state;   // unused

    ptr_exp2 = 0;
    tv_exp1.tv_sec = 0;
    tv_exp1.tv_usec = 0;
    tv_exp2.tv_sec = 0;
    tv_exp2.tv_usec = 0;

    timer_t *timer = timer_create();
    assert_non_null(timer);

    assert_true(timer_register(timer, callback1, (void *)1000));
    tv_exp1.tv_usec = 1;
    timer_tick(timer, false, 1);
    timer_cancel(timer, callback1, (void *)1000);

    assert_true(timer_register(timer, callback1, (void *)1000));
    assert_false(timer_register(timer, callback1, (void *)1000));

    assert_true(timer_register(timer, callback2, (void *)0x100));
    assert_true(timer_register(timer, callback2, (void *)0x200));

    timer_cancel(timer, callback1, (void *)1000);
    timer_cancel(timer, callback1, (void *)1000);

    tv_exp1.tv_usec = -1;
    tv_exp2.tv_usec = 3;
    timer_tick(timer, false, 2);
    assert_int_equal(ptr_exp2, 0x300);

    timer_destroy(timer);
}
Ejemplo n.º 3
0
void program_scheduler_destroy(ProgramScheduler *program_scheduler) {
	program_scheduler_shutdown(program_scheduler);

	if (program_scheduler->last_spawned_process != NULL) {
		object_remove_internal_reference(&program_scheduler->last_spawned_process->base);
	}

	if (program_scheduler->message != NULL) {
		string_unlock_and_release(program_scheduler->message);
	}

	timer_destroy(&program_scheduler->timer);

	string_unlock_and_release(program_scheduler->dev_null_file_name);
	free(program_scheduler->log_directory);

	if (program_scheduler->absolute_stderr_file_name != NULL) {
		string_unlock_and_release(program_scheduler->absolute_stderr_file_name);
	}

	if (program_scheduler->absolute_stdout_file_name != NULL) {
		string_unlock_and_release(program_scheduler->absolute_stdout_file_name);
	}

	if (program_scheduler->absolute_stdin_file_name != NULL) {
		string_unlock_and_release(program_scheduler->absolute_stdin_file_name);
	}

	if (program_scheduler->absolute_working_directory != NULL) {
		string_unlock_and_release(program_scheduler->absolute_working_directory);
	}
}
Ejemplo n.º 4
0
static int detach(void *client_data, int idx)
{
        connect_info_t *connect_info = (connect_info_t *) client_data;

        if (connect_info->timer_id != -1) timer_destroy(connect_info->timer_id);
//        sockbuf_detach_filter(idx, &net_connect_filter, NULL);
        free(connect_info);
        return(0);
}
Ejemplo n.º 5
0
/* testet, ob der Computer schnell genug für das
   Atomfeld ist */
gboolean afield_benchmark(GtkWidget *darea, AtomField *af, gdouble max_t)
{
    MyTimer *timer;
    gulong i;

    timer = timer_new(1.0);

    for (i = 0; i < af->number; i++) {
        if (timer_elapsed(timer) > max_t) {
            timer_destroy(timer);
            return FALSE;
        }
        afield_draw_atom(darea, af, i);
    }

    timer_destroy(timer);

    return TRUE;
}
Ejemplo n.º 6
0
static int dcc_recv_connect(void *client_data, int idx, const char *peer_ip, int peer_port)
{
	dcc_send_t *send = client_data;

	/* send->connect_time holds our connect timer if there was one */
	if (send->timer_id >= 0) timer_destroy(send->timer_id);
	timer_get_now_sec(&send->connect_time);
	sockbuf_on_connect(idx, DCC_FILTER_LEVEL, peer_ip, peer_port);
	return(0);
}
Ejemplo n.º 7
0
void game_destroy(Game* game) {
    timer_destroy(game->timer);
    scene_destroy(game->scene);

    SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Destroy Vertex Arrays.\n");
    glDeleteVertexArrays(1, &game->vao_id);
    SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Destroy GL context.\n");
    glcontext_destroy(game->gl);

    window_destroy(game->window);
    free(game);
}
Ejemplo n.º 8
0
int main()
{
    bool auto_reload = true;

    task_t task1;
    create_timer(&tt, "name", 500, auto_reload, NULL, (task_routine_t)handle_sig);

    system_init();
    task_create(&task1, task, NULL, NULL, 0, 0);
    system_start();

    timer_destroy(tt);

    return 0;
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
	struct timer *timer = timer_new();
	sleep(1);
	printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL));

	timer_stop(timer);
	sleep(1);
	printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL));

	timer_continue(timer);
	sleep(1);
	printf("Elapsed: %lu ms\n", timer_elapsed(timer, NULL));

	timer_destroy(&timer);
	return 0;
}
Ejemplo n.º 10
0
void timers_remove(uint8_t pos) {
	if(selected==pos){
		selected=-1;
	}
	if(selected>pos){
		selected--;
	}
	if(timer_getDirection(timers[pos])==TIMER_DIRECTION_UP){
		count->stopwatch--;
	}else{
		count->timer--;
	}
	timer_destroy(timers[pos]);
	for(uint8_t i=pos;i<timers_count();i++){
		timers[i]=timers[i+1];
	}
	timers_updateNearest();
}
Ejemplo n.º 11
0
static int dcc_recv_delete(void *client_data, int idx)
{
	dcc_send_t *send = client_data;
	dcc_send_t *prev, *ptr;

	if (send->timer_id != -1) timer_destroy(send->timer_id);

	if (send->fd != -1) close(send->fd);
	if (send->fname) free(send->fname);
	if (send->nick) free(send->nick);
	if (send->ip) free(send->ip);
	prev = NULL;
	for (ptr = dcc_recv_head; ptr; ptr = ptr->next) {
		if (ptr == send) break;
		prev = ptr;
	}
	if (prev) prev->next = send->next;
	else dcc_recv_head = send->next;
	free(send);
	return(0);
}
Ejemplo n.º 12
0
void udelay(int us)
{
	u8 heap[0x10];
	u32 msg;
	s32 mqueue = -1;
	s32 timer = -1;

	mqueue = mqueue_create(heap, 1);
	if(mqueue < 0)
		goto out;
	timer = timer_create(us, 0, mqueue, 0xbabababa);
	if(timer < 0)
		goto out;
	mqueue_recv(mqueue, &msg, 0);
	
out:
	if(timer > 0)
		timer_destroy(timer);
	if(mqueue > 0)
		mqueue_destroy(mqueue);
}
Ejemplo n.º 13
0
static int dcc_listen_delete(event_owner_t *owner, void *client_data)
{
	dcc_listen_t *listen = client_data;

	/* If the timer is still going, kill it. */
	if (listen->timer_id != -1) {
		timer_destroy(listen->timer_id);
		listen->timer_id = -1;
	}

	/* If we're still waiting for the connection to come in, then send
	 * an error to the associated client sock. */
	if (sockbuf_isvalid(listen->client)) {
		if (listen->timeout) {
			sockbuf_on_eof(listen->client, SOCKBUF_LEVEL_INTERNAL, -1, "DCC timed out");
		}
		else {
			sockbuf_on_eof(listen->client, SOCKBUF_LEVEL_INTERNAL, -2, "DCC listening socket unexpectedly closed");
		}
	}
	free(listen);
	return(0);
}
Ejemplo n.º 14
0
void storage_load(){
	APP_LOG(APP_LOG_LEVEL_INFO,"storage_load()");
	
	if(!persist_exists(STORAGE_KEY_VERSION)){ 
		APP_LOG(APP_LOG_LEVEL_WARNING,"no version"); 
		return;
	}
	if(persist_read_int(STORAGE_KEY_VERSION)!=STORAGE_VERSION){
		APP_LOG(APP_LOG_LEVEL_WARNING,"wrong version");
		return;
	}
	if(!persist_exists(STORAGE_KEY_COUNT)){ 
		APP_LOG(APP_LOG_LEVEL_ERROR,"no count"); 
		return;
	}
	uint8_t storage_count=(uint8_t)persist_read_int(STORAGE_KEY_COUNT);
 	APP_LOG(APP_LOG_LEVEL_INFO,"storage count: %d",storage_count);
	Timer* timer;
	int result;
	for(uint8_t i=0;i<storage_count;i++){
		if(!persist_exists(STORAGE_KEY_DATA+i)){ 
			APP_LOG(APP_LOG_LEVEL_ERROR,"missing timer %d in storage %d",i,STORAGE_KEY_DATA+i); 
			continue;
		}
		timer=timer_create();
		result=persist_read_data(STORAGE_KEY_DATA+i,timer,sizeof(Timer));
		if(result<0){
			APP_LOG(APP_LOG_LEVEL_ERROR,"read error timer %d in storage %d",i,STORAGE_KEY_DATA+i);
			timer_destroy(timer);
			continue;
		}
		timers_add(timer);
		APP_LOG(APP_LOG_LEVEL_INFO,"loaded timer %d",i);
	}
		
	APP_LOG(APP_LOG_LEVEL_INFO,"loaded");
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
	bcm2835_init();

	timer_init();

	tlc_init();

	printf("got back!\n");
	fflush (stdout);

	for (int i=0; i<16; i++)
		tlc_set_duty_cycle(i, 4095);

	//tlc_pack_send_buffer();
	//tlc_update_gpio();

//	sleep(15);
	usleep(5000);

//	for (int i=0; i<16; i++)
//		tlc_set_duty_cycle(i, 2048);
	tlc_set_duty_cycle(15, 2048);

	usleep(5000);

	printf("Run successful\n");

	tlc_destroy();

	timer_destroy();

	bcm2835_close();

	return 0;
}
Ejemplo n.º 16
0
Archivo: gt.c Proyecto: eligo/mul
void gt_release() {
	lock_delete(gT->mLock);
	timer_destroy(gT->mTimer);
	free(gT);
}
Ejemplo n.º 17
0
// destructor
CE_Network_Loading::~CE_Network_Loading() {
  timer_destroy(t_settle);
}
Ejemplo n.º 18
0
// main program
int main (int argc, char **argv)
{
    // command-line options
    int verbose = 1;

    int ppm_error = 0;
    int gain = 0;
    unsigned int nfft    = 64;
    float offset         = -65.0f;
    float scale          = 5.0f;
    float fft_rate       = 10.0f;
    float rx_resamp_rate;
    float bandwidth      = 800e3f;
    unsigned int logsize = 4096;
    char filename[256]   = "rtl_asgram.dat";
    int r, n_read;

    uint32_t frequency = 100000000;
    uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
    uint32_t out_block_size = DEFAULT_BUF_LENGTH;
    uint8_t *buffer;

    int dev_index = 0;
    int dev_given = 0;

    struct sigaction sigact;
    normalizer_t *norm;

    //
    int d;
    while ((d = getopt(argc,argv,"hf:b:B:G:n:p:s:o:r:L:F:")) != EOF) {
        switch (d) {
        case 'h':
            usage();
            return 0;
        case 'f':
            frequency   = atof(optarg);
            break;
        case 'b':
            bandwidth   = atof(optarg);
            break;
        case 'B':
            out_block_size = (uint32_t)atof(optarg);
            break;
        case 'G':
            gain = (int)(atof(optarg) * 10);
            break;
        case 'n':
            nfft        = atoi(optarg);
            break;
        case 'o':
            offset      = atof(optarg);
            break;
        case 'p':
            ppm_error = atoi(optarg);
            break;
        case 's':
            samp_rate = (uint32_t)atofs(optarg);
            break;
        case 'r':
            fft_rate    = atof(optarg);
            break;
        case 'L':
            logsize     = atoi(optarg);
            break;
        case 'F':
            strncpy(filename,optarg,255);
            break;
        case 'd':
            dev_index = verbose_device_search(optarg);
            dev_given = 1;
            break;
        default:
            usage();
            return 1;
        }
    }

    // validate parameters
    if (fft_rate <= 0.0f || fft_rate > 100.0f) {
        fprintf(stderr,"error: %s, fft rate must be in (0, 100) Hz\n", argv[0]);
        exit(1);
    }

    if (!dev_given) {
        dev_index = verbose_device_search("0");
    }

    if (dev_index < 0) {
        exit(1);
    }

    r = rtlsdr_open(&dev, (uint32_t)dev_index);
    if (r < 0) {
        fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
        exit(1);
    }

    sigact.sa_handler = sighandler;
    sigemptyset(&sigact.sa_mask);
    sigact.sa_flags = 0;
    sigaction(SIGINT, &sigact, NULL);
    sigaction(SIGTERM, &sigact, NULL);
    sigaction(SIGQUIT, &sigact, NULL);
    sigaction(SIGPIPE, &sigact, NULL);

    /* Set the sample rate */
    verbose_set_sample_rate(dev, samp_rate);

    /* Set the frequency */
    verbose_set_frequency(dev, frequency);

    if (0 == gain) {
        /* Enable automatic gain */
        verbose_auto_gain(dev);
    } else {
        /* Enable manual gain */
        gain = nearest_gain(dev, gain);
        verbose_gain_set(dev, gain);
    }

    verbose_ppm_set(dev, ppm_error);

    rx_resamp_rate = bandwidth/samp_rate;

    printf("frequency       :   %10.4f [MHz]\n", frequency*1e-6f);
    printf("bandwidth       :   %10.4f [kHz]\n", bandwidth*1e-3f);
    printf("sample rate     :   %10.4f kHz = %10.4f kHz * %8.6f\n",
           samp_rate * 1e-3f,
           bandwidth    * 1e-3f,
           1.0f / rx_resamp_rate);
    printf("verbosity       :    %s\n", (verbose?"enabled":"disabled"));

    unsigned int i;

    // add arbitrary resampling component
    msresamp_crcf resamp = msresamp_crcf_create(rx_resamp_rate, 60.0f);
    assert(resamp);

    // create buffer for sample logging
    windowcf log = windowcf_create(logsize);

    // create ASCII spectrogram object
    float maxval;
    float maxfreq;
    char ascii[nfft+1];
    ascii[nfft] = '\0'; // append null character to end of string
    asgram q = asgram_create(nfft);
    asgram_set_scale(q, offset, scale);

    // assemble footer
    unsigned int footer_len = nfft + 16;
    char footer[footer_len+1];
    for (i=0; i<footer_len; i++)
        footer[i] = ' ';
    footer[1] = '[';
    footer[nfft/2 + 3] = '+';
    footer[nfft + 4] = ']';
    sprintf(&footer[nfft+6], "%8.3f MHz", frequency*1e-6f);
    unsigned int msdelay = 1000 / fft_rate;

    // create/initialize Hamming window
    float w[nfft];
    for (i=0; i<nfft; i++)
        w[i] = hamming(i,nfft);

    //allocate recv buffer
    buffer = malloc(out_block_size * sizeof(uint8_t));
    assert(buffer);

    // create buffer for arbitrary resamper output
    int b_len = ((int)(out_block_size * rx_resamp_rate) + 64) >> 1;
    complex float buffer_resamp[b_len];
    debug("resamp_buffer_len: %d", b_len);

    // timer to control asgram output
    timer t1 = timer_create();
    timer_tic(t1);

    norm = normalizer_create();

    verbose_reset_buffer(dev);

    while (!do_exit) {
        // grab data from device
        r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read);
        if (r < 0) {
            fprintf(stderr, "WARNING: sync read failed.\n");
            break;
        }

        if ((bytes_to_read > 0) && (bytes_to_read < (uint32_t)n_read)) {
            n_read = bytes_to_read;
            do_exit = 1;
        }

        // push data through arbitrary resampler and give to frame synchronizer
        // TODO : apply bandwidth-dependent gain
        for (i=0; i<n_read/2; i++) {
            // grab sample from usrp buffer
            complex float rtlsdr_sample = normalizer_normalize(norm, *((uint16_t*)buffer+i));

            // push through resampler (one at a time)
            unsigned int nw;
            msresamp_crcf_execute(resamp, &rtlsdr_sample, 1, buffer_resamp, &nw);

            // push resulting samples into asgram object
            asgram_push(q, buffer_resamp, nw);

            // write samples to log
            windowcf_write(log, buffer_resamp, nw);
        }

        if ((uint32_t)n_read < out_block_size) {
            fprintf(stderr, "Short read, samples lost, exiting!\n");
            break;
        }

        if (bytes_to_read > 0)
            bytes_to_read -= n_read;

        if (timer_toc(t1) > msdelay*1e-3f) {
            // reset timer
            timer_tic(t1);

            // run the spectrogram
            asgram_execute(q, ascii, &maxval, &maxfreq);

            // print the spectrogram
            printf(" > %s < pk%5.1fdB [%5.2f]\n", ascii, maxval, maxfreq);
            printf("%s\r", footer);
            fflush(stdout);
        }
    }

    // try to write samples to file
    FILE * fid = fopen(filename,"w");
    if (fid != NULL) {
        // write header
        fprintf(fid, "# %s : auto-generated file\n", filename);
        fprintf(fid, "#\n");
        fprintf(fid, "# num_samples :   %u\n", logsize);
        fprintf(fid, "# frequency   :   %12.8f MHz\n", frequency*1e-6f);
        fprintf(fid, "# bandwidth   :   %12.8f kHz\n", bandwidth*1e-3f);

        // save results to file
        complex float * rc;   // read pointer
        windowcf_read(log, &rc);
        for (i=0; i<logsize; i++)
            fprintf(fid, "%12.4e %12.4e\n", crealf(rc[i]), cimagf(rc[i]));

        // close it up
        fclose(fid);
        printf("results written to '%s'\n", filename);
    } else {
        fprintf(stderr,"error: %s, could not open '%s' for writing\n", argv[0], filename);
    }

    // destroy objects
    normalizer_destroy(&norm);
    msresamp_crcf_destroy(resamp);
    windowcf_destroy(log);
    asgram_destroy(q);
    timer_destroy(t1);

    rtlsdr_close(dev);
    free (buffer);

    return 0;
}