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: SoftSerial MAX14690 Buffer
Fork of rtos_threading_with_callback by
sdLogger.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "global.h" 00004 #include <stdio.h> 00005 #include <errno.h> 00006 #include "SDBlockDevice.h" 00007 #include "LittleFileSystem.h" 00008 #include "FATFileSystem.h" 00009 #include "logger.h" 00010 00011 static void return_error(int ret_val){ 00012 if (ret_val) 00013 printf("SD: Failure. %d\r\n", ret_val); 00014 //else 00015 //printf("SD: done.\r\n"); 00016 } 00017 00018 static void errno_error(void* ret_val){ 00019 if (ret_val == NULL) 00020 printf("SD: Failure. %d \r\n", errno); 00021 //else 00022 //printf("SD: done.\r\n"); 00023 } 00024 class SDLogger 00025 { 00026 public: 00027 static void run() 00028 { 00029 for (;;) { 00030 //char buffer[200]; 00031 //sprintf(buffer, "Pressure: %4.1f \t Temperature: %3.2f\t Altitude: %4.1f\r\nACC1:%2.1f;%2.1f;%2.1f\r\nACC2:%2.1f;%2.1f;%2.1f\r\n", pressure, temperature, altitude, (acc1[0]), (acc1[1]), (acc1[2]),(acc2[0]), (acc2[1]), (acc2[2])); 00032 char* msg = (char*) Logger::q.get(osWaitForever).value.p; 00033 SD_appendData(msg); 00034 delete[] msg; 00035 rtos::Thread::wait(6000);//10 datasets per minute. TODO: log current system time 00036 } 00037 } 00038 SDLogger() 00039 { 00040 testSD(); 00041 registerThread(SDLogger::run); 00042 } 00043 static void testSD() 00044 { 00045 printf("SD: Mounting the filesystem on \"/fs\". "); 00046 int error = fs.mount(&bd); 00047 return_error(error); 00048 00049 printf("SD: Opening a new file, numbers.txt."); 00050 FILE* fd = fopen("/fs/numbers.txt", "w"); 00051 errno_error(fd); 00052 00053 for (int i = 0; i < 20; i++){ 00054 printf("SD: Writing decimal numbers to a file (%d/20)\r", i); 00055 fprintf(fd, "%d\r\n", i); 00056 } 00057 printf("SD: Writing decimal numbers to a file (20/20) done.\r\n"); 00058 00059 printf("SD: Closing file.\r\n"); 00060 fclose(fd); 00061 printf("SD: done.\r\n"); 00062 } 00063 static void SD_appendData(const char* data) 00064 { 00065 00066 //printf("SD: Opening file data.txt.\r\n"); 00067 FILE* fd = fopen("/fs/data.txt", "w+"); 00068 errno_error(fd); 00069 00070 fprintf(fd, "%s", data); 00071 //printf("SD: Writing done.\r\n"); 00072 00073 //printf("SD: Closing file.\r\n"); 00074 fclose(fd); 00075 //printf("SD: done.\r\n"); 00076 } 00077 static SDBlockDevice bd;//PinName mosi, PinName miso, PinName sclk, PinName cs 00078 static FATFileSystem fs; 00079 }; 00080 SDBlockDevice SDLogger::bd(P0_5, P0_6, P0_4, P0_7); 00081 FATFileSystem SDLogger::fs("fs"); 00082 00083 // some witchcraft to register run function without touching anything outside our library 00084 static SDLogger _dummy;
Generated on Tue Sep 13 2022 05:19:36 by
1.7.2
