bug fix, But not applied

Dependencies:   ADXL362_bugFix stm-spirit1-rf-driver_for_cubebite

Fork of cubebite_rnd_ev-cog-ad3029lz_433MHz_2nd_testing2_RF10CountSensingCheckOK_180619_initReviseTest by JunMo Hong

Files at this revision

API Documentation at this revision

Comitter:
jmhong
Date:
Thu Sep 20 06:36:52 2018 +0000
Parent:
1:04f46755f8af
Commit message:
10 sensing data and adxl bug fix

Changed in this revision

ADXL362.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
stm-spirit1-rf-driver_for_cubebite.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 04f46755f8af -r b87c19873d46 ADXL362.lib
--- a/ADXL362.lib	Fri Jun 22 03:43:49 2018 +0000
+++ b/ADXL362.lib	Thu Sep 20 06:36:52 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/jmhong/code/ADXL362/#bf56b783747e
+https://os.mbed.com/users/jmhong/code/ADXL362_bugFix/#e484040b8f84
diff -r 04f46755f8af -r b87c19873d46 main.cpp
--- a/main.cpp	Fri Jun 22 03:43:49 2018 +0000
+++ b/main.cpp	Thu Sep 20 06:36:52 2018 +0000
@@ -1,7 +1,8 @@
 //HJM : 선풍기 에이징 테스트 용 소스임.
 //180615 HJM : 선풍기 에이징 용 온도 1개 진동 10개 전송용 테스트 임.
 //            CUBEBITE_TEMPERATURE_DISABLE  define 값으로 온도 센서 (연결 및 미연결) 시 설정을 할 수 있음.
-
+//180717 HJM : 인증(온도) 테스트용 소스 버전 관리, 0.1 -> 온도(저온) 테스트
+//180717 HJM : 수정 1
 
 
 #include "mbed.h"
@@ -10,6 +11,14 @@
 #include "main.h"
 
 
+#define FIRMWARE_VERSION_MAJOR        0
+#define FIRMWARE_VERSION_MINOR        2
+#define FIRMWARE_VERSION_REVISE       2
+
+//#define DEBUG_PRINT_TEMP
+//#define DEBUG_PRINT_SEND
+
+//#define FIRMWARE_VERSION_PRINT(x)  printf(#x " = %s\n", x);
 
 //*************************************************************************************
 //Define : Test, Compile 
@@ -32,13 +41,12 @@
 
 
 //180411 HJM : 현재 1~3 까지 3대까지 가능 -> 게이트웨이에서 3대까지만 처리하게끔 되어있
-#define CUBEBITE_SENSOR_UUID        1   //180621 HJM : 온도 및 진동 테스트 용
-//#define CUBEBITE_SENSOR_UUID        2 //180621 HJM : 철기연 테스트 용
+#define CUBEBITE_SENSOR_UUID        1   //3180621 HJM : 온도 및 진동 테스트 용
+//#define CUBEBITE_SENSOR_UUID        2 //180621 HJM : 철기연 테스트 용, 방대리님 테스트 용
 //*************************************************************************************
 
 
 
-
 //HJM : 타이머 인터럽트 테스트 용
 #ifdef  CUBEBITE_DEBUG
     DigitalOut led1(LED1);
@@ -46,18 +54,13 @@
 
 
 
+#define RETURN_ERROR_NUMBER     100
+
 
 //*************************************************************************************
 //HJM SUDO code : 3개 객체 생성->RF, 온도, 진동
 //*************************************************************************************
-//RF 객체
-static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(P0_01, P0_02, P0_00, P1_12 ,P2_08, P1_14);  
-                         // P0_01[SPI0_MOSI]
-                          // P0_02[SPI0_MISO], 
-                          // P0_00[SPI0_CLK], 
-                        // P1_12[GPIO 28, RF(GPIO 0)]->IRQ로 설정, 
-                        // P2_08[SPI0_CS2], 
-                        // P1_14[GPIO 30, RF (SDN)]
+
 
 
 //온도 객체
@@ -83,6 +86,8 @@
 static void callback_func(int event);   //RF user callback 함수임.
 void UserTimerInterrupt(void);          //1초, 타이머 인터럽트 임
 int UserTimerInterrupt_Execution(void);
