void main (void)
{
  /*开硬件浮点*/
  SCB->CPACR |=((3UL << 10*2)|(3UL << 11*2));     /* set CP10 and CP11 Full Access */
  
  
  
  uint16 flag; 
  uint16 i,j;
  
  DisableInterrupts;
  LCD_init(1);
  Disp_single_colour(Black);
  LCD_PutString(10, 50,"Frequency: ", White, Black);
  LCD_PutString(145, 50,"  KHz", White, Black);
  LCD_PutString(10, 80,"Power: ", White, Black);
  LCD_PutString(145, 80,"   W", White, Black);
  LCD_PutString(10, 110,"Amplify: ", White, Black);
  LCD_PutString(165, 110,"Restrain: ", White, Black);
  init_ADC();
  init_DAC();
  init_DMA();
  init_PDB();
  init_PIT();
  init_gpio_PE24();
  EnableInterrupts;
  LPLD_LPTMR_DelayMs(100);
  
  
  
  flag = Result_flag;
  uint16 ShowAFlag = 0;
  uint16 ShowBFlag = 0;
  uint16 ShowCFlag = 0;
  
  arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], blockSize);
  while(1)
  {
    if( flag==Result_flag && Result_flag == 0)
    {
      if(++ShowAFlag<10)
      {
        for(j = 0;j<LENGTH;j++)
          testInput_x[j*2] = Result_A[j];
        for(j = 0;j<LENGTH;j++)
          testInput_x[j*2+1] = 0;
        
        arm_cfft_f32(&arm_cfft_sR_f32_len2048, testInput_x, ifftFlag, doBitReverse);
        
        /* Process the data through the Complex Magnitude Module for
        calculating the magnitude at each bin */
        arm_cmplx_mag_f32(testInput_x, testOutput, fftSize);
        
        testOutput[0] = 0;
        /* Calculates maxValue and returns corresponding BIN value */
        arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
      }
      else
      {
        ShowAFlag = 0;
        if(starfir !=2 )
            LCD_Put_Float(100, 50,"",testIndex*40.0/2048, White, Black);
      }
      if(starfir == 1)
      {
        PTE24_O = 1;
        for(j = 0;j<LENGTH;j++)
          firInput[j] = Result_A[j];
        inputF32 = &firInput[0];
        outputF32 = &firOutput[0];
        for(i=0; i < numBlocks; i++)
          arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
        for(j = 0;j<LENGTH;j++)
          Result_A[j] = firOutput[j];
        PTE24_O = 0;
      }
      flag = 1;
    }
    else  if(flag==Result_flag && Result_flag == 1)
    {
      if(starfir !=2 )
      {
        if(++ShowBFlag<10)
        {
          power = 0;
          for(i=0;i<LENGTH;i++)
            power+=((Result_B[i] - OFFEST)/1241.0)*((Result_B[i] - OFFEST)/1241.0)*90*MyDb/8.0;
          power = power/LENGTH;
        }
        else
        {
          ShowBFlag = 0;
          LCD_Put_Float(100, 80,"",power, White, Black);
        }
      }
      else
      {
        for(i = 0;i<160;i++)
        {
          FFT_RESULT_NEW[i] = testOutput[i*6]/FFT_VALUE;
          if(FFT_RESULT_NEW[i]>239) FFT_RESULT_NEW[i] = 239;
        }
      }
      
      //     {
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2] = Result_B[j];
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2+1] = 0;
      //     
      //     arm_cfft_f32(&arm_cfft_sR_f32_len2048, testInput_x, ifftFlag, doBitReverse);
      //
      //  /* Process the data through the Complex Magnitude Module for
      //  calculating the magnitude at each bin */
      //    arm_cmplx_mag_f32(testInput_x, testOutput, fftSize);
      //
      //    testOutput[0] = 0;
      //  /* Calculates maxValue and returns corresponding BIN value */
      //    arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
      //     }
      if(starfir == 1)
      {
        PTE24_O = 1;
        for(j = 0;j<LENGTH;j++)
          firInput[j] = Result_B[j];
        inputF32 = &firInput[0];
        outputF32 = &firOutput[0];
        for(i=0; i < numBlocks; i++)
          arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
        for(j = 0;j<LENGTH;j++)
          Result_B[j] = firOutput[j];
        PTE24_O = 0;
      }
      flag = 2;
    }
    else if(flag==Result_flag && Result_flag == 2)
    {
      //   
      //    {
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2] = Result_C[j];
      //     for(j = 0;j<LENGTH;j++)
      //       testInput_x[j*2+1] = 0;
      //     
      //     arm_cfft_f32(&arm_cfft_sR_f32_len2048, testInput_x, ifftFlag, doBitReverse);
      //
      //  /* Process the data through the Complex Magnitude Module for
      //  calculating the magnitude at each bin */
      //    arm_cmplx_mag_f32(testInput_x, testOutput, fftSize);
      //
      //    testOutput[0] = 0;
      //  /* Calculates maxValue and returns corresponding BIN value */
      //    arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
      //     }
      if(starfir == 1)
      {
        //    PTE24_O = 1;
        for(j = 0;j<LENGTH;j++)
          firInput[j] = Result_C[j];
        inputF32 = &firInput[0];
        outputF32 = &firOutput[0];
        for(i=0; i < numBlocks; i++)
          arm_fir_f32(&S, inputF32 + (i * blockSize), outputF32 + (i * blockSize), blockSize);
        for(j = 0;j<LENGTH;j++)
          Result_C[j] = firOutput[j];
        //   PTE24_O = 0;
      }
      if(starfir != 2)
      {
        if(++ShowCFlag<5)
        {
        }
        else
        {
          if(ShowMenu)
          {
            Disp_single_colour(Black);
            LCD_PutString(10, 50,"Frequency: ", White, Black);
            LCD_PutString(145, 50,"  KHz", White, Black);
            LCD_PutString(10, 80,"Power: ", White, Black);
            LCD_PutString(145, 80,"   W", White, Black);
            LCD_PutString(10, 110,"Amplify: ", White, Black);
            LCD_PutString(165, 110,"Restrain: ", White, Black);
            ShowMenu = 0;
          }
          LCD_Put_Float(100, 110,"",MyDb/0.5, White, Black);
          if(starfir)
            LCD_PutString(260, 110,"On  ", White, Black);
          else
            LCD_PutString(260, 110,"Off", White, Black);
        }
      }
      else
      {
        if(ShowMenu)
        {        
          Disp_single_colour(Black);
          ShowMenu = 0;
        }
        draw_fft();
      }
      flag = 0;
    }
    
  } 
}
Example #2
0
void update_stats(stats_t *resolve, stats_t *connect, stats_t *request, stats_t *total, stats_t *ssl_setup, int n_ok, int n_fail, const char *last_connect_str, const char *fp, char use_tfo, char dg, stats_t *st_to, stats_t *tcp_rtt_stats, int re_tx, int pmtu, int tos, stats_t *close_st, stats_t *t_write, int n_cookies, char abbreviate, stats_t *stats_header_size)
{
	double k = 0.0;
	char force_redraw = 0;
	struct pollfd p = { 0, POLLIN, 0 };

	werase(w_stats);

	if (n_ok)
	{
		char buffer[4096] = { 0 }, *scc_str = NULL, *kalman_str = NULL;
		int buflen = 0;

		myprintloc(w_stats, 0, 0, "         %6s %6s %6s %6s %6s", gettext("latest"), gettext("min"), gettext("avg"), gettext("max"), gettext("sd"));
		show_stats_t(1, 0, gettext("resolve"), resolve,   abbreviate);
		show_stats_t(2, 0, gettext("connect"), connect,   abbreviate);
		show_stats_t(3, 0, gettext("ssl    "), ssl_setup, abbreviate);
		show_stats_t(4, 0, gettext("send   "), t_write,   abbreviate);
		show_stats_t(5, 0, gettext("request"), request,   abbreviate);
		show_stats_t(6, 0, gettext("close  "), close_st,  abbreviate);
		show_stats_t(7, 0, gettext("total  "), total,     abbreviate);

		scc_str    = format_value(get_cur_scc(), 5, 3, abbreviate);
		kalman_str = format_value(kalman_do(total -> cur), 5, 3, abbreviate);
		myprintloc(w_stats, 8, 0, gettext("ok: %3d, fail: %3d%s, scc: %s, kalman: %s"), n_ok, n_fail, use_tfo ? gettext(", with TFO") : "", scc_str, kalman_str);
		free(kalman_str);
		free(scc_str);

		if (max_x >= 44 * 2 + 1)
		{
			double trend = calc_trend();
			char trend_dir = ' ';

			myprintloc(w_stats, 0, 45, "         %6s %6s %6s %6s %6s", gettext("cur"), gettext("min"), gettext("avg"), gettext("max"), gettext("sd"));
			show_stats_t(1, 45, gettext("t offst"), st_to, abbreviate);

#if defined(linux) || defined(__FreeBSD__)
			show_stats_t(2, 45, gettext("tcp rtt"), tcp_rtt_stats, abbreviate);
#endif
			show_stats_t(3, 45, gettext("headers"), stats_header_size, abbreviate);

			if (trend < 0)
				trend_dir = '-';
			else if (trend > 0)
				trend_dir = '+';

			myprintloc(w_stats, 8, 48, gettext("# cookies: %d"), n_cookies);

#ifdef linux
			myprintloc(w_stats, 9, 48, gettext("trend: %c%6.2f%%, re-tx: %2d, pmtu: %5d, TOS: %02x"), trend_dir, fabs(trend), re_tx, pmtu, tos);
#else
			myprintloc(w_stats, 9, 48, gettext("trend: %c%6.2f%%, TOS: %02x"), trend_dir, fabs(trend), tos);
#endif
		}

		buflen = snprintf(buffer, sizeof buffer, gettext("HTTP rc: %s, SSL fp: %s"), last_connect_str, fp ? fp : gettext("n/a"));

		if (buflen <= max_x)
			myprintloc(w_stats, 9, 0, "%s", buffer);
		else
		{
			static char prev_sf[48] = { 0 };

			myprintloc(w_stats, 9, 0, gettext("http result code: %s"), last_connect_str);

			if (fp && strcmp(prev_sf, fp))
			{
				slow_log(gettext("\nSSL fingerprint: %s"), fp);

				memcpy(prev_sf, fp, 47);
			}
		}
	}

	memmove(&history[1], &history[0], (history_n - 1) * sizeof(double));
	memmove(&history_set[1], &history_set[0], (history_n - 1) * sizeof(char));

	history[0]= total -> cur;
	history_set[0] = 1;

	if (poll(&p, 1, 0) == 1 && p.revents == POLLIN)
	{
		int c = getch();

		if (c == 12) /* ^L */
			force_redraw = 1;

		if (c == 'H')
			pause_graphs = !pause_graphs;

		if (c == 'q')
			stop = 1;
	}

	if (dg && !pause_graphs)
	{
		draw_graph(k);
#ifdef FW
		draw_fft();
#endif
	}

	wnoutrefresh(w_stats);

	if (win_resize || force_redraw)
		recreate_terminal();
}