JunMo Hong / Mbed 2 deprecated cubebite_rnd_SPSGRFC433

Dependencies:   mbed

Fork of HelloWorld_IDS01A4 by ST

Revision:
11:f8396aa48de6
Parent:
10:cc81b87e005e
Child:
12:5e20115bd13b
--- a/main.cpp	Tue Jan 09 01:58:33 2018 +0000
+++ b/main.cpp	Fri Jan 12 04:57:19 2018 +0000
@@ -1,74 +1,60 @@
 /**
  ******************************************************************************
  * @file    main.cpp
- * @author  Rosarium PILA, STMicroelectronics
+ * @author  JMHong, Cubebite
  * @version V1.0.0
- * @date    June 19th, 2017
+ * @date    June 19th, 2018
  * @brief   mbed test application for the STMicroelectronics X-NUCLEO-IDB01A4/5
- *          Spirit1 Expansion Board
+ *          Spirit1 Module(SPSGRFC-433)
  ******************************************************************************
  * @attention
  *
- * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *   1. Redistributions of source code must retain the above copyright notice,
- *      this list of conditions and the following disclaimer.
- *   2. Redistributions in binary form must reproduce the above copyright notice,
- *      this list of conditions and the following disclaimer in the documentation
- *      and/or other materials provided with the distribution.
- *   3. Neither the name of STMicroelectronics nor the names of its contributors
- *      may be used to endorse or promote products derived from this software
- *      without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * <h2><center>&copy; COPYRIGHT(c) 2018 Cubebite</center></h2>
  *
  ******************************************************************************
  */
 
+//*************************************************************************************
+//Include
+//*************************************************************************************
 #include "mbed.h"
 #include "SimpleSpirit1.h"
+//*************************************************************************************
 
+
+//*************************************************************************************
+//Define : Debug
+//*************************************************************************************
 /* 180108 cubebite HJM : SimpleSpirit1 Debug define */
 #define NDEBUG
 #define HEAVY_DEBUG
 
 
 /* 180108 cubebite HJM : cubebite Debug define */
-#define CUBEBITE_DEBUG
+//#define CUBEBITE_DEBUG
+//*************************************************************************************
 
 
-/* 180108 cubebite HJM : cubebite Testing define */
-//#define CUBEBITE_TEST
+//*************************************************************************************
+//Define : Test, Compile 
+//*************************************************************************************
+/* 180108 cubebite HJM : cubebite Testing define, 1개씩만 켜야 함. */
+//#define CUBEBITE_RF_USER_BUTTON_SEND_TEST
 //#define CUBEBITE_RF_DEVICE_PARTNUMBER_TEST
 //#define CUBEBITE_RF_GPIO_0_TEST
+#define CUBEBITE_RF_SPEED_TEST_SEND_ON
+//#define CUBEBITE_RF_SPEED_TEST_RECV_ON
 
 
-/* 180109 cubebite HJM : cubebite Compile define */
+/* 180109 cubebite HJM : cubebite Compile define, 1개씩만 켜야 함. */
 //#define CUBEBITE_BOARD_F746ZG
 #define CUBEBITE_BOARD_F401RE
