Пример #1
0
int main (int    argc,
	  char** argv)
/* ------------------------------------------------------------------------- *
 * Wrapper.
 * ------------------------------------------------------------------------- */
{
  int_t  i, n = 1, seed = 0;
  real_t mean = 0.0, sdev = 1.0;

  getargs (argc, argv, &n, &seed, &mean, &sdev);

#if 1
  raninit (seed);
#else
  raninit (-((short)time(NULL)));
#endif
  for (i = 0; i < n; i++) printf ("%g\n", dnormal(mean, sdev));

  return EXIT_SUCCESS;
}
Пример #2
0
void test_aa_map_arbitrary_kv_5(void) {

    char mem[aa_map_size];

    struct aa_map *m = aa_map_create( sizeof(mem)
                                    , mem
                                    , sizeof(int64_t)
                                    , ARBITRARY_LEN
                                    , __i64_cmp
                                    , __i64_cpy
                                    , __s32_cpy_never_ever
                                    , 0
                                    , __alloc
                                    , __dealloc
                                    );


    ranctx rctx;
    raninit(&rctx, 0xDEADBEEF);

    const size_t N = 50;
    size_t i = 0;

    const char dict[] = "qwertyuiopasdfghjklzxcvbnm"
                        "QWERTYUIOPASDFGHJKLZXCVBNM1234567890";

    for(; i < N; i++ ) {

        int64_t k = ranval(&rctx) % 10000;

        size_t ln2 = 1 + ranval(&rctx) % (ARBITRARY_LEN-2);
        char v[ARBITRARY_LEN];

        randstr(&rctx, v, ln2, dict);

        aa_map_alter(m, true, &k, v, __kv_5_alter);
    }

    aa_map_enum(m, 0, __kv_5_print);

    aa_map_filter(m, 0, __kv_5_filt_even);

    fprintf(stdout, "filtered\n");

    aa_map_enum(m, 0, __kv_5_print);

    aa_map_destroy(m);
}
Пример #3
0
void oneway_anchor_init () {
	// Make sure the SPI speed is slow for this function
	dw1000_spi_slow();

	// Setup callbacks to this ANCHOR
	dwt_setcallbacks(anchor_txcallback, anchor_rxcallback);

	// Make sure the radio starts off
	dwt_forcetrxoff();

	// Set the anchor so it only receives data and ack packets
	dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN);

	// // Set the ID and PAN ID for this anchor
	uint8_t eui_array[8];
	dw1000_read_eui(eui_array);
	// dwt_seteui(eui_array);
	// dwt_setpanid(POLYPOINT_PANID);

	// Automatically go back to receive
	dwt_setautorxreenable(TRUE);

	// Don't use these
	dwt_setdblrxbuffmode(FALSE);
	dwt_setrxtimeout(FALSE);

	// Load our EUI into the outgoing packet
	dw1000_read_eui(pp_anc_final_pkt.ieee154_header_unicast.sourceAddr);

	// Need a timer
	if (_anchor_timer == NULL) {
		_anchor_timer = timer_init();
	}

	// Init the PRNG for determining when to respond to the tag
	raninit(&_prng_state, eui_array[0]<<8|eui_array[1]);

	// Make SPI fast now that everything has been setup
	dw1000_spi_fast();

	// Reset our state because nothing should be in progress if we call init()
	_state = ASTATE_IDLE;
}
Пример #4
0
dw1000_err_e dw1000_anchor_init () {
	uint8_t eui_array[8];

	// Make sure the radio starts off
	dwt_forcetrxoff();

	// Set the anchor so it only receives data and ack packets
	dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN);

	// Set the ID and PAN ID for this anchor
	dw1000_read_eui(eui_array);
	dwt_seteui(eui_array);
	dwt_setpanid(POLYPOINT_PANID);

	// Automatically go back to receive
	dwt_setautorxreenable(TRUE);

	// Don't use these
	dwt_setdblrxbuffmode(FALSE);
	dwt_setrxtimeout(FALSE);

	// Don't receive at first
	dwt_rxenable(FALSE);

	// Load our EUI into the outgoing packet
	dw1000_read_eui(pp_anc_final_pkt.ieee154_header_unicast.sourceAddr);

	// Need a timer
	_ranging_broadcast_timer = timer_init();

	// Init the PRNG for determining when to respond to the tag
	raninit(&_prng_state, eui_array[0]<<8|eui_array[1]);

	// Make SPI fast now that everything has been setup
	dw1000_spi_fast();

	return DW1000_NO_ERR;
}
Пример #5
0
void test_aa_map_no_val_copy_1(void) {

    char mem[aa_map_size];

    struct aa_map *m = aa_map_create( sizeof(mem)
                                    , mem
                                    , sizeof(int64_t)
                                    , sizeof(int64_t)
                                    , __i64_cmp
                                    , __i64_cpy
                                    , 0 // NO VALUE COPY FUNCTION
                                    , 0
                                    , __alloc
                                    , __dealloc
                                    );


    ranctx rctx;
    raninit(&rctx, 0xDEADBEEF);

    const size_t N = 50;
    size_t i = 0;


    for(; i < N; i++ ) {

        int64_t k = ranval(&rctx) % 100000;

        fprintf(stdout, "added %ld? %s\n", k, aa_map_add(m, &k, &k) ? "yes" : "no");

        aa_map_alter(m, true, &k, 0, __no_val_copy_1_alter);
    }

    aa_map_enum(m, 0, __no_val_copy_1_print);

    aa_map_destroy(m);
}
Пример #6
0
void test_static_mem_pool_1(void) {

    ranctx rctx;
    raninit(&rctx, 0x128e437);

    struct static_mem_pool pool;

    struct hash *hs[20] = { 0 };
    const size_t HSIZE = sizeof(hs)/sizeof(hs[0]);

    void *pp = static_mem_pool_init( &pool
                                   , 8192 - sizeof(struct static_mem_pool)
                                   , 0
                                   , nomem
                                   , 0
                                   , 0
                                   , 0 );

    if( !pp ) {
        fprintf(stderr, "Can't setup memory pool\n");
        return;
    }

    size_t i = 0;
    for(; i < HSIZE; i++ ) {
        hs[i] = hash_create( hash_size
                           , static_mem_pool_alloc(&pool, hash_size)
                           , sizeof(uint32_t)
                           , sizeof(uint32_t)
                           , 32
                           , uint32_hash
                           , uint32_eq
                           , uint32_cpy
                           , uint32_cpy
                           , 0
                           , __alloc
                           , __dealloc );
    }

    for(i = 0; i < 100500; i++ ) {
        size_t hnum = ranval(&rctx) % HSIZE;
        uint32_t k = ranval(&rctx) % 1000001;
        uint32_t v = ranval(&rctx) % 99999999;
        hash_add(hs[hnum], &k, &v);
    }

    for(i = 0; i < HSIZE; i++ ) {

        size_t cap = 0, used = 0, cls = 0, maxb = 0;
        hash_stats(hs[i], &cap, &used, &cls, &maxb);

        fprintf( stdout
               , "\nhash#%zu\n"
                 "capacity:         %zu\n"
                 "used:             %zu\n"
                 "collisions (avg): %zu\n"
                 "max. row:         %zu\n"
               , i
               , cap
               , used
               , cls
               , maxb
               );


        hash_destroy(hs[i]);
    }

    static_mem_pool_destroy(&pool);
}
Пример #7
0
void test_aa_map_arbitrary_kv_3(void) {

    char mem[aa_map_size];

    struct aa_map *m = aa_map_create( sizeof(mem)
                                    , mem
                                    , ARBITRARY_LEN
                                    , ARBITRARY_LEN
                                    , __s32_cmp
                                    , __s32_cpy
                                    , __s32_cpy
                                    , 0
                                    , __alloc
                                    , __dealloc
                                    );

    struct aa_map *m2 = aa_map_create( sizeof(mem)
                                     , mem
                                     , ARBITRARY_LEN
                                     , ARBITRARY_LEN
                                     , __s32_cmp
                                     , __s32_cpy
                                     , __s32_cpy
                                     , 0
                                     , __alloc
                                     , __dealloc
                                     );


    ranctx rctx;
    raninit(&rctx, 0xDEADBEEF);

    const size_t N = 1000;
    size_t i = 0;

    const char dict[] = "qwertyuiopasdfghjklzxcvbnm"
                        "QWERTYUIOPASDFGHJKLZXCVBNM1234567890";

    for(; i < N; i++ ) {
        size_t ln1 = 1 + ranval(&rctx) % (ARBITRARY_LEN-2);
        size_t ln2 = 1 + ranval(&rctx) % (ARBITRARY_LEN-2);
        char k[ARBITRARY_LEN];
        char v[ARBITRARY_LEN];

        randstr(&rctx, k, ln1, dict);
        randstr(&rctx, v, ln2, dict);

        aa_map_add(m, k, v);

    }

    aa_map_enum(m, m2, __add_to_another);

    __s32_cpy_n = 0;
    __s32_cmp_n = 0;

    fprintf(stdout, "\n");

    char ks[] = "SOME STRING";
    void *v = aa_map_find(m, ks);

    fprintf(stdout
           , "found '%s' in m: %s, cmp: %zu\n"
           , ks
           , v ? (char*)v : "no"
           , __s32_cmp_n
           );


    __s32_cpy_n = 0;
    __s32_cmp_n = 0;

    v = aa_map_find(m2, ks);

    fprintf(stdout
           , "found '%s' in m2: %s, cmp: %zu\n"
           , ks
           , v ? (char*)v : "no"
           , __s32_cmp_n
           );

    size_t n = 4;
    aa_map_filter(m2, &n, __s32_shorter);

    aa_map_enum(m2, 0, __s32_print);

    __s32_cpy_n = 0;
    __s32_cmp_n = 0;

    struct lookup_kv3_cc cc = { .m = m, .n = 0, .match = 0 };

    aa_map_enum(m2, &cc, __lookup_kv_3);

    fprintf( stdout
           , "lookup in m, %zu, found %zu, avg. cmp %zu (%zu)\n"
           , cc.n
           , cc.match
           , __s32_cmp_n / cc.n
           , __s32_cmp_n
           );

    aa_map_destroy(m);
    aa_map_destroy(m2);
}

