File manager

Dependencies:   SDFileSystem

Dependents:   RwSDCard_Xml_GPS

Committer:
nsrwsurasak
Date:
Thu May 26 14:05:36 2016 +0000
Revision:
26:2f10fcabed0e
Parent:
25:7f3420c04178
Child:
27:b0eb0f36110e
Fix Bug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Lucyjungz 14:4ba6147f067b 1 /**
Lucyjungz 14:4ba6147f067b 2 ******************************************************************************
Lucyjungz 14:4ba6147f067b 3 * @file FileManager.cpp
Lucyjungz 14:4ba6147f067b 4 * @author Narut T
Lucyjungz 14:4ba6147f067b 5 * @version V1
Lucyjungz 14:4ba6147f067b 6 * @date 19/05/2016
Lucyjungz 14:4ba6147f067b 7 * @brief File Manager for managing file system in SD Card
Lucyjungz 14:4ba6147f067b 8 ******************************************************************************/
Lucyjungz 14:4ba6147f067b 9
nsrwsurasak 13:d83e2dcc882d 10 #include "main.h"
nsrwsurasak 0:a27e0d3581d1 11
Lucyjungz 14:4ba6147f067b 12 char m_StrGpsInterval[XMLTEXT_SIZE]; // GPS Interval
Lucyjungz 14:4ba6147f067b 13 char m_StrDataInterval[XMLTEXT_SIZE]; // Data Interval
Lucyjungz 14:4ba6147f067b 14
Lucyjungz 14:4ba6147f067b 15 uint32_t m_GpsInterval;
Lucyjungz 14:4ba6147f067b 16 uint32_t m_DataInterval;
Lucyjungz 3:6e08d0bba1bb 17 Variable_Data_TypeDef m_varList[MAX_VAR]; // Variable List
Lucyjungz 3:6e08d0bba1bb 18 unsigned int m_amountVarList = 0; // Amount of variable list
Lucyjungz 21:0c52dbc23f52 19 bool m_SdCardHasDisconnected = false; // flag to indicate sd card has disconnected
Lucyjungz 21:0c52dbc23f52 20 char m_varListFileName[MAX_FILE_NAME_SIZE]; // Variable File Name
Lucyjungz 21:0c52dbc23f52 21 bool m_sdCardIsPresent; // Flag to indicate sd card is present
Lucyjungz 21:0c52dbc23f52 22 /** Connect pin for SD Card LED */
Lucyjungz 11:e21d4c5bfd1b 23 #ifdef LED_SDCARD
Lucyjungz 17:d24d2b2bbd42 24 DigitalOut ledStatus(LED_SDCARD);
Lucyjungz 11:e21d4c5bfd1b 25 #else
Lucyjungz 11:e21d4c5bfd1b 26 DigitalOut ledStatus(NC);
Lucyjungz 11:e21d4c5bfd1b 27 #endif
Lucyjungz 11:e21d4c5bfd1b 28
Lucyjungz 17:d24d2b2bbd42 29
Lucyjungz 3:6e08d0bba1bb 30 /* ############### Static function prototype ################## */
nsrwsurasak 0:a27e0d3581d1 31
Lucyjungz 14:4ba6147f067b 32 static void FILEMANAGER_RemoveSpaces(char* s , int size);
Lucyjungz 14:4ba6147f067b 33 static void FILEMANAGER_GetXmlText(char *str, char *ret);
Lucyjungz 14:4ba6147f067b 34 static void FILEMANAGER_GenerateFileNameWithTime(time_t timestamp, char * file_name);
Lucyjungz 14:4ba6147f067b 35 static void FILEMANAGER_SetLedStatus(bool on);
Lucyjungz 3:6e08d0bba1bb 36
Lucyjungz 3:6e08d0bba1bb 37 /**
Lucyjungz 3:6e08d0bba1bb 38 * @brief Utility function to Remove space charector from given char array
Lucyjungz 3:6e08d0bba1bb 39 * @note
Lucyjungz 3:6e08d0bba1bb 40 * @param char array to process remove spaces
Lucyjungz 3:6e08d0bba1bb 41 * @param size of char array
Lucyjungz 3:6e08d0bba1bb 42 * @retval space removed char array
Lucyjungz 3:6e08d0bba1bb 43 */
Lucyjungz 14:4ba6147f067b 44 static void FILEMANAGER_RemoveSpaces(char* s , int size)
nsrwsurasak 0:a27e0d3581d1 45 {
nsrwsurasak 0:a27e0d3581d1 46 char* cpy = s; // an alias to iterate through s without moving s
nsrwsurasak 0:a27e0d3581d1 47 char* temp = s;
nsrwsurasak 0:a27e0d3581d1 48
nsrwsurasak 0:a27e0d3581d1 49 for (int i = 0 ; i < size ; i++) {
nsrwsurasak 0:a27e0d3581d1 50 if (*cpy != ' ')
nsrwsurasak 0:a27e0d3581d1 51 *temp++ = *cpy;
nsrwsurasak 0:a27e0d3581d1 52 cpy++;
nsrwsurasak 0:a27e0d3581d1 53 }
nsrwsurasak 0:a27e0d3581d1 54 *temp = 0;
nsrwsurasak 0:a27e0d3581d1 55 return;
nsrwsurasak 0:a27e0d3581d1 56 }
Lucyjungz 3:6e08d0bba1bb 57 /**
Lucyjungz 3:6e08d0bba1bb 58 * @brief Utility function to get XML tag
Lucyjungz 3:6e08d0bba1bb 59 * @note Only First tag will be returned
Lucyjungz 3:6e08d0bba1bb 60 * @param char array to get XML Text
Lucyjungz 3:6e08d0bba1bb 61 * @param char array to be populate XML text
Lucyjungz 3:6e08d0bba1bb 62 * @retval XML text
Lucyjungz 3:6e08d0bba1bb 63 */
Lucyjungz 14:4ba6147f067b 64 static void FILEMANAGER_GetXmlText(char *str, char *ret)
nsrwsurasak 0:a27e0d3581d1 65 {
nsrwsurasak 0:a27e0d3581d1 66 int size = strlen(str);
nsrwsurasak 0:a27e0d3581d1 67 int i;
nsrwsurasak 0:a27e0d3581d1 68 bool begin_text = false;
nsrwsurasak 0:a27e0d3581d1 69 char * ret_addr = ret;
Lucyjungz 3:6e08d0bba1bb 70 /* initialized our return value */
nsrwsurasak 0:a27e0d3581d1 71 memset (ret,' ',XMLTEXT_SIZE);
nsrwsurasak 0:a27e0d3581d1 72
Lucyjungz 3:6e08d0bba1bb 73 /* Loop to check XML tag symbols */
nsrwsurasak 0:a27e0d3581d1 74 for(i = 0; i < size ; i++) {
nsrwsurasak 0:a27e0d3581d1 75
nsrwsurasak 0:a27e0d3581d1 76 if (*str == '>') {
Lucyjungz 3:6e08d0bba1bb 77 /* Found begining of the tag */
nsrwsurasak 0:a27e0d3581d1 78 begin_text = true;
nsrwsurasak 0:a27e0d3581d1 79 } else if (begin_text && *str == '<') {
Lucyjungz 3:6e08d0bba1bb 80 /* Reach the end of text message */
nsrwsurasak 0:a27e0d3581d1 81 begin_text = false;
nsrwsurasak 0:a27e0d3581d1 82 break;
nsrwsurasak 0:a27e0d3581d1 83 } else if (begin_text && *str != ' ') {
Lucyjungz 3:6e08d0bba1bb 84 /* Populate the return value */
nsrwsurasak 0:a27e0d3581d1 85 *ret = *str;
nsrwsurasak 0:a27e0d3581d1 86 ret++;
nsrwsurasak 0:a27e0d3581d1 87 }
Lucyjungz 3:6e08d0bba1bb 88 /* Move to next char */
nsrwsurasak 0:a27e0d3581d1 89 str++;
nsrwsurasak 0:a27e0d3581d1 90 }
Lucyjungz 3:6e08d0bba1bb 91
Lucyjungz 3:6e08d0bba1bb 92 /* Remove space from return value */
Lucyjungz 14:4ba6147f067b 93 FILEMANAGER_RemoveSpaces(ret_addr, XMLTEXT_SIZE);
nsrwsurasak 0:a27e0d3581d1 94 }
Lucyjungz 3:6e08d0bba1bb 95 /**
Lucyjungz 3:6e08d0bba1bb 96 * @brief Utility function to get File Name with Date
Lucyjungz 3:6e08d0bba1bb 97 * @note Format file will be YYYY-MM-DD.filename
Lucyjungz 3:6e08d0bba1bb 98 * @param timestamp - time structure to get Date
Lucyjungz 3:6e08d0bba1bb 99 * @param file_name - char array to file name
Lucyjungz 3:6e08d0bba1bb 100 * @retval renamed file name
Lucyjungz 3:6e08d0bba1bb 101 */
Lucyjungz 14:4ba6147f067b 102 static void FILEMANAGER_GenerateFileNameWithTime(time_t timestamp, char * file_name)
Lucyjungz 1:1f1f2b99756b 103 {
Lucyjungz 14:4ba6147f067b 104 char str[RENAME_FILE_BUFFER_SIZE];
Lucyjungz 1:1f1f2b99756b 105 struct tm * ptm;
Lucyjungz 1:1f1f2b99756b 106
Lucyjungz 3:6e08d0bba1bb 107 /* Convert timestamp to readable format */
Lucyjungz 3:6e08d0bba1bb 108 ptm = localtime ( &timestamp );
Lucyjungz 3:6e08d0bba1bb 109
Lucyjungz 3:6e08d0bba1bb 110 /* Replacing YYYY to the converted year */
Lucyjungz 14:4ba6147f067b 111 sprintf(str,"%04d", ptm->tm_year + YEAR_4DIGITS_OFFSET);
Lucyjungz 14:4ba6147f067b 112 memcpy(&file_name[TIMESTAMP_YEAR_OFFSET], str, TIMESTAMP_YEAR_SIZE);
Lucyjungz 1:1f1f2b99756b 113
Lucyjungz 3:6e08d0bba1bb 114 /* Replacing MM to converted month */
Lucyjungz 1:1f1f2b99756b 115 sprintf(str,"%02d", ptm->tm_mon+1);
Lucyjungz 14:4ba6147f067b 116 memcpy(&file_name[TIMESTAMP_MONTH_OFFSET], str, TIMESTAMP_MONTH_SIZE);
Lucyjungz 1:1f1f2b99756b 117
Lucyjungz 3:6e08d0bba1bb 118 /* Replacing DD to converted date */
Lucyjungz 1:1f1f2b99756b 119 sprintf(str,"%02d", ptm->tm_mday);
Lucyjungz 14:4ba6147f067b 120 memcpy(&file_name[TIMESTAMP_DATE_OFFSET], str,TIMESTAMP_DATE_SIZE);
Lucyjungz 1:1f1f2b99756b 121 }
Lucyjungz 3:6e08d0bba1bb 122 /**
Lucyjungz 3:6e08d0bba1bb 123 * @brief Function to perform read setup file
Lucyjungz 3:6e08d0bba1bb 124 * @note filename must be defined in FileManager.h, GPS/ Data interval will be stored in dedicated variable
Lucyjungz 3:6e08d0bba1bb 125 * @param None
Lucyjungz 3:6e08d0bba1bb 126 * @retval None
Lucyjungz 3:6e08d0bba1bb 127 */
Lucyjungz 14:4ba6147f067b 128 void FILEMANAGER_ReadSetupFile()
nsrwsurasak 0:a27e0d3581d1 129 {
Lucyjungz 3:6e08d0bba1bb 130 /* Open file in reading mode */
nsrwsurasak 0:a27e0d3581d1 131 FILE *fp = fopen(SETUP_FILE_NAME, "r");
nsrwsurasak 0:a27e0d3581d1 132
Lucyjungz 3:6e08d0bba1bb 133 if (fp == NULL) {
Lucyjungz 3:6e08d0bba1bb 134 /* In case of error, print the message */
nsrwsurasak 0:a27e0d3581d1 135 printf("\nError! Unable to open file! %s \n", SETUP_FILE_NAME);
Lucyjungz 11:e21d4c5bfd1b 136
Lucyjungz 11:e21d4c5bfd1b 137 /* Indicate LED Status (OFF)*/
Lucyjungz 14:4ba6147f067b 138 FILEMANAGER_SetLedStatus(false);
Lucyjungz 3:6e08d0bba1bb 139 } else {
nsrwsurasak 0:a27e0d3581d1 140
Lucyjungz 3:6e08d0bba1bb 141 /* Initialized state */
nsrwsurasak 0:a27e0d3581d1 142 ReadingFileState state = STATE_FINDING;
Lucyjungz 3:6e08d0bba1bb 143
Lucyjungz 3:6e08d0bba1bb 144 /* Allocate buffer for reading file */
Lucyjungz 14:4ba6147f067b 145 char buf[READ_FILE_BUFFER_SIZE];
Lucyjungz 3:6e08d0bba1bb 146
Lucyjungz 11:e21d4c5bfd1b 147 /* Indicate LED Status (ON)*/
Lucyjungz 14:4ba6147f067b 148 FILEMANAGER_SetLedStatus(true);
Lucyjungz 11:e21d4c5bfd1b 149
Lucyjungz 3:6e08d0bba1bb 150 /* Read line from the file */
nsrwsurasak 0:a27e0d3581d1 151 while (fgets(buf, sizeof(buf), fp) != NULL) {
Lucyjungz 3:6e08d0bba1bb 152
Lucyjungz 3:6e08d0bba1bb 153 /* Check the TAG */
Lucyjungz 3:6e08d0bba1bb 154 if (strstr (buf,DATA_TAG))
Lucyjungz 3:6e08d0bba1bb 155 {
Lucyjungz 3:6e08d0bba1bb 156 /* Found the DATA TAG */
nsrwsurasak 0:a27e0d3581d1 157 state = STATE_FOUND_DATA;
Lucyjungz 21:0c52dbc23f52 158 }
Lucyjungz 21:0c52dbc23f52 159 else if (strstr (buf,GPS_TAG))
Lucyjungz 3:6e08d0bba1bb 160 {
Lucyjungz 3:6e08d0bba1bb 161 /* Found GPS TAG */
nsrwsurasak 0:a27e0d3581d1 162 state = STATE_FOUND_GPS;
Lucyjungz 21:0c52dbc23f52 163 }
Lucyjungz 21:0c52dbc23f52 164 else if (strstr (buf,UPDATE_INTERVAL_TAG))
Lucyjungz 3:6e08d0bba1bb 165 {
Lucyjungz 3:6e08d0bba1bb 166 /* Found Interval TAG */
Lucyjungz 3:6e08d0bba1bb 167 if (state == STATE_FOUND_GPS)
Lucyjungz 3:6e08d0bba1bb 168 {
Lucyjungz 3:6e08d0bba1bb 169 /* Get XML text for GPS Interval */
Lucyjungz 14:4ba6147f067b 170 FILEMANAGER_GetXmlText(buf, m_StrGpsInterval);
Lucyjungz 14:4ba6147f067b 171 m_GpsInterval = atoi(m_StrGpsInterval);
Lucyjungz 8:5af4e12c43b2 172 #if DEBUG
Lucyjungz 14:4ba6147f067b 173 printf("\r\n-found GPS interval %s ", m_StrGpsInterval);
Lucyjungz 8:5af4e12c43b2 174 #endif
Lucyjungz 8:5af4e12c43b2 175
Lucyjungz 8:5af4e12c43b2 176 /* Set state to indicate that we are finding */
nsrwsurasak 0:a27e0d3581d1 177 state = STATE_FINDING;
Lucyjungz 3:6e08d0bba1bb 178 }
Lucyjungz 3:6e08d0bba1bb 179 else if(state == STATE_FOUND_DATA)
Lucyjungz 3:6e08d0bba1bb 180 {
Lucyjungz 3:6e08d0bba1bb 181 /* Get XML text for Data Interval */
Lucyjungz 14:4ba6147f067b 182 FILEMANAGER_GetXmlText(buf, m_StrDataInterval);
Lucyjungz 14:4ba6147f067b 183 m_DataInterval = atoi(m_StrDataInterval);
Lucyjungz 8:5af4e12c43b2 184 #if DEBUG
Lucyjungz 14:4ba6147f067b 185 printf("\r\n-found Data interval %s ", m_StrDataInterval);
Lucyjungz 8:5af4e12c43b2 186 #endif
Lucyjungz 8:5af4e12c43b2 187
Lucyjungz 8:5af4e12c43b2 188 /* Set state to indicate that we are finding */
nsrwsurasak 0:a27e0d3581d1 189 state = STATE_FINDING;
nsrwsurasak 0:a27e0d3581d1 190 }
nsrwsurasak 0:a27e0d3581d1 191 }
Lucyjungz 21:0c52dbc23f52 192 else if (strstr (buf,VAR_LIST_FILE_TAG))
Lucyjungz 21:0c52dbc23f52 193 {
Lucyjungz 21:0c52dbc23f52 194 /* Get XML text for Variable File Name */
Lucyjungz 21:0c52dbc23f52 195 char bufFileName[MAX_FILE_NAME_SIZE];
Lucyjungz 21:0c52dbc23f52 196 FILEMANAGER_GetXmlText(buf, bufFileName);
Lucyjungz 21:0c52dbc23f52 197 memcpy(m_varListFileName,PREFIX_FILE_NAME,strlen(PREFIX_FILE_NAME));
Lucyjungz 21:0c52dbc23f52 198 memcpy(&m_varListFileName[strlen(PREFIX_FILE_NAME)],bufFileName,strlen(bufFileName));
Lucyjungz 21:0c52dbc23f52 199
Lucyjungz 21:0c52dbc23f52 200 }
nsrwsurasak 0:a27e0d3581d1 201 }
Lucyjungz 3:6e08d0bba1bb 202 /* Ensure file is closed */
Lucyjungz 3:6e08d0bba1bb 203 fclose(fp);
nsrwsurasak 26:2f10fcabed0e 204
nsrwsurasak 26:2f10fcabed0e 205 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 206 free(fp);
nsrwsurasak 26:2f10fcabed0e 207 #endif
nsrwsurasak 0:a27e0d3581d1 208 }
nsrwsurasak 0:a27e0d3581d1 209 }
Lucyjungz 3:6e08d0bba1bb 210 /**
Lucyjungz 3:6e08d0bba1bb 211 * @brief Function to log GPS Data
Lucyjungz 3:6e08d0bba1bb 212 * @note
Lucyjungz 3:6e08d0bba1bb 213 * @param timestamp - time structure to get Date
Lucyjungz 3:6e08d0bba1bb 214 * @param lat - char array for lattitude
Lucyjungz 3:6e08d0bba1bb 215 * @param longti - char array for longtitude
Lucyjungz 3:6e08d0bba1bb 216 * @retval None
Lucyjungz 3:6e08d0bba1bb 217 */
Lucyjungz 14:4ba6147f067b 218 void FILEMANAGER_LogGPSData(time_t timestamp ,char lat[], char longti[])
nsrwsurasak 0:a27e0d3581d1 219 {
nsrwsurasak 23:7ffd9724e105 220 if (!m_sdCardIsPresent)
nsrwsurasak 23:7ffd9724e105 221 {
nsrwsurasak 23:7ffd9724e105 222 /** Turn off LED */
nsrwsurasak 23:7ffd9724e105 223 FILEMANAGER_SetLedStatus(false);
nsrwsurasak 23:7ffd9724e105 224
nsrwsurasak 23:7ffd9724e105 225 printf("Error! SD Card is not connected \n");
nsrwsurasak 23:7ffd9724e105 226
nsrwsurasak 23:7ffd9724e105 227 /** Return as nothing to be done */
nsrwsurasak 23:7ffd9724e105 228 return;
nsrwsurasak 23:7ffd9724e105 229 }
Lucyjungz 3:6e08d0bba1bb 230 /* Get File name */
Lucyjungz 1:1f1f2b99756b 231 char file_name[] = GPS_LOG_FILE_NAME;
Lucyjungz 1:1f1f2b99756b 232
Lucyjungz 3:6e08d0bba1bb 233 /* Generate file name with time stamp */
Lucyjungz 14:4ba6147f067b 234 FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name);
Lucyjungz 3:6e08d0bba1bb 235
Lucyjungz 3:6e08d0bba1bb 236 /* Open file with "APPEND" mode */
Lucyjungz 1:1f1f2b99756b 237 FILE *fp = fopen(file_name, "a");
Lucyjungz 1:1f1f2b99756b 238
Lucyjungz 3:6e08d0bba1bb 239 if (fp == NULL)
Lucyjungz 3:6e08d0bba1bb 240 {
Lucyjungz 3:6e08d0bba1bb 241 /* if it can't open the file then print error message */
Lucyjungz 1:1f1f2b99756b 242 printf("Error! Unable to open file %s!\n",file_name);
Lucyjungz 11:e21d4c5bfd1b 243
Lucyjungz 11:e21d4c5bfd1b 244 /* Indicate LED Status (OFF)*/
Lucyjungz 14:4ba6147f067b 245 FILEMANAGER_SetLedStatus(false);
Lucyjungz 3:6e08d0bba1bb 246 }
Lucyjungz 11:e21d4c5bfd1b 247 else
Lucyjungz 11:e21d4c5bfd1b 248 {
Lucyjungz 11:e21d4c5bfd1b 249 /* Indicate LED Status (ON)*/
Lucyjungz 14:4ba6147f067b 250 FILEMANAGER_SetLedStatus(true);
Lucyjungz 11:e21d4c5bfd1b 251
Lucyjungz 3:6e08d0bba1bb 252 /* Print some message for information */
Lucyjungz 1:1f1f2b99756b 253 printf("\r\n Writing to Gps Log File (%s)....",file_name);
Lucyjungz 1:1f1f2b99756b 254
Lucyjungz 3:6e08d0bba1bb 255 /* Write the line with lattitude and longtitude */
Lucyjungz 3:6e08d0bba1bb 256 fprintf(fp, "%d,%s,%s\n",timestamp,lat,longti);
Lucyjungz 1:1f1f2b99756b 257
Lucyjungz 1:1f1f2b99756b 258 printf("Done");
Lucyjungz 3:6e08d0bba1bb 259 /* Close file once it done */
Lucyjungz 3:6e08d0bba1bb 260 fclose(fp);
nsrwsurasak 26:2f10fcabed0e 261
nsrwsurasak 26:2f10fcabed0e 262 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 263 free(fp);
nsrwsurasak 26:2f10fcabed0e 264 #endif
Lucyjungz 1:1f1f2b99756b 265 }
Lucyjungz 1:1f1f2b99756b 266 }
Lucyjungz 3:6e08d0bba1bb 267 /**
Lucyjungz 3:6e08d0bba1bb 268 * @brief Function to log RMS Data
Lucyjungz 3:6e08d0bba1bb 269 * @note sequence must be in the same order with variableList
Lucyjungz 3:6e08d0bba1bb 270 * @param timestamp - time structure to get Date
Lucyjungz 3:6e08d0bba1bb 271 * @param var - float array to be log in the file
Lucyjungz 3:6e08d0bba1bb 272 * @param size - size of the float array
nsrwsurasak 25:7f3420c04178 273 * @param p_headerRequired - pointer to flag for log header
nsrwsurasak 25:7f3420c04178 274 * @param msec - time in millisecond
Lucyjungz 3:6e08d0bba1bb 275 * @retval None
Lucyjungz 3:6e08d0bba1bb 276 */
nsrwsurasak 25:7f3420c04178 277 void FILEMANAGER_LogRMSData(time_t timestamp ,float * var, int size, bool * p_headerRequired, uint32_t msec)
Lucyjungz 1:1f1f2b99756b 278 {
nsrwsurasak 23:7ffd9724e105 279 if (!m_sdCardIsPresent)
nsrwsurasak 23:7ffd9724e105 280 {
nsrwsurasak 23:7ffd9724e105 281 /** Turn off LED */
nsrwsurasak 23:7ffd9724e105 282 FILEMANAGER_SetLedStatus(false);
nsrwsurasak 23:7ffd9724e105 283
nsrwsurasak 23:7ffd9724e105 284 printf("Error! SD Card is not connected \n");
nsrwsurasak 23:7ffd9724e105 285
nsrwsurasak 23:7ffd9724e105 286 /** Return as nothing to be done */
nsrwsurasak 23:7ffd9724e105 287 return;
nsrwsurasak 23:7ffd9724e105 288 }
Lucyjungz 3:6e08d0bba1bb 289 /* Get File name */
Lucyjungz 1:1f1f2b99756b 290 char file_name[] = RTL_LOG_FILE_NAME;
Lucyjungz 1:1f1f2b99756b 291
Lucyjungz 3:6e08d0bba1bb 292 /* Generate File name with timestamp */
nsrwsurasak 25:7f3420c04178 293
Lucyjungz 14:4ba6147f067b 294 FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name);
nsrwsurasak 25:7f3420c04178 295 #if DEBUG
nsrwsurasak 25:7f3420c04178 296 printf("\r\n File name is generated \n");
nsrwsurasak 25:7f3420c04178 297 #endif
Lucyjungz 21:0c52dbc23f52 298 if (*p_headerRequired || !FILEMANAGER_IsFileExist(file_name))
Lucyjungz 1:1f1f2b99756b 299 {
Lucyjungz 3:6e08d0bba1bb 300 /* If file is not exist, log the header */
Lucyjungz 14:4ba6147f067b 301 FILEMANAGER_LogRMSHeader(timestamp);
Lucyjungz 21:0c52dbc23f52 302
Lucyjungz 21:0c52dbc23f52 303 /* Clear flag once header has been written */
Lucyjungz 21:0c52dbc23f52 304 *p_headerRequired = false;
Lucyjungz 1:1f1f2b99756b 305 }
nsrwsurasak 25:7f3420c04178 306 #if DEBUG
nsrwsurasak 25:7f3420c04178 307 printf("\r\n Going to Open RMS File For write \n");
nsrwsurasak 25:7f3420c04178 308 #endif
Lucyjungz 3:6e08d0bba1bb 309 /* Open file with "APPEND" mode */
Lucyjungz 1:1f1f2b99756b 310 FILE *fp = fopen(file_name, "a");
nsrwsurasak 0:a27e0d3581d1 311
Lucyjungz 3:6e08d0bba1bb 312 if (fp == NULL)
Lucyjungz 3:6e08d0bba1bb 313 {
Lucyjungz 3:6e08d0bba1bb 314 /* In case of error, print the error message */
Lucyjungz 1:1f1f2b99756b 315 printf("Error! Unable to open file %s!\n",file_name);
Lucyjungz 11:e21d4c5bfd1b 316
Lucyjungz 11:e21d4c5bfd1b 317 /* Indicate LED Status (OFF)*/
Lucyjungz 14:4ba6147f067b 318 FILEMANAGER_SetLedStatus(false);
Lucyjungz 3:6e08d0bba1bb 319 }
Lucyjungz 3:6e08d0bba1bb 320 else
Lucyjungz 3:6e08d0bba1bb 321 {
Lucyjungz 11:e21d4c5bfd1b 322 /* Indicate LED Status (ON)*/
Lucyjungz 14:4ba6147f067b 323 FILEMANAGER_SetLedStatus(true);
Lucyjungz 11:e21d4c5bfd1b 324
Lucyjungz 3:6e08d0bba1bb 325 /* Print some message for information */
Lucyjungz 1:1f1f2b99756b 326 printf("\r\n Writing to Log File (%s)....",file_name);
Lucyjungz 1:1f1f2b99756b 327
Lucyjungz 3:6e08d0bba1bb 328 /* Write timestamp */
nsrwsurasak 25:7f3420c04178 329 fprintf(fp, "%d,%d",timestamp,msec);
Lucyjungz 1:1f1f2b99756b 330
Lucyjungz 3:6e08d0bba1bb 331 /* Write variable data */
Lucyjungz 1:1f1f2b99756b 332 for(int i = 0; i < size; i++)
Lucyjungz 1:1f1f2b99756b 333 {
nsrwsurasak 19:5af5c60e7a9f 334 fprintf(fp, ",%g",var[i]);
Lucyjungz 1:1f1f2b99756b 335 }
Lucyjungz 3:6e08d0bba1bb 336 /* Write new line as we done */
Lucyjungz 3:6e08d0bba1bb 337 fprintf(fp, "\n");
nsrwsurasak 0:a27e0d3581d1 338
Lucyjungz 1:1f1f2b99756b 339 printf("Done");
Lucyjungz 3:6e08d0bba1bb 340 /* Close the file */
Lucyjungz 3:6e08d0bba1bb 341 fclose(fp);
nsrwsurasak 26:2f10fcabed0e 342 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 343 free(fp);
nsrwsurasak 26:2f10fcabed0e 344 #endif
Lucyjungz 3:6e08d0bba1bb 345 }
Lucyjungz 3:6e08d0bba1bb 346 }
Lucyjungz 3:6e08d0bba1bb 347 /**
Lucyjungz 3:6e08d0bba1bb 348 * @brief Function to log RMS Header
Lucyjungz 3:6e08d0bba1bb 349 * @note sequence must be in the same order with variableList
Lucyjungz 3:6e08d0bba1bb 350 * @param timestamp - time structure to get Date
Lucyjungz 3:6e08d0bba1bb 351 * @retval None
Lucyjungz 3:6e08d0bba1bb 352 */
Lucyjungz 14:4ba6147f067b 353 void FILEMANAGER_LogRMSHeader(time_t timestamp)
nsrwsurasak 23:7ffd9724e105 354 {
nsrwsurasak 23:7ffd9724e105 355
Lucyjungz 3:6e08d0bba1bb 356 /* Get File name */
Lucyjungz 3:6e08d0bba1bb 357 char file_name[] = RTL_LOG_FILE_NAME;
Lucyjungz 3:6e08d0bba1bb 358
Lucyjungz 3:6e08d0bba1bb 359 /* Generate file name with time */
Lucyjungz 14:4ba6147f067b 360 FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name);
Lucyjungz 3:6e08d0bba1bb 361
Lucyjungz 3:6e08d0bba1bb 362 /* Open file in append mode */
Lucyjungz 3:6e08d0bba1bb 363 FILE *fp = fopen(file_name, "a");
Lucyjungz 3:6e08d0bba1bb 364
Lucyjungz 3:6e08d0bba1bb 365 if (fp == NULL)
Lucyjungz 3:6e08d0bba1bb 366 {
Lucyjungz 3:6e08d0bba1bb 367 /* In case of error, print the error message */
Lucyjungz 3:6e08d0bba1bb 368 printf("Error! Unable to open file %s!\n",file_name);
Lucyjungz 11:e21d4c5bfd1b 369
Lucyjungz 11:e21d4c5bfd1b 370 /* Indicate LED Status (OFF)*/
Lucyjungz 14:4ba6147f067b 371 FILEMANAGER_SetLedStatus(false);
Lucyjungz 3:6e08d0bba1bb 372 }
Lucyjungz 3:6e08d0bba1bb 373 else
Lucyjungz 3:6e08d0bba1bb 374 {
Lucyjungz 11:e21d4c5bfd1b 375 /* Indicate LED Status (ON)*/
Lucyjungz 14:4ba6147f067b 376 FILEMANAGER_SetLedStatus(true);
Lucyjungz 11:e21d4c5bfd1b 377
Lucyjungz 3:6e08d0bba1bb 378 /* opened file so can write */
Lucyjungz 3:6e08d0bba1bb 379 printf("\r\n Writing to Log File (%s)....",file_name);
Lucyjungz 3:6e08d0bba1bb 380
Lucyjungz 3:6e08d0bba1bb 381 /* Write the header to the file */
Lucyjungz 14:4ba6147f067b 382 fprintf(fp, "%s,%s",RMS_HEADER_TIME,RMS_HEADER_MSECOND);
Lucyjungz 7:ab015947e368 383
Lucyjungz 14:4ba6147f067b 384 for(int i = 0; i < m_amountVarList; i++)
Lucyjungz 14:4ba6147f067b 385 {
Lucyjungz 14:4ba6147f067b 386 fprintf(fp, ",%s",m_varList[i].varName);
Lucyjungz 14:4ba6147f067b 387 }
Lucyjungz 14:4ba6147f067b 388 /* Write new line as done */
Lucyjungz 14:4ba6147f067b 389 fprintf(fp, "\n");
Lucyjungz 14:4ba6147f067b 390
Lucyjungz 14:4ba6147f067b 391 /* Write the timestamp unit to the file */
Lucyjungz 14:4ba6147f067b 392 fprintf(fp, "-,-");
Lucyjungz 14:4ba6147f067b 393
Lucyjungz 15:b63a539c3754 394
Lucyjungz 15:b63a539c3754 395 /* Write the unit of variables to the file */
Lucyjungz 3:6e08d0bba1bb 396 for(int i = 0; i < m_amountVarList; i++)
Lucyjungz 3:6e08d0bba1bb 397 {
Lucyjungz 15:b63a539c3754 398 fprintf(fp, ",%s",m_varList[i].varUnit);
Lucyjungz 3:6e08d0bba1bb 399 }
Lucyjungz 15:b63a539c3754 400
Lucyjungz 3:6e08d0bba1bb 401 /* Write new line as done */
Lucyjungz 3:6e08d0bba1bb 402 fprintf(fp, "\n");
Lucyjungz 3:6e08d0bba1bb 403
Lucyjungz 3:6e08d0bba1bb 404 printf("Done");
Lucyjungz 3:6e08d0bba1bb 405
Lucyjungz 3:6e08d0bba1bb 406 /* Close the file */
Lucyjungz 3:6e08d0bba1bb 407 fclose(fp);
nsrwsurasak 26:2f10fcabed0e 408
nsrwsurasak 26:2f10fcabed0e 409 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 410 free(fp);
nsrwsurasak 26:2f10fcabed0e 411 #endif
Lucyjungz 3:6e08d0bba1bb 412 }
Lucyjungz 3:6e08d0bba1bb 413 }
Lucyjungz 3:6e08d0bba1bb 414 /**
Lucyjungz 3:6e08d0bba1bb 415 * @brief Function to log Mini RMS System Data
Lucyjungz 3:6e08d0bba1bb 416 * @note this file is only for debug
Lucyjungz 3:6e08d0bba1bb 417 * @param gps_interval -
Lucyjungz 3:6e08d0bba1bb 418 * @retval None
Lucyjungz 3:6e08d0bba1bb 419 */
nsrwsurasak 25:7f3420c04178 420 void FILEMANAGER_LogSystemData(float gps_interval,float rms_interval)
Lucyjungz 3:6e08d0bba1bb 421 {
Lucyjungz 3:6e08d0bba1bb 422 /* Open the file in append mode */
Lucyjungz 3:6e08d0bba1bb 423 FILE *fp = fopen(MINIRMS_LOG_FILE_NAME, "a");
Lucyjungz 3:6e08d0bba1bb 424
Lucyjungz 3:6e08d0bba1bb 425 if (fp == NULL) {
Lucyjungz 3:6e08d0bba1bb 426 /* In case of error, print the msg */
Lucyjungz 3:6e08d0bba1bb 427 printf("Error! Unable to open file!\n");
Lucyjungz 11:e21d4c5bfd1b 428
Lucyjungz 11:e21d4c5bfd1b 429 /* Indicate LED Status (OFF)*/
Lucyjungz 14:4ba6147f067b 430 FILEMANAGER_SetLedStatus(false);
Lucyjungz 3:6e08d0bba1bb 431 }
Lucyjungz 3:6e08d0bba1bb 432 else
Lucyjungz 3:6e08d0bba1bb 433 {
Lucyjungz 11:e21d4c5bfd1b 434 /* Indicate LED Status (ON)*/
Lucyjungz 14:4ba6147f067b 435 FILEMANAGER_SetLedStatus(true);
nsrwsurasak 25:7f3420c04178 436 /* get Timestamp */
nsrwsurasak 25:7f3420c04178 437 time_t seconds = time(NULL);
nsrwsurasak 25:7f3420c04178 438
Lucyjungz 3:6e08d0bba1bb 439 /* Write some message, which is TBD */
nsrwsurasak 25:7f3420c04178 440 fprintf(fp, "\nStart Mini-RMS System with At UTC Time %s , Gps Interval = %f second, RMS Interval = %f second, Variable = %d variable(s) ",ctime(&seconds),gps_interval,rms_interval,m_amountVarList);
Lucyjungz 1:1f1f2b99756b 441 fclose(fp); // ensure you close the file after writing
nsrwsurasak 26:2f10fcabed0e 442
nsrwsurasak 26:2f10fcabed0e 443 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 444 free(fp);
nsrwsurasak 26:2f10fcabed0e 445 #endif
Lucyjungz 1:1f1f2b99756b 446 }
Lucyjungz 1:1f1f2b99756b 447 }
Lucyjungz 3:6e08d0bba1bb 448 /**
Lucyjungz 3:6e08d0bba1bb 449 * @brief Utility to delete file
Lucyjungz 3:6e08d0bba1bb 450 * @note
Lucyjungz 3:6e08d0bba1bb 451 * @param filename - file name to be deleted
Lucyjungz 3:6e08d0bba1bb 452 * @retval None
Lucyjungz 3:6e08d0bba1bb 453 */
Lucyjungz 14:4ba6147f067b 454 void FILEMANAGER_Deletefile(char filename[])
nsrwsurasak 0:a27e0d3581d1 455 {
nsrwsurasak 0:a27e0d3581d1 456 printf("Deleting file '%s'...",filename);
nsrwsurasak 0:a27e0d3581d1 457 FILE *fp = fopen(filename, "r"); // try and open file
nsrwsurasak 0:a27e0d3581d1 458 if (fp != NULL) { // if it does open...
nsrwsurasak 0:a27e0d3581d1 459 fclose(fp); // close it
nsrwsurasak 26:2f10fcabed0e 460
nsrwsurasak 26:2f10fcabed0e 461 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 462 free(fp);
nsrwsurasak 26:2f10fcabed0e 463 #endif
nsrwsurasak 26:2f10fcabed0e 464
nsrwsurasak 0:a27e0d3581d1 465 remove(filename); // and then delete
nsrwsurasak 0:a27e0d3581d1 466 printf("Done!\n");
nsrwsurasak 0:a27e0d3581d1 467 }
nsrwsurasak 0:a27e0d3581d1 468 // if we can't open it, it doesn't exist and so we can't delete it
nsrwsurasak 0:a27e0d3581d1 469 }
Lucyjungz 3:6e08d0bba1bb 470 /**
Lucyjungz 3:6e08d0bba1bb 471 * @brief Utility to check file available
Lucyjungz 3:6e08d0bba1bb 472 * @note
Lucyjungz 3:6e08d0bba1bb 473 * @param filename - file name to be checked
Lucyjungz 3:6e08d0bba1bb 474 * @retval true - file is exist , false - file is not exist
Lucyjungz 3:6e08d0bba1bb 475 */
Lucyjungz 14:4ba6147f067b 476 bool FILEMANAGER_IsFileExist(char filename[])
Lucyjungz 1:1f1f2b99756b 477 {
Lucyjungz 1:1f1f2b99756b 478 bool exist = false;
Lucyjungz 1:1f1f2b99756b 479 FILE *fp = fopen(filename, "r"); // try and open file
Lucyjungz 1:1f1f2b99756b 480 if (fp != NULL) { // if it does open...
Lucyjungz 1:1f1f2b99756b 481 fclose(fp); // close it
nsrwsurasak 26:2f10fcabed0e 482
nsrwsurasak 26:2f10fcabed0e 483 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 484 free(fp);
nsrwsurasak 26:2f10fcabed0e 485 #endif
nsrwsurasak 26:2f10fcabed0e 486
Lucyjungz 1:1f1f2b99756b 487 exist = true;
Lucyjungz 1:1f1f2b99756b 488 }
Lucyjungz 1:1f1f2b99756b 489
Lucyjungz 1:1f1f2b99756b 490 return exist;
Lucyjungz 1:1f1f2b99756b 491 }
Lucyjungz 3:6e08d0bba1bb 492 /**
Lucyjungz 3:6e08d0bba1bb 493 * @brief Utility to get GPS Interval
Lucyjungz 14:4ba6147f067b 494 * @note must be called after read the setup file
Lucyjungz 3:6e08d0bba1bb 495 * @param None
Lucyjungz 3:6e08d0bba1bb 496 * @retval GPS interval
Lucyjungz 3:6e08d0bba1bb 497 */
Lucyjungz 14:4ba6147f067b 498 int FILEMANAGER_GPSInterval()
nsrwsurasak 0:a27e0d3581d1 499 {
Lucyjungz 3:6e08d0bba1bb 500 /* Return interval in int */
Lucyjungz 14:4ba6147f067b 501 return ( m_GpsInterval );
nsrwsurasak 0:a27e0d3581d1 502 }
Lucyjungz 3:6e08d0bba1bb 503 /**
Lucyjungz 3:6e08d0bba1bb 504 * @brief Utility to get Data Interval
Lucyjungz 14:4ba6147f067b 505 * @note must be called after read the setup file
Lucyjungz 3:6e08d0bba1bb 506 * @param None
Lucyjungz 3:6e08d0bba1bb 507 * @retval Data interval
Lucyjungz 3:6e08d0bba1bb 508 */
Lucyjungz 14:4ba6147f067b 509 int FILEMANAGER_DataInterval()
nsrwsurasak 0:a27e0d3581d1 510 {
Lucyjungz 3:6e08d0bba1bb 511 /* Return interval in int */
Lucyjungz 14:4ba6147f067b 512 return ( m_DataInterval );
nsrwsurasak 0:a27e0d3581d1 513 }
Lucyjungz 3:6e08d0bba1bb 514 /**
Lucyjungz 3:6e08d0bba1bb 515 * @brief Function to read the variable list file
Lucyjungz 3:6e08d0bba1bb 516 * @note Recommended to call this function at initilization phase
Lucyjungz 3:6e08d0bba1bb 517 * @param None
Lucyjungz 3:6e08d0bba1bb 518 * @retval pointer to variable list
Lucyjungz 3:6e08d0bba1bb 519 */
Lucyjungz 14:4ba6147f067b 520 Variable_Data_TypeDef * FILEMANAGER_ReadVarFile()
nsrwsurasak 0:a27e0d3581d1 521 {
Lucyjungz 3:6e08d0bba1bb 522 /* Open the file with reading mode */
Lucyjungz 21:0c52dbc23f52 523 FILE *fp = fopen(m_varListFileName, "r");
nsrwsurasak 0:a27e0d3581d1 524
Lucyjungz 3:6e08d0bba1bb 525 if (fp == NULL)
Lucyjungz 3:6e08d0bba1bb 526 {
Lucyjungz 3:6e08d0bba1bb 527 /* if it can't open the file then print error message */
Lucyjungz 21:0c52dbc23f52 528 printf("\nError! Unable to open file! %s \n", m_varListFileName);
Lucyjungz 11:e21d4c5bfd1b 529 /* Indicate LED Status (OFF)*/
Lucyjungz 14:4ba6147f067b 530 FILEMANAGER_SetLedStatus(false);
Lucyjungz 11:e21d4c5bfd1b 531
nsrwsurasak 0:a27e0d3581d1 532 return NULL;
Lucyjungz 3:6e08d0bba1bb 533 }
Lucyjungz 3:6e08d0bba1bb 534 else
Lucyjungz 3:6e08d0bba1bb 535 {
Lucyjungz 11:e21d4c5bfd1b 536 /* Indicate LED Status (ON)*/
Lucyjungz 14:4ba6147f067b 537 FILEMANAGER_SetLedStatus(true);
nsrwsurasak 0:a27e0d3581d1 538
Lucyjungz 3:6e08d0bba1bb 539 /* Allocate buffer for reading */
Lucyjungz 14:4ba6147f067b 540 char buf[READ_FILE_BUFFER_SIZE];
nsrwsurasak 0:a27e0d3581d1 541 int index = 0;
Lucyjungz 3:6e08d0bba1bb 542
Lucyjungz 3:6e08d0bba1bb 543 /* Initialize return value */
nsrwsurasak 0:a27e0d3581d1 544 memset(m_varList, ' ', sizeof(m_varList));
Lucyjungz 3:6e08d0bba1bb 545
Lucyjungz 3:6e08d0bba1bb 546 /* Read line from the file */
Lucyjungz 3:6e08d0bba1bb 547 while (fgets(buf, sizeof(buf), fp) != NULL)
Lucyjungz 3:6e08d0bba1bb 548 {
Lucyjungz 3:6e08d0bba1bb 549 /* Check the TAG */
Lucyjungz 3:6e08d0bba1bb 550 if (strstr (buf,VAR_NAME_TAG))
Lucyjungz 3:6e08d0bba1bb 551 {
Lucyjungz 3:6e08d0bba1bb 552 /* Found variable TAG, populate it*/
Lucyjungz 14:4ba6147f067b 553 FILEMANAGER_GetXmlText(buf , m_varList[index].varName);
Lucyjungz 3:6e08d0bba1bb 554 }
Lucyjungz 3:6e08d0bba1bb 555 else if (strstr (buf,VAR_ADDR_TAG))
Lucyjungz 3:6e08d0bba1bb 556 {
Lucyjungz 3:6e08d0bba1bb 557 /* Found variable address TAG, populate it*/
Lucyjungz 14:4ba6147f067b 558 FILEMANAGER_GetXmlText(buf , m_varList[index].varAddress);
Lucyjungz 5:7c513eee7b2b 559 }
Lucyjungz 10:a8003d357cf2 560 else if (strstr (buf,VAR_TYPE_TAG))
Lucyjungz 10:a8003d357cf2 561 {
Lucyjungz 10:a8003d357cf2 562 /* Found variable type TAG, populate it*/
Lucyjungz 14:4ba6147f067b 563 FILEMANAGER_GetXmlText(buf , m_varList[index].varType);
Lucyjungz 10:a8003d357cf2 564 }
Lucyjungz 6:5bd75c0f607c 565 else if (strstr (buf,VAR_LSB1_TAG))
Lucyjungz 6:5bd75c0f607c 566 {
Lucyjungz 6:5bd75c0f607c 567 /* Found variable LSB1 TAG, populate it*/
Lucyjungz 14:4ba6147f067b 568 FILEMANAGER_GetXmlText(buf , m_varList[index].varLSB1);
Lucyjungz 6:5bd75c0f607c 569 }
Lucyjungz 6:5bd75c0f607c 570 else if (strstr (buf,VAR_LSB2_TAG))
Lucyjungz 5:7c513eee7b2b 571 {
Lucyjungz 6:5bd75c0f607c 572 /* Found variable LSB2 TAG, populate it*/
Lucyjungz 14:4ba6147f067b 573 FILEMANAGER_GetXmlText(buf , m_varList[index].varLSB2);
Lucyjungz 6:5bd75c0f607c 574 }
Lucyjungz 6:5bd75c0f607c 575 else if (strstr (buf,VAR_BITMASK_TAG))
Lucyjungz 6:5bd75c0f607c 576 {
Lucyjungz 6:5bd75c0f607c 577 /* Found variable BitMask TAG, populate it*/
Lucyjungz 14:4ba6147f067b 578 FILEMANAGER_GetXmlText(buf , m_varList[index].varBitMask);
Lucyjungz 5:7c513eee7b2b 579 }
Lucyjungz 5:7c513eee7b2b 580 else if (strstr (buf,VAR_UNIT_TAG))
Lucyjungz 5:7c513eee7b2b 581 {
Lucyjungz 5:7c513eee7b2b 582 /* Found variable unit TAG, populate it*/
Lucyjungz 14:4ba6147f067b 583 FILEMANAGER_GetXmlText(buf , m_varList[index].varUnit);
nsrwsurasak 0:a27e0d3581d1 584 index++;
nsrwsurasak 0:a27e0d3581d1 585 }
nsrwsurasak 0:a27e0d3581d1 586
nsrwsurasak 0:a27e0d3581d1 587 }
Lucyjungz 3:6e08d0bba1bb 588 /* Close File */
Lucyjungz 3:6e08d0bba1bb 589 fclose(fp);
nsrwsurasak 26:2f10fcabed0e 590 #if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
nsrwsurasak 26:2f10fcabed0e 591 free(fp);
nsrwsurasak 26:2f10fcabed0e 592 #endif
Lucyjungz 3:6e08d0bba1bb 593
Lucyjungz 3:6e08d0bba1bb 594 /* Populate amount */
nsrwsurasak 0:a27e0d3581d1 595 m_amountVarList = index;
Lucyjungz 3:6e08d0bba1bb 596
Lucyjungz 3:6e08d0bba1bb 597 /* Return variable list */
nsrwsurasak 0:a27e0d3581d1 598 return m_varList;
nsrwsurasak 0:a27e0d3581d1 599 }
nsrwsurasak 0:a27e0d3581d1 600 }
Lucyjungz 3:6e08d0bba1bb 601 /**
Lucyjungz 3:6e08d0bba1bb 602 * @brief Function to amount of variable for data logging
Lucyjungz 3:6e08d0bba1bb 603 * @note Must be called after readVarFile
Lucyjungz 3:6e08d0bba1bb 604 * @param None
Lucyjungz 3:6e08d0bba1bb 605 * @retval amount of variable list
Lucyjungz 3:6e08d0bba1bb 606 */
Lucyjungz 14:4ba6147f067b 607 int FILEMANAGER_GetAmountVarList()
nsrwsurasak 0:a27e0d3581d1 608 {
nsrwsurasak 0:a27e0d3581d1 609 return m_amountVarList;
nsrwsurasak 0:a27e0d3581d1 610 }
Lucyjungz 3:6e08d0bba1bb 611 /**
Lucyjungz 3:6e08d0bba1bb 612 * @brief Function to get variable list
Lucyjungz 3:6e08d0bba1bb 613 * @note Must be called after readVarFile
Lucyjungz 3:6e08d0bba1bb 614 * @param None
Lucyjungz 3:6e08d0bba1bb 615 * @retval pointer to variable list
Lucyjungz 3:6e08d0bba1bb 616 */
Lucyjungz 14:4ba6147f067b 617 Variable_Data_TypeDef * FILEMANAGER_GetVarList()
nsrwsurasak 0:a27e0d3581d1 618 {
nsrwsurasak 0:a27e0d3581d1 619 return m_varList;
nsrwsurasak 0:a27e0d3581d1 620 }
Lucyjungz 14:4ba6147f067b 621
Lucyjungz 11:e21d4c5bfd1b 622 /**
Lucyjungz 11:e21d4c5bfd1b 623 * @brief Utility to play with LED status
Lucyjungz 11:e21d4c5bfd1b 624 * @note Libary user need to assign proper PinName to LED_SDCARD
Lucyjungz 11:e21d4c5bfd1b 625 * @param on - True for turning LED ON, otherwise LED off
Lucyjungz 11:e21d4c5bfd1b 626 * @retval None
Lucyjungz 11:e21d4c5bfd1b 627 */
Lucyjungz 14:4ba6147f067b 628 static void FILEMANAGER_SetLedStatus(bool on)
Lucyjungz 11:e21d4c5bfd1b 629 {
Lucyjungz 12:0045fca3c160 630 /* Check LED Connection */
nsrwsurasak 22:2fc64ad66e35 631 if (ledStatus.is_connected())
Lucyjungz 11:e21d4c5bfd1b 632 {
Lucyjungz 21:0c52dbc23f52 633 /* Set LED regarding to given argment */
nsrwsurasak 22:2fc64ad66e35 634 if (m_sdCardIsPresent)
nsrwsurasak 22:2fc64ad66e35 635 {
nsrwsurasak 22:2fc64ad66e35 636 ledStatus = on;
nsrwsurasak 22:2fc64ad66e35 637 }
nsrwsurasak 22:2fc64ad66e35 638 else
nsrwsurasak 22:2fc64ad66e35 639 {
nsrwsurasak 22:2fc64ad66e35 640 ledStatus = false;
nsrwsurasak 22:2fc64ad66e35 641 }
nsrwsurasak 22:2fc64ad66e35 642
Lucyjungz 12:0045fca3c160 643 }
Lucyjungz 12:0045fca3c160 644 #if DEBUG
Lucyjungz 12:0045fca3c160 645 else
Lucyjungz 12:0045fca3c160 646 {
Lucyjungz 14:4ba6147f067b 647 printf("\r\nSDCard LED is not connected !!");
Lucyjungz 12:0045fca3c160 648 }
Lucyjungz 12:0045fca3c160 649 #endif
Lucyjungz 11:e21d4c5bfd1b 650 }
Lucyjungz 15:b63a539c3754 651