File manager
FileManager.cpp@24:5ee719582d1e, 2016-05-25 (annotated)
- Committer:
- nsrwsurasak
- Date:
- Wed May 25 12:02:43 2016 +0000
- Revision:
- 24:5ee719582d1e
- Parent:
- 23:7ffd9724e105
- Child:
- 25:7f3420c04178
cleanup
Who changed what in which revision?
User | Revision | Line number | New 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 ( ×tamp ); |
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 | 0:a27e0d3581d1 | 204 | } |
nsrwsurasak | 0:a27e0d3581d1 | 205 | } |
Lucyjungz | 3:6e08d0bba1bb | 206 | /** |
Lucyjungz | 3:6e08d0bba1bb | 207 | * @brief Function to log GPS Data |
Lucyjungz | 3:6e08d0bba1bb | 208 | * @note |
Lucyjungz | 3:6e08d0bba1bb | 209 | * @param timestamp - time structure to get Date |
Lucyjungz | 3:6e08d0bba1bb | 210 | * @param lat - char array for lattitude |
Lucyjungz | 3:6e08d0bba1bb | 211 | * @param longti - char array for longtitude |
Lucyjungz | 3:6e08d0bba1bb | 212 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 213 | */ |
Lucyjungz | 14:4ba6147f067b | 214 | void FILEMANAGER_LogGPSData(time_t timestamp ,char lat[], char longti[]) |
nsrwsurasak | 0:a27e0d3581d1 | 215 | { |
nsrwsurasak | 23:7ffd9724e105 | 216 | if (!m_sdCardIsPresent) |
nsrwsurasak | 23:7ffd9724e105 | 217 | { |
nsrwsurasak | 23:7ffd9724e105 | 218 | /** Turn off LED */ |
nsrwsurasak | 23:7ffd9724e105 | 219 | FILEMANAGER_SetLedStatus(false); |
nsrwsurasak | 23:7ffd9724e105 | 220 | |
nsrwsurasak | 23:7ffd9724e105 | 221 | printf("Error! SD Card is not connected \n"); |
nsrwsurasak | 23:7ffd9724e105 | 222 | |
nsrwsurasak | 23:7ffd9724e105 | 223 | /** Return as nothing to be done */ |
nsrwsurasak | 23:7ffd9724e105 | 224 | return; |
nsrwsurasak | 23:7ffd9724e105 | 225 | } |
Lucyjungz | 3:6e08d0bba1bb | 226 | /* Get File name */ |
Lucyjungz | 1:1f1f2b99756b | 227 | char file_name[] = GPS_LOG_FILE_NAME; |
Lucyjungz | 1:1f1f2b99756b | 228 | |
Lucyjungz | 3:6e08d0bba1bb | 229 | /* Generate file name with time stamp */ |
Lucyjungz | 14:4ba6147f067b | 230 | FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name); |
Lucyjungz | 3:6e08d0bba1bb | 231 | |
Lucyjungz | 3:6e08d0bba1bb | 232 | /* Open file with "APPEND" mode */ |
Lucyjungz | 1:1f1f2b99756b | 233 | FILE *fp = fopen(file_name, "a"); |
Lucyjungz | 1:1f1f2b99756b | 234 | |
Lucyjungz | 3:6e08d0bba1bb | 235 | if (fp == NULL) |
Lucyjungz | 3:6e08d0bba1bb | 236 | { |
Lucyjungz | 3:6e08d0bba1bb | 237 | /* if it can't open the file then print error message */ |
Lucyjungz | 1:1f1f2b99756b | 238 | printf("Error! Unable to open file %s!\n",file_name); |
Lucyjungz | 11:e21d4c5bfd1b | 239 | |
Lucyjungz | 11:e21d4c5bfd1b | 240 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 241 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 242 | } |
Lucyjungz | 11:e21d4c5bfd1b | 243 | else |
Lucyjungz | 11:e21d4c5bfd1b | 244 | { |
Lucyjungz | 11:e21d4c5bfd1b | 245 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 246 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 247 | |
Lucyjungz | 3:6e08d0bba1bb | 248 | /* Print some message for information */ |
Lucyjungz | 1:1f1f2b99756b | 249 | printf("\r\n Writing to Gps Log File (%s)....",file_name); |
Lucyjungz | 1:1f1f2b99756b | 250 | |
Lucyjungz | 3:6e08d0bba1bb | 251 | /* Write the line with lattitude and longtitude */ |
Lucyjungz | 3:6e08d0bba1bb | 252 | fprintf(fp, "%d,%s,%s\n",timestamp,lat,longti); |
Lucyjungz | 1:1f1f2b99756b | 253 | |
Lucyjungz | 1:1f1f2b99756b | 254 | printf("Done"); |
Lucyjungz | 3:6e08d0bba1bb | 255 | /* Close file once it done */ |
Lucyjungz | 3:6e08d0bba1bb | 256 | fclose(fp); |
Lucyjungz | 1:1f1f2b99756b | 257 | } |
Lucyjungz | 1:1f1f2b99756b | 258 | } |
Lucyjungz | 3:6e08d0bba1bb | 259 | /** |
Lucyjungz | 3:6e08d0bba1bb | 260 | * @brief Function to log RMS Data |
Lucyjungz | 3:6e08d0bba1bb | 261 | * @note sequence must be in the same order with variableList |
Lucyjungz | 3:6e08d0bba1bb | 262 | * @param timestamp - time structure to get Date |
Lucyjungz | 3:6e08d0bba1bb | 263 | * @param var - float array to be log in the file |
Lucyjungz | 3:6e08d0bba1bb | 264 | * @param size - size of the float array |
Lucyjungz | 3:6e08d0bba1bb | 265 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 266 | */ |
Lucyjungz | 21:0c52dbc23f52 | 267 | void FILEMANAGER_LogRMSData(time_t timestamp ,float * var, int size, bool * p_headerRequired) |
Lucyjungz | 1:1f1f2b99756b | 268 | { |
nsrwsurasak | 23:7ffd9724e105 | 269 | if (!m_sdCardIsPresent) |
nsrwsurasak | 23:7ffd9724e105 | 270 | { |
nsrwsurasak | 23:7ffd9724e105 | 271 | /** Turn off LED */ |
nsrwsurasak | 23:7ffd9724e105 | 272 | FILEMANAGER_SetLedStatus(false); |
nsrwsurasak | 23:7ffd9724e105 | 273 | |
nsrwsurasak | 23:7ffd9724e105 | 274 | printf("Error! SD Card is not connected \n"); |
nsrwsurasak | 23:7ffd9724e105 | 275 | |
nsrwsurasak | 23:7ffd9724e105 | 276 | /** Return as nothing to be done */ |
nsrwsurasak | 23:7ffd9724e105 | 277 | return; |
nsrwsurasak | 23:7ffd9724e105 | 278 | } |
Lucyjungz | 3:6e08d0bba1bb | 279 | /* Get File name */ |
Lucyjungz | 1:1f1f2b99756b | 280 | char file_name[] = RTL_LOG_FILE_NAME; |
Lucyjungz | 1:1f1f2b99756b | 281 | |
Lucyjungz | 3:6e08d0bba1bb | 282 | /* Generate File name with timestamp */ |
Lucyjungz | 14:4ba6147f067b | 283 | FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name); |
Lucyjungz | 21:0c52dbc23f52 | 284 | if (*p_headerRequired || !FILEMANAGER_IsFileExist(file_name)) |
Lucyjungz | 1:1f1f2b99756b | 285 | { |
Lucyjungz | 3:6e08d0bba1bb | 286 | /* If file is not exist, log the header */ |
Lucyjungz | 14:4ba6147f067b | 287 | FILEMANAGER_LogRMSHeader(timestamp); |
Lucyjungz | 21:0c52dbc23f52 | 288 | |
Lucyjungz | 21:0c52dbc23f52 | 289 | /* Clear flag once header has been written */ |
Lucyjungz | 21:0c52dbc23f52 | 290 | *p_headerRequired = false; |
Lucyjungz | 1:1f1f2b99756b | 291 | } |
Lucyjungz | 3:6e08d0bba1bb | 292 | /* Open file with "APPEND" mode */ |
Lucyjungz | 1:1f1f2b99756b | 293 | FILE *fp = fopen(file_name, "a"); |
nsrwsurasak | 0:a27e0d3581d1 | 294 | |
Lucyjungz | 3:6e08d0bba1bb | 295 | if (fp == NULL) |
Lucyjungz | 3:6e08d0bba1bb | 296 | { |
Lucyjungz | 3:6e08d0bba1bb | 297 | /* In case of error, print the error message */ |
Lucyjungz | 1:1f1f2b99756b | 298 | printf("Error! Unable to open file %s!\n",file_name); |
Lucyjungz | 11:e21d4c5bfd1b | 299 | |
Lucyjungz | 11:e21d4c5bfd1b | 300 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 301 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 302 | } |
Lucyjungz | 3:6e08d0bba1bb | 303 | else |
Lucyjungz | 3:6e08d0bba1bb | 304 | { |
Lucyjungz | 11:e21d4c5bfd1b | 305 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 306 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 307 | |
Lucyjungz | 3:6e08d0bba1bb | 308 | /* Print some message for information */ |
Lucyjungz | 1:1f1f2b99756b | 309 | printf("\r\n Writing to Log File (%s)....",file_name); |
Lucyjungz | 1:1f1f2b99756b | 310 | |
Lucyjungz | 3:6e08d0bba1bb | 311 | /* Write timestamp */ |
nsrwsurasak | 22:2fc64ad66e35 | 312 | fprintf(fp, "%d,%d",timestamp,(msec.read_ms()%MSEC_SCALE)); |
Lucyjungz | 1:1f1f2b99756b | 313 | |
Lucyjungz | 3:6e08d0bba1bb | 314 | /* Write variable data */ |
Lucyjungz | 1:1f1f2b99756b | 315 | for(int i = 0; i < size; i++) |
Lucyjungz | 1:1f1f2b99756b | 316 | { |
nsrwsurasak | 19:5af5c60e7a9f | 317 | fprintf(fp, ",%g",var[i]); |
Lucyjungz | 1:1f1f2b99756b | 318 | } |
Lucyjungz | 3:6e08d0bba1bb | 319 | /* Write new line as we done */ |
Lucyjungz | 3:6e08d0bba1bb | 320 | fprintf(fp, "\n"); |
nsrwsurasak | 0:a27e0d3581d1 | 321 | |
Lucyjungz | 1:1f1f2b99756b | 322 | printf("Done"); |
Lucyjungz | 3:6e08d0bba1bb | 323 | /* Close the file */ |
Lucyjungz | 3:6e08d0bba1bb | 324 | fclose(fp); |
Lucyjungz | 3:6e08d0bba1bb | 325 | } |
Lucyjungz | 3:6e08d0bba1bb | 326 | } |
Lucyjungz | 3:6e08d0bba1bb | 327 | /** |
Lucyjungz | 3:6e08d0bba1bb | 328 | * @brief Function to log RMS Header |
Lucyjungz | 3:6e08d0bba1bb | 329 | * @note sequence must be in the same order with variableList |
Lucyjungz | 3:6e08d0bba1bb | 330 | * @param timestamp - time structure to get Date |
Lucyjungz | 3:6e08d0bba1bb | 331 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 332 | */ |
Lucyjungz | 14:4ba6147f067b | 333 | void FILEMANAGER_LogRMSHeader(time_t timestamp) |
nsrwsurasak | 23:7ffd9724e105 | 334 | { |
nsrwsurasak | 23:7ffd9724e105 | 335 | |
Lucyjungz | 3:6e08d0bba1bb | 336 | /* Get File name */ |
Lucyjungz | 3:6e08d0bba1bb | 337 | char file_name[] = RTL_LOG_FILE_NAME; |
Lucyjungz | 3:6e08d0bba1bb | 338 | |
Lucyjungz | 3:6e08d0bba1bb | 339 | /* Generate file name with time */ |
Lucyjungz | 14:4ba6147f067b | 340 | FILEMANAGER_GenerateFileNameWithTime(timestamp,file_name); |
Lucyjungz | 3:6e08d0bba1bb | 341 | |
Lucyjungz | 3:6e08d0bba1bb | 342 | /* Open file in append mode */ |
Lucyjungz | 3:6e08d0bba1bb | 343 | FILE *fp = fopen(file_name, "a"); |
Lucyjungz | 3:6e08d0bba1bb | 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 | 3:6e08d0bba1bb | 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 | |
Lucyjungz | 3:6e08d0bba1bb | 358 | /* opened file so can write */ |
Lucyjungz | 3:6e08d0bba1bb | 359 | printf("\r\n Writing to Log File (%s)....",file_name); |
Lucyjungz | 3:6e08d0bba1bb | 360 | |
Lucyjungz | 3:6e08d0bba1bb | 361 | /* Write the header to the file */ |
Lucyjungz | 14:4ba6147f067b | 362 | fprintf(fp, "%s,%s",RMS_HEADER_TIME,RMS_HEADER_MSECOND); |
Lucyjungz | 7:ab015947e368 | 363 | |
Lucyjungz | 14:4ba6147f067b | 364 | for(int i = 0; i < m_amountVarList; i++) |
Lucyjungz | 14:4ba6147f067b | 365 | { |
Lucyjungz | 14:4ba6147f067b | 366 | fprintf(fp, ",%s",m_varList[i].varName); |
Lucyjungz | 14:4ba6147f067b | 367 | } |
Lucyjungz | 14:4ba6147f067b | 368 | /* Write new line as done */ |
Lucyjungz | 14:4ba6147f067b | 369 | fprintf(fp, "\n"); |
Lucyjungz | 14:4ba6147f067b | 370 | |
Lucyjungz | 14:4ba6147f067b | 371 | /* Write the timestamp unit to the file */ |
Lucyjungz | 14:4ba6147f067b | 372 | fprintf(fp, "-,-"); |
Lucyjungz | 14:4ba6147f067b | 373 | |
Lucyjungz | 15:b63a539c3754 | 374 | |
Lucyjungz | 15:b63a539c3754 | 375 | /* Write the unit of variables to the file */ |
Lucyjungz | 3:6e08d0bba1bb | 376 | for(int i = 0; i < m_amountVarList; i++) |
Lucyjungz | 3:6e08d0bba1bb | 377 | { |
Lucyjungz | 15:b63a539c3754 | 378 | fprintf(fp, ",%s",m_varList[i].varUnit); |
Lucyjungz | 3:6e08d0bba1bb | 379 | } |
Lucyjungz | 15:b63a539c3754 | 380 | |
Lucyjungz | 3:6e08d0bba1bb | 381 | /* Write new line as done */ |
Lucyjungz | 3:6e08d0bba1bb | 382 | fprintf(fp, "\n"); |
Lucyjungz | 3:6e08d0bba1bb | 383 | |
Lucyjungz | 3:6e08d0bba1bb | 384 | printf("Done"); |
Lucyjungz | 3:6e08d0bba1bb | 385 | |
Lucyjungz | 3:6e08d0bba1bb | 386 | /* Close the file */ |
Lucyjungz | 3:6e08d0bba1bb | 387 | fclose(fp); |
Lucyjungz | 3:6e08d0bba1bb | 388 | } |
Lucyjungz | 3:6e08d0bba1bb | 389 | } |
Lucyjungz | 3:6e08d0bba1bb | 390 | /** |
Lucyjungz | 3:6e08d0bba1bb | 391 | * @brief Function to log Mini RMS System Data |
Lucyjungz | 3:6e08d0bba1bb | 392 | * @note this file is only for debug |
Lucyjungz | 3:6e08d0bba1bb | 393 | * @param gps_interval - |
Lucyjungz | 3:6e08d0bba1bb | 394 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 395 | */ |
Lucyjungz | 14:4ba6147f067b | 396 | void FILEMANAGER_LogSystemData(float gps_interval) |
Lucyjungz | 3:6e08d0bba1bb | 397 | { |
Lucyjungz | 3:6e08d0bba1bb | 398 | /* Open the file in append mode */ |
Lucyjungz | 3:6e08d0bba1bb | 399 | FILE *fp = fopen(MINIRMS_LOG_FILE_NAME, "a"); |
Lucyjungz | 3:6e08d0bba1bb | 400 | |
Lucyjungz | 3:6e08d0bba1bb | 401 | if (fp == NULL) { |
Lucyjungz | 3:6e08d0bba1bb | 402 | /* In case of error, print the msg */ |
Lucyjungz | 3:6e08d0bba1bb | 403 | printf("Error! Unable to open file!\n"); |
Lucyjungz | 11:e21d4c5bfd1b | 404 | |
Lucyjungz | 11:e21d4c5bfd1b | 405 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 406 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 3:6e08d0bba1bb | 407 | } |
Lucyjungz | 3:6e08d0bba1bb | 408 | else |
Lucyjungz | 3:6e08d0bba1bb | 409 | { |
Lucyjungz | 11:e21d4c5bfd1b | 410 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 411 | FILEMANAGER_SetLedStatus(true); |
Lucyjungz | 11:e21d4c5bfd1b | 412 | |
Lucyjungz | 3:6e08d0bba1bb | 413 | /* Write some message, which is TBD */ |
Lucyjungz | 3:6e08d0bba1bb | 414 | fprintf(fp, "\nStart Mini-RMS System with Gps Interval = %f",gps_interval); |
Lucyjungz | 1:1f1f2b99756b | 415 | fclose(fp); // ensure you close the file after writing |
Lucyjungz | 1:1f1f2b99756b | 416 | } |
Lucyjungz | 1:1f1f2b99756b | 417 | } |
Lucyjungz | 3:6e08d0bba1bb | 418 | /** |
Lucyjungz | 3:6e08d0bba1bb | 419 | * @brief Utility to delete file |
Lucyjungz | 3:6e08d0bba1bb | 420 | * @note |
Lucyjungz | 3:6e08d0bba1bb | 421 | * @param filename - file name to be deleted |
Lucyjungz | 3:6e08d0bba1bb | 422 | * @retval None |
Lucyjungz | 3:6e08d0bba1bb | 423 | */ |
Lucyjungz | 14:4ba6147f067b | 424 | void FILEMANAGER_Deletefile(char filename[]) |
nsrwsurasak | 0:a27e0d3581d1 | 425 | { |
nsrwsurasak | 0:a27e0d3581d1 | 426 | printf("Deleting file '%s'...",filename); |
nsrwsurasak | 0:a27e0d3581d1 | 427 | FILE *fp = fopen(filename, "r"); // try and open file |
nsrwsurasak | 0:a27e0d3581d1 | 428 | if (fp != NULL) { // if it does open... |
nsrwsurasak | 0:a27e0d3581d1 | 429 | fclose(fp); // close it |
nsrwsurasak | 0:a27e0d3581d1 | 430 | remove(filename); // and then delete |
nsrwsurasak | 0:a27e0d3581d1 | 431 | printf("Done!\n"); |
nsrwsurasak | 0:a27e0d3581d1 | 432 | } |
nsrwsurasak | 0:a27e0d3581d1 | 433 | // if we can't open it, it doesn't exist and so we can't delete it |
nsrwsurasak | 0:a27e0d3581d1 | 434 | } |
Lucyjungz | 3:6e08d0bba1bb | 435 | /** |
Lucyjungz | 3:6e08d0bba1bb | 436 | * @brief Utility to check file available |
Lucyjungz | 3:6e08d0bba1bb | 437 | * @note |
Lucyjungz | 3:6e08d0bba1bb | 438 | * @param filename - file name to be checked |
Lucyjungz | 3:6e08d0bba1bb | 439 | * @retval true - file is exist , false - file is not exist |
Lucyjungz | 3:6e08d0bba1bb | 440 | */ |
Lucyjungz | 14:4ba6147f067b | 441 | bool FILEMANAGER_IsFileExist(char filename[]) |
Lucyjungz | 1:1f1f2b99756b | 442 | { |
Lucyjungz | 1:1f1f2b99756b | 443 | bool exist = false; |
Lucyjungz | 1:1f1f2b99756b | 444 | FILE *fp = fopen(filename, "r"); // try and open file |
Lucyjungz | 1:1f1f2b99756b | 445 | if (fp != NULL) { // if it does open... |
Lucyjungz | 1:1f1f2b99756b | 446 | fclose(fp); // close it |
Lucyjungz | 1:1f1f2b99756b | 447 | exist = true; |
Lucyjungz | 1:1f1f2b99756b | 448 | } |
Lucyjungz | 1:1f1f2b99756b | 449 | |
Lucyjungz | 1:1f1f2b99756b | 450 | return exist; |
Lucyjungz | 1:1f1f2b99756b | 451 | } |
Lucyjungz | 3:6e08d0bba1bb | 452 | /** |
Lucyjungz | 3:6e08d0bba1bb | 453 | * @brief Utility to get GPS Interval |
Lucyjungz | 14:4ba6147f067b | 454 | * @note must be called after read the setup file |
Lucyjungz | 3:6e08d0bba1bb | 455 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 456 | * @retval GPS interval |
Lucyjungz | 3:6e08d0bba1bb | 457 | */ |
Lucyjungz | 14:4ba6147f067b | 458 | int FILEMANAGER_GPSInterval() |
nsrwsurasak | 0:a27e0d3581d1 | 459 | { |
Lucyjungz | 3:6e08d0bba1bb | 460 | /* Return interval in int */ |
Lucyjungz | 14:4ba6147f067b | 461 | return ( m_GpsInterval ); |
nsrwsurasak | 0:a27e0d3581d1 | 462 | } |
Lucyjungz | 3:6e08d0bba1bb | 463 | /** |
Lucyjungz | 3:6e08d0bba1bb | 464 | * @brief Utility to get Data Interval |
Lucyjungz | 14:4ba6147f067b | 465 | * @note must be called after read the setup file |
Lucyjungz | 3:6e08d0bba1bb | 466 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 467 | * @retval Data interval |
Lucyjungz | 3:6e08d0bba1bb | 468 | */ |
Lucyjungz | 14:4ba6147f067b | 469 | int FILEMANAGER_DataInterval() |
nsrwsurasak | 0:a27e0d3581d1 | 470 | { |
Lucyjungz | 3:6e08d0bba1bb | 471 | /* Return interval in int */ |
Lucyjungz | 14:4ba6147f067b | 472 | return ( m_DataInterval ); |
nsrwsurasak | 0:a27e0d3581d1 | 473 | } |
Lucyjungz | 3:6e08d0bba1bb | 474 | /** |
Lucyjungz | 3:6e08d0bba1bb | 475 | * @brief Function to read the variable list file |
Lucyjungz | 3:6e08d0bba1bb | 476 | * @note Recommended to call this function at initilization phase |
Lucyjungz | 3:6e08d0bba1bb | 477 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 478 | * @retval pointer to variable list |
Lucyjungz | 3:6e08d0bba1bb | 479 | */ |
Lucyjungz | 14:4ba6147f067b | 480 | Variable_Data_TypeDef * FILEMANAGER_ReadVarFile() |
nsrwsurasak | 0:a27e0d3581d1 | 481 | { |
Lucyjungz | 3:6e08d0bba1bb | 482 | /* Open the file with reading mode */ |
Lucyjungz | 21:0c52dbc23f52 | 483 | FILE *fp = fopen(m_varListFileName, "r"); |
nsrwsurasak | 0:a27e0d3581d1 | 484 | |
Lucyjungz | 3:6e08d0bba1bb | 485 | if (fp == NULL) |
Lucyjungz | 3:6e08d0bba1bb | 486 | { |
Lucyjungz | 3:6e08d0bba1bb | 487 | /* if it can't open the file then print error message */ |
Lucyjungz | 21:0c52dbc23f52 | 488 | printf("\nError! Unable to open file! %s \n", m_varListFileName); |
Lucyjungz | 11:e21d4c5bfd1b | 489 | /* Indicate LED Status (OFF)*/ |
Lucyjungz | 14:4ba6147f067b | 490 | FILEMANAGER_SetLedStatus(false); |
Lucyjungz | 11:e21d4c5bfd1b | 491 | |
nsrwsurasak | 0:a27e0d3581d1 | 492 | return NULL; |
Lucyjungz | 3:6e08d0bba1bb | 493 | } |
Lucyjungz | 3:6e08d0bba1bb | 494 | else |
Lucyjungz | 3:6e08d0bba1bb | 495 | { |
Lucyjungz | 11:e21d4c5bfd1b | 496 | /* Indicate LED Status (ON)*/ |
Lucyjungz | 14:4ba6147f067b | 497 | FILEMANAGER_SetLedStatus(true); |
nsrwsurasak | 0:a27e0d3581d1 | 498 | |
Lucyjungz | 3:6e08d0bba1bb | 499 | /* Allocate buffer for reading */ |
Lucyjungz | 14:4ba6147f067b | 500 | char buf[READ_FILE_BUFFER_SIZE]; |
nsrwsurasak | 0:a27e0d3581d1 | 501 | int index = 0; |
Lucyjungz | 3:6e08d0bba1bb | 502 | |
Lucyjungz | 3:6e08d0bba1bb | 503 | /* Initialize return value */ |
nsrwsurasak | 0:a27e0d3581d1 | 504 | memset(m_varList, ' ', sizeof(m_varList)); |
Lucyjungz | 3:6e08d0bba1bb | 505 | |
Lucyjungz | 3:6e08d0bba1bb | 506 | /* Read line from the file */ |
Lucyjungz | 3:6e08d0bba1bb | 507 | while (fgets(buf, sizeof(buf), fp) != NULL) |
Lucyjungz | 3:6e08d0bba1bb | 508 | { |
Lucyjungz | 3:6e08d0bba1bb | 509 | /* Check the TAG */ |
Lucyjungz | 3:6e08d0bba1bb | 510 | if (strstr (buf,VAR_NAME_TAG)) |
Lucyjungz | 3:6e08d0bba1bb | 511 | { |
Lucyjungz | 3:6e08d0bba1bb | 512 | /* Found variable TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 513 | FILEMANAGER_GetXmlText(buf , m_varList[index].varName); |
Lucyjungz | 3:6e08d0bba1bb | 514 | } |
Lucyjungz | 3:6e08d0bba1bb | 515 | else if (strstr (buf,VAR_ADDR_TAG)) |
Lucyjungz | 3:6e08d0bba1bb | 516 | { |
Lucyjungz | 3:6e08d0bba1bb | 517 | /* Found variable address TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 518 | FILEMANAGER_GetXmlText(buf , m_varList[index].varAddress); |
Lucyjungz | 5:7c513eee7b2b | 519 | } |
Lucyjungz | 10:a8003d357cf2 | 520 | else if (strstr (buf,VAR_TYPE_TAG)) |
Lucyjungz | 10:a8003d357cf2 | 521 | { |
Lucyjungz | 10:a8003d357cf2 | 522 | /* Found variable type TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 523 | FILEMANAGER_GetXmlText(buf , m_varList[index].varType); |
Lucyjungz | 10:a8003d357cf2 | 524 | } |
Lucyjungz | 6:5bd75c0f607c | 525 | else if (strstr (buf,VAR_LSB1_TAG)) |
Lucyjungz | 6:5bd75c0f607c | 526 | { |
Lucyjungz | 6:5bd75c0f607c | 527 | /* Found variable LSB1 TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 528 | FILEMANAGER_GetXmlText(buf , m_varList[index].varLSB1); |
Lucyjungz | 6:5bd75c0f607c | 529 | } |
Lucyjungz | 6:5bd75c0f607c | 530 | else if (strstr (buf,VAR_LSB2_TAG)) |
Lucyjungz | 5:7c513eee7b2b | 531 | { |
Lucyjungz | 6:5bd75c0f607c | 532 | /* Found variable LSB2 TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 533 | FILEMANAGER_GetXmlText(buf , m_varList[index].varLSB2); |
Lucyjungz | 6:5bd75c0f607c | 534 | } |
Lucyjungz | 6:5bd75c0f607c | 535 | else if (strstr (buf,VAR_BITMASK_TAG)) |
Lucyjungz | 6:5bd75c0f607c | 536 | { |
Lucyjungz | 6:5bd75c0f607c | 537 | /* Found variable BitMask TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 538 | FILEMANAGER_GetXmlText(buf , m_varList[index].varBitMask); |
Lucyjungz | 5:7c513eee7b2b | 539 | } |
Lucyjungz | 5:7c513eee7b2b | 540 | else if (strstr (buf,VAR_UNIT_TAG)) |
Lucyjungz | 5:7c513eee7b2b | 541 | { |
Lucyjungz | 5:7c513eee7b2b | 542 | /* Found variable unit TAG, populate it*/ |
Lucyjungz | 14:4ba6147f067b | 543 | FILEMANAGER_GetXmlText(buf , m_varList[index].varUnit); |
nsrwsurasak | 0:a27e0d3581d1 | 544 | index++; |
nsrwsurasak | 0:a27e0d3581d1 | 545 | } |
nsrwsurasak | 0:a27e0d3581d1 | 546 | |
nsrwsurasak | 0:a27e0d3581d1 | 547 | } |
Lucyjungz | 3:6e08d0bba1bb | 548 | /* Close File */ |
Lucyjungz | 3:6e08d0bba1bb | 549 | fclose(fp); |
Lucyjungz | 3:6e08d0bba1bb | 550 | |
Lucyjungz | 3:6e08d0bba1bb | 551 | /* Populate amount */ |
nsrwsurasak | 0:a27e0d3581d1 | 552 | m_amountVarList = index; |
Lucyjungz | 3:6e08d0bba1bb | 553 | |
Lucyjungz | 3:6e08d0bba1bb | 554 | /* Return variable list */ |
nsrwsurasak | 0:a27e0d3581d1 | 555 | return m_varList; |
nsrwsurasak | 0:a27e0d3581d1 | 556 | } |
nsrwsurasak | 0:a27e0d3581d1 | 557 | } |
Lucyjungz | 3:6e08d0bba1bb | 558 | /** |
Lucyjungz | 3:6e08d0bba1bb | 559 | * @brief Function to amount of variable for data logging |
Lucyjungz | 3:6e08d0bba1bb | 560 | * @note Must be called after readVarFile |
Lucyjungz | 3:6e08d0bba1bb | 561 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 562 | * @retval amount of variable list |
Lucyjungz | 3:6e08d0bba1bb | 563 | */ |
Lucyjungz | 14:4ba6147f067b | 564 | int FILEMANAGER_GetAmountVarList() |
nsrwsurasak | 0:a27e0d3581d1 | 565 | { |
nsrwsurasak | 0:a27e0d3581d1 | 566 | return m_amountVarList; |
nsrwsurasak | 0:a27e0d3581d1 | 567 | } |
Lucyjungz | 3:6e08d0bba1bb | 568 | /** |
Lucyjungz | 3:6e08d0bba1bb | 569 | * @brief Function to get variable list |
Lucyjungz | 3:6e08d0bba1bb | 570 | * @note Must be called after readVarFile |
Lucyjungz | 3:6e08d0bba1bb | 571 | * @param None |
Lucyjungz | 3:6e08d0bba1bb | 572 | * @retval pointer to variable list |
Lucyjungz | 3:6e08d0bba1bb | 573 | */ |
Lucyjungz | 14:4ba6147f067b | 574 | Variable_Data_TypeDef * FILEMANAGER_GetVarList() |
nsrwsurasak | 0:a27e0d3581d1 | 575 | { |
nsrwsurasak | 0:a27e0d3581d1 | 576 | return m_varList; |
nsrwsurasak | 0:a27e0d3581d1 | 577 | } |
Lucyjungz | 14:4ba6147f067b | 578 | |
Lucyjungz | 11:e21d4c5bfd1b | 579 | /** |
Lucyjungz | 11:e21d4c5bfd1b | 580 | * @brief Utility to play with LED status |
Lucyjungz | 11:e21d4c5bfd1b | 581 | * @note Libary user need to assign proper PinName to LED_SDCARD |
Lucyjungz | 11:e21d4c5bfd1b | 582 | * @param on - True for turning LED ON, otherwise LED off |
Lucyjungz | 11:e21d4c5bfd1b | 583 | * @retval None |
Lucyjungz | 11:e21d4c5bfd1b | 584 | */ |
Lucyjungz | 14:4ba6147f067b | 585 | static void FILEMANAGER_SetLedStatus(bool on) |
Lucyjungz | 11:e21d4c5bfd1b | 586 | { |
Lucyjungz | 12:0045fca3c160 | 587 | /* Check LED Connection */ |
nsrwsurasak | 22:2fc64ad66e35 | 588 | if (ledStatus.is_connected()) |
Lucyjungz | 11:e21d4c5bfd1b | 589 | { |
Lucyjungz | 21:0c52dbc23f52 | 590 | /* Set LED regarding to given argment */ |
nsrwsurasak | 22:2fc64ad66e35 | 591 | if (m_sdCardIsPresent) |
nsrwsurasak | 22:2fc64ad66e35 | 592 | { |
nsrwsurasak | 22:2fc64ad66e35 | 593 | ledStatus = on; |
nsrwsurasak | 22:2fc64ad66e35 | 594 | } |
nsrwsurasak | 22:2fc64ad66e35 | 595 | else |
nsrwsurasak | 22:2fc64ad66e35 | 596 | { |
nsrwsurasak | 22:2fc64ad66e35 | 597 | ledStatus = false; |
nsrwsurasak | 22:2fc64ad66e35 | 598 | } |
nsrwsurasak | 22:2fc64ad66e35 | 599 | |
Lucyjungz | 12:0045fca3c160 | 600 | } |
Lucyjungz | 12:0045fca3c160 | 601 | #if DEBUG |
Lucyjungz | 12:0045fca3c160 | 602 | else |
Lucyjungz | 12:0045fca3c160 | 603 | { |
Lucyjungz | 14:4ba6147f067b | 604 | printf("\r\nSDCard LED is not connected !!"); |
Lucyjungz | 12:0045fca3c160 | 605 | } |
Lucyjungz | 12:0045fca3c160 | 606 | #endif |
Lucyjungz | 11:e21d4c5bfd1b | 607 | } |
Lucyjungz | 15:b63a539c3754 | 608 |