+int UserTimerInterrupt_Execution2(void);
+//void UserTimerInterrupt2(void);
 static int SendData(SimpleSpirit1& myspirit);
 
 
@@ -99,7 +104,14 @@
 //(테스트용)HJM SUDO code : 전역 변수, 진동, 온도 쪽 테스트용임. 추후 서대리님이 클래스 재 정의시 없어질 예정
 //*************************************************************************************
 
-
+//RF 객체
+    static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(P0_01, P0_02, P0_00, P1_12 ,P2_08, P1_14);  
+                         // P0_01[SPI0_MOSI]
+                          // P0_02[SPI0_MISO], 
+                          // P0_00[SPI0_CLK], 
+                        // P1_12[GPIO 28, RF(GPIO 0)]->IRQ로 설정, 
+                        // P2_08[SPI0_CS2], 
+                        // P1_14[GPIO 30, RF (SDN)]
 
 
 //진동
@@ -154,6 +166,12 @@
 #define ID_CON_ADDR 0x01
 #define ID_REG_ADDR 0x07
 
+#define RESET_HW_OFF    1
+#define RESET_HW_ON     0
+
+#define SPIRIT1_POWER_OFF    1
+#define SPIRIT1_POWER_ON     2
+
 
 //RF->이거도 클래스 내부에 넣기
 static volatile bool bRxDoneFlag = false; 
@@ -171,13 +189,19 @@
 
 
 //HJM : I2C PullUp 용.. RF IRQ 도 이 핀 이지만 사용안하기 때문에 괜찮음.
-DigitalOut TempSupply(P1_12);
+DigitalOut resetHW(P1_12);
+//prit1(P1_11);  //GPIO27
 
 bool iTempFlag = false;
 bool isTimerInterruptStarted = false;
 bool bIs1SecTimerSet = false;
 int iTempInitCount = 0;
 bool isTempInitOk = false;
+
+int iMainCounting = 1;
+static int iIsResetStartCounting = 0;
+//static int iIsResetStartCountingInterrupt = 0;
+bool isTempOk = false;
 int main(void)
 {    
 //*************************************************************************************
@@ -185,7 +209,31 @@
 //*************************************************************************************    
     
     //필수!!!
-    TempSupply.write(1);
+    resetHW.write(RESET_HW_OFF);    
+    //Describe
+    printf("\n\n FIRMWARE_VERSION : %d.%d.%d \n\n", FIRMWARE_VERSION_MAJOR, FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_REVISE);    
+    printf("\n\n FIRMWARE_VERSION_DESCRIBE : Cold test \n");    
+    printf("FIRMWARE_VERSION_REVISE_DESCRIBE : BANDWIDTH change and debug line all delete\n");
+    
+    printf("Xtal offset in ppm              : [%d]\n", XTAL_OFFSET_PPM);
+    printf("base frequency                  : [%d]\n", (uint32_t)BASE_FREQUENCY);
+    printf("channel space                   : [%d]\n", (uint32_t)CHANNEL_SPACE);
+    printf("channel number                  : [%d]\n", CHANNEL_NUMBER);    
+    printf("modulation select               : [%d]\n", MODULATION_SELECT);
+    printf("data rate                       : [%d]\n", DATARATE);
+    printf("frequency deviation             : [%d]\n", (uint32_t)FREQ_DEVIATION);
+    printf("channel filter bandwidth        : [%d]\n", (uint32_t)BANDWIDTH);
+    
+#ifdef  USE_SPIRIT1_433MHz
+    printf("\n is 433Mhz FREQ !!!\n");
+#endif
+    
+    
+    
+    
+//    FIRMWARE_VERSION_PRINT(FIRMWARE_VERSION);
+    
+    
     
     
     //진동 init_시작
@@ -194,19 +242,17 @@
         // Set up accelerometer
     adxl362.init_adxl362();
     
-    wait_ms(25);
+//    wait_ms(25);
     //진동 init_끝
     
     
     //온도 init_시작    
         //Power supply for the sensor is given from GPIO28(VDD_MCU_B).
+        // JMOD Init
+#ifndef CUBEBITE_TEMPERATURE_DISABLE       
+    printf("[Temperature] Init start");
     
-#ifndef CUBEBITE_TEMPERATURE_DISABLE
-    i2c.frequency(100000);
-#endif
-    
-        // JMOD Init
-#ifndef CUBEBITE_TEMPERATURE_DISABLE        
+    i2c.frequency(100000);  //100khz
     wReg[0] = ID_CON_ADDR;
     
     while(rReg[0] != 0x03)
@@ -233,15 +279,17 @@
 
         if(rReg[0] == 0x03)
         {
-            printf(" (Success!!)\n\n");
+//            printf(" (Vib Success!!)\n\n");
 
             //write 0x00(ID_CON_ADDR) 
             wReg[1] = 0x00;
             wACK = i2c.write(busAddr, wReg, 2);
             isTempInitOk = true;
             wait_ms(250);     
+//            wait_ms(60);     
+//            wait_ms(150);    
         }
-        else if (3 == iTempInitCount)
+        else if (10 == iTempInitCount)
         {
             isTempInitOk = false;
             break;
@@ -253,14 +301,18 @@
         }
         
         wait_ms(500);           
+//        wait_ms(80);
+//        wait_ms(200);
     }
 #endif    