static void __kv_4_alter(void *c, void *k, void *v, bool n) {

    if( n ) {
        __s32_cpy(v, c);
    } else {
        char *p = v;
        char *pe = p + ARBITRARY_LEN;
        for(; *p && p < pe; p++ ) {
            *p = tolower(*p);
        }
    }
}

static void __kv_4_alter_up(void *c, void *k, void *v, bool n) {

    if( !n ) {
        char *p = v;
        char *pe = p + ARBITRARY_LEN;
        for(; *p && p < pe; p++ ) {
            *p = toupper(*p);
        }
    }
}


void test_aa_map_arbitrary_kv_4(void) {

    char mem[aa_map_size];

    struct aa_map *m = aa_map_create( sizeof(mem)
                                    , mem
                                    , ARBITRARY_LEN
                                    , ARBITRARY_LEN
                                    , __s32_cmp
                                    , __s32_cpy
                                    , __s32_cpy
                                    , 0
                                    , __alloc
                                    , __dealloc
                                    );


    ranctx rctx;
    raninit(&rctx, 0xDEADBEEF);

    const size_t N = 20;
    size_t i = 0;

    const char dict[] = "qwertyuiopasdfghjklzxcvbnm"
                        "QWERTYUIOPASDFGHJKLZXCVBNM1234567890";

    for(; i < N; i++ ) {
        size_t ln1 = 1 + ranval(&rctx) % (ARBITRARY_LEN-2);
        size_t ln2 = 1 + ranval(&rctx) % (ARBITRARY_LEN-2);
        char k[ARBITRARY_LEN];
        char v[ARBITRARY_LEN];

        randstr(&rctx, k, ln1, dict);
        randstr(&rctx, v, ln2, dict);

        aa_map_alter(m, true, k, v, __kv_4_alter);
        aa_map_alter(m, true, k, v, __kv_4_alter);
        aa_map_alter(m, false, k, v, __kv_4_alter_up);
    }

    aa_map_enum(m, 0, __s32_print);

    fprintf(stdout, "filtering\n");

    size_t n = 8;
    aa_map_filter(m, &n, __s32_shorter);

    aa_map_enum(m, 0, __s32_print);

    fprintf(stdout, "wiping\n");
    aa_map_filter(m, 0, 0);

    aa_map_enum(m, 0, __s32_print);

    aa_map_destroy(m);
}
Пример #8
0
void test_aa_tree_clinical_1(void) {

    ranctx rctx;
    raninit(&rctx, 0xDEADBEEF);

    char mem[aa_tree_size];

    fprintf(stdout, "clinical case\n");

    struct aa_tree *t = aa_tree_create( sizeof(mem)
                                      , mem
                                      , sizeof(uint32_t)
                                      , __u32_cmp_stat
                                      , __u32_cpy
                                      , 0
                                      , __alloc
                                      , __dealloc
                                      );

    const size_t N = 10000;
    size_t i = 0;

    size_t cn = 0;

    for(; i < N; i++ ) {
        uint32_t tmp = i;

        __cmp_num = 0;

        aa_tree_insert(t, &tmp);

        cn = __cmp_num > cn ? __cmp_num : cn;
    }

    fprintf( stdout
           , "inserted %zu, max. cmp: %zu ops\n"
           , i
           , cn );


    cn = 0;

    size_t found = 0;
    for(i = 0; i < N; i++ ) {
        uint32_t tmp = ranval(&rctx) % N;

        __cmp_num = 0;

        if( aa_tree_find(t, &tmp) ) {
            found++;
        }

        cn = __cmp_num > cn ? __cmp_num : cn;

    }

    fprintf( stdout
           , "found %zu of %zu, max. cmp: %zu ops\n"
           , found
           , i
           , cn );

    aa_tree_destroy(t,0,0);
}
Пример #9
0
int main(int argc, char **argv)
{
	//unsigned int n_hop = sizeof(hopping_frequencies)/sizeof(hopping_frequencies[0]);
	//int i = 0;
	time_t curtime;
	struct timeval tv;
	char buffer[30];
	unsigned int R, F, T;

	// for catching signals
	signal(SIGINT, INThandler);

	
	printf("\033[2J");
	printf("M1GEO - RigHop - Jumps Radio TRX Frequency in time.\nCurrent Timestamp:  ");
	
	gettimeofday(&tv, NULL);
	curtime=tv.tv_sec;
	strftime(buffer, 30 ,"%d/%m/%Y %T.", localtime(&curtime));
	printf("%s%06ld - Must be NTP Synced.\n", buffer, tv.tv_usec);
	
	if (argc != 4) {
		printf("\n\tusage:\t\t%s serial_port radio_civ seed\n", argv[0]);
		printf("\texample:\t%s /dev/ttyUSB0 0x88 1234\n", argv[0]);
		return -1;
	}
	
	serialport = (char *) malloc(strlen(argv[1])+1);
	strcpy(serialport, argv[1]);
	
	rigaddress = str2hex(argv[2]);
	
	// seed PRNG
	raninit( &PRNG, atoi(argv[3]) );
	
	//// TODO - DOES NOT WORK! NOT UINQUE ACROSS COMPUTERS!
	//printf("Generataing Hopping Patterns from seed '%d': ", atoi(argv[3]));
	//for (i=0; i<60; i++) {
		//hopping_pattern[i] = ranval(&PRNG) % n_hop; // get PRNG value
	//}
	//printf("OK\n");
	
	//printf("Selected Hopping Frequencies: ");
	//for (i=0; i<60; i++) {
	//	printf("   %u:\t%.4f MHz\n", i, (double)((double)hopping_frequencies[hopping_pattern[i]]/(unsigned int)1e6));	
	//}
	//printf("\n");
	
	
	//termios - structure contains options for port manipulation
	struct termios specs; // for setting baud rate 

	//setup part
	printf("Opening serial port '%s' at 19200 for CI-V Address 0x%X.\n\n\n\n\n", serialport, rigaddress);
	port = open_port();
	if (port < 0) {
		return -1;
	}
	tcgetattr(port, &specs); 

	//now the specs points to the opened port's specifications
	specs.c_cflag &= ~PARENB;
	specs.c_cflag &= ~CSIZE;
	specs.c_cflag |= CS8;

	//output flags
	//CR3 - delay of 150ms after transmitting every line
	specs.c_oflag = (OPOST | CR3);

	//set Baud Rate to 19200bps
	cfsetospeed(&specs, B19200);
	
	//our custom specifications set to the port
	//TCSANOW - constant that prompts the system to set
	//specifications immediately.
	tcsetattr(port, TCSANOW, &specs);
	
	// main loop
	while (runmainloop)
	{
		// get the current system clock
		gettimeofday(&tv, NULL);
		
		// work out time to next interval, and then set timer
		
		T = (1E6 - tv.tv_usec - tCal);
		usleep(T);
		
		//update for actual running time
		gettimeofday(&tv, NULL);
		curtime=tv.tv_sec;
		
		// shuffle average along 1
		if (tv.tv_usec < 5E5) {
			tCal += (tv.tv_usec / 2);
		} else {
			tCal -= ((1E6-tv.tv_usec) / 2);
		}
		
		if (tCal > 1E3) {
			tCal = 0;
		}
		
		if (tv.tv_usec >= 5E5) {
			R = hopping_pattern[((tv.tv_sec+1)%60)];
		} else {
			R = hopping_pattern[tv.tv_sec%60];
		}
		F = hopping_frequencies[R];
		
		// push frequency to radio
		sendtorig(F);
		
		// print wakeup time
		printf("\033[3A\r"); // jump up 2 lines
		strftime(buffer, 30 ,"%d/%m/%Y, %T.", localtime(&curtime)); printf("\tTimestamp:\t%s%06ld\n", buffer, tv.tv_usec);
		printf("\tFrequency:\t%.4f MHz\n", ((double)F/(double)1E6));
		printf("\tTime Cal:\t%u us (T=%u us)\n", tCal, T);
		fflush(stdout);
		
	}
	printf("Leaving main loop.\n");
	printf("Returning to home frequency.\n");
	sendtorig(432.7E6);
	usleep(1E6);
	free (serialport);
	return 0;
}