Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Rejestrator
FileWritter.cpp
00001 #include "FileWritter.h" 00002 00003 int record_counter = 0; 00004 int filenumber = 0; 00005 led_live writter_led(0.01, 0.5, 1.); 00006 00007 void FileWritter(const void *param) 00008 { 00009 USBHostMSD* msd = new USBHostMSD("usb"); 00010 FILE *ft = NULL; 00011 00012 led_red = 1.; 00013 00014 operating_mode = Collecting; 00015 // pc.printf("Starting USB\n"); 00016 00017 while (operating_mode != Exiting) 00018 { 00019 led_red = 0.0; 00020 if (!msd->connected()) 00021 { 00022 // try to connect a MSD device 00023 while((!msd->connect()) && (operating_mode != Exiting)) 00024 { 00025 rtos::Thread::wait(500); 00026 // operating_mode = USB_Connecting; 00027 } 00028 } 00029 00030 led_red = 1.; 00031 00032 while (ft == NULL) 00033 { 00034 char filetrgt[25]; 00035 00036 if (operating_mode == Exiting) 00037 return; 00038 00039 led_red = 0.0; 00040 sprintf(filetrgt, "/usb/R/R%07d.csv", ++filenumber); 00041 pc.printf("Opening file %s\n", filetrgt); 00042 ft = fopen(filetrgt, "rb"); 00043 if (ft == NULL) 00044 { 00045 ft = fopen(filetrgt, "wb"); 00046 if (ft == NULL) 00047 { 00048 // operating_mode = File_opening; 00049 } 00050 } 00051 else 00052 { 00053 led_red = 1.0; 00054 fclose (ft); 00055 ft = NULL; 00056 } 00057 } 00058 00059 led_red = 1; 00060 operating_mode = Collecting; 00061 00062 for (record_counter=0; ((record_counter < FILESIZE) && (operating_mode != Exiting)); ++record_counter) 00063 { 00064 osEvent queue_returned; 00065 00066 if ((ft != NULL) && (record_counter == 0)) 00067 fprintf(ft, "File\tTime\tnr\tmag_X\tmag_Y\tmag_z\tacc_X\tacc_Y\tacc_Z\tgiro_X\tgiro_Y\tgiro_Z\tlight\tAin0\tTSI\tTemperature\toverflow\t\n"); 00068 00069 do 00070 { 00071 queue_returned = data_queue.get(20); 00072 } while ((queue_returned.status != osEventMessage) && (operating_mode != Exiting)); 00073 00074 struct row_type *data_buffer = (struct row_type *)queue_returned.value.p; 00075 00076 if (ft != NULL) 00077 { 00078 fprintf(ft, "%8d\t%12d\t%5d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6.4f\t%6.4f\t%6.3f\t%5d\t%1d\t\n", 00079 (int)filenumber, (int)data_buffer->time, (int)record_counter, 00080 (int)data_buffer->mag_x, (int)data_buffer->mag_y, (int)data_buffer->mag_z, 00081 (int)data_buffer->acc_x, (int)data_buffer->acc_y, (int)data_buffer->acc_z, 00082 (int)data_buffer->giro_x, (int)data_buffer->giro_y, (int)data_buffer->giro_z, 00083 (float)data_buffer->light, (float)data_buffer->Ain0, 00084 (float)data_buffer->tsi, 00085 (int)data_buffer->temperature, 00086 (int)data_buffer->was_overflow); 00087 fflush(ft); 00088 } 00089 data_memory.free(data_buffer); 00090 writter_led.live(led_red); 00091 } 00092 00093 if (NULL != ft) 00094 { 00095 fflush(ft); 00096 fclose(ft); 00097 ft=NULL; 00098 } 00099 fflush(NULL); 00100 } 00101 00102 pc.printf("Ending file writing task\n"); 00103 00104 for (int i=0; i<10; ++i) 00105 { 00106 led_red = 0.9; 00107 rtos::Thread::wait(200); 00108 led_red = 0.1; 00109 rtos::Thread::wait(400); 00110 } 00111 led_red = 1.0; 00112 }
Generated on Sat Jul 30 2022 15:40:23 by