+    printf("(OK)\n");
     //온도 init_끝
     
     
     
+    
     //RF init_시작    
-    myspirit.attach_irq_callback(callback_func);      
+//    myspirit.attach_irq_callback(callback_func);      
     if (myspirit.on())
     {
         printf("ERROR.\n");        
@@ -278,19 +330,41 @@
 //HJM SUDO code : 1초 타이머 인터럽트 생성, 1초 간격 호출 함수 : UserTimerInterrupt()
 //*************************************************************************************
 //    Timeout timeoutUserInterrupt;                         //1번만 실행
-//    Ticker timeoutUserInterrupt;                            //매번 실행
+    Ticker timeoutUserInterrupt;                            //매번 실행
+//    Ticker timeoutUserInterrupt2;                            //매번 실행
 //    timeoutUserInterrupt.attach(&UserTimerInterrupt, 1.0); //1 sec 
-//    timeoutUserInterrupt.attach(&UserTimerInterrupt, 3.0); //3 sec 
+    timeoutUserInterrupt.attach(&UserTimerInterrupt, 900.0); //15 minuite, reset test
+//    timeoutUserInterrupt2.attach(&UserTimerInterrupt2, 1.0); //1 sec
+//    timeoutUserInterrupt.attach(&UserTimerInterrupt, 5.0); //test, 5sec
 //*************************************************************************************
     
-    wait(1);
+//    wait(1);
     
     
     while(1)
     {
-        __WFE();    //HJM : sleep 모드 ON                
+        __WFE();    //HJM : sleep 모드 ON                                
+        
+        if (false == isTempOk)
+        {
+            isTempOk = true;
+            
+            UserTimerInterrupt_Execution();    
+        }        
+        UserTimerInterrupt_Execution2();
         
-        UserTimerInterrupt_Execution();
+//        myspirit.off();
+//        myspirit.on();
+        
+        //if (0 == (iMainCounting % 10))
+//        {
+////            myspirit.reset_board();
+////            iMainCounting = 0;            
+//            iMainCounting = 1;
+//            myspirit.off();
+//            myspirit.on();    
+//        }
+        
         if (true == isTimerInterruptStarted)
         {            
             isTimerInterruptStarted = false;
@@ -307,7 +381,6 @@
 #ifdef  CUBEBITE_DEBUG
     printf("[CUBEBITE] callback_func(int event) \n");
 #endif
-
   
     if(event == SimpleSpirit1::RX_DONE) 
     {         
@@ -323,36 +396,58 @@
 
 void UserTimerInterrupt(void)
 {
-//*************************************************************************************
-//HJM : 타이머 인터럽트 작동 테스트
-//*************************************************************************************    
-//180329 HJM : 작동 테스트 완료
-#ifdef  CUBEBITE_DEBUG
-    led1 = !led1;
-#endif
-
-//*************************************************************************************
-    
-    if (false == bIs1SecTimerSet)
-    {
-        bIs1SecTimerSet = true;        
-    }
+    resetHW.write(RESET_HW_ON);        
 
     return;    
 }
 
 
+bool bIsResetGo = false;
+int UserTimerInterrupt_Execution(void)
+{
+    if (true == isTempInitOk)
+    {               
+        wReg[0] = ID_DATA_ADDR;            
+            
+        i2c.write(busAddr, wReg, 1);
+        i2c.read(busAddr, rReg, 2);                                            
+    
+        Tem16 = (rReg[0] << 8) | (rReg[1]);
+        Tem16 >>= 5;
+        TempData = Tem16;
+        
+        TempData = TempData *0.125;
+        
+        //if (5 > TempData)
+//        {
+//            if (false == bIsResetGo)
+//            {
+//                bIsResetGo = true;
+//                resetHW.write(RESET_HW_ON); 
+//            }            
+//        }
+
+#ifdef  DEBUG_PRINT_TEMP        
+        printf("TEMP DEBUG : %f\n", TempData);
+#endif  //DEBUG_PRINT_TEMP
+    }   
+    
+    return 0;    
+}
+
+
+
+
 volatile int iFunctionCallCounting = 0;
-int UserTimerInterrupt_Execution(void)
+int UserTimerInterrupt_Execution2(void)
 {
 //    printf("UserTimerInterrupt_Execution 호출, dataCount : [%d]\n", dataCount);
     ++iFunctionCallCounting;
     
     if (false == isTimerInterruptStarted)
-    {
+    {               
         //진동    
-        adxl362.ACC_GetXYZ8(&x8, &y8, &z8);        
-        
+        adxl362.ACC_GetXYZ8(&x8, &y8, &z8);                
         if (0 == x8)
         {
             uiSendBuf[dataCount++] = '0';
@@ -364,8 +459,7 @@
             int8tX8Result = x8;
                                     
             uiSendBuf[dataCount++] = (uint8_t)int8tX8Result;            
-        }
-        
+        }        
         if (0 == y8)
         {
             uiSendBuf[dataCount++] = '0';
@@ -377,8 +471,7 @@
             int8tY8Result = y8;   
             
             uiSendBuf[dataCount++] = (uint8_t)int8tY8Result; 
-        }
-        
+        }        
         if (0 == z8)
         {
             uiSendBuf[dataCount++] = '0';
@@ -390,49 +483,43 @@
             int8tZ8Result = z8;            
                         
             uiSendBuf[dataCount++] = (uint8_t)int8tZ8Result;   
-        }  
-        
-//        printf("int8tX8Result : %d\n", (uint8_t)int8tX8Result);
-        
-//        printf("int8tY8Result : %d\n", (uint8_t)int8tY8Result);
-        
-//        printf("int8tZ8Result : %d\n", (uint8_t)int8tZ8Result);
-                    
-                
-         
+        }           
     
-            wait(0.025); // 25ms, Wait is required in this mode
+        wait(0.025); // 25ms, Wait is required in this mode
     
         //온도     
     //        temperature data receive
-#ifndef CUBEBITE_TEMPERATURE_DISABLE
         if (true == isTempInitOk)
-        {
-            wReg[0] = ID_DATA_ADDR;
-    
-            i2c.write(busAddr, wReg, 1);
-            i2c.read(busAddr, rReg, 2);
-        
-            Tem16 = (rReg[0] << 8) | (rReg[1]);
-            Tem16 >>= 5;
-            TempData = Tem16;
-            
-            TempData = TempData *0.125;
+        {       
+           // wReg[0] = ID_DATA_ADDR;            
+//                
+//            i2c.write(busAddr, wReg, 1);
+//            i2c.read(busAddr, rReg, 2);                                            
+//        
+//            Tem16 = (rReg[0] << 8) | (rReg[1]);
+//            Tem16 >>= 5;
+//            TempData = Tem16;
+//            
+//            TempData = TempData *0.125;
             
             if (0 == rReg[0])
             {            
+                uiSendBuf[dataCount++] = '@';
                 uiSendBuf[dataCount++] = '0';            
-    //            uiSendBuf[dataCount++] = '1';            
+//                uiSendBuf[dataCount++] = '1';            
             }
             else
             {
                 uiSendBuf[dataCount++] = (uint8_t)rReg[0];    
             }
             
+            
+            
             if (0 == rReg[1])
             {
+                uiSendBuf[dataCount++] = '@';
                 uiSendBuf[dataCount++] = '0';            
-    //            uiSendBuf[dataCount++] = '2';            
+//                uiSendBuf[dataCount++] = '2';            
             }
             else
             {
@@ -441,31 +528,27 @@
         }
         else
         {
-            uiSendBuf[dataCount++] = '0';
+            uiSendBuf[dataCount++] = '@';
             uiSendBuf[dataCount++] = '0';
+//            uiSendBuf[dataCount++] = '1';
+            uiSendBuf[dataCount++] = '@';
+            uiSendBuf[dataCount++] = '0';
+//            uiSendBuf[dataCount++] = '2';            
         }
-        
 
-#else   //온도 안쓰면,
-        uiSendBuf[dataCount++] = '0';
-        uiSendBuf[dataCount++] = '0';
-#endif
-    
-#ifdef  CUBEBITE_DEBUG    
-        printf("!!!!!!!!!!!!!! cFileWriteData : %d@%d@%d@%f\n", x8, y8, z8, TempData);        
-#endif  //CUBEBITE_DEBUG
-        
-    
-//        printf("iFunctionCallCounting : [%d]\n", iFunctionCallCounting);
-        
         uiSendBuf[dataCount++] = '#';        
         uiSendBuf[dataCount++] = '#';
         
         wait(0.025); // 25ms, Wait is required in this mode
-    
     }
     
-    if (iFunctionCallCounting >= 10)    //10번의 측정이 끝나면,
+    
+    
+    
+    
+//    if (iFunctionCallCounting >= 10)    //10번의 측정이 끝나면,
+//    if (iFunctionCallCounting >= 8)    //8번의 측정이 끝나면, 180703 온도 0도 표현시 버그 발생..
+    if (iFunctionCallCounting >= 1)    //180718 HJM : 테스트 중...
     {
         isTimerInterruptStarted = true;
 //        printf("if in!!\n");
@@ -502,6 +585,11 @@
  */
 static int SendData(SimpleSpirit1& myspirit)
 {
+//    ++iMainCounting;
+//    printf("iMainCounting : %d\n", iMainCounting);
+//    ++iIsResetStartCountingInterrupt;
+    
+    isTempOk = false;
 #ifdef  CUBEBITE_DEBUG
     printf("=========================================\n");
 #endif  //CUBEBITE_DEBUG    
@@ -511,12 +599,18 @@
 #endif  //CUBEBITE_DEBUG    
     
     int iRet;
+    
+//    while(1 == myspirit.channel_clear());    
     while(myspirit.is_receiving()); /* wait for ongoing RX ends 180110 HJM 아마 이 전에 보내던 거 마저 다 보내려고 하는 거 같다. */
     
+    
+    
+    
     size_t curr_len = strlen((const char*)uiSendBuf) + 1;
 //    printf("curr_len : [%d]\n", curr_len);
     
     
+    
     iRet = myspirit.send(uiSendBuf, curr_len);
     
     
@@ -525,28 +619,46 @@
     {
         uiSendBuf[iTemp] = 0;
     }
-    
-//    static uint8_t uiRFSpeedTestSendBuf[MAX_BUFFER_LEN] = { 0, };  //70 Byte    //성공    
-
-//    sprintf((char *)uiRFSpeedTestSendBuf, "%f@%f@%f@%f@%f", G_x, G_y, G_z, Output, TempData);    //HJM : 데이터 파싱 용
-//    sprintf((char *)uiRFSpeedTestSendBuf, "%.2f@%.2f@%.2f@%.2lf@%.2f@%d", G_x, G_y, G_z, dVibOutputSqrt, TempData, CUBEBITE_SENSOR_UUID);    //HJM : 데이터 파싱 용
-//    printf("%.2f@%.2f@%.2f@%.2lf@%.2f@%d\n\n", G_x, G_y, G_z, dVibOutputSqrt, TempData, CUBEBITE_SENSOR_UUID);
+#ifdef DEBUG_PRINT_SEND    
+    printf("iIsResetStartCounting : %d\n", iIsResetStartCounting);
+#endif  //DEBUG_PRINT_COLD_TEST
+    if (10 < iIsResetStartCounting)
+    {//HJM : 아예 뻗으면 하드웨어 리셋으로
+        iIsResetStartCounting = 0;        
+        //180709 HJM : 하드웨어 리셋이 아니고 SPIRIT1 만 리셋하는 걸로 수정
+        resetHW.write(RESET_HW_ON);                
 
-    //서버 에서 split 처리 시, 아래와 같음.
-    //0 -> 진동 x 축 값
-    //1 -> 진동 y 축 값
-    //2 -> 진동 z 축 값
-    //3 -> 온도 값
-    //
- 
-//    iRet = myspirit.send(uiSendBuf, curr_len);
+        return RADIO_TX_ERR_RESET;
+    }
+
+
     if (iRet == RADIO_TX_OK)
     {
+        iIsResetStartCounting = 0;
         return RADIO_TX_OK;
     }
     else if (iRet == RADIO_TX_ERR)
     {
-        return RADIO_TX_ERR;
+        iRet = myspirit.off();
+        if (RETURN_ERROR_NUMBER == iRet)
+        {
+            resetHW.write(RESET_HW_ON);
+        }
+        
+        iRet = myspirit.on();
+        if (RETURN_ERROR_NUMBER == iRet)
+        {
+            resetHW.write(RESET_HW_ON);
+        }
+        
+        //HJM : 테스트 !!, 
+//        while(1 == myspirit.channel_clear());
+        ++iIsResetStartCounting;
+        return RADIO_TX_ERR;        
+    }
+    else if (iRet == RETURN_ERROR_NUMBER)
+    {
+        resetHW.write(RESET_HW_ON);
     }
     else if (iRet == RADIO_TX_COLLISION)
     {     
@@ -554,15 +666,31 @@
     }
     else if (iRet == RADIO_TX_NOACK)
     {
+        ++iIsResetStartCounting;
         return RADIO_TX_NOACK;              
     }
     else if (iRet == RADIO_TX_ERR_RESET)
     {
-        printf("RADIO_TX_ERR_RESET return.\n");
-//        myspirit.off();
+        printf("RADIO_TX_ERR_RESET return.\n");    
+        ++iIsResetStartCounting;    
+        
+        //소프트웨어 리셋
         myspirit.reset_board();
-        myspirit.off();
-        myspirit.on();
+        iRet = myspirit.off();
+        if (RETURN_ERROR_NUMBER == iRet)
+        {
+            resetHW.write(RESET_HW_ON);
+        }
+        
+        iRet = myspirit.on();
+        if (RETURN_ERROR_NUMBER == iRet)
+        {
+            resetHW.write(RESET_HW_ON);
+        }
+        
+        //180703 HJM : 하드웨어 리셋으로 바꿈
+//        resetHW.write(SPIRIT1_POWER_OFF);
+        return RADIO_TX_ERR_RESET;
     }
     
     dataCount = 0;
@@ -571,7 +699,10 @@
     {
         uiSendBuf[iTemp] = 0;
     }
-        
+     
+    
+    
+    
     
 #ifdef  CUBEBITE_DEBUG
     printf("[CUBEBITE] SendData() 호출 끝.\n");
diff -r 04f46755f8af -r b87c19873d46 stm-spirit1-rf-driver_for_cubebite.lib
--- a/stm-spirit1-rf-driver_for_cubebite.lib	Fri Jun 22 03:43:49 2018 +0000
+++ b/stm-spirit1-rf-driver_for_cubebite.lib	Thu Sep 20 06:36:52 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/jmhong/code/EV-COG-AD3029LZ/#45b9ff78a066
+https://os.mbed.com/users/jmhong/code/stm-spirit1-rf-driver_for_cubebite/#38de5ee78824