#include "mbed.h" LocalFileSystem local("local"); //ローカルファイルシステム // Create the local filesystem - the name "local" Serial pc(USBTX, USBRX); // tx, rx //シリアル通信 int x; //履歴レコードカウンタ int flg, alt; //whileループフラグ、ファイル交代回数カウンタ int main() { // setup time structure struct tm t; t.tm_sec = 30; //30 0-59 t.tm_min = 45; //45 0-59 t.tm_hour = 13; //13 0-23 t.tm_mday = 9; //9 1-31 t.tm_mon = 6; //6 0-11 t.tm_year = 110; //110 year since 1900 pc.printf( "year %d/mon %d/day %d/hour %d/min %d/sec %d \n\r", t.tm_year,t.tm_mon,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec ); // convert to timestamp and display (&tm) time_t seconds_d = mktime(&t); //時間構造体→経過秒数 pc.printf("Time as seconds since January 1, 1970 = %d \n\r", seconds_d); set_time(seconds_d); // Set RTC time //RTC時刻設定 time_t seconds = time(NULL); //RTC時刻取得 pc.printf("It is %d seconds since January 1, 1970 \n\r", seconds); struct tm *ta = localtime(&seconds); pc.printf("year %d/mon %d/day %d/hour %d/min %d/sec %d \n\r", ta->tm_year,ta->tm_mon,ta->tm_mday,ta->tm_hour,ta->tm_min,ta->tm_sec ); pc.printf("Time as a string = %s \n\r", ctime(&seconds)); set_time(seconds); // Set RTC time //RTC時刻設定 x=101; pc.printf("\n\r"); pc.printf("Hello World %d \n\r", x); flg = 1; //履歴レコードカウンタ初期値 alt = 0; //ファイル交代回数カウンタ初期値 while(flg) { //whileループ開始端 alt ++; //ファイル交代回数カウントアップ if(alt>9){ // 10 alternatory files A&B flg = 0; // while loop to end } //A ++++++++++++++++++++ FILE *fpA = fopen("/local/pgx_04LA.txt", "w"); // Open " pgx_04LA.txt " for(int ii=0; ii<1000; ii++){ int ii_t = 1+ii%100; seconds = time(NULL); //タイムスタンプ取得 fprintf(fpA, "%d Hello %d A World! - Event %d --- mbed application / Date %s # \r\n",alt, 1+ii, ii_t, ctime(&seconds)); x++; } fclose(fpA); //ファイルA閉鎖