Bladeren bron

Оптимизация. Замер времени recv().

zaytsev.mikhail.olegovich@gmail.com 1 jaar geleden
bovenliggende
commit
c11e451f8d
4 gewijzigde bestanden met toevoegingen van 26 en 7 verwijderingen
  1. 1 0
      CMakeLists.txt
  2. 1 2
      Devices/lmx2594.c
  3. 3 2
      command.c
  4. 21 3
      main.c

+ 1 - 0
CMakeLists.txt

@@ -1,5 +1,6 @@
 cmake_minimum_required(VERSION 3.5.0)
 project(TMSG44_CoolPi VERSION 0.1.0 LANGUAGES C CXX)
+add_compile_options(-Wall)
 
 add_executable(TMSG44_CoolPi command.c main.c
         Devices/ad9912.c

+ 1 - 2
Devices/lmx2594.c

@@ -737,6 +737,7 @@ double lmx_get_freq(double freq) {
     else if (freq > 27e9 && freq <= 45e9) {
         return freq/4;
     }
+    return 0;
 }
 
 int lmx_freq_set(void *bar1, double lmx_freq,double f_pd) {
@@ -746,7 +747,6 @@ int lmx_freq_set(void *bar1, double lmx_freq,double f_pd) {
     SET_REGISTER_PARAM(cfg_reg, CFG_REG_SPI_MODE_BITM, CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_4MOSI); 
     uint32_t *spi_mode = bar1 +CFG_REG_ADDR;
     *spi_mode = cfg_reg;
-    usleep(1);
     // if the frequency is in the main band - 7.5 GHz to 15 GHz
     if (lmx_freq >= 7.5e9 && lmx_freq <= 15e9) {
         // lmx_freq_set_main_band(bar1, freq, f_pd);
@@ -760,7 +760,6 @@ int lmx_freq_set(void *bar1, double lmx_freq,double f_pd) {
     usleep(1);
     SET_REGISTER_PARAM(cfg_reg,CFG_REG_SPI_MODE_BITM,CFG_REG_SPI_MODE_BITP, CFG_REG_SPI_MODE_1MOSI);
     *spi_mode = cfg_reg;
-    usleep(1);
     set_cfg_reg(cfg_reg);
     return 0;
 }

+ 3 - 2
command.c

@@ -7,6 +7,7 @@
 #include <strings.h>
 #include <string.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <unistd.h>
 #include <time.h>
 
@@ -30,13 +31,13 @@ Command commands[] = {
 //handleXXXXCmd - обработчики команд
 void handleFreqCmd(const char* recvBuff)
 {
+	
 	printf("\nHandle command \"TMSG44:FREQ\"\n");
 	double freq[1] = {0};
 	double lmx_freq = 0;
 
 	splitLexeme(recvBuff, freq, sizeof(freq[0]), convertToDouble);
 
-	printf("Frequency: %.2f Hz\n", freq[0]);
 	lmx_freq = lmx_get_freq(freq[0]);
 	f_pd = ad9912_set(bar1, lmx_freq, f_pd);
 	printf("f_pd frequency is set to %.6f MHz\n", f_pd/1e6);
@@ -44,11 +45,11 @@ void handleFreqCmd(const char* recvBuff)
 	// Switch the keys 
 	key_switch(bar1, freq[0],lmx_freq);
     printf("The frequency is set to %.2f MHz\n", freq[0]/1e6);
+	
 }
 
 void handleLdCmd(const char* recvBuff)
 {
-	int n = 0;
 	char messageLd[] = "1\n";
 
 	printf("\nHandle command \"TMSG44:LD?\"\n");

+ 21 - 3
main.c

@@ -9,6 +9,7 @@
 #include <signal.h>
 #include <sys/mman.h>
 #include <fcntl.h>
+#include <sys/time.h>
 
 #include "Devices//tmsgheaders.h"
 #include "Devices//lmx2594.h"
@@ -162,10 +163,10 @@ int main(int argc, char *argv[])
 		//Очистка буфера
 		memset(recvBuff, 0, sizeof(recvBuff));
 
-		while ((n = recv(conn_fd, recvBuff, sizeof(recvBuff) - 1, 0)) > 0)
+		n = recv(conn_fd, recvBuff, sizeof(recvBuff) - 1, 0);
+		struct timeval  tv;
+		while (n > 0)
 		{
-			recvBuff[n] = 0;
-		
 			if(fputs(recvBuff, stdout) == EOF)
 			{
 				printf("\n Error : Fputs error\n");
@@ -188,6 +189,23 @@ int main(int argc, char *argv[])
 				// Ищем команды разделенные разделителем
 				ptrLexeme = strtok_r(NULL, charSeparator, &savePtr);
 			}
+			
+			gettimeofday(&tv, NULL);
+
+			double time_begin = ((double)tv.tv_sec) * 1000 +
+                      ((double)tv.tv_usec) / 1000;
+
+			recvBuff[n] = 0;
+
+			n = recv(conn_fd, recvBuff, sizeof(recvBuff) - 1, 0);
+
+			gettimeofday(&tv, NULL);
+			double time_end = ((double)tv.tv_sec) * 1000 +
+                    ((double)tv.tv_usec) / 1000 ;
+
+			double total_time_ms = time_end - time_begin;
+
+			printf("TOTAL TIME (ms) = %f\n", total_time_ms);
 		} 
 
 		if (n == 0)