UD-GS01治具の試作プログラムです

Dependencies:   mbed nRF24L01P SDFileSystem

Revision:
9:086fae0bd5f8
Parent:
8:3369eef8f9e1
Child:
10:6e3bdd6f11c3
--- a/Goto_UD-GS01.cpp	Thu Dec 10 02:05:19 2020 +0000
+++ b/Goto_UD-GS01.cpp	Thu Dec 10 04:49:42 2020 +0000
@@ -3,9 +3,8 @@
 
 #include "mbed.h"
 #include "nRF24L01P.h"
-//#include <assert.h>
-//#include <stdbool.h>
-#include "SDFileSystem.h"
+
+//#include "SDFileSystem.h"
 Serial  pc(PA_2, PA_3);  //ここはpcとケーブルでつないだときにシリアル通信させてたところだから、ここから牛のUARTにつなぐだけで大丈夫なはず。→ここは元々ST基板のPC部分(パキッと折れそうな方)との通信用に使われてるから他のシリアルは無理らしい。
 Serial  UDGS01(PA_0, PA_1); // UD-GS01とのシリアル通信用にUARTピンを新たに定義。
        
@@ -25,7 +24,7 @@
 int      rxDataIdx = 0;                 
 int      rxDataCnt=0;
 int      i=0;
-int      which=0;
+int      open_flg=0;
 int bufferidx=0;
 
 nRF24L01P my_nrf24l01p(D11, D12, D13, D10, D9,D8);    // mosi, miso, sck, csn, ce, irq
@@ -42,12 +41,8 @@
         if (rxDataIdx >= TRANSFER_SIZE) 
         rxDataIdx=0;
         rcv_flg = 0;       
-      }
-      if(rcv_flg == 2) { 
-        
-        pc.printf("\r\n");
-        rcv_flg = 0;    
-      }
+        i++;
+    }
 }
 
 void recieve(){
@@ -55,46 +50,17 @@
              
      // ...read the data into the receive buffer
         txData1[txDataIdx] = UDGS01.getc();  //getcharだと、PCからのキーボード入力という標準コンソール?のやつだからだめらしい
-//        pc.printf("tx[%d] = %s", txDataIdx, &txData[txDataIdx]);
+
         txDataIdx++;
-/*        
-        if(txData1[txDataIdx] == 0x0A){ //改行(0x0A)があればその時点で送りたい
-              memcpy(txData2, txData1, txDataIdx);
-              txDataIdx = 0;
-              snd_flg = 2;
-*/              
-        }else if (txDataIdx == TRANSFER_SIZE) {//最初の32回
            memcpy(txData2, txData1, TRANSFER_SIZE);
                
                txDataIdx=0;
                snd_flg = 1;
                
         }
-               
-//    }
     
 }
 
-//for文でrxData1とrxData2を比較して、まったく同じ中身なら0,違えば1を返す関数のつもり 
-//bool rxData_equal(char* rxData1,/* size_t size1,*/ const char* rxData2/*, size_t size2*/)
-//{
-//    assert(rxData1 != NULL);
-//    assert(rxData2 != NULL);
-//    assert(size1 != 0);
-//    assert(size2 != 0);
-
-    // 要素数が違うなら、絶対に一致しない
-//    if (size1 != size2) {
-//        return false;
-//    }
-
-//    for (i = 0; i < TRANSFER_SIZE; ++i) {
-//        if (rxData1[i] != rxData2[i]) {
-//            return false;
-//        }
-//    }
-//    return true;
-//}  
     
 int main() {
     pc.baud(115200);
@@ -114,12 +80,11 @@
     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );//mAX 32
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();
-    
-    
+//    SDFileSystem *sd = new SDFileSystem(PB_15,  PB_14, PB_13, PB_11, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); //SDカードのやつ mosi, miso, sclk, cs, name, card detect, sw type, freq
+//    FILE *fp;    
     wait_ms(100);
-   // my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char*)rxData,1);//dummy
-
-    interrput.attach(&timer, 0.5);//100 usec 10Khz
+ 
+    interrput.attach(&timer, 1);//100 usec 10Khz
     UDGS01.attach(recieve,Serial::RxIrq);//牛からのデータ受信したら割り込み発生してrecieveを呼び出す
 
  //   my_nrf24l01p.flush_rx_fifo();
@@ -127,34 +92,34 @@
        
        if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P0) ) {    //受信可能であれば
            
-         rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, (char*)(rxData1),TRANSFER_SIZE );
-         if(/*rxData_equal(rxData1, rxData2)==*/1){ //rxData1で読んだ値が以前コピーしたのと完全一致なら0, 違えば1を出す。              
+         rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, (char*)(rxData1),TRANSFER_SIZE );             
             
              memcpy(rxData2, rxData1, TRANSFER_SIZE);
-             SDFileSystem *sd = new SDFileSystem(PB_15,  PB_14, PB_13, PB_11, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); //SDカードのやつ mosi, miso, sclk, cs, name, card detect, sw type, freq
-             FILE *fp;    
-             fp = fopen("/sd/log/log(UD-GS01).txt", "a");
-             fputs(rxData2, fp);
-             wait(1);
-             fclose(fp);
+            
              
+//             if(open_flg == 0){
+//                 fp = fopen("/sd/log/log(UD-GS01).txt", "a");
+//                 open_flg = 1;
+
+//               if(open_flg == 1){
+//                  fputs(rxData2, fp);
+//               }
+                 
+//             if(i>10){
+//                 i=0;
+//                wait(1);
+//                 fclose(fp);
+//                 open_flg = 0;
+//             }
              rcv_flg = 1;
             
-         }
-         /*else{
-             rcv_flg = 2;
-          }
-        */
-       }
+         }      
 
        if (snd_flg==1) {//最初のバッファ
                snd_flg=0;
                
                my_nrf24l01p.write( NRF24L01P_PIPE_P0, (char *)txData2 , TRANSFER_SIZE  );
- //              memset(txData2, 0, TRANSFER_SIZE/*何バイト書き込むか*/);
-//               for(i=0; i>32; i++){
-//               pc.printf("tx[%d] = %s", 30, txData[30]);
-//               }
+
                pc.putc('1');
                wait(1);
          }else if (snd_flg==2)  {//後半のバッファ         
@@ -164,7 +129,7 @@
                wait(1);
          }    
 
-         
-         
- } //一番最初のwhileの}
-}
+                 
+       } //一番最初のwhileの}
+//   }                            
+}
\ No newline at end of file