int main(void)
{
  unsigned int i;
  unsigned long long t[NRUNS];

  pk = calloc(crypto_dh_PUBLICKEYBYTES,1);
  if(!pk) fail("allocation of pk failed");
  sk = calloc(crypto_dh_SECRETKEYBYTES,1);
  if(!sk) fail("allocation of sk failed");
  s = calloc(crypto_dh_BYTES,1);
  if(!s) fail("allocation of s failed");

  for(i=0;i<NRUNS;i++)
  {
    t[i] = cpucycles();
    crypto_dh_keypair(pk,sk);
  }
  print_speed(XSTR(crypto_dh_keypair),-1,t,NRUNS);

  for(i=0;i<NRUNS;i++)
  {
    t[i] = cpucycles();
    crypto_dh(s,pk,sk);
  }
  print_speed(XSTR(crypto_dh),-1,t,NRUNS);

  free(pk);
  free(sk);
  free(s);

  avr_end();
  return 0;
}
Example #2
0
int
check (int n, int freq)
{
  SchroBuffer *buffer;
  OilProfile prof;
  double ave, std;
  int x;
  int y;

  buffer = schro_buffer_new_and_alloc (100000);

  encode(buffer, n, freq);

  print_speed();

  x = decode(buffer, n, &prof, 0);
  oil_profile_get_ave_std (&prof, &ave, &std);
  printf("orig %d,%d: %g (%g) %d\n", n, freq, ave, std, x);

  x = decode(buffer, n, &prof, 1);
  oil_profile_get_ave_std (&prof, &ave, &std);
  printf("ref  %d,%d: %g (%g) %d\n", n, freq, ave, std, x);

  y = decode(buffer, n, &prof, 2);
  oil_profile_get_ave_std (&prof, &ave, &std);
  printf("test %d,%d: %g (%g) %d\n", n, freq, ave, std, y);
  if (x != y) {
    printf("BROKEN\n");
  }

  schro_buffer_unref (buffer);

  return 0;
}
Example #3
0
static void
track_disp_hdr_cb(const route_head *track)
{
    cur_info = &route_info[route_idx];
    cur_info->prev_wpt = NULL;
    cur_info->total = 0;
    current_trk = (route_head *)track;
    if (track->rte_waypt_ct <= 0) return;

    if (!gtxt_flags.track_header_written) {
        gtxt_flags.track_header_written = 1;
        gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[track_header]);
    }

    print_string("\r\nTrack\t%s\t", current_trk->rte_name ? current_trk->rte_name : "");
    print_date_and_time(cur_info->start, 0);
    print_date_and_time(cur_info->time, 1);
    print_distance(cur_info->length, 0, 1, 0);
    print_speed(&cur_info->length, &cur_info->time);
    print_string("%s", (track->rte_url != NULL) ? track->rte_url : "");
    gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n\r\n", headers[trkpt_header]);
}
Example #4
0
void reticolo () { 
	double passo = 0.0;//passo del reticolo 
	//contatori 
	double rx = 0.0;
	double ry = 0.0; 
	int q=0;
    int m=0;
    int i,j;
    double speed_cm[2]={0.0,0.0};
     //Definisco il passo del reticolo cercando il minimo doppio di un quadrato: m >= n.
      //Questa procedur  	a permette di sfruttare l'intero spazio a disposizione per la creazione del reticolo.
     for (q = 0; m < number_of_particles; q++){
    	m = 2*q*q;
    }
    passo = sqrt(2/(double)m);
	printf("passo %lf\n", passo);
      	  //creazione reticolo
	rx=0;
	ry=0;
    genera_sottoreticolo(rx,ry,q,0,passo);
	rx = passo/2.0;
	ry = passo/2.0;
    genera_sottoreticolo(rx,ry,q,number_of_particles/2, passo);
	for (i =0 ; i< number_of_particles; i++){
		for ( j = 0; j<N;j++){	
				speed_cm[j] += particleList[i].speed[j];
		}
	}

	for ( i= 0; i<number_of_particles;i++){
		for(j=0;j<N;j++){
			particleList[i].speed[j] -= speed_cm[j]/((double) number_of_particles);
		}
	}
	print_coordinate();
	print_speed();

}
Example #5
0
static void
track_disp_wpt_cb(const waypoint *wpt)
{
    waypoint *prev = cur_info->prev_wpt;
    time_t delta;
    double dist, depth;

    gbfprintf(fout, "Trackpoint\t");

    print_position(wpt);
    print_date_and_time(wpt->creation_time, 0);
    if IS_VALID_ALT(wpt->altitude)
        print_distance(wpt->altitude, 1, 0, 0);

    gbfprintf(fout, "\t");
    depth = WAYPT_GET(wpt, depth, unknown_alt);
    if (depth != unknown_alt)
        print_distance(depth, 1, 0, 1);

    if (prev != NULL) {
        float temp;
        gbfprintf(fout, "\t");
        delta = wpt->creation_time - prev->creation_time;
        temp = WAYPT_GET(wpt, temperature, -999);
        if (temp != -999)
            print_temperature(temp);
        gbfprintf(fout, "\t");
        dist = waypt_distance_ex(prev, wpt);
        print_distance(dist, 0, 1, 0);
        print_date_and_time(delta, 1);
        print_speed(&dist, &delta);
        print_course(prev, wpt);
    }
    gbfprintf(fout, "\r\n");

    cur_info->prev_wpt = (waypoint *)wpt;
}
Example #6
0
void
handle_com_port_command(unsigned char *buf)
{
    unsigned char cmd = *buf++;
    int cmdarg;
    int cmdidx;
    int is_notify = 0;
    int notify;

    cmdidx = (int) cmd;

    if (cmd >= RAS_COM_START && cmd <= RAS_COM_END) {
	cmdidx -= RAS_COM_START;
    }

    print_command(cmdidx);

    switch (cmd) {
    case RAS_COM_SIGNATURE:
    case RAS_COM_FLOWCONTROL_SUSPEND:
    case RAS_COM_FLOWCONTROL_RESUME:
	break;
    case RAS_COM_SET_BAUDRATE:
	Comport.portconfig.speed = GET_VALUE_4(buf);
	print_speed(Comport.portconfig.speed);
	break;
    case RAS_COM_SET_DATASIZE:
	Comport.portconfig.datasize = GET_VALUE_1(buf);
	print_datasize(Comport.portconfig.datasize);
	break;
    case RAS_COM_SET_PARITY:
	Comport.portconfig.parity = GET_VALUE_1(buf);
	print_parity(Comport.portconfig.parity);
	break;

    case RAS_COM_SET_STOPSIZE:
	Comport.portconfig.stopsize = GET_VALUE_1(buf);
	print_stopsize(Comport.portconfig.stopsize);
	break;

    case RAS_COM_SET_CONTROL:
	cmdarg = GET_VALUE_1(buf);
	print_setcontrol(cmdarg);
	switch (cmdarg) {
	case COM_OFLOW_NONE:
	case COM_OFLOW_SOFT:
	case COM_OFLOW_HARD:
	    Comport.portconfig.flowc = cmdarg;
	    break;
	default:
	    break;
	}

	break;

    case RAS_COM_NOTIFY_LINESTATE:
	is_notify = 1;
	cmdarg = GET_VALUE_1(buf);
	print_linestate(cmdarg);
	Comport.portstate.linestate = cmdarg;
	if (cmdarg & LINE_BREAK_ERROR) {
	    notify = NT_BREAK;
	    SET_EVENT(EV_RN, EV_RNNTFY, &notify, sizeof(int));
	}
	if (cmdarg & LINE_PARITY_ERROR) {
	    notify = NT_PARITY;
	    SET_EVENT(EV_RN, EV_RNNTFY, &notify, sizeof(int));
	}
	break;

    case RAS_COM_SET_LINESTATE_MASK:
	cmdarg = GET_VALUE_1(buf);
	print_linestate(cmdarg);
	break;

    case RAS_COM_NOTIFY_MODEMSTATE:
	is_notify = 1;
	cmdarg = GET_VALUE_1(buf);
	if ((cmdarg ^ Comport.portstate.modemstate) & MODEM_DCD) {
	    if (Comport.portstate.modemstate & MODEM_DCD) {
		notify = NT_DCDOFF;
		SET_EVENT(EV_RN, EV_RNNTFY, &notify, sizeof(int));
	    }
	    else {
		notify = NT_DCDON;
		SET_EVENT(EV_RN, EV_RNNTFY, &notify, sizeof(int));
	    }
	}
	Comport.portstate.modemstate = cmdarg;
	print_modemstate(cmdarg);
	break;

    case RAS_COM_SET_MODEMSTATE_MASK:
	cmdarg = GET_VALUE_1(buf);
	print_modemstate(cmdarg);
	break;
    case RAS_COM_PURGE_DATA:
	cmdarg = GET_VALUE_1(buf);
	print_purge(cmdarg);
	break;
    default:
	sysmessage(MSG_NOTICE, "Unnimplemented command: %d\n", cmd);
	break;
    }

    if (!is_notify) {
	if (IS_CMD_ACTIVE(cmdidx)) {
	    CLR_CMD_ACTIVE(cmdidx);	/* Synchronous operation */
	}
	else {
	    SET_EVENT(EV_RN, EV_RNCMDOK, 0, 0);
	}
    }
    print_all();
}
Example #7
0
static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
    switch (event) {
    case ESP_SPP_INIT_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_INIT_EVT");
        esp_bt_dev_set_device_name(EXCAMPLE_DEVICE_NAME);
        esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
        esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps);

        break;
    case ESP_SPP_DISCOVERY_COMP_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_DISCOVERY_COMP_EVT status=%d scn_num=%d",param->disc_comp.status, param->disc_comp.scn_num);
        if (param->disc_comp.status == ESP_SPP_SUCCESS) {
            esp_spp_connect(sec_mask, role_master, param->disc_comp.scn[0], peer_bd_addr);
        }
        break;
    case ESP_SPP_OPEN_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_OPEN_EVT");
        esp_spp_write(param->srv_open.handle, SPP_DATA_LEN, spp_data);
        gettimeofday(&time_old, NULL);
        break;
    case ESP_SPP_CLOSE_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_CLOSE_EVT");
        break;
    case ESP_SPP_START_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_START_EVT");
        break;
    case ESP_SPP_CL_INIT_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_CL_INIT_EVT");
        break;
    case ESP_SPP_DATA_IND_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_DATA_IND_EVT");
        break;
    case ESP_SPP_CONG_EVT:
#if (SPP_SHOW_MODE == SPP_SHOW_DATA)
        ESP_LOGI(SPP_TAG, "ESP_SPP_CONG_EVT cong=%d", param->cong.cong);
#endif
        if (param->cong.cong == 0) {
            esp_spp_write(param->cong.handle, SPP_DATA_LEN, spp_data);
        }
        break;
    case ESP_SPP_WRITE_EVT:
#if (SPP_SHOW_MODE == SPP_SHOW_DATA)
        ESP_LOGI(SPP_TAG, "ESP_SPP_WRITE_EVT len=%d cong=%d", param->write.len , param->write.cong);
        esp_log_buffer_hex("",spp_data,SPP_DATA_LEN);
#else
        gettimeofday(&time_new, NULL);
        data_num += param->write.len;
        if (time_new.tv_sec - time_old.tv_sec >= 3) {
            print_speed();
        }
#endif
        if (param->write.cong == 0) {
            esp_spp_write(param->write.handle, SPP_DATA_LEN, spp_data);
        }
        break;
    case ESP_SPP_SRV_OPEN_EVT:
        ESP_LOGI(SPP_TAG, "ESP_SPP_SRV_OPEN_EVT");
        break;
    default:
        break;
    }
}