File manager

Dependencies:   SDFileSystem

Dependents:   RwSDCard_Xml_GPS

Committer:
Lucyjungz
Date:
Sat May 28 06:23:38 2016 +0000
Revision:
29:964610d82f8d
Parent:
28:12c88b5e46e5
Child:
30:184d2ef7dff7
Support RxID & TxID

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