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@1:5ad44a4edff9, 2015-05-09 (annotated)
- Committer:
- Waldek
- Date:
- Sat May 09 15:06:38 2015 +0000
- Revision:
- 1:5ad44a4edff9
- Parent:
- 0:fa31f8461c63
Correction in the magnetic measurement
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Waldek | 0:fa31f8461c63 | 1 | #include "FileWritter.h" |
| Waldek | 0:fa31f8461c63 | 2 | |
| Waldek | 0:fa31f8461c63 | 3 | int record_counter = 0; |
| Waldek | 0:fa31f8461c63 | 4 | int filenumber = 0; |
| Waldek | 0:fa31f8461c63 | 5 | led_live writter_led(0.01, 0.5, 1.); |
| Waldek | 0:fa31f8461c63 | 6 | |
| Waldek | 0:fa31f8461c63 | 7 | void FileWritter(const void *param) |
| Waldek | 0:fa31f8461c63 | 8 | { |
| Waldek | 0:fa31f8461c63 | 9 | USBHostMSD* msd = new USBHostMSD("usb"); |
| Waldek | 0:fa31f8461c63 | 10 | FILE *ft = NULL; |
| Waldek | 0:fa31f8461c63 | 11 | |
| Waldek | 0:fa31f8461c63 | 12 | led_red = 1.; |
| Waldek | 0:fa31f8461c63 | 13 | |
| Waldek | 0:fa31f8461c63 | 14 | operating_mode = Collecting; |
| Waldek | 0:fa31f8461c63 | 15 | // pc.printf("Starting USB\n"); |
| Waldek | 0:fa31f8461c63 | 16 | |
| Waldek | 0:fa31f8461c63 | 17 | while (operating_mode != Exiting) |
| Waldek | 0:fa31f8461c63 | 18 | { |
| Waldek | 0:fa31f8461c63 | 19 | led_red = 0.0; |
| Waldek | 0:fa31f8461c63 | 20 | if (!msd->connected()) |
| Waldek | 0:fa31f8461c63 | 21 | { |
| Waldek | 0:fa31f8461c63 | 22 | // try to connect a MSD device |
| Waldek | 0:fa31f8461c63 | 23 | while((!msd->connect()) && (operating_mode != Exiting)) |
| Waldek | 0:fa31f8461c63 | 24 | { |
| Waldek | 0:fa31f8461c63 | 25 | rtos::Thread::wait(500); |
| Waldek | 0:fa31f8461c63 | 26 | // operating_mode = USB_Connecting; |
| Waldek | 0:fa31f8461c63 | 27 | } |
| Waldek | 0:fa31f8461c63 | 28 | } |
| Waldek | 0:fa31f8461c63 | 29 | |
| Waldek | 0:fa31f8461c63 | 30 | led_red = 1.; |
| Waldek | 0:fa31f8461c63 | 31 | |
| Waldek | 0:fa31f8461c63 | 32 | while (ft == NULL) |
| Waldek | 0:fa31f8461c63 | 33 | { |
| Waldek | 0:fa31f8461c63 | 34 | char filetrgt[25]; |
| Waldek | 0:fa31f8461c63 | 35 | |
| Waldek | 0:fa31f8461c63 | 36 | if (operating_mode == Exiting) |
| Waldek | 0:fa31f8461c63 | 37 | return; |
| Waldek | 0:fa31f8461c63 | 38 | |
| Waldek | 0:fa31f8461c63 | 39 | led_red = 0.0; |
| Waldek | 0:fa31f8461c63 | 40 | sprintf(filetrgt, "/usb/R/R%07d.csv", ++filenumber); |
| Waldek | 0:fa31f8461c63 | 41 | pc.printf("Opening file %s\n", filetrgt); |
| Waldek | 0:fa31f8461c63 | 42 | ft = fopen(filetrgt, "rb"); |
| Waldek | 0:fa31f8461c63 | 43 | if (ft == NULL) |
| Waldek | 0:fa31f8461c63 | 44 | { |
| Waldek | 0:fa31f8461c63 | 45 | ft = fopen(filetrgt, "wb"); |
| Waldek | 0:fa31f8461c63 | 46 | if (ft == NULL) |
| Waldek | 0:fa31f8461c63 | 47 | { |
| Waldek | 0:fa31f8461c63 | 48 | // operating_mode = File_opening; |
| Waldek | 0:fa31f8461c63 | 49 | } |
| Waldek | 0:fa31f8461c63 | 50 | } |
| Waldek | 0:fa31f8461c63 | 51 | else |
| Waldek | 0:fa31f8461c63 | 52 | { |
| Waldek | 0:fa31f8461c63 | 53 | led_red = 1.0; |
| Waldek | 0:fa31f8461c63 | 54 | fclose (ft); |
| Waldek | 0:fa31f8461c63 | 55 | ft = NULL; |
| Waldek | 0:fa31f8461c63 | 56 | } |
| Waldek | 0:fa31f8461c63 | 57 | } |
| Waldek | 0:fa31f8461c63 | 58 | |
| Waldek | 0:fa31f8461c63 | 59 | led_red = 1; |
| Waldek | 0:fa31f8461c63 | 60 | operating_mode = Collecting; |
| Waldek | 0:fa31f8461c63 | 61 | |
| Waldek | 0:fa31f8461c63 | 62 | for (record_counter=0; ((record_counter < FILESIZE) && (operating_mode != Exiting)); ++record_counter) |
| Waldek | 0:fa31f8461c63 | 63 | { |
| Waldek | 0:fa31f8461c63 | 64 | osEvent queue_returned; |
| Waldek | 0:fa31f8461c63 | 65 | |
| Waldek | 0:fa31f8461c63 | 66 | if ((ft != NULL) && (record_counter == 0)) |
| Waldek | 0:fa31f8461c63 | 67 | 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"); |
| Waldek | 0:fa31f8461c63 | 68 | |
| Waldek | 0:fa31f8461c63 | 69 | do |
| Waldek | 0:fa31f8461c63 | 70 | { |
| Waldek | 0:fa31f8461c63 | 71 | queue_returned = data_queue.get(20); |
| Waldek | 0:fa31f8461c63 | 72 | } while ((queue_returned.status != osEventMessage) && (operating_mode != Exiting)); |
| Waldek | 0:fa31f8461c63 | 73 | |
| Waldek | 0:fa31f8461c63 | 74 | struct row_type *data_buffer = (struct row_type *)queue_returned.value.p; |
| Waldek | 0:fa31f8461c63 | 75 | |
| Waldek | 0:fa31f8461c63 | 76 | if (ft != NULL) |
| Waldek | 0:fa31f8461c63 | 77 | { |
| Waldek | 0:fa31f8461c63 | 78 | 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", |
| Waldek | 0:fa31f8461c63 | 79 | (int)filenumber, (int)data_buffer->time, (int)record_counter, |
| Waldek | 1:5ad44a4edff9 | 80 | (int)data_buffer->mag_x, (int)data_buffer->mag_y, (int)data_buffer->mag_z, |
| Waldek | 0:fa31f8461c63 | 81 | (int)data_buffer->acc_x, (int)data_buffer->acc_y, (int)data_buffer->acc_z, |
| Waldek | 0:fa31f8461c63 | 82 | (int)data_buffer->giro_x, (int)data_buffer->giro_y, (int)data_buffer->giro_z, |
| Waldek | 0:fa31f8461c63 | 83 | (float)data_buffer->light, (float)data_buffer->Ain0, |
| Waldek | 0:fa31f8461c63 | 84 | (float)data_buffer->tsi, |
| Waldek | 0:fa31f8461c63 | 85 | (int)data_buffer->temperature, |
| Waldek | 0:fa31f8461c63 | 86 | (int)data_buffer->was_overflow); |
| Waldek | 0:fa31f8461c63 | 87 | fflush(ft); |
| Waldek | 0:fa31f8461c63 | 88 | } |
| Waldek | 0:fa31f8461c63 | 89 | data_memory.free(data_buffer); |
| Waldek | 0:fa31f8461c63 | 90 | writter_led.live(led_red); |
| Waldek | 0:fa31f8461c63 | 91 | } |
| Waldek | 0:fa31f8461c63 | 92 | |
| Waldek | 0:fa31f8461c63 | 93 | if (NULL != ft) |
| Waldek | 0:fa31f8461c63 | 94 | { |
| Waldek | 0:fa31f8461c63 | 95 | fflush(ft); |
| Waldek | 0:fa31f8461c63 | 96 | fclose(ft); |
| Waldek | 0:fa31f8461c63 | 97 | ft=NULL; |
| Waldek | 0:fa31f8461c63 | 98 | } |
| Waldek | 0:fa31f8461c63 | 99 | fflush(NULL); |
| Waldek | 0:fa31f8461c63 | 100 | } |
| Waldek | 0:fa31f8461c63 | 101 | |
| Waldek | 0:fa31f8461c63 | 102 | pc.printf("Ending file writing task\n"); |
| Waldek | 0:fa31f8461c63 | 103 | |
| Waldek | 0:fa31f8461c63 | 104 | for (int i=0; i<10; ++i) |
| Waldek | 0:fa31f8461c63 | 105 | { |
| Waldek | 0:fa31f8461c63 | 106 | led_red = 0.9; |
| Waldek | 0:fa31f8461c63 | 107 | rtos::Thread::wait(200); |
| Waldek | 0:fa31f8461c63 | 108 | led_red = 0.1; |
| Waldek | 0:fa31f8461c63 | 109 | rtos::Thread::wait(400); |
| Waldek | 0:fa31f8461c63 | 110 | } |
| Waldek | 0:fa31f8461c63 | 111 | led_red = 1.0; |
| Waldek | 0:fa31f8461c63 | 112 | } |