+//*************************************************************************************
 
 
-/* 180108 cubebite HJM : send testing, orignal code  */
-#define TEST_STR_LEN (32) 
-static uint8_t send_buf[TEST_STR_LEN] ={'S','P','I','R','I','T','1',' ','H','E','L','L','O',' ','W','O','R','L','D',' ','P','2','P',' ','D','E','M','O'};
-static uint8_t read_buf[TEST_STR_LEN] ={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
-
-/* 180108 cubebite HJM : send testing, testing code  */
-//#define TEST_STR_LEN (3) 
-//static uint8_t send_buf[TEST_STR_LEN] ={'H'};
-//static uint8_t read_buf[TEST_STR_LEN] ={'0','0','0'};
-
+//*************************************************************************************
+//Global variable : Create an instance by board
+//*************************************************************************************
 /* 180108 cubebite HJM : orignal code, backup */          
 //static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(D11, D12, D3, D9, D10, D2); /* (SPI_CLK) = (D13:PA5:resistorR7 --> D3:PB3:resistorR4)*/
 
@@ -80,16 +66,6 @@
 static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(PA_7, PA_6, PA_5, PA_0, PB_6, PA_10);    //F401re borad, IRQ Testing, GPIO 3 -> IRQ
 #endif
 
-#ifdef  CUBEBITE_BOARD_F401RE
-    #ifdef  CUBEBITE_RF_GPIO_0_TEST
-/* 180108 cubebite HJM : F401re borad, PC_1 == RF_MODULE_GPIO 0, Testing code */
-static DigitalIn RF_GPIO_0_INPUT(PC_1);   //F401re borad
-    #endif
-#endif
-//static DigitalIn RF_GPIO_3_INPUT(PA_0);   //F401re borad, 사용시, send 정상 동작 안함, Spirit1 IRQ 핀이랑 같이 물려있기 때문
-
-
-
 
 
 #ifdef  CUBEBITE_BOARD_F746ZG
@@ -99,26 +75,97 @@
 //static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(PB_5, PB_4, PB_3, PD_14, PD_5, PD_6);    //F746zg borad
 static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(PB_5, PB_4, PB_3, PA_3, PD_5, PD_6);    //F746zg borad, IRQ Testing, GPIO 3 -> IRQ
 #endif
+//*************************************************************************************
+
+
+//*************************************************************************************
+//Global variable : LEDs and user buttons by board
+//*************************************************************************************
+#ifdef  CUBEBITE_BOARD_F401RE
+static DigitalOut TestLED(D5);         /* LED of IDS01A4/5 */
+#endif
 
 #ifdef  CUBEBITE_BOARD_F746ZG
-    #ifdef  CUBEBITE_RF_GPIO_0_TEST
-/* 180108 cubebite HJM : F746zg borad, PC_1 == RF_MODULE_GPIO 0, Testing code */
-static DigitalIn RF_GPIO_0_INPUT(PF_5); //F746zg borad
+static DigitalOut TestLED(PB_0);         /* LED of IDS01A4/5 */
+#endif
+
+#ifdef  CUBEBITE_RF_USER_BUTTON_SEND_TEST
+static InterruptIn event(USER_BUTTON); /* Interrupt event to give userinterface to send pkt. */
+#endif
+//*************************************************************************************
+
+
+//*************************************************************************************
+//Global variable : Rf Send, read Buffer
+//*************************************************************************************
+/* 180108 cubebite HJM : send testing, orignal code  */
+#define TEST_STR_LEN (32)
+static uint8_t send_buf[TEST_STR_LEN] ={'S','P','I','R','I','T','1',' ','H','E','L','L','O',' ','W','O','R','L','D',' ','P','2','P',' ','D','E','M','O'};
+static uint8_t read_buf[TEST_STR_LEN] ={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
+//*************************************************************************************
+
+
+//*************************************************************************************
+//Global variable : tx, rx Flag
+//*************************************************************************************
+static volatile bool rx_done_flag = false; 
+static volatile bool tx_done_flag = false; 
+static volatile bool send_data_flag = false;
+//*************************************************************************************
+
+
+//*************************************************************************************
+//Global variable : Testing
+//*************************************************************************************
+/* Test : GPIO 0 */
+#ifdef  CUBEBITE_RF_GPIO_0_TEST
+    #ifdef  CUBEBITE_BOARD_F401RE
+/* 180108 cubebite HJM : F401re borad, PC_1 == RF_MODULE_GPIO 0, Testing code */
+static DigitalIn RF_GPIO_0_INPUT(PC_1);   //F401re borad
+//static DigitalIn RF_GPIO_3_INPUT(PA_0);   //F401re borad, 사용시, send 정상 동작 안함, Spirit1 IRQ 핀이랑 같이 물려있기 때문
     #endif
 #endif
 
+#ifdef  CUBEBITE_RF_GPIO_0_TEST
+    #ifdef  CUBEBITE_BOARD_F746ZG
+/* 180108 cubebite HJM : F746zg borad, PC_1 == RF_MODULE_GPIO 0, Testing code */
+static DigitalIn RF_GPIO_0_INPUT(PF_5); //F746zg borad
 //static DigitalIn RF_GPIO_3_INPUT(PA_3); //F746zg borad, 사용시, send 정상 동작 안함, Spirit1 IRQ 핀이랑 같이 물려있기 때문
+    #endif
+#endif
+
+
+
+/* Test : RF Speed Test */
+#ifdef  CUBEBITE_RF_SPEED_TEST_SEND_ON
+static clock_t clockRfSpeedTestStart, clockRfSpeedTestEnd;
+static float fRfSpeedTestResult;
+
+static bool bIsSendFirstClockFunctionStarted = false;
+static bool bIsSetSendFlag = false;
+#endif
+
+#ifdef  CUBEBITE_RF_SPEED_TEST_RECV_ON
+#define TEST_ACK_STR_LEN (6)
+static uint8_t send_ack_buf[TEST_ACK_STR_LEN] ={'O','K'};
+size_t curr_ack_len = strlen((const char*)send_ack_buf) + 1;
+
+static bool bIsAckSended = false;
+#endif
+//*************************************************************************************
 
 
 
 
 
-static volatile bool rx_done_flag = false; 
-static volatile bool tx_done_flag = false; 
-static volatile bool send_data_flag = false;
+
+
+
 
-static DigitalOut TestLED(D5);         /* LED of IDS01A4/5 */
-static InterruptIn event(USER_BUTTON); /* Interrupt event to give userinterface to send pkt. */
+
+
+
+
 
 
 
@@ -129,18 +176,25 @@
  */
 static void callback_func(int event) 
 {
-  printf("\r\n***EVENT !!!!!!!!!!!!!***\r\n");  
+#ifdef  CUBEBITE_DEBUG
+    printf("[CUBEBITE] callback_func(int event) \n");
+#endif
+  
+  
   
-  if(event == SimpleSpirit1::RX_DONE) 
-  {              
-    rx_done_flag = 1;
-  }
-  else if (event == SimpleSpirit1::TX_DONE) 
-  {
-    tx_done_flag = 1;
-  }
+    if(event == SimpleSpirit1::RX_DONE) 
+    {         
+        rx_done_flag = 1;
+    }
+    else if (event == SimpleSpirit1::TX_DONE) 
+    {  
+        tx_done_flag = 1;
+    }
 }
 
+
+
+
 /**
  * @brief  set_send_data_flag
  * @param  None
@@ -148,9 +202,14 @@
  */
 static void set_send_data_flag(void)
 {  
-  send_data_flag = 1 ;
+    send_data_flag = 1 ;
 }
 
+
+
+
+
+
 /**
  * @brief  send_data
  * @param  None
@@ -158,38 +217,73 @@
  */
 static void send_data(void)
 {
-  printf("\r\n***Sending a packet Start***\r\n");  
-  
-  printf("[CUBEBITE] myspirit, is_receiving()\t......");
-  while(myspirit.is_receiving()); /* wait for ongoing RX ends */
-  printf("OK\n");
- 
-  size_t curr_len = strlen((const char*)send_buf) + 1;
- 
+#ifdef  CUBEBITE_DEBUG
+    printf("[CUBEBITE] send_data() 호출 됨.\n");
+    printf("[CUBEBITE] myspirit, is_receiving()\t......");
+#endif
+    while(myspirit.is_receiving()); /* wait for ongoing RX ends 180110 HJM 아마 이 전에 보내던 거 마저 다 보내려고 하는 거 같다. */
+#ifdef  CUBEBITE_DEBUG
+    printf("OK\n");
+#endif
+
+
+    size_t curr_len = strlen((const char*)send_buf) + 1;
     int iRet = 0;
-  
-  printf("[CUBEBITE] myspirit, send()\t......");
-  iRet = myspirit.send(send_buf, curr_len);
+
+
+#ifdef  CUBEBITE_DEBUG  
+    printf("[CUBEBITE] myspirit, send()\t......");
+#endif
+    iRet = myspirit.send(send_buf, curr_len);
     if (iRet == RADIO_TX_OK)
     {
-      printf("[RADIO_TX_OK]\n");
+#ifdef  CUBEBITE_DEBUG        
+        printf("[RADIO_TX_OK]\n");
+#endif
+
+#ifdef  CUBEBITE_RF_SPEED_TEST_SEND_ON 
+    #ifdef CUBEBITE_BOARD_F401RE
+        if (false == bIsSendFirstClockFunctionStarted)
+        {
+            clockRfSpeedTestStart = clock();    
+            bIsSendFirstClockFunctionStarted = true;
+        }
+    #endif
+#endif
     }
     else if (iRet == RADIO_TX_ERR)
     {
+#ifdef  CUBEBITE_DEBUG
         printf("[RADIO_TX_ERR]\n");
+#endif
     }
     else if (iRet == RADIO_TX_COLLISION)
     {
+#ifdef  CUBEBITE_DEBUG
         printf("[RADIO_TX_COLLISION]\n");
+#endif
     }
     else if (iRet == RADIO_TX_NOACK)
     {
+#ifdef  CUBEBITE_DEBUG
         printf("[RADIO_TX_NOACK]\n");
+#endif
     }
     
-    printf("\r***Sending a packet End***\r\n");
+#ifdef  CUBEBITE_DEBUG
+    printf("[CUBEBITE] send_data() 호출 끝.\n");
+#endif
 }
 
+
+
+
+
+
+
+
+
+
 /**
  * @brief  read_rcvd_data
  * @param  None
@@ -197,27 +291,102 @@
  */
 static void read_rcvd_data(void)
 {  
-    printf("\r\n***Recving a packet Start***\r\n");  
+#ifdef  CUBEBITE_DEBUG
+    printf("[CUBEBITE] read_rcvd_data() 호출 됨. \n");  
+#endif
  
-  for(unsigned int flush_count = 0; flush_count < TEST_STR_LEN; flush_count++) read_buf[flush_count] = 0 ;/* clear the read buffer */
-      printf("[CUBEBITE][myspirit] read()\t......");
-      int ret = myspirit.read(read_buf, sizeof(read_buf));
-      printf("OK => ");
-      printf("read value : [%s]\n", read_buf);
-      
-      TestLED = !TestLED;     /* Toggle LED at the receiver */
-      
-      if(ret == 0) 
-      {
-        printf("\nNothing to read\n\r");
+    for(unsigned int flush_count = 0; flush_count < TEST_STR_LEN; flush_count++) read_buf[flush_count] = 0 ;/* clear the read buffer */
+
+    int ret = myspirit.read(read_buf, sizeof(read_buf));
+    if (ret == 0) 
+    {
+        printf("[CUBEBITE] Read() Error : Nothing to read\n");
         return;
-      }
-      //printf("\r\n***Received a packet***\r\n\rReceived string = '%s' (len=%d) \n\r", read_buf, ret); 
-      printf("\n\rReceived string = '%s' (len=%d) \n\r", read_buf, ret); 
-      
-      printf("\r\n***Recving a packet End***\r\n");
+    }
+#ifdef  CUBEBITE_RF_SPEED_TEST_RECV_ON
+    ret = strcmp((const char *)read_buf, (const char *)send_buf);
+    if (0 == ret)
+    {        
+        printf("read, send buf collect!!\n");
+        TestLED = !TestLED;     /* Toggle LED at the receiver */
+//        bIsAckSended = true;
+        //746zg 보드
+        int iRet = myspirit.send(send_ack_buf, curr_ack_len);
+        if (iRet == RADIO_TX_OK)
+        {
+        #ifdef  CUBEBITE_DEBUG
+            printf("ACK : [RADIO_TX_OK]\n");
+        #endif
+        }
+        else if (iRet == RADIO_TX_ERR)
+        {
+        #ifdef  CUBEBITE_DEBUG            
+            printf("ACK : [RADIO_TX_ERR]\n");
+        #endif
+        }
+        else if (iRet == RADIO_TX_COLLISION)
+        {
+        #ifdef  CUBEBITE_DEBUG            
+            printf("ACK : [RADIO_TX_COLLISION]\n");
+        #endif            
+        }
+        else if (iRet == RADIO_TX_NOACK)
+        {
+        #ifdef  CUBEBITE_DEBUG            
+            printf("ACK : [RADIO_TX_NOACK]\n");
+        #endif
+        }    
+                        
+    }
+#endif
+
+#ifdef  CUBEBITE_RF_SPEED_TEST_SEND_ON 
+    //401re 보드
+    if (true == bIsSendFirstClockFunctionStarted)
+    {
+        clockRfSpeedTestEnd = clock();
+    } 
+#endif    
+
+
+#ifdef  CUBEBITE_DEBUG
+    printf("[CUBEBITE] read_rcvd_data() 호출 끝. \n");  
+#endif
 }
 
+static void ack_send_data(void)
+{  
+#ifdef  CUBEBITE_RF_SPEED_TEST_RECV_ON
+    //746zg 보드
+    int iRet = myspirit.send(send_ack_buf, curr_ack_len);
+    if (iRet == RADIO_TX_OK)
+    {
+    #ifdef  CUBEBITE_DEBUG
+        printf("ACK : [RADIO_TX_OK]\n");
+    #endif
+    }
+    else if (iRet == RADIO_TX_ERR)
+    {
+    #ifdef  CUBEBITE_DEBUG            
+        printf("ACK : [RADIO_TX_ERR]\n");
+    #endif
+    }
+    else if (iRet == RADIO_TX_COLLISION)
+    {
+    #ifdef  CUBEBITE_DEBUG            
+        printf("ACK : [RADIO_TX_COLLISION]\n");
+    #endif            
+    }
+    else if (iRet == RADIO_TX_NOACK)
+    {
+    #ifdef  CUBEBITE_DEBUG            
+        printf("ACK : [RADIO_TX_NOACK]\n");
+    #endif
+    }    
+#endif
+}
+
+
 
 /**
  * @brief  main routine
@@ -226,12 +395,12 @@
  */
 int main() 
 {  
-    TestLED = 0;                  /* LED off */
-    
+    /* LED off */
+    TestLED = 0;                  
     /* 180108 cubebite HJM : function return value print */
     int iRet = 0;
-    
-    
+
+#ifdef  CUBEBITE_RF_GPIO_0_TEST
     /* 180108 cubebite HJM : GPIO 0, init code */
     SGpioInit gpioIRQ={
         SPIRIT_GPIO_0,
@@ -240,18 +409,12 @@
     };
     SpiritGpioInit(&gpioIRQ);
     
-    
-    
     /* 180108 cubebite HJM : GPIO 0, For spiritFunctionalState(), Testing code */
-#ifdef  CUBEBITE_RF_GPIO_0_TEST    
     SpiritFunctionalState spiritFunctionalState={
           S_DISABLE
     };
 #endif    
     
-    
-    
-    
     /* 180108 cubebite HJM : spirit module, init code  */
     printf("[CUBEBITE] myspirit, attach_irq_callback()\t......");
     myspirit.attach_irq_callback(callback_func);
@@ -267,88 +430,112 @@
     {
         printf("ERROR\n");
     }
-    
-  
- // printf("\n**************HelloWorld mbed demo for Spirit1 (X-NUCLEO-IDS01A4/5)**************\r\n");
-//  printf("\nPress User Button on one of the two boards to send a packaet to the other and the LED D1 on the receiver X-NUCLEO-IDS01A4/5 should toggle \n\r\n");
-
-
-
+#ifdef  CUBEBITE_DEBUG
+    printf("[CUBEBITE] CUBEBITE_DEBUG ON. \n");
+#endif
 
       
-  printf("[CUBEBITE] rise(&set_send_data_flag)\t......");
-  event.rise(&set_send_data_flag); /*User button interrupt trigger to set send data flag */
-  printf("OK\n");
+#ifdef  CUBEBITE_RF_USER_BUTTON_SEND_TEST
+    event.rise(&set_send_data_flag); /*User button interrupt trigger to set send data flag */
+#endif
+
 
 #ifdef  CUBEBITE_RF_DEVICE_PARTNUMBER_TEST  
   uint16_t int16SpiritPartNum = 0;
 #endif
-  while(1) 
-  {
+    while(1) 
+    {
 #ifdef  CUBEBITE_RF_DEVICE_PARTNUMBER_TEST
-    printf("[CUBEBITE][devicePartNumber] SpiritGeneralGetDevicePartNumber()\t......");
-
-    int16SpiritPartNum = SpiritGeneralGetDevicePartNumber();
-    printf("OK => ");
-    printf("int16SpiritPartNum value : [0x%04X]\n", int16SpiritPartNum);
-    int16SpiritPartNum = 0;
+        printf("[CUBEBITE][devicePartNumber] SpiritGeneralGetDevicePartNumber()\t......");
+    
+        int16SpiritPartNum = SpiritGeneralGetDevicePartNumber();
+        printf("OK => ");
+        printf("int16SpiritPartNum value : [0x%04X]\n", int16SpiritPartNum);
+        int16SpiritPartNum = 0;
 #endif    
 
-    __WFE(); /* low power in idle condition., waiting for an event */
-    
-    //180108 HJM : For spiritFunctionalState(), testing code
-    /*
-    if (S_ENABLE == spiritFunctionalState)
-    {
-        spiritFunctionalState = S_DISABLE;    
-    }
-    else
-    {
-        spiritFunctionalState = S_ENABLE;    
-    }
-    */
-    
-    
+        /* low power in idle condition., waiting for an event */
+        __WFE(); 
     
 #ifdef  CUBEBITE_RF_GPIO_0_TEST    
-    /* 180108 cubebite HJM : GPIO 0, For, spiritFunctionalState() => Enables or Disables the output of temperature sensor on SPIRIT GPIO_0. */
-    SpiritGpioTemperatureSensor(spiritFunctionalState);
+        //180108 HJM : For spiritFunctionalState(), testing code
+        
+        if (S_ENABLE == spiritFunctionalState)
+        {
+            spiritFunctionalState = S_DISABLE;    
+        }
+        else
+        {
+            spiritFunctionalState = S_ENABLE;    
+        }
+        
+        /* 180108 cubebite HJM : GPIO 0, For, spiritFunctionalState() => Enables or Disables the output of temperature sensor on SPIRIT GPIO_0. */
+        SpiritGpioTemperatureSensor(spiritFunctionalState);
+        
+        /* 180108 cubebite HJM : RF_GPIO_0_INPUT pin value print */
+        printf("****** RF GPIO_0 Status Testing => [%d] ******\n", (int)RF_GPIO_0_INPUT);
+        wait(1);
+#endif
     
-    /* 180108 cubebite HJM : RF_GPIO_0_INPUT pin value print */
-    printf("****** RF GPIO_0 Status Testing => [%d] ******\n", (int)RF_GPIO_0_INPUT);
-    //wait(1);
+#ifdef  CUBEBITE_RF_SPEED_TEST_SEND_ON 
+        if (true == bIsSetSendFlag)
+        {
+            set_send_data_flag();    
+            bIsSetSendFlag = false;
+        }
 #endif
     
-    
-    /* 180108 cubebite HJM : RF_GPIO_3_INPUT pin value print */    
-//    printf("****** RF GPIO_3 Status Testing => [%d] ******\n", (int)RF_GPIO_3_INPUT);    
-    
-    
-    
+        if(rx_done_flag) 
+        {
+            rx_done_flag = false; 
+            read_rcvd_data();
+            printf("recvedd.\n");            
+#ifdef  CUBEBITE_RF_SPEED_TEST_SEND_ON                
+            if (true == bIsSendFirstClockFunctionStarted)
+            {
+                fRfSpeedTestResult = (float)(clockRfSpeedTestEnd - clockRfSpeedTestStart)/CLOCKS_PER_SEC;
+                printf("\n Clock Rf Speed Test : [%.9f(sec)] \n", fRfSpeedTestResult);      
+                
+                bIsSendFirstClockFunctionStarted = false;
+            }
+#endif
+        }
+        
+        else if (send_data_flag)
+        { 
+#ifdef  CUBEBITE_RF_SPEED_TEST_SEND_ON        
+    //180112 HJM : Ack 응답 올 때 까지의 Timeout.
+//            wait(0.1);  //100ms, 정상 동작, 오류 없음.    (5분 테스트)
+//            wait(0.06); //60ms, 정상 동작, 오류 없음.       (5분 테스트)
+            wait(0.05);  // 50ms, 정상 동작, 오류 없음.     (10분 테스트)
+//            wait(0.01);  // 10ms, 정상 동작.
+//            wait(0.008);    // 8ms, 정상 동작, 하지만 0.01 이 최대 속도값으로 보임.
+//            wait(0.005);  // 5ms, 정상 동작, 하지만 0.01 이 최대 속도값으로 보임, 하지만 Nothing to read 오류가 많이 뜸.    (20분 테스트)
+//            wait(0.00001);  // 0.01ms, 비 정상 동작.   (30분 테스트)
+#endif
+                         
+            send_data_flag = false;
+            send_data();
+            printf("sended.\n");
+
+        }
     
+        else if (tx_done_flag)
+        {
+          tx_done_flag = false;
+    //      printf("\n***Packet sent ***\nSent string ='%s' (len=%d)\n", send_buf, strlen((const char*)send_buf) + 1);      
+        }
     
-    /* 180108 cubebite HJM : RF 모듈 간 통신 때 사용되는 코드 */
-    //read_rcvd_data();
-    if(rx_done_flag) 
-    {
-      rx_done_flag = false; 
-      read_rcvd_data();
+#ifdef  CUBEBITE_RF_SPEED_TEST_RECV_ON 
+//180112 HJM 오후 1시, 현재 사용 안하는 중, recv 쪽에서 strcmp로 보낸 데이터와 받은 데이터 비교 후, send 를 바로 하는 코드로 바꿨음.
+        else if (true == bIsAckSended)
+        {
+            bIsAckSended = false;
+            ack_send_data();
+            printf("recv sended.\n"); 
+        }
+#endif
     }
-    
-    else if (send_data_flag)
-    {
-      send_data_flag = false;
-      send_data();
-    }
-    
-    else if (tx_done_flag)
-    {
-      tx_done_flag = false;
-      printf("\r\n***Packet sent ***\r\nSent string ='%s' (len=%d)\n\r", send_buf, strlen((const char*)send_buf) + 1);
-    }
-    
-  }
-  
   /* unreachable */
   // myspirit.off();
   // return 0;