for CAN test for MonitoringSystem

Dependencies:   mbed SB1602E MSCFILESytem FatFileSystemCpp

Dependents:   Monitor2020_ver5

Revision:
2:14b832fdd69f
Parent:
1:93775378e5d9
--- a/main.cpp	Thu Aug 27 08:14:30 2020 +0000
+++ b/main.cpp	Thu Sep 03 02:55:39 2020 +0000
@@ -1,5 +1,6 @@
-//20200807モニタリングシステム kikkawa
+//20200828モニタリングシステム kikkawa
 //CAN,  dekaLCD, 4*20LCD
+//USBのファイル生成プログラムが微妙
 #include "stdio.h"
 #include "mbed.h"
 #include "SB1602E.h"    //デカ文字LCD
@@ -19,9 +20,8 @@
 CAN can1(p30, p29); //CANのピン設定
 
 //printf用
-char cnt_printf = 0;
+bool printf_flag = 0;
 Timer timer1;   //いろんなprintf表示用のタイマー
-Timer timer2;   //処理時確認用タイマー
 /*テレメトリシステム(XBee)の設定*/
 Serial xbee(p13,p14);   //XBeeとシリアル通信するピンの設定
 /*LCDの設定*/
@@ -61,6 +61,7 @@
     }
     else {  //usbhost_lpc17xx.cppでの処理につながる
         usbCheck = 1;
+        xbee.printf("  USBinit => OK\n\r");
         //LCDにUSB:×を表示させる処理
         lcd1.locate(15, 3);  //4*20LCDの4行目に表示 //lcd1.locate(横方向, 縦方向)
         lcd1.printf("USB:o");
@@ -118,9 +119,9 @@
     lcd1.locate(0, 1);  //4*20LCDの2行目に表示
     lcd1.printf("B:%5.1fv%5.1fA%5.0fw", Vbatt, Cbatt, Pbatt);     //-10.0Aとかでも表示の桁が変わらないように%5.1fにしている
     lcd1.locate(0, 2);  //4*20LCDの3行目に表示
-    lcd1.printf("M:%5.1fA", Cmotor);
+    lcd1.printf("M:%5.1fv%5.1fA", Vmotor, Cmotor);
     lcd1.locate(0, 3);  //4*20LCDの4行目に表示
-    lcd1.printf("S:%5.1fA", Csolar);
+    lcd1.printf("S:%5.1fv%5.1fA", Vsolar, Csolar);
     //デカ文字LCDへの表示
     lcd2.printf( 0, "%5.1fkm/h %5.1fv\r", speed, Vmotor );    //  速度、IPM入力電圧(システム電圧)の表示
     lcd2.printf( 1, "%5.0fw %4.0fw %3d\r", Pmotor, Psolar, dutylatio );  //消費電力、発電電力、バッテリ電圧の表示
@@ -130,31 +131,23 @@
 //    lcd1.printf("CAN_Error\n\r");
 }
 int main() {
-    timer1.start(); //printf用タイマースタート
-    timer2.start(); //printf用タイマースタート
     pc.baud(115200);  //9600bpsで150ms 115200bpsで13msくらい処理速度が違う(処理時間は送るデータ量にもよる)
     xbee.baud(115200);
-    xbee.printf("XBee => OK\n\r");
+    xbee.printf("\n\n\r");
+    xbee.printf("XBee => OK");
     can1.attach(&Handler_can1Recieve, CAN::RxIrq);   //CAN受信割り込みの設定
     can1.attach(&Handler_can1Error, CAN::BeIrq );   //バスエラー時の割り込み設定
     MSC_init(); //USBメモリ初期化
+    pc.printf("  SPEED(km/h)  Duty  Vmotor(V)  Cmotor(A)  Pmotor(W)  Vsolar(V)  Csolar(A)  Psolar(W)" );
+    pc.printf("  Vbat(V)  Cbatt(A)  Pbatt(W)  Vbatt_max(V)  Vbatt_avg(V)  Vbatt_min(V)\n\r" );    
+    xbee.printf("  SPEED(km/h)  Duty  Vmotor(V)  Cmotor(A)  Pmotor(W)  Vsolar(V)  Csolar(A)  Psolar(W)" );
+    xbee.printf("  Vbat(V)  Cbatt(A)  Pbatt(W)  Vbatt_max(V)  Vbatt_avg(V)  Vbatt_min(V)\n\r" );      
+    timer1.start(); //printf用タイマースタート
     
     while(1) {
         //PCへのシリアル通信処理(teratermなどへ表示)
-        if( timer1.read_ms() >= 50 && !cnt_printf ){  //0.1秒ごとにprintf処理をする
-            //xbee.printf("  timer1: %d  timer2: %d", timer1.read_ms(), timer2.read_ms());
-            xbee.printf("timer1: %d", timer1.read_ms() );
-            //printf("SPD:%5.1f DC:%3d Vmot:%5.1f Cmot:%6.2f Pmot:%6.1f Vsol:%5.1f Csol:%6.2f Psol:%5.1f Vbat:%5.1f Cbat:%6.2f Pbat:%6.1f Vmax:%5.3f Vavg:%5.3f Vmin:%5.3f\n\r", speed, dutylatio, Vmotor, Cmotor, Pmotor, Vsolar, Csolar, Psolar, Vbatt, Cbatt, Pbatt, Vbatt_max, Vbatt_avg, Vbatt_min );        
-            pc.printf("%5.1f km/h  Duty:%3d  Motor:%5.1f(V),%6.2f(A),%6.1f(W)   solar:%5.1f(V),%6.2f(A),%5.1f(W)", speed, dutylatio, Vmotor, Cmotor, Pmotor, Vsolar, Csolar, Psolar );
-            pc.printf("  bat:%5.1f(V),%6.2f(A),%6.1f(W),max:%5.3f,avg:%5.3f,min:%5.3f\n\r", Vbatt, Cbatt, Pbatt, Vbatt_max, Vbatt_avg, Vbatt_min );        
-            xbee.printf("  timer1: %d", timer1.read_ms() );
-            //xbee.printf("  timer1: %d  timer2: %d\n\r", timer1.read_ms(), timer2.read_ms());
-            //LCDへの書き込み処理
-            LCD_write();
-            cnt_printf = 1;
-        }
-        if( timer1.read_ms() >= 100 && cnt_printf ){  //0.1秒ごとにprintf処理をする
-            xbee.printf("  timer1: %d", timer1.read_ms() );
+        if( timer1.read_ms() >= 50 && !printf_flag ){  //0.1秒ごとにprintf処理をする
+            //xbee.printf("  timer1: %d", timer1.read_ms() );
             //USBが刺さっているかいないか確認し、データを書き込む処理
             if( usbCheck ){ //初期設定時(プログラムスタート時)、USBが刺さっていればusbCheck==1(true)
                 fp1 = fopen( cary, "a");    //ファイルを開く, aは上書きの命令(ファイルが存在しなければ新規作成する)
@@ -163,15 +156,30 @@
                     lcd1.locate(15, 3);  //4*20LCDの4行目に表示 //lcd1.locate(横方向, 縦方向)
                     lcd1.printf("USB:x"); //LCDに、USBは未接続(X)と表示する
                 }
-                else {  //開けたらする処理
-                    //メモリへの書き込み
+                else {  //開けたらする処理  //メモリへの書き込み
                     fprintf( fp1,"%5.1f,%3d,%5.1f,%5.1f,%6.1f,%5.1f,%5.1f,%6.1f,%5.1f,%5.1f,%6.1f,%5.3f,%5.3f,%5.3f\n", speed, dutylatio, Vmotor, Cmotor, Pmotor, Vsolar, Csolar, Psolar, Vbatt, Cbatt, Pbatt, Vbatt_max, Vbatt_avg, Vbatt_min );   
                     fclose(fp1);         //ファイルを閉じる  
                 }
             }
-            xbee.printf("  timer1: %d\n\r", timer1.read_ms() );
-            cnt_printf = 0;
+            //xbee.printf("  timer1: %d\n\r", timer1.read_ms() );
+            //リセット           
+            printf_flag = 1;
+        }
+        if( timer1.read_ms() >= 200 && printf_flag ){  //0.2秒ごとにprintf処理をする
             timer1.reset();
+            //xbee.printf("timer1: %d", timer1.read_ms() );
+            //printf("SPD:%5.1f DC:%3d Vmot:%5.1f Cmot:%6.2f Pmot:%6.1f Vsol:%5.1f Csol:%6.2f Psol:%5.1f Vbat:%5.1f Cbat:%6.2f Pbat:%6.1f Vmax:%5.3f Vavg:%5.3f Vmin:%5.3f\n\r", speed, dutylatio, Vmotor, Cmotor, Pmotor, Vsolar, Csolar, Psolar, Vbatt, Cbatt, Pbatt, Vbatt_max, Vbatt_avg, Vbatt_min );        
+            pc.printf("       %5.1f    %3d   %5.1f     %6.2f     %6.1f      %5.1f      %6.2f     %5.1f", speed, dutylatio, Vmotor, Cmotor, Pmotor, Vsolar, Csolar, Psolar );
+            pc.printf("     %5.1f     %6.2f    %6.1f       %5.3f        %5.3f        %5.3f", Vbatt, Cbatt, Pbatt, Vbatt_max, Vbatt_avg, Vbatt_min );  
+            pc.printf("\r");
+            xbee.printf("       %5.1f    %3d   %5.1f     %6.2f     %6.1f      %5.1f      %6.2f     %5.1f", speed, dutylatio, Vmotor, Cmotor, Pmotor, Vsolar, Csolar, Psolar );
+            xbee.printf("     %5.1f     %6.2f    %6.1f       %5.3f        %5.3f        %5.3f", Vbatt, Cbatt, Pbatt, Vbatt_max, Vbatt_avg, Vbatt_min );   
+            xbee.printf("\r");  
+            //xbee.printf("  timer1: %d", timer1.read_ms() );
+            //LCDへの書き込み処理
+            LCD_write();
+            //リセット
+            printf_flag = 0;
         }
         /*if( !running ){ data file change }
         else if( running ){ write_MSC();    //USBメモリへ書き込む関数}*/